Rename 'desc' column of checklist table to 'description', and update associated tests and views

This commit is contained in:
Timothy Warren 2014-08-13 15:57:24 -04:00
parent 591173f163
commit 98c55a78ad
15 changed files with 67 additions and 34 deletions

View File

@ -1,12 +1,13 @@
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
install:
- composer install
- composer install --dev --no-progress
env:
- DB=mysql

View File

@ -424,6 +424,7 @@ class Todo {
->where('user_id', $user_id)
->where('name !=', $username)
->where('is_admin', 1)
->order_by('name')
->get();
return $groups->result_array();
@ -510,7 +511,7 @@ class Todo {
$friends = $this->CI->db
->select('user_friend_id,user_friend_link.user_id as uid,user.username')
->from('todo_user_friend_link')
->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner')
->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner')
->where('confirmed', FRIEND_CONFIRMED)
->where('username !=', $username)
@ -541,6 +542,7 @@ class Todo {
->select('user_id')
->from('group_users_link')
->where('group_id', $group_id)
->order_by('user_id')
->get();
return $friends->result_array();
@ -678,7 +680,7 @@ class Todo {
* Kanji Num
*
* Converts arabic to chinese number
* @param int $number
* @param int $orig_number
* @return string
*/
public function kanji_num($orig_number)

View File

@ -29,7 +29,7 @@ class Friend_model extends CI_Model {
$friends = $this->db
->select('user_friend_id,user_friend_link.user_id as uid,user.username,user.email')
->from('todo_user_friend_link')
->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner')
->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner')
->group_start()
->where_in('todo_user_friend_link.user_id', $user_id)

View File

@ -116,7 +116,7 @@ class Task_model extends CI_Model {
public function get_checklist($task_id)
{
//Get the checklist for the current task from the database
$chk = $this->db->select('id, task_id, "desc", is_checked')
$chk = $this->db->select('id, task_id, description, is_checked')
->from('checklist')
->where('task_id', $task_id)
->order_by('is_checked', 'asc')
@ -138,36 +138,34 @@ class Task_model extends CI_Model {
public function add_checklist_item()
{
$task_id = (int)$this->input->post('task_id');
$desc = xss_clean($this->input->post('desc'));
$desc = $this->input->post('desc', TRUE);
//Check if the current item already exists.
$exists = $this->db->select('task_id, "desc"')
$exists = $this->db->select('task_id, description')
->from('checklist')
->where('task_id', $task_id)
->where('"desc"', $desc)
->where('description', $desc)
->get();
if($exists->num_rows() < 1)
{
//Insert the item
$this->db->set('task_id', $task_id)
->set('"desc"', $desc)
->set('description', $desc)
->insert('checklist');
//Return the row
$return = $this->db->select('id, task_id, "desc", is_checked')
$return = $this->db->select('id, task_id, description, is_checked')
->from('checklist')
->where('task_id', $task_id)
->where('"desc"', $desc)
->where('description', $desc)
->get();
return $return->row_array();
}
else
{
return FALSE;
}
}
// --------------------------------------------------------------------------
@ -235,6 +233,7 @@ class Task_model extends CI_Model {
*
* Retrieves the user's archived tasks from the database
*
* @param int $page
* @param int $per_page
* @return array
*/

View File

@ -20,13 +20,6 @@ class Fixture {
{
exit('can\'t load fixture library class when not in test mode!');
}
// Turn off foreign key checks for mysql so test tables can be easily truncated
if (getenv('DB') === 'mysql')
{
$this->_assign_db();
$this->CI->db->simple_query('SET foreign_key_checks = 0;');
}
}
/**
@ -87,6 +80,9 @@ class Fixture {
private function truncate($table)
{
// Turn off foreign key checks for mysql so test tables can be easily truncated
if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 0;');
$sql = 'TRUNCATE TABLE ' . $table;
if (getenv('DB') !== 'mysql')
@ -94,7 +90,12 @@ class Fixture {
$sql .= ' CASCADE';
}
return $this->CI->db->simple_query($sql);
$res = $this->CI->db->simple_query($sql);
// Reset foreign key checks
//if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 1;');
return $res;
}
}

View File

@ -1,5 +1,5 @@
<li>
<input type="checkbox" name="checklist[]" value="<?= $id ?>" id="check_<?= $id?>" <?= ($is_checked == 1) ? 'checked="checked"' : '' ?> />
&nbsp;&nbsp;<label for="check_<?= $id ?>"><?= $desc ?></label>
&nbsp;&nbsp;<label for="check_<?= $id ?>"><?= $description ?></label>
</li>

View File

@ -7,7 +7,7 @@
<?php foreach($checklist as $c) : ?>
<li>
<input type="checkbox" name="checklist[]" value="<?= $c['id'] ?>" id="check_<?= $c['id']?>" <?= ($c['is_checked']== 1) ? 'checked="checked"' : '' ?> <?= ($user_perms <= PERM_CHECKLIST_ACCESS) ? 'disabled="disabled"' : '' ?> />
&nbsp;&nbsp;<label for="check_<?= $c['id']?>"><?= $c['desc'] ?></label>
&nbsp;&nbsp;<label for="check_<?= $c['id']?>"><?= $c['description'] ?></label>
</li>
<?php endforeach ?>
<?php endif ?>

View File

@ -1,5 +1,16 @@
{
"name":"timw4mail/tims-todo",
"type":"project",
"license": "BSD-3-Clause",
"authors": [{
"name": "Timothy J. Warren",
"email": "tim@timshomepage.net",
"homepage": "https://timshomepage.net",
"role": "Developer"
}],
"require": {
"robmorgan/phinx": "*"
"php": ">=5.4",
"robmorgan/phinx": "*",
"ircmaxell/password-compat": "1.0.*"
}
}

View File

@ -0,0 +1,15 @@
<?php
use Phinx\Migration\AbstractMigration;
class RenameDescColumnMigration extends AbstractMigration
{
/**
* Rename 'desc' field to 'description'. Reserved words suck
*/
public function change()
{
$this->table('todo_checklist')
->renameColumn('desc', 'description');
}
}

View File

@ -1,5 +1,8 @@
<?php
// Autoloader for password compat
require_once(__DIR__ . '/../vendor/autoload.php');
// Require base bootstrap file
require_once(__DIR__ . '/../application/third_party/CIUnit/bootstrap_phpunit.php');

View File

@ -1,12 +1,12 @@
0:
id: 18
task_id: 97
desc: 'Share this task'
description: 'Share this task'
is_checked: 1
1:
id: 136
task_id: 97
desc: 'Allow un-sharing'
description: 'Allow un-sharing'
is_checked: 1

View File

@ -3,7 +3,7 @@
user_id: 3
item_id: 97
comment: "This is a test comment"
time_posted: 1405457296
time_posted: 1405457299
status: 3
2:

View File

@ -418,10 +418,10 @@ class TodoLibTest extends Todo_TestCase {
{
$expected = [
array (
'user_id' => '7',
'user_id' => '3',
),
array (
'user_id' => '3',
'user_id' => '7',
)
];
$actual = $this->CI->todo->get_friends_in_group(62);

View File

@ -427,7 +427,7 @@ class TaskModelTest extends Todo_TestCase {
'user_id' => '3',
'item_id' => '97',
'comment' => 'This is a test comment',
'time_posted' => '1405457296',
'time_posted' => '1405457299',
'email' => 'guest@timshomepage.net',
'status' => 'In Progress',
),
@ -452,13 +452,13 @@ class TaskModelTest extends Todo_TestCase {
array (
'id' => '18',
'task_id' => '97',
'desc' => 'Share this task',
'description' => 'Share this task',
'is_checked' => '1',
),
array (
'id' => '136',
'task_id' => '97',
'desc' => 'Allow un-sharing',
'description' => 'Allow un-sharing',
'is_checked' => '1',
),
];

View File

@ -271,6 +271,7 @@ define('VIEWPATH', $view_folder);
*
* And away we go...
*/
require_once '../vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */