diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/ActionModel.php (renamed from app/Model/Action.php) | 22 | ||||
-rw-r--r-- | app/Model/ActionParameterModel.php (renamed from app/Model/ActionParameter.php) | 14 | ||||
-rw-r--r-- | app/Model/AvatarFileModel.php (renamed from app/Model/AvatarFile.php) | 11 | ||||
-rw-r--r-- | app/Model/Base.php | 34 | ||||
-rw-r--r-- | app/Model/BoardModel.php (renamed from app/Model/Board.php) | 22 | ||||
-rw-r--r-- | app/Model/CategoryModel.php (renamed from app/Model/Category.php) | 12 | ||||
-rw-r--r-- | app/Model/ColorModel.php (renamed from app/Model/Color.php) | 8 | ||||
-rw-r--r-- | app/Model/ColumnModel.php (renamed from app/Model/Column.php) | 8 | ||||
-rw-r--r-- | app/Model/CommentModel.php (renamed from app/Model/Comment.php) | 31 | ||||
-rw-r--r-- | app/Model/ConfigModel.php (renamed from app/Model/Config.php) | 4 | ||||
-rw-r--r-- | app/Model/CurrencyModel.php (renamed from app/Model/Currency.php) | 8 | ||||
-rw-r--r-- | app/Model/CustomFilterModel.php (renamed from app/Model/CustomFilter.php) | 14 | ||||
-rw-r--r-- | app/Model/FileModel.php (renamed from app/Model/File.php) | 88 | ||||
-rw-r--r-- | app/Model/GroupMemberModel.php (renamed from app/Model/GroupMember.php) | 16 | ||||
-rw-r--r-- | app/Model/GroupModel.php (renamed from app/Model/Group.php) | 8 | ||||
-rw-r--r-- | app/Model/LanguageModel.php (renamed from app/Model/Language.php) | 5 | ||||
-rw-r--r-- | app/Model/LastLoginModel.php (renamed from app/Model/LastLogin.php) | 6 | ||||
-rw-r--r-- | app/Model/LinkModel.php (renamed from app/Model/Link.php) | 5 | ||||
-rw-r--r-- | app/Model/MetadataModel.php (renamed from app/Model/Metadata.php) | 6 | ||||
-rw-r--r-- | app/Model/NotificationModel.php (renamed from app/Model/Notification.php) | 68 | ||||
-rw-r--r-- | app/Model/NotificationTypeModel.php (renamed from app/Model/NotificationType.php) | 7 | ||||
-rw-r--r-- | app/Model/PasswordResetModel.php (renamed from app/Model/PasswordReset.php) | 8 | ||||
-rw-r--r-- | app/Model/ProjectActivityModel.php (renamed from app/Model/ProjectActivity.php) | 15 | ||||
-rw-r--r-- | app/Model/ProjectDailyColumnStatsModel.php (renamed from app/Model/ProjectDailyColumnStats.php) | 20 | ||||
-rw-r--r-- | app/Model/ProjectDailyStatsModel.php (renamed from app/Model/ProjectDailyStats.php) | 6 | ||||
-rw-r--r-- | app/Model/ProjectDuplicationModel.php (renamed from app/Model/ProjectDuplication.php) | 21 | ||||
-rw-r--r-- | app/Model/ProjectFile.php | 40 | ||||
-rw-r--r-- | app/Model/ProjectFileModel.php | 74 | ||||
-rw-r--r-- | app/Model/ProjectGroupRoleModel.php (renamed from app/Model/ProjectGroupRole.php) | 45 | ||||
-rw-r--r-- | app/Model/ProjectMetadataModel.php (renamed from app/Model/ProjectMetadata.php) | 4 | ||||
-rw-r--r-- | app/Model/ProjectModel.php (renamed from app/Model/Project.php) | 33 | ||||
-rw-r--r-- | app/Model/ProjectNotificationModel.php (renamed from app/Model/ProjectNotification.php) | 18 | ||||
-rw-r--r-- | app/Model/ProjectNotificationTypeModel.php (renamed from app/Model/ProjectNotificationType.php) | 4 | ||||
-rw-r--r-- | app/Model/ProjectPermissionModel.php (renamed from app/Model/ProjectPermission.php) | 43 | ||||
-rw-r--r-- | app/Model/ProjectUserRoleModel.php (renamed from app/Model/ProjectUserRole.php) | 53 | ||||
-rw-r--r-- | app/Model/RememberMeSessionModel.php (renamed from app/Model/RememberMeSession.php) | 5 | ||||
-rw-r--r-- | app/Model/SettingModel.php (renamed from app/Model/Setting.php) | 6 | ||||
-rw-r--r-- | app/Model/SubtaskModel.php (renamed from app/Model/Subtask.php) | 53 | ||||
-rw-r--r-- | app/Model/SubtaskTimeTrackingModel.php (renamed from app/Model/SubtaskTimeTracking.php) | 69 | ||||
-rw-r--r-- | app/Model/SwimlaneModel.php (renamed from app/Model/Swimlane.php) | 25 | ||||
-rw-r--r-- | app/Model/TaskAnalyticModel.php (renamed from app/Model/TaskAnalytic.php) | 10 | ||||
-rw-r--r-- | app/Model/TaskCreationModel.php (renamed from app/Model/TaskCreation.php) | 27 | ||||
-rw-r--r-- | app/Model/TaskDuplicationModel.php (renamed from app/Model/TaskDuplication.php) | 49 | ||||
-rw-r--r-- | app/Model/TaskExternalLinkModel.php (renamed from app/Model/TaskExternalLink.php) | 12 | ||||
-rw-r--r-- | app/Model/TaskFile.php | 54 | ||||
-rw-r--r-- | app/Model/TaskFileModel.php | 88 | ||||
-rw-r--r-- | app/Model/TaskFinderModel.php (renamed from app/Model/TaskFinder.php) | 199 | ||||
-rw-r--r-- | app/Model/TaskLinkModel.php (renamed from app/Model/TaskLink.php) | 61 | ||||
-rw-r--r-- | app/Model/TaskMetadataModel.php (renamed from app/Model/TaskMetadata.php) | 4 | ||||
-rw-r--r-- | app/Model/TaskModel.php (renamed from app/Model/Task.php) | 34 | ||||
-rw-r--r-- | app/Model/TaskModificationModel.php (renamed from app/Model/TaskModification.php) | 15 | ||||
-rw-r--r-- | app/Model/TaskPositionModel.php (renamed from app/Model/TaskPosition.php) | 27 | ||||
-rw-r--r-- | app/Model/TaskStatusModel.php (renamed from app/Model/TaskStatus.php) | 27 | ||||
-rw-r--r-- | app/Model/TimezoneModel.php (renamed from app/Model/Timezone.php) | 6 | ||||
-rw-r--r-- | app/Model/TransitionModel.php (renamed from app/Model/Transition.php) | 32 | ||||
-rw-r--r-- | app/Model/UserLockingModel.php (renamed from app/Model/UserLocking.php) | 16 | ||||
-rw-r--r-- | app/Model/UserMentionModel.php (renamed from app/Model/UserMention.php) | 11 | ||||
-rw-r--r-- | app/Model/UserMetadataModel.php (renamed from app/Model/UserMetadata.php) | 4 | ||||
-rw-r--r-- | app/Model/UserModel.php (renamed from app/Model/User.php) | 31 | ||||
-rw-r--r-- | app/Model/UserNotificationFilterModel.php (renamed from app/Model/UserNotificationFilter.php) | 10 | ||||
-rw-r--r-- | app/Model/UserNotificationModel.php (renamed from app/Model/UserNotification.php) | 73 | ||||
-rw-r--r-- | app/Model/UserNotificationTypeModel.php (renamed from app/Model/UserNotificationType.php) | 4 | ||||
-rw-r--r-- | app/Model/UserUnreadNotificationModel.php (renamed from app/Model/UserUnreadNotification.php) | 32 |
63 files changed, 969 insertions, 796 deletions
diff --git a/app/Model/Action.php b/app/Model/ActionModel.php index f055d9d0..53393ed5 100644 --- a/app/Model/Action.php +++ b/app/Model/ActionModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Action Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Action extends Base +class ActionModel extends Base { /** * SQL table name for actions @@ -26,12 +28,12 @@ class Action extends Base */ public function getAllByUser($user_id) { - $project_ids = $this->projectPermission->getActiveProjectIds($user_id); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($user_id); $actions = array(); if (! empty($project_ids)) { $actions = $this->db->table(self::TABLE)->in('project_id', $project_ids)->findAll(); - $params = $this->actionParameter->getAllByActions(array_column($actions, 'id')); + $params = $this->actionParameterModel->getAllByActions(array_column($actions, 'id')); $this->attachParamsToActions($actions, $params); } @@ -48,7 +50,7 @@ class Action extends Base public function getAllByProject($project_id) { $actions = $this->db->table(self::TABLE)->eq('project_id', $project_id)->findAll(); - $params = $this->actionParameter->getAllByActions(array_column($actions, 'id')); + $params = $this->actionParameterModel->getAllByActions(array_column($actions, 'id')); return $this->attachParamsToActions($actions, $params); } @@ -61,7 +63,7 @@ class Action extends Base public function getAll() { $actions = $this->db->table(self::TABLE)->findAll(); - $params = $this->actionParameter->getAll(); + $params = $this->actionParameterModel->getAll(); return $this->attachParamsToActions($actions, $params); } @@ -77,7 +79,7 @@ class Action extends Base $action = $this->db->table(self::TABLE)->eq('id', $action_id)->findOne(); if (! empty($action)) { - $action['params'] = $this->actionParameter->getAllByAction($action_id); + $action['params'] = $this->actionParameterModel->getAllByAction($action_id); } return $action; @@ -136,7 +138,7 @@ class Action extends Base $action_id = $this->db->getLastId(); - if (! $this->actionParameter->create($action_id, $values)) { + if (! $this->actionParameterModel->create($action_id, $values)) { $this->db->cancelTransaction(); return false; } @@ -156,7 +158,7 @@ class Action extends Base */ public function duplicate($src_project_id, $dst_project_id) { - $actions = $this->action->getAllByProject($src_project_id); + $actions = $this->actionModel->getAllByProject($src_project_id); foreach ($actions as $action) { $this->db->startTransaction(); @@ -174,7 +176,7 @@ class Action extends Base $action_id = $this->db->getLastId(); - if (! $this->actionParameter->duplicateParameters($dst_project_id, $action_id, $action['params'])) { + if (! $this->actionParameterModel->duplicateParameters($dst_project_id, $action_id, $action['params'])) { $this->logger->error('Action::duplicate => skip action '.$action['action_name'].' '.$action['id']); $this->db->cancelTransaction(); continue; diff --git a/app/Model/ActionParameter.php b/app/Model/ActionParameterModel.php index 53edcbc8..9895da0f 100644 --- a/app/Model/ActionParameter.php +++ b/app/Model/ActionParameterModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Action Parameter Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ActionParameter extends Base +class ActionParameterModel extends Base { /** * SQL table name @@ -145,16 +147,16 @@ class ActionParameter extends Base case 'project_id': return $value != $project_id ? $value : false; case 'category_id': - return $this->category->getIdByName($project_id, $this->category->getNameById($value)) ?: false; + return $this->categoryModel->getIdByName($project_id, $this->categoryModel->getNameById($value)) ?: false; case 'src_column_id': case 'dest_column_id': case 'dst_column_id': case 'column_id': - $column = $this->column->getById($value); - return empty($column) ? false : $this->column->getColumnIdByTitle($project_id, $column['title']) ?: false; + $column = $this->columnModel->getById($value); + return empty($column) ? false : $this->columnModel->getColumnIdByTitle($project_id, $column['title']) ?: false; case 'user_id': case 'owner_id': - return $this->projectPermission->isAssignable($project_id, $value) ? $value : false; + return $this->projectPermissionModel->isAssignable($project_id, $value) ? $value : false; default: return $value; } diff --git a/app/Model/AvatarFile.php b/app/Model/AvatarFileModel.php index 9f47ccc7..6e36d83f 100644 --- a/app/Model/AvatarFile.php +++ b/app/Model/AvatarFileModel.php @@ -3,14 +3,15 @@ namespace Kanboard\Model; use Exception; +use Kanboard\Core\Base; /** * Avatar File * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class AvatarFile extends Base +class AvatarFileModel extends Base { /** * Path prefix @@ -28,7 +29,7 @@ class AvatarFile extends Base */ public function getFilename($user_id) { - return $this->db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('avatar_path'); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->findOneColumn('avatar_path'); } /** @@ -41,7 +42,7 @@ class AvatarFile extends Base */ public function create($user_id, $path) { - $result = $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( + $result = $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array( 'avatar_path' => $path, )); @@ -64,7 +65,7 @@ class AvatarFile extends Base if (! empty($filename)) { $this->objectStorage->remove($filename); - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('avatar_path' => '')); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('avatar_path' => '')); } } catch (Exception $e) { $this->logger->error($e->getMessage()); diff --git a/app/Model/Base.php b/app/Model/Base.php deleted file mode 100644 index a27560c8..00000000 --- a/app/Model/Base.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -namespace Kanboard\Model; - -use PicoDb\Database; - -/** - * Base model class - * - * @package model - * @author Frederic Guillot - */ -abstract class Base extends \Kanboard\Core\Base -{ - /** - * Save a record in the database - * - * @access public - * @param string $table Table name - * @param array $values Form values - * @return boolean|integer - */ - public function persist($table, array $values) - { - return $this->db->transaction(function (Database $db) use ($table, $values) { - - if (! $db->table($table)->save($values)) { - return false; - } - - return (int) $db->getLastId(); - }); - } -} diff --git a/app/Model/Board.php b/app/Model/BoardModel.php index d41ecafe..d2718b47 100644 --- a/app/Model/Board.php +++ b/app/Model/BoardModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Board model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Board extends Base +class BoardModel extends Base { /** * Get Kanboard default columns @@ -29,7 +31,7 @@ class Board extends Base */ public function getUserColumns() { - $column_names = explode(',', $this->config->get('board_columns', implode(',', $this->getDefaultColumns()))); + $column_names = explode(',', $this->configModel->get('board_columns', implode(',', $this->getDefaultColumns()))); $columns = array(); foreach ($column_names as $column_name) { @@ -64,7 +66,7 @@ class Board extends Base 'description' => $column['description'], ); - if (! $this->db->table(Column::TABLE)->save($values)) { + if (! $this->db->table(ColumnModel::TABLE)->save($values)) { return false; } } @@ -82,13 +84,13 @@ class Board extends Base */ public function duplicate($project_from, $project_to) { - $columns = $this->db->table(Column::TABLE) + $columns = $this->db->table(ColumnModel::TABLE) ->columns('title', 'task_limit', 'description') ->eq('project_id', $project_from) ->asc('position') ->findAll(); - return $this->board->create($project_to, $columns); + return $this->boardModel->create($project_to, $columns); } /** @@ -101,8 +103,8 @@ class Board extends Base */ public function getBoard($project_id, $callback = null) { - $swimlanes = $this->swimlane->getSwimlanes($project_id); - $columns = $this->column->getAll($project_id); + $swimlanes = $this->swimlaneModel->getSwimlanes($project_id); + $columns = $this->columnModel->getAll($project_id); $nb_columns = count($columns); for ($i = 0, $ilen = count($swimlanes); $i < $ilen; $i++) { @@ -120,7 +122,7 @@ class Board extends Base $swimlanes[0]['columns'][$j]['total_score'] = 0; } - $swimlanes[$i]['columns'][$j]['tasks'] = $callback === null ? $this->taskFinder->getTasksByColumnAndSwimlane($project_id, $column_id, $swimlane_id) : $callback($project_id, $column_id, $swimlane_id); + $swimlanes[$i]['columns'][$j]['tasks'] = $callback === null ? $this->taskFinderModel->getTasksByColumnAndSwimlane($project_id, $column_id, $swimlane_id) : $callback($project_id, $column_id, $swimlane_id); $swimlanes[$i]['columns'][$j]['nb_tasks'] = count($swimlanes[$i]['columns'][$j]['tasks']); $swimlanes[$i]['columns'][$j]['score'] = $this->getColumnSum($swimlanes[$i]['columns'][$j]['tasks'], 'score'); $swimlanes[$i]['nb_tasks'] += $swimlanes[$i]['columns'][$j]['nb_tasks']; @@ -162,7 +164,7 @@ class Board extends Base public function getColumnStats($project_id, $prepend = false) { $listing = $this->db - ->hashtable(Task::TABLE) + ->hashtable(TaskModel::TABLE) ->eq('project_id', $project_id) ->eq('is_active', 1) ->groupBy('column_id') diff --git a/app/Model/Category.php b/app/Model/CategoryModel.php index 1d5f6546..62fb5611 100644 --- a/app/Model/Category.php +++ b/app/Model/CategoryModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Category model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Category extends Base +class CategoryModel extends Base { /** * SQL table name @@ -123,7 +125,7 @@ class Category extends Base public function createDefaultCategories($project_id) { $results = array(); - $categories = explode(',', $this->config->get('project_categories')); + $categories = explode(',', $this->configModel->get('project_categories')); foreach ($categories as $category) { $category = trim($category); @@ -148,7 +150,7 @@ class Category extends Base */ public function create(array $values) { - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** @@ -174,7 +176,7 @@ class Category extends Base { $this->db->startTransaction(); - $this->db->table(Task::TABLE)->eq('category_id', $category_id)->update(array('category_id' => 0)); + $this->db->table(TaskModel::TABLE)->eq('category_id', $category_id)->update(array('category_id' => 0)); if (! $this->db->table(self::TABLE)->eq('id', $category_id)->remove()) { $this->db->cancelTransaction(); diff --git a/app/Model/Color.php b/app/Model/ColorModel.php index dee28643..9e69dda2 100644 --- a/app/Model/Color.php +++ b/app/Model/ColorModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Color model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Color extends Base +class ColorModel extends Base { /** * Default colors @@ -163,7 +165,7 @@ class Color extends Base */ public function getDefaultColor() { - return $this->config->get('default_color', 'yellow'); + return $this->configModel->get('default_color', 'yellow'); } /** diff --git a/app/Model/Column.php b/app/Model/ColumnModel.php index ccdcb049..1adac0f2 100644 --- a/app/Model/Column.php +++ b/app/Model/ColumnModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Column Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Column extends Base +class ColumnModel extends Base { /** * SQL table name @@ -140,7 +142,7 @@ class Column extends Base 'description' => $description, ); - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** diff --git a/app/Model/Comment.php b/app/Model/CommentModel.php index c5091d89..36e1fc48 100644 --- a/app/Model/Comment.php +++ b/app/Model/CommentModel.php @@ -3,14 +3,15 @@ namespace Kanboard\Model; use Kanboard\Event\CommentEvent; +use Kanboard\Core\Base; /** * Comment model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Comment extends Base +class CommentModel extends Base { /** * SQL table name @@ -46,12 +47,12 @@ class Comment extends Base self::TABLE.'.task_id', self::TABLE.'.user_id', self::TABLE.'.comment', - User::TABLE.'.username', - User::TABLE.'.name', - User::TABLE.'.email', - User::TABLE.'.avatar_path' + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.email', + UserModel::TABLE.'.avatar_path' ) - ->join(User::TABLE, 'id', 'user_id') + ->join(UserModel::TABLE, 'id', 'user_id') ->orderBy(self::TABLE.'.date_creation', $sorting) ->eq(self::TABLE.'.task_id', $task_id) ->findAll(); @@ -75,12 +76,12 @@ class Comment extends Base self::TABLE.'.date_creation', self::TABLE.'.comment', self::TABLE.'.reference', - User::TABLE.'.username', - User::TABLE.'.name', - User::TABLE.'.email', - User::TABLE.'.avatar_path' + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.email', + UserModel::TABLE.'.avatar_path' ) - ->join(User::TABLE, 'id', 'user_id') + ->join(UserModel::TABLE, 'id', 'user_id') ->eq(self::TABLE.'.id', $comment_id) ->findOne(); } @@ -110,12 +111,12 @@ class Comment extends Base public function create(array $values) { $values['date_creation'] = time(); - $comment_id = $this->persist(self::TABLE, $values); + $comment_id = $this->db->table(self::TABLE)->persist($values); - if ($comment_id) { + if ($comment_id !== false) { $event = new CommentEvent(array('id' => $comment_id) + $values); $this->dispatcher->dispatch(self::EVENT_CREATE, $event); - $this->userMention->fireEvents($values['comment'], self::EVENT_USER_MENTION, $event); + $this->userMentionModel->fireEvents($values['comment'], self::EVENT_USER_MENTION, $event); } return $comment_id; diff --git a/app/Model/Config.php b/app/Model/ConfigModel.php index 1b14efa1..945c5e6f 100644 --- a/app/Model/Config.php +++ b/app/Model/ConfigModel.php @@ -7,10 +7,10 @@ use Kanboard\Core\Security\Token; /** * Config model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Config extends Setting +class ConfigModel extends SettingModel { /** * Get a config variable with in-memory caching diff --git a/app/Model/Currency.php b/app/Model/CurrencyModel.php index abcce2f0..bfd9697c 100644 --- a/app/Model/Currency.php +++ b/app/Model/CurrencyModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Currency * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Currency extends Base +class CurrencyModel extends Base { /** * SQL table name @@ -65,7 +67,7 @@ class Currency extends Base public function getPrice($currency, $price) { static $rates = null; - $reference = $this->config->get('application_currency', 'USD'); + $reference = $this->configModel->get('application_currency', 'USD'); if ($reference !== $currency) { $rates = $rates === null ? $this->db->hashtable(self::TABLE)->getAll('currency', 'rate') : $rates; diff --git a/app/Model/CustomFilter.php b/app/Model/CustomFilterModel.php index 3a6a1a3a..a4c23b5c 100644 --- a/app/Model/CustomFilter.php +++ b/app/Model/CustomFilterModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Custom Filter model * - * @package model + * @package Kanboard\Model * @author Timo Litzbarski */ -class CustomFilter extends Base +class CustomFilterModel extends Base { /** * SQL table name @@ -30,8 +32,8 @@ class CustomFilter extends Base return $this->db ->table(self::TABLE) ->columns( - User::TABLE.'.name as owner_name', - User::TABLE.'.username as owner_username', + UserModel::TABLE.'.name as owner_name', + UserModel::TABLE.'.username as owner_username', self::TABLE.'.id', self::TABLE.'.user_id', self::TABLE.'.project_id', @@ -41,7 +43,7 @@ class CustomFilter extends Base self::TABLE.'.append' ) ->asc(self::TABLE.'.name') - ->join(User::TABLE, 'id', 'user_id') + ->join(UserModel::TABLE, 'id', 'user_id') ->beginOr() ->eq('is_shared', 1) ->eq('user_id', $user_id) @@ -71,7 +73,7 @@ class CustomFilter extends Base */ public function create(array $values) { - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** diff --git a/app/Model/File.php b/app/Model/FileModel.php index e383235c..8cdea9a0 100644 --- a/app/Model/File.php +++ b/app/Model/FileModel.php @@ -3,6 +3,7 @@ namespace Kanboard\Model; use Exception; +use Kanboard\Core\Base; use Kanboard\Core\Thumbnail; use Kanboard\Event\FileEvent; use Kanboard\Core\ObjectStorage\ObjectStorageException; @@ -10,12 +11,48 @@ use Kanboard\Core\ObjectStorage\ObjectStorageException; /** * Base File Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -abstract class File extends Base +abstract class FileModel extends Base { /** + * Get the table + * + * @abstract + * @access protected + * @return string + */ + abstract protected function getTable(); + + /** + * Define the foreign key + * + * @abstract + * @access protected + * @return string + */ + abstract protected function getForeignKey(); + + /** + * Get the path prefix + * + * @abstract + * @access protected + * @return string + */ + abstract protected function getPathPrefix(); + + /** + * Get event name + * + * @abstract + * @access protected + * @return string + */ + abstract protected function getEventName(); + + /** * Get PicoDb query to get all files * * @access protected @@ -24,21 +61,21 @@ abstract class File extends Base protected function getQuery() { return $this->db - ->table(static::TABLE) + ->table($this->getTable()) ->columns( - static::TABLE.'.id', - static::TABLE.'.name', - static::TABLE.'.path', - static::TABLE.'.is_image', - static::TABLE.'.'.static::FOREIGN_KEY, - static::TABLE.'.date', - static::TABLE.'.user_id', - static::TABLE.'.size', - User::TABLE.'.username', - User::TABLE.'.name as user_name' + $this->getTable().'.id', + $this->getTable().'.name', + $this->getTable().'.path', + $this->getTable().'.is_image', + $this->getTable().'.'.$this->getForeignKey(), + $this->getTable().'.date', + $this->getTable().'.user_id', + $this->getTable().'.size', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name as user_name' ) - ->join(User::TABLE, 'id', 'user_id') - ->asc(static::TABLE.'.name'); + ->join(UserModel::TABLE, 'id', 'user_id') + ->asc($this->getTable().'.name'); } /** @@ -50,7 +87,7 @@ abstract class File extends Base */ public function getById($file_id) { - return $this->db->table(static::TABLE)->eq('id', $file_id)->findOne(); + return $this->db->table($this->getTable())->eq('id', $file_id)->findOne(); } /** @@ -62,7 +99,7 @@ abstract class File extends Base */ public function getAll($id) { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->findAll(); + return $this->getQuery()->eq($this->getForeignKey(), $id)->findAll(); } /** @@ -74,7 +111,7 @@ abstract class File extends Base */ public function getAllImages($id) { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 1)->findAll(); + return $this->getQuery()->eq($this->getForeignKey(), $id)->eq('is_image', 1)->findAll(); } /** @@ -86,7 +123,7 @@ abstract class File extends Base */ public function getAllDocuments($id) { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 0)->findAll(); + return $this->getQuery()->eq($this->getForeignKey(), $id)->eq('is_image', 0)->findAll(); } /** @@ -102,7 +139,7 @@ abstract class File extends Base public function create($id, $name, $path, $size) { $values = array( - static::FOREIGN_KEY => $id, + $this->getForeignKey() => $id, 'name' => substr($name, 0, 255), 'path' => $path, 'is_image' => $this->isImage($name) ? 1 : 0, @@ -111,12 +148,12 @@ abstract class File extends Base 'date' => time(), ); - $result = $this->db->table(static::TABLE)->insert($values); + $result = $this->db->table($this->getTable())->insert($values); if ($result) { $file_id = (int) $this->db->getLastId(); $event = new FileEvent($values + array('file_id' => $file_id)); - $this->dispatcher->dispatch(static::EVENT_CREATE, $event); + $this->dispatcher->dispatch($this->getEventName(), $event); return $file_id; } @@ -132,7 +169,7 @@ abstract class File extends Base */ public function removeAll($id) { - $file_ids = $this->db->table(static::TABLE)->eq(static::FOREIGN_KEY, $id)->asc('id')->findAllByColumn('id'); + $file_ids = $this->db->table($this->getTable())->eq($this->getForeignKey(), $id)->asc('id')->findAllByColumn('id'); $results = array(); foreach ($file_ids as $file_id) { @@ -159,7 +196,7 @@ abstract class File extends Base $this->objectStorage->remove($this->getThumbnailPath($file['path'])); } - return $this->db->table(static::TABLE)->eq('id', $file['id'])->remove(); + return $this->db->table($this->getTable())->eq('id', $file['id'])->remove(); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); return false; @@ -210,7 +247,7 @@ abstract class File extends Base */ public function generatePath($id, $filename) { - return static::PATH_PREFIX.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.hash('sha1', $filename.time()); + return $this->getPathPrefix().DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.hash('sha1', $filename.time()); } /** @@ -252,6 +289,7 @@ abstract class File extends Base * @access public * @param integer $id * @param array $file + * @throws Exception */ public function uploadFile($id, array $file) { diff --git a/app/Model/GroupMember.php b/app/Model/GroupMemberModel.php index baf303c4..a2077789 100644 --- a/app/Model/GroupMember.php +++ b/app/Model/GroupMemberModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Group Member Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class GroupMember extends Base +class GroupMemberModel extends Base { /** * SQL table name @@ -27,7 +29,7 @@ class GroupMember extends Base public function getQuery($group_id) { return $this->db->table(self::TABLE) - ->join(User::TABLE, 'id', 'user_id') + ->join(UserModel::TABLE, 'id', 'user_id') ->eq('group_id', $group_id); } @@ -56,7 +58,7 @@ class GroupMember extends Base ->columns('user_id') ->eq('group_id', $group_id); - return $this->db->table(User::TABLE) + return $this->db->table(UserModel::TABLE) ->notInSubquery('id', $subquery) ->findAll(); } @@ -119,10 +121,10 @@ class GroupMember extends Base public function getGroups($user_id) { return $this->db->table(self::TABLE) - ->columns(Group::TABLE.'.id', Group::TABLE.'.external_id', Group::TABLE.'.name') - ->join(Group::TABLE, 'id', 'group_id') + ->columns(GroupModel::TABLE.'.id', GroupModel::TABLE.'.external_id', GroupModel::TABLE.'.name') + ->join(GroupModel::TABLE, 'id', 'group_id') ->eq(self::TABLE.'.user_id', $user_id) - ->asc(Group::TABLE.'.name') + ->asc(GroupModel::TABLE.'.name') ->findAll(); } } diff --git a/app/Model/Group.php b/app/Model/GroupModel.php index 24dc432b..0a975570 100644 --- a/app/Model/Group.php +++ b/app/Model/GroupModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Group Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Group extends Base +class GroupModel extends Base { /** * SQL table name @@ -97,7 +99,7 @@ class Group extends Base */ public function create($name, $external_id = '') { - return $this->persist(self::TABLE, array( + return $this->db->table(self::TABLE)->persist(array( 'name' => $name, 'external_id' => $external_id, )); diff --git a/app/Model/Language.php b/app/Model/LanguageModel.php index 441771e0..eb6de004 100644 --- a/app/Model/Language.php +++ b/app/Model/LanguageModel.php @@ -2,6 +2,7 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Translator; /** @@ -10,7 +11,7 @@ use Kanboard\Core\Translator; * @package Kanboard\Model * @author Frederic Guillot */ -class Language extends Base +class LanguageModel extends Base { /** * Get all language codes @@ -163,7 +164,7 @@ class Language extends Base return $this->sessionStorage->user['language']; } - return $this->config->get('application_language', 'en_US'); + return $this->configModel->get('application_language', 'en_US'); } /** diff --git a/app/Model/LastLogin.php b/app/Model/LastLoginModel.php index feb5f5a3..16821392 100644 --- a/app/Model/LastLogin.php +++ b/app/Model/LastLoginModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * LastLogin model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class LastLogin extends Base +class LastLoginModel extends Base { /** * SQL table name diff --git a/app/Model/Link.php b/app/Model/LinkModel.php index 903a98d6..b72c7532 100644 --- a/app/Model/Link.php +++ b/app/Model/LinkModel.php @@ -3,15 +3,16 @@ namespace Kanboard\Model; use PDO; +use Kanboard\Core\Base; /** * Link model * - * @package model + * @package Kanboard\Model * @author Olivier Maridat * @author Frederic Guillot */ -class Link extends Base +class LinkModel extends Base { /** * SQL table name diff --git a/app/Model/Metadata.php b/app/Model/MetadataModel.php index 52f6b009..6177e5f3 100644 --- a/app/Model/Metadata.php +++ b/app/Model/MetadataModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Metadata * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -abstract class Metadata extends Base +abstract class MetadataModel extends Base { /** * Get the table diff --git a/app/Model/Notification.php b/app/Model/NotificationModel.php index c252aa31..8937b77e 100644 --- a/app/Model/Notification.php +++ b/app/Model/NotificationModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Notification * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Notification extends Base +class NotificationModel extends Base { /** * Get the event title with author @@ -22,7 +24,7 @@ class Notification extends Base public function getTitleWithAuthor($event_author, $event_name, array $event_data) { switch ($event_name) { - case Task::EVENT_ASSIGNEE_CHANGE: + case TaskModel::EVENT_ASSIGNEE_CHANGE: $assignee = $event_data['task']['assignee_name'] ?: $event_data['task']['assignee_username']; if (! empty($assignee)) { @@ -30,22 +32,22 @@ class Notification extends Base } return e('%s remove the assignee of the task %s', $event_author, e('#%d', $event_data['task']['id'])); - case Task::EVENT_UPDATE: + case TaskModel::EVENT_UPDATE: return e('%s updated the task #%d', $event_author, $event_data['task']['id']); - case Task::EVENT_CREATE: + case TaskModel::EVENT_CREATE: return e('%s created the task #%d', $event_author, $event_data['task']['id']); - case Task::EVENT_CLOSE: + case TaskModel::EVENT_CLOSE: return e('%s closed the task #%d', $event_author, $event_data['task']['id']); - case Task::EVENT_OPEN: + case TaskModel::EVENT_OPEN: return e('%s open the task #%d', $event_author, $event_data['task']['id']); - case Task::EVENT_MOVE_COLUMN: + case TaskModel::EVENT_MOVE_COLUMN: return e( '%s moved the task #%d to the column "%s"', $event_author, $event_data['task']['id'], $event_data['task']['column_title'] ); - case Task::EVENT_MOVE_POSITION: + case TaskModel::EVENT_MOVE_POSITION: return e( '%s moved the task #%d to the position %d in the column "%s"', $event_author, @@ -53,7 +55,7 @@ class Notification extends Base $event_data['task']['position'], $event_data['task']['column_title'] ); - case Task::EVENT_MOVE_SWIMLANE: + case TaskModel::EVENT_MOVE_SWIMLANE: if ($event_data['task']['swimlane_id'] == 0) { return e('%s moved the task #%d to the first swimlane', $event_author, $event_data['task']['id']); } @@ -64,19 +66,19 @@ class Notification extends Base $event_data['task']['id'], $event_data['task']['swimlane_name'] ); - case Subtask::EVENT_UPDATE: + case SubtaskModel::EVENT_UPDATE: return e('%s updated a subtask for the task #%d', $event_author, $event_data['task']['id']); - case Subtask::EVENT_CREATE: + case SubtaskModel::EVENT_CREATE: return e('%s created a subtask for the task #%d', $event_author, $event_data['task']['id']); - case Comment::EVENT_UPDATE: + case CommentModel::EVENT_UPDATE: return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']); - case Comment::EVENT_CREATE: + case CommentModel::EVENT_CREATE: return e('%s commented on the task #%d', $event_author, $event_data['task']['id']); - case TaskFile::EVENT_CREATE: + case TaskFileModel::EVENT_CREATE: return e('%s attached a file to the task #%d', $event_author, $event_data['task']['id']); - case Task::EVENT_USER_MENTION: + case TaskModel::EVENT_USER_MENTION: return e('%s mentioned you in the task #%d', $event_author, $event_data['task']['id']); - case Comment::EVENT_USER_MENTION: + case CommentModel::EVENT_USER_MENTION: return e('%s mentioned you in a comment on the task #%d', $event_author, $event_data['task']['id']); default: return e('Notification'); @@ -94,38 +96,38 @@ class Notification extends Base public function getTitleWithoutAuthor($event_name, array $event_data) { switch ($event_name) { - case TaskFile::EVENT_CREATE: + case TaskFileModel::EVENT_CREATE: return e('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']); - case Comment::EVENT_CREATE: + case CommentModel::EVENT_CREATE: return e('New comment on task #%d', $event_data['comment']['task_id']); - case Comment::EVENT_UPDATE: + case CommentModel::EVENT_UPDATE: return e('Comment updated on task #%d', $event_data['comment']['task_id']); - case Subtask::EVENT_CREATE: + case SubtaskModel::EVENT_CREATE: return e('New subtask on task #%d', $event_data['subtask']['task_id']); - case Subtask::EVENT_UPDATE: + case SubtaskModel::EVENT_UPDATE: return e('Subtask updated on task #%d', $event_data['subtask']['task_id']); - case Task::EVENT_CREATE: + case TaskModel::EVENT_CREATE: return e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']); - case Task::EVENT_UPDATE: + case TaskModel::EVENT_UPDATE: return e('Task updated #%d', $event_data['task']['id']); - case Task::EVENT_CLOSE: + case TaskModel::EVENT_CLOSE: return e('Task #%d closed', $event_data['task']['id']); - case Task::EVENT_OPEN: + case TaskModel::EVENT_OPEN: return e('Task #%d opened', $event_data['task']['id']); - case Task::EVENT_MOVE_COLUMN: + case TaskModel::EVENT_MOVE_COLUMN: return e('Column changed for task #%d', $event_data['task']['id']); - case Task::EVENT_MOVE_POSITION: + case TaskModel::EVENT_MOVE_POSITION: return e('New position for task #%d', $event_data['task']['id']); - case Task::EVENT_MOVE_SWIMLANE: + case TaskModel::EVENT_MOVE_SWIMLANE: return e('Swimlane changed for task #%d', $event_data['task']['id']); - case Task::EVENT_ASSIGNEE_CHANGE: + case TaskModel::EVENT_ASSIGNEE_CHANGE: return e('Assignee changed on task #%d', $event_data['task']['id']); - case Task::EVENT_OVERDUE: + case TaskModel::EVENT_OVERDUE: $nb = count($event_data['tasks']); return $nb > 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']); - case Task::EVENT_USER_MENTION: + case TaskModel::EVENT_USER_MENTION: return e('You were mentioned in the task #%d', $event_data['task']['id']); - case Comment::EVENT_USER_MENTION: + case CommentModel::EVENT_USER_MENTION: return e('You were mentioned in a comment on the task #%d', $event_data['task']['id']); default: return e('Notification'); diff --git a/app/Model/NotificationType.php b/app/Model/NotificationTypeModel.php index 289aae9c..432832ee 100644 --- a/app/Model/NotificationType.php +++ b/app/Model/NotificationTypeModel.php @@ -3,6 +3,7 @@ namespace Kanboard\Model; use Pimple\Container; +use Kanboard\Core\Base; /** * Notification Type @@ -10,7 +11,7 @@ use Pimple\Container; * @package model * @author Frederic Guillot */ -abstract class NotificationType extends Base +abstract class NotificationTypeModel extends Base { /** * Container @@ -56,7 +57,7 @@ abstract class NotificationType extends Base * @param string $label * @param string $class * @param boolean $hidden - * @return NotificationType + * @return NotificationTypeModel */ public function setType($type, $label, $class, $hidden = false) { @@ -80,7 +81,7 @@ abstract class NotificationType extends Base * * @access public * @param string $type - * @return \Kanboard\Notification\NotificationInterface + * @return \Kanboard\Core\Notification\NotificationInterface */ public function getType($type) { diff --git a/app/Model/PasswordReset.php b/app/Model/PasswordResetModel.php index 5cfd3c97..d7c74969 100644 --- a/app/Model/PasswordReset.php +++ b/app/Model/PasswordResetModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Password Reset Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class PasswordReset extends Base +class PasswordResetModel extends Base { /** * SQL table name @@ -46,7 +48,7 @@ class PasswordReset extends Base */ public function create($username, $expiration = 0) { - $user_id = $this->db->table(User::TABLE)->eq('username', $username)->neq('email', '')->notNull('email')->findOneColumn('id'); + $user_id = $this->db->table(UserModel::TABLE)->eq('username', $username)->neq('email', '')->notNull('email')->findOneColumn('id'); if (! $user_id) { return false; diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivityModel.php index d993015b..380ea125 100644 --- a/app/Model/ProjectActivity.php +++ b/app/Model/ProjectActivityModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use PicoDb\Table; /** * Project activity model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectActivity extends Base +class ProjectActivityModel extends Base { /** * SQL table name @@ -62,17 +63,17 @@ class ProjectActivity extends Base { return $this ->db - ->table(ProjectActivity::TABLE) + ->table(ProjectActivityModel::TABLE) ->columns( - ProjectActivity::TABLE.'.*', + ProjectActivityModel::TABLE.'.*', 'uc.username AS author_username', 'uc.name AS author_name', 'uc.email', 'uc.avatar_path' ) - ->join(Task::TABLE, 'id', 'task_id') - ->join(Project::TABLE, 'id', 'project_id') - ->left(User::TABLE, 'uc', 'id', ProjectActivity::TABLE, 'creator_id'); + ->join(TaskModel::TABLE, 'id', 'task_id') + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->left(UserModel::TABLE, 'uc', 'id', ProjectActivityModel::TABLE, 'creator_id'); } /** diff --git a/app/Model/ProjectDailyColumnStats.php b/app/Model/ProjectDailyColumnStatsModel.php index 0706a110..a0f14cf4 100644 --- a/app/Model/ProjectDailyColumnStats.php +++ b/app/Model/ProjectDailyColumnStatsModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Project Daily Column Stats * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectDailyColumnStats extends Base +class ProjectDailyColumnStatsModel extends Base { /** * SQL table name @@ -84,7 +86,7 @@ class ProjectDailyColumnStats extends Base */ public function getAggregatedMetrics($project_id, $from, $to, $field = 'total') { - $columns = $this->column->getList($project_id); + $columns = $this->columnModel->getList($project_id); $metrics = $this->getMetrics($project_id, $from, $to); return $this->buildAggregate($metrics, $columns, $field); } @@ -205,10 +207,10 @@ class ProjectDailyColumnStats extends Base */ private function getScoreByColumns($project_id) { - $stats = $this->db->table(Task::TABLE) + $stats = $this->db->table(TaskModel::TABLE) ->columns('column_id', 'SUM(score) AS score') ->eq('project_id', $project_id) - ->eq('is_active', Task::STATUS_OPEN) + ->eq('is_active', TaskModel::STATUS_OPEN) ->notNull('score') ->groupBy('column_id') ->findAll(); @@ -225,7 +227,7 @@ class ProjectDailyColumnStats extends Base */ private function getTotalByColumns($project_id) { - $stats = $this->db->table(Task::TABLE) + $stats = $this->db->table(TaskModel::TABLE) ->columns('column_id', 'COUNT(*) AS total') ->eq('project_id', $project_id) ->in('is_active', $this->getTaskStatusConfig()) @@ -243,10 +245,10 @@ class ProjectDailyColumnStats extends Base */ private function getTaskStatusConfig() { - if ($this->config->get('cfd_include_closed_tasks') == 1) { - return array(Task::STATUS_OPEN, Task::STATUS_CLOSED); + if ($this->configModel->get('cfd_include_closed_tasks') == 1) { + return array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED); } - return array(Task::STATUS_OPEN); + return array(TaskModel::STATUS_OPEN); } } diff --git a/app/Model/ProjectDailyStats.php b/app/Model/ProjectDailyStatsModel.php index 974f5813..0754d263 100644 --- a/app/Model/ProjectDailyStats.php +++ b/app/Model/ProjectDailyStatsModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Project Daily Stats * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectDailyStats extends Base +class ProjectDailyStatsModel extends Base { /** * SQL table name diff --git a/app/Model/ProjectDuplication.php b/app/Model/ProjectDuplicationModel.php index 79011258..b67f8302 100644 --- a/app/Model/ProjectDuplication.php +++ b/app/Model/ProjectDuplicationModel.php @@ -2,16 +2,17 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Role; /** * Project Duplication * - * @package model + * @package Kanboard\Model * @author Frederic Guillot * @author Antonio Rabelo */ -class ProjectDuplication extends Base +class ProjectDuplicationModel extends Base { /** * Get list of optional models to duplicate @@ -21,7 +22,7 @@ class ProjectDuplication extends Base */ public function getOptionalSelection() { - return array('category', 'projectPermission', 'action', 'swimlane', 'task', 'projectMetadata'); + return array('categoryModel', 'projectPermissionModel', 'actionModel', 'swimlaneModel', 'taskModel', 'projectMetadataModel'); } /** @@ -32,7 +33,7 @@ class ProjectDuplication extends Base */ public function getPossibleSelection() { - return array('board', 'category', 'projectPermission', 'action', 'swimlane', 'task', 'projectMetadata'); + return array('boardModel', 'categoryModel', 'projectPermissionModel', 'actionModel', 'swimlaneModel', 'taskModel', 'projectMetadataModel'); } /** @@ -64,7 +65,7 @@ class ProjectDuplication extends Base * @param boolean $private Force the project to be private * @return integer Cloned Project Id */ - public function duplicate($src_project_id, $selection = array('projectPermission', 'category', 'action'), $owner_id = 0, $name = null, $private = null) + public function duplicate($src_project_id, $selection = array('projectPermissionModel', 'categoryModel', 'actionModel'), $owner_id = 0, $name = null, $private = null) { $this->db->startTransaction(); @@ -85,7 +86,7 @@ class ProjectDuplication extends Base } // Skip permissions for private projects - if ($private && $model === 'projectPermission') { + if ($private && $model === 'projectPermissionModel') { continue; } @@ -117,7 +118,7 @@ class ProjectDuplication extends Base */ private function copy($src_project_id, $owner_id = 0, $name = null, $private = null) { - $project = $this->project->getById($src_project_id); + $project = $this->projectModel->getById($src_project_id); $is_private = empty($project['is_private']) ? 0 : 1; $values = array( @@ -130,7 +131,7 @@ class ProjectDuplication extends Base 'owner_id' => $owner_id, ); - if (! $this->db->table(Project::TABLE)->save($values)) { + if (! $this->db->table(ProjectModel::TABLE)->save($values)) { return false; } @@ -148,9 +149,9 @@ class ProjectDuplication extends Base private function makeOwnerManager($dst_project_id, $owner_id) { if ($owner_id > 0) { - $this->projectUserRole->removeUser($dst_project_id, $owner_id); + $this->projectUserRoleModel->removeUser($dst_project_id, $owner_id); - if (! $this->projectUserRole->addUser($dst_project_id, $owner_id, Role::PROJECT_MANAGER)) { + if (! $this->projectUserRoleModel->addUser($dst_project_id, $owner_id, Role::PROJECT_MANAGER)) { return false; } } diff --git a/app/Model/ProjectFile.php b/app/Model/ProjectFile.php deleted file mode 100644 index aa9bf15b..00000000 --- a/app/Model/ProjectFile.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -namespace Kanboard\Model; - -/** - * Project File Model - * - * @package model - * @author Frederic Guillot - */ -class ProjectFile extends File -{ - /** - * SQL table name - * - * @var string - */ - const TABLE = 'project_has_files'; - - /** - * SQL foreign key - * - * @var string - */ - const FOREIGN_KEY = 'project_id'; - - /** - * Path prefix - * - * @var string - */ - const PATH_PREFIX = 'projects'; - - /** - * Events - * - * @var string - */ - const EVENT_CREATE = 'project.file.create'; -} diff --git a/app/Model/ProjectFileModel.php b/app/Model/ProjectFileModel.php new file mode 100644 index 00000000..b464bb2a --- /dev/null +++ b/app/Model/ProjectFileModel.php @@ -0,0 +1,74 @@ +<?php + +namespace Kanboard\Model; + +/** + * Project File Model + * + * @package Kanboard\Model + * @author Frederic Guillot + */ +class ProjectFileModel extends FileModel +{ + /** + * Table name + * + * @var string + */ + const TABLE = 'project_has_files'; + + /** + * Events + * + * @var string + */ + const EVENT_CREATE = 'project.file.create'; + + /** + * Get the table + * + * @abstract + * @access protected + * @return string + */ + protected function getTable() + { + return self::TABLE; + } + + /** + * Define the foreign key + * + * @abstract + * @access protected + * @return string + */ + protected function getForeignKey() + { + return 'project_id'; + } + + /** + * Define the path prefix + * + * @abstract + * @access protected + * @return string + */ + protected function getPathPrefix() + { + return 'projects'; + } + + /** + * Get event name + * + * @abstract + * @access protected + * @return string + */ + protected function getEventName() + { + return self::EVENT_CREATE; + } +} diff --git a/app/Model/ProjectGroupRole.php b/app/Model/ProjectGroupRoleModel.php index afad4a44..2729d5a6 100644 --- a/app/Model/ProjectGroupRole.php +++ b/app/Model/ProjectGroupRoleModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Role; /** * Project Group Role * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectGroupRole extends Base +class ProjectGroupRoleModel extends Base { /** * SQL table name @@ -27,15 +28,15 @@ class ProjectGroupRole extends Base * @param array $status * @return array */ - public function getProjectsByUser($user_id, $status = array(Project::ACTIVE, Project::INACTIVE)) + public function getProjectsByUser($user_id, $status = array(ProjectModel::ACTIVE, ProjectModel::INACTIVE)) { return $this->db - ->hashtable(Project::TABLE) + ->hashtable(ProjectModel::TABLE) ->join(self::TABLE, 'project_id', 'id') - ->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE) - ->eq(GroupMember::TABLE.'.user_id', $user_id) - ->in(Project::TABLE.'.is_active', $status) - ->getAll(Project::TABLE.'.id', Project::TABLE.'.name'); + ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', self::TABLE) + ->eq(GroupMemberModel::TABLE.'.user_id', $user_id) + ->in(ProjectModel::TABLE.'.is_active', $status) + ->getAll(ProjectModel::TABLE.'.id', ProjectModel::TABLE.'.name'); } /** @@ -49,8 +50,8 @@ class ProjectGroupRole extends Base public function getUserRole($project_id, $user_id) { $roles = $this->db->table(self::TABLE) - ->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE) - ->eq(GroupMember::TABLE.'.user_id', $user_id) + ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', self::TABLE) + ->eq(GroupMemberModel::TABLE.'.user_id', $user_id) ->eq(self::TABLE.'.project_id', $project_id) ->findAllByColumn('role'); @@ -67,8 +68,8 @@ class ProjectGroupRole extends Base public function getGroups($project_id) { return $this->db->table(self::TABLE) - ->columns(Group::TABLE.'.id', Group::TABLE.'.name', self::TABLE.'.role') - ->join(Group::TABLE, 'id', 'group_id') + ->columns(GroupModel::TABLE.'.id', GroupModel::TABLE.'.name', self::TABLE.'.role') + ->join(GroupModel::TABLE, 'id', 'group_id') ->eq('project_id', $project_id) ->asc('name') ->findAll(); @@ -84,11 +85,11 @@ class ProjectGroupRole extends Base public function getUsers($project_id) { return $this->db->table(self::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', self::TABLE.'.role') - ->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE) - ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', self::TABLE.'.role') + ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', self::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id', GroupMemberModel::TABLE) ->eq(self::TABLE.'.project_id', $project_id) - ->asc(User::TABLE.'.username') + ->asc(UserModel::TABLE.'.username') ->findAll(); } @@ -101,14 +102,14 @@ class ProjectGroupRole extends Base */ public function getAssignableUsers($project_id) { - return $this->db->table(User::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name') - ->join(GroupMember::TABLE, 'user_id', 'id', User::TABLE) - ->join(self::TABLE, 'group_id', 'group_id', GroupMember::TABLE) + return $this->db->table(UserModel::TABLE) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name') + ->join(GroupMemberModel::TABLE, 'user_id', 'id', UserModel::TABLE) + ->join(self::TABLE, 'group_id', 'group_id', GroupMemberModel::TABLE) ->eq(self::TABLE.'.project_id', $project_id) - ->eq(User::TABLE.'.is_active', 1) + ->eq(UserModel::TABLE.'.is_active', 1) ->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER)) - ->asc(User::TABLE.'.username') + ->asc(UserModel::TABLE.'.username') ->findAll(); } diff --git a/app/Model/ProjectMetadata.php b/app/Model/ProjectMetadataModel.php index 2b3aadf5..760acd7d 100644 --- a/app/Model/ProjectMetadata.php +++ b/app/Model/ProjectMetadataModel.php @@ -5,10 +5,10 @@ namespace Kanboard\Model; /** * Project Metadata * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectMetadata extends Metadata +class ProjectMetadataModel extends MetadataModel { /** * Get the table diff --git a/app/Model/Project.php b/app/Model/ProjectModel.php index 9843a54c..34e11c13 100644 --- a/app/Model/Project.php +++ b/app/Model/ProjectModel.php @@ -2,16 +2,17 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Token; use Kanboard\Core\Security\Role; /** * Project model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Project extends Base +class ProjectModel extends Base { /** * SQL table name for projects @@ -70,9 +71,9 @@ class Project extends Base public function getByIdWithOwner($project_id) { return $this->db->table(self::TABLE) - ->columns(self::TABLE.'.*', User::TABLE.'.username AS owner_username', User::TABLE.'.name AS owner_name') + ->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name') ->eq(self::TABLE.'.id', $project_id) - ->join(User::TABLE, 'id', 'owner_id') + ->join(UserModel::TABLE, 'id', 'owner_id') ->findOne(); } @@ -268,8 +269,8 @@ class Project extends Base { $stats = array(); $stats['nb_active_tasks'] = 0; - $columns = $this->column->getAll($project_id); - $column_stats = $this->board->getColumnStats($project_id); + $columns = $this->columnModel->getAll($project_id); + $column_stats = $this->boardModel->getColumnStats($project_id); foreach ($columns as &$column) { $column['nb_active_tasks'] = isset($column_stats[$column['id']]) ? $column_stats[$column['id']] : 0; @@ -277,7 +278,7 @@ class Project extends Base } $stats['columns'] = $columns; - $stats['nb_tasks'] = $this->taskFinder->countByProjectId($project_id); + $stats['nb_tasks'] = $this->taskFinderModel->countByProjectId($project_id); $stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks']; return $stats; @@ -292,8 +293,8 @@ class Project extends Base */ public function getColumnStats(array &$project) { - $project['columns'] = $this->column->getAll($project['id']); - $stats = $this->board->getColumnStats($project['id']); + $project['columns'] = $this->columnModel->getAll($project['id']); + $stats = $this->boardModel->getColumnStats($project['id']); foreach ($project['columns'] as &$column) { $column['nb_tasks'] = isset($stats[$column['id']]) ? $stats[$column['id']] : 0; @@ -328,13 +329,13 @@ class Project extends Base public function getQueryColumnStats(array $project_ids) { if (empty($project_ids)) { - return $this->db->table(Project::TABLE)->limit(0); + return $this->db->table(ProjectModel::TABLE)->limit(0); } return $this->db - ->table(Project::TABLE) - ->columns(self::TABLE.'.*', User::TABLE.'.username AS owner_username', User::TABLE.'.name AS owner_name') - ->join(User::TABLE, 'id', 'owner_id') + ->table(ProjectModel::TABLE) + ->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name') + ->join(UserModel::TABLE, 'id', 'owner_id') ->in(self::TABLE.'.id', $project_ids) ->callback(array($this, 'applyColumnStats')); } @@ -370,16 +371,16 @@ class Project extends Base $project_id = $this->db->getLastId(); - if (! $this->board->create($project_id, $this->board->getUserColumns())) { + if (! $this->boardModel->create($project_id, $this->boardModel->getUserColumns())) { $this->db->cancelTransaction(); return false; } if ($add_user && $user_id) { - $this->projectUserRole->addUser($project_id, $user_id, Role::PROJECT_MANAGER); + $this->projectUserRoleModel->addUser($project_id, $user_id, Role::PROJECT_MANAGER); } - $this->category->createDefaultCategories($project_id); + $this->categoryModel->createDefaultCategories($project_id); $this->db->closeTransaction(); diff --git a/app/Model/ProjectNotification.php b/app/Model/ProjectNotificationModel.php index a355902f..aeeee4cd 100644 --- a/app/Model/ProjectNotification.php +++ b/app/Model/ProjectNotificationModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Project Notification * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectNotification extends Base +class ProjectNotificationModel extends Base { /** * Send notifications @@ -20,15 +22,15 @@ class ProjectNotification extends Base */ public function sendNotifications($project_id, $event_name, array $event_data) { - $project = $this->project->getById($project_id); + $project = $this->projectModel->getById($project_id); $types = array_merge( - $this->projectNotificationType->getHiddenTypes(), - $this->projectNotificationType->getSelectedTypes($project_id) + $this->projectNotificationTypeModel->getHiddenTypes(), + $this->projectNotificationTypeModel->getSelectedTypes($project_id) ); foreach ($types as $type) { - $this->projectNotificationType->getType($type)->notifyProject($project, $event_name, $event_data); + $this->projectNotificationTypeModel->getType($type)->notifyProject($project, $event_name, $event_data); } } @@ -44,7 +46,7 @@ class ProjectNotification extends Base $this->db->startTransaction(); $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); - $this->projectNotificationType->saveSelectedTypes($project_id, $types); + $this->projectNotificationTypeModel->saveSelectedTypes($project_id, $types); $this->db->closeTransaction(); } @@ -59,7 +61,7 @@ class ProjectNotification extends Base public function readSettings($project_id) { return array( - 'notification_types' => $this->projectNotificationType->getSelectedTypes($project_id), + 'notification_types' => $this->projectNotificationTypeModel->getSelectedTypes($project_id), ); } } diff --git a/app/Model/ProjectNotificationType.php b/app/Model/ProjectNotificationTypeModel.php index a4719598..aeec77f2 100644 --- a/app/Model/ProjectNotificationType.php +++ b/app/Model/ProjectNotificationTypeModel.php @@ -5,10 +5,10 @@ namespace Kanboard\Model; /** * Project Notification Type * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectNotificationType extends NotificationType +class ProjectNotificationTypeModel extends NotificationTypeModel { /** * SQL table name diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermissionModel.php index 59af2b58..a7c1857c 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermissionModel.php @@ -2,6 +2,7 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Role; use Kanboard\Filter\ProjectGroupRoleProjectFilter; use Kanboard\Filter\ProjectGroupRoleUsernameFilter; @@ -11,10 +12,10 @@ use Kanboard\Filter\ProjectUserRoleUsernameFilter; /** * Project Permission * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectPermission extends Base +class ProjectPermissionModel extends Base { /** * Get query for project users overview @@ -32,18 +33,18 @@ class ProjectPermission extends Base return $this ->db - ->table(ProjectUserRole::TABLE) - ->join(User::TABLE, 'id', 'user_id') - ->join(Project::TABLE, 'id', 'project_id') - ->eq(ProjectUserRole::TABLE.'.role', $role) - ->eq(Project::TABLE.'.is_private', 0) - ->in(Project::TABLE.'.id', $project_ids) + ->table(ProjectUserRoleModel::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id') + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->eq(ProjectUserRoleModel::TABLE.'.role', $role) + ->eq(ProjectModel::TABLE.'.is_private', 0) + ->in(ProjectModel::TABLE.'.id', $project_ids) ->columns( - User::TABLE.'.id', - User::TABLE.'.username', - User::TABLE.'.name', - Project::TABLE.'.name AS project_name', - Project::TABLE.'.id' + UserModel::TABLE.'.id', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + ProjectModel::TABLE.'.name AS project_name', + ProjectModel::TABLE.'.id' ); } @@ -86,7 +87,7 @@ class ProjectPermission extends Base public function isEverybodyAllowed($project_id) { return $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $project_id) ->eq('is_everybody_allowed', 1) ->exists(); @@ -106,7 +107,7 @@ class ProjectPermission extends Base } return in_array( - $this->projectUserRole->getUserRole($project_id, $user_id), + $this->projectUserRoleModel->getUserRole($project_id, $user_id), array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER, Role::PROJECT_VIEWER) ); } @@ -121,8 +122,8 @@ class ProjectPermission extends Base */ public function isAssignable($project_id, $user_id) { - return $this->user->isActive($user_id) && - in_array($this->projectUserRole->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER)); + return $this->userModel->isActive($user_id) && + in_array($this->projectUserRoleModel->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER)); } /** @@ -135,7 +136,7 @@ class ProjectPermission extends Base */ public function isMember($project_id, $user_id) { - return in_array($this->projectUserRole->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER, Role::PROJECT_VIEWER)); + return in_array($this->projectUserRoleModel->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER, Role::PROJECT_VIEWER)); } /** @@ -147,7 +148,7 @@ class ProjectPermission extends Base */ public function getActiveProjectIds($user_id) { - return array_keys($this->projectUserRole->getActiveProjectsByUser($user_id)); + return array_keys($this->projectUserRoleModel->getActiveProjectsByUser($user_id)); } /** @@ -159,7 +160,7 @@ class ProjectPermission extends Base */ public function duplicate($project_src_id, $project_dst_id) { - return $this->projectUserRole->duplicate($project_src_id, $project_dst_id) && - $this->projectGroupRole->duplicate($project_src_id, $project_dst_id); + return $this->projectUserRoleModel->duplicate($project_src_id, $project_dst_id) && + $this->projectGroupRoleModel->duplicate($project_src_id, $project_dst_id); } } diff --git a/app/Model/ProjectUserRole.php b/app/Model/ProjectUserRoleModel.php index db26fd5f..a0df0cfa 100644 --- a/app/Model/ProjectUserRole.php +++ b/app/Model/ProjectUserRoleModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Role; /** * Project User Role * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class ProjectUserRole extends Base +class ProjectUserRoleModel extends Base { /** * SQL table name @@ -28,7 +29,7 @@ class ProjectUserRole extends Base */ public function getActiveProjectsByUser($user_id) { - return $this->getProjectsByUser($user_id, array(Project::ACTIVE)); + return $this->getProjectsByUser($user_id, array(ProjectModel::ACTIVE)); } /** @@ -39,19 +40,19 @@ class ProjectUserRole extends Base * @param array $status * @return array */ - public function getProjectsByUser($user_id, $status = array(Project::ACTIVE, Project::INACTIVE)) + public function getProjectsByUser($user_id, $status = array(ProjectModel::ACTIVE, ProjectModel::INACTIVE)) { $userProjects = $this->db - ->hashtable(Project::TABLE) + ->hashtable(ProjectModel::TABLE) ->beginOr() ->eq(self::TABLE.'.user_id', $user_id) - ->eq(Project::TABLE.'.is_everybody_allowed', 1) + ->eq(ProjectModel::TABLE.'.is_everybody_allowed', 1) ->closeOr() - ->in(Project::TABLE.'.is_active', $status) + ->in(ProjectModel::TABLE.'.is_active', $status) ->join(self::TABLE, 'project_id', 'id') - ->getAll(Project::TABLE.'.id', Project::TABLE.'.name'); + ->getAll(ProjectModel::TABLE.'.id', ProjectModel::TABLE.'.name'); - $groupProjects = $this->projectGroupRole->getProjectsByUser($user_id, $status); + $groupProjects = $this->projectGroupRoleModel->getProjectsByUser($user_id, $status); $projects = $userProjects + $groupProjects; asort($projects); @@ -69,7 +70,7 @@ class ProjectUserRole extends Base */ public function getUserRole($project_id, $user_id) { - $projectInfo = $this->db->table(Project::TABLE) + $projectInfo = $this->db->table(ProjectModel::TABLE) ->eq('id', $project_id) ->columns('owner_id', 'is_everybody_allowed') ->findOne(); @@ -81,7 +82,7 @@ class ProjectUserRole extends Base $role = $this->db->table(self::TABLE)->eq('user_id', $user_id)->eq('project_id', $project_id)->findOneColumn('role'); if (empty($role)) { - $role = $this->projectGroupRole->getUserRole($project_id, $user_id); + $role = $this->projectGroupRoleModel->getUserRole($project_id, $user_id); } return $role; @@ -97,11 +98,11 @@ class ProjectUserRole extends Base public function getUsers($project_id) { return $this->db->table(self::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', self::TABLE.'.role') - ->join(User::TABLE, 'id', 'user_id') + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', self::TABLE.'.role') + ->join(UserModel::TABLE, 'id', 'user_id') ->eq('project_id', $project_id) - ->asc(User::TABLE.'.username') - ->asc(User::TABLE.'.name') + ->asc(UserModel::TABLE.'.username') + ->asc(UserModel::TABLE.'.name') ->findAll(); } @@ -115,10 +116,10 @@ class ProjectUserRole extends Base public function getAllUsers($project_id) { $userMembers = $this->getUsers($project_id); - $groupMembers = $this->projectGroupRole->getUsers($project_id); + $groupMembers = $this->projectGroupRoleModel->getUsers($project_id); $members = array_merge($userMembers, $groupMembers); - return $this->user->prepareList($members); + return $this->userModel->prepareList($members); } /** @@ -133,7 +134,7 @@ class ProjectUserRole extends Base $users = array(); $userMembers = $this->getUsers($project_id); - $groupMembers = $this->projectGroupRole->getUsers($project_id); + $groupMembers = $this->projectGroupRoleModel->getUsers($project_id); $members = array_merge($userMembers, $groupMembers); foreach ($members as $user) { @@ -156,22 +157,22 @@ class ProjectUserRole extends Base */ public function getAssignableUsers($project_id) { - if ($this->projectPermission->isEverybodyAllowed($project_id)) { - return $this->user->getActiveUsersList(); + if ($this->projectPermissionModel->isEverybodyAllowed($project_id)) { + return $this->userModel->getActiveUsersList(); } $userMembers = $this->db->table(self::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name') - ->join(User::TABLE, 'id', 'user_id') - ->eq(User::TABLE.'.is_active', 1) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name') + ->join(UserModel::TABLE, 'id', 'user_id') + ->eq(UserModel::TABLE.'.is_active', 1) ->eq(self::TABLE.'.project_id', $project_id) ->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER)) ->findAll(); - $groupMembers = $this->projectGroupRole->getAssignableUsers($project_id); + $groupMembers = $this->projectGroupRoleModel->getAssignableUsers($project_id); $members = array_merge($userMembers, $groupMembers); - return $this->user->prepareList($members); + return $this->userModel->prepareList($members); } /** @@ -197,7 +198,7 @@ class ProjectUserRole extends Base } if ($everybody) { - $users = array(User::EVERYBODY_ID => t('Everybody')) + $users; + $users = array(UserModel::EVERYBODY_ID => t('Everybody')) + $users; } return $users; diff --git a/app/Model/RememberMeSession.php b/app/Model/RememberMeSessionModel.php index 8989a6d7..f6c8d648 100644 --- a/app/Model/RememberMeSession.php +++ b/app/Model/RememberMeSessionModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Security\Token; /** * Remember Me Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class RememberMeSession extends Base +class RememberMeSessionModel extends Base { /** * SQL table name diff --git a/app/Model/Setting.php b/app/Model/SettingModel.php index c5a4765c..5b2ee54f 100644 --- a/app/Model/Setting.php +++ b/app/Model/SettingModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Application Settings * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -abstract class Setting extends Base +abstract class SettingModel extends Base { /** * SQL table name diff --git a/app/Model/Subtask.php b/app/Model/SubtaskModel.php index e56796a0..019064ad 100644 --- a/app/Model/Subtask.php +++ b/app/Model/SubtaskModel.php @@ -3,15 +3,16 @@ namespace Kanboard\Model; use PicoDb\Database; +use Kanboard\Core\Base; use Kanboard\Event\SubtaskEvent; /** * Subtask Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Subtask extends Base +class SubtaskModel extends Base { /** * SQL table name @@ -95,20 +96,20 @@ class Subtask extends Base */ public function getUserQuery($user_id, array $status) { - return $this->db->table(Subtask::TABLE) + return $this->db->table(SubtaskModel::TABLE) ->columns( - Subtask::TABLE.'.*', - Task::TABLE.'.project_id', - Task::TABLE.'.color_id', - Task::TABLE.'.title AS task_name', - Project::TABLE.'.name AS project_name' + SubtaskModel::TABLE.'.*', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.color_id', + TaskModel::TABLE.'.title AS task_name', + ProjectModel::TABLE.'.name AS project_name' ) - ->subquery($this->subtaskTimeTracking->getTimerQuery($user_id), 'timer_start_date') + ->subquery($this->subtaskTimeTrackingModel->getTimerQuery($user_id), 'timer_start_date') ->eq('user_id', $user_id) - ->eq(Project::TABLE.'.is_active', Project::ACTIVE) - ->in(Subtask::TABLE.'.status', $status) - ->join(Task::TABLE, 'id', 'task_id') - ->join(Project::TABLE, 'id', 'project_id', Task::TABLE) + ->eq(ProjectModel::TABLE.'.is_active', ProjectModel::ACTIVE) + ->in(SubtaskModel::TABLE.'.status', $status) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->join(ProjectModel::TABLE, 'id', 'project_id', TaskModel::TABLE) ->callback(array($this, 'addStatusName')); } @@ -126,11 +127,11 @@ class Subtask extends Base ->eq('task_id', $task_id) ->columns( self::TABLE.'.*', - User::TABLE.'.username', - User::TABLE.'.name' + UserModel::TABLE.'.username', + UserModel::TABLE.'.name' ) - ->subquery($this->subtaskTimeTracking->getTimerQuery($this->userSession->getId()), 'timer_start_date') - ->join(User::TABLE, 'id', 'user_id') + ->subquery($this->subtaskTimeTrackingModel->getTimerQuery($this->userSession->getId()), 'timer_start_date') + ->join(UserModel::TABLE, 'id', 'user_id') ->asc(self::TABLE.'.position') ->callback(array($this, 'addStatusName')) ->findAll(); @@ -150,9 +151,9 @@ class Subtask extends Base return $this->db ->table(self::TABLE) ->eq(self::TABLE.'.id', $subtask_id) - ->columns(self::TABLE.'.*', User::TABLE.'.username', User::TABLE.'.name') - ->subquery($this->subtaskTimeTracking->getTimerQuery($this->userSession->getId()), 'timer_start_date') - ->join(User::TABLE, 'id', 'user_id') + ->columns(self::TABLE.'.*', UserModel::TABLE.'.username', UserModel::TABLE.'.name') + ->subquery($this->subtaskTimeTrackingModel->getTimerQuery($this->userSession->getId()), 'timer_start_date') + ->join(UserModel::TABLE, 'id', 'user_id') ->callback(array($this, 'addStatusName')) ->findOne(); } @@ -215,9 +216,9 @@ class Subtask extends Base public function create(array $values) { $this->prepareCreation($values); - $subtask_id = $this->persist(self::TABLE, $values); + $subtask_id = $this->db->table(self::TABLE)->persist($values); - if ($subtask_id) { + if ($subtask_id !== false) { $this->container['dispatcher']->dispatch( self::EVENT_CREATE, new SubtaskEvent(array('id' => $subtask_id) + $values) @@ -344,7 +345,7 @@ class Subtask extends Base */ public function hasSubtaskInProgress($user_id) { - return $this->config->get('subtask_restriction') == 1 && + return $this->configModel->get('subtask_restriction') == 1 && $this->db->table(self::TABLE) ->eq('status', self::STATUS_INPROGRESS) ->eq('user_id', $user_id) @@ -382,7 +383,7 @@ class Subtask extends Base { return $this->db->transaction(function (Database $db) use ($src_task_id, $dst_task_id) { - $subtasks = $db->table(Subtask::TABLE) + $subtasks = $db->table(SubtaskModel::TABLE) ->columns('title', 'time_estimated', 'position') ->eq('task_id', $src_task_id) ->asc('position') @@ -391,7 +392,7 @@ class Subtask extends Base foreach ($subtasks as &$subtask) { $subtask['task_id'] = $dst_task_id; - if (! $db->table(Subtask::TABLE)->save($subtask)) { + if (! $db->table(SubtaskModel::TABLE)->save($subtask)) { return false; } } @@ -410,7 +411,7 @@ class Subtask extends Base { $subtask = $this->getById($subtask_id); - $task_id = $this->taskCreation->create(array( + $task_id = $this->taskCreationModel->create(array( 'project_id' => $project_id, 'title' => $subtask['title'], 'time_estimated' => $subtask['time_estimated'], diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTrackingModel.php index be04ee1b..062e594a 100644 --- a/app/Model/SubtaskTimeTracking.php +++ b/app/Model/SubtaskTimeTrackingModel.php @@ -3,14 +3,15 @@ namespace Kanboard\Model; use DateTime; +use Kanboard\Core\Base; /** - * Subtask timesheet + * Subtask time tracking * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class SubtaskTimeTracking extends Base +class SubtaskTimeTrackingModel extends Base { /** * SQL table name @@ -36,7 +37,7 @@ class SubtaskTimeTracking extends Base $user_id, $this->db->escapeIdentifier('end'), $this->db->escapeIdentifier('subtask_id'), - Subtask::TABLE.'.id' + SubtaskModel::TABLE.'.id' ); } @@ -57,14 +58,14 @@ class SubtaskTimeTracking extends Base self::TABLE.'.end', self::TABLE.'.start', self::TABLE.'.time_spent', - Subtask::TABLE.'.task_id', - Subtask::TABLE.'.title AS subtask_title', - Task::TABLE.'.title AS task_title', - Task::TABLE.'.project_id', - Task::TABLE.'.color_id' + SubtaskModel::TABLE.'.task_id', + SubtaskModel::TABLE.'.title AS subtask_title', + TaskModel::TABLE.'.title AS task_title', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.color_id' ) - ->join(Subtask::TABLE, 'id', 'subtask_id') - ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) + ->join(SubtaskModel::TABLE, 'id', 'subtask_id') + ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE) ->eq(self::TABLE.'.user_id', $user_id); } @@ -86,16 +87,16 @@ class SubtaskTimeTracking extends Base self::TABLE.'.start', self::TABLE.'.time_spent', self::TABLE.'.user_id', - Subtask::TABLE.'.task_id', - Subtask::TABLE.'.title AS subtask_title', - Task::TABLE.'.project_id', - User::TABLE.'.username', - User::TABLE.'.name AS user_fullname' + SubtaskModel::TABLE.'.task_id', + SubtaskModel::TABLE.'.title AS subtask_title', + TaskModel::TABLE.'.project_id', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name AS user_fullname' ) - ->join(Subtask::TABLE, 'id', 'subtask_id') - ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) - ->join(User::TABLE, 'id', 'user_id', self::TABLE) - ->eq(Task::TABLE.'.id', $task_id); + ->join(SubtaskModel::TABLE, 'id', 'subtask_id') + ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id', self::TABLE) + ->eq(TaskModel::TABLE.'.id', $task_id); } /** @@ -116,17 +117,17 @@ class SubtaskTimeTracking extends Base self::TABLE.'.start', self::TABLE.'.time_spent', self::TABLE.'.user_id', - Subtask::TABLE.'.task_id', - Subtask::TABLE.'.title AS subtask_title', - Task::TABLE.'.project_id', - Task::TABLE.'.color_id', - User::TABLE.'.username', - User::TABLE.'.name AS user_fullname' + SubtaskModel::TABLE.'.task_id', + SubtaskModel::TABLE.'.title AS subtask_title', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.color_id', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name AS user_fullname' ) - ->join(Subtask::TABLE, 'id', 'subtask_id') - ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) - ->join(User::TABLE, 'id', 'user_id', self::TABLE) - ->eq(Task::TABLE.'.project_id', $project_id) + ->join(SubtaskModel::TABLE, 'id', 'subtask_id') + ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id', self::TABLE) + ->eq(TaskModel::TABLE.'.project_id', $project_id) ->asc(self::TABLE.'.id'); } @@ -249,10 +250,10 @@ class SubtaskTimeTracking extends Base */ public function updateSubtaskTimeSpent($subtask_id, $time_spent) { - $subtask = $this->subtask->getById($subtask_id); + $subtask = $this->subtaskModel->getById($subtask_id); // Fire the event subtask.update - return $this->subtask->update(array( + return $this->subtaskModel->update(array( 'id' => $subtask['id'], 'time_spent' => $subtask['time_spent'] + $time_spent, 'task_id' => $subtask['task_id'], @@ -271,7 +272,7 @@ class SubtaskTimeTracking extends Base $values = $this->calculateSubtaskTime($task_id); return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('id', $task_id) ->update($values); } @@ -286,7 +287,7 @@ class SubtaskTimeTracking extends Base public function calculateSubtaskTime($task_id) { return $this->db - ->table(Subtask::TABLE) + ->table(SubtaskModel::TABLE) ->eq('task_id', $task_id) ->columns( 'SUM(time_spent) AS time_spent', diff --git a/app/Model/Swimlane.php b/app/Model/SwimlaneModel.php index 721f20d3..87591b99 100644 --- a/app/Model/Swimlane.php +++ b/app/Model/SwimlaneModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Swimlanes * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Swimlane extends Base +class SwimlaneModel extends Base { /** * SQL table name @@ -97,7 +99,7 @@ class Swimlane extends Base public function getDefault($project_id) { $result = $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $project_id) ->columns('id', 'default_swimlane', 'show_default_swimlane') ->findOne(); @@ -167,7 +169,7 @@ class Swimlane extends Base ->findAll(); $default_swimlane = $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $project_id) ->eq('show_default_swimlane', 1) ->findOneColumn('default_swimlane'); @@ -195,7 +197,7 @@ class Swimlane extends Base public function getList($project_id, $prepend = false, $only_active = false) { $swimlanes = array(); - $default = $this->db->table(Project::TABLE)->eq('id', $project_id)->eq('show_default_swimlane', 1)->findOneColumn('default_swimlane'); + $default = $this->db->table(ProjectModel::TABLE)->eq('id', $project_id)->eq('show_default_swimlane', 1)->findOneColumn('default_swimlane'); if ($prepend) { $swimlanes[-1] = t('All swimlanes'); @@ -222,11 +224,12 @@ class Swimlane extends Base */ public function create($values) { - if (! $this->project->exists($values['project_id'])) { + if (! $this->projectModel->exists($values['project_id'])) { return 0; } + $values['position'] = $this->getLastPosition($values['project_id']); - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** @@ -254,7 +257,7 @@ class Swimlane extends Base public function updateDefault(array $values) { return $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $values['id']) ->update(array( 'default_swimlane' => $values['default_swimlane'], @@ -272,7 +275,7 @@ class Swimlane extends Base public function enableDefault($project_id) { return $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $project_id) ->update(array( 'show_default_swimlane' => 1, @@ -289,7 +292,7 @@ class Swimlane extends Base public function disableDefault($project_id) { return $this->db - ->table(Project::TABLE) + ->table(ProjectModel::TABLE) ->eq('id', $project_id) ->update(array( 'show_default_swimlane' => 0, @@ -370,7 +373,7 @@ class Swimlane extends Base $this->db->startTransaction(); // Tasks should not be assigned anymore to this swimlane - $this->db->table(Task::TABLE)->eq('swimlane_id', $swimlane_id)->update(array('swimlane_id' => 0)); + $this->db->table(TaskModel::TABLE)->eq('swimlane_id', $swimlane_id)->update(array('swimlane_id' => 0)); if (! $this->db->table(self::TABLE)->eq('id', $swimlane_id)->remove()) { $this->db->cancelTransaction(); diff --git a/app/Model/TaskAnalytic.php b/app/Model/TaskAnalyticModel.php index cff56744..3d6fe8a8 100644 --- a/app/Model/TaskAnalytic.php +++ b/app/Model/TaskAnalyticModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Task Analytic * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskAnalytic extends Base +class TaskAnalyticModel extends Base { /** * Get the time between date_creation and date_completed or now if empty @@ -48,8 +50,8 @@ class TaskAnalytic extends Base public function getTimeSpentByColumn(array $task) { $result = array(); - $columns = $this->column->getList($task['project_id']); - $sums = $this->transition->getTimeSpentByTask($task['id']); + $columns = $this->columnModel->getList($task['project_id']); + $sums = $this->transitionModel->getTimeSpentByTask($task['id']); foreach ($columns as $column_id => $column_title) { $time_spent = isset($sums[$column_id]) ? $sums[$column_id] : 0; diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreationModel.php index 2d2e5504..3800f831 100644 --- a/app/Model/TaskCreation.php +++ b/app/Model/TaskCreationModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\TaskEvent; /** * Task Creation * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskCreation extends Base +class TaskCreationModel extends Base { /** * Create a task @@ -21,18 +22,18 @@ class TaskCreation extends Base */ public function create(array $values) { - if (! $this->project->exists($values['project_id'])) { + if (! $this->projectModel->exists($values['project_id'])) { return 0; } $position = empty($values['position']) ? 0 : $values['position']; $this->prepare($values); - $task_id = $this->persist(Task::TABLE, $values); + $task_id = $this->db->table(TaskModel::TABLE)->persist($values); if ($task_id !== false) { if ($position > 0 && $values['position'] > 1) { - $this->taskPosition->movePosition($values['project_id'], $task_id, $values['column_id'], $position, $values['swimlane_id'], false); + $this->taskPositionModel->movePosition($values['project_id'], $task_id, $values['column_id'], $position, $values['swimlane_id'], false); } $this->fireEvents($task_id, $values); @@ -56,11 +57,11 @@ class TaskCreation extends Base $this->helper->model->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated')); if (empty($values['column_id'])) { - $values['column_id'] = $this->column->getFirstColumnId($values['project_id']); + $values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']); } if (empty($values['color_id'])) { - $values['color_id'] = $this->color->getDefaultColor(); + $values['color_id'] = $this->colorModel->getDefaultColor(); } if (empty($values['title'])) { @@ -75,7 +76,7 @@ class TaskCreation extends Base $values['date_creation'] = time(); $values['date_modification'] = $values['date_creation']; $values['date_moved'] = $values['date_creation']; - $values['position'] = $this->taskFinder->countByColumnAndSwimlaneId($values['project_id'], $values['column_id'], $values['swimlane_id']) + 1; + $values['position'] = $this->taskFinderModel->countByColumnAndSwimlaneId($values['project_id'], $values['column_id'], $values['swimlane_id']) + 1; } /** @@ -89,14 +90,14 @@ class TaskCreation extends Base { $event = new TaskEvent(array('task_id' => $task_id) + $values); - $this->logger->debug('Event fired: '.Task::EVENT_CREATE_UPDATE); - $this->logger->debug('Event fired: '.Task::EVENT_CREATE); + $this->logger->debug('Event fired: '.TaskModel::EVENT_CREATE_UPDATE); + $this->logger->debug('Event fired: '.TaskModel::EVENT_CREATE); - $this->dispatcher->dispatch(Task::EVENT_CREATE_UPDATE, $event); - $this->dispatcher->dispatch(Task::EVENT_CREATE, $event); + $this->dispatcher->dispatch(TaskModel::EVENT_CREATE_UPDATE, $event); + $this->dispatcher->dispatch(TaskModel::EVENT_CREATE, $event); if (! empty($values['description'])) { - $this->userMention->fireEvents($values['description'], Task::EVENT_USER_MENTION, $event); + $this->userMentionModel->fireEvents($values['description'], TaskModel::EVENT_USER_MENTION, $event); } } } diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplicationModel.php index ebdd4d29..9a4613e2 100644 --- a/app/Model/TaskDuplication.php +++ b/app/Model/TaskDuplicationModel.php @@ -4,15 +4,16 @@ namespace Kanboard\Model; use DateTime; use DateInterval; +use Kanboard\Core\Base; use Kanboard\Event\TaskEvent; /** * Task Duplication * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskDuplication extends Base +class TaskDuplicationModel extends Base { /** * Fields to copy when duplicating a task @@ -62,19 +63,19 @@ class TaskDuplication extends Base { $values = $this->copyFields($task_id); - if ($values['recurrence_status'] == Task::RECURRING_STATUS_PENDING) { + if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { $values['recurrence_parent'] = $task_id; - $values['column_id'] = $this->column->getFirstColumnId($values['project_id']); + $values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']); $this->calculateRecurringTaskDueDate($values); $recurring_task_id = $this->save($task_id, $values); if ($recurring_task_id > 0) { $parent_update = $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('id', $task_id) ->update(array( - 'recurrence_status' => Task::RECURRING_STATUS_PROCESSED, + 'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED, 'recurrence_child' => $recurring_task_id, )); @@ -127,22 +128,22 @@ class TaskDuplication extends Base */ public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) { - $task = $this->taskFinder->getById($task_id); + $task = $this->taskFinderModel->getById($task_id); $values = array(); $values['is_active'] = 1; $values['project_id'] = $project_id; $values['column_id'] = $column_id !== null ? $column_id : $task['column_id']; - $values['position'] = $this->taskFinder->countByColumnId($project_id, $values['column_id']) + 1; + $values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1; $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id']; $values['category_id'] = $category_id !== null ? $category_id : $task['category_id']; $values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id']; $this->checkDestinationProjectValues($values); - if ($this->db->table(Task::TABLE)->eq('id', $task['id'])->update($values)) { + if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) { $this->container['dispatcher']->dispatch( - Task::EVENT_MOVE_PROJECT, + TaskModel::EVENT_MOVE_PROJECT, new TaskEvent(array_merge($task, $values, array('task_id' => $task['id']))) ); } @@ -160,34 +161,34 @@ class TaskDuplication extends Base public function checkDestinationProjectValues(array &$values) { // Check if the assigned user is allowed for the destination project - if ($values['owner_id'] > 0 && ! $this->projectPermission->isUserAllowed($values['project_id'], $values['owner_id'])) { + if ($values['owner_id'] > 0 && ! $this->projectPermissionModel->isUserAllowed($values['project_id'], $values['owner_id'])) { $values['owner_id'] = 0; } // Check if the category exists for the destination project if ($values['category_id'] > 0) { - $values['category_id'] = $this->category->getIdByName( + $values['category_id'] = $this->categoryModel->getIdByName( $values['project_id'], - $this->category->getNameById($values['category_id']) + $this->categoryModel->getNameById($values['category_id']) ); } // Check if the swimlane exists for the destination project if ($values['swimlane_id'] > 0) { - $values['swimlane_id'] = $this->swimlane->getIdByName( + $values['swimlane_id'] = $this->swimlaneModel->getIdByName( $values['project_id'], - $this->swimlane->getNameById($values['swimlane_id']) + $this->swimlaneModel->getNameById($values['swimlane_id']) ); } // Check if the column exists for the destination project if ($values['column_id'] > 0) { - $values['column_id'] = $this->column->getColumnIdByTitle( + $values['column_id'] = $this->columnModel->getColumnIdByTitle( $values['project_id'], - $this->column->getColumnTitleById($values['column_id']) + $this->columnModel->getColumnTitleById($values['column_id']) ); - $values['column_id'] = $values['column_id'] ?: $this->column->getFirstColumnId($values['project_id']); + $values['column_id'] = $values['column_id'] ?: $this->columnModel->getFirstColumnId($values['project_id']); } return $values; @@ -202,7 +203,7 @@ class TaskDuplication extends Base public function calculateRecurringTaskDueDate(array &$values) { if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { - if ($values['recurrence_basedate'] == Task::RECURRING_BASEDATE_TRIGGERDATE) { + if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) { $values['date_due'] = time(); } @@ -210,10 +211,10 @@ class TaskDuplication extends Base $subtract = $values['recurrence_factor'] < 0; switch ($values['recurrence_timeframe']) { - case Task::RECURRING_TIMEFRAME_MONTHS: + case TaskModel::RECURRING_TIMEFRAME_MONTHS: $interval = 'P' . $factor . 'M'; break; - case Task::RECURRING_TIMEFRAME_YEARS: + case TaskModel::RECURRING_TIMEFRAME_YEARS: $interval = 'P' . $factor . 'Y'; break; default: @@ -238,7 +239,7 @@ class TaskDuplication extends Base */ private function copyFields($task_id) { - $task = $this->taskFinder->getById($task_id); + $task = $this->taskFinderModel->getById($task_id); $values = array(); foreach ($this->fields_to_duplicate as $field) { @@ -258,10 +259,10 @@ class TaskDuplication extends Base */ private function save($task_id, array $values) { - $new_task_id = $this->taskCreation->create($values); + $new_task_id = $this->taskCreationModel->create($values); if ($new_task_id) { - $this->subtask->duplicate($task_id, $new_task_id); + $this->subtaskModel->duplicate($task_id, $new_task_id); } return $new_task_id; diff --git a/app/Model/TaskExternalLink.php b/app/Model/TaskExternalLinkModel.php index f2c756b4..220b9c6f 100644 --- a/app/Model/TaskExternalLink.php +++ b/app/Model/TaskExternalLinkModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Task External Link Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskExternalLink extends Base +class TaskExternalLinkModel extends Base { /** * SQL table name @@ -29,10 +31,10 @@ class TaskExternalLink extends Base $types = $this->externalLinkManager->getTypes(); $links = $this->db->table(self::TABLE) - ->columns(self::TABLE.'.*', User::TABLE.'.name AS creator_name', User::TABLE.'.username AS creator_username') + ->columns(self::TABLE.'.*', UserModel::TABLE.'.name AS creator_name', UserModel::TABLE.'.username AS creator_username') ->eq('task_id', $task_id) ->asc('title') - ->join(User::TABLE, 'id', 'creator_id') + ->join(UserModel::TABLE, 'id', 'creator_id') ->findAll(); foreach ($links as &$link) { @@ -69,7 +71,7 @@ class TaskExternalLink extends Base $values['date_creation'] = time(); $values['date_modification'] = $values['date_creation']; - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** diff --git a/app/Model/TaskFile.php b/app/Model/TaskFile.php deleted file mode 100644 index 45a3b97f..00000000 --- a/app/Model/TaskFile.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Kanboard\Model; - -/** - * Task File Model - * - * @package model - * @author Frederic Guillot - */ -class TaskFile extends File -{ - /** - * SQL table name - * - * @var string - */ - const TABLE = 'task_has_files'; - - /** - * SQL foreign key - * - * @var string - */ - const FOREIGN_KEY = 'task_id'; - - /** - * Path prefix - * - * @var string - */ - const PATH_PREFIX = 'tasks'; - - /** - * Events - * - * @var string - */ - const EVENT_CREATE = 'task.file.create'; - - /** - * Handle screenshot upload - * - * @access public - * @param integer $task_id Task id - * @param string $blob Base64 encoded image - * @return bool|integer - */ - public function uploadScreenshot($task_id, $blob) - { - $original_filename = e('Screenshot taken %s', $this->helper->dt->datetime(time())).'.png'; - return $this->uploadContent($task_id, $original_filename, $blob); - } -} diff --git a/app/Model/TaskFileModel.php b/app/Model/TaskFileModel.php new file mode 100644 index 00000000..24c1ad4b --- /dev/null +++ b/app/Model/TaskFileModel.php @@ -0,0 +1,88 @@ +<?php + +namespace Kanboard\Model; + +/** + * Task File Model + * + * @package Kanboard\Model + * @author Frederic Guillot + */ +class TaskFileModel extends FileModel +{ + /** + * Table name + * + * @var string + */ + const TABLE = 'task_has_files'; + + /** + * Events + * + * @var string + */ + const EVENT_CREATE = 'task.file.create'; + + /** + * Get the table + * + * @abstract + * @access protected + * @return string + */ + protected function getTable() + { + return self::TABLE; + } + + /** + * Define the foreign key + * + * @abstract + * @access protected + * @return string + */ + protected function getForeignKey() + { + return 'task_id'; + } + + /** + * Define the path prefix + * + * @abstract + * @access protected + * @return string + */ + protected function getPathPrefix() + { + return 'tasks'; + } + + /** + * Get event name + * + * @abstract + * @access protected + * @return string + */ + protected function getEventName() + { + return self::EVENT_CREATE; + } + + /** + * Handle screenshot upload + * + * @access public + * @param integer $task_id Task id + * @param string $blob Base64 encoded image + * @return bool|integer + */ + public function uploadScreenshot($task_id, $blob) + { + $original_filename = e('Screenshot taken %s', $this->helper->dt->datetime(time())).'.png'; + return $this->uploadContent($task_id, $original_filename, $blob); + } +} diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinderModel.php index f8566bc2..8b636e28 100644 --- a/app/Model/TaskFinder.php +++ b/app/Model/TaskFinderModel.php @@ -3,14 +3,15 @@ namespace Kanboard\Model; use PDO; +use Kanboard\Core\Base; /** * Task Finder model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskFinder extends Base +class TaskFinderModel extends Base { /** * Get query for project user overview @@ -27,27 +28,27 @@ class TaskFinder extends Base } return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', - Task::TABLE.'.date_due', - Task::TABLE.'.date_started', - Task::TABLE.'.project_id', - Task::TABLE.'.color_id', - Task::TABLE.'.priority', - Task::TABLE.'.time_spent', - Task::TABLE.'.time_estimated', - Project::TABLE.'.name AS project_name', - Column::TABLE.'.title AS column_name', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name' + TaskModel::TABLE.'.id', + TaskModel::TABLE.'.title', + TaskModel::TABLE.'.date_due', + TaskModel::TABLE.'.date_started', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.color_id', + TaskModel::TABLE.'.priority', + TaskModel::TABLE.'.time_spent', + TaskModel::TABLE.'.time_estimated', + ProjectModel::TABLE.'.name AS project_name', + ColumnModel::TABLE.'.title AS column_name', + UserModel::TABLE.'.username AS assignee_username', + UserModel::TABLE.'.name AS assignee_name' ) - ->eq(Task::TABLE.'.is_active', $is_active) - ->in(Project::TABLE.'.id', $project_ids) - ->join(Project::TABLE, 'id', 'project_id') - ->join(Column::TABLE, 'id', 'column_id', Task::TABLE) - ->join(User::TABLE, 'id', 'owner_id', Task::TABLE); + ->eq(TaskModel::TABLE.'.is_active', $is_active) + ->in(ProjectModel::TABLE.'.id', $project_ids) + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->join(ColumnModel::TABLE, 'id', 'column_id', TaskModel::TABLE) + ->join(UserModel::TABLE, 'id', 'owner_id', TaskModel::TABLE); } /** @@ -60,7 +61,7 @@ class TaskFinder extends Base public function getUserQuery($user_id) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->columns( 'tasks.id', 'tasks.title', @@ -76,11 +77,11 @@ class TaskFinder extends Base 'projects.name AS project_name', 'columns.title AS column_title' ) - ->join(Project::TABLE, 'id', 'project_id') - ->join(Column::TABLE, 'id', 'column_id') - ->eq(Task::TABLE.'.owner_id', $user_id) - ->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN) - ->eq(Project::TABLE.'.is_active', Project::ACTIVE); + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->join(ColumnModel::TABLE, 'id', 'column_id') + ->eq(TaskModel::TABLE.'.owner_id', $user_id) + ->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN) + ->eq(ProjectModel::TABLE.'.is_active', ProjectModel::ACTIVE); } /** @@ -92,15 +93,15 @@ class TaskFinder extends Base public function getExtendedQuery() { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->columns( - '(SELECT COUNT(*) FROM '.Comment::TABLE.' WHERE task_id=tasks.id) AS nb_comments', - '(SELECT COUNT(*) FROM '.TaskFile::TABLE.' WHERE task_id=tasks.id) AS nb_files', - '(SELECT COUNT(*) FROM '.Subtask::TABLE.' WHERE '.Subtask::TABLE.'.task_id=tasks.id) AS nb_subtasks', - '(SELECT COUNT(*) FROM '.Subtask::TABLE.' WHERE '.Subtask::TABLE.'.task_id=tasks.id AND status=2) AS nb_completed_subtasks', - '(SELECT COUNT(*) FROM '.TaskLink::TABLE.' WHERE '.TaskLink::TABLE.'.task_id = tasks.id) AS nb_links', - '(SELECT COUNT(*) FROM '.TaskExternalLink::TABLE.' WHERE '.TaskExternalLink::TABLE.'.task_id = tasks.id) AS nb_external_links', - '(SELECT DISTINCT 1 FROM '.TaskLink::TABLE.' WHERE '.TaskLink::TABLE.'.task_id = tasks.id AND '.TaskLink::TABLE.'.link_id = 9) AS is_milestone', + '(SELECT COUNT(*) FROM '.CommentModel::TABLE.' WHERE task_id=tasks.id) AS nb_comments', + '(SELECT COUNT(*) FROM '.TaskFileModel::TABLE.' WHERE task_id=tasks.id) AS nb_files', + '(SELECT COUNT(*) FROM '.SubtaskModel::TABLE.' WHERE '.SubtaskModel::TABLE.'.task_id=tasks.id) AS nb_subtasks', + '(SELECT COUNT(*) FROM '.SubtaskModel::TABLE.' WHERE '.SubtaskModel::TABLE.'.task_id=tasks.id AND status=2) AS nb_completed_subtasks', + '(SELECT COUNT(*) FROM '.TaskLinkModel::TABLE.' WHERE '.TaskLinkModel::TABLE.'.task_id = tasks.id) AS nb_links', + '(SELECT COUNT(*) FROM '.TaskExternalLinkModel::TABLE.' WHERE '.TaskExternalLinkModel::TABLE.'.task_id = tasks.id) AS nb_external_links', + '(SELECT DISTINCT 1 FROM '.TaskLinkModel::TABLE.' WHERE '.TaskLinkModel::TABLE.'.task_id = tasks.id AND '.TaskLinkModel::TABLE.'.link_id = 9) AS is_milestone', 'tasks.id', 'tasks.reference', 'tasks.title', @@ -131,24 +132,24 @@ class TaskFinder extends Base 'tasks.recurrence_child', 'tasks.time_estimated', 'tasks.time_spent', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name', - User::TABLE.'.email AS assignee_email', - User::TABLE.'.avatar_path AS assignee_avatar_path', - Category::TABLE.'.name AS category_name', - Category::TABLE.'.description AS category_description', - Column::TABLE.'.title AS column_name', - Column::TABLE.'.position AS column_position', - Swimlane::TABLE.'.name AS swimlane_name', - Project::TABLE.'.default_swimlane', - Project::TABLE.'.name AS project_name' + UserModel::TABLE.'.username AS assignee_username', + UserModel::TABLE.'.name AS assignee_name', + UserModel::TABLE.'.email AS assignee_email', + UserModel::TABLE.'.avatar_path AS assignee_avatar_path', + CategoryModel::TABLE.'.name AS category_name', + CategoryModel::TABLE.'.description AS category_description', + ColumnModel::TABLE.'.title AS column_name', + ColumnModel::TABLE.'.position AS column_position', + SwimlaneModel::TABLE.'.name AS swimlane_name', + ProjectModel::TABLE.'.default_swimlane', + ProjectModel::TABLE.'.name AS project_name' ) - ->join(User::TABLE, 'id', 'owner_id', Task::TABLE) - ->left(User::TABLE, 'uc', 'id', Task::TABLE, 'creator_id') - ->join(Category::TABLE, 'id', 'category_id', Task::TABLE) - ->join(Column::TABLE, 'id', 'column_id', Task::TABLE) - ->join(Swimlane::TABLE, 'id', 'swimlane_id', Task::TABLE) - ->join(Project::TABLE, 'id', 'project_id', Task::TABLE); + ->join(UserModel::TABLE, 'id', 'owner_id', TaskModel::TABLE) + ->left(UserModel::TABLE, 'uc', 'id', TaskModel::TABLE, 'creator_id') + ->join(CategoryModel::TABLE, 'id', 'category_id', TaskModel::TABLE) + ->join(ColumnModel::TABLE, 'id', 'column_id', TaskModel::TABLE) + ->join(SwimlaneModel::TABLE, 'id', 'swimlane_id', TaskModel::TABLE) + ->join(ProjectModel::TABLE, 'id', 'project_id', TaskModel::TABLE); } /** @@ -163,11 +164,11 @@ class TaskFinder extends Base public function getTasksByColumnAndSwimlane($project_id, $column_id, $swimlane_id = 0) { return $this->getExtendedQuery() - ->eq(Task::TABLE.'.project_id', $project_id) - ->eq(Task::TABLE.'.column_id', $column_id) - ->eq(Task::TABLE.'.swimlane_id', $swimlane_id) - ->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN) - ->asc(Task::TABLE.'.position') + ->eq(TaskModel::TABLE.'.project_id', $project_id) + ->eq(TaskModel::TABLE.'.column_id', $column_id) + ->eq(TaskModel::TABLE.'.swimlane_id', $swimlane_id) + ->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN) + ->asc(TaskModel::TABLE.'.position') ->findAll(); } @@ -179,12 +180,12 @@ class TaskFinder extends Base * @param integer $status_id Status id * @return array */ - public function getAll($project_id, $status_id = Task::STATUS_OPEN) + public function getAll($project_id, $status_id = TaskModel::STATUS_OPEN) { return $this->db - ->table(Task::TABLE) - ->eq(Task::TABLE.'.project_id', $project_id) - ->eq(Task::TABLE.'.is_active', $status_id) + ->table(TaskModel::TABLE) + ->eq(TaskModel::TABLE.'.project_id', $project_id) + ->eq(TaskModel::TABLE.'.is_active', $status_id) ->findAll(); } @@ -196,12 +197,12 @@ class TaskFinder extends Base * @param array $status * @return array */ - public function getAllIds($project_id, array $status = array(Task::STATUS_OPEN)) + public function getAllIds($project_id, array $status = array(TaskModel::STATUS_OPEN)) { return $this->db - ->table(Task::TABLE) - ->eq(Task::TABLE.'.project_id', $project_id) - ->in(Task::TABLE.'.is_active', $status) + ->table(TaskModel::TABLE) + ->eq(TaskModel::TABLE.'.project_id', $project_id) + ->in(TaskModel::TABLE.'.is_active', $status) ->findAllByColumn('id'); } @@ -213,24 +214,24 @@ class TaskFinder extends Base */ public function getOverdueTasksQuery() { - return $this->db->table(Task::TABLE) + return $this->db->table(TaskModel::TABLE) ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', - Task::TABLE.'.date_due', - Task::TABLE.'.project_id', - Task::TABLE.'.creator_id', - Task::TABLE.'.owner_id', - Project::TABLE.'.name AS project_name', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name' + TaskModel::TABLE.'.id', + TaskModel::TABLE.'.title', + TaskModel::TABLE.'.date_due', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.creator_id', + TaskModel::TABLE.'.owner_id', + ProjectModel::TABLE.'.name AS project_name', + UserModel::TABLE.'.username AS assignee_username', + UserModel::TABLE.'.name AS assignee_name' ) - ->join(Project::TABLE, 'id', 'project_id') - ->join(User::TABLE, 'id', 'owner_id') - ->eq(Project::TABLE.'.is_active', 1) - ->eq(Task::TABLE.'.is_active', 1) - ->neq(Task::TABLE.'.date_due', 0) - ->lte(Task::TABLE.'.date_due', mktime(23, 59, 59)); + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->join(UserModel::TABLE, 'id', 'owner_id') + ->eq(ProjectModel::TABLE.'.is_active', 1) + ->eq(TaskModel::TABLE.'.is_active', 1) + ->neq(TaskModel::TABLE.'.date_due', 0) + ->lte(TaskModel::TABLE.'.date_due', mktime(23, 59, 59)); } /** @@ -253,7 +254,7 @@ class TaskFinder extends Base */ public function getOverdueTasksByProject($project_id) { - return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.project_id', $project_id)->findAll(); + return $this->getOverdueTasksQuery()->eq(TaskModel::TABLE.'.project_id', $project_id)->findAll(); } /** @@ -265,7 +266,7 @@ class TaskFinder extends Base */ public function getOverdueTasksByUser($user_id) { - return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.owner_id', $user_id)->findAll(); + return $this->getOverdueTasksQuery()->eq(TaskModel::TABLE.'.owner_id', $user_id)->findAll(); } /** @@ -277,7 +278,7 @@ class TaskFinder extends Base */ public function getProjectId($task_id) { - return (int) $this->db->table(Task::TABLE)->eq('id', $task_id)->findOneColumn('project_id') ?: 0; + return (int) $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOneColumn('project_id') ?: 0; } /** @@ -289,7 +290,7 @@ class TaskFinder extends Base */ public function getById($task_id) { - return $this->db->table(Task::TABLE)->eq('id', $task_id)->findOne(); + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOne(); } /** @@ -302,7 +303,7 @@ class TaskFinder extends Base */ public function getByReference($project_id, $reference) { - return $this->db->table(Task::TABLE)->eq('project_id', $project_id)->eq('reference', $reference)->findOne(); + return $this->db->table(TaskModel::TABLE)->eq('project_id', $project_id)->eq('reference', $reference)->findOne(); } /** @@ -377,11 +378,11 @@ class TaskFinder extends Base */ public function getICalQuery() { - return $this->db->table(Task::TABLE) - ->left(User::TABLE, 'ua', 'id', Task::TABLE, 'owner_id') - ->left(User::TABLE, 'uc', 'id', Task::TABLE, 'creator_id') + return $this->db->table(TaskModel::TABLE) + ->left(UserModel::TABLE, 'ua', 'id', TaskModel::TABLE, 'owner_id') + ->left(UserModel::TABLE, 'uc', 'id', TaskModel::TABLE, 'creator_id') ->columns( - Task::TABLE.'.*', + TaskModel::TABLE.'.*', 'ua.email AS assignee_email', 'ua.name AS assignee_name', 'ua.username AS assignee_username', @@ -398,10 +399,10 @@ class TaskFinder extends Base * @param array $status List of status id * @return integer */ - public function countByProjectId($project_id, array $status = array(Task::STATUS_OPEN, Task::STATUS_CLOSED)) + public function countByProjectId($project_id, array $status = array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('project_id', $project_id) ->in('is_active', $status) ->count(); @@ -418,7 +419,7 @@ class TaskFinder extends Base public function countByColumnId($project_id, $column_id) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('project_id', $project_id) ->eq('column_id', $column_id) ->eq('is_active', 1) @@ -437,7 +438,7 @@ class TaskFinder extends Base public function countByColumnAndSwimlaneId($project_id, $column_id, $swimlane_id) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('project_id', $project_id) ->eq('column_id', $column_id) ->eq('swimlane_id', $swimlane_id) @@ -454,7 +455,7 @@ class TaskFinder extends Base */ public function exists($task_id) { - return $this->db->table(Task::TABLE)->eq('id', $task_id)->exists(); + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->exists(); } /** @@ -467,9 +468,9 @@ class TaskFinder extends Base public function getProjectToken($task_id) { return $this->db - ->table(Task::TABLE) - ->eq(Task::TABLE.'.id', $task_id) - ->join(Project::TABLE, 'id', 'project_id') - ->findOneColumn(Project::TABLE.'.token'); + ->table(TaskModel::TABLE) + ->eq(TaskModel::TABLE.'.id', $task_id) + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->findOneColumn(ProjectModel::TABLE.'.token'); } } diff --git a/app/Model/TaskLink.php b/app/Model/TaskLinkModel.php index e46ea476..45225e35 100644 --- a/app/Model/TaskLink.php +++ b/app/Model/TaskLinkModel.php @@ -2,16 +2,17 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\TaskLinkEvent; /** * TaskLink model * - * @package model + * @package Kanboard\Model * @author Olivier Maridat * @author Frederic Guillot */ -class TaskLink extends Base +class TaskLinkModel extends Base { /** * SQL table name @@ -48,7 +49,7 @@ class TaskLink extends Base */ public function getOppositeTaskLink(array $task_link) { - $opposite_link_id = $this->link->getOppositeLinkId($task_link['link_id']); + $opposite_link_id = $this->linkModel->getOppositeLinkId($task_link['link_id']); return $this->db->table(self::TABLE) ->eq('opposite_task_id', $task_link['task_id']) @@ -71,31 +72,31 @@ class TaskLink extends Base ->columns( self::TABLE.'.id', self::TABLE.'.opposite_task_id AS task_id', - Link::TABLE.'.label', - Task::TABLE.'.title', - Task::TABLE.'.is_active', - Task::TABLE.'.project_id', - Task::TABLE.'.column_id', - Task::TABLE.'.color_id', - Task::TABLE.'.time_spent AS task_time_spent', - Task::TABLE.'.time_estimated AS task_time_estimated', - Task::TABLE.'.owner_id AS task_assignee_id', - User::TABLE.'.username AS task_assignee_username', - User::TABLE.'.name AS task_assignee_name', - Column::TABLE.'.title AS column_title', - Project::TABLE.'.name AS project_name' + LinkModel::TABLE.'.label', + TaskModel::TABLE.'.title', + TaskModel::TABLE.'.is_active', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.column_id', + TaskModel::TABLE.'.color_id', + TaskModel::TABLE.'.time_spent AS task_time_spent', + TaskModel::TABLE.'.time_estimated AS task_time_estimated', + TaskModel::TABLE.'.owner_id AS task_assignee_id', + UserModel::TABLE.'.username AS task_assignee_username', + UserModel::TABLE.'.name AS task_assignee_name', + ColumnModel::TABLE.'.title AS column_title', + ProjectModel::TABLE.'.name AS project_name' ) ->eq(self::TABLE.'.task_id', $task_id) - ->join(Link::TABLE, 'id', 'link_id') - ->join(Task::TABLE, 'id', 'opposite_task_id') - ->join(Column::TABLE, 'id', 'column_id', Task::TABLE) - ->join(User::TABLE, 'id', 'owner_id', Task::TABLE) - ->join(Project::TABLE, 'id', 'project_id', Task::TABLE) - ->asc(Link::TABLE.'.id') - ->desc(Column::TABLE.'.position') - ->desc(Task::TABLE.'.is_active') - ->asc(Task::TABLE.'.position') - ->asc(Task::TABLE.'.id') + ->join(LinkModel::TABLE, 'id', 'link_id') + ->join(TaskModel::TABLE, 'id', 'opposite_task_id') + ->join(ColumnModel::TABLE, 'id', 'column_id', TaskModel::TABLE) + ->join(UserModel::TABLE, 'id', 'owner_id', TaskModel::TABLE) + ->join(ProjectModel::TABLE, 'id', 'project_id', TaskModel::TABLE) + ->asc(LinkModel::TABLE.'.id') + ->desc(ColumnModel::TABLE.'.position') + ->desc(TaskModel::TABLE.'.is_active') + ->asc(TaskModel::TABLE.'.position') + ->asc(TaskModel::TABLE.'.id') ->findAll(); } @@ -131,7 +132,7 @@ class TaskLink extends Base private function fireEvents(array $events) { foreach ($events as $event) { - $event['project_id'] = $this->taskFinder->getProjectId($event['task_id']); + $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']); $this->container['dispatcher']->dispatch(self::EVENT_CREATE_UPDATE, new TaskLinkEvent($event)); } } @@ -151,7 +152,7 @@ class TaskLink extends Base $this->db->startTransaction(); // Get opposite link - $opposite_link_id = $this->link->getOppositeLinkId($link_id); + $opposite_link_id = $this->linkModel->getOppositeLinkId($link_id); $values = array( 'task_id' => $task_id, @@ -203,7 +204,7 @@ class TaskLink extends Base $opposite_task_link = $this->getOppositeTaskLink($task_link); // Get opposite link - $opposite_link_id = $this->link->getOppositeLinkId($link_id); + $opposite_link_id = $this->linkModel->getOppositeLinkId($link_id); // Update the original task link $values = array( @@ -247,7 +248,7 @@ class TaskLink extends Base $this->db->startTransaction(); $link = $this->getById($task_link_id); - $link_id = $this->link->getOppositeLinkId($link['link_id']); + $link_id = $this->linkModel->getOppositeLinkId($link['link_id']); $this->db->table(self::TABLE)->eq('id', $task_link_id)->remove(); diff --git a/app/Model/TaskMetadata.php b/app/Model/TaskMetadataModel.php index d9d024bf..dc3f56ec 100644 --- a/app/Model/TaskMetadata.php +++ b/app/Model/TaskMetadataModel.php @@ -5,10 +5,10 @@ namespace Kanboard\Model; /** * Task Metadata * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskMetadata extends Metadata +class TaskMetadataModel extends MetadataModel { /** * Get the table diff --git a/app/Model/Task.php b/app/Model/TaskModel.php index f8b41b9f..b0e7772a 100644 --- a/app/Model/Task.php +++ b/app/Model/TaskModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Task model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Task extends Base +class TaskModel extends Base { /** * SQL table name @@ -88,11 +90,11 @@ class Task extends Base */ public function remove($task_id) { - if (! $this->taskFinder->exists($task_id)) { + if (! $this->taskFinderModel->exists($task_id)) { return false; } - $this->taskFile->removeAll($task_id); + $this->taskFileModel->removeAll($task_id); return $this->db->table(self::TABLE)->eq('id', $task_id)->remove(); } @@ -124,8 +126,8 @@ class Task extends Base public function getRecurrenceStatusList() { return array( - Task::RECURRING_STATUS_NONE => t('No'), - Task::RECURRING_STATUS_PENDING => t('Yes'), + TaskModel::RECURRING_STATUS_NONE => t('No'), + TaskModel::RECURRING_STATUS_PENDING => t('Yes'), ); } @@ -138,9 +140,9 @@ class Task extends Base public function getRecurrenceTriggerList() { return array( - Task::RECURRING_TRIGGER_FIRST_COLUMN => t('When task is moved from first column'), - Task::RECURRING_TRIGGER_LAST_COLUMN => t('When task is moved to last column'), - Task::RECURRING_TRIGGER_CLOSE => t('When task is closed'), + TaskModel::RECURRING_TRIGGER_FIRST_COLUMN => t('When task is moved from first column'), + TaskModel::RECURRING_TRIGGER_LAST_COLUMN => t('When task is moved to last column'), + TaskModel::RECURRING_TRIGGER_CLOSE => t('When task is closed'), ); } @@ -153,8 +155,8 @@ class Task extends Base public function getRecurrenceBasedateList() { return array( - Task::RECURRING_BASEDATE_DUEDATE => t('Existing due date'), - Task::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'), + TaskModel::RECURRING_BASEDATE_DUEDATE => t('Existing due date'), + TaskModel::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'), ); } @@ -167,9 +169,9 @@ class Task extends Base public function getRecurrenceTimeframeList() { return array( - Task::RECURRING_TIMEFRAME_DAYS => t('Day(s)'), - Task::RECURRING_TIMEFRAME_MONTHS => t('Month(s)'), - Task::RECURRING_TIMEFRAME_YEARS => t('Year(s)'), + TaskModel::RECURRING_TIMEFRAME_DAYS => t('Day(s)'), + TaskModel::RECURRING_TIMEFRAME_MONTHS => t('Month(s)'), + TaskModel::RECURRING_TIMEFRAME_YEARS => t('Year(s)'), ); } @@ -210,10 +212,10 @@ class Task extends Base */ public function duplicate($src_project_id, $dst_project_id) { - $task_ids = $this->taskFinder->getAllIds($src_project_id, array(Task::STATUS_OPEN, Task::STATUS_CLOSED)); + $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); foreach ($task_ids as $task_id) { - if (! $this->taskDuplication->duplicateToProject($task_id, $dst_project_id)) { + if (! $this->taskDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { return false; } } diff --git a/app/Model/TaskModification.php b/app/Model/TaskModificationModel.php index a77b78a4..762af2c5 100644 --- a/app/Model/TaskModification.php +++ b/app/Model/TaskModificationModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\TaskEvent; /** * Task Modification * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskModification extends Base +class TaskModificationModel extends Base { /** * Update a task @@ -22,10 +23,10 @@ class TaskModification extends Base */ public function update(array $values, $fire_events = true) { - $original_task = $this->taskFinder->getById($values['id']); + $original_task = $this->taskFinderModel->getById($values['id']); $this->prepare($values); - $result = $this->db->table(Task::TABLE)->eq('id', $original_task['id'])->update($values); + $result = $this->db->table(TaskModel::TABLE)->eq('id', $original_task['id'])->update($values); if ($fire_events && $result) { $this->fireEvents($original_task, $values); @@ -51,10 +52,10 @@ class TaskModification extends Base unset($event_data['changes']['date_modification']); if ($this->isFieldModified('owner_id', $event_data['changes'])) { - $events[] = Task::EVENT_ASSIGNEE_CHANGE; + $events[] = TaskModel::EVENT_ASSIGNEE_CHANGE; } elseif (! empty($event_data['changes'])) { - $events[] = Task::EVENT_CREATE_UPDATE; - $events[] = Task::EVENT_UPDATE; + $events[] = TaskModel::EVENT_CREATE_UPDATE; + $events[] = TaskModel::EVENT_UPDATE; } foreach ($events as $event) { diff --git a/app/Model/TaskPosition.php b/app/Model/TaskPositionModel.php index 4c9928d7..9fdb8f7d 100644 --- a/app/Model/TaskPosition.php +++ b/app/Model/TaskPositionModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\TaskEvent; /** * Task Position * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskPosition extends Base +class TaskPositionModel extends Base { /** * Move a task to another column or to another position @@ -30,9 +31,9 @@ class TaskPosition extends Base return false; } - $task = $this->taskFinder->getById($task_id); + $task = $this->taskFinderModel->getById($task_id); - if ($task['is_active'] == Task::STATUS_CLOSED) { + if ($task['is_active'] == TaskModel::STATUS_CLOSED) { return true; } @@ -131,7 +132,7 @@ class TaskPosition extends Base */ private function saveTaskPositions($project_id, $task_id, $position, $column_id, $swimlane_id) { - $tasks_ids = $this->db->table(Task::TABLE) + $tasks_ids = $this->db->table(TaskModel::TABLE) ->eq('is_active', 1) ->eq('swimlane_id', $swimlane_id) ->eq('project_id', $project_id) @@ -168,7 +169,7 @@ class TaskPosition extends Base $now = time(); - return $this->db->table(Task::TABLE)->eq('id', $task_id)->update(array( + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(array( 'date_moved' => $now, 'date_modification' => $now, )); @@ -186,7 +187,7 @@ class TaskPosition extends Base */ private function saveTaskPosition($task_id, $position, $column_id, $swimlane_id) { - $result = $this->db->table(Task::TABLE)->eq('id', $task_id)->update(array( + $result = $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(array( 'position' => $position, 'column_id' => $column_id, 'swimlane_id' => $swimlane_id, @@ -225,14 +226,14 @@ class TaskPosition extends Base ); if ($task['swimlane_id'] != $new_swimlane_id) { - $this->logger->debug('Event fired: '.Task::EVENT_MOVE_SWIMLANE); - $this->dispatcher->dispatch(Task::EVENT_MOVE_SWIMLANE, new TaskEvent($event_data)); + $this->logger->debug('Event fired: '.TaskModel::EVENT_MOVE_SWIMLANE); + $this->dispatcher->dispatch(TaskModel::EVENT_MOVE_SWIMLANE, new TaskEvent($event_data)); } elseif ($task['column_id'] != $new_column_id) { - $this->logger->debug('Event fired: '.Task::EVENT_MOVE_COLUMN); - $this->dispatcher->dispatch(Task::EVENT_MOVE_COLUMN, new TaskEvent($event_data)); + $this->logger->debug('Event fired: '.TaskModel::EVENT_MOVE_COLUMN); + $this->dispatcher->dispatch(TaskModel::EVENT_MOVE_COLUMN, new TaskEvent($event_data)); } elseif ($task['position'] != $new_position) { - $this->logger->debug('Event fired: '.Task::EVENT_MOVE_POSITION); - $this->dispatcher->dispatch(Task::EVENT_MOVE_POSITION, new TaskEvent($event_data)); + $this->logger->debug('Event fired: '.TaskModel::EVENT_MOVE_POSITION); + $this->dispatcher->dispatch(TaskModel::EVENT_MOVE_POSITION, new TaskEvent($event_data)); } } } diff --git a/app/Model/TaskStatus.php b/app/Model/TaskStatusModel.php index ac35a96d..4d573f0e 100644 --- a/app/Model/TaskStatus.php +++ b/app/Model/TaskStatusModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\TaskEvent; /** * Task Status * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class TaskStatus extends Base +class TaskStatusModel extends Base { /** * Return true if the task is closed @@ -21,7 +22,7 @@ class TaskStatus extends Base */ public function isClosed($task_id) { - return $this->checkStatus($task_id, Task::STATUS_CLOSED); + return $this->checkStatus($task_id, TaskModel::STATUS_CLOSED); } /** @@ -33,7 +34,7 @@ class TaskStatus extends Base */ public function isOpen($task_id) { - return $this->checkStatus($task_id, Task::STATUS_OPEN); + return $this->checkStatus($task_id, TaskModel::STATUS_OPEN); } /** @@ -45,8 +46,8 @@ class TaskStatus extends Base */ public function close($task_id) { - $this->subtask->closeAll($task_id); - return $this->changeStatus($task_id, Task::STATUS_CLOSED, time(), Task::EVENT_CLOSE); + $this->subtaskModel->closeAll($task_id); + return $this->changeStatus($task_id, TaskModel::STATUS_CLOSED, time(), TaskModel::EVENT_CLOSE); } /** @@ -58,7 +59,7 @@ class TaskStatus extends Base */ public function open($task_id) { - return $this->changeStatus($task_id, Task::STATUS_OPEN, 0, Task::EVENT_OPEN); + return $this->changeStatus($task_id, TaskModel::STATUS_OPEN, 0, TaskModel::EVENT_OPEN); } /** @@ -84,10 +85,10 @@ class TaskStatus extends Base public function closeTasksBySwimlaneAndColumn($swimlane_id, $column_id) { $task_ids = $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('swimlane_id', $swimlane_id) ->eq('column_id', $column_id) - ->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN) + ->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN) ->findAllByColumn('id'); $this->closeMultipleTasks($task_ids); @@ -105,12 +106,12 @@ class TaskStatus extends Base */ private function changeStatus($task_id, $status, $date_completed, $event) { - if (! $this->taskFinder->exists($task_id)) { + if (! $this->taskFinderModel->exists($task_id)) { return false; } $result = $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('id', $task_id) ->update(array( 'is_active' => $status, @@ -120,7 +121,7 @@ class TaskStatus extends Base if ($result) { $this->logger->debug('Event fired: '.$event); - $this->dispatcher->dispatch($event, new TaskEvent(array('task_id' => $task_id) + $this->taskFinder->getById($task_id))); + $this->dispatcher->dispatch($event, new TaskEvent(array('task_id' => $task_id) + $this->taskFinderModel->getById($task_id))); } return $result; @@ -137,7 +138,7 @@ class TaskStatus extends Base private function checkStatus($task_id, $status) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->eq('id', $task_id) ->eq('is_active', $status) ->count() === 1; diff --git a/app/Model/Timezone.php b/app/Model/TimezoneModel.php index c6b33736..8b3e895a 100644 --- a/app/Model/Timezone.php +++ b/app/Model/TimezoneModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Class Timezone * * @package Kanboard\Model * @author Frederic Guillot */ -class Timezone extends Base +class TimezoneModel extends Base { /** * Get available timezones @@ -41,7 +43,7 @@ class Timezone extends Base return $this->sessionStorage->user['timezone']; } - return $this->config->get('application_timezone', 'UTC'); + return $this->configModel->get('application_timezone', 'UTC'); } /** diff --git a/app/Model/Transition.php b/app/Model/TransitionModel.php index 870d95fd..a4a58472 100644 --- a/app/Model/Transition.php +++ b/app/Model/TransitionModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * Transition * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class Transition extends Base +class TransitionModel extends Base { /** * SQL table name @@ -69,17 +71,17 @@ class Transition extends Base ->columns( 'src.title as src_column', 'dst.title as dst_column', - User::TABLE.'.name', - User::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.username', self::TABLE.'.user_id', self::TABLE.'.date', self::TABLE.'.time_spent' ) ->eq('task_id', $task_id) ->desc('date') - ->join(User::TABLE, 'id', 'user_id') - ->join(Column::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') - ->join(Column::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') + ->join(UserModel::TABLE, 'id', 'user_id') + ->join(ColumnModel::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') + ->join(ColumnModel::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') ->findAll(); } @@ -104,12 +106,12 @@ class Transition extends Base return $this->db->table(self::TABLE) ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', + TaskModel::TABLE.'.id', + TaskModel::TABLE.'.title', 'src.title as src_column', 'dst.title as dst_column', - User::TABLE.'.name', - User::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.username', self::TABLE.'.user_id', self::TABLE.'.date', self::TABLE.'.time_spent' @@ -119,10 +121,10 @@ class Transition extends Base ->eq(self::TABLE.'.project_id', $project_id) ->desc('date') ->desc(self::TABLE.'.id') - ->join(Task::TABLE, 'id', 'task_id') - ->join(User::TABLE, 'id', 'user_id') - ->join(Column::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') - ->join(Column::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') + ->join(TaskModel::TABLE, 'id', 'task_id') + ->join(UserModel::TABLE, 'id', 'user_id') + ->join(ColumnModel::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src') + ->join(ColumnModel::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst') ->findAll(); } } diff --git a/app/Model/UserLocking.php b/app/Model/UserLockingModel.php index 67e4c244..1d4d994c 100644 --- a/app/Model/UserLocking.php +++ b/app/Model/UserLockingModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * User Locking Model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserLocking extends Base +class UserLockingModel extends Base { /** * Get the number of failed login for the user @@ -19,7 +21,7 @@ class UserLocking extends Base */ public function getFailedLogin($username) { - return (int) $this->db->table(User::TABLE) + return (int) $this->db->table(UserModel::TABLE) ->eq('username', $username) ->findOneColumn('nb_failed_login'); } @@ -33,7 +35,7 @@ class UserLocking extends Base */ public function resetFailedLogin($username) { - return $this->db->table(User::TABLE) + return $this->db->table(UserModel::TABLE) ->eq('username', $username) ->update(array( 'nb_failed_login' => 0, @@ -50,7 +52,7 @@ class UserLocking extends Base */ public function incrementFailedLogin($username) { - return $this->db->table(User::TABLE) + return $this->db->table(UserModel::TABLE) ->eq('username', $username) ->increment('nb_failed_login', 1); } @@ -64,7 +66,7 @@ class UserLocking extends Base */ public function isLocked($username) { - return $this->db->table(User::TABLE) + return $this->db->table(UserModel::TABLE) ->eq('username', $username) ->neq('lock_expiration_date', 0) ->gte('lock_expiration_date', time()) @@ -81,7 +83,7 @@ class UserLocking extends Base */ public function lock($username, $duration = 15) { - return $this->db->table(User::TABLE) + return $this->db->table(UserModel::TABLE) ->eq('username', $username) ->update(array( 'lock_expiration_date' => time() + $duration * 60 diff --git a/app/Model/UserMention.php b/app/Model/UserMentionModel.php index 97a4e419..cdb9949e 100644 --- a/app/Model/UserMention.php +++ b/app/Model/UserMentionModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Event\GenericEvent; /** * User Mention * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserMention extends Base +class UserMentionModel extends Base { /** * Get list of mentioned users @@ -24,7 +25,7 @@ class UserMention extends Base $users = array(); if (preg_match_all('/@([^\s]+)/', $content, $matches)) { - $users = $this->db->table(User::TABLE) + $users = $this->db->table(UserModel::TABLE) ->columns('id', 'username', 'name', 'email', 'language') ->eq('notifications_enabled', 1) ->neq('id', $this->userSession->getId()) @@ -46,13 +47,13 @@ class UserMention extends Base public function fireEvents($content, $eventName, GenericEvent $event) { if (empty($event['project_id'])) { - $event['project_id'] = $this->taskFinder->getProjectId($event['task_id']); + $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']); } $users = $this->getMentionedUsers($content); foreach ($users as $user) { - if ($this->projectPermission->isMember($event['project_id'], $user['id'])) { + if ($this->projectPermissionModel->isMember($event['project_id'], $user['id'])) { $event['mention'] = $user; $this->dispatcher->dispatch($eventName, $event); } diff --git a/app/Model/UserMetadata.php b/app/Model/UserMetadataModel.php index 8b880756..e931d3ba 100644 --- a/app/Model/UserMetadata.php +++ b/app/Model/UserMetadataModel.php @@ -5,10 +5,10 @@ namespace Kanboard\Model; /** * User Metadata * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserMetadata extends Metadata +class UserMetadataModel extends MetadataModel { /** * Get the table diff --git a/app/Model/User.php b/app/Model/UserModel.php index 6dd78dbb..f7a051c5 100644 --- a/app/Model/User.php +++ b/app/Model/UserModel.php @@ -3,16 +3,17 @@ namespace Kanboard\Model; use PicoDb\Database; +use Kanboard\Core\Base; use Kanboard\Core\Security\Token; use Kanboard\Core\Security\Role; /** * User model * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class User extends Base +class UserModel extends Base { /** * SQL table name @@ -85,7 +86,7 @@ class User extends Base { return $this->userSession->isAdmin() || // Avoid SQL query if connected $this->db - ->table(User::TABLE) + ->table(UserModel::TABLE) ->eq('id', $user_id) ->eq('role', Role::APP_ADMIN) ->exists(); @@ -211,7 +212,7 @@ class User extends Base $listing = $this->prepareList($users); if ($prepend) { - return array(User::EVERYBODY_ID => t('Everybody')) + $listing; + return array(UserModel::EVERYBODY_ID => t('Everybody')) + $listing; } return $listing; @@ -269,7 +270,7 @@ class User extends Base public function create(array $values) { $this->prepare($values); - return $this->persist(self::TABLE, $values); + return $this->db->table(self::TABLE)->persist($values); } /** @@ -320,38 +321,38 @@ class User extends Base */ public function remove($user_id) { - $this->avatarFile->remove($user_id); + $this->avatarFileModel->remove($user_id); return $this->db->transaction(function (Database $db) use ($user_id) { // All assigned tasks are now unassigned (no foreign key) - if (! $db->table(Task::TABLE)->eq('owner_id', $user_id)->update(array('owner_id' => 0))) { + if (! $db->table(TaskModel::TABLE)->eq('owner_id', $user_id)->update(array('owner_id' => 0))) { return false; } // All assigned subtasks are now unassigned (no foreign key) - if (! $db->table(Subtask::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) { + if (! $db->table(SubtaskModel::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) { return false; } // All comments are not assigned anymore (no foreign key) - if (! $db->table(Comment::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) { + if (! $db->table(CommentModel::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) { return false; } // All private projects are removed - $project_ids = $db->table(Project::TABLE) + $project_ids = $db->table(ProjectModel::TABLE) ->eq('is_private', 1) - ->eq(ProjectUserRole::TABLE.'.user_id', $user_id) - ->join(ProjectUserRole::TABLE, 'project_id', 'id') - ->findAllByColumn(Project::TABLE.'.id'); + ->eq(ProjectUserRoleModel::TABLE.'.user_id', $user_id) + ->join(ProjectUserRoleModel::TABLE, 'project_id', 'id') + ->findAllByColumn(ProjectModel::TABLE.'.id'); if (! empty($project_ids)) { - $db->table(Project::TABLE)->in('id', $project_ids)->remove(); + $db->table(ProjectModel::TABLE)->in('id', $project_ids)->remove(); } // Finally remove the user - if (! $db->table(User::TABLE)->eq('id', $user_id)->remove()) { + if (! $db->table(UserModel::TABLE)->eq('id', $user_id)->remove()) { return false; } }); diff --git a/app/Model/UserNotificationFilter.php b/app/Model/UserNotificationFilterModel.php index 780ddfc7..112ba290 100644 --- a/app/Model/UserNotificationFilter.php +++ b/app/Model/UserNotificationFilterModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * User Notification Filter * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserNotificationFilter extends Base +class UserNotificationFilterModel extends Base { /** * SQL table name @@ -52,7 +54,7 @@ class UserNotificationFilter extends Base */ public function getSelectedFilter($user_id) { - return $this->db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); } /** @@ -65,7 +67,7 @@ class UserNotificationFilter extends Base */ public function saveFilter($user_id, $filter) { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array( 'notifications_filter' => $filter, )); } diff --git a/app/Model/UserNotification.php b/app/Model/UserNotificationModel.php index 6882e671..d77526f6 100644 --- a/app/Model/UserNotification.php +++ b/app/Model/UserNotificationModel.php @@ -2,15 +2,16 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; use Kanboard\Core\Translator; /** * User Notification * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserNotification extends Base +class UserNotificationModel extends Base { /** * Send notifications to people @@ -24,7 +25,7 @@ class UserNotification extends Base $users = $this->getUsersWithNotificationEnabled($event_data['task']['project_id'], $this->userSession->getId()); foreach ($users as $user) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, $event_data)) { + if ($this->userNotificationFilterModel->shouldReceiveNotification($user, $event_data)) { $this->sendUserNotification($user, $event_name, $event_data); } } @@ -46,15 +47,15 @@ class UserNotification extends Base if (! empty($user['language'])) { Translator::load($user['language']); } else { - Translator::load($this->config->get('application_language', 'en_US')); + Translator::load($this->configModel->get('application_language', 'en_US')); } - foreach ($this->userNotificationType->getSelectedTypes($user['id']) as $type) { - $this->userNotificationType->getType($type)->notifyUser($user, $event_name, $event_data); + foreach ($this->userNotificationTypeModel->getSelectedTypes($user['id']) as $type) { + $this->userNotificationTypeModel->getType($type)->notifyUser($user, $event_name, $event_data); } // Restore locales - $this->language->loadCurrentLanguage(); + $this->languageModel->loadCurrentLanguage(); } /** @@ -67,7 +68,7 @@ class UserNotification extends Base */ public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) { - if ($this->projectPermission->isEverybodyAllowed($project_id)) { + if ($this->projectPermissionModel->isEverybodyAllowed($project_id)) { return $this->getEverybodyWithNotificationEnabled($exclude_user_id); } @@ -93,7 +94,7 @@ class UserNotification extends Base */ public function enableNotification($user_id) { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 1)); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 1)); } /** @@ -105,7 +106,7 @@ class UserNotification extends Base */ public function disableNotification($user_id) { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 0)); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 0)); } /** @@ -125,12 +126,12 @@ class UserNotification extends Base $this->disableNotification($user_id); } - $filter = empty($values['notifications_filter']) ? UserNotificationFilter::FILTER_BOTH : $values['notifications_filter']; + $filter = empty($values['notifications_filter']) ? UserNotificationFilterModel::FILTER_BOTH : $values['notifications_filter']; $project_ids = empty($values['notification_projects']) ? array() : array_keys($values['notification_projects']); - $this->userNotificationFilter->saveFilter($user_id, $filter); - $this->userNotificationFilter->saveSelectedProjects($user_id, $project_ids); - $this->userNotificationType->saveSelectedTypes($user_id, $types); + $this->userNotificationFilterModel->saveFilter($user_id, $filter); + $this->userNotificationFilterModel->saveSelectedProjects($user_id, $project_ids); + $this->userNotificationTypeModel->saveSelectedTypes($user_id, $types); } /** @@ -142,9 +143,9 @@ class UserNotification extends Base */ public function readSettings($user_id) { - $values = $this->db->table(User::TABLE)->eq('id', $user_id)->columns('notifications_enabled', 'notifications_filter')->findOne(); - $values['notification_types'] = $this->userNotificationType->getSelectedTypes($user_id); - $values['notification_projects'] = $this->userNotificationFilter->getSelectedProjects($user_id); + $values = $this->db->table(UserModel::TABLE)->eq('id', $user_id)->columns('notifications_enabled', 'notifications_filter')->findOne(); + $values['notification_types'] = $this->userNotificationTypeModel->getSelectedTypes($user_id); + $values['notification_projects'] = $this->userNotificationFilterModel->getSelectedProjects($user_id); return $values; } @@ -159,27 +160,27 @@ class UserNotification extends Base private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id) { return $this->db - ->table(ProjectUserRole::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') - ->join(User::TABLE, 'id', 'user_id') - ->eq(ProjectUserRole::TABLE.'.project_id', $project_id) - ->eq(User::TABLE.'.notifications_enabled', '1') - ->eq(User::TABLE.'.is_active', 1) - ->neq(User::TABLE.'.id', $exclude_user_id) + ->table(ProjectUserRoleModel::TABLE) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter') + ->join(UserModel::TABLE, 'id', 'user_id') + ->eq(ProjectUserRoleModel::TABLE.'.project_id', $project_id) + ->eq(UserModel::TABLE.'.notifications_enabled', '1') + ->eq(UserModel::TABLE.'.is_active', 1) + ->neq(UserModel::TABLE.'.id', $exclude_user_id) ->findAll(); } private function getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id) { return $this->db - ->table(ProjectGroupRole::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') - ->join(GroupMember::TABLE, 'group_id', 'group_id', ProjectGroupRole::TABLE) - ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE) - ->eq(ProjectGroupRole::TABLE.'.project_id', $project_id) - ->eq(User::TABLE.'.notifications_enabled', '1') - ->neq(User::TABLE.'.id', $exclude_user_id) - ->eq(User::TABLE.'.is_active', 1) + ->table(ProjectGroupRoleModel::TABLE) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter') + ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', ProjectGroupRoleModel::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id', GroupMemberModel::TABLE) + ->eq(ProjectGroupRoleModel::TABLE.'.project_id', $project_id) + ->eq(UserModel::TABLE.'.notifications_enabled', '1') + ->neq(UserModel::TABLE.'.id', $exclude_user_id) + ->eq(UserModel::TABLE.'.is_active', 1) ->findAll(); } @@ -193,11 +194,11 @@ class UserNotification extends Base private function getEverybodyWithNotificationEnabled($exclude_user_id) { return $this->db - ->table(User::TABLE) - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') + ->table(UserModel::TABLE) + ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter') ->eq('notifications_enabled', '1') - ->neq(User::TABLE.'.id', $exclude_user_id) - ->eq(User::TABLE.'.is_active', 1) + ->neq(UserModel::TABLE.'.id', $exclude_user_id) + ->eq(UserModel::TABLE.'.is_active', 1) ->findAll(); } } diff --git a/app/Model/UserNotificationType.php b/app/Model/UserNotificationTypeModel.php index 89beb480..0f377220 100644 --- a/app/Model/UserNotificationType.php +++ b/app/Model/UserNotificationTypeModel.php @@ -5,10 +5,10 @@ namespace Kanboard\Model; /** * User Notification Type * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserNotificationType extends NotificationType +class UserNotificationTypeModel extends NotificationTypeModel { /** * SQL table name diff --git a/app/Model/UserUnreadNotification.php b/app/Model/UserUnreadNotificationModel.php index cc0f326a..6c930eef 100644 --- a/app/Model/UserUnreadNotification.php +++ b/app/Model/UserUnreadNotificationModel.php @@ -2,13 +2,15 @@ namespace Kanboard\Model; +use Kanboard\Core\Base; + /** * User Unread Notification * - * @package model + * @package Kanboard\Model * @author Frederic Guillot */ -class UserUnreadNotification extends Base +class UserUnreadNotificationModel extends Base { /** * SQL table name @@ -36,6 +38,23 @@ class UserUnreadNotification extends Base } /** + * Get one notification + * + * @param integer $notification_id + * @return array|null + */ + public function getById($notification_id) + { + $notification = $this->db->table(self::TABLE)->eq('id', $notification_id)->findOne(); + + if (! empty($notification)) { + $this->unserialize($notification); + } + + return $notification; + } + + /** * Get all notifications for a user * * @access public @@ -47,8 +66,7 @@ class UserUnreadNotification extends Base $events = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('date_creation')->findAll(); foreach ($events as &$event) { - $event['event_data'] = json_decode($event['event_data'], true); - $event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']); + $this->unserialize($event); } return $events; @@ -90,4 +108,10 @@ class UserUnreadNotification extends Base { return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists(); } + + private function unserialize(&$event) + { + $event['event_data'] = json_decode($event['event_data'], true); + $event['title'] = $this->notificationModel->getTitleWithoutAuthor($event['event_name'], $event['event_data']); + } } |