From 14713b0ec7ed93ca45578da069ad4e19a7d8addf Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 19:48:22 -0400 Subject: Rename all models --- app/Action/CommentCreation.php | 4 +- app/Action/CommentCreationMoveTaskColumn.php | 8 +- app/Action/TaskAssignCategoryColor.php | 6 +- app/Action/TaskAssignCategoryLabel.php | 2 +- app/Action/TaskAssignCategoryLink.php | 8 +- app/Action/TaskAssignColorCategory.php | 6 +- app/Action/TaskAssignColorColumn.php | 8 +- app/Action/TaskAssignColorLink.php | 6 +- app/Action/TaskAssignColorPriority.php | 6 +- app/Action/TaskAssignColorUser.php | 8 +- app/Action/TaskAssignCurrentUser.php | 6 +- app/Action/TaskAssignCurrentUserColumn.php | 6 +- app/Action/TaskAssignSpecificUser.php | 8 +- app/Action/TaskAssignUser.php | 4 +- app/Action/TaskClose.php | 2 +- app/Action/TaskCloseColumn.php | 6 +- app/Action/TaskCloseNoActivity.php | 6 +- app/Action/TaskCreation.php | 2 +- app/Action/TaskDuplicateAnotherProject.php | 10 +- app/Action/TaskEmail.php | 12 +- app/Action/TaskEmailNoActivity.php | 10 +- app/Action/TaskMoveAnotherProject.php | 8 +- app/Action/TaskMoveColumnAssigned.php | 10 +- app/Action/TaskMoveColumnCategoryChange.php | 8 +- app/Action/TaskMoveColumnUnAssigned.php | 10 +- app/Action/TaskOpen.php | 2 +- app/Action/TaskUpdateStartDate.php | 6 +- app/Analytic/AverageLeadCycleTimeAnalytic.php | 4 +- app/Analytic/AverageTimeSpentColumnAnalytic.php | 8 +- app/Analytic/EstimatedTimeComparisonAnalytic.php | 6 +- app/Analytic/TaskDistributionAnalytic.php | 4 +- app/Analytic/UserDistributionAnalytic.php | 4 +- app/Api/ActionApi.php | 6 +- app/Api/AppApi.php | 8 +- app/Api/AuthApi.php | 6 +- app/Api/BaseApi.php | 6 +- app/Api/BoardApi.php | 2 +- app/Api/CategoryApi.php | 10 +- app/Api/ColumnApi.php | 12 +- app/Api/CommentApi.php | 10 +- app/Api/FileApi.php | 12 +- app/Api/GroupApi.php | 10 +- app/Api/GroupMemberApi.php | 10 +- app/Api/LinkApi.php | 14 +- app/Api/MeApi.php | 22 +- app/Api/ProjectApi.php | 20 +- app/Api/ProjectPermissionApi.php | 16 +- app/Api/SubtaskApi.php | 10 +- app/Api/SwimlaneApi.php | 24 +- app/Api/TaskApi.php | 34 +- app/Api/TaskLinkApi.php | 10 +- app/Api/UserApi.php | 20 +- app/Auth/DatabaseAuth.php | 6 +- app/Auth/RememberMeAuth.php | 6 +- app/Console/BaseCommand.php | 36 +- .../ProjectDailyColumnStatsExportCommand.php | 2 +- .../ProjectDailyStatsCalculationCommand.php | 8 +- app/Console/ResetPasswordCommand.php | 4 +- app/Console/ResetTwoFactorCommand.php | 4 +- app/Console/TaskOverdueNotificationCommand.php | 26 +- app/Console/TaskTriggerCommand.php | 8 +- app/Controller/ActionController.php | 20 +- app/Controller/ActionCreationController.php | 16 +- app/Controller/ActivityController.php | 2 +- app/Controller/AnalyticController.php | 12 +- app/Controller/AuthController.php | 2 +- app/Controller/AvatarFileController.php | 6 +- app/Controller/BaseController.php | 12 +- app/Controller/BoardAjaxController.php | 10 +- app/Controller/BoardPopoverController.php | 10 +- app/Controller/BoardTooltipController.php | 18 +- app/Controller/BoardViewController.php | 14 +- app/Controller/CalendarController.php | 8 +- app/Controller/CategoryController.php | 10 +- app/Controller/ColumnController.php | 14 +- app/Controller/CommentController.php | 8 +- app/Controller/ConfigController.php | 20 +- app/Controller/CurrencyController.php | 10 +- app/Controller/CustomFilterController.php | 18 +- app/Controller/DashboardController.php | 14 +- app/Controller/DocumentationController.php | 4 +- app/Controller/ExportController.php | 2 +- app/Controller/FeedController.php | 6 +- app/Controller/GroupCreationController.php | 2 +- app/Controller/GroupListController.php | 22 +- app/Controller/GroupModificationController.php | 4 +- app/Controller/ICalendarController.php | 10 +- app/Controller/LinkController.php | 12 +- app/Controller/PasswordResetController.php | 14 +- .../ProjectActionDuplicationController.php | 4 +- app/Controller/ProjectCreationController.php | 8 +- app/Controller/ProjectEditController.php | 4 +- app/Controller/ProjectFileController.php | 8 +- app/Controller/ProjectGanttController.php | 12 +- app/Controller/ProjectListController.php | 6 +- app/Controller/ProjectOverviewController.php | 8 +- app/Controller/ProjectPermissionController.php | 20 +- app/Controller/ProjectStatusController.php | 6 +- app/Controller/ProjectUserOverviewController.php | 16 +- app/Controller/ProjectViewController.php | 18 +- app/Controller/SearchController.php | 2 +- app/Controller/SubtaskController.php | 14 +- app/Controller/SubtaskConverterController.php | 2 +- app/Controller/SubtaskRestrictionController.php | 8 +- app/Controller/SubtaskStatusController.php | 10 +- app/Controller/SwimlaneController.php | 30 +- app/Controller/TaskAjaxController.php | 2 +- app/Controller/TaskBulkController.php | 8 +- app/Controller/TaskCreationController.php | 14 +- app/Controller/TaskDuplicationController.php | 18 +- app/Controller/TaskExternalLinkController.php | 10 +- app/Controller/TaskFileController.php | 10 +- app/Controller/TaskGanttController.php | 4 +- app/Controller/TaskGanttCreationController.php | 12 +- app/Controller/TaskInternalLinkController.php | 14 +- app/Controller/TaskListController.php | 2 +- app/Controller/TaskModificationController.php | 18 +- app/Controller/TaskPopoverController.php | 12 +- app/Controller/TaskRecurrenceController.php | 10 +- app/Controller/TaskStatusController.php | 2 +- app/Controller/TaskSuppressionController.php | 2 +- app/Controller/TaskViewController.php | 48 +- app/Controller/TwoFactorController.php | 6 +- app/Controller/UserAjaxController.php | 4 +- app/Controller/UserCreationController.php | 12 +- app/Controller/UserCredentialController.php | 6 +- app/Controller/UserListController.php | 2 +- app/Controller/UserModificationController.php | 6 +- app/Controller/UserStatusController.php | 6 +- app/Controller/UserViewController.php | 36 +- app/Controller/WebNotificationController.php | 8 +- app/Core/Action/ActionManager.php | 4 +- app/Core/Base.php | 260 +++++----- app/Core/Event/EventManager.php | 22 +- app/Core/Markdown.php | 4 +- app/Core/User/GroupSync.php | 8 +- app/Core/User/UserProfile.php | 6 +- app/Core/User/UserSession.php | 2 +- app/Core/User/UserSync.php | 8 +- app/Export/SubtaskExport.php | 24 +- app/Export/TaskExport.php | 8 +- app/Export/TransitionExport.php | 4 +- app/Filter/ProjectActivityCreationDateFilter.php | 4 +- app/Filter/ProjectActivityCreatorFilter.php | 4 +- app/Filter/ProjectActivityProjectIdFilter.php | 4 +- app/Filter/ProjectActivityProjectIdsFilter.php | 6 +- app/Filter/ProjectActivityProjectNameFilter.php | 4 +- app/Filter/ProjectActivityTaskIdFilter.php | 4 +- app/Filter/ProjectActivityTaskStatusFilter.php | 6 +- app/Filter/ProjectGroupRoleProjectFilter.php | 4 +- app/Filter/ProjectGroupRoleUsernameFilter.php | 12 +- app/Filter/ProjectIdsFilter.php | 6 +- app/Filter/ProjectStatusFilter.php | 8 +- app/Filter/ProjectTypeFilter.php | 8 +- app/Filter/ProjectUserRoleProjectFilter.php | 4 +- app/Filter/ProjectUserRoleUsernameFilter.php | 6 +- app/Filter/TaskAssigneeFilter.php | 14 +- app/Filter/TaskCategoryFilter.php | 10 +- app/Filter/TaskColorFilter.php | 12 +- app/Filter/TaskColumnFilter.php | 8 +- app/Filter/TaskCommentFilter.php | 8 +- app/Filter/TaskCompletionDateFilter.php | 4 +- app/Filter/TaskCreationDateFilter.php | 4 +- app/Filter/TaskCreatorFilter.php | 8 +- app/Filter/TaskDescriptionFilter.php | 4 +- app/Filter/TaskDueDateFilter.php | 8 +- app/Filter/TaskDueDateRangeFilter.php | 6 +- app/Filter/TaskIdExclusionFilter.php | 4 +- app/Filter/TaskIdFilter.php | 4 +- app/Filter/TaskLinkFilter.php | 20 +- app/Filter/TaskModificationDateFilter.php | 4 +- app/Filter/TaskProjectFilter.php | 8 +- app/Filter/TaskProjectsFilter.php | 6 +- app/Filter/TaskReferenceFilter.php | 4 +- app/Filter/TaskStartDateFilter.php | 4 +- app/Filter/TaskStatusFilter.php | 6 +- app/Filter/TaskSubtaskAssigneeFilter.php | 34 +- app/Filter/TaskSwimlaneFilter.php | 14 +- app/Filter/TaskTitleFilter.php | 8 +- app/Formatter/BoardFormatter.php | 8 +- app/Formatter/ProjectActivityEventFormatter.php | 2 +- app/Formatter/ProjectGanttFormatter.php | 4 +- .../SubtaskTimeTrackingCalendarFormatter.php | 4 +- app/Formatter/TaskAutoCompleteFormatter.php | 4 +- app/Formatter/TaskCalendarFormatter.php | 6 +- app/Formatter/TaskGanttFormatter.php | 6 +- app/Formatter/UserAutoCompleteFormatter.php | 4 +- app/Group/DatabaseBackendGroupProvider.php | 2 +- app/Helper/AppHelper.php | 6 +- app/Helper/AssetHelper.php | 6 +- app/Helper/CalendarHelper.php | 4 +- app/Helper/DateHelper.php | 6 +- app/Helper/LayoutHelper.php | 4 +- app/Helper/ProjectActivityHelper.php | 12 +- app/Helper/ProjectHeaderHelper.php | 6 +- app/Helper/TaskHelper.php | 16 +- app/Helper/UrlHelper.php | 2 +- app/Helper/UserHelper.php | 6 +- app/Import/TaskImport.php | 14 +- app/Import/UserImport.php | 6 +- app/Job/NotificationJob.php | 18 +- app/Job/ProjectMetricJob.php | 4 +- app/Middleware/ProjectAuthorizationMiddleware.php | 2 +- app/Model/Action.php | 190 -------- app/Model/ActionModel.php | 190 ++++++++ app/Model/ActionParameter.php | 164 ------- app/Model/ActionParameterModel.php | 164 +++++++ app/Model/AvatarFile.php | 139 ------ app/Model/AvatarFileModel.php | 139 ++++++ app/Model/Board.php | 175 ------- app/Model/BoardModel.php | 175 +++++++ app/Model/Category.php | 218 --------- app/Model/CategoryModel.php | 218 +++++++++ app/Model/Color.php | 228 --------- app/Model/ColorModel.php | 228 +++++++++ app/Model/Column.php | 211 --------- app/Model/ColumnModel.php | 211 +++++++++ app/Model/Comment.php | 158 ------- app/Model/CommentModel.php | 158 +++++++ app/Model/Config.php | 89 ---- app/Model/ConfigModel.php | 89 ++++ app/Model/Currency.php | 111 ----- app/Model/CurrencyModel.php | 111 +++++ app/Model/CustomFilter.php | 104 ---- app/Model/CustomFilterModel.php | 104 ++++ app/Model/File.php | 341 ------------- app/Model/FileModel.php | 341 +++++++++++++ app/Model/Group.php | 119 ----- app/Model/GroupMember.php | 130 ----- app/Model/GroupMemberModel.php | 130 +++++ app/Model/GroupModel.php | 119 +++++ app/Model/Language.php | 179 ------- app/Model/LanguageModel.php | 179 +++++++ app/Model/LastLogin.php | 92 ---- app/Model/LastLoginModel.php | 92 ++++ app/Model/Link.php | 178 ------- app/Model/LinkModel.php | 178 +++++++ app/Model/Metadata.php | 139 ------ app/Model/MetadataModel.php | 139 ++++++ app/Model/Notification.php | 136 ------ app/Model/NotificationModel.php | 136 ++++++ app/Model/NotificationType.php | 128 ----- app/Model/NotificationTypeModel.php | 128 +++++ app/Model/PasswordReset.php | 95 ---- app/Model/PasswordResetModel.php | 95 ++++ app/Model/Project.php | 526 --------------------- app/Model/ProjectActivity.php | 94 ---- app/Model/ProjectActivityModel.php | 94 ++++ app/Model/ProjectDailyColumnStats.php | 254 ---------- app/Model/ProjectDailyColumnStatsModel.php | 254 ++++++++++ app/Model/ProjectDailyStats.php | 76 --- app/Model/ProjectDailyStatsModel.php | 76 +++ app/Model/ProjectDuplication.php | 161 ------- app/Model/ProjectDuplicationModel.php | 161 +++++++ app/Model/ProjectFile.php | 42 -- app/Model/ProjectFileModel.php | 40 ++ app/Model/ProjectGroupRole.php | 191 -------- app/Model/ProjectGroupRoleModel.php | 191 ++++++++ app/Model/ProjectMetadata.php | 56 --- app/Model/ProjectMetadataModel.php | 54 +++ app/Model/ProjectModel.php | 526 +++++++++++++++++++++ app/Model/ProjectNotification.php | 67 --- app/Model/ProjectNotificationModel.php | 67 +++ app/Model/ProjectNotificationType.php | 59 --- app/Model/ProjectNotificationTypeModel.php | 57 +++ app/Model/ProjectPermission.php | 166 ------- app/Model/ProjectPermissionModel.php | 166 +++++++ app/Model/ProjectUserRole.php | 282 ----------- app/Model/ProjectUserRoleModel.php | 282 +++++++++++ app/Model/RememberMeSession.php | 152 ------ app/Model/RememberMeSessionModel.php | 152 ++++++ app/Model/Setting.php | 113 ----- app/Model/SettingModel.php | 113 +++++ app/Model/Subtask.php | 428 ----------------- app/Model/SubtaskModel.php | 428 +++++++++++++++++ app/Model/SubtaskTimeTracking.php | 298 ------------ app/Model/SubtaskTimeTrackingModel.php | 298 ++++++++++++ app/Model/Swimlane.php | 490 ------------------- app/Model/SwimlaneModel.php | 490 +++++++++++++++++++ app/Model/Task.php | 225 --------- app/Model/TaskAnalytic.php | 72 --- app/Model/TaskAnalyticModel.php | 72 +++ app/Model/TaskCreation.php | 103 ---- app/Model/TaskCreationModel.php | 103 ++++ app/Model/TaskDuplication.php | 270 ----------- app/Model/TaskDuplicationModel.php | 270 +++++++++++ app/Model/TaskExternalLink.php | 101 ---- app/Model/TaskExternalLinkModel.php | 101 ++++ app/Model/TaskFile.php | 54 --- app/Model/TaskFileModel.php | 54 +++ app/Model/TaskFinder.php | 476 ------------------- app/Model/TaskFinderModel.php | 476 +++++++++++++++++++ app/Model/TaskLink.php | 265 ----------- app/Model/TaskLinkModel.php | 265 +++++++++++ app/Model/TaskMetadata.php | 35 -- app/Model/TaskMetadataModel.php | 35 ++ app/Model/TaskModel.php | 225 +++++++++ app/Model/TaskModification.php | 97 ---- app/Model/TaskModificationModel.php | 97 ++++ app/Model/TaskPosition.php | 239 ---------- app/Model/TaskPositionModel.php | 239 ++++++++++ app/Model/TaskStatus.php | 146 ------ app/Model/TaskStatusModel.php | 146 ++++++ app/Model/Timezone.php | 58 --- app/Model/TimezoneModel.php | 58 +++ app/Model/Transition.php | 130 ----- app/Model/TransitionModel.php | 130 +++++ app/Model/User.php | 390 --------------- app/Model/UserLocking.php | 105 ---- app/Model/UserLockingModel.php | 105 ++++ app/Model/UserMention.php | 62 --- app/Model/UserMentionModel.php | 62 +++ app/Model/UserMetadata.php | 37 -- app/Model/UserMetadataModel.php | 35 ++ app/Model/UserModel.php | 390 +++++++++++++++ app/Model/UserNotification.php | 204 -------- app/Model/UserNotificationFilter.php | 206 -------- app/Model/UserNotificationFilterModel.php | 206 ++++++++ app/Model/UserNotificationModel.php | 204 ++++++++ app/Model/UserNotificationType.php | 54 --- app/Model/UserNotificationTypeModel.php | 52 ++ app/Model/UserUnreadNotification.php | 117 ----- app/Model/UserUnreadNotificationModel.php | 117 +++++ app/Notification/ActivityStreamNotification.php | 2 +- app/Notification/MailNotification.php | 42 +- app/Notification/WebNotification.php | 2 +- app/Notification/WebhookNotification.php | 4 +- app/ServiceProvider/ClassProvider.php | 108 ++--- app/ServiceProvider/FilterProvider.php | 26 +- app/ServiceProvider/NotificationProvider.php | 12 +- app/Subscriber/AuthSubscriber.php | 16 +- app/Subscriber/BootstrapSubscriber.php | 6 +- app/Subscriber/LdapUserPhotoSubscriber.php | 2 +- app/Subscriber/NotificationSubscriber.php | 38 +- app/Subscriber/ProjectDailySummarySubscriber.php | 12 +- .../ProjectModificationDateSubscriber.php | 20 +- app/Subscriber/RecurringTaskSubscriber.php | 20 +- app/Subscriber/SubtaskTimeTrackingSubscriber.php | 20 +- app/Subscriber/TransitionSubscriber.php | 6 +- app/Template/analytic/compare_hours.php | 2 +- app/Template/board/task_footer.php | 4 +- app/Template/dashboard/projects.php | 2 +- app/Template/project_creation/create.php | 8 +- app/Template/project_view/duplicate.php | 10 +- app/Template/search/results.php | 2 +- app/Template/task/time_tracking_details.php | 2 +- app/Template/task_list/show.php | 2 +- app/Template/task_recurrence/edit.php | 4 +- app/Template/task_recurrence/info.php | 4 +- app/User/Avatar/GravatarProvider.php | 2 +- app/User/LdapUserProvider.php | 4 +- app/Validator/AuthValidator.php | 4 +- app/Validator/GroupValidator.php | 4 +- app/Validator/LinkValidator.php | 6 +- app/Validator/ProjectValidator.php | 4 +- app/Validator/TaskLinkValidator.php | 4 +- app/Validator/UserValidator.php | 4 +- tests/integration/ApiTest.php | 30 +- .../Action/CommentCreationMoveTaskColumnTest.php | 22 +- tests/units/Action/CommentCreationTest.php | 34 +- tests/units/Action/TaskAssignCategoryColorTest.php | 28 +- tests/units/Action/TaskAssignCategoryLabelTest.php | 28 +- tests/units/Action/TaskAssignCategoryLinkTest.php | 38 +- tests/units/Action/TaskAssignColorCategoryTest.php | 26 +- tests/units/Action/TaskAssignColorColumnTest.php | 22 +- tests/units/Action/TaskAssignColorLinkTest.php | 22 +- tests/units/Action/TaskAssignColorPriorityTest.php | 26 +- tests/units/Action/TaskAssignColorUserTest.php | 22 +- .../Action/TaskAssignCurrentUserColumnTest.php | 28 +- tests/units/Action/TaskAssignCurrentUserTest.php | 22 +- tests/units/Action/TaskAssignSpecificUserTest.php | 22 +- tests/units/Action/TaskAssignUserTest.php | 24 +- tests/units/Action/TaskCloseColumnTest.php | 22 +- tests/units/Action/TaskCloseNoActivityTest.php | 18 +- tests/units/Action/TaskCloseTest.php | 16 +- tests/units/Action/TaskCreationTest.php | 10 +- .../Action/TaskDuplicateAnotherProjectTest.php | 20 +- tests/units/Action/TaskEmailNoActivityTest.php | 44 +- tests/units/Action/TaskEmailTest.php | 20 +- tests/units/Action/TaskMoveAnotherProjectTest.php | 20 +- tests/units/Action/TaskMoveColumnAssignedTest.php | 20 +- .../Action/TaskMoveColumnCategoryChangeTest.php | 36 +- .../units/Action/TaskMoveColumnUnAssignedTest.php | 24 +- tests/units/Action/TaskOpenTest.php | 16 +- tests/units/Action/TaskUpdateStartDateTest.php | 22 +- .../Analytic/AverageLeadCycleTimeAnalyticTest.php | 22 +- .../AverageTimeSpentColumnAnalyticTest.php | 30 +- .../EstimatedTimeComparisonAnalyticTest.php | 16 +- .../Analytic/TaskDistributionAnalyticTest.php | 8 +- .../Analytic/UserDistributionAnalyticTest.php | 16 +- tests/units/Auth/DatabaseAuthTest.php | 4 +- tests/units/Base.php | 4 +- tests/units/Core/Action/ActionManagerTest.php | 48 +- tests/units/Core/Filter/LexerBuilderTest.php | 32 +- tests/units/Core/Filter/OrCriteriaTest.php | 24 +- tests/units/Core/Group/GroupManagerTest.php | 4 +- tests/units/Core/User/GroupSyncTest.php | 20 +- tests/units/Export/TaskExportTest.php | 16 +- tests/units/Export/TransitionExportTest.php | 12 +- .../ProjectActivityCreationDateFilterTest.php | 60 +-- .../Filter/ProjectActivityCreatorFilterTest.php | 50 +- .../Filter/ProjectActivityProjectIdFilterTest.php | 22 +- .../Filter/ProjectActivityProjectIdsFilterTest.php | 38 +- .../ProjectActivityProjectNameFilterTest.php | 22 +- .../Filter/ProjectActivityTaskIdFilterTest.php | 22 +- .../Filter/ProjectActivityTaskStatusFilterTest.php | 26 +- .../Filter/ProjectActivityTaskTitleFilterTest.php | 46 +- tests/units/Filter/TaskAssigneeFilterTest.php | 46 +- tests/units/Filter/TaskCommentFilterTest.php | 24 +- tests/units/Filter/TaskCreatorFilterTest.php | 46 +- tests/units/Helper/AssetHelperTest.php | 4 +- tests/units/Helper/ProjectActivityHelperTest.php | 50 +- tests/units/Helper/TextHelperTest.php | 8 +- tests/units/Helper/UrlHelperTest.php | 4 +- tests/units/Helper/UserHelperTest.php | 43 +- tests/units/Model/ActionTest.php | 176 +++---- tests/units/Model/BoardTest.php | 34 +- tests/units/Model/CategoryTest.php | 64 +-- tests/units/Model/ColorTest.php | 22 +- tests/units/Model/ColumnTest.php | 52 +- tests/units/Model/CommentTest.php | 30 +- tests/units/Model/ConfigTest.php | 14 +- tests/units/Model/CurrencyTest.php | 12 +- tests/units/Model/CustomFilterTest.php | 24 +- tests/units/Model/GroupMemberTest.php | 16 +- tests/units/Model/GroupTest.php | 12 +- tests/units/Model/LanguageTest.php | 16 +- tests/units/Model/LastLoginTest.php | 6 +- tests/units/Model/LinkTest.php | 14 +- tests/units/Model/NotificationTest.php | 32 +- tests/units/Model/PasswordResetTest.php | 24 +- tests/units/Model/ProjectActivityTest.php | 38 +- tests/units/Model/ProjectDailyColumnStatsTest.php | 44 +- tests/units/Model/ProjectDailyStatsTest.php | 16 +- tests/units/Model/ProjectDuplicationTest.php | 168 +++---- tests/units/Model/ProjectFileTest.php | 42 +- tests/units/Model/ProjectGroupRoleTest.php | 128 ++--- tests/units/Model/ProjectMetadataTest.php | 16 +- tests/units/Model/ProjectNotificationTypeTest.php | 10 +- tests/units/Model/ProjectPermissionTest.php | 112 ++--- tests/units/Model/ProjectTest.php | 58 +-- tests/units/Model/ProjectUserRoleTest.php | 150 +++--- tests/units/Model/SubtaskTest.php | 108 ++--- tests/units/Model/SubtaskTimeTrackingTest.php | 70 +-- tests/units/Model/SwimlaneTest.php | 56 +-- tests/units/Model/TaskCreationTest.php | 150 +++--- tests/units/Model/TaskDuplicationTest.php | 254 +++++----- tests/units/Model/TaskExternalLinkTest.php | 36 +- tests/units/Model/TaskFileTest.php | 90 ++-- tests/units/Model/TaskFinderTest.php | 36 +- tests/units/Model/TaskLinkTest.php | 46 +- tests/units/Model/TaskMetadataTest.php | 12 +- tests/units/Model/TaskModificationTest.php | 114 ++--- tests/units/Model/TaskPositionTest.php | 118 ++--- tests/units/Model/TaskStatusTest.php | 52 +- tests/units/Model/TaskTest.php | 38 +- tests/units/Model/TimezoneTest.php | 6 +- tests/units/Model/TransitionTest.php | 24 +- tests/units/Model/UserLockingTest.php | 8 +- tests/units/Model/UserMentionTest.php | 58 +-- tests/units/Model/UserMetadataTest.php | 8 +- tests/units/Model/UserNotificationFilterTest.php | 112 ++--- tests/units/Model/UserNotificationTest.php | 102 ++-- tests/units/Model/UserNotificationTypeTest.php | 6 +- tests/units/Model/UserTest.php | 66 +-- tests/units/Model/UserUnreadNotificationTest.php | 64 +-- tests/units/Notification/MailTest.php | 48 +- tests/units/Notification/WebhookTest.php | 12 +- .../Subscriber/LdapUserPhotoSubscriberTest.php | 10 +- tests/units/Validator/ProjectValidatorTest.php | 6 +- tests/units/Validator/TaskLinkValidatorTest.php | 16 +- 471 files changed, 13720 insertions(+), 13731 deletions(-) delete mode 100644 app/Model/Action.php create mode 100644 app/Model/ActionModel.php delete mode 100644 app/Model/ActionParameter.php create mode 100644 app/Model/ActionParameterModel.php delete mode 100644 app/Model/AvatarFile.php create mode 100644 app/Model/AvatarFileModel.php delete mode 100644 app/Model/Board.php create mode 100644 app/Model/BoardModel.php delete mode 100644 app/Model/Category.php create mode 100644 app/Model/CategoryModel.php delete mode 100644 app/Model/Color.php create mode 100644 app/Model/ColorModel.php delete mode 100644 app/Model/Column.php create mode 100644 app/Model/ColumnModel.php delete mode 100644 app/Model/Comment.php create mode 100644 app/Model/CommentModel.php delete mode 100644 app/Model/Config.php create mode 100644 app/Model/ConfigModel.php delete mode 100644 app/Model/Currency.php create mode 100644 app/Model/CurrencyModel.php delete mode 100644 app/Model/CustomFilter.php create mode 100644 app/Model/CustomFilterModel.php delete mode 100644 app/Model/File.php create mode 100644 app/Model/FileModel.php delete mode 100644 app/Model/Group.php delete mode 100644 app/Model/GroupMember.php create mode 100644 app/Model/GroupMemberModel.php create mode 100644 app/Model/GroupModel.php delete mode 100644 app/Model/Language.php create mode 100644 app/Model/LanguageModel.php delete mode 100644 app/Model/LastLogin.php create mode 100644 app/Model/LastLoginModel.php delete mode 100644 app/Model/Link.php create mode 100644 app/Model/LinkModel.php delete mode 100644 app/Model/Metadata.php create mode 100644 app/Model/MetadataModel.php delete mode 100644 app/Model/Notification.php create mode 100644 app/Model/NotificationModel.php delete mode 100644 app/Model/NotificationType.php create mode 100644 app/Model/NotificationTypeModel.php delete mode 100644 app/Model/PasswordReset.php create mode 100644 app/Model/PasswordResetModel.php delete mode 100644 app/Model/Project.php delete mode 100644 app/Model/ProjectActivity.php create mode 100644 app/Model/ProjectActivityModel.php delete mode 100644 app/Model/ProjectDailyColumnStats.php create mode 100644 app/Model/ProjectDailyColumnStatsModel.php delete mode 100644 app/Model/ProjectDailyStats.php create mode 100644 app/Model/ProjectDailyStatsModel.php delete mode 100644 app/Model/ProjectDuplication.php create mode 100644 app/Model/ProjectDuplicationModel.php delete mode 100644 app/Model/ProjectFile.php create mode 100644 app/Model/ProjectFileModel.php delete mode 100644 app/Model/ProjectGroupRole.php create mode 100644 app/Model/ProjectGroupRoleModel.php delete mode 100644 app/Model/ProjectMetadata.php create mode 100644 app/Model/ProjectMetadataModel.php create mode 100644 app/Model/ProjectModel.php delete mode 100644 app/Model/ProjectNotification.php create mode 100644 app/Model/ProjectNotificationModel.php delete mode 100644 app/Model/ProjectNotificationType.php create mode 100644 app/Model/ProjectNotificationTypeModel.php delete mode 100644 app/Model/ProjectPermission.php create mode 100644 app/Model/ProjectPermissionModel.php delete mode 100644 app/Model/ProjectUserRole.php create mode 100644 app/Model/ProjectUserRoleModel.php delete mode 100644 app/Model/RememberMeSession.php create mode 100644 app/Model/RememberMeSessionModel.php delete mode 100644 app/Model/Setting.php create mode 100644 app/Model/SettingModel.php delete mode 100644 app/Model/Subtask.php create mode 100644 app/Model/SubtaskModel.php delete mode 100644 app/Model/SubtaskTimeTracking.php create mode 100644 app/Model/SubtaskTimeTrackingModel.php delete mode 100644 app/Model/Swimlane.php create mode 100644 app/Model/SwimlaneModel.php delete mode 100644 app/Model/Task.php delete mode 100644 app/Model/TaskAnalytic.php create mode 100644 app/Model/TaskAnalyticModel.php delete mode 100644 app/Model/TaskCreation.php create mode 100644 app/Model/TaskCreationModel.php delete mode 100644 app/Model/TaskDuplication.php create mode 100644 app/Model/TaskDuplicationModel.php delete mode 100644 app/Model/TaskExternalLink.php create mode 100644 app/Model/TaskExternalLinkModel.php delete mode 100644 app/Model/TaskFile.php create mode 100644 app/Model/TaskFileModel.php delete mode 100644 app/Model/TaskFinder.php create mode 100644 app/Model/TaskFinderModel.php delete mode 100644 app/Model/TaskLink.php create mode 100644 app/Model/TaskLinkModel.php delete mode 100644 app/Model/TaskMetadata.php create mode 100644 app/Model/TaskMetadataModel.php create mode 100644 app/Model/TaskModel.php delete mode 100644 app/Model/TaskModification.php create mode 100644 app/Model/TaskModificationModel.php delete mode 100644 app/Model/TaskPosition.php create mode 100644 app/Model/TaskPositionModel.php delete mode 100644 app/Model/TaskStatus.php create mode 100644 app/Model/TaskStatusModel.php delete mode 100644 app/Model/Timezone.php create mode 100644 app/Model/TimezoneModel.php delete mode 100644 app/Model/Transition.php create mode 100644 app/Model/TransitionModel.php delete mode 100644 app/Model/User.php delete mode 100644 app/Model/UserLocking.php create mode 100644 app/Model/UserLockingModel.php delete mode 100644 app/Model/UserMention.php create mode 100644 app/Model/UserMentionModel.php delete mode 100644 app/Model/UserMetadata.php create mode 100644 app/Model/UserMetadataModel.php create mode 100644 app/Model/UserModel.php delete mode 100644 app/Model/UserNotification.php delete mode 100644 app/Model/UserNotificationFilter.php create mode 100644 app/Model/UserNotificationFilterModel.php create mode 100644 app/Model/UserNotificationModel.php delete mode 100644 app/Model/UserNotificationType.php create mode 100644 app/Model/UserNotificationTypeModel.php delete mode 100644 app/Model/UserUnreadNotification.php create mode 100644 app/Model/UserUnreadNotificationModel.php diff --git a/app/Action/CommentCreation.php b/app/Action/CommentCreation.php index b91e39e2..60ca24f7 100644 --- a/app/Action/CommentCreation.php +++ b/app/Action/CommentCreation.php @@ -65,11 +65,11 @@ class CommentCreation extends Base */ public function doAction(array $data) { - return (bool) $this->comment->create(array( + return (bool) $this->commentModel->create(array( 'reference' => isset($data['reference']) ? $data['reference'] : '', 'comment' => $data['comment'], 'task_id' => $data['task_id'], - 'user_id' => isset($data['user_id']) && $this->projectPermission->isAssignable($this->getProjectId(), $data['user_id']) ? $data['user_id'] : 0, + 'user_id' => isset($data['user_id']) && $this->projectPermissionModel->isAssignable($this->getProjectId(), $data['user_id']) ? $data['user_id'] : 0, )); } diff --git a/app/Action/CommentCreationMoveTaskColumn.php b/app/Action/CommentCreationMoveTaskColumn.php index 11224d67..1b16f481 100644 --- a/app/Action/CommentCreationMoveTaskColumn.php +++ b/app/Action/CommentCreationMoveTaskColumn.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Add a comment of the triggering event to the task description. @@ -32,7 +32,7 @@ class CommentCreationMoveTaskColumn extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -71,9 +71,9 @@ class CommentCreationMoveTaskColumn extends Base return false; } - $column = $this->column->getById($data['column_id']); + $column = $this->columnModel->getById($data['column_id']); - return (bool) $this->comment->create(array( + return (bool) $this->commentModel->create(array( 'comment' => t('Moved to column %s', $column['title']), 'task_id' => $data['task_id'], 'user_id' => $this->userSession->getId(), diff --git a/app/Action/TaskAssignCategoryColor.php b/app/Action/TaskAssignCategoryColor.php index f5085cb0..fc486870 100644 --- a/app/Action/TaskAssignCategoryColor.php +++ b/app/Action/TaskAssignCategoryColor.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Set a category automatically according to the color @@ -32,7 +32,7 @@ class TaskAssignCategoryColor extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE_UPDATE, + TaskModel::EVENT_CREATE_UPDATE, ); } @@ -78,7 +78,7 @@ class TaskAssignCategoryColor extends Base 'category_id' => $this->getParam('category_id'), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** diff --git a/app/Action/TaskAssignCategoryLabel.php b/app/Action/TaskAssignCategoryLabel.php index 95fa116e..48299010 100644 --- a/app/Action/TaskAssignCategoryLabel.php +++ b/app/Action/TaskAssignCategoryLabel.php @@ -74,7 +74,7 @@ class TaskAssignCategoryLabel extends Base 'category_id' => $this->getParam('category_id'), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** diff --git a/app/Action/TaskAssignCategoryLink.php b/app/Action/TaskAssignCategoryLink.php index b39e41b4..6937edd1 100644 --- a/app/Action/TaskAssignCategoryLink.php +++ b/app/Action/TaskAssignCategoryLink.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskLinkModel; /** * Set a category automatically according to a task link @@ -33,7 +33,7 @@ class TaskAssignCategoryLink extends Base public function getCompatibleEvents() { return array( - TaskLink::EVENT_CREATE_UPDATE, + TaskLinkModel::EVENT_CREATE_UPDATE, ); } @@ -79,7 +79,7 @@ class TaskAssignCategoryLink extends Base 'category_id' => $this->getParam('category_id'), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** @@ -92,7 +92,7 @@ class TaskAssignCategoryLink extends Base public function hasRequiredCondition(array $data) { if ($data['link_id'] == $this->getParam('link_id')) { - $task = $this->taskFinder->getById($data['task_id']); + $task = $this->taskFinderModel->getById($data['task_id']); return empty($task['category_id']); } diff --git a/app/Action/TaskAssignColorCategory.php b/app/Action/TaskAssignColorCategory.php index 139c24cb..284b8f40 100644 --- a/app/Action/TaskAssignColorCategory.php +++ b/app/Action/TaskAssignColorCategory.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a color to a specific category @@ -32,7 +32,7 @@ class TaskAssignColorCategory extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE_UPDATE, + TaskModel::EVENT_CREATE_UPDATE, ); } @@ -78,7 +78,7 @@ class TaskAssignColorCategory extends Base 'color_id' => $this->getParam('color_id'), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Action/TaskAssignColorColumn.php b/app/Action/TaskAssignColorColumn.php index 92412739..57fd6f44 100644 --- a/app/Action/TaskAssignColorColumn.php +++ b/app/Action/TaskAssignColorColumn.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a color to a task @@ -32,8 +32,8 @@ class TaskAssignColorColumn extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE, - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_CREATE, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -79,7 +79,7 @@ class TaskAssignColorColumn extends Base 'color_id' => $this->getParam('color_id'), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Action/TaskAssignColorLink.php b/app/Action/TaskAssignColorLink.php index 12ceabb3..9ab5458b 100644 --- a/app/Action/TaskAssignColorLink.php +++ b/app/Action/TaskAssignColorLink.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskLinkModel; /** * Assign a color to a specific task link @@ -32,7 +32,7 @@ class TaskAssignColorLink extends Base public function getCompatibleEvents() { return array( - TaskLink::EVENT_CREATE_UPDATE, + TaskLinkModel::EVENT_CREATE_UPDATE, ); } @@ -78,7 +78,7 @@ class TaskAssignColorLink extends Base 'color_id' => $this->getParam('color_id'), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Action/TaskAssignColorPriority.php b/app/Action/TaskAssignColorPriority.php index 2e24f9ef..eae1b771 100644 --- a/app/Action/TaskAssignColorPriority.php +++ b/app/Action/TaskAssignColorPriority.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a color to a priority @@ -32,7 +32,7 @@ class TaskAssignColorPriority extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE_UPDATE, + TaskModel::EVENT_CREATE_UPDATE, ); } @@ -78,7 +78,7 @@ class TaskAssignColorPriority extends Base 'color_id' => $this->getParam('color_id'), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Action/TaskAssignColorUser.php b/app/Action/TaskAssignColorUser.php index 6ec8ce95..4bcf7a5c 100644 --- a/app/Action/TaskAssignColorUser.php +++ b/app/Action/TaskAssignColorUser.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a color to a specific user @@ -32,8 +32,8 @@ class TaskAssignColorUser extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE, - Task::EVENT_ASSIGNEE_CHANGE, + TaskModel::EVENT_CREATE, + TaskModel::EVENT_ASSIGNEE_CHANGE, ); } @@ -79,7 +79,7 @@ class TaskAssignColorUser extends Base 'color_id' => $this->getParam('color_id'), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Action/TaskAssignCurrentUser.php b/app/Action/TaskAssignCurrentUser.php index 192a120c..997aa98f 100644 --- a/app/Action/TaskAssignCurrentUser.php +++ b/app/Action/TaskAssignCurrentUser.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a task to the logged user @@ -32,7 +32,7 @@ class TaskAssignCurrentUser extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE, + TaskModel::EVENT_CREATE, ); } @@ -78,7 +78,7 @@ class TaskAssignCurrentUser extends Base 'owner_id' => $this->userSession->getId(), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** diff --git a/app/Action/TaskAssignCurrentUserColumn.php b/app/Action/TaskAssignCurrentUserColumn.php index 05d08dd3..bc28a90b 100644 --- a/app/Action/TaskAssignCurrentUserColumn.php +++ b/app/Action/TaskAssignCurrentUserColumn.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a task to the logged user on column change @@ -32,7 +32,7 @@ class TaskAssignCurrentUserColumn extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -81,7 +81,7 @@ class TaskAssignCurrentUserColumn extends Base 'owner_id' => $this->userSession->getId(), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** diff --git a/app/Action/TaskAssignSpecificUser.php b/app/Action/TaskAssignSpecificUser.php index 2dc3e966..50a2b2ae 100644 --- a/app/Action/TaskAssignSpecificUser.php +++ b/app/Action/TaskAssignSpecificUser.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Assign a task to a specific user @@ -32,8 +32,8 @@ class TaskAssignSpecificUser extends Base public function getCompatibleEvents() { return array( - Task::EVENT_CREATE_UPDATE, - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_CREATE_UPDATE, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -79,7 +79,7 @@ class TaskAssignSpecificUser extends Base 'owner_id' => $this->getParam('user_id'), ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** diff --git a/app/Action/TaskAssignUser.php b/app/Action/TaskAssignUser.php index da54d186..9ea22986 100644 --- a/app/Action/TaskAssignUser.php +++ b/app/Action/TaskAssignUser.php @@ -71,7 +71,7 @@ class TaskAssignUser extends Base 'owner_id' => $data['owner_id'], ); - return $this->taskModification->update($values); + return $this->taskModificationModel->update($values); } /** @@ -83,6 +83,6 @@ class TaskAssignUser extends Base */ public function hasRequiredCondition(array $data) { - return $this->projectPermission->isAssignable($this->getProjectId(), $data['owner_id']); + return $this->projectPermissionModel->isAssignable($this->getProjectId(), $data['owner_id']); } } diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php index cf91e83e..91e8cf43 100644 --- a/app/Action/TaskClose.php +++ b/app/Action/TaskClose.php @@ -63,7 +63,7 @@ class TaskClose extends Base */ public function doAction(array $data) { - return $this->taskStatus->close($data['task_id']); + return $this->taskStatusModel->close($data['task_id']); } /** diff --git a/app/Action/TaskCloseColumn.php b/app/Action/TaskCloseColumn.php index 09af3b96..1edce8fa 100644 --- a/app/Action/TaskCloseColumn.php +++ b/app/Action/TaskCloseColumn.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Close automatically a task in a specific column @@ -32,7 +32,7 @@ class TaskCloseColumn extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -67,7 +67,7 @@ class TaskCloseColumn extends Base */ public function doAction(array $data) { - return $this->taskStatus->close($data['task_id']); + return $this->taskStatusModel->close($data['task_id']); } /** diff --git a/app/Action/TaskCloseNoActivity.php b/app/Action/TaskCloseNoActivity.php index 59f7f56a..5a10510f 100644 --- a/app/Action/TaskCloseNoActivity.php +++ b/app/Action/TaskCloseNoActivity.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Close automatically a task after when inactive @@ -31,7 +31,7 @@ class TaskCloseNoActivity extends Base */ public function getCompatibleEvents() { - return array(Task::EVENT_DAILY_CRONJOB); + return array(TaskModel::EVENT_DAILY_CRONJOB); } /** @@ -74,7 +74,7 @@ class TaskCloseNoActivity extends Base $duration = time() - $task['date_modification']; if ($duration > $max) { - $results[] = $this->taskStatus->close($task['id']); + $results[] = $this->taskStatusModel->close($task['id']); } } diff --git a/app/Action/TaskCreation.php b/app/Action/TaskCreation.php index 290c31e1..e9e5c5f3 100644 --- a/app/Action/TaskCreation.php +++ b/app/Action/TaskCreation.php @@ -66,7 +66,7 @@ class TaskCreation extends Base */ public function doAction(array $data) { - return (bool) $this->taskCreation->create(array( + return (bool) $this->taskCreationModel->create(array( 'project_id' => $data['project_id'], 'title' => $data['title'], 'reference' => $data['reference'], diff --git a/app/Action/TaskDuplicateAnotherProject.php b/app/Action/TaskDuplicateAnotherProject.php index 5f05136e..93fae5cc 100644 --- a/app/Action/TaskDuplicateAnotherProject.php +++ b/app/Action/TaskDuplicateAnotherProject.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Duplicate a task to another project @@ -32,8 +32,8 @@ class TaskDuplicateAnotherProject extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, - Task::EVENT_CLOSE, + TaskModel::EVENT_MOVE_COLUMN, + TaskModel::EVENT_CLOSE, ); } @@ -74,8 +74,8 @@ class TaskDuplicateAnotherProject extends Base */ public function doAction(array $data) { - $destination_column_id = $this->column->getFirstColumnId($this->getParam('project_id')); - return (bool) $this->taskDuplication->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id); + $destination_column_id = $this->columnModel->getFirstColumnId($this->getParam('project_id')); + return (bool) $this->taskDuplicationModel->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id); } /** diff --git a/app/Action/TaskEmail.php b/app/Action/TaskEmail.php index 4e0e06a6..7f9ba416 100644 --- a/app/Action/TaskEmail.php +++ b/app/Action/TaskEmail.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Email a task to someone @@ -32,8 +32,8 @@ class TaskEmail extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, - Task::EVENT_CLOSE, + TaskModel::EVENT_MOVE_COLUMN, + TaskModel::EVENT_CLOSE, ); } @@ -75,16 +75,16 @@ class TaskEmail extends Base */ public function doAction(array $data) { - $user = $this->user->getById($this->getParam('user_id')); + $user = $this->userModel->getById($this->getParam('user_id')); if (! empty($user['email'])) { - $task = $this->taskFinder->getDetails($data['task_id']); + $task = $this->taskFinderModel->getDetails($data['task_id']); $this->emailClient->send( $user['email'], $user['name'] ?: $user['username'], $this->getParam('subject'), - $this->template->render('notification/task_create', array('task' => $task, 'application_url' => $this->config->get('application_url'))) + $this->template->render('notification/task_create', array('task' => $task, 'application_url' => $this->configModel->get('application_url'))) ); return true; diff --git a/app/Action/TaskEmailNoActivity.php b/app/Action/TaskEmailNoActivity.php index c5d7a797..c60702fb 100644 --- a/app/Action/TaskEmailNoActivity.php +++ b/app/Action/TaskEmailNoActivity.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Email a task with no activity @@ -32,7 +32,7 @@ class TaskEmailNoActivity extends Base public function getCompatibleEvents() { return array( - Task::EVENT_DAILY_CRONJOB, + TaskModel::EVENT_DAILY_CRONJOB, ); } @@ -85,7 +85,7 @@ class TaskEmailNoActivity extends Base { $results = array(); $max = $this->getParam('duration') * 86400; - $user = $this->user->getById($this->getParam('user_id')); + $user = $this->userModel->getById($this->getParam('user_id')); if (! empty($user['email'])) { foreach ($data['tasks'] as $task) { @@ -110,13 +110,13 @@ class TaskEmailNoActivity extends Base */ private function sendEmail($task_id, array $user) { - $task = $this->taskFinder->getDetails($task_id); + $task = $this->taskFinderModel->getDetails($task_id); $this->emailClient->send( $user['email'], $user['name'] ?: $user['username'], $this->getParam('subject'), - $this->template->render('notification/task_create', array('task' => $task, 'application_url' => $this->config->get('application_url'))) + $this->template->render('notification/task_create', array('task' => $task, 'application_url' => $this->configModel->get('application_url'))) ); return true; diff --git a/app/Action/TaskMoveAnotherProject.php b/app/Action/TaskMoveAnotherProject.php index fdff0d8c..73ad4b69 100644 --- a/app/Action/TaskMoveAnotherProject.php +++ b/app/Action/TaskMoveAnotherProject.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Move a task to another project @@ -32,8 +32,8 @@ class TaskMoveAnotherProject extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, - Task::EVENT_CLOSE, + TaskModel::EVENT_MOVE_COLUMN, + TaskModel::EVENT_CLOSE, ); } @@ -75,7 +75,7 @@ class TaskMoveAnotherProject extends Base */ public function doAction(array $data) { - return $this->taskDuplication->moveToProject($data['task_id'], $this->getParam('project_id')); + return $this->taskDuplicationModel->moveToProject($data['task_id'], $this->getParam('project_id')); } /** diff --git a/app/Action/TaskMoveColumnAssigned.php b/app/Action/TaskMoveColumnAssigned.php index 1b23a591..7e3db9c5 100644 --- a/app/Action/TaskMoveColumnAssigned.php +++ b/app/Action/TaskMoveColumnAssigned.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Move a task to another column when an assignee is set @@ -32,8 +32,8 @@ class TaskMoveColumnAssigned extends Base public function getCompatibleEvents() { return array( - Task::EVENT_ASSIGNEE_CHANGE, - Task::EVENT_UPDATE, + TaskModel::EVENT_ASSIGNEE_CHANGE, + TaskModel::EVENT_UPDATE, ); } @@ -75,9 +75,9 @@ class TaskMoveColumnAssigned extends Base */ public function doAction(array $data) { - $original_task = $this->taskFinder->getById($data['task_id']); + $original_task = $this->taskFinderModel->getById($data['task_id']); - return $this->taskPosition->movePosition( + return $this->taskPositionModel->movePosition( $data['project_id'], $data['task_id'], $this->getParam('dest_column_id'), diff --git a/app/Action/TaskMoveColumnCategoryChange.php b/app/Action/TaskMoveColumnCategoryChange.php index 0f591eda..e4f88760 100644 --- a/app/Action/TaskMoveColumnCategoryChange.php +++ b/app/Action/TaskMoveColumnCategoryChange.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Move a task to another column when the category is changed @@ -32,7 +32,7 @@ class TaskMoveColumnCategoryChange extends Base public function getCompatibleEvents() { return array( - Task::EVENT_UPDATE, + TaskModel::EVENT_UPDATE, ); } @@ -74,9 +74,9 @@ class TaskMoveColumnCategoryChange extends Base */ public function doAction(array $data) { - $original_task = $this->taskFinder->getById($data['task_id']); + $original_task = $this->taskFinderModel->getById($data['task_id']); - return $this->taskPosition->movePosition( + return $this->taskPositionModel->movePosition( $data['project_id'], $data['task_id'], $this->getParam('dest_column_id'), diff --git a/app/Action/TaskMoveColumnUnAssigned.php b/app/Action/TaskMoveColumnUnAssigned.php index 99ef9351..c3ae9e1d 100644 --- a/app/Action/TaskMoveColumnUnAssigned.php +++ b/app/Action/TaskMoveColumnUnAssigned.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Move a task to another column when an assignee is cleared @@ -32,8 +32,8 @@ class TaskMoveColumnUnAssigned extends Base public function getCompatibleEvents() { return array( - Task::EVENT_ASSIGNEE_CHANGE, - Task::EVENT_UPDATE, + TaskModel::EVENT_ASSIGNEE_CHANGE, + TaskModel::EVENT_UPDATE, ); } @@ -75,9 +75,9 @@ class TaskMoveColumnUnAssigned extends Base */ public function doAction(array $data) { - $original_task = $this->taskFinder->getById($data['task_id']); + $original_task = $this->taskFinderModel->getById($data['task_id']); - return $this->taskPosition->movePosition( + return $this->taskPositionModel->movePosition( $data['project_id'], $data['task_id'], $this->getParam('dest_column_id'), diff --git a/app/Action/TaskOpen.php b/app/Action/TaskOpen.php index ec0f96f7..8e847b8e 100644 --- a/app/Action/TaskOpen.php +++ b/app/Action/TaskOpen.php @@ -63,7 +63,7 @@ class TaskOpen extends Base */ public function doAction(array $data) { - return $this->taskStatus->open($data['task_id']); + return $this->taskStatusModel->open($data['task_id']); } /** diff --git a/app/Action/TaskUpdateStartDate.php b/app/Action/TaskUpdateStartDate.php index e5cea01b..e5410a87 100644 --- a/app/Action/TaskUpdateStartDate.php +++ b/app/Action/TaskUpdateStartDate.php @@ -2,7 +2,7 @@ namespace Kanboard\Action; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Set the start date of task @@ -32,7 +32,7 @@ class TaskUpdateStartDate extends Base public function getCompatibleEvents() { return array( - Task::EVENT_MOVE_COLUMN, + TaskModel::EVENT_MOVE_COLUMN, ); } @@ -77,7 +77,7 @@ class TaskUpdateStartDate extends Base 'date_started' => time(), ); - return $this->taskModification->update($values, false); + return $this->taskModificationModel->update($values, false); } /** diff --git a/app/Analytic/AverageLeadCycleTimeAnalytic.php b/app/Analytic/AverageLeadCycleTimeAnalytic.php index 62c83559..d6cd1f86 100644 --- a/app/Analytic/AverageLeadCycleTimeAnalytic.php +++ b/app/Analytic/AverageLeadCycleTimeAnalytic.php @@ -3,7 +3,7 @@ namespace Kanboard\Analytic; use Kanboard\Core\Base; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Average Lead and Cycle Time @@ -106,7 +106,7 @@ class AverageLeadCycleTimeAnalytic extends Base private function getTasks($project_id) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->columns('date_completed', 'date_creation', 'date_started') ->eq('project_id', $project_id) ->desc('id') diff --git a/app/Analytic/AverageTimeSpentColumnAnalytic.php b/app/Analytic/AverageTimeSpentColumnAnalytic.php index 11078323..3556fb9d 100644 --- a/app/Analytic/AverageTimeSpentColumnAnalytic.php +++ b/app/Analytic/AverageTimeSpentColumnAnalytic.php @@ -3,7 +3,7 @@ namespace Kanboard\Analytic; use Kanboard\Core\Base; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Average Time Spent by Column @@ -40,7 +40,7 @@ class AverageTimeSpentColumnAnalytic extends Base private function initialize($project_id) { $stats = array(); - $columns = $this->column->getList($project_id); + $columns = $this->columnModel->getList($project_id); foreach ($columns as $column_id => $column_title) { $stats[$column_id] = array( @@ -110,7 +110,7 @@ class AverageTimeSpentColumnAnalytic extends Base */ private function getTaskTimeByColumns(array &$task) { - $columns = $this->transition->getTimeSpentByTask($task['id']); + $columns = $this->transitionModel->getTimeSpentByTask($task['id']); if (! isset($columns[$task['column_id']])) { $columns[$task['column_id']] = 0; @@ -144,7 +144,7 @@ class AverageTimeSpentColumnAnalytic extends Base private function getTasks($project_id) { return $this->db - ->table(Task::TABLE) + ->table(TaskModel::TABLE) ->columns('id', 'date_completed', 'date_moved', 'column_id') ->eq('project_id', $project_id) ->desc('id') diff --git a/app/Analytic/EstimatedTimeComparisonAnalytic.php b/app/Analytic/EstimatedTimeComparisonAnalytic.php index 490bcd50..d9aea32d 100644 --- a/app/Analytic/EstimatedTimeComparisonAnalytic.php +++ b/app/Analytic/EstimatedTimeComparisonAnalytic.php @@ -3,7 +3,7 @@ namespace Kanboard\Analytic; use Kanboard\Core\Base; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Estimated/Spent Time Comparison @@ -22,7 +22,7 @@ class EstimatedTimeComparisonAnalytic extends Base */ public function build($project_id) { - $rows = $this->db->table(Task::TABLE) + $rows = $this->db->table(TaskModel::TABLE) ->columns('SUM(time_estimated) AS time_estimated', 'SUM(time_spent) AS time_spent', 'is_active') ->eq('project_id', $project_id) ->groupBy('is_active') @@ -40,7 +40,7 @@ class EstimatedTimeComparisonAnalytic extends Base ); foreach ($rows as $row) { - $key = $row['is_active'] == Task::STATUS_OPEN ? 'open' : 'closed'; + $key = $row['is_active'] == TaskModel::STATUS_OPEN ? 'open' : 'closed'; $metrics[$key]['time_spent'] = $row['time_spent']; $metrics[$key]['time_estimated'] = $row['time_estimated']; } diff --git a/app/Analytic/TaskDistributionAnalytic.php b/app/Analytic/TaskDistributionAnalytic.php index 838652e3..447d88a1 100644 --- a/app/Analytic/TaskDistributionAnalytic.php +++ b/app/Analytic/TaskDistributionAnalytic.php @@ -23,10 +23,10 @@ class TaskDistributionAnalytic extends Base { $metrics = array(); $total = 0; - $columns = $this->column->getAll($project_id); + $columns = $this->columnModel->getAll($project_id); foreach ($columns as $column) { - $nb_tasks = $this->taskFinder->countByColumnId($project_id, $column['id']); + $nb_tasks = $this->taskFinderModel->countByColumnId($project_id, $column['id']); $total += $nb_tasks; $metrics[] = array( diff --git a/app/Analytic/UserDistributionAnalytic.php b/app/Analytic/UserDistributionAnalytic.php index e1815f9c..421d4242 100644 --- a/app/Analytic/UserDistributionAnalytic.php +++ b/app/Analytic/UserDistributionAnalytic.php @@ -23,8 +23,8 @@ class UserDistributionAnalytic extends Base { $metrics = array(); $total = 0; - $tasks = $this->taskFinder->getAll($project_id); - $users = $this->projectUserRole->getAssignableUsersList($project_id); + $tasks = $this->taskFinderModel->getAll($project_id); + $users = $this->projectUserRoleModel->getAssignableUsersList($project_id); foreach ($tasks as $task) { $user = isset($users[$task['owner_id']]) ? $users[$task['owner_id']] : $users[0]; diff --git a/app/Api/ActionApi.php b/app/Api/ActionApi.php index 0647f9e8..116742d8 100644 --- a/app/Api/ActionApi.php +++ b/app/Api/ActionApi.php @@ -29,12 +29,12 @@ class ActionApi extends Base public function removeAction($action_id) { - return $this->action->remove($action_id); + return $this->actionModel->remove($action_id); } public function getActions($project_id) { - return $this->action->getAllByProject($project_id); + return $this->actionModel->getAllByProject($project_id); } public function createAction($project_id, $event_name, $action_name, array $params) @@ -82,6 +82,6 @@ class ActionApi extends Base } } - return $this->action->create($values); + return $this->actionModel->create($values); } } diff --git a/app/Api/AppApi.php b/app/Api/AppApi.php index 865ba21a..637de5c5 100644 --- a/app/Api/AppApi.php +++ b/app/Api/AppApi.php @@ -14,7 +14,7 @@ class AppApi extends Base { public function getTimezone() { - return $this->timezone->getCurrentTimezone(); + return $this->timezoneModel->getCurrentTimezone(); } public function getVersion() @@ -24,17 +24,17 @@ class AppApi extends Base public function getDefaultTaskColor() { - return $this->color->getDefaultColor(); + return $this->colorModel->getDefaultColor(); } public function getDefaultTaskColors() { - return $this->color->getDefaultColors(); + return $this->colorModel->getDefaultColors(); } public function getColorList() { - return $this->color->getList(); + return $this->colorModel->getList(); } public function getApplicationRoles() diff --git a/app/Api/AuthApi.php b/app/Api/AuthApi.php index a9ad5baf..1cbce5ae 100644 --- a/app/Api/AuthApi.php +++ b/app/Api/AuthApi.php @@ -28,7 +28,7 @@ class AuthApi extends BaseApi if ($this->isUserAuthenticated($username, $password)) { $this->checkProcedurePermission(true, $method); - $this->userSession->initialize($this->user->getByUsername($username)); + $this->userSession->initialize($this->userModel->getByUsername($username)); } elseif ($this->isAppAuthenticated($username, $password)) { $this->checkProcedurePermission(false, $method); } else { @@ -48,7 +48,7 @@ class AuthApi extends BaseApi private function isUserAuthenticated($username, $password) { return $username !== 'jsonrpc' && - ! $this->userLocking->isLocked($username) && + ! $this->userLockingModel->isLocked($username) && $this->authenticationManager->passwordAuthentication($username, $password); } @@ -77,6 +77,6 @@ class AuthApi extends BaseApi return API_AUTHENTICATION_TOKEN; } - return $this->config->get('api_token'); + return $this->configModel->get('api_token'); } } diff --git a/app/Api/BaseApi.php b/app/Api/BaseApi.php index b70356cf..ae41e5b5 100644 --- a/app/Api/BaseApi.php +++ b/app/Api/BaseApi.php @@ -60,7 +60,7 @@ abstract class BaseApi extends Base public function checkProjectPermission($project_id) { - if ($this->userSession->isLogged() && ! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) { + if ($this->userSession->isLogged() && ! $this->projectPermissionModel->isUserAllowed($project_id, $this->userSession->getId())) { throw new AccessDeniedException('Permission denied'); } } @@ -68,7 +68,7 @@ abstract class BaseApi extends Base public function checkTaskPermission($task_id) { if ($this->userSession->isLogged()) { - $this->checkProjectPermission($this->taskFinder->getProjectId($task_id)); + $this->checkProjectPermission($this->taskFinderModel->getProjectId($task_id)); } } @@ -76,7 +76,7 @@ abstract class BaseApi extends Base { if (! empty($task)) { $task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); - $task['color'] = $this->color->getColorProperties($task['color_id']); + $task['color'] = $this->colorModel->getColorProperties($task['color_id']); } return $task; diff --git a/app/Api/BoardApi.php b/app/Api/BoardApi.php index c7d93aa0..aa5942af 100644 --- a/app/Api/BoardApi.php +++ b/app/Api/BoardApi.php @@ -13,6 +13,6 @@ class BoardApi extends BaseApi public function getBoard($project_id) { $this->checkProjectPermission($project_id); - return $this->board->getBoard($project_id); + return $this->boardModel->getBoard($project_id); } } diff --git a/app/Api/CategoryApi.php b/app/Api/CategoryApi.php index 7c5d3bfb..c56cfb35 100644 --- a/app/Api/CategoryApi.php +++ b/app/Api/CategoryApi.php @@ -14,17 +14,17 @@ class CategoryApi extends Base { public function getCategory($category_id) { - return $this->category->getById($category_id); + return $this->categoryModel->getById($category_id); } public function getAllCategories($project_id) { - return $this->category->getAll($project_id); + return $this->categoryModel->getAll($project_id); } public function removeCategory($category_id) { - return $this->category->remove($category_id); + return $this->categoryModel->remove($category_id); } public function createCategory($project_id, $name) @@ -35,7 +35,7 @@ class CategoryApi extends Base ); list($valid, ) = $this->categoryValidator->validateCreation($values); - return $valid ? $this->category->create($values) : false; + return $valid ? $this->categoryModel->create($values) : false; } public function updateCategory($id, $name) @@ -46,6 +46,6 @@ class CategoryApi extends Base ); list($valid, ) = $this->categoryValidator->validateModification($values); - return $valid && $this->category->update($values); + return $valid && $this->categoryModel->update($values); } } diff --git a/app/Api/ColumnApi.php b/app/Api/ColumnApi.php index 45ce521d..aa4026f6 100644 --- a/app/Api/ColumnApi.php +++ b/app/Api/ColumnApi.php @@ -12,31 +12,31 @@ class ColumnApi extends BaseApi { public function getColumns($project_id) { - return $this->column->getAll($project_id); + return $this->columnModel->getAll($project_id); } public function getColumn($column_id) { - return $this->column->getById($column_id); + return $this->columnModel->getById($column_id); } public function updateColumn($column_id, $title, $task_limit = 0, $description = '') { - return $this->column->update($column_id, $title, $task_limit, $description); + return $this->columnModel->update($column_id, $title, $task_limit, $description); } public function addColumn($project_id, $title, $task_limit = 0, $description = '') { - return $this->column->create($project_id, $title, $task_limit, $description); + return $this->columnModel->create($project_id, $title, $task_limit, $description); } public function removeColumn($column_id) { - return $this->column->remove($column_id); + return $this->columnModel->remove($column_id); } public function changeColumnPosition($project_id, $column_id, $position) { - return $this->column->changePosition($project_id, $column_id, $position); + return $this->columnModel->changePosition($project_id, $column_id, $position); } } diff --git a/app/Api/CommentApi.php b/app/Api/CommentApi.php index f16b0f7f..8358efee 100644 --- a/app/Api/CommentApi.php +++ b/app/Api/CommentApi.php @@ -14,17 +14,17 @@ class CommentApi extends Base { public function getComment($comment_id) { - return $this->comment->getById($comment_id); + return $this->commentModel->getById($comment_id); } public function getAllComments($task_id) { - return $this->comment->getAll($task_id); + return $this->commentModel->getAll($task_id); } public function removeComment($comment_id) { - return $this->comment->remove($comment_id); + return $this->commentModel->remove($comment_id); } public function createComment($task_id, $user_id, $content, $reference = '') @@ -38,7 +38,7 @@ class CommentApi extends Base list($valid, ) = $this->commentValidator->validateCreation($values); - return $valid ? $this->comment->create($values) : false; + return $valid ? $this->commentModel->create($values) : false; } public function updateComment($id, $content) @@ -49,6 +49,6 @@ class CommentApi extends Base ); list($valid, ) = $this->commentValidator->validateModification($values); - return $valid && $this->comment->update($values); + return $valid && $this->commentModel->update($values); } } diff --git a/app/Api/FileApi.php b/app/Api/FileApi.php index cc2e3986..1ed3aeb9 100644 --- a/app/Api/FileApi.php +++ b/app/Api/FileApi.php @@ -14,18 +14,18 @@ class FileApi extends BaseApi { public function getTaskFile($file_id) { - return $this->taskFile->getById($file_id); + return $this->taskFileModel->getById($file_id); } public function getAllTaskFiles($task_id) { - return $this->taskFile->getAll($task_id); + return $this->taskFileModel->getAll($task_id); } public function downloadTaskFile($file_id) { try { - $file = $this->taskFile->getById($file_id); + $file = $this->taskFileModel->getById($file_id); if (! empty($file)) { return base64_encode($this->objectStorage->get($file['path'])); @@ -40,7 +40,7 @@ class FileApi extends BaseApi public function createTaskFile($project_id, $task_id, $filename, $blob) { try { - return $this->taskFile->uploadContent($task_id, $filename, $blob); + return $this->taskFileModel->uploadContent($task_id, $filename, $blob); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); return false; @@ -49,12 +49,12 @@ class FileApi extends BaseApi public function removeTaskFile($file_id) { - return $this->taskFile->remove($file_id); + return $this->taskFileModel->remove($file_id); } public function removeAllTaskFiles($task_id) { - return $this->taskFile->removeAll($task_id); + return $this->taskFileModel->removeAll($task_id); } // Deprecated procedures diff --git a/app/Api/GroupApi.php b/app/Api/GroupApi.php index f1841fa3..1701edc3 100644 --- a/app/Api/GroupApi.php +++ b/app/Api/GroupApi.php @@ -14,7 +14,7 @@ class GroupApi extends Base { public function createGroup($name, $external_id = '') { - return $this->group->create($name, $external_id); + return $this->groupModel->create($name, $external_id); } public function updateGroup($group_id, $name = null, $external_id = null) @@ -31,21 +31,21 @@ class GroupApi extends Base } } - return $this->group->update($values); + return $this->groupModel->update($values); } public function removeGroup($group_id) { - return $this->group->remove($group_id); + return $this->groupModel->remove($group_id); } public function getGroup($group_id) { - return $this->group->getById($group_id); + return $this->groupModel->getById($group_id); } public function getAllGroups() { - return $this->group->getAll(); + return $this->groupModel->getAll(); } } diff --git a/app/Api/GroupMemberApi.php b/app/Api/GroupMemberApi.php index f5171e23..e09f6975 100644 --- a/app/Api/GroupMemberApi.php +++ b/app/Api/GroupMemberApi.php @@ -14,26 +14,26 @@ class GroupMemberApi extends Base { public function getMemberGroups($user_id) { - return $this->groupMember->getGroups($user_id); + return $this->groupMemberModel->getGroups($user_id); } public function getGroupMembers($group_id) { - return $this->groupMember->getMembers($group_id); + return $this->groupMemberModel->getMembers($group_id); } public function addGroupMember($group_id, $user_id) { - return $this->groupMember->addUser($group_id, $user_id); + return $this->groupMemberModel->addUser($group_id, $user_id); } public function removeGroupMember($group_id, $user_id) { - return $this->groupMember->removeUser($group_id, $user_id); + return $this->groupMemberModel->removeUser($group_id, $user_id); } public function isGroupMember($group_id, $user_id) { - return $this->groupMember->isMember($group_id, $user_id); + return $this->groupMemberModel->isMember($group_id, $user_id); } } diff --git a/app/Api/LinkApi.php b/app/Api/LinkApi.php index a76cb802..d8e525e4 100644 --- a/app/Api/LinkApi.php +++ b/app/Api/LinkApi.php @@ -21,7 +21,7 @@ class LinkApi extends Base */ public function getLinkById($link_id) { - return $this->link->getById($link_id); + return $this->linkModel->getById($link_id); } /** @@ -33,7 +33,7 @@ class LinkApi extends Base */ public function getLinkByLabel($label) { - return $this->link->getByLabel($label); + return $this->linkModel->getByLabel($label); } /** @@ -45,7 +45,7 @@ class LinkApi extends Base */ public function getOppositeLinkId($link_id) { - return $this->link->getOppositeLinkId($link_id); + return $this->linkModel->getOppositeLinkId($link_id); } /** @@ -56,7 +56,7 @@ class LinkApi extends Base */ public function getAllLinks() { - return $this->link->getAll(); + return $this->linkModel->getAll(); } /** @@ -75,7 +75,7 @@ class LinkApi extends Base ); list($valid, ) = $this->linkValidator->validateCreation($values); - return $valid ? $this->link->create($label, $opposite_label) : false; + return $valid ? $this->linkModel->create($label, $opposite_label) : false; } /** @@ -96,7 +96,7 @@ class LinkApi extends Base ); list($valid, ) = $this->linkValidator->validateModification($values); - return $valid && $this->link->update($values); + return $valid && $this->linkModel->update($values); } /** @@ -108,6 +108,6 @@ class LinkApi extends Base */ public function removeLink($link_id) { - return $this->link->remove($link_id); + return $this->linkModel->remove($link_id); } } diff --git a/app/Api/MeApi.php b/app/Api/MeApi.php index 7d46a962..497749b6 100644 --- a/app/Api/MeApi.php +++ b/app/Api/MeApi.php @@ -2,7 +2,7 @@ namespace Kanboard\Api; -use Kanboard\Model\Subtask as SubtaskModel; +use Kanboard\Model\SubtaskModel; /** * Me API controller @@ -20,25 +20,25 @@ class MeApi extends BaseApi public function getMyDashboard() { $user_id = $this->userSession->getId(); - $projects = $this->project->getQueryColumnStats($this->projectPermission->getActiveProjectIds($user_id))->findAll(); - $tasks = $this->taskFinder->getUserQuery($user_id)->findAll(); + $projects = $this->projectModel->getQueryColumnStats($this->projectPermissionModel->getActiveProjectIds($user_id))->findAll(); + $tasks = $this->taskFinderModel->getUserQuery($user_id)->findAll(); return array( 'projects' => $this->formatProjects($projects), 'tasks' => $this->formatTasks($tasks), - 'subtasks' => $this->subtask->getUserQuery($user_id, array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), + 'subtasks' => $this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), ); } public function getMyActivityStream() { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); } public function createMyPrivateProject($name, $description = null) { - if ($this->config->get('disable_private_project', 0) == 1) { + if ($this->configModel->get('disable_private_project', 0) == 1) { return false; } @@ -49,23 +49,23 @@ class MeApi extends BaseApi ); list($valid, ) = $this->projectValidator->validateCreation($values); - return $valid ? $this->project->create($values, $this->userSession->getId(), true) : false; + return $valid ? $this->projectModel->create($values, $this->userSession->getId(), true) : false; } public function getMyProjectsList() { - return $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + return $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); } public function getMyOverdueTasks() { - return $this->taskFinder->getOverdueTasksByUser($this->userSession->getId()); + return $this->taskFinderModel->getOverdueTasksByUser($this->userSession->getId()); } public function getMyProjects() { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); - $projects = $this->project->getAllByIds($project_ids); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + $projects = $this->projectModel->getAllByIds($project_ids); return $this->formatProjects($projects); } diff --git a/app/Api/ProjectApi.php b/app/Api/ProjectApi.php index 70cd8d16..29a9cd79 100644 --- a/app/Api/ProjectApi.php +++ b/app/Api/ProjectApi.php @@ -13,42 +13,42 @@ class ProjectApi extends BaseApi public function getProjectById($project_id) { $this->checkProjectPermission($project_id); - return $this->formatProject($this->project->getById($project_id)); + return $this->formatProject($this->projectModel->getById($project_id)); } public function getProjectByName($name) { - return $this->formatProject($this->project->getByName($name)); + return $this->formatProject($this->projectModel->getByName($name)); } public function getAllProjects() { - return $this->formatProjects($this->project->getAll()); + return $this->formatProjects($this->projectModel->getAll()); } public function removeProject($project_id) { - return $this->project->remove($project_id); + return $this->projectModel->remove($project_id); } public function enableProject($project_id) { - return $this->project->enable($project_id); + return $this->projectModel->enable($project_id); } public function disableProject($project_id) { - return $this->project->disable($project_id); + return $this->projectModel->disable($project_id); } public function enableProjectPublicAccess($project_id) { - return $this->project->enablePublicAccess($project_id); + return $this->projectModel->enablePublicAccess($project_id); } public function disableProjectPublicAccess($project_id) { - return $this->project->disablePublicAccess($project_id); + return $this->projectModel->disablePublicAccess($project_id); } public function getProjectActivities(array $project_ids) @@ -70,7 +70,7 @@ class ProjectApi extends BaseApi ); list($valid, ) = $this->projectValidator->validateCreation($values); - return $valid ? $this->project->create($values) : false; + return $valid ? $this->projectModel->create($values) : false; } public function updateProject($id, $name, $description = null) @@ -82,6 +82,6 @@ class ProjectApi extends BaseApi ); list($valid, ) = $this->projectValidator->validateModification($values); - return $valid && $this->project->update($values); + return $valid && $this->projectModel->update($values); } } diff --git a/app/Api/ProjectPermissionApi.php b/app/Api/ProjectPermissionApi.php index 10ee3852..703cd0f3 100644 --- a/app/Api/ProjectPermissionApi.php +++ b/app/Api/ProjectPermissionApi.php @@ -15,42 +15,42 @@ class ProjectPermissionApi extends Base { public function getProjectUsers($project_id) { - return $this->projectUserRole->getAllUsers($project_id); + return $this->projectUserRoleModel->getAllUsers($project_id); } public function getAssignableUsers($project_id, $prepend_unassigned = false) { - return $this->projectUserRole->getAssignableUsersList($project_id, $prepend_unassigned); + return $this->projectUserRoleModel->getAssignableUsersList($project_id, $prepend_unassigned); } public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) { - return $this->projectUserRole->addUser($project_id, $user_id, $role); + return $this->projectUserRoleModel->addUser($project_id, $user_id, $role); } public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) { - return $this->projectGroupRole->addGroup($project_id, $group_id, $role); + return $this->projectGroupRoleModel->addGroup($project_id, $group_id, $role); } public function removeProjectUser($project_id, $user_id) { - return $this->projectUserRole->removeUser($project_id, $user_id); + return $this->projectUserRoleModel->removeUser($project_id, $user_id); } public function removeProjectGroup($project_id, $group_id) { - return $this->projectGroupRole->removeGroup($project_id, $group_id); + return $this->projectGroupRoleModel->removeGroup($project_id, $group_id); } public function changeProjectUserRole($project_id, $user_id, $role) { - return $this->projectUserRole->changeUserRole($project_id, $user_id, $role); + return $this->projectUserRoleModel->changeUserRole($project_id, $user_id, $role); } public function changeProjectGroupRole($project_id, $group_id, $role) { - return $this->projectGroupRole->changeGroupRole($project_id, $group_id, $role); + return $this->projectGroupRoleModel->changeGroupRole($project_id, $group_id, $role); } // Deprecated diff --git a/app/Api/SubtaskApi.php b/app/Api/SubtaskApi.php index 305f9ae7..5764ff7d 100644 --- a/app/Api/SubtaskApi.php +++ b/app/Api/SubtaskApi.php @@ -14,17 +14,17 @@ class SubtaskApi extends Base { public function getSubtask($subtask_id) { - return $this->subtask->getById($subtask_id); + return $this->subtaskModel->getById($subtask_id); } public function getAllSubtasks($task_id) { - return $this->subtask->getAll($task_id); + return $this->subtaskModel->getAll($task_id); } public function removeSubtask($subtask_id) { - return $this->subtask->remove($subtask_id); + return $this->subtaskModel->remove($subtask_id); } public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) @@ -39,7 +39,7 @@ class SubtaskApi extends Base ); list($valid, ) = $this->subtaskValidator->validateCreation($values); - return $valid ? $this->subtask->create($values) : false; + return $valid ? $this->subtaskModel->create($values) : false; } public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) @@ -61,6 +61,6 @@ class SubtaskApi extends Base } list($valid, ) = $this->subtaskValidator->validateApiModification($values); - return $valid && $this->subtask->update($values); + return $valid && $this->subtaskModel->update($values); } } diff --git a/app/Api/SwimlaneApi.php b/app/Api/SwimlaneApi.php index f179e11b..c3c56a71 100644 --- a/app/Api/SwimlaneApi.php +++ b/app/Api/SwimlaneApi.php @@ -14,37 +14,37 @@ class SwimlaneApi extends Base { public function getActiveSwimlanes($project_id) { - return $this->swimlane->getSwimlanes($project_id); + return $this->swimlaneModel->getSwimlanes($project_id); } public function getAllSwimlanes($project_id) { - return $this->swimlane->getAll($project_id); + return $this->swimlaneModel->getAll($project_id); } public function getSwimlaneById($swimlane_id) { - return $this->swimlane->getById($swimlane_id); + return $this->swimlaneModel->getById($swimlane_id); } public function getSwimlaneByName($project_id, $name) { - return $this->swimlane->getByName($project_id, $name); + return $this->swimlaneModel->getByName($project_id, $name); } public function getSwimlane($swimlane_id) { - return $this->swimlane->getById($swimlane_id); + return $this->swimlaneModel->getById($swimlane_id); } public function getDefaultSwimlane($project_id) { - return $this->swimlane->getDefault($project_id); + return $this->swimlaneModel->getDefault($project_id); } public function addSwimlane($project_id, $name, $description = '') { - return $this->swimlane->create(array('project_id' => $project_id, 'name' => $name, 'description' => $description)); + return $this->swimlaneModel->create(array('project_id' => $project_id, 'name' => $name, 'description' => $description)); } public function updateSwimlane($swimlane_id, $name, $description = null) @@ -55,26 +55,26 @@ class SwimlaneApi extends Base $values['description'] = $description; } - return $this->swimlane->update($values); + return $this->swimlaneModel->update($values); } public function removeSwimlane($project_id, $swimlane_id) { - return $this->swimlane->remove($project_id, $swimlane_id); + return $this->swimlaneModel->remove($project_id, $swimlane_id); } public function disableSwimlane($project_id, $swimlane_id) { - return $this->swimlane->disable($project_id, $swimlane_id); + return $this->swimlaneModel->disable($project_id, $swimlane_id); } public function enableSwimlane($project_id, $swimlane_id) { - return $this->swimlane->enable($project_id, $swimlane_id); + return $this->swimlaneModel->enable($project_id, $swimlane_id); } public function changeSwimlanePosition($project_id, $swimlane_id, $position) { - return $this->swimlane->changePosition($project_id, $swimlane_id, $position); + return $this->swimlaneModel->changePosition($project_id, $swimlane_id, $position); } } diff --git a/app/Api/TaskApi.php b/app/Api/TaskApi.php index 4d745fa6..ddb3ac54 100644 --- a/app/Api/TaskApi.php +++ b/app/Api/TaskApi.php @@ -3,7 +3,7 @@ namespace Kanboard\Api; use Kanboard\Filter\TaskProjectFilter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; /** * Task API controller @@ -22,63 +22,63 @@ class TaskApi extends BaseApi public function getTask($task_id) { $this->checkTaskPermission($task_id); - return $this->formatTask($this->taskFinder->getById($task_id)); + return $this->formatTask($this->taskFinderModel->getById($task_id)); } public function getTaskByReference($project_id, $reference) { $this->checkProjectPermission($project_id); - return $this->formatTask($this->taskFinder->getByReference($project_id, $reference)); + return $this->formatTask($this->taskFinderModel->getByReference($project_id, $reference)); } public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) { $this->checkProjectPermission($project_id); - return $this->formatTasks($this->taskFinder->getAll($project_id, $status_id)); + return $this->formatTasks($this->taskFinderModel->getAll($project_id, $status_id)); } public function getOverdueTasks() { - return $this->taskFinder->getOverdueTasks(); + return $this->taskFinderModel->getOverdueTasks(); } public function getOverdueTasksByProject($project_id) { $this->checkProjectPermission($project_id); - return $this->taskFinder->getOverdueTasksByProject($project_id); + return $this->taskFinderModel->getOverdueTasksByProject($project_id); } public function openTask($task_id) { $this->checkTaskPermission($task_id); - return $this->taskStatus->open($task_id); + return $this->taskStatusModel->open($task_id); } public function closeTask($task_id) { $this->checkTaskPermission($task_id); - return $this->taskStatus->close($task_id); + return $this->taskStatusModel->close($task_id); } public function removeTask($task_id) { - return $this->task->remove($task_id); + return $this->taskModel->remove($task_id); } public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) { $this->checkProjectPermission($project_id); - return $this->taskPosition->movePosition($project_id, $task_id, $column_id, $position, $swimlane_id); + return $this->taskPositionModel->movePosition($project_id, $task_id, $column_id, $position, $swimlane_id); } public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) { - return $this->taskDuplication->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); } public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) { - return $this->taskDuplication->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); } public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, @@ -88,7 +88,7 @@ class TaskApi extends BaseApi { $this->checkProjectPermission($project_id); - if ($owner_id !== 0 && ! $this->projectPermission->isAssignable($project_id, $owner_id)) { + if ($owner_id !== 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { return false; } @@ -119,7 +119,7 @@ class TaskApi extends BaseApi list($valid, ) = $this->taskValidator->validateCreation($values); - return $valid ? $this->taskCreation->create($values) : false; + return $valid ? $this->taskCreationModel->create($values) : false; } public function updateTask($id, $title = null, $color_id = null, $owner_id = null, @@ -129,13 +129,13 @@ class TaskApi extends BaseApi { $this->checkTaskPermission($id); - $project_id = $this->taskFinder->getProjectId($id); + $project_id = $this->taskFinderModel->getProjectId($id); if ($project_id === 0) { return false; } - if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermission->isAssignable($project_id, $owner_id)) { + if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { return false; } @@ -164,6 +164,6 @@ class TaskApi extends BaseApi } list($valid) = $this->taskValidator->validateApiModification($values); - return $valid && $this->taskModification->update($values); + return $valid && $this->taskModificationModel->update($values); } } diff --git a/app/Api/TaskLinkApi.php b/app/Api/TaskLinkApi.php index 8c02c524..bb809133 100644 --- a/app/Api/TaskLinkApi.php +++ b/app/Api/TaskLinkApi.php @@ -21,7 +21,7 @@ class TaskLinkApi extends Base */ public function getTaskLinkById($task_link_id) { - return $this->taskLink->getById($task_link_id); + return $this->taskLinkModel->getById($task_link_id); } /** @@ -33,7 +33,7 @@ class TaskLinkApi extends Base */ public function getAllTaskLinks($task_id) { - return $this->taskLink->getAll($task_id); + return $this->taskLinkModel->getAll($task_id); } /** @@ -47,7 +47,7 @@ class TaskLinkApi extends Base */ public function createTaskLink($task_id, $opposite_task_id, $link_id) { - return $this->taskLink->create($task_id, $opposite_task_id, $link_id); + return $this->taskLinkModel->create($task_id, $opposite_task_id, $link_id); } /** @@ -62,7 +62,7 @@ class TaskLinkApi extends Base */ public function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id) { - return $this->taskLink->update($task_link_id, $task_id, $opposite_task_id, $link_id); + return $this->taskLinkModel->update($task_link_id, $task_id, $opposite_task_id, $link_id); } /** @@ -74,6 +74,6 @@ class TaskLinkApi extends Base */ public function removeTaskLink($task_link_id) { - return $this->taskLink->remove($task_link_id); + return $this->taskLinkModel->remove($task_link_id); } } diff --git a/app/Api/UserApi.php b/app/Api/UserApi.php index 9786e6cf..88d75527 100644 --- a/app/Api/UserApi.php +++ b/app/Api/UserApi.php @@ -19,37 +19,37 @@ class UserApi extends Base { public function getUser($user_id) { - return $this->user->getById($user_id); + return $this->userModel->getById($user_id); } public function getUserByName($username) { - return $this->user->getByUsername($username); + return $this->userModel->getByUsername($username); } public function getAllUsers() { - return $this->user->getAll(); + return $this->userModel->getAll(); } public function removeUser($user_id) { - return $this->user->remove($user_id); + return $this->userModel->remove($user_id); } public function disableUser($user_id) { - return $this->user->disable($user_id); + return $this->userModel->disable($user_id); } public function enableUser($user_id) { - return $this->user->enable($user_id); + return $this->userModel->enable($user_id); } public function isActiveUser($user_id) { - return $this->user->isActive($user_id); + return $this->userModel->isActive($user_id); } public function createUser($username, $password, $name = '', $email = '', $role = Role::APP_USER) @@ -64,7 +64,7 @@ class UserApi extends Base ); list($valid, ) = $this->userValidator->validateCreation($values); - return $valid ? $this->user->create($values) : false; + return $valid ? $this->userModel->create($values) : false; } /** @@ -108,7 +108,7 @@ class UserApi extends Base 'is_ldap_user' => 1, ); - return $this->user->create($values); + return $this->userModel->create($values); } catch (LdapException $e) { $this->logger->error($e->getMessage()); @@ -133,6 +133,6 @@ class UserApi extends Base } list($valid, ) = $this->userValidator->validateApiModification($values); - return $valid && $this->user->update($values); + return $valid && $this->userModel->update($values); } } diff --git a/app/Auth/DatabaseAuth.php b/app/Auth/DatabaseAuth.php index c13af687..ecb42c17 100644 --- a/app/Auth/DatabaseAuth.php +++ b/app/Auth/DatabaseAuth.php @@ -5,7 +5,7 @@ namespace Kanboard\Auth; use Kanboard\Core\Base; use Kanboard\Core\Security\PasswordAuthenticationProviderInterface; use Kanboard\Core\Security\SessionCheckProviderInterface; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; use Kanboard\User\DatabaseUserProvider; /** @@ -60,7 +60,7 @@ class DatabaseAuth extends Base implements PasswordAuthenticationProviderInterfa public function authenticate() { $user = $this->db - ->table(User::TABLE) + ->table(UserModel::TABLE) ->columns('id', 'password') ->eq('username', $this->username) ->eq('disable_login_form', 0) @@ -84,7 +84,7 @@ class DatabaseAuth extends Base implements PasswordAuthenticationProviderInterfa */ public function isValidSession() { - return $this->user->isActive($this->userSession->getId()); + return $this->userModel->isActive($this->userSession->getId()); } /** diff --git a/app/Auth/RememberMeAuth.php b/app/Auth/RememberMeAuth.php index 509a511d..5d0a8b2e 100644 --- a/app/Auth/RememberMeAuth.php +++ b/app/Auth/RememberMeAuth.php @@ -44,16 +44,16 @@ class RememberMeAuth extends Base implements PreAuthenticationProviderInterface $credentials = $this->rememberMeCookie->read(); if ($credentials !== false) { - $session = $this->rememberMeSession->find($credentials['token'], $credentials['sequence']); + $session = $this->rememberMeSessionModel->find($credentials['token'], $credentials['sequence']); if (! empty($session)) { $this->rememberMeCookie->write( $session['token'], - $this->rememberMeSession->updateSequence($session['token']), + $this->rememberMeSessionModel->updateSequence($session['token']), $session['expiration'] ); - $this->userInfo = $this->user->getById($session['user_id']); + $this->userInfo = $this->userModel->getById($session['user_id']); return true; } diff --git a/app/Console/BaseCommand.php b/app/Console/BaseCommand.php index ca566266..d6806d93 100644 --- a/app/Console/BaseCommand.php +++ b/app/Console/BaseCommand.php @@ -11,24 +11,24 @@ use Symfony\Component\Console\Command\Command; * @package console * @author Frederic Guillot * - * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator - * @property \Kanboard\Export\SubtaskExport $subtaskExport - * @property \Kanboard\Export\TaskExport $taskExport - * @property \Kanboard\Export\TransitionExport $transitionExport - * @property \Kanboard\Model\Notification $notification - * @property \Kanboard\Model\Project $project - * @property \Kanboard\Model\ProjectPermission $projectPermission - * @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats - * @property \Kanboard\Model\ProjectDailyStats $projectDailyStats - * @property \Kanboard\Model\Task $task - * @property \Kanboard\Model\TaskFinder $taskFinder - * @property \Kanboard\Model\User $user - * @property \Kanboard\Model\UserNotification $userNotification - * @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter - * @property \Kanboard\Model\ProjectUserRole $projectUserRole - * @property \Kanboard\Core\Plugin\Loader $pluginLoader - * @property \Kanboard\Core\Http\Client $httpClient - * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator + * @property \Kanboard\Export\SubtaskExport $subtaskExport + * @property \Kanboard\Export\TaskExport $taskExport + * @property \Kanboard\Export\TransitionExport $transitionExport + * @property \Kanboard\Model\NotificationModel $notificationModel + * @property \Kanboard\Model\ProjectModel $projectModel + * @property \Kanboard\Model\ProjectPermissionModel $projectPermissionModel + * @property \Kanboard\Model\ProjectDailyColumnStatsModel $projectDailyColumnStatsModel + * @property \Kanboard\Model\ProjectDailyStatsModel $projectDailyStatsModel + * @property \Kanboard\Model\TaskModel $taskModel + * @property \Kanboard\Model\TaskFinderModel $taskFinderModel + * @property \Kanboard\Model\UserModel $userModel + * @property \Kanboard\Model\UserNotificationModel $userNotificationModel + * @property \Kanboard\Model\UserNotificationFilterModel $userNotificationFilterModel + * @property \Kanboard\Model\ProjectUserRoleModel $projectUserRoleModel + * @property \Kanboard\Core\Plugin\Loader $pluginLoader + * @property \Kanboard\Core\Http\Client $httpClient + * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */ abstract class BaseCommand extends Command { diff --git a/app/Console/ProjectDailyColumnStatsExportCommand.php b/app/Console/ProjectDailyColumnStatsExportCommand.php index ced1a374..1e8af727 100644 --- a/app/Console/ProjectDailyColumnStatsExportCommand.php +++ b/app/Console/ProjectDailyColumnStatsExportCommand.php @@ -21,7 +21,7 @@ class ProjectDailyColumnStatsExportCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { - $data = $this->projectDailyColumnStats->getAggregatedMetrics( + $data = $this->projectDailyColumnStatsModel->getAggregatedMetrics( $input->getArgument('project_id'), $input->getArgument('start_date'), $input->getArgument('end_date') diff --git a/app/Console/ProjectDailyStatsCalculationCommand.php b/app/Console/ProjectDailyStatsCalculationCommand.php index 5b898f02..8dde8a79 100644 --- a/app/Console/ProjectDailyStatsCalculationCommand.php +++ b/app/Console/ProjectDailyStatsCalculationCommand.php @@ -2,7 +2,7 @@ namespace Kanboard\Console; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -17,12 +17,12 @@ class ProjectDailyStatsCalculationCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { - $projects = $this->project->getAllByStatus(Project::ACTIVE); + $projects = $this->projectModel->getAllByStatus(ProjectModel::ACTIVE); foreach ($projects as $project) { $output->writeln('Run calculation for '.$project['name']); - $this->projectDailyColumnStats->updateTotals($project['id'], date('Y-m-d')); - $this->projectDailyStats->updateTotals($project['id'], date('Y-m-d')); + $this->projectDailyColumnStatsModel->updateTotals($project['id'], date('Y-m-d')); + $this->projectDailyStatsModel->updateTotals($project['id'], date('Y-m-d')); } } } diff --git a/app/Console/ResetPasswordCommand.php b/app/Console/ResetPasswordCommand.php index 93dc3761..b483f902 100644 --- a/app/Console/ResetPasswordCommand.php +++ b/app/Console/ResetPasswordCommand.php @@ -60,14 +60,14 @@ class ResetPasswordCommand extends BaseCommand private function resetPassword(OutputInterface $output, $username, $password) { - $userId = $this->user->getIdByUsername($username); + $userId = $this->userModel->getIdByUsername($username); if (empty($userId)) { $output->writeln('User not found'); return false; } - if (!$this->user->update(array('id' => $userId, 'password' => $password))) { + if (!$this->userModel->update(array('id' => $userId, 'password' => $password))) { $output->writeln('Unable to update password'); return false; } diff --git a/app/Console/ResetTwoFactorCommand.php b/app/Console/ResetTwoFactorCommand.php index 3bf01e81..a64206b6 100644 --- a/app/Console/ResetTwoFactorCommand.php +++ b/app/Console/ResetTwoFactorCommand.php @@ -19,14 +19,14 @@ class ResetTwoFactorCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); - $userId = $this->user->getIdByUsername($username); + $userId = $this->userModel->getIdByUsername($username); if (empty($userId)) { $output->writeln('User not found'); return false; } - if (!$this->user->update(array('id' => $userId, 'twofactor_activated' => 0, 'twofactor_secret' => ''))) { + if (!$this->userModel->update(array('id' => $userId, 'twofactor_activated' => 0, 'twofactor_secret' => ''))) { $output->writeln('Unable to update user profile'); return false; } diff --git a/app/Console/TaskOverdueNotificationCommand.php b/app/Console/TaskOverdueNotificationCommand.php index 7e8484c8..225a6a1a 100644 --- a/app/Console/TaskOverdueNotificationCommand.php +++ b/app/Console/TaskOverdueNotificationCommand.php @@ -2,7 +2,7 @@ namespace Kanboard\Console; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Kanboard\Core\Security\Role; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; @@ -65,10 +65,10 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendGroupOverdueTaskNotifications() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'owner_id') as $user_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($user_tasks[0]['project_id']); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($user_tasks[0]['project_id']); foreach ($users as $user) { $this->sendUserOverdueTaskNotifications($user, $user_tasks); @@ -85,14 +85,14 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendOverdueTaskNotificationsToManagers() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id); $managers = array(); foreach ($users as $user) { - $role = $this->projectUserRole->getUserRole($project_id, $user['id']); + $role = $this->projectUserRoleModel->getUserRole($project_id, $user['id']); if($role == Role::PROJECT_MANAGER) { $managers[] = $user; } @@ -113,10 +113,10 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendOverdueTaskNotifications() { - $tasks = $this->taskFinder->getOverdueTasks(); + $tasks = $this->taskFinderModel->getOverdueTasks(); foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id); foreach ($users as $user) { $this->sendUserOverdueTaskNotifications($user, $project_tasks); @@ -139,16 +139,16 @@ class TaskOverdueNotificationCommand extends BaseCommand $project_names = array(); foreach ($tasks as $task) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + if ($this->userNotificationFilterModel->shouldReceiveNotification($user, array('task' => $task))) { $user_tasks[] = $task; $project_names[$task['project_id']] = $task['project_name']; } } if (! empty($user_tasks)) { - $this->userNotification->sendUserNotification( + $this->userNotificationModel->sendUserNotification( $user, - Task::EVENT_OVERDUE, + TaskModel::EVENT_OVERDUE, array('tasks' => $user_tasks, 'project_name' => implode(", ", $project_names)) ); } @@ -163,9 +163,9 @@ class TaskOverdueNotificationCommand extends BaseCommand */ public function sendUserOverdueTaskNotificationsToManagers(array $manager, array $tasks) { - $this->userNotification->sendUserNotification( + $this->userNotificationModel->sendUserNotification( $manager, - Task::EVENT_OVERDUE, + TaskModel::EVENT_OVERDUE, array('tasks' => $tasks, 'project_name' => $tasks[0]['project_name']) ); } diff --git a/app/Console/TaskTriggerCommand.php b/app/Console/TaskTriggerCommand.php index 9e9554f9..a1f4dccf 100644 --- a/app/Console/TaskTriggerCommand.php +++ b/app/Console/TaskTriggerCommand.php @@ -4,7 +4,7 @@ namespace Kanboard\Console; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Kanboard\Event\TaskListEvent; class TaskTriggerCommand extends BaseCommand @@ -19,7 +19,7 @@ class TaskTriggerCommand extends BaseCommand protected function execute(InputInterface $input, OutputInterface $output) { foreach ($this->getProjectIds() as $project_id) { - $tasks = $this->taskFinder->getAll($project_id); + $tasks = $this->taskFinderModel->getAll($project_id); $nb_tasks = count($tasks); if ($nb_tasks > 0) { @@ -31,7 +31,7 @@ class TaskTriggerCommand extends BaseCommand private function getProjectIds() { - $listeners = $this->dispatcher->getListeners(Task::EVENT_DAILY_CRONJOB); + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_DAILY_CRONJOB); $project_ids = array(); foreach ($listeners as $listener) { @@ -46,6 +46,6 @@ class TaskTriggerCommand extends BaseCommand $event = new TaskListEvent(array('project_id' => $project_id)); $event->setTasks($tasks); - $this->dispatcher->dispatch(Task::EVENT_DAILY_CRONJOB, $event); + $this->dispatcher->dispatch(TaskModel::EVENT_DAILY_CRONJOB, $event); } } diff --git a/app/Controller/ActionController.php b/app/Controller/ActionController.php index 51090d22..097640f6 100644 --- a/app/Controller/ActionController.php +++ b/app/Controller/ActionController.php @@ -18,7 +18,7 @@ class ActionController extends BaseController public function index() { $project = $this->getProject(); - $actions = $this->action->getAllByProject($project['id']); + $actions = $this->actionModel->getAllByProject($project['id']); $this->response->html($this->helper->layout->project('action/index', array( 'values' => array('project_id' => $project['id']), @@ -27,12 +27,12 @@ class ActionController extends BaseController 'available_actions' => $this->actionManager->getAvailableActions(), 'available_events' => $this->eventManager->getAll(), 'available_params' => $this->actionManager->getAvailableParameters($actions), - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), - 'projects_list' => $this->projectUserRole->getProjectsByUser($this->userSession->getId()), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'links_list' => $this->link->getList(0, false), + 'columns_list' => $this->columnModel->getList($project['id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id']), + 'projects_list' => $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($project['id']), + 'links_list' => $this->linkModel->getList(0, false), 'title' => t('Automatic actions') ))); } @@ -47,7 +47,7 @@ class ActionController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project('action/remove', array( - 'action' => $this->action->getById($this->request->getIntegerParam('action_id')), + 'action' => $this->actionModel->getById($this->request->getIntegerParam('action_id')), 'available_events' => $this->eventManager->getAll(), 'available_actions' => $this->actionManager->getAvailableActions(), 'project' => $project, @@ -64,9 +64,9 @@ class ActionController extends BaseController { $this->checkCSRFParam(); $project = $this->getProject(); - $action = $this->action->getById($this->request->getIntegerParam('action_id')); + $action = $this->actionModel->getById($this->request->getIntegerParam('action_id')); - if (! empty($action) && $this->action->remove($action['id'])) { + if (! empty($action) && $this->actionModel->remove($action['id'])) { $this->flash->success(t('Action removed successfully.')); } else { $this->flash->failure(t('Unable to remove this action.')); diff --git a/app/Controller/ActionCreationController.php b/app/Controller/ActionCreationController.php index e055f11b..e984f8d4 100644 --- a/app/Controller/ActionCreationController.php +++ b/app/Controller/ActionCreationController.php @@ -69,19 +69,19 @@ class ActionCreationController extends BaseController $this->doCreation($project, $values + array('params' => array())); } - $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + $projects_list = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); unset($projects_list[$project['id']]); $this->response->html($this->template->render('action_creation/params', array( 'values' => $values, 'action_params' => $action_params, - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), + 'columns_list' => $this->columnModel->getList($project['id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id']), 'projects_list' => $projects_list, - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'links_list' => $this->link->getList(0, false), - 'priorities_list' => $this->project->getPriorities($project), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($project['id']), + 'links_list' => $this->linkModel->getList(0, false), + 'priorities_list' => $this->projectModel->getPriorities($project), 'project' => $project, 'available_actions' => $this->actionManager->getAvailableActions(), 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), @@ -110,7 +110,7 @@ class ActionCreationController extends BaseController list($valid, ) = $this->actionValidator->validateCreation($values); if ($valid) { - if ($this->action->create($values) !== false) { + if ($this->actionModel->create($values) !== false) { $this->flash->success(t('Your automatic action have been created successfully.')); } else { $this->flash->failure(t('Unable to create your automatic action.')); diff --git a/app/Controller/ActivityController.php b/app/Controller/ActivityController.php index a8fc1b39..9f9841af 100644 --- a/app/Controller/ActivityController.php +++ b/app/Controller/ActivityController.php @@ -38,7 +38,7 @@ class ActivityController extends BaseController $this->response->html($this->helper->layout->task('activity/task', array( 'title' => $task['title'], 'task' => $task, - 'project' => $this->project->getById($task['project_id']), + 'project' => $this->projectModel->getById($task['project_id']), 'events' => $this->helper->projectActivity->getTaskEvents($task['id']), ))); } diff --git a/app/Controller/AnalyticController.php b/app/Controller/AnalyticController.php index 99d34c66..cf3ba034 100644 --- a/app/Controller/AnalyticController.php +++ b/app/Controller/AnalyticController.php @@ -3,7 +3,7 @@ namespace Kanboard\Controller; use Kanboard\Filter\TaskProjectFilter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; /** * Project Analytic Controller @@ -30,8 +30,8 @@ class AnalyticController extends BaseController ), 'project' => $project, 'average' => $this->averageLeadCycleTimeAnalytic->build($project['id']), - 'metrics' => $this->projectDailyStats->getRawMetrics($project['id'], $from, $to), - 'date_format' => $this->config->get('application_date_format'), + 'metrics' => $this->projectDailyStatsModel->getRawMetrics($project['id'], $from, $to), + 'date_format' => $this->configModel->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), 'title' => t('Lead and Cycle time for "%s"', $project['name']), ))); @@ -145,7 +145,7 @@ class AnalyticController extends BaseController $project = $this->getProject(); list($from, $to) = $this->getDates(); - $display_graph = $this->projectDailyColumnStats->countDays($project['id'], $from, $to) >= 2; + $display_graph = $this->projectDailyColumnStatsModel->countDays($project['id'], $from, $to) >= 2; $this->response->html($this->helper->layout->analytic($template, array( 'values' => array( @@ -153,9 +153,9 @@ class AnalyticController extends BaseController 'to' => $to, ), 'display_graph' => $display_graph, - 'metrics' => $display_graph ? $this->projectDailyColumnStats->getAggregatedMetrics($project['id'], $from, $to, $column) : array(), + 'metrics' => $display_graph ? $this->projectDailyColumnStatsModel->getAggregatedMetrics($project['id'], $from, $to, $column) : array(), 'project' => $project, - 'date_format' => $this->config->get('application_date_format'), + 'date_format' => $this->configModel->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), 'title' => t($title, $project['name']), ))); diff --git a/app/Controller/AuthController.php b/app/Controller/AuthController.php index 598b3ff8..dc46070c 100644 --- a/app/Controller/AuthController.php +++ b/app/Controller/AuthController.php @@ -23,7 +23,7 @@ class AuthController extends BaseController $this->response->redirect($this->helper->url->to('DashboardController', 'show')); } else { $this->response->html($this->helper->layout->app('auth/index', array( - 'captcha' => ! empty($values['username']) && $this->userLocking->hasCaptcha($values['username']), + 'captcha' => ! empty($values['username']) && $this->userLockingModel->hasCaptcha($values['username']), 'errors' => $errors, 'values' => $values, 'no_layout' => true, diff --git a/app/Controller/AvatarFileController.php b/app/Controller/AvatarFileController.php index 0e2ed1bb..6879c577 100644 --- a/app/Controller/AvatarFileController.php +++ b/app/Controller/AvatarFileController.php @@ -32,7 +32,7 @@ class AvatarFileController extends BaseController { $user = $this->getUser(); - if (! $this->avatarFile->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) { + if (! $this->avatarFileModel->uploadImageFile($user['id'], $this->request->getFileInfo('avatar'))) { $this->flash->failure(t('Unable to upload the file.')); } @@ -46,7 +46,7 @@ class AvatarFileController extends BaseController { $this->checkCSRFParam(); $user = $this->getUser(); - $this->avatarFile->remove($user['id']); + $this->avatarFileModel->remove($user['id']); $this->userSession->refresh($user['id']); $this->response->redirect($this->helper->url->to('AvatarFileController', 'show', array('user_id' => $user['id']))); } @@ -58,7 +58,7 @@ class AvatarFileController extends BaseController { $user_id = $this->request->getIntegerParam('user_id'); $size = $this->request->getStringParam('size', 48); - $filename = $this->avatarFile->getFilename($user_id); + $filename = $this->avatarFileModel->getFilename($user_id); $etag = md5($filename.$size); $this->response->withCache(365 * 86400, $etag); diff --git a/app/Controller/BaseController.php b/app/Controller/BaseController.php index ad02f708..36871bb4 100644 --- a/app/Controller/BaseController.php +++ b/app/Controller/BaseController.php @@ -33,7 +33,7 @@ abstract class BaseController extends Base */ protected function checkWebhookToken() { - if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { + if ($this->configModel->get('webhook_token') !== $this->request->getStringParam('token')) { $this->response->text('Not Authorized', 401); } } @@ -49,7 +49,7 @@ abstract class BaseController extends Base protected function getTask() { $project_id = $this->request->getIntegerParam('project_id'); - $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id')); + $task = $this->taskFinderModel->getDetails($this->request->getIntegerParam('task_id')); if (empty($task)) { throw new PageNotFoundException(); @@ -78,7 +78,7 @@ abstract class BaseController extends Base if ($task_id > 0) { $model = 'taskFile'; - $project_id = $this->taskFinder->getProjectId($task_id); + $project_id = $this->taskFinderModel->getProjectId($task_id); if ($project_id !== $this->request->getIntegerParam('project_id')) { throw new AccessForbiddenException(); @@ -106,7 +106,7 @@ abstract class BaseController extends Base protected function getProject($project_id = 0) { $project_id = $this->request->getIntegerParam('project_id', $project_id); - $project = $this->project->getByIdWithOwner($project_id); + $project = $this->projectModel->getByIdWithOwner($project_id); if (empty($project)) { throw new PageNotFoundException(); @@ -125,7 +125,7 @@ abstract class BaseController extends Base */ protected function getUser() { - $user = $this->user->getById($this->request->getIntegerParam('user_id', $this->userSession->getId())); + $user = $this->userModel->getById($this->request->getIntegerParam('user_id', $this->userSession->getId())); if (empty($user)) { throw new PageNotFoundException(); @@ -147,7 +147,7 @@ abstract class BaseController extends Base */ protected function getSubtask() { - $subtask = $this->subtask->getById($this->request->getIntegerParam('subtask_id')); + $subtask = $this->subtaskModel->getById($this->request->getIntegerParam('subtask_id')); if (empty($subtask)) { throw new PageNotFoundException(); diff --git a/app/Controller/BoardAjaxController.php b/app/Controller/BoardAjaxController.php index d4714699..24914671 100644 --- a/app/Controller/BoardAjaxController.php +++ b/app/Controller/BoardAjaxController.php @@ -28,7 +28,7 @@ class BoardAjaxController extends BaseController $values = $this->request->getJson(); - $result =$this->taskPosition->movePosition( + $result =$this->taskPositionModel->movePosition( $project_id, $values['task_id'], $values['column_id'], @@ -55,7 +55,7 @@ class BoardAjaxController extends BaseController if (! $project_id || ! $this->request->isAjax()) { throw new AccessForbiddenException(); - } elseif (! $this->project->isModifiedSince($project_id, $timestamp)) { + } elseif (! $this->projectModel->isModifiedSince($project_id, $timestamp)) { $this->response->status(304); } else { $this->response->html($this->renderBoard($project_id)); @@ -129,9 +129,9 @@ class BoardAjaxController extends BaseController protected function renderBoard($project_id) { return $this->template->render('board/table_container', array( - 'project' => $this->project->getById($project_id), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), + 'project' => $this->projectModel->getById($project_id), + 'board_private_refresh_interval' => $this->configModel->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->configModel->get('board_highlight_period'), 'swimlanes' => $this->taskLexer ->build($this->userSession->getFilters($project_id)) ->format(BoardFormatter::getInstance($this->container)->setProjectId($project_id)) diff --git a/app/Controller/BoardPopoverController.php b/app/Controller/BoardPopoverController.php index 2c2e5dc6..a0f5ae12 100644 --- a/app/Controller/BoardPopoverController.php +++ b/app/Controller/BoardPopoverController.php @@ -23,9 +23,9 @@ class BoardPopoverController extends BaseController $this->response->html($this->template->render('board_popover/close_all_tasks_column', array( 'project' => $project, - 'nb_tasks' => $this->taskFinder->countByColumnAndSwimlaneId($project['id'], $column_id, $swimlane_id), - 'column' => $this->column->getColumnTitleById($column_id), - 'swimlane' => $this->swimlane->getNameById($swimlane_id) ?: t($project['default_swimlane']), + 'nb_tasks' => $this->taskFinderModel->countByColumnAndSwimlaneId($project['id'], $column_id, $swimlane_id), + 'column' => $this->columnModel->getColumnTitleById($column_id), + 'swimlane' => $this->swimlaneModel->getNameById($swimlane_id) ?: t($project['default_swimlane']), 'values' => array('column_id' => $column_id, 'swimlane_id' => $swimlane_id), ))); } @@ -40,8 +40,8 @@ class BoardPopoverController extends BaseController $project = $this->getProject(); $values = $this->request->getValues(); - $this->taskStatus->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']); - $this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->column->getColumnTitleById($values['column_id']), $this->swimlane->getNameById($values['swimlane_id']) ?: t($project['default_swimlane']))); + $this->taskStatusModel->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']); + $this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->columnModel->getColumnTitleById($values['column_id']), $this->swimlaneModel->getNameById($values['swimlane_id']) ?: t($project['default_swimlane']))); $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']))); } } diff --git a/app/Controller/BoardTooltipController.php b/app/Controller/BoardTooltipController.php index 2f1d949e..2a947027 100644 --- a/app/Controller/BoardTooltipController.php +++ b/app/Controller/BoardTooltipController.php @@ -19,7 +19,7 @@ class BoardTooltipController extends BaseController { $task = $this->getTask(); $this->response->html($this->template->render('board/tooltip_tasklinks', array( - 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), + 'links' => $this->taskLinkModel->getAllGroupedByLabel($task['id']), 'task' => $task, ))); } @@ -33,7 +33,7 @@ class BoardTooltipController extends BaseController { $task = $this->getTask(); $this->response->html($this->template->render('board/tooltip_external_links', array( - 'links' => $this->taskExternalLink->getAll($task['id']), + 'links' => $this->taskExternalLinkModel->getAll($task['id']), 'task' => $task, ))); } @@ -47,7 +47,7 @@ class BoardTooltipController extends BaseController { $task = $this->getTask(); $this->response->html($this->template->render('board/tooltip_subtasks', array( - 'subtasks' => $this->subtask->getAll($task['id']), + 'subtasks' => $this->subtaskModel->getAll($task['id']), 'task' => $task, ))); } @@ -62,7 +62,7 @@ class BoardTooltipController extends BaseController $task = $this->getTask(); $this->response->html($this->template->render('board/tooltip_files', array( - 'files' => $this->taskFile->getAll($task['id']), + 'files' => $this->taskFileModel->getAll($task['id']), 'task' => $task, ))); } @@ -78,7 +78,7 @@ class BoardTooltipController extends BaseController $this->response->html($this->template->render('board/tooltip_comments', array( 'task' => $task, - 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()) + 'comments' => $this->commentModel->getAll($task['id'], $this->userSession->getCommentSorting()) ))); } @@ -107,9 +107,9 @@ class BoardTooltipController extends BaseController $this->response->html($this->template->render('task_recurrence/info', array( 'task' => $task, - 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), - 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), - 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + 'recurrence_trigger_list' => $this->taskModel->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->taskModel->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->taskModel->getRecurrenceBasedateList(), ))); } @@ -121,7 +121,7 @@ class BoardTooltipController extends BaseController public function swimlane() { $this->getProject(); - $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); + $swimlane = $this->swimlaneModel->getById($this->request->getIntegerParam('swimlane_id')); $this->response->html($this->template->render('board/tooltip_description', array('task' => $swimlane))); } } diff --git a/app/Controller/BoardViewController.php b/app/Controller/BoardViewController.php index 3c96af73..496fa995 100644 --- a/app/Controller/BoardViewController.php +++ b/app/Controller/BoardViewController.php @@ -22,7 +22,7 @@ class BoardViewController extends BaseController public function readonly() { $token = $this->request->getStringParam('token'); - $project = $this->project->getByToken($token); + $project = $this->projectModel->getByToken($token); if (empty($project)) { throw AccessForbiddenException::getInstance()->withoutLayout(); @@ -30,14 +30,14 @@ class BoardViewController extends BaseController $this->response->html($this->helper->layout->app('board/view_public', array( 'project' => $project, - 'swimlanes' => $this->board->getBoard($project['id']), + 'swimlanes' => $this->boardModel->getBoard($project['id']), 'title' => $project['name'], 'description' => $project['description'], 'no_layout' => true, 'not_editable' => true, - 'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), + 'board_public_refresh_interval' => $this->configModel->get('board_public_refresh_interval'), + 'board_private_refresh_interval' => $this->configModel->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->configModel->get('board_highlight_period'), ))); } @@ -55,8 +55,8 @@ class BoardViewController extends BaseController 'project' => $project, 'title' => $project['name'], 'description' => $this->helper->projectHeader->getDescription($project), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), + 'board_private_refresh_interval' => $this->configModel->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->configModel->get('board_highlight_period'), 'swimlanes' => $this->taskLexer ->build($search) ->format(BoardFormatter::getInstance($this->container)->setProjectId($project['id'])) diff --git a/app/Controller/CalendarController.php b/app/Controller/CalendarController.php index c875a18c..e5114f02 100644 --- a/app/Controller/CalendarController.php +++ b/app/Controller/CalendarController.php @@ -5,7 +5,7 @@ namespace Kanboard\Controller; use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Filter\TaskStatusFilter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; /** * Calendar Controller @@ -29,7 +29,7 @@ class CalendarController extends BaseController 'project' => $project, 'title' => $project['name'], 'description' => $this->helper->projectHeader->getDescription($project), - 'check_interval' => $this->config->get('board_private_refresh_interval'), + 'check_interval' => $this->configModel->get('board_private_refresh_interval'), ))); } @@ -75,7 +75,7 @@ class CalendarController extends BaseController $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end); $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end)); - if ($this->config->get('calendar_user_subtasks_time_tracking') == 1) { + if ($this->configModel->get('calendar_user_subtasks_time_tracking') == 1) { $events = array_merge($events, $this->helper->calendar->getSubtaskTimeTrackingEvents($user_id, $start, $end)); } @@ -98,7 +98,7 @@ class CalendarController extends BaseController if ($this->request->isAjax() && $this->request->isPost()) { $values = $this->request->getJson(); - $this->taskModification->update(array( + $this->taskModificationModel->update(array( 'id' => $values['task_id'], 'date_due' => substr($values['date_due'], 0, 10), )); diff --git a/app/Controller/CategoryController.php b/app/Controller/CategoryController.php index e7c8db54..fd1b3f94 100644 --- a/app/Controller/CategoryController.php +++ b/app/Controller/CategoryController.php @@ -21,7 +21,7 @@ class CategoryController extends BaseController */ private function getCategory() { - $category = $this->category->getById($this->request->getIntegerParam('category_id')); + $category = $this->categoryModel->getById($this->request->getIntegerParam('category_id')); if (empty($category)) { throw new PageNotFoundException(); @@ -43,7 +43,7 @@ class CategoryController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project('category/index', array( - 'categories' => $this->category->getList($project['id'], false), + 'categories' => $this->categoryModel->getList($project['id'], false), 'values' => $values + array('project_id' => $project['id']), 'errors' => $errors, 'project' => $project, @@ -64,7 +64,7 @@ class CategoryController extends BaseController list($valid, $errors) = $this->categoryValidator->validateCreation($values); if ($valid) { - if ($this->category->create($values)) { + if ($this->categoryModel->create($values)) { $this->flash->success(t('Your category have been created successfully.')); return $this->response->redirect($this->helper->url->to('CategoryController', 'index', array('project_id' => $project['id']))); } else { @@ -109,7 +109,7 @@ class CategoryController extends BaseController list($valid, $errors) = $this->categoryValidator->validateModification($values); if ($valid) { - if ($this->category->update($values)) { + if ($this->categoryModel->update($values)) { $this->flash->success(t('Your category have been updated successfully.')); return $this->response->redirect($this->helper->url->to('CategoryController', 'index', array('project_id' => $project['id']))); } else { @@ -148,7 +148,7 @@ class CategoryController extends BaseController $project = $this->getProject(); $category = $this->getCategory(); - if ($this->category->remove($category['id'])) { + if ($this->categoryModel->remove($category['id'])) { $this->flash->success(t('Category removed successfully.')); } else { $this->flash->failure(t('Unable to remove this category.')); diff --git a/app/Controller/ColumnController.php b/app/Controller/ColumnController.php index 5f04f426..8bf3d562 100644 --- a/app/Controller/ColumnController.php +++ b/app/Controller/ColumnController.php @@ -20,7 +20,7 @@ class ColumnController extends BaseController public function index() { $project = $this->getProject(); - $columns = $this->column->getAll($project['id']); + $columns = $this->columnModel->getAll($project['id']); $this->response->html($this->helper->layout->project('column/index', array( 'columns' => $columns, @@ -66,7 +66,7 @@ class ColumnController extends BaseController list($valid, $errors) = $this->columnValidator->validateCreation($values); if ($valid) { - if ($this->column->create($project['id'], $values['title'], $values['task_limit'], $values['description'])) { + if ($this->columnModel->create($project['id'], $values['title'], $values['task_limit'], $values['description'])) { $this->flash->success(t('Column created successfully.')); return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id'])), true); } else { @@ -87,7 +87,7 @@ class ColumnController extends BaseController public function edit(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $column = $this->column->getById($this->request->getIntegerParam('column_id')); + $column = $this->columnModel->getById($this->request->getIntegerParam('column_id')); $this->response->html($this->helper->layout->project('column/edit', array( 'errors' => $errors, @@ -111,7 +111,7 @@ class ColumnController extends BaseController list($valid, $errors) = $this->columnValidator->validateModification($values); if ($valid) { - if ($this->column->update($values['id'], $values['title'], $values['task_limit'], $values['description'])) { + if ($this->columnModel->update($values['id'], $values['title'], $values['task_limit'], $values['description'])) { $this->flash->success(t('Board updated successfully.')); return $this->response->redirect($this->helper->url->to('ColumnController', 'index', array('project_id' => $project['id']))); } else { @@ -133,7 +133,7 @@ class ColumnController extends BaseController $values = $this->request->getJson(); if (! empty($values) && isset($values['column_id']) && isset($values['position'])) { - $result = $this->column->changePosition($project['id'], $values['column_id'], $values['position']); + $result = $this->columnModel->changePosition($project['id'], $values['column_id'], $values['position']); $this->response->json(array('result' => $result)); } else { throw new AccessForbiddenException(); @@ -150,7 +150,7 @@ class ColumnController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project('column/remove', array( - 'column' => $this->column->getById($this->request->getIntegerParam('column_id')), + 'column' => $this->columnModel->getById($this->request->getIntegerParam('column_id')), 'project' => $project, 'title' => t('Remove a column from a board') ))); @@ -167,7 +167,7 @@ class ColumnController extends BaseController $this->checkCSRFParam(); $column_id = $this->request->getIntegerParam('column_id'); - if ($this->column->remove($column_id)) { + if ($this->columnModel->remove($column_id)) { $this->flash->success(t('Column removed successfully.')); } else { $this->flash->failure(t('Unable to remove this column.')); diff --git a/app/Controller/CommentController.php b/app/Controller/CommentController.php index 8d1132ae..696d240f 100644 --- a/app/Controller/CommentController.php +++ b/app/Controller/CommentController.php @@ -23,7 +23,7 @@ class CommentController extends BaseController */ private function getComment() { - $comment = $this->comment->getById($this->request->getIntegerParam('comment_id')); + $comment = $this->commentModel->getById($this->request->getIntegerParam('comment_id')); if (empty($comment)) { throw new PageNotFoundException(); @@ -76,7 +76,7 @@ class CommentController extends BaseController list($valid, $errors) = $this->commentValidator->validateCreation($values); if ($valid) { - if ($this->comment->create($values)) { + if ($this->commentModel->create($values)) { $this->flash->success(t('Comment added successfully.')); } else { $this->flash->failure(t('Unable to create your comment.')); @@ -125,7 +125,7 @@ class CommentController extends BaseController list($valid, $errors) = $this->commentValidator->validateModification($values); if ($valid) { - if ($this->comment->update($values)) { + if ($this->commentModel->update($values)) { $this->flash->success(t('Comment updated successfully.')); } else { $this->flash->failure(t('Unable to update your comment.')); @@ -165,7 +165,7 @@ class CommentController extends BaseController $task = $this->getTask(); $comment = $this->getComment(); - if ($this->comment->remove($comment['id'])) { + if ($this->commentModel->remove($comment['id'])) { $this->flash->success(t('Comment removed successfully.')); } else { $this->flash->failure(t('Unable to remove this comment.')); diff --git a/app/Controller/ConfigController.php b/app/Controller/ConfigController.php index a5af0246..8bcf4c35 100644 --- a/app/Controller/ConfigController.php +++ b/app/Controller/ConfigController.php @@ -18,7 +18,7 @@ class ConfigController extends BaseController public function index() { $this->response->html($this->helper->layout->config('config/about', array( - 'db_size' => $this->config->getDatabaseSize(), + 'db_size' => $this->configModel->getDatabaseSize(), 'db_version' => $this->db->getDriver()->getDatabaseVersion(), 'user_agent' => $this->request->getServerVariable('HTTP_USER_AGENT'), 'title' => t('Settings').' > '.t('About'), @@ -54,8 +54,8 @@ class ConfigController extends BaseController break; } - if ($this->config->save($values)) { - $this->language->loadCurrentLanguage(); + if ($this->configModel->save($values)) { + $this->languageModel->loadCurrentLanguage(); $this->flash->success(t('Settings saved successfully.')); } else { $this->flash->failure(t('Unable to save your settings.')); @@ -72,8 +72,8 @@ class ConfigController extends BaseController public function application() { $this->response->html($this->helper->layout->config('config/application', array( - 'languages' => $this->language->getLanguages(), - 'timezones' => $this->timezone->getTimezones(), + 'languages' => $this->languageModel->getLanguages(), + 'timezones' => $this->timezoneModel->getTimezones(), 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), 'datetime_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateTimeFormats()), 'time_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getTimeFormats()), @@ -89,8 +89,8 @@ class ConfigController extends BaseController public function project() { $this->response->html($this->helper->layout->config('config/project', array( - 'colors' => $this->color->getList(), - 'default_columns' => implode(', ', $this->board->getDefaultColumns()), + 'colors' => $this->colorModel->getList(), + 'default_columns' => implode(', ', $this->boardModel->getDefaultColumns()), 'title' => t('Settings').' > '.t('Project settings'), ))); } @@ -164,7 +164,7 @@ class ConfigController extends BaseController { $this->checkCSRFParam(); $this->response->withFileDownload('db.sqlite.gz'); - $this->response->binary($this->config->downloadDatabase()); + $this->response->binary($this->configModel->downloadDatabase()); } /** @@ -175,7 +175,7 @@ class ConfigController extends BaseController public function optimizeDb() { $this->checkCSRFParam(); - $this->config->optimizeDatabase(); + $this->configModel->optimizeDatabase(); $this->flash->success(t('Database optimization done.')); $this->response->redirect($this->helper->url->to('ConfigController', 'index')); } @@ -190,7 +190,7 @@ class ConfigController extends BaseController $type = $this->request->getStringParam('type'); $this->checkCSRFParam(); - $this->config->regenerateToken($type.'_token'); + $this->configModel->regenerateToken($type.'_token'); $this->flash->success(t('Token regenerated.')); $this->response->redirect($this->helper->url->to('ConfigController', $type)); diff --git a/app/Controller/CurrencyController.php b/app/Controller/CurrencyController.php index 5a0fac37..ad590035 100644 --- a/app/Controller/CurrencyController.php +++ b/app/Controller/CurrencyController.php @@ -20,11 +20,11 @@ class CurrencyController extends BaseController public function index(array $values = array(), array $errors = array()) { $this->response->html($this->helper->layout->config('currency/index', array( - 'config_values' => array('application_currency' => $this->config->get('application_currency')), + 'config_values' => array('application_currency' => $this->configModel->get('application_currency')), 'values' => $values, 'errors' => $errors, - 'rates' => $this->currency->getAll(), - 'currencies' => $this->currency->getCurrencies(), + 'rates' => $this->currencyModel->getAll(), + 'currencies' => $this->currencyModel->getCurrencies(), 'title' => t('Settings').' > '.t('Currency rates'), ))); } @@ -40,7 +40,7 @@ class CurrencyController extends BaseController list($valid, $errors) = $this->currencyValidator->validateCreation($values); if ($valid) { - if ($this->currency->create($values['currency'], $values['rate'])) { + if ($this->currencyModel->create($values['currency'], $values['rate'])) { $this->flash->success(t('The currency rate have been added successfully.')); return $this->response->redirect($this->helper->url->to('CurrencyController', 'index')); } else { @@ -60,7 +60,7 @@ class CurrencyController extends BaseController { $values = $this->request->getValues(); - if ($this->config->save($values)) { + if ($this->configModel->save($values)) { $this->flash->success(t('Settings saved successfully.')); } else { $this->flash->failure(t('Unable to save your settings.')); diff --git a/app/Controller/CustomFilterController.php b/app/Controller/CustomFilterController.php index 8dd98764..8bba0856 100644 --- a/app/Controller/CustomFilterController.php +++ b/app/Controller/CustomFilterController.php @@ -27,7 +27,7 @@ class CustomFilterController extends BaseController 'values' => $values + array('project_id' => $project['id']), 'errors' => $errors, 'project' => $project, - 'custom_filters' => $this->customFilter->getAll($project['id'], $this->userSession->getId()), + 'custom_filters' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()), 'title' => t('Custom filters'), ))); } @@ -47,7 +47,7 @@ class CustomFilterController extends BaseController list($valid, $errors) = $this->customFilterValidator->validateCreation($values); if ($valid) { - if ($this->customFilter->create($values)) { + if ($this->customFilterModel->create($values)) { $this->flash->success(t('Your custom filter have been created successfully.')); return $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); } else { @@ -66,7 +66,7 @@ class CustomFilterController extends BaseController public function confirm() { $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + $filter = $this->customFilterModel->getById($this->request->getIntegerParam('filter_id')); $this->response->html($this->helper->layout->project('custom_filter/remove', array( 'project' => $project, @@ -84,11 +84,11 @@ class CustomFilterController extends BaseController { $this->checkCSRFParam(); $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + $filter = $this->customFilterModel->getById($this->request->getIntegerParam('filter_id')); $this->checkPermission($project, $filter); - if ($this->customFilter->remove($filter['id'])) { + if ($this->customFilterModel->remove($filter['id'])) { $this->flash->success(t('Custom filter removed successfully.')); } else { $this->flash->failure(t('Unable to remove this custom filter.')); @@ -105,7 +105,7 @@ class CustomFilterController extends BaseController public function edit(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + $filter = $this->customFilterModel->getById($this->request->getIntegerParam('filter_id')); $this->checkPermission($project, $filter); @@ -126,7 +126,7 @@ class CustomFilterController extends BaseController public function update() { $project = $this->getProject(); - $filter = $this->customFilter->getById($this->request->getIntegerParam('filter_id')); + $filter = $this->customFilterModel->getById($this->request->getIntegerParam('filter_id')); $this->checkPermission($project, $filter); @@ -143,7 +143,7 @@ class CustomFilterController extends BaseController list($valid, $errors) = $this->customFilterValidator->validateModification($values); if ($valid) { - if ($this->customFilter->update($values)) { + if ($this->customFilterModel->update($values)) { $this->flash->success(t('Your custom filter have been updated successfully.')); return $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); } else { @@ -158,7 +158,7 @@ class CustomFilterController extends BaseController { $user_id = $this->userSession->getId(); - if ($filter['user_id'] != $user_id && ($this->projectUserRole->getUserRole($project['id'], $user_id) === Role::PROJECT_MANAGER || ! $this->userSession->isAdmin())) { + if ($filter['user_id'] != $user_id && ($this->projectUserRoleModel->getUserRole($project['id'], $user_id) === Role::PROJECT_MANAGER || ! $this->userSession->isAdmin())) { throw new AccessForbiddenException(); } } diff --git a/app/Controller/DashboardController.php b/app/Controller/DashboardController.php index 145e0bff..44874546 100644 --- a/app/Controller/DashboardController.php +++ b/app/Controller/DashboardController.php @@ -2,8 +2,8 @@ namespace Kanboard\Controller; -use Kanboard\Model\Project as ProjectModel; -use Kanboard\Model\Subtask as SubtaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\SubtaskModel; /** * Dashboard Controller @@ -28,7 +28,7 @@ class DashboardController extends BaseController ->setUrl('DashboardController', $action, array('pagination' => 'projects', 'user_id' => $user_id)) ->setMax($max) ->setOrder(ProjectModel::TABLE.'.name') - ->setQuery($this->project->getQueryColumnStats($this->projectPermission->getActiveProjectIds($user_id))) + ->setQuery($this->projectModel->getQueryColumnStats($this->projectPermissionModel->getActiveProjectIds($user_id))) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'projects'); } @@ -47,7 +47,7 @@ class DashboardController extends BaseController ->setUrl('DashboardController', $action, array('pagination' => 'tasks', 'user_id' => $user_id)) ->setMax($max) ->setOrder('tasks.id') - ->setQuery($this->taskFinder->getUserQuery($user_id)) + ->setQuery($this->taskFinderModel->getUserQuery($user_id)) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks'); } @@ -66,7 +66,7 @@ class DashboardController extends BaseController ->setUrl('DashboardController', $action, array('pagination' => 'subtasks', 'user_id' => $user_id)) ->setMax($max) ->setOrder('tasks.id') - ->setQuery($this->subtask->getUserQuery($user_id, array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))) + ->setQuery($this->subtaskModel->getUserQuery($user_id, array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); } @@ -147,7 +147,7 @@ class DashboardController extends BaseController $this->response->html($this->helper->layout->dashboard('dashboard/activity', array( 'title' => t('My activity stream'), - 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermission->getActiveProjectIds($user['id']), 100), + 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermissionModel->getActiveProjectIds($user['id']), 100), 'user' => $user, ))); } @@ -176,7 +176,7 @@ class DashboardController extends BaseController $this->response->html($this->helper->layout->dashboard('dashboard/notifications', array( 'title' => t('My notifications'), - 'notifications' => $this->userUnreadNotification->getAll($user['id']), + 'notifications' => $this->userUnreadNotificationModel->getAll($user['id']), 'user' => $user, ))); } diff --git a/app/Controller/DocumentationController.php b/app/Controller/DocumentationController.php index 379e3dab..d86fb3c8 100644 --- a/app/Controller/DocumentationController.php +++ b/app/Controller/DocumentationController.php @@ -20,7 +20,7 @@ class DocumentationController extends BaseController $page = 'index'; } - if ($this->language->getCurrentLanguage() === 'fr_FR') { + if ($this->languageModel->getCurrentLanguage() === 'fr_FR') { $filename = __DIR__.'/../../doc/fr/' . $page . '.markdown'; } else { $filename = __DIR__ . '/../../doc/' . $page . '.markdown'; @@ -83,7 +83,7 @@ class DocumentationController extends BaseController */ public function replaceImageUrl(array $matches) { - if ($this->language->getCurrentLanguage() === 'fr_FR') { + if ($this->languageModel->getCurrentLanguage() === 'fr_FR') { return '('.$this->helper->url->base().'doc/fr/'.$matches[1].')'; } diff --git a/app/Controller/ExportController.php b/app/Controller/ExportController.php index 4ed9ee08..b2fe0ebd 100644 --- a/app/Controller/ExportController.php +++ b/app/Controller/ExportController.php @@ -42,7 +42,7 @@ class ExportController extends BaseController 'to' => $to, ), 'errors' => array(), - 'date_format' => $this->config->get('application_date_format'), + 'date_format' => $this->configModel->get('application_date_format'), 'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()), 'project' => $project, 'title' => $page_title, diff --git a/app/Controller/FeedController.php b/app/Controller/FeedController.php index e453ecb9..cf2b1088 100644 --- a/app/Controller/FeedController.php +++ b/app/Controller/FeedController.php @@ -20,7 +20,7 @@ class FeedController extends BaseController public function user() { $token = $this->request->getStringParam('token'); - $user = $this->user->getByToken($token); + $user = $this->userModel->getByToken($token); // Token verification if (empty($user)) { @@ -28,7 +28,7 @@ class FeedController extends BaseController } $this->response->xml($this->template->render('feed/user', array( - 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermission->getActiveProjectIds($user['id'])), + 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermissionModel->getActiveProjectIds($user['id'])), 'user' => $user, ))); } @@ -41,7 +41,7 @@ class FeedController extends BaseController public function project() { $token = $this->request->getStringParam('token'); - $project = $this->project->getByToken($token); + $project = $this->projectModel->getByToken($token); if (empty($project)) { throw AccessForbiddenException::getInstance()->withoutLayout(); diff --git a/app/Controller/GroupCreationController.php b/app/Controller/GroupCreationController.php index 7d0bb93c..b297b19f 100644 --- a/app/Controller/GroupCreationController.php +++ b/app/Controller/GroupCreationController.php @@ -36,7 +36,7 @@ class GroupCreationController extends BaseController list($valid, $errors) = $this->groupValidator->validateCreation($values); if ($valid) { - if ($this->group->create($values['name']) !== false) { + if ($this->groupModel->create($values['name']) !== false) { $this->flash->success(t('Group created successfully.')); return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true); } else { diff --git a/app/Controller/GroupListController.php b/app/Controller/GroupListController.php index 17f3b2a9..4486bbff 100644 --- a/app/Controller/GroupListController.php +++ b/app/Controller/GroupListController.php @@ -21,7 +21,7 @@ class GroupListController extends BaseController ->setUrl('GroupListController', 'index') ->setMax(30) ->setOrder('name') - ->setQuery($this->group->getQuery()) + ->setQuery($this->groupModel->getQuery()) ->calculate(); $this->response->html($this->helper->layout->app('group/index', array( @@ -38,13 +38,13 @@ class GroupListController extends BaseController public function users() { $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); + $group = $this->groupModel->getById($group_id); $paginator = $this->paginator ->setUrl('GroupListController', 'users', array('group_id' => $group_id)) ->setMax(30) ->setOrder('username') - ->setQuery($this->groupMember->getQuery($group_id)) + ->setQuery($this->groupMemberModel->getQuery($group_id)) ->calculate(); $this->response->html($this->helper->layout->app('group/users', array( @@ -64,14 +64,14 @@ class GroupListController extends BaseController public function associate(array $values = array(), array $errors = array()) { $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); + $group = $this->groupModel->getById($group_id); if (empty($values)) { $values['group_id'] = $group_id; } $this->response->html($this->template->render('group/associate', array( - 'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)), + 'users' => $this->userModel->prepareList($this->groupMemberModel->getNotMembers($group_id)), 'group' => $group, 'errors' => $errors, 'values' => $values, @@ -88,7 +88,7 @@ class GroupListController extends BaseController $values = $this->request->getValues(); if (isset($values['group_id']) && isset($values['user_id'])) { - if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) { + if ($this->groupMemberModel->addUser($values['group_id'], $values['user_id'])) { $this->flash->success(t('Group member added successfully.')); return $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $values['group_id'])), true); } else { @@ -108,8 +108,8 @@ class GroupListController extends BaseController { $group_id = $this->request->getIntegerParam('group_id'); $user_id = $this->request->getIntegerParam('user_id'); - $group = $this->group->getById($group_id); - $user = $this->user->getById($user_id); + $group = $this->groupModel->getById($group_id); + $user = $this->userModel->getById($user_id); $this->response->html($this->template->render('group/dissociate', array( 'group' => $group, @@ -128,7 +128,7 @@ class GroupListController extends BaseController $group_id = $this->request->getIntegerParam('group_id'); $user_id = $this->request->getIntegerParam('user_id'); - if ($this->groupMember->removeUser($group_id, $user_id)) { + if ($this->groupMemberModel->removeUser($group_id, $user_id)) { $this->flash->success(t('User removed successfully from this group.')); } else { $this->flash->failure(t('Unable to remove this user from the group.')); @@ -145,7 +145,7 @@ class GroupListController extends BaseController public function confirm() { $group_id = $this->request->getIntegerParam('group_id'); - $group = $this->group->getById($group_id); + $group = $this->groupModel->getById($group_id); $this->response->html($this->template->render('group/remove', array( 'group' => $group, @@ -162,7 +162,7 @@ class GroupListController extends BaseController $this->checkCSRFParam(); $group_id = $this->request->getIntegerParam('group_id'); - if ($this->group->remove($group_id)) { + if ($this->groupModel->remove($group_id)) { $this->flash->success(t('Group removed successfully.')); } else { $this->flash->failure(t('Unable to remove this group.')); diff --git a/app/Controller/GroupModificationController.php b/app/Controller/GroupModificationController.php index 1f225a14..bd181b74 100644 --- a/app/Controller/GroupModificationController.php +++ b/app/Controller/GroupModificationController.php @@ -20,7 +20,7 @@ class GroupModificationController extends BaseController public function show(array $values = array(), array $errors = array()) { if (empty($values)) { - $values = $this->group->getById($this->request->getIntegerParam('group_id')); + $values = $this->groupModel->getById($this->request->getIntegerParam('group_id')); } $this->response->html($this->template->render('group_modification/show', array( @@ -40,7 +40,7 @@ class GroupModificationController extends BaseController list($valid, $errors) = $this->groupValidator->validateModification($values); if ($valid) { - if ($this->group->update($values) !== false) { + if ($this->groupModel->update($values) !== false) { $this->flash->success(t('Group updated successfully.')); return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true); } else { diff --git a/app/Controller/ICalendarController.php b/app/Controller/ICalendarController.php index 78ea4d67..e354c6f1 100644 --- a/app/Controller/ICalendarController.php +++ b/app/Controller/ICalendarController.php @@ -8,7 +8,7 @@ use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Filter\TaskStatusFilter; use Kanboard\Formatter\TaskICalFormatter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; use Eluceo\iCal\Component\Calendar as iCalendar; /** @@ -27,7 +27,7 @@ class ICalendarController extends BaseController public function user() { $token = $this->request->getStringParam('token'); - $user = $this->user->getByToken($token); + $user = $this->userModel->getByToken($token); // Token verification if (empty($user)) { @@ -37,7 +37,7 @@ class ICalendarController extends BaseController // Common filter $queryBuilder = new QueryBuilder(); $queryBuilder - ->withQuery($this->taskFinder->getICalQuery()) + ->withQuery($this->taskFinderModel->getICalQuery()) ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)) ->withFilter(new TaskAssigneeFilter($user['id'])); @@ -58,7 +58,7 @@ class ICalendarController extends BaseController public function project() { $token = $this->request->getStringParam('token'); - $project = $this->project->getByToken($token); + $project = $this->projectModel->getByToken($token); // Token verification if (empty($project)) { @@ -68,7 +68,7 @@ class ICalendarController extends BaseController // Common filter $queryBuilder = new QueryBuilder(); $queryBuilder - ->withQuery($this->taskFinder->getICalQuery()) + ->withQuery($this->taskFinderModel->getICalQuery()) ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN)) ->withFilter(new TaskProjectFilter($project['id'])); diff --git a/app/Controller/LinkController.php b/app/Controller/LinkController.php index 08627d40..477b25a4 100644 --- a/app/Controller/LinkController.php +++ b/app/Controller/LinkController.php @@ -22,7 +22,7 @@ class LinkController extends BaseController */ private function getLink() { - $link = $this->link->getById($this->request->getIntegerParam('link_id')); + $link = $this->linkModel->getById($this->request->getIntegerParam('link_id')); if (empty($link)) { throw new PageNotFoundException(); @@ -41,7 +41,7 @@ class LinkController extends BaseController public function index(array $values = array(), array $errors = array()) { $this->response->html($this->helper->layout->config('link/index', array( - 'links' => $this->link->getMergedList(), + 'links' => $this->linkModel->getMergedList(), 'values' => $values, 'errors' => $errors, 'title' => t('Settings').' > '.t('Task\'s links'), @@ -59,7 +59,7 @@ class LinkController extends BaseController list($valid, $errors) = $this->linkValidator->validateCreation($values); if ($valid) { - if ($this->link->create($values['label'], $values['opposite_label']) !== false) { + if ($this->linkModel->create($values['label'], $values['opposite_label']) !== false) { $this->flash->success(t('Link added successfully.')); return $this->response->redirect($this->helper->url->to('LinkController', 'index')); } else { @@ -86,7 +86,7 @@ class LinkController extends BaseController $this->response->html($this->helper->layout->config('link/edit', array( 'values' => $values ?: $link, 'errors' => $errors, - 'labels' => $this->link->getList($link['id']), + 'labels' => $this->linkModel->getList($link['id']), 'link' => $link, 'title' => t('Link modification') ))); @@ -103,7 +103,7 @@ class LinkController extends BaseController list($valid, $errors) = $this->linkValidator->validateModification($values); if ($valid) { - if ($this->link->update($values)) { + if ($this->linkModel->update($values)) { $this->flash->success(t('Link updated successfully.')); return $this->response->redirect($this->helper->url->to('LinkController', 'index')); } else { @@ -139,7 +139,7 @@ class LinkController extends BaseController $this->checkCSRFParam(); $link = $this->getLink(); - if ($this->link->remove($link['id'])) { + if ($this->linkModel->remove($link['id'])) { $this->flash->success(t('Link removed successfully.')); } else { $this->flash->failure(t('Unable to remove this link.')); diff --git a/app/Controller/PasswordResetController.php b/app/Controller/PasswordResetController.php index 9036b3e7..18b4be80 100644 --- a/app/Controller/PasswordResetController.php +++ b/app/Controller/PasswordResetController.php @@ -52,7 +52,7 @@ class PasswordResetController extends BaseController $this->checkActivation(); $token = $this->request->getStringParam('token'); - $user_id = $this->passwordReset->getUserIdByToken($token); + $user_id = $this->passwordResetModel->getUserIdByToken($token); if ($user_id !== false) { $this->response->html($this->helper->layout->app('password_reset/change', array( @@ -78,11 +78,11 @@ class PasswordResetController extends BaseController list($valid, $errors) = $this->passwordResetValidator->validateModification($values); if ($valid) { - $user_id = $this->passwordReset->getUserIdByToken($token); + $user_id = $this->passwordResetModel->getUserIdByToken($token); if ($user_id !== false) { - $this->user->update(array('id' => $user_id, 'password' => $values['password'])); - $this->passwordReset->disable($user_id); + $this->userModel->update(array('id' => $user_id, 'password' => $values['password'])); + $this->passwordResetModel->disable($user_id); } return $this->response->redirect($this->helper->url->to('AuthController', 'login')); @@ -96,10 +96,10 @@ class PasswordResetController extends BaseController */ private function sendEmail($username) { - $token = $this->passwordReset->create($username); + $token = $this->passwordResetModel->create($username); if ($token !== false) { - $user = $this->user->getByUsername($username); + $user = $this->userModel->getByUsername($username); $this->emailClient->send( $user['email'], @@ -115,7 +115,7 @@ class PasswordResetController extends BaseController */ private function checkActivation() { - if ($this->config->get('password_reset', 0) == 0) { + if ($this->configModel->get('password_reset', 0) == 0) { throw AccessForbiddenException::getInstance()->withoutLayout(); } } diff --git a/app/Controller/ProjectActionDuplicationController.php b/app/Controller/ProjectActionDuplicationController.php index 790b7ed3..a4993cca 100644 --- a/app/Controller/ProjectActionDuplicationController.php +++ b/app/Controller/ProjectActionDuplicationController.php @@ -13,7 +13,7 @@ class ProjectActionDuplicationController extends BaseController public function show() { $project = $this->getProject(); - $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + $projects = $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); unset($projects[$project['id']]); $this->response->html($this->template->render('project_action_duplication/show', array( @@ -27,7 +27,7 @@ class ProjectActionDuplicationController extends BaseController $project = $this->getProject(); $src_project_id = $this->request->getValue('src_project_id'); - if ($this->action->duplicate($src_project_id, $project['id'])) { + if ($this->actionModel->duplicate($src_project_id, $project['id'])) { $this->flash->success(t('Actions duplicated successfully.')); } else { $this->flash->failure(t('Unable to duplicate actions.')); diff --git a/app/Controller/ProjectCreationController.php b/app/Controller/ProjectCreationController.php index 4166ead1..c471cfdd 100644 --- a/app/Controller/ProjectCreationController.php +++ b/app/Controller/ProjectCreationController.php @@ -20,7 +20,7 @@ class ProjectCreationController extends BaseController public function create(array $values = array(), array $errors = array()) { $is_private = isset($values['is_private']) && $values['is_private'] == 1; - $projects_list = array(0 => t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + $projects_list = array(0 => t('Do not duplicate anything')) + $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); $this->response->html($this->helper->layout->app('project_creation/create', array( 'values' => $values, @@ -98,7 +98,7 @@ class ProjectCreationController extends BaseController 'is_private' => $values['is_private'], ); - return $this->project->create($project, $this->userSession->getId(), true); + return $this->projectModel->create($project, $this->userSession->getId(), true); } /** @@ -112,13 +112,13 @@ class ProjectCreationController extends BaseController { $selection = array(); - foreach ($this->projectDuplication->getOptionalSelection() as $item) { + foreach ($this->projectDuplicationModel->getOptionalSelection() as $item) { if (isset($values[$item]) && $values[$item] == 1) { $selection[] = $item; } } - return $this->projectDuplication->duplicate( + return $this->projectDuplicationModel->duplicate( $values['src_project_id'], $selection, $this->userSession->getId(), diff --git a/app/Controller/ProjectEditController.php b/app/Controller/ProjectEditController.php index 64e02d1a..228d681c 100644 --- a/app/Controller/ProjectEditController.php +++ b/app/Controller/ProjectEditController.php @@ -73,7 +73,7 @@ class ProjectEditController extends BaseController list($valid, $errors) = $this->projectValidator->validateModification($values); if ($valid) { - if ($this->project->update($values)) { + if ($this->projectModel->update($values)) { $this->flash->success(t('Project updated successfully.')); return $this->response->redirect($this->helper->url->to('ProjectEditController', $redirect, array('project_id' => $project['id'])), true); } else { @@ -123,7 +123,7 @@ class ProjectEditController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project($template, array( - 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true), + 'owners' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true), 'values' => empty($values) ? $project : $values, 'errors' => $errors, 'project' => $project, diff --git a/app/Controller/ProjectFileController.php b/app/Controller/ProjectFileController.php index f1bce09d..cbe48679 100644 --- a/app/Controller/ProjectFileController.php +++ b/app/Controller/ProjectFileController.php @@ -34,7 +34,7 @@ class ProjectFileController extends BaseController { $project = $this->getProject(); - if (! $this->projectFile->uploadFiles($project['id'], $this->request->getFileInfo('files'))) { + if (! $this->projectFileModel->uploadFiles($project['id'], $this->request->getFileInfo('files'))) { $this->flash->failure(t('Unable to upload the file.')); } @@ -50,9 +50,9 @@ class ProjectFileController extends BaseController { $this->checkCSRFParam(); $project = $this->getProject(); - $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + $file = $this->projectFileModel->getById($this->request->getIntegerParam('file_id')); - if ($this->projectFile->remove($file['id'])) { + if ($this->projectFileModel->remove($file['id'])) { $this->flash->success(t('File removed successfully.')); } else { $this->flash->failure(t('Unable to remove this file.')); @@ -69,7 +69,7 @@ class ProjectFileController extends BaseController public function confirm() { $project = $this->getProject(); - $file = $this->projectFile->getById($this->request->getIntegerParam('file_id')); + $file = $this->projectFileModel->getById($this->request->getIntegerParam('file_id')); $this->response->html($this->template->render('project_file/remove', array( 'project' => $project, diff --git a/app/Controller/ProjectGanttController.php b/app/Controller/ProjectGanttController.php index 1c6ace58..a70d9eee 100644 --- a/app/Controller/ProjectGanttController.php +++ b/app/Controller/ProjectGanttController.php @@ -6,7 +6,7 @@ use Kanboard\Filter\ProjectIdsFilter; use Kanboard\Filter\ProjectStatusFilter; use Kanboard\Filter\ProjectTypeFilter; use Kanboard\Formatter\ProjectGanttFormatter; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Projects Gantt Controller @@ -21,13 +21,13 @@ class ProjectGanttController extends BaseController */ public function show() { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); $filter = $this->projectQuery - ->withFilter(new ProjectTypeFilter(Project::TYPE_TEAM)) - ->withFilter(new ProjectStatusFilter(Project::ACTIVE)) + ->withFilter(new ProjectTypeFilter(ProjectModel::TYPE_TEAM)) + ->withFilter(new ProjectStatusFilter(ProjectModel::ACTIVE)) ->withFilter(new ProjectIdsFilter($project_ids)); - $filter->getQuery()->asc(Project::TABLE.'.start_date'); + $filter->getQuery()->asc(ProjectModel::TABLE.'.start_date'); $this->response->html($this->helper->layout->app('project_gantt/show', array( 'projects' => $filter->format(new ProjectGanttFormatter($this->container)), @@ -42,7 +42,7 @@ class ProjectGanttController extends BaseController { $values = $this->request->getJson(); - $result = $this->project->update(array( + $result = $this->projectModel->update(array( 'id' => $values['id'], 'start_date' => $this->dateParser->getIsoDate(strtotime($values['start'])), 'end_date' => $this->dateParser->getIsoDate(strtotime($values['end'])), diff --git a/app/Controller/ProjectListController.php b/app/Controller/ProjectListController.php index 5571b3c9..e1172400 100644 --- a/app/Controller/ProjectListController.php +++ b/app/Controller/ProjectListController.php @@ -18,9 +18,9 @@ class ProjectListController extends BaseController public function show() { if ($this->userSession->isAdmin()) { - $project_ids = $this->project->getAllIds(); + $project_ids = $this->projectModel->getAllIds(); } else { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); } $nb_projects = count($project_ids); @@ -29,7 +29,7 @@ class ProjectListController extends BaseController ->setUrl('ProjectListController', 'show') ->setMax(20) ->setOrder('name') - ->setQuery($this->project->getQueryColumnStats($project_ids)) + ->setQuery($this->projectModel->getQueryColumnStats($project_ids)) ->calculate(); $this->response->html($this->helper->layout->app('project_list/show', array( diff --git a/app/Controller/ProjectOverviewController.php b/app/Controller/ProjectOverviewController.php index 75cf25ba..abdff657 100644 --- a/app/Controller/ProjectOverviewController.php +++ b/app/Controller/ProjectOverviewController.php @@ -16,17 +16,17 @@ class ProjectOverviewController extends BaseController public function show() { $project = $this->getProject(); - $this->project->getColumnStats($project); + $this->projectModel->getColumnStats($project); $this->response->html($this->helper->layout->app('project_overview/show', array( 'project' => $project, 'title' => $project['name'], 'description' => $this->helper->projectHeader->getDescription($project), - 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), + 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), 'roles' => $this->role->getProjectRoles(), 'events' => $this->helper->projectActivity->getProjectEvents($project['id'], 10), - 'images' => $this->projectFile->getAllImages($project['id']), - 'files' => $this->projectFile->getAllDocuments($project['id']), + 'images' => $this->projectFileModel->getAllImages($project['id']), + 'files' => $this->projectFileModel->getAllDocuments($project['id']), ))); } } diff --git a/app/Controller/ProjectPermissionController.php b/app/Controller/ProjectPermissionController.php index d27681b1..f3ca6ed9 100644 --- a/app/Controller/ProjectPermissionController.php +++ b/app/Controller/ProjectPermissionController.php @@ -50,8 +50,8 @@ class ProjectPermissionController extends BaseController $this->response->html($this->helper->layout->project('project_permission/index', array( 'project' => $project, - 'users' => $this->projectUserRole->getUsers($project['id']), - 'groups' => $this->projectGroupRole->getGroups($project['id']), + 'users' => $this->projectUserRoleModel->getUsers($project['id']), + 'groups' => $this->projectGroupRoleModel->getGroups($project['id']), 'roles' => $this->role->getProjectRoles(), 'values' => $values, 'errors' => $errors, @@ -69,7 +69,7 @@ class ProjectPermissionController extends BaseController $project = $this->getProject(); $values = $this->request->getValues() + array('is_everybody_allowed' => 0); - if ($this->project->update($values)) { + if ($this->projectModel->update($values)) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -90,7 +90,7 @@ class ProjectPermissionController extends BaseController if (empty($values['user_id'])) { $this->flash->failure(t('User not found.')); - } elseif ($this->projectUserRole->addUser($values['project_id'], $values['user_id'], $values['role'])) { + } elseif ($this->projectUserRoleModel->addUser($values['project_id'], $values['user_id'], $values['role'])) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -110,7 +110,7 @@ class ProjectPermissionController extends BaseController $project = $this->getProject(); $user_id = $this->request->getIntegerParam('user_id'); - if ($this->projectUserRole->removeUser($project['id'], $user_id)) { + if ($this->projectUserRoleModel->removeUser($project['id'], $user_id)) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -129,7 +129,7 @@ class ProjectPermissionController extends BaseController $project = $this->getProject(); $values = $this->request->getJson(); - if (! empty($project) && ! empty($values) && $this->projectUserRole->changeUserRole($project['id'], $values['id'], $values['role'])) { + if (! empty($project) && ! empty($values) && $this->projectUserRoleModel->changeUserRole($project['id'], $values['id'], $values['role'])) { $this->response->json(array('status' => 'ok')); } else { $this->response->json(array('status' => 'error')); @@ -147,10 +147,10 @@ class ProjectPermissionController extends BaseController $values = $this->request->getValues(); if (empty($values['group_id']) && ! empty($values['external_id'])) { - $values['group_id'] = $this->group->create($values['name'], $values['external_id']); + $values['group_id'] = $this->groupModel->create($values['name'], $values['external_id']); } - if ($this->projectGroupRole->addGroup($project['id'], $values['group_id'], $values['role'])) { + if ($this->projectGroupRoleModel->addGroup($project['id'], $values['group_id'], $values['role'])) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -170,7 +170,7 @@ class ProjectPermissionController extends BaseController $project = $this->getProject(); $group_id = $this->request->getIntegerParam('group_id'); - if ($this->projectGroupRole->removeGroup($project['id'], $group_id)) { + if ($this->projectGroupRoleModel->removeGroup($project['id'], $group_id)) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -189,7 +189,7 @@ class ProjectPermissionController extends BaseController $project = $this->getProject(); $values = $this->request->getJson(); - if (! empty($project) && ! empty($values) && $this->projectGroupRole->changeGroupRole($project['id'], $values['id'], $values['role'])) { + if (! empty($project) && ! empty($values) && $this->projectGroupRoleModel->changeGroupRole($project['id'], $values['id'], $values['role'])) { $this->response->json(array('status' => 'ok')); } else { $this->response->json(array('status' => 'error')); diff --git a/app/Controller/ProjectStatusController.php b/app/Controller/ProjectStatusController.php index 16ac32b8..78e77870 100644 --- a/app/Controller/ProjectStatusController.php +++ b/app/Controller/ProjectStatusController.php @@ -31,7 +31,7 @@ class ProjectStatusController extends BaseController $project = $this->getProject(); $this->checkCSRFParam(); - if ($this->project->enable($project['id'])) { + if ($this->projectModel->enable($project['id'])) { $this->flash->success(t('Project activated successfully.')); } else { $this->flash->failure(t('Unable to activate this project.')); @@ -61,7 +61,7 @@ class ProjectStatusController extends BaseController $project = $this->getProject(); $this->checkCSRFParam(); - if ($this->project->disable($project['id'])) { + if ($this->projectModel->disable($project['id'])) { $this->flash->success(t('Project disabled successfully.')); } else { $this->flash->failure(t('Unable to disable this project.')); @@ -91,7 +91,7 @@ class ProjectStatusController extends BaseController $project = $this->getProject(); $this->checkCSRFParam(); - if ($this->project->remove($project['id'])) { + if ($this->projectModel->remove($project['id'])) { $this->flash->success(t('Project removed successfully.')); } else { $this->flash->failure(t('Unable to remove this project.')); diff --git a/app/Controller/ProjectUserOverviewController.php b/app/Controller/ProjectUserOverviewController.php index 90887a8a..686de830 100644 --- a/app/Controller/ProjectUserOverviewController.php +++ b/app/Controller/ProjectUserOverviewController.php @@ -2,8 +2,8 @@ namespace Kanboard\Controller; -use Kanboard\Model\User as UserModel; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskModel; use Kanboard\Core\Security\Role; /** @@ -19,19 +19,19 @@ class ProjectUserOverviewController extends BaseController $user_id = $this->request->getIntegerParam('user_id', UserModel::EVERYBODY_ID); if ($this->userSession->isAdmin()) { - $project_ids = $this->project->getAllIds(); + $project_ids = $this->projectModel->getAllIds(); } else { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); } - return array($user_id, $project_ids, $this->user->getActiveUsersList(true)); + return array($user_id, $project_ids, $this->userModel->getActiveUsersList(true)); } private function role($role, $action, $title, $title_user) { list($user_id, $project_ids, $users) = $this->common(); - $query = $this->projectPermission->getQueryByRole($project_ids, $role)->callback(array($this->project, 'applyColumnStats')); + $query = $this->projectPermissionModel->getQueryByRole($project_ids, $role)->callback(array($this->projectModel, 'applyColumnStats')); if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { $query->eq(UserModel::TABLE.'.id', $user_id); @@ -57,7 +57,7 @@ class ProjectUserOverviewController extends BaseController { list($user_id, $project_ids, $users) = $this->common(); - $query = $this->taskFinder->getProjectUserOverviewQuery($project_ids, $is_active); + $query = $this->taskFinderModel->getProjectUserOverviewQuery($project_ids, $is_active); if ($user_id !== UserModel::EVERYBODY_ID && isset($users[$user_id])) { $query->eq(TaskModel::TABLE.'.owner_id', $user_id); @@ -123,7 +123,7 @@ class ProjectUserOverviewController extends BaseController $project = $this->getProject(); return $this->response->html($this->template->render('project_user_overview/tooltip_users', array( - 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), + 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), 'roles' => $this->role->getProjectRoles(), ))); } diff --git a/app/Controller/ProjectViewController.php b/app/Controller/ProjectViewController.php index ca112a41..92b93804 100644 --- a/app/Controller/ProjectViewController.php +++ b/app/Controller/ProjectViewController.php @@ -21,7 +21,7 @@ class ProjectViewController extends BaseController $this->response->html($this->helper->layout->project('project_view/show', array( 'project' => $project, - 'stats' => $this->project->getTaskStats($project['id']), + 'stats' => $this->projectModel->getTaskStats($project['id']), 'title' => $project['name'], ))); } @@ -53,7 +53,7 @@ class ProjectViewController extends BaseController $this->checkCSRFParam(); $switch = $this->request->getStringParam('switch'); - if ($this->project->{$switch.'PublicAccess'}($project['id'])) { + if ($this->projectModel->{$switch.'PublicAccess'}($project['id'])) { $this->flash->success(t('Project updated successfully.')); } else { $this->flash->failure(t('Unable to update this project.')); @@ -74,8 +74,8 @@ class ProjectViewController extends BaseController $this->response->html($this->helper->layout->project('project_view/integrations', array( 'project' => $project, 'title' => t('Integrations'), - 'webhook_token' => $this->config->get('webhook_token'), - 'values' => $this->projectMetadata->getAll($project['id']), + 'webhook_token' => $this->configModel->get('webhook_token'), + 'values' => $this->projectMetadataModel->getAll($project['id']), 'errors' => array(), ))); } @@ -89,7 +89,7 @@ class ProjectViewController extends BaseController { $project = $this->getProject(); - $this->projectMetadata->save($project['id'], $this->request->getValues()); + $this->projectMetadataModel->save($project['id'], $this->request->getValues()); $this->flash->success(t('Project updated successfully.')); $this->response->redirect($this->helper->url->to('ProjectViewController', 'integrations', array('project_id' => $project['id']))); } @@ -104,8 +104,8 @@ class ProjectViewController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project('project_view/notifications', array( - 'notifications' => $this->projectNotification->readSettings($project['id']), - 'types' => $this->projectNotificationType->getTypes(), + 'notifications' => $this->projectNotificationModel->readSettings($project['id']), + 'types' => $this->projectNotificationTypeModel->getTypes(), 'project' => $project, 'title' => t('Notifications'), ))); @@ -121,7 +121,7 @@ class ProjectViewController extends BaseController $project = $this->getProject(); $values = $this->request->getValues(); - $this->projectNotification->saveSettings($project['id'], $values); + $this->projectNotificationModel->saveSettings($project['id'], $values); $this->flash->success(t('Project updated successfully.')); $this->response->redirect($this->helper->url->to('ProjectViewController', 'notifications', array('project_id' => $project['id']))); } @@ -149,7 +149,7 @@ class ProjectViewController extends BaseController public function doDuplication() { $project = $this->getProject(); - $project_id = $this->projectDuplication->duplicate($project['id'], array_keys($this->request->getValues()), $this->userSession->getId()); + $project_id = $this->projectDuplicationModel->duplicate($project['id'], array_keys($this->request->getValues()), $this->userSession->getId()); if ($project_id !== false) { $this->flash->success(t('Project cloned successfully.')); diff --git a/app/Controller/SearchController.php b/app/Controller/SearchController.php index 88718cf7..8557b182 100644 --- a/app/Controller/SearchController.php +++ b/app/Controller/SearchController.php @@ -14,7 +14,7 @@ class SearchController extends BaseController { public function index() { - $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + $projects = $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); $search = urldecode($this->request->getStringParam('search')); $nb_tasks = 0; diff --git a/app/Controller/SubtaskController.php b/app/Controller/SubtaskController.php index 26659fb4..46061122 100644 --- a/app/Controller/SubtaskController.php +++ b/app/Controller/SubtaskController.php @@ -36,7 +36,7 @@ class SubtaskController extends BaseController $this->response->html($this->template->render('subtask/create', array( 'values' => $values, 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']), 'task' => $task, ))); } @@ -54,7 +54,7 @@ class SubtaskController extends BaseController list($valid, $errors) = $this->subtaskValidator->validateCreation($values); if ($valid) { - if ($this->subtask->create($values)) { + if ($this->subtaskModel->create($values)) { $this->flash->success(t('Sub-task added successfully.')); } else { $this->flash->failure(t('Unable to create your sub-task.')); @@ -87,8 +87,8 @@ class SubtaskController extends BaseController $this->response->html($this->template->render('subtask/edit', array( 'values' => empty($values) ? $subtask : $values, 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), - 'status_list' => $this->subtask->getStatusList(), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']), + 'status_list' => $this->subtaskModel->getStatusList(), 'subtask' => $subtask, 'task' => $task, ))); @@ -108,7 +108,7 @@ class SubtaskController extends BaseController list($valid, $errors) = $this->subtaskValidator->validateModification($values); if ($valid) { - if ($this->subtask->update($values)) { + if ($this->subtaskModel->update($values)) { $this->flash->success(t('Sub-task updated successfully.')); } else { $this->flash->failure(t('Unable to update your sub-task.')); @@ -147,7 +147,7 @@ class SubtaskController extends BaseController $task = $this->getTask(); $subtask = $this->getSubtask(); - if ($this->subtask->remove($subtask['id'])) { + if ($this->subtaskModel->remove($subtask['id'])) { $this->flash->success(t('Sub-task removed successfully.')); } else { $this->flash->failure(t('Unable to remove this sub-task.')); @@ -168,7 +168,7 @@ class SubtaskController extends BaseController $values = $this->request->getJson(); if (! empty($values) && $this->helper->user->hasProjectAccess('SubtaskController', 'movePosition', $project_id)) { - $result = $this->subtask->changePosition($task_id, $values['subtask_id'], $values['position']); + $result = $this->subtaskModel->changePosition($task_id, $values['subtask_id'], $values['position']); $this->response->json(array('result' => $result)); } else { throw new AccessForbiddenException(); diff --git a/app/Controller/SubtaskConverterController.php b/app/Controller/SubtaskConverterController.php index 8a3021e2..65bcd2da 100644 --- a/app/Controller/SubtaskConverterController.php +++ b/app/Controller/SubtaskConverterController.php @@ -26,7 +26,7 @@ class SubtaskConverterController extends BaseController $project = $this->getProject(); $subtask = $this->getSubtask(); - $task_id = $this->subtask->convertToTask($project['id'], $subtask['id']); + $task_id = $this->subtaskModel->convertToTask($project['id'], $subtask['id']); if ($task_id !== false) { $this->flash->success(t('Subtask converted to task successfully.')); diff --git a/app/Controller/SubtaskRestrictionController.php b/app/Controller/SubtaskRestrictionController.php index 77626ba9..084fc0d9 100644 --- a/app/Controller/SubtaskRestrictionController.php +++ b/app/Controller/SubtaskRestrictionController.php @@ -2,7 +2,7 @@ namespace Kanboard\Controller; -use Kanboard\Model\Subtask as SubtaskModel; +use Kanboard\Model\SubtaskModel; /** * Subtask Restriction @@ -27,7 +27,7 @@ class SubtaskRestrictionController extends BaseController SubtaskModel::STATUS_TODO => t('Todo'), SubtaskModel::STATUS_DONE => t('Done'), ), - 'subtask_inprogress' => $this->subtask->getSubtaskInProgress($this->userSession->getId()), + 'subtask_inprogress' => $this->subtaskModel->getSubtaskInProgress($this->userSession->getId()), 'subtask' => $subtask, 'task' => $task, ))); @@ -45,13 +45,13 @@ class SubtaskRestrictionController extends BaseController $values = $this->request->getValues(); // Change status of the previous "in progress" subtask - $this->subtask->update(array( + $this->subtaskModel->update(array( 'id' => $values['id'], 'status' => $values['status'], )); // Set the current subtask to "in progress" - $this->subtask->update(array( + $this->subtaskModel->update(array( 'id' => $subtask['id'], 'status' => SubtaskModel::STATUS_INPROGRESS, )); diff --git a/app/Controller/SubtaskStatusController.php b/app/Controller/SubtaskStatusController.php index 909123ec..699951fe 100644 --- a/app/Controller/SubtaskStatusController.php +++ b/app/Controller/SubtaskStatusController.php @@ -20,7 +20,7 @@ class SubtaskStatusController extends BaseController $task = $this->getTask(); $subtask = $this->getSubtask(); - $status = $this->subtask->toggleStatus($subtask['id']); + $status = $this->subtaskModel->toggleStatus($subtask['id']); if ($this->request->getIntegerParam('refresh-table') === 0) { $subtask['status'] = $status; @@ -44,10 +44,10 @@ class SubtaskStatusController extends BaseController $timer = $this->request->getStringParam('timer'); if ($timer === 'start') { - $this->subtaskTimeTracking->logStartTime($subtask_id, $this->userSession->getId()); + $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $this->userSession->getId()); } elseif ($timer === 'stop') { - $this->subtaskTimeTracking->logEndTime($subtask_id, $this->userSession->getId()); - $this->subtaskTimeTracking->updateTaskTimeTracking($task['id']); + $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $this->userSession->getId()); + $this->subtaskTimeTrackingModel->updateTaskTimeTracking($task['id']); } $this->response->html($this->renderTable($task)); @@ -64,7 +64,7 @@ class SubtaskStatusController extends BaseController { return $this->template->render('subtask/table', array( 'task' => $task, - 'subtasks' => $this->subtask->getAll($task['id']), + 'subtasks' => $this->subtaskModel->getAll($task['id']), 'editable' => true, )); } diff --git a/app/Controller/SwimlaneController.php b/app/Controller/SwimlaneController.php index 13a64d40..4b9567e6 100644 --- a/app/Controller/SwimlaneController.php +++ b/app/Controller/SwimlaneController.php @@ -4,7 +4,7 @@ namespace Kanboard\Controller; use Kanboard\Core\Controller\AccessForbiddenException; use Kanboard\Core\Controller\PageNotFoundException; -use Kanboard\Model\Swimlane as SwimlaneModel; +use Kanboard\Model\SwimlaneModel; /** * Swimlanes Controller @@ -23,7 +23,7 @@ class SwimlaneController extends BaseController */ private function getSwimlane() { - $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); + $swimlane = $this->swimlaneModel->getById($this->request->getIntegerParam('swimlane_id')); if (empty($swimlane)) { throw new PageNotFoundException(); @@ -42,9 +42,9 @@ class SwimlaneController extends BaseController $project = $this->getProject(); $this->response->html($this->helper->layout->project('swimlane/index', array( - 'default_swimlane' => $this->swimlane->getDefault($project['id']), - 'active_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::ACTIVE), - 'inactive_swimlanes' => $this->swimlane->getAllByStatus($project['id'], SwimlaneModel::INACTIVE), + 'default_swimlane' => $this->swimlaneModel->getDefault($project['id']), + 'active_swimlanes' => $this->swimlaneModel->getAllByStatus($project['id'], SwimlaneModel::ACTIVE), + 'inactive_swimlanes' => $this->swimlaneModel->getAllByStatus($project['id'], SwimlaneModel::INACTIVE), 'project' => $project, 'title' => t('Swimlanes') ))); @@ -81,7 +81,7 @@ class SwimlaneController extends BaseController list($valid, $errors) = $this->swimlaneValidator->validateCreation($values); if ($valid) { - if ($this->swimlane->create($values)) { + if ($this->swimlaneModel->create($values)) { $this->flash->success(t('Your swimlane have been created successfully.')); return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); } else { @@ -103,7 +103,7 @@ class SwimlaneController extends BaseController public function editDefault(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $swimlane = $this->swimlane->getDefault($project['id']); + $swimlane = $this->swimlaneModel->getDefault($project['id']); $this->response->html($this->helper->layout->project('swimlane/edit_default', array( 'values' => empty($values) ? $swimlane : $values, @@ -125,7 +125,7 @@ class SwimlaneController extends BaseController list($valid, $errors) = $this->swimlaneValidator->validateDefaultModification($values); if ($valid) { - if ($this->swimlane->updateDefault($values)) { + if ($this->swimlaneModel->updateDefault($values)) { $this->flash->success(t('The default swimlane have been updated successfully.')); return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id'])), true); } else { @@ -169,7 +169,7 @@ class SwimlaneController extends BaseController list($valid, $errors) = $this->swimlaneValidator->validateModification($values); if ($valid) { - if ($this->swimlane->update($values)) { + if ($this->swimlaneModel->update($values)) { $this->flash->success(t('Swimlane updated successfully.')); return $this->response->redirect($this->helper->url->to('SwimlaneController', 'index', array('project_id' => $project['id']))); } else { @@ -207,7 +207,7 @@ class SwimlaneController extends BaseController $project = $this->getProject(); $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - if ($this->swimlane->remove($project['id'], $swimlane_id)) { + if ($this->swimlaneModel->remove($project['id'], $swimlane_id)) { $this->flash->success(t('Swimlane removed successfully.')); } else { $this->flash->failure(t('Unable to remove this swimlane.')); @@ -227,7 +227,7 @@ class SwimlaneController extends BaseController $project = $this->getProject(); $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - if ($this->swimlane->disable($project['id'], $swimlane_id)) { + if ($this->swimlaneModel->disable($project['id'], $swimlane_id)) { $this->flash->success(t('Swimlane updated successfully.')); } else { $this->flash->failure(t('Unable to update this swimlane.')); @@ -246,7 +246,7 @@ class SwimlaneController extends BaseController $this->checkCSRFParam(); $project = $this->getProject(); - if ($this->swimlane->disableDefault($project['id'])) { + if ($this->swimlaneModel->disableDefault($project['id'])) { $this->flash->success(t('Swimlane updated successfully.')); } else { $this->flash->failure(t('Unable to update this swimlane.')); @@ -266,7 +266,7 @@ class SwimlaneController extends BaseController $project = $this->getProject(); $swimlane_id = $this->request->getIntegerParam('swimlane_id'); - if ($this->swimlane->enable($project['id'], $swimlane_id)) { + if ($this->swimlaneModel->enable($project['id'], $swimlane_id)) { $this->flash->success(t('Swimlane updated successfully.')); } else { $this->flash->failure(t('Unable to update this swimlane.')); @@ -285,7 +285,7 @@ class SwimlaneController extends BaseController $this->checkCSRFParam(); $project = $this->getProject(); - if ($this->swimlane->enableDefault($project['id'])) { + if ($this->swimlaneModel->enableDefault($project['id'])) { $this->flash->success(t('Swimlane updated successfully.')); } else { $this->flash->failure(t('Unable to update this swimlane.')); @@ -305,7 +305,7 @@ class SwimlaneController extends BaseController $values = $this->request->getJson(); if (! empty($values) && isset($values['swimlane_id']) && isset($values['position'])) { - $result = $this->swimlane->changePosition($project['id'], $values['swimlane_id'], $values['position']); + $result = $this->swimlaneModel->changePosition($project['id'], $values['swimlane_id'], $values['position']); $this->response->json(array('result' => $result)); } else { throw new AccessForbiddenException(); diff --git a/app/Controller/TaskAjaxController.php b/app/Controller/TaskAjaxController.php index d630b962..f9feff15 100644 --- a/app/Controller/TaskAjaxController.php +++ b/app/Controller/TaskAjaxController.php @@ -24,7 +24,7 @@ class TaskAjaxController extends BaseController public function autocomplete() { $search = $this->request->getStringParam('term'); - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); $exclude_task_id = $this->request->getIntegerParam('exclude_task_id'); if (empty($project_ids)) { diff --git a/app/Controller/TaskBulkController.php b/app/Controller/TaskBulkController.php index 528ae7a3..df7f589b 100644 --- a/app/Controller/TaskBulkController.php +++ b/app/Controller/TaskBulkController.php @@ -32,9 +32,9 @@ class TaskBulkController extends BaseController 'project' => $project, 'values' => $values, 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($project['id']), ))); } @@ -74,7 +74,7 @@ class TaskBulkController extends BaseController $title = trim($title); if (! empty($title)) { - $this->taskCreation->create(array( + $this->taskCreationModel->create(array( 'title' => $title, 'column_id' => $values['column_id'], 'swimlane_id' => $values['swimlane_id'], diff --git a/app/Controller/TaskCreationController.php b/app/Controller/TaskCreationController.php index b7af6d87..819de96e 100644 --- a/app/Controller/TaskCreationController.php +++ b/app/Controller/TaskCreationController.php @@ -21,13 +21,13 @@ class TaskCreationController extends BaseController public function show(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $swimlanes_list = $this->swimlane->getList($project['id'], false, true); + $swimlanes_list = $this->swimlaneModel->getList($project['id'], false, true); if (empty($values)) { $values = array( 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanes_list)), 'column_id' => $this->request->getIntegerParam('column_id'), - 'color_id' => $this->color->getDefaultColor(), + 'color_id' => $this->colorModel->getDefaultColor(), 'owner_id' => $this->userSession->getId(), ); @@ -39,10 +39,10 @@ class TaskCreationController extends BaseController 'project' => $project, 'errors' => $errors, 'values' => $values + array('project_id' => $project['id']), - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), + 'columns_list' => $this->columnModel->getList($project['id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($project['id']), 'swimlanes_list' => $swimlanes_list, 'title' => $project['name'].' > '.t('New task') ))); @@ -60,7 +60,7 @@ class TaskCreationController extends BaseController list($valid, $errors) = $this->taskValidator->validateCreation($values); - if ($valid && $this->taskCreation->create($values)) { + if ($valid && $this->taskCreationModel->create($values)) { $this->flash->success(t('Task created successfully.')); return $this->afterSave($project, $values); } diff --git a/app/Controller/TaskDuplicationController.php b/app/Controller/TaskDuplicationController.php index ab7b6b42..6a475374 100644 --- a/app/Controller/TaskDuplicationController.php +++ b/app/Controller/TaskDuplicationController.php @@ -21,7 +21,7 @@ class TaskDuplicationController extends BaseController if ($this->request->getStringParam('confirmation') === 'yes') { $this->checkCSRFParam(); - $task_id = $this->taskDuplication->duplicate($task['id']); + $task_id = $this->taskDuplicationModel->duplicate($task['id']); if ($task_id > 0) { $this->flash->success(t('Task created successfully.')); @@ -50,7 +50,7 @@ class TaskDuplicationController extends BaseController $values = $this->request->getValues(); list($valid, ) = $this->taskValidator->validateProjectModification($values); - if ($valid && $this->taskDuplication->moveToProject($task['id'], + if ($valid && $this->taskDuplicationModel->moveToProject($task['id'], $values['project_id'], $values['swimlane_id'], $values['column_id'], @@ -80,7 +80,7 @@ class TaskDuplicationController extends BaseController list($valid, ) = $this->taskValidator->validateProjectModification($values); if ($valid) { - $task_id = $this->taskDuplication->duplicateToProject( + $task_id = $this->taskDuplicationModel->duplicateToProject( $task['id'], $values['project_id'], $values['swimlane_id'], $values['column_id'], $values['category_id'], $values['owner_id'] ); @@ -107,19 +107,19 @@ class TaskDuplicationController extends BaseController private function chooseDestination(array $task, $template) { $values = array(); - $projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + $projects_list = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); unset($projects_list[$task['project_id']]); if (! empty($projects_list)) { $dst_project_id = $this->request->getIntegerParam('dst_project_id', key($projects_list)); - $swimlanes_list = $this->swimlane->getList($dst_project_id, false, true); - $columns_list = $this->column->getList($dst_project_id); - $categories_list = $this->category->getList($dst_project_id); - $users_list = $this->projectUserRole->getAssignableUsersList($dst_project_id); + $swimlanes_list = $this->swimlaneModel->getList($dst_project_id, false, true); + $columns_list = $this->columnModel->getList($dst_project_id); + $categories_list = $this->categoryModel->getList($dst_project_id); + $users_list = $this->projectUserRoleModel->getAssignableUsersList($dst_project_id); - $values = $this->taskDuplication->checkDestinationProjectValues($task); + $values = $this->taskDuplicationModel->checkDestinationProjectValues($task); $values['project_id'] = $dst_project_id; } else { $swimlanes_list = array(); diff --git a/app/Controller/TaskExternalLinkController.php b/app/Controller/TaskExternalLinkController.php index 91dc734a..f3c6050d 100644 --- a/app/Controller/TaskExternalLinkController.php +++ b/app/Controller/TaskExternalLinkController.php @@ -76,7 +76,7 @@ class TaskExternalLinkController extends BaseController $values = $this->request->getValues(); list($valid, $errors) = $this->externalLinkValidator->validateCreation($values); - if ($valid && $this->taskExternalLink->create($values)) { + if ($valid && $this->taskExternalLinkModel->create($values)) { $this->flash->success(t('Link added successfully.')); return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } @@ -100,7 +100,7 @@ class TaskExternalLinkController extends BaseController $link_id = $this->request->getIntegerParam('link_id'); if ($link_id > 0) { - $values = $this->taskExternalLink->getById($link_id); + $values = $this->taskExternalLinkModel->getById($link_id); } if (empty($values)) { @@ -128,7 +128,7 @@ class TaskExternalLinkController extends BaseController $values = $this->request->getValues(); list($valid, $errors) = $this->externalLinkValidator->validateModification($values); - if ($valid && $this->taskExternalLink->update($values)) { + if ($valid && $this->taskExternalLinkModel->update($values)) { $this->flash->success(t('Link updated successfully.')); return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } @@ -145,7 +145,7 @@ class TaskExternalLinkController extends BaseController { $task = $this->getTask(); $link_id = $this->request->getIntegerParam('link_id'); - $link = $this->taskExternalLink->getById($link_id); + $link = $this->taskExternalLinkModel->getById($link_id); if (empty($link)) { throw new PageNotFoundException(); @@ -167,7 +167,7 @@ class TaskExternalLinkController extends BaseController $this->checkCSRFParam(); $task = $this->getTask(); - if ($this->taskExternalLink->remove($this->request->getIntegerParam('link_id'))) { + if ($this->taskExternalLinkModel->remove($this->request->getIntegerParam('link_id'))) { $this->flash->success(t('Link removed successfully.')); } else { $this->flash->failure(t('Unable to remove this link.')); diff --git a/app/Controller/TaskFileController.php b/app/Controller/TaskFileController.php index 44c19c27..77c0c026 100644 --- a/app/Controller/TaskFileController.php +++ b/app/Controller/TaskFileController.php @@ -19,7 +19,7 @@ class TaskFileController extends BaseController { $task = $this->getTask(); - if ($this->request->isPost() && $this->taskFile->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { + if ($this->request->isPost() && $this->taskFileModel->uploadScreenshot($task['id'], $this->request->getValue('screenshot')) !== false) { $this->flash->success(t('Screenshot uploaded successfully.')); return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } @@ -53,7 +53,7 @@ class TaskFileController extends BaseController { $task = $this->getTask(); - if (! $this->taskFile->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { + if (! $this->taskFileModel->uploadFiles($task['id'], $this->request->getFileInfo('files'))) { $this->flash->failure(t('Unable to upload the file.')); } @@ -69,9 +69,9 @@ class TaskFileController extends BaseController { $this->checkCSRFParam(); $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + $file = $this->taskFileModel->getById($this->request->getIntegerParam('file_id')); - if ($file['task_id'] == $task['id'] && $this->taskFile->remove($file['id'])) { + if ($file['task_id'] == $task['id'] && $this->taskFileModel->remove($file['id'])) { $this->flash->success(t('File removed successfully.')); } else { $this->flash->failure(t('Unable to remove this file.')); @@ -88,7 +88,7 @@ class TaskFileController extends BaseController public function confirm() { $task = $this->getTask(); - $file = $this->taskFile->getById($this->request->getIntegerParam('file_id')); + $file = $this->taskFileModel->getById($this->request->getIntegerParam('file_id')); $this->response->html($this->template->render('task_file/remove', array( 'task' => $task, diff --git a/app/Controller/TaskGanttController.php b/app/Controller/TaskGanttController.php index 3d0c5f50..868368e1 100644 --- a/app/Controller/TaskGanttController.php +++ b/app/Controller/TaskGanttController.php @@ -4,7 +4,7 @@ namespace Kanboard\Controller; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Formatter\TaskGanttFormatter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; /** * Tasks Gantt Controller @@ -47,7 +47,7 @@ class TaskGanttController extends BaseController $this->getProject(); $values = $this->request->getJson(); - $result = $this->taskModification->update(array( + $result = $this->taskModificationModel->update(array( 'id' => $values['id'], 'date_started' => strtotime($values['start']), 'date_due' => strtotime($values['end']), diff --git a/app/Controller/TaskGanttCreationController.php b/app/Controller/TaskGanttCreationController.php index 0ae4ab3b..c2998a3e 100644 --- a/app/Controller/TaskGanttCreationController.php +++ b/app/Controller/TaskGanttCreationController.php @@ -24,7 +24,7 @@ class TaskGanttCreationController extends BaseController $values = $values + array( 'project_id' => $project['id'], - 'column_id' => $this->column->getFirstColumnId($project['id']), + 'column_id' => $this->columnModel->getFirstColumnId($project['id']), 'position' => 1 ); @@ -35,10 +35,10 @@ class TaskGanttCreationController extends BaseController 'project' => $project, 'errors' => $errors, 'values' => $values, - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'swimlanes_list' => $this->swimlane->getList($project['id'], false, true), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($project['id']), + 'swimlanes_list' => $this->swimlaneModel->getList($project['id'], false, true), 'title' => $project['name'].' > '.t('New task') ))); } @@ -56,7 +56,7 @@ class TaskGanttCreationController extends BaseController list($valid, $errors) = $this->taskValidator->validateCreation($values); if ($valid) { - $task_id = $this->taskCreation->create($values); + $task_id = $this->taskCreationModel->create($values); if ($task_id !== false) { $this->flash->success(t('Task created successfully.')); diff --git a/app/Controller/TaskInternalLinkController.php b/app/Controller/TaskInternalLinkController.php index 4018c3a5..a140f1ff 100644 --- a/app/Controller/TaskInternalLinkController.php +++ b/app/Controller/TaskInternalLinkController.php @@ -22,7 +22,7 @@ class TaskInternalLinkController extends BaseController */ private function getTaskLink() { - $link = $this->taskLink->getById($this->request->getIntegerParam('link_id')); + $link = $this->taskLinkModel->getById($this->request->getIntegerParam('link_id')); if (empty($link)) { throw new PageNotFoundException(); @@ -48,7 +48,7 @@ class TaskInternalLinkController extends BaseController 'values' => $values, 'errors' => $errors, 'task' => $task, - 'labels' => $this->link->getList(0, false), + 'labels' => $this->linkModel->getList(0, false), ))); } @@ -65,7 +65,7 @@ class TaskInternalLinkController extends BaseController list($valid, $errors) = $this->taskLinkValidator->validateCreation($values); if ($valid) { - if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) { + if ($this->taskLinkModel->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) { $this->flash->success(t('Link added successfully.')); return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); } @@ -92,7 +92,7 @@ class TaskInternalLinkController extends BaseController $task_link = $this->getTaskLink(); if (empty($values)) { - $opposite_task = $this->taskFinder->getById($task_link['opposite_task_id']); + $opposite_task = $this->taskFinderModel->getById($task_link['opposite_task_id']); $values = $task_link; $values['title'] = '#'.$opposite_task['id'].' - '.$opposite_task['title']; } @@ -102,7 +102,7 @@ class TaskInternalLinkController extends BaseController 'errors' => $errors, 'task_link' => $task_link, 'task' => $task, - 'labels' => $this->link->getList(0, false) + 'labels' => $this->linkModel->getList(0, false) ))); } @@ -119,7 +119,7 @@ class TaskInternalLinkController extends BaseController list($valid, $errors) = $this->taskLinkValidator->validateModification($values); if ($valid) { - if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { + if ($this->taskLinkModel->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { $this->flash->success(t('Link updated successfully.')); return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } @@ -156,7 +156,7 @@ class TaskInternalLinkController extends BaseController $this->checkCSRFParam(); $task = $this->getTask(); - if ($this->taskLink->remove($this->request->getIntegerParam('link_id'))) { + if ($this->taskLinkModel->remove($this->request->getIntegerParam('link_id'))) { $this->flash->success(t('Link removed successfully.')); } else { $this->flash->failure(t('Unable to remove this link.')); diff --git a/app/Controller/TaskListController.php b/app/Controller/TaskListController.php index 898c14c8..c6d1fa92 100644 --- a/app/Controller/TaskListController.php +++ b/app/Controller/TaskListController.php @@ -3,7 +3,7 @@ namespace Kanboard\Controller; use Kanboard\Filter\TaskProjectFilter; -use Kanboard\Model\Task as TaskModel; +use Kanboard\Model\TaskModel; /** * Task List Controller diff --git a/app/Controller/TaskModificationController.php b/app/Controller/TaskModificationController.php index 09a8fabe..fc9113dd 100644 --- a/app/Controller/TaskModificationController.php +++ b/app/Controller/TaskModificationController.php @@ -20,7 +20,7 @@ class TaskModificationController extends BaseController public function start() { $task = $this->getTask(); - $this->taskModification->update(array('id' => $task['id'], 'date_started' => time())); + $this->taskModificationModel->update(array('id' => $task['id'], 'date_started' => time())); $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); } @@ -61,7 +61,7 @@ class TaskModificationController extends BaseController list($valid, $errors) = $this->taskValidator->validateDescriptionCreation($values); if ($valid) { - if ($this->taskModification->update($values)) { + if ($this->taskModificationModel->update($values)) { $this->flash->success(t('Task updated successfully.')); } else { $this->flash->failure(t('Unable to update your task.')); @@ -85,7 +85,7 @@ class TaskModificationController extends BaseController public function edit(array $values = array(), array $errors = array()) { $task = $this->getTask(); - $project = $this->project->getById($task['project_id']); + $project = $this->projectModel->getById($task['project_id']); if (empty($values)) { $values = $task; @@ -93,17 +93,17 @@ class TaskModificationController extends BaseController $values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values)); } - $values = $this->dateParser->format($values, array('date_due'), $this->config->get('application_date_format', DateParser::DATE_FORMAT)); - $values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); + $values = $this->dateParser->format($values, array('date_due'), $this->configModel->get('application_date_format', DateParser::DATE_FORMAT)); + $values = $this->dateParser->format($values, array('date_started'), $this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); $this->response->html($this->template->render('task_modification/edit_task', array( 'project' => $project, 'values' => $values, 'errors' => $errors, 'task' => $task, - 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($task['project_id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']), + 'colors_list' => $this->colorModel->getList(), + 'categories_list' => $this->categoryModel->getList($task['project_id']), ))); } @@ -119,7 +119,7 @@ class TaskModificationController extends BaseController list($valid, $errors) = $this->taskValidator->validateModification($values); - if ($valid && $this->taskModification->update($values)) { + if ($valid && $this->taskModificationModel->update($values)) { $this->flash->success(t('Task updated successfully.')); $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); } else { diff --git a/app/Controller/TaskPopoverController.php b/app/Controller/TaskPopoverController.php index 9916a5d1..bf4e23d5 100644 --- a/app/Controller/TaskPopoverController.php +++ b/app/Controller/TaskPopoverController.php @@ -18,11 +18,11 @@ class TaskPopoverController extends BaseController public function changeAssignee() { $task = $this->getTask(); - $project = $this->project->getById($task['project_id']); + $project = $this->projectModel->getById($task['project_id']); $this->response->html($this->template->render('task_popover/change_assignee', array( 'values' => $task, - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id']), 'project' => $project, ))); } @@ -38,7 +38,7 @@ class TaskPopoverController extends BaseController list($valid,) = $this->taskValidator->validateAssigneeModification($values); - if ($valid && $this->taskModification->update($values)) { + if ($valid && $this->taskModificationModel->update($values)) { $this->flash->success(t('Task updated successfully.')); } else { $this->flash->failure(t('Unable to update your task.')); @@ -55,11 +55,11 @@ class TaskPopoverController extends BaseController public function changeCategory() { $task = $this->getTask(); - $project = $this->project->getById($task['project_id']); + $project = $this->projectModel->getById($task['project_id']); $this->response->html($this->template->render('task_popover/change_category', array( 'values' => $task, - 'categories_list' => $this->category->getList($project['id']), + 'categories_list' => $this->categoryModel->getList($project['id']), 'project' => $project, ))); } @@ -75,7 +75,7 @@ class TaskPopoverController extends BaseController list($valid,) = $this->taskValidator->validateCategoryModification($values); - if ($valid && $this->taskModification->update($values)) { + if ($valid && $this->taskModificationModel->update($values)) { $this->flash->success(t('Task updated successfully.')); } else { $this->flash->failure(t('Unable to update your task.')); diff --git a/app/Controller/TaskRecurrenceController.php b/app/Controller/TaskRecurrenceController.php index cd9a2c92..dc7a0e1b 100644 --- a/app/Controller/TaskRecurrenceController.php +++ b/app/Controller/TaskRecurrenceController.php @@ -31,10 +31,10 @@ class TaskRecurrenceController extends BaseController 'values' => $values, 'errors' => $errors, 'task' => $task, - 'recurrence_status_list' => $this->task->getRecurrenceStatusList(), - 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), - 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), - 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + 'recurrence_status_list' => $this->taskModel->getRecurrenceStatusList(), + 'recurrence_trigger_list' => $this->taskModel->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->taskModel->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->taskModel->getRecurrenceBasedateList(), ))); } @@ -51,7 +51,7 @@ class TaskRecurrenceController extends BaseController list($valid, $errors) = $this->taskValidator->validateEditRecurrence($values); if ($valid) { - if ($this->taskModification->update($values)) { + if ($this->taskModificationModel->update($values)) { $this->flash->success(t('Task updated successfully.')); } else { $this->flash->failure(t('Unable to update your task.')); diff --git a/app/Controller/TaskStatusController.php b/app/Controller/TaskStatusController.php index 98ab4e1e..82b4f9c4 100644 --- a/app/Controller/TaskStatusController.php +++ b/app/Controller/TaskStatusController.php @@ -46,7 +46,7 @@ class TaskStatusController extends BaseController if ($this->request->getStringParam('confirmation') === 'yes') { $this->checkCSRFParam(); - if ($this->taskStatus->$method($task['id'])) { + if ($this->taskStatusModel->$method($task['id'])) { $this->flash->success($success_message); } else { $this->flash->failure($failure_message); diff --git a/app/Controller/TaskSuppressionController.php b/app/Controller/TaskSuppressionController.php index 7c9165eb..600107c9 100644 --- a/app/Controller/TaskSuppressionController.php +++ b/app/Controller/TaskSuppressionController.php @@ -41,7 +41,7 @@ class TaskSuppressionController extends BaseController throw new AccessForbiddenException(); } - if ($this->task->remove($task['id'])) { + if ($this->taskModel->remove($task['id'])) { $this->flash->success(t('Task removed successfully.')); } else { $this->flash->failure(t('Unable to remove this task.')); diff --git a/app/Controller/TaskViewController.php b/app/Controller/TaskViewController.php index b16c15de..2a79ee45 100644 --- a/app/Controller/TaskViewController.php +++ b/app/Controller/TaskViewController.php @@ -21,14 +21,14 @@ class TaskViewController extends BaseController */ public function readonly() { - $project = $this->project->getByToken($this->request->getStringParam('token')); + $project = $this->projectModel->getByToken($this->request->getStringParam('token')); // Token verification if (empty($project)) { throw AccessForbiddenException::getInstance()->withoutLayout(); } - $task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id')); + $task = $this->taskFinderModel->getDetails($this->request->getIntegerParam('task_id')); if (empty($task)) { throw PageNotFoundException::getInstance()->withoutLayout(); @@ -40,12 +40,12 @@ class TaskViewController extends BaseController $this->response->html($this->helper->layout->app('task/public', array( 'project' => $project, - 'comments' => $this->comment->getAll($task['id']), - 'subtasks' => $this->subtask->getAll($task['id']), - 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), + 'comments' => $this->commentModel->getAll($task['id']), + 'subtasks' => $this->subtaskModel->getAll($task['id']), + 'links' => $this->taskLinkModel->getAllGroupedByLabel($task['id']), 'task' => $task, - 'columns_list' => $this->column->getList($task['project_id']), - 'colors_list' => $this->color->getList(), + 'columns_list' => $this->columnModel->getList($task['project_id']), + 'colors_list' => $this->colorModel->getList(), 'title' => $task['title'], 'no_layout' => true, 'auto_refresh' => true, @@ -61,7 +61,7 @@ class TaskViewController extends BaseController public function show() { $task = $this->getTask(); - $subtasks = $this->subtask->getAll($task['id']); + $subtasks = $this->subtaskModel->getAll($task['id']); $values = array( 'id' => $task['id'], @@ -70,19 +70,19 @@ class TaskViewController extends BaseController 'time_spent' => $task['time_spent'] ?: '', ); - $values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); + $values = $this->dateParser->format($values, array('date_started'), $this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT)); $this->response->html($this->helper->layout->task('task/show', array( 'task' => $task, - 'project' => $this->project->getById($task['project_id']), + 'project' => $this->projectModel->getById($task['project_id']), 'values' => $values, - 'files' => $this->taskFile->getAllDocuments($task['id']), - 'images' => $this->taskFile->getAllImages($task['id']), - 'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()), + 'files' => $this->taskFileModel->getAllDocuments($task['id']), + 'images' => $this->taskFileModel->getAllImages($task['id']), + 'comments' => $this->commentModel->getAll($task['id'], $this->userSession->getCommentSorting()), 'subtasks' => $subtasks, - 'internal_links' => $this->taskLink->getAllGroupedByLabel($task['id']), - 'external_links' => $this->taskExternalLink->getAll($task['id']), - 'link_label_list' => $this->link->getList(0, false), + 'internal_links' => $this->taskLinkModel->getAllGroupedByLabel($task['id']), + 'external_links' => $this->taskExternalLinkModel->getAll($task['id']), + 'link_label_list' => $this->linkModel->getList(0, false), ))); } @@ -97,10 +97,10 @@ class TaskViewController extends BaseController $this->response->html($this->helper->layout->task('task/analytics', array( 'task' => $task, - 'project' => $this->project->getById($task['project_id']), - 'lead_time' => $this->taskAnalytic->getLeadTime($task), - 'cycle_time' => $this->taskAnalytic->getCycleTime($task), - 'time_spent_columns' => $this->taskAnalytic->getTimeSpentByColumn($task), + 'project' => $this->projectModel->getById($task['project_id']), + 'lead_time' => $this->taskAnalyticModel->getLeadTime($task), + 'cycle_time' => $this->taskAnalyticModel->getCycleTime($task), + 'time_spent_columns' => $this->taskAnalyticModel->getTimeSpentByColumn($task), ))); } @@ -118,12 +118,12 @@ class TaskViewController extends BaseController ->setMax(15) ->setOrder('start') ->setDirection('DESC') - ->setQuery($this->subtaskTimeTracking->getTaskQuery($task['id'])) + ->setQuery($this->subtaskTimeTrackingModel->getTaskQuery($task['id'])) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); $this->response->html($this->helper->layout->task('task/time_tracking_details', array( 'task' => $task, - 'project' => $this->project->getById($task['project_id']), + 'project' => $this->projectModel->getById($task['project_id']), 'subtask_paginator' => $subtask_paginator, ))); } @@ -139,8 +139,8 @@ class TaskViewController extends BaseController $this->response->html($this->helper->layout->task('task/transitions', array( 'task' => $task, - 'project' => $this->project->getById($task['project_id']), - 'transitions' => $this->transition->getAllByTask($task['id']), + 'project' => $this->projectModel->getById($task['project_id']), + 'transitions' => $this->transitionModel->getAllByTask($task['id']), ))); } } diff --git a/app/Controller/TwoFactorController.php b/app/Controller/TwoFactorController.php index c8540f85..d02c8950 100644 --- a/app/Controller/TwoFactorController.php +++ b/app/Controller/TwoFactorController.php @@ -91,7 +91,7 @@ class TwoFactorController extends UserViewController if ($provider->authenticate()) { $this->flash->success(t('The two factor authentication code is valid.')); - $this->user->update(array( + $this->userModel->update(array( 'id' => $user['id'], 'twofactor_activated' => 1, 'twofactor_secret' => $this->authenticationManager->getPostAuthenticationProvider()->getSecret(), @@ -117,7 +117,7 @@ class TwoFactorController extends UserViewController $user = $this->getUser(); $this->checkCurrentUser($user); - $this->user->update(array( + $this->userModel->update(array( 'id' => $user['id'], 'twofactor_activated' => 0, 'twofactor_secret' => '', @@ -186,7 +186,7 @@ class TwoFactorController extends UserViewController if ($this->request->getStringParam('disable') === 'yes') { $this->checkCSRFParam(); - $this->user->update(array( + $this->userModel->update(array( 'id' => $user['id'], 'twofactor_activated' => 0, 'twofactor_secret' => '', diff --git a/app/Controller/UserAjaxController.php b/app/Controller/UserAjaxController.php index 7b365667..ed180471 100644 --- a/app/Controller/UserAjaxController.php +++ b/app/Controller/UserAjaxController.php @@ -4,7 +4,7 @@ namespace Kanboard\Controller; use Kanboard\Filter\UserNameFilter; use Kanboard\Formatter\UserAutoCompleteFormatter; -use Kanboard\Model\User as UserModel; +use Kanboard\Model\UserModel; /** * User Ajax Controller @@ -36,7 +36,7 @@ class UserAjaxController extends BaseController { $project_id = $this->request->getStringParam('project_id'); $query = $this->request->getStringParam('q'); - $users = $this->projectPermission->findUsernames($project_id, $query); + $users = $this->projectPermissionModel->findUsernames($project_id, $query); $this->response->json($users); } diff --git a/app/Controller/UserCreationController.php b/app/Controller/UserCreationController.php index 4ae170e0..9c873f85 100644 --- a/app/Controller/UserCreationController.php +++ b/app/Controller/UserCreationController.php @@ -26,10 +26,10 @@ class UserCreationController extends BaseController $template = $isRemote ? 'user_creation/remote' : 'user_creation/local'; $this->response->html($this->template->render($template, array( - 'timezones' => $this->timezone->getTimezones(true), - 'languages' => $this->language->getLanguages(true), + 'timezones' => $this->timezoneModel->getTimezones(true), + 'languages' => $this->languageModel->getLanguages(true), 'roles' => $this->role->getApplicationRoles(), - 'projects' => $this->project->getList(), + 'projects' => $this->projectModel->getList(), 'errors' => $errors, 'values' => $values + array('role' => Role::APP_USER), ))); @@ -62,15 +62,15 @@ class UserCreationController extends BaseController $project_id = empty($values['project_id']) ? 0 : $values['project_id']; unset($values['project_id']); - $user_id = $this->user->create($values); + $user_id = $this->userModel->create($values); if ($user_id !== false) { if ($project_id !== 0) { - $this->projectUserRole->addUser($project_id, $user_id, Role::PROJECT_MEMBER); + $this->projectUserRoleModel->addUser($project_id, $user_id, Role::PROJECT_MEMBER); } if (! empty($values['notifications_enabled'])) { - $this->userNotificationType->saveSelectedTypes($user_id, array(MailNotification::TYPE)); + $this->userNotificationTypeModel->saveSelectedTypes($user_id, array(MailNotification::TYPE)); } $this->flash->success(t('User created successfully.')); diff --git a/app/Controller/UserCredentialController.php b/app/Controller/UserCredentialController.php index 3310aaa8..4021dc37 100644 --- a/app/Controller/UserCredentialController.php +++ b/app/Controller/UserCredentialController.php @@ -44,9 +44,9 @@ class UserCredentialController extends BaseController list($valid, $errors) = $this->userValidator->validatePasswordModification($values); if ($valid) { - if ($this->user->update($values)) { + if ($this->userModel->update($values)) { $this->flash->success(t('Password modified successfully.')); - $this->userLocking->resetFailedLogin($user['username']); + $this->userLockingModel->resetFailedLogin($user['username']); } else { $this->flash->failure(t('Unable to change the password.')); } @@ -95,7 +95,7 @@ class UserCredentialController extends BaseController list($valid, $errors) = $this->userValidator->validateModification($values); if ($valid) { - if ($this->user->update($values)) { + if ($this->userModel->update($values)) { $this->flash->success(t('User updated successfully.')); } else { $this->flash->failure(t('Unable to update your user.')); diff --git a/app/Controller/UserListController.php b/app/Controller/UserListController.php index 685746fb..31fcdd44 100644 --- a/app/Controller/UserListController.php +++ b/app/Controller/UserListController.php @@ -21,7 +21,7 @@ class UserListController extends BaseController ->setUrl('UserListController', 'show') ->setMax(30) ->setOrder('username') - ->setQuery($this->user->getQuery()) + ->setQuery($this->userModel->getQuery()) ->calculate(); $this->response->html($this->helper->layout->app('user_list/show', array( diff --git a/app/Controller/UserModificationController.php b/app/Controller/UserModificationController.php index 0a50eb5b..d339fd9a 100644 --- a/app/Controller/UserModificationController.php +++ b/app/Controller/UserModificationController.php @@ -32,8 +32,8 @@ class UserModificationController extends BaseController 'values' => $values, 'errors' => $errors, 'user' => $user, - 'timezones' => $this->timezone->getTimezones(true), - 'languages' => $this->language->getLanguages(true), + 'timezones' => $this->timezoneModel->getTimezones(true), + 'languages' => $this->languageModel->getLanguages(true), 'roles' => $this->role->getApplicationRoles(), ))); } @@ -55,7 +55,7 @@ class UserModificationController extends BaseController list($valid, $errors) = $this->userValidator->validateModification($values); if ($valid) { - if ($this->user->update($values)) { + if ($this->userModel->update($values)) { $this->flash->success(t('User updated successfully.')); } else { $this->flash->failure(t('Unable to update your user.')); diff --git a/app/Controller/UserStatusController.php b/app/Controller/UserStatusController.php index bc40a7dd..070fb6fc 100644 --- a/app/Controller/UserStatusController.php +++ b/app/Controller/UserStatusController.php @@ -34,7 +34,7 @@ class UserStatusController extends BaseController $user = $this->getUser(); $this->checkCSRFParam(); - if ($this->user->remove($user['id'])) { + if ($this->userModel->remove($user['id'])) { $this->flash->success(t('User removed successfully.')); } else { $this->flash->failure(t('Unable to remove this user.')); @@ -67,7 +67,7 @@ class UserStatusController extends BaseController $user = $this->getUser(); $this->checkCSRFParam(); - if ($this->user->enable($user['id'])) { + if ($this->userModel->enable($user['id'])) { $this->flash->success(t('User activated successfully.')); } else { $this->flash->failure(t('Unable to enable this user.')); @@ -100,7 +100,7 @@ class UserStatusController extends BaseController $user = $this->getUser(); $this->checkCSRFParam(); - if ($this->user->disable($user['id'])) { + if ($this->userModel->disable($user['id'])) { $this->flash->success(t('User disabled successfully.')); } else { $this->flash->failure(t('Unable to disable this user.')); diff --git a/app/Controller/UserViewController.php b/app/Controller/UserViewController.php index b299e35b..a73c5c51 100644 --- a/app/Controller/UserViewController.php +++ b/app/Controller/UserViewController.php @@ -3,7 +3,7 @@ namespace Kanboard\Controller; use Kanboard\Core\Controller\PageNotFoundException; -use Kanboard\Model\Project as ProjectModel; +use Kanboard\Model\ProjectModel; /** * Class UserViewController @@ -21,7 +21,7 @@ class UserViewController extends BaseController */ public function profile() { - $user = $this->user->getById($this->request->getIntegerParam('user_id')); + $user = $this->userModel->getById($this->request->getIntegerParam('user_id')); if (empty($user)) { throw new PageNotFoundException(); @@ -43,8 +43,8 @@ class UserViewController extends BaseController $user = $this->getUser(); $this->response->html($this->helper->layout->user('user_view/show', array( 'user' => $user, - 'timezones' => $this->timezone->getTimezones(true), - 'languages' => $this->language->getLanguages(true), + 'timezones' => $this->timezoneModel->getTimezones(true), + 'languages' => $this->languageModel->getLanguages(true), ))); } @@ -62,7 +62,7 @@ class UserViewController extends BaseController ->setMax(20) ->setOrder('start') ->setDirection('DESC') - ->setQuery($this->subtaskTimeTracking->getUserQuery($user['id'])) + ->setQuery($this->subtaskTimeTrackingModel->getUserQuery($user['id'])) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); $this->response->html($this->helper->layout->user('user_view/timesheet', array( @@ -80,7 +80,7 @@ class UserViewController extends BaseController { $user = $this->getUser(); $this->response->html($this->helper->layout->user('user_view/password_reset', array( - 'tokens' => $this->passwordReset->getAll($user['id']), + 'tokens' => $this->passwordResetModel->getAll($user['id']), 'user' => $user, ))); } @@ -94,7 +94,7 @@ class UserViewController extends BaseController { $user = $this->getUser(); $this->response->html($this->helper->layout->user('user_view/last', array( - 'last_logins' => $this->lastLogin->getAll($user['id']), + 'last_logins' => $this->lastLoginModel->getAll($user['id']), 'user' => $user, ))); } @@ -108,7 +108,7 @@ class UserViewController extends BaseController { $user = $this->getUser(); $this->response->html($this->helper->layout->user('user_view/sessions', array( - 'sessions' => $this->rememberMeSession->getAll($user['id']), + 'sessions' => $this->rememberMeSessionModel->getAll($user['id']), 'user' => $user, ))); } @@ -122,7 +122,7 @@ class UserViewController extends BaseController { $this->checkCSRFParam(); $user = $this->getUser(); - $this->rememberMeSession->remove($this->request->getIntegerParam('id')); + $this->rememberMeSessionModel->remove($this->request->getIntegerParam('id')); $this->response->redirect($this->helper->url->to('UserViewController', 'sessions', array('user_id' => $user['id']))); } @@ -137,16 +137,16 @@ class UserViewController extends BaseController if ($this->request->isPost()) { $values = $this->request->getValues(); - $this->userNotification->saveSettings($user['id'], $values); + $this->userNotificationModel->saveSettings($user['id'], $values); $this->flash->success(t('User updated successfully.')); return $this->response->redirect($this->helper->url->to('UserViewController', 'notifications', array('user_id' => $user['id']))); } return $this->response->html($this->helper->layout->user('user_view/notifications', array( - 'projects' => $this->projectUserRole->getProjectsByUser($user['id'], array(ProjectModel::ACTIVE)), - 'notifications' => $this->userNotification->readSettings($user['id']), - 'types' => $this->userNotificationType->getTypes(), - 'filters' => $this->userNotificationFilter->getFilters(), + 'projects' => $this->projectUserRoleModel->getProjectsByUser($user['id'], array(ProjectModel::ACTIVE)), + 'notifications' => $this->userNotificationModel->readSettings($user['id']), + 'types' => $this->userNotificationTypeModel->getTypes(), + 'filters' => $this->userNotificationFilterModel->getFilters(), 'user' => $user, ))); } @@ -162,14 +162,14 @@ class UserViewController extends BaseController if ($this->request->isPost()) { $values = $this->request->getValues(); - $this->userMetadata->save($user['id'], $values); + $this->userMetadataModel->save($user['id'], $values); $this->flash->success(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('UserViewController', 'integrations', array('user_id' => $user['id']))); } $this->response->html($this->helper->layout->user('user_view/integrations', array( 'user' => $user, - 'values' => $this->userMetadata->getAll($user['id']), + 'values' => $this->userMetadataModel->getAll($user['id']), ))); } @@ -182,7 +182,7 @@ class UserViewController extends BaseController { $user = $this->getUser(); $this->response->html($this->helper->layout->user('user_view/external', array( - 'last_logins' => $this->lastLogin->getAll($user['id']), + 'last_logins' => $this->lastLoginModel->getAll($user['id']), 'user' => $user, ))); } @@ -200,7 +200,7 @@ class UserViewController extends BaseController if ($switch === 'enable' || $switch === 'disable') { $this->checkCSRFParam(); - if ($this->user->{$switch . 'PublicAccess'}($user['id'])) { + if ($this->userModel->{$switch . 'PublicAccess'}($user['id'])) { $this->flash->success(t('User updated successfully.')); } else { $this->flash->failure(t('Unable to update this user.')); diff --git a/app/Controller/WebNotificationController.php b/app/Controller/WebNotificationController.php index 263d6d9e..46a42063 100644 --- a/app/Controller/WebNotificationController.php +++ b/app/Controller/WebNotificationController.php @@ -19,7 +19,7 @@ class WebNotificationController extends BaseController { $user_id = $this->getUserId(); - $this->userUnreadNotification->markAllAsRead($user_id); + $this->userUnreadNotificationModel->markAllAsRead($user_id); $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); } @@ -33,7 +33,7 @@ class WebNotificationController extends BaseController $user_id = $this->getUserId(); $notification_id = $this->request->getIntegerParam('notification_id'); - $this->userUnreadNotification->markAsRead($user_id, $notification_id); + $this->userUnreadNotificationModel->markAsRead($user_id, $notification_id); $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); } @@ -45,8 +45,8 @@ class WebNotificationController extends BaseController $user_id = $this->getUserId(); $notification_id = $this->request->getIntegerParam('notification_id'); - $notification = $this->userUnreadNotification->getById($notification_id); - $this->userUnreadNotification->markAsRead($user_id, $notification_id); + $notification = $this->userUnreadNotificationModel->getById($notification_id); + $this->userUnreadNotificationModel->markAsRead($user_id, $notification_id); if (empty($notification)) { $this->response->redirect($this->helper->url->to('DashboardController', 'notifications', array('user_id' => $user_id))); diff --git a/app/Core/Action/ActionManager.php b/app/Core/Action/ActionManager.php index dfa5a140..1dfd820c 100644 --- a/app/Core/Action/ActionManager.php +++ b/app/Core/Action/ActionManager.php @@ -121,9 +121,9 @@ class ActionManager extends Base public function attachEvents() { if ($this->userSession->isLogged()) { - $actions = $this->action->getAllByUser($this->userSession->getId()); + $actions = $this->actionModel->getAllByUser($this->userSession->getId()); } else { - $actions = $this->action->getAll(); + $actions = $this->actionModel->getAll(); } foreach ($actions as $action) { diff --git a/app/Core/Base.php b/app/Core/Base.php index e490484c..99c093e4 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -10,136 +10,136 @@ use Pimple\Container; * @package core * @author Frederic Guillot * - * @property \Kanboard\Analytic\TaskDistributionAnalytic $taskDistributionAnalytic - * @property \Kanboard\Analytic\UserDistributionAnalytic $userDistributionAnalytic - * @property \Kanboard\Analytic\EstimatedTimeComparisonAnalytic $estimatedTimeComparisonAnalytic - * @property \Kanboard\Analytic\AverageLeadCycleTimeAnalytic $averageLeadCycleTimeAnalytic - * @property \Kanboard\Analytic\AverageTimeSpentColumnAnalytic $averageTimeSpentColumnAnalytic - * @property \Kanboard\Core\Action\ActionManager $actionManager - * @property \Kanboard\Core\ExternalLink\ExternalLinkManager $externalLinkManager - * @property \Kanboard\Core\Cache\MemoryCache $memoryCache - * @property \Kanboard\Core\Event\EventManager $eventManager - * @property \Kanboard\Core\Group\GroupManager $groupManager - * @property \Kanboard\Core\Http\Client $httpClient - * @property \Kanboard\Core\Http\OAuth2 $oauth - * @property \Kanboard\Core\Http\RememberMeCookie $rememberMeCookie - * @property \Kanboard\Core\Http\Request $request - * @property \Kanboard\Core\Http\Response $response - * @property \Kanboard\Core\Http\Router $router - * @property \Kanboard\Core\Http\Route $route - * @property \Kanboard\Core\Queue\QueueManager $queueManager - * @property \Kanboard\Core\Mail\Client $emailClient - * @property \Kanboard\Core\ObjectStorage\ObjectStorageInterface $objectStorage - * @property \Kanboard\Core\Plugin\Hook $hook - * @property \Kanboard\Core\Plugin\Loader $pluginLoader - * @property \Kanboard\Core\Security\AuthenticationManager $authenticationManager - * @property \Kanboard\Core\Security\AccessMap $applicationAccessMap - * @property \Kanboard\Core\Security\AccessMap $projectAccessMap - * @property \Kanboard\Core\Security\Authorization $applicationAuthorization - * @property \Kanboard\Core\Security\Authorization $projectAuthorization - * @property \Kanboard\Core\Security\Role $role - * @property \Kanboard\Core\Security\Token $token - * @property \Kanboard\Core\Session\FlashMessage $flash - * @property \Kanboard\Core\Session\SessionManager $sessionManager - * @property \Kanboard\Core\Session\SessionStorage $sessionStorage - * @property \Kanboard\Core\User\Avatar\AvatarManager $avatarManager - * @property \Kanboard\Core\User\GroupSync $groupSync - * @property \Kanboard\Core\User\UserProfile $userProfile - * @property \Kanboard\Core\User\UserSync $userSync - * @property \Kanboard\Core\User\UserSession $userSession - * @property \Kanboard\Core\DateParser $dateParser - * @property \Kanboard\Core\Helper $helper - * @property \Kanboard\Core\Paginator $paginator - * @property \Kanboard\Core\Template $template - * @property \Kanboard\Model\Action $action - * @property \Kanboard\Model\ActionParameter $actionParameter - * @property \Kanboard\Model\AvatarFile $avatarFile - * @property \Kanboard\Model\Board $board - * @property \Kanboard\Model\Category $category - * @property \Kanboard\Model\Color $color - * @property \Kanboard\Model\Column $column - * @property \Kanboard\Model\Comment $comment - * @property \Kanboard\Model\Config $config - * @property \Kanboard\Model\Currency $currency - * @property \Kanboard\Model\CustomFilter $customFilter - * @property \Kanboard\Model\TaskFile $taskFile - * @property \Kanboard\Model\ProjectFile $projectFile - * @property \Kanboard\Model\Group $group - * @property \Kanboard\Model\GroupMember $groupMember - * @property \Kanboard\Model\Language $language - * @property \Kanboard\Model\LastLogin $lastLogin - * @property \Kanboard\Model\Link $link - * @property \Kanboard\Model\Notification $notification - * @property \Kanboard\Model\PasswordReset $passwordReset - * @property \Kanboard\Model\Project $project - * @property \Kanboard\Model\ProjectActivity $projectActivity - * @property \Kanboard\Model\ProjectDuplication $projectDuplication - * @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats - * @property \Kanboard\Model\ProjectDailyStats $projectDailyStats - * @property \Kanboard\Model\ProjectMetadata $projectMetadata - * @property \Kanboard\Model\ProjectPermission $projectPermission - * @property \Kanboard\Model\ProjectUserRole $projectUserRole - * @property \Kanboard\Model\ProjectGroupRole $projectGroupRole - * @property \Kanboard\Model\ProjectNotification $projectNotification - * @property \Kanboard\Model\ProjectNotificationType $projectNotificationType - * @property \Kanboard\Model\RememberMeSession $rememberMeSession - * @property \Kanboard\Model\Subtask $subtask - * @property \Kanboard\Model\SubtaskTimeTracking $subtaskTimeTracking - * @property \Kanboard\Model\Swimlane $swimlane - * @property \Kanboard\Model\Task $task - * @property \Kanboard\Model\TaskAnalytic $taskAnalytic - * @property \Kanboard\Model\TaskCreation $taskCreation - * @property \Kanboard\Model\TaskDuplication $taskDuplication - * @property \Kanboard\Model\TaskExternalLink $taskExternalLink - * @property \Kanboard\Model\TaskFinder $taskFinder - * @property \Kanboard\Model\TaskLink $taskLink - * @property \Kanboard\Model\TaskModification $taskModification - * @property \Kanboard\Model\TaskPosition $taskPosition - * @property \Kanboard\Model\TaskStatus $taskStatus - * @property \Kanboard\Model\TaskMetadata $taskMetadata - * @property \Kanboard\Model\Timezone $timezone - * @property \Kanboard\Model\Transition $transition - * @property \Kanboard\Model\User $user - * @property \Kanboard\Model\UserLocking $userLocking - * @property \Kanboard\Model\UserMention $userMention - * @property \Kanboard\Model\UserNotification $userNotification - * @property \Kanboard\Model\UserNotificationType $userNotificationType - * @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter - * @property \Kanboard\Model\UserUnreadNotification $userUnreadNotification - * @property \Kanboard\Model\UserMetadata $userMetadata - * @property \Kanboard\Validator\ActionValidator $actionValidator - * @property \Kanboard\Validator\AuthValidator $authValidator - * @property \Kanboard\Validator\ColumnValidator $columnValidator - * @property \Kanboard\Validator\CategoryValidator $categoryValidator - * @property \Kanboard\Validator\CommentValidator $commentValidator - * @property \Kanboard\Validator\CurrencyValidator $currencyValidator - * @property \Kanboard\Validator\CustomFilterValidator $customFilterValidator - * @property \Kanboard\Validator\GroupValidator $groupValidator - * @property \Kanboard\Validator\LinkValidator $linkValidator - * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator - * @property \Kanboard\Validator\ProjectValidator $projectValidator - * @property \Kanboard\Validator\SubtaskValidator $subtaskValidator - * @property \Kanboard\Validator\SwimlaneValidator $swimlaneValidator - * @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator - * @property \Kanboard\Validator\ExternalLinkValidator $externalLinkValidator - * @property \Kanboard\Validator\TaskValidator $taskValidator - * @property \Kanboard\Validator\UserValidator $userValidator - * @property \Kanboard\Import\TaskImport $taskImport - * @property \Kanboard\Import\UserImport $userImport - * @property \Kanboard\Export\SubtaskExport $subtaskExport - * @property \Kanboard\Export\TaskExport $taskExport - * @property \Kanboard\Export\TransitionExport $transitionExport - * @property \Kanboard\Core\Filter\QueryBuilder $projectGroupRoleQuery - * @property \Kanboard\Core\Filter\QueryBuilder $projectUserRoleQuery - * @property \Kanboard\Core\Filter\QueryBuilder $projectActivityQuery - * @property \Kanboard\Core\Filter\QueryBuilder $userQuery - * @property \Kanboard\Core\Filter\QueryBuilder $projectQuery - * @property \Kanboard\Core\Filter\QueryBuilder $taskQuery - * @property \Kanboard\Core\Filter\LexerBuilder $taskLexer - * @property \Kanboard\Core\Filter\LexerBuilder $projectActivityLexer - * @property \Psr\Log\LoggerInterface $logger - * @property \PicoDb\Database $db - * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher + * @property \Kanboard\Analytic\TaskDistributionAnalytic $taskDistributionAnalytic + * @property \Kanboard\Analytic\UserDistributionAnalytic $userDistributionAnalytic + * @property \Kanboard\Analytic\EstimatedTimeComparisonAnalytic $estimatedTimeComparisonAnalytic + * @property \Kanboard\Analytic\AverageLeadCycleTimeAnalytic $averageLeadCycleTimeAnalytic + * @property \Kanboard\Analytic\AverageTimeSpentColumnAnalytic $averageTimeSpentColumnAnalytic + * @property \Kanboard\Core\Action\ActionManager $actionManager + * @property \Kanboard\Core\ExternalLink\ExternalLinkManager $externalLinkManager + * @property \Kanboard\Core\Cache\MemoryCache $memoryCache + * @property \Kanboard\Core\Event\EventManager $eventManager + * @property \Kanboard\Core\Group\GroupManager $groupManager + * @property \Kanboard\Core\Http\Client $httpClient + * @property \Kanboard\Core\Http\OAuth2 $oauth + * @property \Kanboard\Core\Http\RememberMeCookie $rememberMeCookie + * @property \Kanboard\Core\Http\Request $request + * @property \Kanboard\Core\Http\Response $response + * @property \Kanboard\Core\Http\Router $router + * @property \Kanboard\Core\Http\Route $route + * @property \Kanboard\Core\Queue\QueueManager $queueManager + * @property \Kanboard\Core\Mail\Client $emailClient + * @property \Kanboard\Core\ObjectStorage\ObjectStorageInterface $objectStorage + * @property \Kanboard\Core\Plugin\Hook $hook + * @property \Kanboard\Core\Plugin\Loader $pluginLoader + * @property \Kanboard\Core\Security\AuthenticationManager $authenticationManager + * @property \Kanboard\Core\Security\AccessMap $applicationAccessMap + * @property \Kanboard\Core\Security\AccessMap $projectAccessMap + * @property \Kanboard\Core\Security\Authorization $applicationAuthorization + * @property \Kanboard\Core\Security\Authorization $projectAuthorization + * @property \Kanboard\Core\Security\Role $role + * @property \Kanboard\Core\Security\Token $token + * @property \Kanboard\Core\Session\FlashMessage $flash + * @property \Kanboard\Core\Session\SessionManager $sessionManager + * @property \Kanboard\Core\Session\SessionStorage $sessionStorage + * @property \Kanboard\Core\User\Avatar\AvatarManager $avatarManager + * @property \Kanboard\Core\User\GroupSync $groupSync + * @property \Kanboard\Core\User\UserProfile $userProfile + * @property \Kanboard\Core\User\UserSync $userSync + * @property \Kanboard\Core\User\UserSession $userSession + * @property \Kanboard\Core\DateParser $dateParser + * @property \Kanboard\Core\Helper $helper + * @property \Kanboard\Core\Paginator $paginator + * @property \Kanboard\Core\Template $template + * @property \Kanboard\Model\ActionModel $actionModel + * @property \Kanboard\Model\ActionParameterModel $actionParameterModel + * @property \Kanboard\Model\AvatarFileModel $avatarFileModel + * @property \Kanboard\Model\BoardModel $boardModel + * @property \Kanboard\Model\CategoryModel $categoryModel + * @property \Kanboard\Model\ColorModel $colorModel + * @property \Kanboard\Model\ColumnModel $columnModel + * @property \Kanboard\Model\CommentModel $commentModel + * @property \Kanboard\Model\ConfigModel $configModel + * @property \Kanboard\Model\CurrencyModel $currencyModel + * @property \Kanboard\Model\CustomFilterModel $customFilterModel + * @property \Kanboard\Model\TaskFileModel $taskFileModel + * @property \Kanboard\Model\ProjectFileModel $projectFileModel + * @property \Kanboard\Model\GroupModel $groupModel + * @property \Kanboard\Model\GroupMemberModel $groupMemberModel + * @property \Kanboard\Model\LanguageModel $languageModel + * @property \Kanboard\Model\LastLoginModel $lastLoginModel + * @property \Kanboard\Model\LinkModel $linkModel + * @property \Kanboard\Model\NotificationModel $notificationModel + * @property \Kanboard\Model\PasswordResetModel $passwordResetModel + * @property \Kanboard\Model\ProjectModel $projectModel + * @property \Kanboard\Model\ProjectActivityModel $projectActivityModel + * @property \Kanboard\Model\ProjectDuplicationModel $projectDuplicationModel + * @property \Kanboard\Model\ProjectDailyColumnStatsModel $projectDailyColumnStatsModel + * @property \Kanboard\Model\ProjectDailyStatsModel $projectDailyStatsModel + * @property \Kanboard\Model\ProjectMetadataModel $projectMetadataModel + * @property \Kanboard\Model\ProjectPermissionModel $projectPermissionModel + * @property \Kanboard\Model\ProjectUserRoleModel $projectUserRoleModel + * @property \Kanboard\Model\ProjectGroupRoleModel $projectGroupRoleModel + * @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel + * @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel + * @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel + * @property \Kanboard\Model\SubtaskModel $subtaskModel + * @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel + * @property \Kanboard\Model\SwimlaneModel $swimlaneModel + * @property \Kanboard\Model\TaskModel $taskModel + * @property \Kanboard\Model\TaskAnalyticModel $taskAnalyticModel + * @property \Kanboard\Model\TaskCreationModel $taskCreationModel + * @property \Kanboard\Model\TaskDuplicationModel $taskDuplicationModel + * @property \Kanboard\Model\TaskExternalLinkModel $taskExternalLinkModel + * @property \Kanboard\Model\TaskFinderModel $taskFinderModel + * @property \Kanboard\Model\TaskLinkModel $taskLinkModel + * @property \Kanboard\Model\TaskModificationModel $taskModificationModel + * @property \Kanboard\Model\TaskPositionModel $taskPositionModel + * @property \Kanboard\Model\TaskStatusModel $taskStatusModel + * @property \Kanboard\Model\TaskMetadataModel $taskMetadataModel + * @property \Kanboard\Model\TimezoneModel $timezoneModel + * @property \Kanboard\Model\TransitionModel $transitionModel + * @property \Kanboard\Model\UserModel $userModel + * @property \Kanboard\Model\UserLockingModel $userLockingModel + * @property \Kanboard\Model\UserMentionModel $userMentionModel + * @property \Kanboard\Model\UserNotificationModel $userNotificationModel + * @property \Kanboard\Model\UserNotificationTypeModel $userNotificationTypeModel + * @property \Kanboard\Model\UserNotificationFilterModel $userNotificationFilterModel + * @property \Kanboard\Model\UserUnreadNotificationModel $userUnreadNotificationModel + * @property \Kanboard\Model\UserMetadataModel $userMetadataModel + * @property \Kanboard\Validator\ActionValidator $actionValidator + * @property \Kanboard\Validator\AuthValidator $authValidator + * @property \Kanboard\Validator\ColumnValidator $columnValidator + * @property \Kanboard\Validator\CategoryValidator $categoryValidator + * @property \Kanboard\Validator\CommentValidator $commentValidator + * @property \Kanboard\Validator\CurrencyValidator $currencyValidator + * @property \Kanboard\Validator\CustomFilterValidator $customFilterValidator + * @property \Kanboard\Validator\GroupValidator $groupValidator + * @property \Kanboard\Validator\LinkValidator $linkValidator + * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator + * @property \Kanboard\Validator\ProjectValidator $projectValidator + * @property \Kanboard\Validator\SubtaskValidator $subtaskValidator + * @property \Kanboard\Validator\SwimlaneValidator $swimlaneValidator + * @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator + * @property \Kanboard\Validator\ExternalLinkValidator $externalLinkValidator + * @property \Kanboard\Validator\TaskValidator $taskValidator + * @property \Kanboard\Validator\UserValidator $userValidator + * @property \Kanboard\Import\TaskImport $taskImport + * @property \Kanboard\Import\UserImport $userImport + * @property \Kanboard\Export\SubtaskExport $subtaskExport + * @property \Kanboard\Export\TaskExport $taskExport + * @property \Kanboard\Export\TransitionExport $transitionExport + * @property \Kanboard\Core\Filter\QueryBuilder $projectGroupRoleQuery + * @property \Kanboard\Core\Filter\QueryBuilder $projectUserRoleQuery + * @property \Kanboard\Core\Filter\QueryBuilder $projectActivityQuery + * @property \Kanboard\Core\Filter\QueryBuilder $userQuery + * @property \Kanboard\Core\Filter\QueryBuilder $projectQuery + * @property \Kanboard\Core\Filter\QueryBuilder $taskQuery + * @property \Kanboard\Core\Filter\LexerBuilder $taskLexer + * @property \Kanboard\Core\Filter\LexerBuilder $projectActivityLexer + * @property \Psr\Log\LoggerInterface $logger + * @property \PicoDb\Database $db + * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */ abstract class Base { diff --git a/app/Core/Event/EventManager.php b/app/Core/Event/EventManager.php index 162d23e8..9ae43170 100644 --- a/app/Core/Event/EventManager.php +++ b/app/Core/Event/EventManager.php @@ -2,8 +2,8 @@ namespace Kanboard\Core\Event; -use Kanboard\Model\Task; -use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskLinkModel; /** * Event Manager @@ -44,15 +44,15 @@ class EventManager public function getAll() { $events = array( - TaskLink::EVENT_CREATE_UPDATE => t('Task link creation or modification'), - Task::EVENT_MOVE_COLUMN => t('Move a task to another column'), - Task::EVENT_UPDATE => t('Task modification'), - Task::EVENT_CREATE => t('Task creation'), - Task::EVENT_OPEN => t('Reopen a task'), - Task::EVENT_CLOSE => t('Closing a task'), - Task::EVENT_CREATE_UPDATE => t('Task creation or modification'), - Task::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'), - Task::EVENT_DAILY_CRONJOB => t('Daily background job for tasks'), + TaskLinkModel::EVENT_CREATE_UPDATE => t('Task link creation or modification'), + TaskModel::EVENT_MOVE_COLUMN => t('Move a task to another column'), + TaskModel::EVENT_UPDATE => t('Task modification'), + TaskModel::EVENT_CREATE => t('Task creation'), + TaskModel::EVENT_OPEN => t('Reopen a task'), + TaskModel::EVENT_CLOSE => t('Closing a task'), + TaskModel::EVENT_CREATE_UPDATE => t('Task creation or modification'), + TaskModel::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'), + TaskModel::EVENT_DAILY_CRONJOB => t('Daily background job for tasks'), ); $events = array_merge($events, $this->events); diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php index 592c29b1..b5abe5ed 100644 --- a/app/Core/Markdown.php +++ b/app/Core/Markdown.php @@ -87,7 +87,7 @@ class Markdown extends Parsedown protected function inlineUserLink(array $Excerpt) { if (! $this->isPublicLink && preg_match('/^@([^\s]+)/', $Excerpt['text'], $matches)) { - $user_id = $this->container['user']->getIdByUsername($matches[1]); + $user_id = $this->container['userModel']->getIdByUsername($matches[1]); if (! empty($user_id)) { $url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user_id)); @@ -116,7 +116,7 @@ class Markdown extends Parsedown private function buildTaskLink($task_id) { if ($this->isPublicLink) { - $token = $this->container['memoryCache']->proxy($this->container['taskFinder'], 'getProjectToken', $task_id); + $token = $this->container['memoryCache']->proxy($this->container['taskFinderModel'], 'getProjectToken', $task_id); if (! empty($token)) { return $this->container['helper']->url->href( diff --git a/app/Core/User/GroupSync.php b/app/Core/User/GroupSync.php index 4e08d574..d0bb647b 100644 --- a/app/Core/User/GroupSync.php +++ b/app/Core/User/GroupSync.php @@ -21,7 +21,7 @@ class GroupSync extends Base */ public function synchronize($userId, array $externalGroupIds) { - $userGroups = $this->groupMember->getGroups($userId); + $userGroups = $this->groupMemberModel->getGroups($userId); $this->addGroups($userId, $userGroups, $externalGroupIds); $this->removeGroups($userId, $userGroups, $externalGroupIds); } @@ -40,10 +40,10 @@ class GroupSync extends Base foreach ($externalGroupIds as $externalGroupId) { if (! isset($userGroupIds[$externalGroupId])) { - $group = $this->group->getByExternalId($externalGroupId); + $group = $this->groupModel->getByExternalId($externalGroupId); if (! empty($group)) { - $this->groupMember->addUser($group['id'], $userId); + $this->groupMemberModel->addUser($group['id'], $userId); } } } @@ -61,7 +61,7 @@ class GroupSync extends Base { foreach ($userGroups as $userGroup) { if (! empty($userGroup['external_id']) && ! in_array($userGroup['external_id'], $externalGroupIds)) { - $this->groupMember->removeUser($userGroup['id'], $userId); + $this->groupMemberModel->removeUser($userGroup['id'], $userId); } } } diff --git a/app/Core/User/UserProfile.php b/app/Core/User/UserProfile.php index 4f873390..8b9ebb71 100644 --- a/app/Core/User/UserProfile.php +++ b/app/Core/User/UserProfile.php @@ -25,12 +25,12 @@ class UserProfile extends Base */ public function assign($userId, UserProviderInterface $user) { - $profile = $this->user->getById($userId); + $profile = $this->userModel->getById($userId); $values = UserProperty::filterProperties($profile, UserProperty::getProperties($user)); $values['id'] = $userId; - if ($this->user->update($values)) { + if ($this->userModel->update($values)) { $profile = array_merge($profile, $values); $this->userSession->initialize($profile); return true; @@ -49,7 +49,7 @@ class UserProfile extends Base public function initialize(UserProviderInterface $user) { if ($user->getInternalId()) { - $profile = $this->user->getById($user->getInternalId()); + $profile = $this->userModel->getById($user->getInternalId()); } elseif ($user->getExternalIdColumn() && $user->getExternalId()) { $profile = $this->userSync->synchronize($user); $this->groupSync->synchronize($profile['id'], $user->getExternalGroupIds()); diff --git a/app/Core/User/UserSession.php b/app/Core/User/UserSession.php index 0034c47a..9c63f07a 100644 --- a/app/Core/User/UserSession.php +++ b/app/Core/User/UserSession.php @@ -22,7 +22,7 @@ class UserSession extends Base public function refresh($user_id) { if ($this->getId() == $user_id) { - $this->initialize($this->user->getById($user_id)); + $this->initialize($this->userModel->getById($user_id)); } } diff --git a/app/Core/User/UserSync.php b/app/Core/User/UserSync.php index 055c7106..c2f85498 100644 --- a/app/Core/User/UserSync.php +++ b/app/Core/User/UserSync.php @@ -21,7 +21,7 @@ class UserSync extends Base */ public function synchronize(UserProviderInterface $user) { - $profile = $this->user->getByExternalId($user->getExternalIdColumn(), $user->getExternalId()); + $profile = $this->userModel->getByExternalId($user->getExternalIdColumn(), $user->getExternalId()); $properties = UserProperty::getProperties($user); if (! empty($profile)) { @@ -47,7 +47,7 @@ class UserSync extends Base if (! empty($values)) { $values['id'] = $profile['id']; - $result = $this->user->update($values); + $result = $this->userModel->update($values); return $result ? array_merge($profile, $properties) : $profile; } @@ -64,13 +64,13 @@ class UserSync extends Base */ private function createUser(UserProviderInterface $user, array $properties) { - $userId = $this->user->create($properties); + $userId = $this->userModel->create($properties); if ($userId === false) { $this->logger->error('Unable to create user profile: '.$user->getExternalId()); return array(); } - return $this->user->getById($userId); + return $this->userModel->getById($userId); } } diff --git a/app/Export/SubtaskExport.php b/app/Export/SubtaskExport.php index 386c566b..0939838f 100644 --- a/app/Export/SubtaskExport.php +++ b/app/Export/SubtaskExport.php @@ -3,9 +3,9 @@ namespace Kanboard\Export; use Kanboard\Core\Base; -use Kanboard\Model\Task; -use Kanboard\Model\Subtask; -use Kanboard\Model\User; +use Kanboard\Model\TaskModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\UserModel; /** * Subtask Export @@ -34,7 +34,7 @@ class SubtaskExport extends Base */ public function export($project_id, $from, $to) { - $this->subtask_status = $this->subtask->getStatusList(); + $this->subtask_status = $this->subtaskModel->getStatusList(); $subtasks = $this->getSubtasks($project_id, $from, $to); $results = array($this->getColumns()); @@ -106,19 +106,19 @@ class SubtaskExport extends Base $to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to))); } - return $this->db->table(Subtask::TABLE) + return $this->db->table(SubtaskModel::TABLE) ->eq('project_id', $project_id) ->columns( - Subtask::TABLE.'.*', - User::TABLE.'.username AS assignee_username', - User::TABLE.'.name AS assignee_name', - Task::TABLE.'.title AS task_title' + SubtaskModel::TABLE.'.*', + UserModel::TABLE.'.username AS assignee_username', + UserModel::TABLE.'.name AS assignee_name', + TaskModel::TABLE.'.title AS task_title' ) ->gte('date_creation', $from) ->lte('date_creation', $to) - ->join(Task::TABLE, 'id', 'task_id') - ->join(User::TABLE, 'id', 'user_id') - ->asc(Subtask::TABLE.'.id') + ->join(TaskModel::TABLE, 'id', 'task_id') + ->join(UserModel::TABLE, 'id', 'user_id') + ->asc(SubtaskModel::TABLE.'.id') ->findAll(); } } diff --git a/app/Export/TaskExport.php b/app/Export/TaskExport.php index b98582aa..0e576d33 100644 --- a/app/Export/TaskExport.php +++ b/app/Export/TaskExport.php @@ -4,7 +4,7 @@ namespace Kanboard\Export; use Kanboard\Core\Base; use Kanboard\Core\DateParser; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use PDO; /** @@ -27,7 +27,7 @@ class TaskExport extends Base public function export($project_id, $from, $to) { $tasks = $this->getTasks($project_id, $from, $to); - $swimlanes = $this->swimlane->getList($project_id); + $swimlanes = $this->swimlaneModel->getList($project_id); $results = array($this->getColumns()); foreach ($tasks as &$task) { @@ -102,9 +102,9 @@ class TaskExport extends Base */ public function format(array &$task, array &$swimlanes) { - $colors = $this->color->getList(); + $colors = $this->colorModel->getList(); - $task['is_active'] = $task['is_active'] == Task::STATUS_OPEN ? e('Open') : e('Closed'); + $task['is_active'] = $task['is_active'] == TaskModel::STATUS_OPEN ? e('Open') : e('Closed'); $task['color_id'] = $colors[$task['color_id']]; $task['score'] = $task['score'] ?: 0; $task['swimlane_id'] = isset($swimlanes[$task['swimlane_id']]) ? $swimlanes[$task['swimlane_id']] : '?'; diff --git a/app/Export/TransitionExport.php b/app/Export/TransitionExport.php index 97dc28a7..0df1f70e 100644 --- a/app/Export/TransitionExport.php +++ b/app/Export/TransitionExport.php @@ -25,7 +25,7 @@ class TransitionExport extends Base public function export($project_id, $from, $to) { $results = array($this->getColumns()); - $transitions = $this->transition->getAllByProjectAndDate($project_id, $from, $to); + $transitions = $this->transitionModel->getAllByProjectAndDate($project_id, $from, $to); foreach ($transitions as $transition) { $results[] = $this->format($transition); @@ -68,7 +68,7 @@ class TransitionExport extends Base $transition['src_column'], $transition['dst_column'], $transition['name'] ?: $transition['username'], - date($this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT), $transition['date']), + date($this->configModel->get('application_datetime_format', DateParser::DATE_TIME_FORMAT), $transition['date']), round($transition['time_spent'] / 3600, 2) ); diff --git a/app/Filter/ProjectActivityCreationDateFilter.php b/app/Filter/ProjectActivityCreationDateFilter.php index d0b7f754..451f6548 100644 --- a/app/Filter/ProjectActivityCreationDateFilter.php +++ b/app/Filter/ProjectActivityCreationDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Filter activity events by creation date @@ -32,7 +32,7 @@ class ProjectActivityCreationDateFilter extends BaseDateFilter implements Filter */ public function apply() { - $this->applyDateFilter(ProjectActivity::TABLE.'.date_creation'); + $this->applyDateFilter(ProjectActivityModel::TABLE.'.date_creation'); return $this; } } diff --git a/app/Filter/ProjectActivityCreatorFilter.php b/app/Filter/ProjectActivityCreatorFilter.php index c95569d6..573238d8 100644 --- a/app/Filter/ProjectActivityCreatorFilter.php +++ b/app/Filter/ProjectActivityCreatorFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Filter activity events by creator @@ -54,7 +54,7 @@ class ProjectActivityCreatorFilter extends BaseFilter implements FilterInterface public function apply() { if ($this->value === 'me') { - $this->query->eq(ProjectActivity::TABLE . '.creator_id', $this->currentUserId); + $this->query->eq(ProjectActivityModel::TABLE . '.creator_id', $this->currentUserId); } else { $this->query->beginOr(); $this->query->ilike('uc.username', '%'.$this->value.'%'); diff --git a/app/Filter/ProjectActivityProjectIdFilter.php b/app/Filter/ProjectActivityProjectIdFilter.php index bb4d8bd1..7146a057 100644 --- a/app/Filter/ProjectActivityProjectIdFilter.php +++ b/app/Filter/ProjectActivityProjectIdFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Filter activity events by projectId @@ -32,7 +32,7 @@ class ProjectActivityProjectIdFilter extends BaseFilter implements FilterInterfa */ public function apply() { - $this->query->eq(ProjectActivity::TABLE.'.project_id', $this->value); + $this->query->eq(ProjectActivityModel::TABLE.'.project_id', $this->value); return $this; } } diff --git a/app/Filter/ProjectActivityProjectIdsFilter.php b/app/Filter/ProjectActivityProjectIdsFilter.php index 47cf0c25..70968f79 100644 --- a/app/Filter/ProjectActivityProjectIdsFilter.php +++ b/app/Filter/ProjectActivityProjectIdsFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Filter activity events by projectIds @@ -33,9 +33,9 @@ class ProjectActivityProjectIdsFilter extends BaseFilter implements FilterInterf public function apply() { if (empty($this->value)) { - $this->query->eq(ProjectActivity::TABLE.'.project_id', 0); + $this->query->eq(ProjectActivityModel::TABLE.'.project_id', 0); } else { - $this->query->in(ProjectActivity::TABLE.'.project_id', $this->value); + $this->query->in(ProjectActivityModel::TABLE.'.project_id', $this->value); } return $this; diff --git a/app/Filter/ProjectActivityProjectNameFilter.php b/app/Filter/ProjectActivityProjectNameFilter.php index 0cf73657..b4872182 100644 --- a/app/Filter/ProjectActivityProjectNameFilter.php +++ b/app/Filter/ProjectActivityProjectNameFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Filter activity events by project name @@ -32,7 +32,7 @@ class ProjectActivityProjectNameFilter extends BaseFilter implements FilterInter */ public function apply() { - $this->query->ilike(Project::TABLE.'.name', '%'.$this->value.'%'); + $this->query->ilike(ProjectModel::TABLE.'.name', '%'.$this->value.'%'); return $this; } } diff --git a/app/Filter/ProjectActivityTaskIdFilter.php b/app/Filter/ProjectActivityTaskIdFilter.php index e99efe09..b8e074db 100644 --- a/app/Filter/ProjectActivityTaskIdFilter.php +++ b/app/Filter/ProjectActivityTaskIdFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Filter activity events by taskId @@ -32,7 +32,7 @@ class ProjectActivityTaskIdFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->eq(ProjectActivity::TABLE.'.task_id', $this->value); + $this->query->eq(ProjectActivityModel::TABLE.'.task_id', $this->value); return $this; } } diff --git a/app/Filter/ProjectActivityTaskStatusFilter.php b/app/Filter/ProjectActivityTaskStatusFilter.php index 69e2c52d..2c98cabf 100644 --- a/app/Filter/ProjectActivityTaskStatusFilter.php +++ b/app/Filter/ProjectActivityTaskStatusFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter activity events by task status @@ -33,9 +33,9 @@ class ProjectActivityTaskStatusFilter extends BaseFilter implements FilterInterf public function apply() { if ($this->value === 'open') { - $this->query->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN); + $this->query->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN); } elseif ($this->value === 'closed') { - $this->query->eq(Task::TABLE.'.is_active', Task::STATUS_CLOSED); + $this->query->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_CLOSED); } return $this; diff --git a/app/Filter/ProjectGroupRoleProjectFilter.php b/app/Filter/ProjectGroupRoleProjectFilter.php index b0950868..035931b3 100644 --- a/app/Filter/ProjectGroupRoleProjectFilter.php +++ b/app/Filter/ProjectGroupRoleProjectFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectGroupRole; +use Kanboard\Model\ProjectGroupRoleModel; /** * Filter ProjectGroupRole users by project @@ -32,7 +32,7 @@ class ProjectGroupRoleProjectFilter extends BaseFilter implements FilterInterfac */ public function apply() { - $this->query->eq(ProjectGroupRole::TABLE.'.project_id', $this->value); + $this->query->eq(ProjectGroupRoleModel::TABLE.'.project_id', $this->value); return $this; } } diff --git a/app/Filter/ProjectGroupRoleUsernameFilter.php b/app/Filter/ProjectGroupRoleUsernameFilter.php index c10855bc..9feac33f 100644 --- a/app/Filter/ProjectGroupRoleUsernameFilter.php +++ b/app/Filter/ProjectGroupRoleUsernameFilter.php @@ -3,9 +3,9 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\User; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\UserModel; /** * Filter ProjectGroupRole users by username @@ -35,9 +35,9 @@ class ProjectGroupRoleUsernameFilter extends BaseFilter implements FilterInterfa public function apply() { $this->query - ->join(GroupMember::TABLE, 'group_id', 'group_id', ProjectGroupRole::TABLE) - ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE) - ->ilike(User::TABLE.'.username', $this->value.'%'); + ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', ProjectGroupRoleModel::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id', GroupMemberModel::TABLE) + ->ilike(UserModel::TABLE.'.username', $this->value.'%'); return $this; } diff --git a/app/Filter/ProjectIdsFilter.php b/app/Filter/ProjectIdsFilter.php index 641f7f18..9af9db5a 100644 --- a/app/Filter/ProjectIdsFilter.php +++ b/app/Filter/ProjectIdsFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Filter project by ids @@ -33,9 +33,9 @@ class ProjectIdsFilter extends BaseFilter implements FilterInterface public function apply() { if (empty($this->value)) { - $this->query->eq(Project::TABLE.'.id', 0); + $this->query->eq(ProjectModel::TABLE.'.id', 0); } else { - $this->query->in(Project::TABLE.'.id', $this->value); + $this->query->in(ProjectModel::TABLE.'.id', $this->value); } return $this; diff --git a/app/Filter/ProjectStatusFilter.php b/app/Filter/ProjectStatusFilter.php index a994600c..c1a06eff 100644 --- a/app/Filter/ProjectStatusFilter.php +++ b/app/Filter/ProjectStatusFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Filter project by status @@ -33,11 +33,11 @@ class ProjectStatusFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Project::TABLE.'.is_active', $this->value); + $this->query->eq(ProjectModel::TABLE.'.is_active', $this->value); } elseif ($this->value === 'inactive' || $this->value === 'closed' || $this->value === 'disabled') { - $this->query->eq(Project::TABLE.'.is_active', 0); + $this->query->eq(ProjectModel::TABLE.'.is_active', 0); } else { - $this->query->eq(Project::TABLE.'.is_active', 1); + $this->query->eq(ProjectModel::TABLE.'.is_active', 1); } return $this; diff --git a/app/Filter/ProjectTypeFilter.php b/app/Filter/ProjectTypeFilter.php index e085e2f6..6afcd293 100644 --- a/app/Filter/ProjectTypeFilter.php +++ b/app/Filter/ProjectTypeFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Filter project by type @@ -33,11 +33,11 @@ class ProjectTypeFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Project::TABLE.'.is_private', $this->value); + $this->query->eq(ProjectModel::TABLE.'.is_private', $this->value); } elseif ($this->value === 'private') { - $this->query->eq(Project::TABLE.'.is_private', Project::TYPE_PRIVATE); + $this->query->eq(ProjectModel::TABLE.'.is_private', ProjectModel::TYPE_PRIVATE); } else { - $this->query->eq(Project::TABLE.'.is_private', Project::TYPE_TEAM); + $this->query->eq(ProjectModel::TABLE.'.is_private', ProjectModel::TYPE_TEAM); } return $this; diff --git a/app/Filter/ProjectUserRoleProjectFilter.php b/app/Filter/ProjectUserRoleProjectFilter.php index 3b880df5..6952364e 100644 --- a/app/Filter/ProjectUserRoleProjectFilter.php +++ b/app/Filter/ProjectUserRoleProjectFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectUserRoleModel; /** * Filter ProjectUserRole users by project @@ -32,7 +32,7 @@ class ProjectUserRoleProjectFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->eq(ProjectUserRole::TABLE.'.project_id', $this->value); + $this->query->eq(ProjectUserRoleModel::TABLE.'.project_id', $this->value); return $this; } } diff --git a/app/Filter/ProjectUserRoleUsernameFilter.php b/app/Filter/ProjectUserRoleUsernameFilter.php index c00493a3..327d3d57 100644 --- a/app/Filter/ProjectUserRoleUsernameFilter.php +++ b/app/Filter/ProjectUserRoleUsernameFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; /** * Filter ProjectUserRole users by username @@ -33,8 +33,8 @@ class ProjectUserRoleUsernameFilter extends BaseFilter implements FilterInterfac public function apply() { $this->query - ->join(User::TABLE, 'id', 'user_id') - ->ilike(User::TABLE.'.username', $this->value.'%'); + ->join(UserModel::TABLE, 'id', 'user_id') + ->ilike(UserModel::TABLE.'.username', $this->value.'%'); return $this; } diff --git a/app/Filter/TaskAssigneeFilter.php b/app/Filter/TaskAssigneeFilter.php index 783d6a12..d6962a93 100644 --- a/app/Filter/TaskAssigneeFilter.php +++ b/app/Filter/TaskAssigneeFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; -use Kanboard\Model\User; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; /** * Filter tasks by assignee @@ -55,19 +55,19 @@ class TaskAssigneeFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.owner_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.owner_id', $this->value); } else { switch ($this->value) { case 'me': - $this->query->eq(Task::TABLE.'.owner_id', $this->currentUserId); + $this->query->eq(TaskModel::TABLE.'.owner_id', $this->currentUserId); break; case 'nobody': - $this->query->eq(Task::TABLE.'.owner_id', 0); + $this->query->eq(TaskModel::TABLE.'.owner_id', 0); break; default: $this->query->beginOr(); - $this->query->ilike(User::TABLE.'.username', '%'.$this->value.'%'); - $this->query->ilike(User::TABLE.'.name', '%'.$this->value.'%'); + $this->query->ilike(UserModel::TABLE.'.username', '%'.$this->value.'%'); + $this->query->ilike(UserModel::TABLE.'.name', '%'.$this->value.'%'); $this->query->closeOr(); } } diff --git a/app/Filter/TaskCategoryFilter.php b/app/Filter/TaskCategoryFilter.php index 517f24d9..35c52f69 100644 --- a/app/Filter/TaskCategoryFilter.php +++ b/app/Filter/TaskCategoryFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Category; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by category @@ -34,11 +34,11 @@ class TaskCategoryFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.category_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.category_id', $this->value); } elseif ($this->value === 'none') { - $this->query->eq(Task::TABLE.'.category_id', 0); + $this->query->eq(TaskModel::TABLE.'.category_id', 0); } else { - $this->query->eq(Category::TABLE.'.name', $this->value); + $this->query->eq(CategoryModel::TABLE.'.name', $this->value); } return $this; diff --git a/app/Filter/TaskColorFilter.php b/app/Filter/TaskColorFilter.php index 784162d4..2ddb47ce 100644 --- a/app/Filter/TaskColorFilter.php +++ b/app/Filter/TaskColorFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Color; -use Kanboard\Model\Task; +use Kanboard\Model\ColorModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by color @@ -18,7 +18,7 @@ class TaskColorFilter extends BaseFilter implements FilterInterface * Color object * * @access private - * @var Color + * @var ColorModel */ private $colorModel; @@ -26,10 +26,10 @@ class TaskColorFilter extends BaseFilter implements FilterInterface * Set color model object * * @access public - * @param Color $colorModel + * @param ColorModel $colorModel * @return TaskColorFilter */ - public function setColorModel(Color $colorModel) + public function setColorModel(ColorModel $colorModel) { $this->colorModel = $colorModel; return $this; @@ -54,7 +54,7 @@ class TaskColorFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->eq(Task::TABLE.'.color_id', $this->colorModel->find($this->value)); + $this->query->eq(TaskModel::TABLE.'.color_id', $this->colorModel->find($this->value)); return $this; } } diff --git a/app/Filter/TaskColumnFilter.php b/app/Filter/TaskColumnFilter.php index 9a4d4253..fa925b79 100644 --- a/app/Filter/TaskColumnFilter.php +++ b/app/Filter/TaskColumnFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Column; -use Kanboard\Model\Task; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by column @@ -34,9 +34,9 @@ class TaskColumnFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.column_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.column_id', $this->value); } else { - $this->query->eq(Column::TABLE.'.title', $this->value); + $this->query->eq(ColumnModel::TABLE.'.title', $this->value); } return $this; diff --git a/app/Filter/TaskCommentFilter.php b/app/Filter/TaskCommentFilter.php index 455098c2..52db5581 100644 --- a/app/Filter/TaskCommentFilter.php +++ b/app/Filter/TaskCommentFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Comment; -use Kanboard\Model\Task; +use Kanboard\Model\CommentModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by comment @@ -33,8 +33,8 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->ilike(Comment::TABLE.'.comment', '%'.$this->value.'%'); - $this->query->join(Comment::TABLE, 'task_id', 'id', Task::TABLE); + $this->query->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%'); + $this->query->join(CommentModel::TABLE, 'task_id', 'id', TaskModel::TABLE); return $this; } diff --git a/app/Filter/TaskCompletionDateFilter.php b/app/Filter/TaskCompletionDateFilter.php index f206a3e2..79b5e7d8 100644 --- a/app/Filter/TaskCompletionDateFilter.php +++ b/app/Filter/TaskCompletionDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by completion date @@ -32,7 +32,7 @@ class TaskCompletionDateFilter extends BaseDateFilter implements FilterInterface */ public function apply() { - $this->applyDateFilter(Task::TABLE.'.date_completed'); + $this->applyDateFilter(TaskModel::TABLE.'.date_completed'); return $this; } } diff --git a/app/Filter/TaskCreationDateFilter.php b/app/Filter/TaskCreationDateFilter.php index bb6efad6..db28ac88 100644 --- a/app/Filter/TaskCreationDateFilter.php +++ b/app/Filter/TaskCreationDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by creation date @@ -32,7 +32,7 @@ class TaskCreationDateFilter extends BaseDateFilter implements FilterInterface */ public function apply() { - $this->applyDateFilter(Task::TABLE.'.date_creation'); + $this->applyDateFilter(TaskModel::TABLE.'.date_creation'); return $this; } } diff --git a/app/Filter/TaskCreatorFilter.php b/app/Filter/TaskCreatorFilter.php index af35e6bc..611db189 100644 --- a/app/Filter/TaskCreatorFilter.php +++ b/app/Filter/TaskCreatorFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by creator @@ -54,14 +54,14 @@ class TaskCreatorFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.creator_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.creator_id', $this->value); } else { switch ($this->value) { case 'me': - $this->query->eq(Task::TABLE.'.creator_id', $this->currentUserId); + $this->query->eq(TaskModel::TABLE.'.creator_id', $this->currentUserId); break; case 'nobody': - $this->query->eq(Task::TABLE.'.creator_id', 0); + $this->query->eq(TaskModel::TABLE.'.creator_id', 0); break; default: $this->query->beginOr(); diff --git a/app/Filter/TaskDescriptionFilter.php b/app/Filter/TaskDescriptionFilter.php index 6dda58ae..c73c2f56 100644 --- a/app/Filter/TaskDescriptionFilter.php +++ b/app/Filter/TaskDescriptionFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by description @@ -32,7 +32,7 @@ class TaskDescriptionFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->ilike(Task::TABLE.'.description', '%'.$this->value.'%'); + $this->query->ilike(TaskModel::TABLE.'.description', '%'.$this->value.'%'); return $this; } } diff --git a/app/Filter/TaskDueDateFilter.php b/app/Filter/TaskDueDateFilter.php index e36efdd0..0de055bf 100644 --- a/app/Filter/TaskDueDateFilter.php +++ b/app/Filter/TaskDueDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by due date @@ -32,9 +32,9 @@ class TaskDueDateFilter extends BaseDateFilter implements FilterInterface */ public function apply() { - $this->query->neq(Task::TABLE.'.date_due', 0); - $this->query->notNull(Task::TABLE.'.date_due'); - $this->applyDateFilter(Task::TABLE.'.date_due'); + $this->query->neq(TaskModel::TABLE.'.date_due', 0); + $this->query->notNull(TaskModel::TABLE.'.date_due'); + $this->applyDateFilter(TaskModel::TABLE.'.date_due'); return $this; } diff --git a/app/Filter/TaskDueDateRangeFilter.php b/app/Filter/TaskDueDateRangeFilter.php index 10deb0d3..a6aefbe2 100644 --- a/app/Filter/TaskDueDateRangeFilter.php +++ b/app/Filter/TaskDueDateRangeFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by due date range @@ -32,8 +32,8 @@ class TaskDueDateRangeFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->gte(Task::TABLE.'.date_due', is_numeric($this->value[0]) ? $this->value[0] : strtotime($this->value[0])); - $this->query->lte(Task::TABLE.'.date_due', is_numeric($this->value[1]) ? $this->value[1] : strtotime($this->value[1])); + $this->query->gte(TaskModel::TABLE.'.date_due', is_numeric($this->value[0]) ? $this->value[0] : strtotime($this->value[0])); + $this->query->lte(TaskModel::TABLE.'.date_due', is_numeric($this->value[1]) ? $this->value[1] : strtotime($this->value[1])); return $this; } } diff --git a/app/Filter/TaskIdExclusionFilter.php b/app/Filter/TaskIdExclusionFilter.php index 8bfefb2b..20177b29 100644 --- a/app/Filter/TaskIdExclusionFilter.php +++ b/app/Filter/TaskIdExclusionFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Exclude task ids @@ -32,7 +32,7 @@ class TaskIdExclusionFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->notin(Task::TABLE.'.id', $this->value); + $this->query->notin(TaskModel::TABLE.'.id', $this->value); return $this; } } diff --git a/app/Filter/TaskIdFilter.php b/app/Filter/TaskIdFilter.php index 87bac794..fdf668b6 100644 --- a/app/Filter/TaskIdFilter.php +++ b/app/Filter/TaskIdFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by id @@ -32,7 +32,7 @@ class TaskIdFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->eq(Task::TABLE.'.id', $this->value); + $this->query->eq(TaskModel::TABLE.'.id', $this->value); return $this; } } diff --git a/app/Filter/TaskLinkFilter.php b/app/Filter/TaskLinkFilter.php index 18a13a09..98cd597f 100644 --- a/app/Filter/TaskLinkFilter.php +++ b/app/Filter/TaskLinkFilter.php @@ -3,9 +3,9 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Link; -use Kanboard\Model\Task; -use Kanboard\Model\TaskLink; +use Kanboard\Model\LinkModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskLinkModel; use PicoDb\Database; use PicoDb\Table; @@ -60,9 +60,9 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface $task_ids = $this->getSubQuery()->findAllByColumn('task_id'); if (! empty($task_ids)) { - $this->query->in(Task::TABLE.'.id', $task_ids); + $this->query->in(TaskModel::TABLE.'.id', $task_ids); } else { - $this->query->eq(Task::TABLE.'.id', 0); // No match + $this->query->eq(TaskModel::TABLE.'.id', 0); // No match } } @@ -74,12 +74,12 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface */ protected function getSubQuery() { - return $this->db->table(TaskLink::TABLE) + return $this->db->table(TaskLinkModel::TABLE) ->columns( - TaskLink::TABLE.'.task_id', - Link::TABLE.'.label' + TaskLinkModel::TABLE.'.task_id', + LinkModel::TABLE.'.label' ) - ->join(Link::TABLE, 'id', 'link_id', TaskLink::TABLE) - ->ilike(Link::TABLE.'.label', $this->value); + ->join(LinkModel::TABLE, 'id', 'link_id', TaskLinkModel::TABLE) + ->ilike(LinkModel::TABLE.'.label', $this->value); } } diff --git a/app/Filter/TaskModificationDateFilter.php b/app/Filter/TaskModificationDateFilter.php index 5036e9c1..316f1835 100644 --- a/app/Filter/TaskModificationDateFilter.php +++ b/app/Filter/TaskModificationDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by modification date @@ -32,7 +32,7 @@ class TaskModificationDateFilter extends BaseDateFilter implements FilterInterfa */ public function apply() { - $this->applyDateFilter(Task::TABLE.'.date_modification'); + $this->applyDateFilter(TaskModel::TABLE.'.date_modification'); return $this; } } diff --git a/app/Filter/TaskProjectFilter.php b/app/Filter/TaskProjectFilter.php index e432efee..0b5a336b 100644 --- a/app/Filter/TaskProjectFilter.php +++ b/app/Filter/TaskProjectFilter.php @@ -3,8 +3,8 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by project @@ -34,9 +34,9 @@ class TaskProjectFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.project_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.project_id', $this->value); } else { - $this->query->ilike(Project::TABLE.'.name', $this->value); + $this->query->ilike(ProjectModel::TABLE.'.name', $this->value); } return $this; diff --git a/app/Filter/TaskProjectsFilter.php b/app/Filter/TaskProjectsFilter.php index 47636b1d..2b6b16cb 100644 --- a/app/Filter/TaskProjectsFilter.php +++ b/app/Filter/TaskProjectsFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by project ids @@ -33,9 +33,9 @@ class TaskProjectsFilter extends BaseFilter implements FilterInterface public function apply() { if (empty($this->value)) { - $this->query->eq(Task::TABLE.'.project_id', 0); + $this->query->eq(TaskModel::TABLE.'.project_id', 0); } else { - $this->query->in(Task::TABLE.'.project_id', $this->value); + $this->query->in(TaskModel::TABLE.'.project_id', $this->value); } return $this; diff --git a/app/Filter/TaskReferenceFilter.php b/app/Filter/TaskReferenceFilter.php index 4ad47dd5..27c838f8 100644 --- a/app/Filter/TaskReferenceFilter.php +++ b/app/Filter/TaskReferenceFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by reference @@ -32,7 +32,7 @@ class TaskReferenceFilter extends BaseFilter implements FilterInterface */ public function apply() { - $this->query->eq(Task::TABLE.'.reference', $this->value); + $this->query->eq(TaskModel::TABLE.'.reference', $this->value); return $this; } } diff --git a/app/Filter/TaskStartDateFilter.php b/app/Filter/TaskStartDateFilter.php index dd30762b..d5abedb5 100644 --- a/app/Filter/TaskStartDateFilter.php +++ b/app/Filter/TaskStartDateFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by start date @@ -32,7 +32,7 @@ class TaskStartDateFilter extends BaseDateFilter implements FilterInterface */ public function apply() { - $this->applyDateFilter(Task::TABLE.'.date_started'); + $this->applyDateFilter(TaskModel::TABLE.'.date_started'); return $this; } } diff --git a/app/Filter/TaskStatusFilter.php b/app/Filter/TaskStatusFilter.php index 0ba4361e..a55532cb 100644 --- a/app/Filter/TaskStatusFilter.php +++ b/app/Filter/TaskStatusFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by status @@ -33,9 +33,9 @@ class TaskStatusFilter extends BaseFilter implements FilterInterface public function apply() { if ($this->value === 'open' || $this->value === 'closed') { - $this->query->eq(Task::TABLE.'.is_active', $this->value === 'open' ? Task::STATUS_OPEN : Task::STATUS_CLOSED); + $this->query->eq(TaskModel::TABLE.'.is_active', $this->value === 'open' ? TaskModel::STATUS_OPEN : TaskModel::STATUS_CLOSED); } else { - $this->query->eq(Task::TABLE.'.is_active', $this->value); + $this->query->eq(TaskModel::TABLE.'.is_active', $this->value); } return $this; diff --git a/app/Filter/TaskSubtaskAssigneeFilter.php b/app/Filter/TaskSubtaskAssigneeFilter.php index 4c757315..46553a3d 100644 --- a/app/Filter/TaskSubtaskAssigneeFilter.php +++ b/app/Filter/TaskSubtaskAssigneeFilter.php @@ -3,9 +3,9 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Subtask; -use Kanboard\Model\Task; -use Kanboard\Model\User; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; use PicoDb\Database; use PicoDb\Table; @@ -81,9 +81,9 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface $task_ids = $this->getSubQuery()->findAllByColumn('task_id'); if (! empty($task_ids)) { - $this->query->in(Task::TABLE.'.id', $task_ids); + $this->query->in(TaskModel::TABLE.'.id', $task_ids); } else { - $this->query->eq(Task::TABLE.'.id', 0); // No match + $this->query->eq(TaskModel::TABLE.'.id', 0); // No match } } @@ -95,15 +95,15 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface */ protected function getSubQuery() { - $subquery = $this->db->table(Subtask::TABLE) + $subquery = $this->db->table(SubtaskModel::TABLE) ->columns( - Subtask::TABLE.'.user_id', - Subtask::TABLE.'.task_id', - User::TABLE.'.name', - User::TABLE.'.username' + SubtaskModel::TABLE.'.user_id', + SubtaskModel::TABLE.'.task_id', + UserModel::TABLE.'.name', + UserModel::TABLE.'.username' ) - ->join(User::TABLE, 'id', 'user_id', Subtask::TABLE) - ->neq(Subtask::TABLE.'.status', Subtask::STATUS_DONE); + ->join(UserModel::TABLE, 'id', 'user_id', SubtaskModel::TABLE) + ->neq(SubtaskModel::TABLE.'.status', SubtaskModel::STATUS_DONE); return $this->applySubQueryFilter($subquery); } @@ -118,19 +118,19 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface protected function applySubQueryFilter(Table $subquery) { if (is_int($this->value) || ctype_digit($this->value)) { - $subquery->eq(Subtask::TABLE.'.user_id', $this->value); + $subquery->eq(SubtaskModel::TABLE.'.user_id', $this->value); } else { switch ($this->value) { case 'me': - $subquery->eq(Subtask::TABLE.'.user_id', $this->currentUserId); + $subquery->eq(SubtaskModel::TABLE.'.user_id', $this->currentUserId); break; case 'nobody': - $subquery->eq(Subtask::TABLE.'.user_id', 0); + $subquery->eq(SubtaskModel::TABLE.'.user_id', 0); break; default: $subquery->beginOr(); - $subquery->ilike(User::TABLE.'.username', $this->value.'%'); - $subquery->ilike(User::TABLE.'.name', '%'.$this->value.'%'); + $subquery->ilike(UserModel::TABLE.'.username', $this->value.'%'); + $subquery->ilike(UserModel::TABLE.'.name', '%'.$this->value.'%'); $subquery->closeOr(); } } diff --git a/app/Filter/TaskSwimlaneFilter.php b/app/Filter/TaskSwimlaneFilter.php index 4e030244..07243969 100644 --- a/app/Filter/TaskSwimlaneFilter.php +++ b/app/Filter/TaskSwimlaneFilter.php @@ -3,9 +3,9 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Project; -use Kanboard\Model\Swimlane; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TaskModel; /** * Filter tasks by swimlane @@ -35,13 +35,13 @@ class TaskSwimlaneFilter extends BaseFilter implements FilterInterface public function apply() { if (is_int($this->value) || ctype_digit($this->value)) { - $this->query->eq(Task::TABLE.'.swimlane_id', $this->value); + $this->query->eq(TaskModel::TABLE.'.swimlane_id', $this->value); } elseif ($this->value === 'default') { - $this->query->eq(Task::TABLE.'.swimlane_id', 0); + $this->query->eq(TaskModel::TABLE.'.swimlane_id', 0); } else { $this->query->beginOr(); - $this->query->ilike(Swimlane::TABLE.'.name', $this->value); - $this->query->ilike(Project::TABLE.'.default_swimlane', $this->value); + $this->query->ilike(SwimlaneModel::TABLE.'.name', $this->value); + $this->query->ilike(ProjectModel::TABLE.'.default_swimlane', $this->value); $this->query->closeOr(); } diff --git a/app/Filter/TaskTitleFilter.php b/app/Filter/TaskTitleFilter.php index 9853369c..4e3a2df1 100644 --- a/app/Filter/TaskTitleFilter.php +++ b/app/Filter/TaskTitleFilter.php @@ -3,7 +3,7 @@ namespace Kanboard\Filter; use Kanboard\Core\Filter\FilterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Filter tasks by title @@ -34,11 +34,11 @@ class TaskTitleFilter extends BaseFilter implements FilterInterface { if (ctype_digit($this->value) || (strlen($this->value) > 1 && $this->value{0} === '#' && ctype_digit(substr($this->value, 1)))) { $this->query->beginOr(); - $this->query->eq(Task::TABLE.'.id', str_replace('#', '', $this->value)); - $this->query->ilike(Task::TABLE.'.title', '%'.$this->value.'%'); + $this->query->eq(TaskModel::TABLE.'.id', str_replace('#', '', $this->value)); + $this->query->ilike(TaskModel::TABLE.'.title', '%'.$this->value.'%'); $this->query->closeOr(); } else { - $this->query->ilike(Task::TABLE.'.title', '%'.$this->value.'%'); + $this->query->ilike(TaskModel::TABLE.'.title', '%'.$this->value.'%'); } return $this; diff --git a/app/Formatter/BoardFormatter.php b/app/Formatter/BoardFormatter.php index 6a96b3e6..dbc7cf21 100644 --- a/app/Formatter/BoardFormatter.php +++ b/app/Formatter/BoardFormatter.php @@ -3,7 +3,7 @@ namespace Kanboard\Formatter; use Kanboard\Core\Filter\FormatterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Board Formatter @@ -43,11 +43,11 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface public function format() { $tasks = $this->query - ->eq(Task::TABLE.'.project_id', $this->projectId) - ->asc(Task::TABLE.'.position') + ->eq(TaskModel::TABLE.'.project_id', $this->projectId) + ->asc(TaskModel::TABLE.'.position') ->findAll(); - return $this->board->getBoard($this->projectId, function ($project_id, $column_id, $swimlane_id) use ($tasks) { + return $this->boardModel->getBoard($this->projectId, function ($project_id, $column_id, $swimlane_id) use ($tasks) { return array_filter($tasks, function (array $task) use ($column_id, $swimlane_id) { return $task['column_id'] == $column_id && $task['swimlane_id'] == $swimlane_id; }); diff --git a/app/Formatter/ProjectActivityEventFormatter.php b/app/Formatter/ProjectActivityEventFormatter.php index ae80e5e7..aa0ea7cd 100644 --- a/app/Formatter/ProjectActivityEventFormatter.php +++ b/app/Formatter/ProjectActivityEventFormatter.php @@ -21,7 +21,7 @@ class ProjectActivityEventFormatter extends BaseFormatter implements FormatterIn unset($event['data']); $event['author'] = $event['author_name'] ?: $event['author_username']; - $event['event_title'] = $this->notification->getTitleWithAuthor($event['author'], $event['event_name'], $event); + $event['event_title'] = $this->notificationModel->getTitleWithAuthor($event['author'], $event['event_name'], $event); $event['event_content'] = $this->renderEvent($event); } diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php index 2400ed70..af04f498 100644 --- a/app/Formatter/ProjectGanttFormatter.php +++ b/app/Formatter/ProjectGanttFormatter.php @@ -21,7 +21,7 @@ class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface public function format() { $projects = $this->query->findAll(); - $colors = $this->color->getDefaultColors(); + $colors = $this->colorModel->getDefaultColors(); $bars = array(); foreach ($projects as $project) { @@ -48,7 +48,7 @@ class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface 'gantt_link' => $this->helper->url->href('TaskGanttController', 'show', array('project_id' => $project['id'])), 'color' => $color, 'not_defined' => empty($project['start_date']) || empty($project['end_date']), - 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), + 'users' => $this->projectUserRoleModel->getAllUsersGroupedByRole($project['id']), ); } diff --git a/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php b/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php index 047a39b9..b7b81d87 100644 --- a/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php +++ b/app/Formatter/SubtaskTimeTrackingCalendarFormatter.php @@ -25,8 +25,8 @@ class SubtaskTimeTrackingCalendarFormatter extends BaseFormatter implements Form 'title' => t('#%d', $row['task_id']).' '.$row['subtask_title'].$user, 'start' => date('Y-m-d\TH:i:s', $row['start']), 'end' => date('Y-m-d\TH:i:s', $row['end'] ?: time()), - 'backgroundColor' => $this->color->getBackgroundColor($row['color_id']), - 'borderColor' => $this->color->getBorderColor($row['color_id']), + 'backgroundColor' => $this->colorModel->getBackgroundColor($row['color_id']), + 'borderColor' => $this->colorModel->getBorderColor($row['color_id']), 'textColor' => 'black', 'url' => $this->helper->url->to('TaskViewController', 'show', array('task_id' => $row['task_id'], 'project_id' => $row['project_id'])), 'editable' => false, diff --git a/app/Formatter/TaskAutoCompleteFormatter.php b/app/Formatter/TaskAutoCompleteFormatter.php index 480ee797..4f1c4c69 100644 --- a/app/Formatter/TaskAutoCompleteFormatter.php +++ b/app/Formatter/TaskAutoCompleteFormatter.php @@ -3,7 +3,7 @@ namespace Kanboard\Formatter; use Kanboard\Core\Filter\FormatterInterface; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Task AutoComplete Formatter @@ -21,7 +21,7 @@ class TaskAutoCompleteFormatter extends BaseFormatter implements FormatterInterf */ public function format() { - $tasks = $this->query->columns(Task::TABLE.'.id', Task::TABLE.'.title')->findAll(); + $tasks = $this->query->columns(TaskModel::TABLE.'.id', TaskModel::TABLE.'.title')->findAll(); foreach ($tasks as &$task) { $task['value'] = $task['title']; diff --git a/app/Formatter/TaskCalendarFormatter.php b/app/Formatter/TaskCalendarFormatter.php index d478d2bd..75d2a83e 100644 --- a/app/Formatter/TaskCalendarFormatter.php +++ b/app/Formatter/TaskCalendarFormatter.php @@ -44,11 +44,11 @@ class TaskCalendarFormatter extends BaseTaskCalendarFormatter implements Formatt foreach ($this->query->findAll() as $task) { $events[] = array( - 'timezoneParam' => $this->timezone->getCurrentTimezone(), + 'timezoneParam' => $this->timezoneModel->getCurrentTimezone(), 'id' => $task['id'], 'title' => t('#%d', $task['id']).' '.$task['title'], - 'backgroundColor' => $this->color->getBackgroundColor($task['color_id']), - 'borderColor' => $this->color->getBorderColor($task['color_id']), + 'backgroundColor' => $this->colorModel->getBackgroundColor($task['color_id']), + 'borderColor' => $this->colorModel->getBorderColor($task['color_id']), 'textColor' => 'black', 'url' => $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), 'start' => date($this->getDateTimeFormat(), $task[$this->startColumn]), diff --git a/app/Formatter/TaskGanttFormatter.php b/app/Formatter/TaskGanttFormatter.php index 4ff5c019..ddb3f93a 100644 --- a/app/Formatter/TaskGanttFormatter.php +++ b/app/Formatter/TaskGanttFormatter.php @@ -47,7 +47,7 @@ class TaskGanttFormatter extends BaseFormatter implements FormatterInterface private function formatTask(array $task) { if (! isset($this->columns[$task['project_id']])) { - $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + $this->columns[$task['project_id']] = $this->columnModel->getList($task['project_id']); } $start = $task['date_started'] ?: time(); @@ -69,9 +69,9 @@ class TaskGanttFormatter extends BaseFormatter implements FormatterInterface ), 'column_title' => $task['column_name'], 'assignee' => $task['assignee_name'] ?: $task['assignee_username'], - 'progress' => $this->task->getProgress($task, $this->columns[$task['project_id']]).'%', + 'progress' => $this->taskModel->getProgress($task, $this->columns[$task['project_id']]).'%', 'link' => $this->helper->url->href('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), - 'color' => $this->color->getColorProperties($task['color_id']), + 'color' => $this->colorModel->getColorProperties($task['color_id']), 'not_defined' => empty($task['date_due']) || empty($task['date_started']), ); } diff --git a/app/Formatter/UserAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index c46a24d0..cd23a2a4 100644 --- a/app/Formatter/UserAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -2,7 +2,7 @@ namespace Kanboard\Formatter; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; use Kanboard\Core\Filter\FormatterInterface; /** @@ -21,7 +21,7 @@ class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterf */ public function format() { - $users = $this->query->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')->findAll(); + $users = $this->query->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')->findAll(); foreach ($users as &$user) { $user['value'] = $user['username'].' (#'.$user['id'].')'; diff --git a/app/Group/DatabaseBackendGroupProvider.php b/app/Group/DatabaseBackendGroupProvider.php index 6dbaa43c..29d04d57 100644 --- a/app/Group/DatabaseBackendGroupProvider.php +++ b/app/Group/DatabaseBackendGroupProvider.php @@ -23,7 +23,7 @@ class DatabaseBackendGroupProvider extends Base implements GroupBackendProviderI public function find($input) { $result = array(); - $groups = $this->group->search($input); + $groups = $this->groupModel->search($input); foreach ($groups as $group) { $result[] = new DatabaseGroupProvider($group); diff --git a/app/Helper/AppHelper.php b/app/Helper/AppHelper.php index 1f497929..b738f85c 100644 --- a/app/Helper/AppHelper.php +++ b/app/Helper/AppHelper.php @@ -22,7 +22,7 @@ class AppHelper extends Base */ public function config($param, $default_value = '') { - return $this->config->get($param, $default_value); + return $this->configModel->get($param, $default_value); } /** @@ -90,7 +90,7 @@ class AppHelper extends Base */ public function jsLang() { - return $this->language->getJsLanguageCode(); + return $this->languageModel->getJsLanguageCode(); } /** @@ -101,7 +101,7 @@ class AppHelper extends Base */ public function getTimezone() { - return $this->timezone->getCurrentTimezone(); + return $this->timezoneModel->getCurrentTimezone(); } /** diff --git a/app/Helper/AssetHelper.php b/app/Helper/AssetHelper.php index b3dc711f..dad1448a 100644 --- a/app/Helper/AssetHelper.php +++ b/app/Helper/AssetHelper.php @@ -45,8 +45,8 @@ class AssetHelper extends Base */ public function customCss() { - if ($this->config->get('application_stylesheet')) { - return ''; + if ($this->configModel->get('application_stylesheet')) { + return ''; } return ''; @@ -60,6 +60,6 @@ class AssetHelper extends Base */ public function colorCss() { - return ''; + return ''; } } diff --git a/app/Helper/CalendarHelper.php b/app/Helper/CalendarHelper.php index d5f4af21..b35c40f7 100644 --- a/app/Helper/CalendarHelper.php +++ b/app/Helper/CalendarHelper.php @@ -47,7 +47,7 @@ class CalendarHelper extends Base */ public function getTaskEvents(QueryBuilder $queryBuilder, $start, $end) { - $startColumn = $this->config->get('calendar_project_tasks', 'date_started'); + $startColumn = $this->configModel->get('calendar_project_tasks', 'date_started'); $queryBuilder->getQuery()->addCondition($this->getCalendarCondition( $this->dateParser->getTimestampFromIsoFormat($start), @@ -75,7 +75,7 @@ class CalendarHelper extends Base { $formatter = new SubtaskTimeTrackingCalendarFormatter($this->container); return $formatter - ->withQuery($this->subtaskTimeTracking->getUserQuery($user_id) + ->withQuery($this->subtaskTimeTrackingModel->getUserQuery($user_id) ->addCondition($this->getCalendarCondition( $this->dateParser->getTimestampFromIsoFormat($start), $this->dateParser->getTimestampFromIsoFormat($end), diff --git a/app/Helper/DateHelper.php b/app/Helper/DateHelper.php index 3844ce64..7e2ec79c 100644 --- a/app/Helper/DateHelper.php +++ b/app/Helper/DateHelper.php @@ -22,7 +22,7 @@ class DateHelper extends Base */ public function time($value) { - return date($this->config->get('application_time_format', 'H:i'), $value); + return date($this->configModel->get('application_time_format', 'H:i'), $value); } /** @@ -42,7 +42,7 @@ class DateHelper extends Base $value = strtotime($value); } - return date($this->config->get('application_date_format', 'm/d/Y'), $value); + return date($this->configModel->get('application_date_format', 'm/d/Y'), $value); } /** @@ -54,7 +54,7 @@ class DateHelper extends Base */ public function datetime($value) { - return date($this->config->get('application_datetime_format', 'm/d/Y H:i'), $value); + return date($this->configModel->get('application_datetime_format', 'm/d/Y H:i'), $value); } /** diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php index 42047dd9..8ebb05d4 100644 --- a/app/Helper/LayoutHelper.php +++ b/app/Helper/LayoutHelper.php @@ -27,7 +27,7 @@ class LayoutHelper extends Base } if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { - $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + $params['board_selector'] = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); } return $this->pageLayout($template, $params); @@ -110,7 +110,7 @@ class LayoutHelper extends Base public function config($template, array $params) { if (! isset($params['values'])) { - $params['values'] = $this->config->getAll(); + $params['values'] = $this->configModel->getAll(); } if (! isset($params['errors'])) { diff --git a/app/Helper/ProjectActivityHelper.php b/app/Helper/ProjectActivityHelper.php index 0638a978..40f386db 100644 --- a/app/Helper/ProjectActivityHelper.php +++ b/app/Helper/ProjectActivityHelper.php @@ -7,7 +7,7 @@ use Kanboard\Filter\ProjectActivityProjectIdFilter; use Kanboard\Filter\ProjectActivityProjectIdsFilter; use Kanboard\Filter\ProjectActivityTaskIdFilter; use Kanboard\Formatter\ProjectActivityEventFormatter; -use Kanboard\Model\ProjectActivity; +use Kanboard\Model\ProjectActivityModel; /** * Project Activity Helper @@ -26,7 +26,7 @@ class ProjectActivityHelper extends Base */ public function searchEvents($search) { - $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + $projects = $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); $events = array(); if ($search !== '') { @@ -34,7 +34,7 @@ class ProjectActivityHelper extends Base $queryBuilder ->withFilter(new ProjectActivityProjectIdsFilter(array_keys($projects))) ->getQuery() - ->desc(ProjectActivity::TABLE.'.id') + ->desc(ProjectActivityModel::TABLE.'.id') ->limit(500) ; @@ -58,7 +58,7 @@ class ProjectActivityHelper extends Base ->withFilter(new ProjectActivityProjectIdFilter($project_id)); $queryBuilder->getQuery() - ->desc(ProjectActivity::TABLE.'.id') + ->desc(ProjectActivityModel::TABLE.'.id') ->limit($limit) ; @@ -79,7 +79,7 @@ class ProjectActivityHelper extends Base ->withFilter(new ProjectActivityProjectIdsFilter($project_ids)); $queryBuilder->getQuery() - ->desc(ProjectActivity::TABLE.'.id') + ->desc(ProjectActivityModel::TABLE.'.id') ->limit($limit) ; @@ -98,7 +98,7 @@ class ProjectActivityHelper extends Base $queryBuilder = $this->projectActivityQuery ->withFilter(new ProjectActivityTaskIdFilter($task_id)); - $queryBuilder->getQuery()->desc(ProjectActivity::TABLE.'.id'); + $queryBuilder->getQuery()->desc(ProjectActivityModel::TABLE.'.id'); return $queryBuilder->format(new ProjectActivityEventFormatter($this->container)); } diff --git a/app/Helper/ProjectHeaderHelper.php b/app/Helper/ProjectHeaderHelper.php index 19570059..9514f4f2 100644 --- a/app/Helper/ProjectHeaderHelper.php +++ b/app/Helper/ProjectHeaderHelper.php @@ -48,9 +48,9 @@ class ProjectHeaderHelper extends Base return $this->template->render('project_header/header', array( 'project' => $project, 'filters' => $filters, - 'categories_list' => $this->category->getList($project['id'], false), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], false), - 'custom_filters_list' => $this->customFilter->getAll($project['id'], $this->userSession->getId()), + 'categories_list' => $this->categoryModel->getList($project['id'], false), + 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], false), + 'custom_filters_list' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()), 'board_view' => $boardView, )); } diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php index 4857d0ee..1b510d2a 100644 --- a/app/Helper/TaskHelper.php +++ b/app/Helper/TaskHelper.php @@ -22,22 +22,22 @@ class TaskHelper extends Base public function getColors() { - return $this->color->getList(); + return $this->colorModel->getList(); } public function recurrenceTriggers() { - return $this->task->getRecurrenceTriggerList(); + return $this->taskModel->getRecurrenceTriggerList(); } public function recurrenceTimeframes() { - return $this->task->getRecurrenceTimeframeList(); + return $this->taskModel->getRecurrenceTimeframeList(); } public function recurrenceBasedates() { - return $this->task->getRecurrenceBasedateList(); + return $this->taskModel->getRecurrenceBasedateList(); } public function canRemove(array $task) @@ -142,7 +142,7 @@ class TaskHelper extends Base public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->config->get('application_date_format', 'm/d/Y H:i')); + $placeholder = date($this->configModel->get('application_date_format', 'm/d/Y H:i')); $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); $html = $this->helper->form->label(t('Start Date'), 'date_started'); @@ -153,7 +153,7 @@ class TaskHelper extends Base public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->config->get('application_date_format', 'm/d/Y')); + $placeholder = date($this->configModel->get('application_date_format', 'm/d/Y')); $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); $html = $this->helper->form->label(t('Due Date'), 'date_due'); @@ -178,9 +178,9 @@ class TaskHelper extends Base public function getProgress($task) { if (! isset($this->columns[$task['project_id']])) { - $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + $this->columns[$task['project_id']] = $this->columnModel->getList($task['project_id']); } - return $this->task->getProgress($task, $this->columns[$task['project_id']]); + return $this->taskModel->getProgress($task, $this->columns[$task['project_id']]); } } diff --git a/app/Helper/UrlHelper.php b/app/Helper/UrlHelper.php index ab642c62..2127c69e 100644 --- a/app/Helper/UrlHelper.php +++ b/app/Helper/UrlHelper.php @@ -109,7 +109,7 @@ class UrlHelper extends Base public function base() { if (empty($this->base)) { - $this->base = $this->config->get('application_url') ?: $this->server(); + $this->base = $this->configModel->get('application_url') ?: $this->server(); } return $this->base; diff --git a/app/Helper/UserHelper.php b/app/Helper/UserHelper.php index b39d7b62..5c466df3 100644 --- a/app/Helper/UserHelper.php +++ b/app/Helper/UserHelper.php @@ -21,7 +21,7 @@ class UserHelper extends Base */ public function hasNotifications() { - return $this->userUnreadNotification->hasNotifications($this->userSession->getId()); + return $this->userUnreadNotificationModel->hasNotifications($this->userSession->getId()); } /** @@ -50,7 +50,7 @@ class UserHelper extends Base */ public function getFullname(array $user = array()) { - return $this->user->getFullname(empty($user) ? $this->userSession->getAll() : $user); + return $this->userModel->getFullname(empty($user) ? $this->userSession->getAll() : $user); } /** @@ -157,7 +157,7 @@ class UserHelper extends Base */ public function getProjectUserRole($project_id) { - return $this->memoryCache->proxy($this->projectUserRole, 'getUserRole', $project_id, $this->userSession->getId()); + return $this->memoryCache->proxy($this->projectUserRoleModel, 'getUserRole', $project_id, $this->userSession->getId()); } /** diff --git a/app/Import/TaskImport.php b/app/Import/TaskImport.php index 2abafe14..f5ca9b0e 100644 --- a/app/Import/TaskImport.php +++ b/app/Import/TaskImport.php @@ -69,7 +69,7 @@ class TaskImport extends Base $row = $this->prepare($row); if ($this->validateCreation($row)) { - if ($this->taskCreation->create($row) > 0) { + if ($this->taskCreationModel->create($row) > 0) { $this->logger->debug('TaskImport: imported successfully line '.$line_number); $this->counter++; } else { @@ -100,27 +100,27 @@ class TaskImport extends Base $values['time_spent'] = (float) $row['time_spent']; if (! empty($row['assignee'])) { - $values['owner_id'] = $this->user->getIdByUsername($row['assignee']); + $values['owner_id'] = $this->userModel->getIdByUsername($row['assignee']); } if (! empty($row['creator'])) { - $values['creator_id'] = $this->user->getIdByUsername($row['creator']); + $values['creator_id'] = $this->userModel->getIdByUsername($row['creator']); } if (! empty($row['color'])) { - $values['color_id'] = $this->color->find($row['color']); + $values['color_id'] = $this->colorModel->find($row['color']); } if (! empty($row['column'])) { - $values['column_id'] = $this->column->getColumnIdByTitle($this->projectId, $row['column']); + $values['column_id'] = $this->columnModel->getColumnIdByTitle($this->projectId, $row['column']); } if (! empty($row['category'])) { - $values['category_id'] = $this->category->getIdByName($this->projectId, $row['category']); + $values['category_id'] = $this->categoryModel->getIdByName($this->projectId, $row['category']); } if (! empty($row['swimlane'])) { - $values['swimlane_id'] = $this->swimlane->getIdByName($this->projectId, $row['swimlane']); + $values['swimlane_id'] = $this->swimlaneModel->getIdByName($this->projectId, $row['swimlane']); } if (! empty($row['date_due'])) { diff --git a/app/Import/UserImport.php b/app/Import/UserImport.php index 64300d77..c877e82a 100644 --- a/app/Import/UserImport.php +++ b/app/Import/UserImport.php @@ -2,7 +2,7 @@ namespace Kanboard\Import; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; use SimpleValidator\Validator; use SimpleValidator\Validators; use Kanboard\Core\Security\Role; @@ -56,7 +56,7 @@ class UserImport extends Base $row = $this->prepare($row); if ($this->validateCreation($row)) { - if ($this->user->create($row)) { + if ($this->userModel->create($row)) { $this->logger->debug('UserImport: imported successfully line '.$line_number); $this->counter++; } else { @@ -109,7 +109,7 @@ class UserImport extends Base { $v = new Validator($values, array( new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), - new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), User::TABLE, 'id'), + new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), UserModel::TABLE, 'id'), new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6), new Validators\Email('email', t('Email address invalid')), new Validators\Integer('is_ldap_user', t('This value must be an integer')), diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php index d5fce222..904a9273 100644 --- a/app/Job/NotificationJob.php +++ b/app/Job/NotificationJob.php @@ -39,10 +39,10 @@ class NotificationJob extends BaseJob if (! empty($eventData)) { if (! empty($event['mention'])) { - $this->userNotification->sendUserNotification($event['mention'], $eventName, $eventData); + $this->userNotificationModel->sendUserNotification($event['mention'], $eventName, $eventData); } else { - $this->userNotification->sendNotifications($eventName, $eventData); - $this->projectNotification->sendNotifications($eventData['task']['project_id'], $eventName, $eventData); + $this->userNotificationModel->sendNotifications($eventName, $eventData); + $this->projectNotificationModel->sendNotifications($eventData['task']['project_id'], $eventName, $eventData); } } } @@ -64,19 +64,19 @@ class NotificationJob extends BaseJob switch ($eventObjectName) { case 'Kanboard\Event\TaskEvent': - $values['task'] = $this->taskFinder->getDetails($event['task_id']); + $values['task'] = $this->taskFinderModel->getDetails($event['task_id']); break; case 'Kanboard\Event\SubtaskEvent': - $values['subtask'] = $this->subtask->getById($event['id'], true); - $values['task'] = $this->taskFinder->getDetails($values['subtask']['task_id']); + $values['subtask'] = $this->subtaskModel->getById($event['id'], true); + $values['task'] = $this->taskFinderModel->getDetails($values['subtask']['task_id']); break; case 'Kanboard\Event\FileEvent': $values['file'] = $event; - $values['task'] = $this->taskFinder->getDetails($values['file']['task_id']); + $values['task'] = $this->taskFinderModel->getDetails($values['file']['task_id']); break; case 'Kanboard\Event\CommentEvent': - $values['comment'] = $this->comment->getById($event['id']); - $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']); + $values['comment'] = $this->commentModel->getById($event['id']); + $values['task'] = $this->taskFinderModel->getDetails($values['comment']['task_id']); break; } diff --git a/app/Job/ProjectMetricJob.php b/app/Job/ProjectMetricJob.php index 2c3e589c..6330bd4c 100644 --- a/app/Job/ProjectMetricJob.php +++ b/app/Job/ProjectMetricJob.php @@ -34,7 +34,7 @@ class ProjectMetricJob extends BaseJob $this->logger->debug(__METHOD__.' Run project metrics calculation'); $now = date('Y-m-d'); - $this->projectDailyColumnStats->updateTotals($projectId, $now); - $this->projectDailyStats->updateTotals($projectId, $now); + $this->projectDailyColumnStatsModel->updateTotals($projectId, $now); + $this->projectDailyStatsModel->updateTotals($projectId, $now); } } diff --git a/app/Middleware/ProjectAuthorizationMiddleware.php b/app/Middleware/ProjectAuthorizationMiddleware.php index 6000ee0e..704491b7 100644 --- a/app/Middleware/ProjectAuthorizationMiddleware.php +++ b/app/Middleware/ProjectAuthorizationMiddleware.php @@ -22,7 +22,7 @@ class ProjectAuthorizationMiddleware extends BaseMiddleware $task_id = $this->request->getIntegerParam('task_id'); if ($task_id > 0 && $project_id === 0) { - $project_id = $this->taskFinder->getProjectId($task_id); + $project_id = $this->taskFinderModel->getProjectId($task_id); } if ($project_id > 0 && ! $this->helper->user->hasProjectAccess($this->router->getController(), $this->router->getAction(), $project_id)) { diff --git a/app/Model/Action.php b/app/Model/Action.php deleted file mode 100644 index 568ac85a..00000000 --- a/app/Model/Action.php +++ /dev/null @@ -1,190 +0,0 @@ -projectPermission->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')); - $this->attachParamsToActions($actions, $params); - } - - return $actions; - } - - /** - * Return actions and parameters for a given project - * - * @access public - * @param integer $project_id - * @return array - */ - 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')); - return $this->attachParamsToActions($actions, $params); - } - - /** - * Return all actions and parameters - * - * @access public - * @return array - */ - public function getAll() - { - $actions = $this->db->table(self::TABLE)->findAll(); - $params = $this->actionParameter->getAll(); - return $this->attachParamsToActions($actions, $params); - } - - /** - * Fetch an action - * - * @access public - * @param integer $action_id - * @return array - */ - public function getById($action_id) - { - $action = $this->db->table(self::TABLE)->eq('id', $action_id)->findOne(); - - if (! empty($action)) { - $action['params'] = $this->actionParameter->getAllByAction($action_id); - } - - return $action; - } - - /** - * Attach parameters to actions - * - * @access private - * @param array &$actions - * @param array &$params - * @return array - */ - private function attachParamsToActions(array &$actions, array &$params) - { - foreach ($actions as &$action) { - $action['params'] = isset($params[$action['id']]) ? $params[$action['id']] : array(); - } - - return $actions; - } - - /** - * Remove an action - * - * @access public - * @param integer $action_id - * @return bool - */ - public function remove($action_id) - { - return $this->db->table(self::TABLE)->eq('id', $action_id)->remove(); - } - - /** - * Create an action - * - * @access public - * @param array $values Required parameters to save an action - * @return boolean|integer - */ - public function create(array $values) - { - $this->db->startTransaction(); - - $action = array( - 'project_id' => $values['project_id'], - 'event_name' => $values['event_name'], - 'action_name' => $values['action_name'], - ); - - if (! $this->db->table(self::TABLE)->insert($action)) { - $this->db->cancelTransaction(); - return false; - } - - $action_id = $this->db->getLastId(); - - if (! $this->actionParameter->create($action_id, $values)) { - $this->db->cancelTransaction(); - return false; - } - - $this->db->closeTransaction(); - - return $action_id; - } - - /** - * Copy actions from a project to another one (skip actions that cannot resolve parameters) - * - * @author Antonio Rabelo - * @param integer $src_project_id Source project id - * @param integer $dst_project_id Destination project id - * @return boolean - */ - public function duplicate($src_project_id, $dst_project_id) - { - $actions = $this->action->getAllByProject($src_project_id); - - foreach ($actions as $action) { - $this->db->startTransaction(); - - $values = array( - 'project_id' => $dst_project_id, - 'event_name' => $action['event_name'], - 'action_name' => $action['action_name'], - ); - - if (! $this->db->table(self::TABLE)->insert($values)) { - $this->db->cancelTransaction(); - continue; - } - - $action_id = $this->db->getLastId(); - - if (! $this->actionParameter->duplicateParameters($dst_project_id, $action_id, $action['params'])) { - $this->logger->error('Action::duplicate => skip action '.$action['action_name'].' '.$action['id']); - $this->db->cancelTransaction(); - continue; - } - - $this->db->closeTransaction(); - } - - return true; - } -} diff --git a/app/Model/ActionModel.php b/app/Model/ActionModel.php new file mode 100644 index 00000000..53393ed5 --- /dev/null +++ b/app/Model/ActionModel.php @@ -0,0 +1,190 @@ +projectPermissionModel->getActiveProjectIds($user_id); + $actions = array(); + + if (! empty($project_ids)) { + $actions = $this->db->table(self::TABLE)->in('project_id', $project_ids)->findAll(); + $params = $this->actionParameterModel->getAllByActions(array_column($actions, 'id')); + $this->attachParamsToActions($actions, $params); + } + + return $actions; + } + + /** + * Return actions and parameters for a given project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getAllByProject($project_id) + { + $actions = $this->db->table(self::TABLE)->eq('project_id', $project_id)->findAll(); + $params = $this->actionParameterModel->getAllByActions(array_column($actions, 'id')); + return $this->attachParamsToActions($actions, $params); + } + + /** + * Return all actions and parameters + * + * @access public + * @return array + */ + public function getAll() + { + $actions = $this->db->table(self::TABLE)->findAll(); + $params = $this->actionParameterModel->getAll(); + return $this->attachParamsToActions($actions, $params); + } + + /** + * Fetch an action + * + * @access public + * @param integer $action_id + * @return array + */ + public function getById($action_id) + { + $action = $this->db->table(self::TABLE)->eq('id', $action_id)->findOne(); + + if (! empty($action)) { + $action['params'] = $this->actionParameterModel->getAllByAction($action_id); + } + + return $action; + } + + /** + * Attach parameters to actions + * + * @access private + * @param array &$actions + * @param array &$params + * @return array + */ + private function attachParamsToActions(array &$actions, array &$params) + { + foreach ($actions as &$action) { + $action['params'] = isset($params[$action['id']]) ? $params[$action['id']] : array(); + } + + return $actions; + } + + /** + * Remove an action + * + * @access public + * @param integer $action_id + * @return bool + */ + public function remove($action_id) + { + return $this->db->table(self::TABLE)->eq('id', $action_id)->remove(); + } + + /** + * Create an action + * + * @access public + * @param array $values Required parameters to save an action + * @return boolean|integer + */ + public function create(array $values) + { + $this->db->startTransaction(); + + $action = array( + 'project_id' => $values['project_id'], + 'event_name' => $values['event_name'], + 'action_name' => $values['action_name'], + ); + + if (! $this->db->table(self::TABLE)->insert($action)) { + $this->db->cancelTransaction(); + return false; + } + + $action_id = $this->db->getLastId(); + + if (! $this->actionParameterModel->create($action_id, $values)) { + $this->db->cancelTransaction(); + return false; + } + + $this->db->closeTransaction(); + + return $action_id; + } + + /** + * Copy actions from a project to another one (skip actions that cannot resolve parameters) + * + * @author Antonio Rabelo + * @param integer $src_project_id Source project id + * @param integer $dst_project_id Destination project id + * @return boolean + */ + public function duplicate($src_project_id, $dst_project_id) + { + $actions = $this->actionModel->getAllByProject($src_project_id); + + foreach ($actions as $action) { + $this->db->startTransaction(); + + $values = array( + 'project_id' => $dst_project_id, + 'event_name' => $action['event_name'], + 'action_name' => $action['action_name'], + ); + + if (! $this->db->table(self::TABLE)->insert($values)) { + $this->db->cancelTransaction(); + continue; + } + + $action_id = $this->db->getLastId(); + + 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; + } + + $this->db->closeTransaction(); + } + + return true; + } +} diff --git a/app/Model/ActionParameter.php b/app/Model/ActionParameter.php deleted file mode 100644 index a2fe74e5..00000000 --- a/app/Model/ActionParameter.php +++ /dev/null @@ -1,164 +0,0 @@ -db->table(self::TABLE)->findAll(); - return $this->toDictionary($params); - } - - /** - * Get all params for a list of actions - * - * @access public - * @param array $action_ids - * @return array - */ - public function getAllByActions(array $action_ids) - { - $params = $this->db->table(self::TABLE)->in('action_id', $action_ids)->findAll(); - return $this->toDictionary($params); - } - - /** - * Build params dictionary - * - * @access private - * @param array $params - * @return array - */ - private function toDictionary(array $params) - { - $result = array(); - - foreach ($params as $param) { - $result[$param['action_id']][$param['name']] = $param['value']; - } - - return $result; - } - - /** - * Get all action params for a given action - * - * @access public - * @param integer $action_id - * @return array - */ - public function getAllByAction($action_id) - { - return $this->db->hashtable(self::TABLE)->eq('action_id', $action_id)->getAll('name', 'value'); - } - - /** - * Insert new parameters for an action - * - * @access public - * @param integer $action_id - * @param array $values - * @return boolean - */ - public function create($action_id, array $values) - { - foreach ($values['params'] as $name => $value) { - $param = array( - 'action_id' => $action_id, - 'name' => $name, - 'value' => $value, - ); - - if (! $this->db->table(self::TABLE)->save($param)) { - return false; - } - } - - return true; - } - - /** - * Duplicate action parameters - * - * @access public - * @param integer $project_id - * @param integer $action_id - * @param array $params - * @return boolean - */ - public function duplicateParameters($project_id, $action_id, array $params) - { - foreach ($params as $name => $value) { - $value = $this->resolveParameter($project_id, $name, $value); - - if ($value === false) { - $this->logger->error('ActionParameter::duplicateParameters => unable to resolve '.$name.'='.$value); - return false; - } - - $values = array( - 'action_id' => $action_id, - 'name' => $name, - 'value' => $value, - ); - - if (! $this->db->table(self::TABLE)->insert($values)) { - return false; - } - } - - return true; - } - - /** - * Resolve action parameter values according to another project - * - * @access private - * @param integer $project_id - * @param string $name - * @param string $value - * @return mixed - */ - private function resolveParameter($project_id, $name, $value) - { - switch ($name) { - case 'project_id': - return $value != $project_id ? $value : false; - case 'category_id': - return $this->category->getIdByName($project_id, $this->category->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; - case 'user_id': - case 'owner_id': - return $this->projectPermission->isAssignable($project_id, $value) ? $value : false; - default: - return $value; - } - } -} diff --git a/app/Model/ActionParameterModel.php b/app/Model/ActionParameterModel.php new file mode 100644 index 00000000..9895da0f --- /dev/null +++ b/app/Model/ActionParameterModel.php @@ -0,0 +1,164 @@ +db->table(self::TABLE)->findAll(); + return $this->toDictionary($params); + } + + /** + * Get all params for a list of actions + * + * @access public + * @param array $action_ids + * @return array + */ + public function getAllByActions(array $action_ids) + { + $params = $this->db->table(self::TABLE)->in('action_id', $action_ids)->findAll(); + return $this->toDictionary($params); + } + + /** + * Build params dictionary + * + * @access private + * @param array $params + * @return array + */ + private function toDictionary(array $params) + { + $result = array(); + + foreach ($params as $param) { + $result[$param['action_id']][$param['name']] = $param['value']; + } + + return $result; + } + + /** + * Get all action params for a given action + * + * @access public + * @param integer $action_id + * @return array + */ + public function getAllByAction($action_id) + { + return $this->db->hashtable(self::TABLE)->eq('action_id', $action_id)->getAll('name', 'value'); + } + + /** + * Insert new parameters for an action + * + * @access public + * @param integer $action_id + * @param array $values + * @return boolean + */ + public function create($action_id, array $values) + { + foreach ($values['params'] as $name => $value) { + $param = array( + 'action_id' => $action_id, + 'name' => $name, + 'value' => $value, + ); + + if (! $this->db->table(self::TABLE)->save($param)) { + return false; + } + } + + return true; + } + + /** + * Duplicate action parameters + * + * @access public + * @param integer $project_id + * @param integer $action_id + * @param array $params + * @return boolean + */ + public function duplicateParameters($project_id, $action_id, array $params) + { + foreach ($params as $name => $value) { + $value = $this->resolveParameter($project_id, $name, $value); + + if ($value === false) { + $this->logger->error('ActionParameter::duplicateParameters => unable to resolve '.$name.'='.$value); + return false; + } + + $values = array( + 'action_id' => $action_id, + 'name' => $name, + 'value' => $value, + ); + + if (! $this->db->table(self::TABLE)->insert($values)) { + return false; + } + } + + return true; + } + + /** + * Resolve action parameter values according to another project + * + * @access private + * @param integer $project_id + * @param string $name + * @param string $value + * @return mixed + */ + private function resolveParameter($project_id, $name, $value) + { + switch ($name) { + case 'project_id': + return $value != $project_id ? $value : false; + case 'category_id': + 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->columnModel->getById($value); + return empty($column) ? false : $this->columnModel->getColumnIdByTitle($project_id, $column['title']) ?: false; + case 'user_id': + case 'owner_id': + return $this->projectPermissionModel->isAssignable($project_id, $value) ? $value : false; + default: + return $value; + } + } +} diff --git a/app/Model/AvatarFile.php b/app/Model/AvatarFile.php deleted file mode 100644 index cfb9e713..00000000 --- a/app/Model/AvatarFile.php +++ /dev/null @@ -1,139 +0,0 @@ -db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('avatar_path'); - } - - /** - * Add avatar in the user profile - * - * @access public - * @param integer $user_id Foreign key - * @param string $path Path on the disk - * @return bool - */ - public function create($user_id, $path) - { - $result = $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( - 'avatar_path' => $path, - )); - - $this->userSession->refresh($user_id); - - return $result; - } - - /** - * Remove avatar from the user profile - * - * @access public - * @param integer $user_id Foreign key - * @return bool - */ - public function remove($user_id) - { - try { - $filename = $this->getFilename($user_id); - - if (! empty($filename)) { - $this->objectStorage->remove($filename); - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('avatar_path' => '')); - } - } catch (Exception $e) { - $this->logger->error($e->getMessage()); - return false; - } - - return true; - } - - /** - * Upload avatar image file - * - * @access public - * @param integer $user_id - * @param array $file - * @return boolean - */ - public function uploadImageFile($user_id, array $file) - { - try { - if ($file['error'] == UPLOAD_ERR_OK && $file['size'] > 0) { - $destinationFilename = $this->generatePath($user_id, $file['name']); - $this->objectStorage->moveUploadedFile($file['tmp_name'], $destinationFilename); - $this->create($user_id, $destinationFilename); - } else { - throw new Exception('File not uploaded: '.var_export($file['error'], true)); - } - - } catch (Exception $e) { - $this->logger->error($e->getMessage()); - return false; - } - - return true; - } - - /** - * Upload avatar image content - * - * @access public - * @param integer $user_id - * @param string $blob - * @return boolean - */ - public function uploadImageContent($user_id, &$blob) - { - try { - $destinationFilename = $this->generatePath($user_id, 'imageContent'); - $this->objectStorage->put($destinationFilename, $blob); - $this->create($user_id, $destinationFilename); - } catch (Exception $e) { - $this->logger->error($e->getMessage()); - return false; - } - - return true; - } - - /** - * Generate the path for a new filename - * - * @access public - * @param integer $user_id - * @param string $filename - * @return string - */ - public function generatePath($user_id, $filename) - { - return implode(DIRECTORY_SEPARATOR, array(self::PATH_PREFIX, $user_id, hash('sha1', $filename.time()))); - } -} diff --git a/app/Model/AvatarFileModel.php b/app/Model/AvatarFileModel.php new file mode 100644 index 00000000..6e36d83f --- /dev/null +++ b/app/Model/AvatarFileModel.php @@ -0,0 +1,139 @@ +db->table(UserModel::TABLE)->eq('id', $user_id)->findOneColumn('avatar_path'); + } + + /** + * Add avatar in the user profile + * + * @access public + * @param integer $user_id Foreign key + * @param string $path Path on the disk + * @return bool + */ + public function create($user_id, $path) + { + $result = $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array( + 'avatar_path' => $path, + )); + + $this->userSession->refresh($user_id); + + return $result; + } + + /** + * Remove avatar from the user profile + * + * @access public + * @param integer $user_id Foreign key + * @return bool + */ + public function remove($user_id) + { + try { + $filename = $this->getFilename($user_id); + + if (! empty($filename)) { + $this->objectStorage->remove($filename); + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('avatar_path' => '')); + } + } catch (Exception $e) { + $this->logger->error($e->getMessage()); + return false; + } + + return true; + } + + /** + * Upload avatar image file + * + * @access public + * @param integer $user_id + * @param array $file + * @return boolean + */ + public function uploadImageFile($user_id, array $file) + { + try { + if ($file['error'] == UPLOAD_ERR_OK && $file['size'] > 0) { + $destinationFilename = $this->generatePath($user_id, $file['name']); + $this->objectStorage->moveUploadedFile($file['tmp_name'], $destinationFilename); + $this->create($user_id, $destinationFilename); + } else { + throw new Exception('File not uploaded: '.var_export($file['error'], true)); + } + + } catch (Exception $e) { + $this->logger->error($e->getMessage()); + return false; + } + + return true; + } + + /** + * Upload avatar image content + * + * @access public + * @param integer $user_id + * @param string $blob + * @return boolean + */ + public function uploadImageContent($user_id, &$blob) + { + try { + $destinationFilename = $this->generatePath($user_id, 'imageContent'); + $this->objectStorage->put($destinationFilename, $blob); + $this->create($user_id, $destinationFilename); + } catch (Exception $e) { + $this->logger->error($e->getMessage()); + return false; + } + + return true; + } + + /** + * Generate the path for a new filename + * + * @access public + * @param integer $user_id + * @param string $filename + * @return string + */ + public function generatePath($user_id, $filename) + { + return implode(DIRECTORY_SEPARATOR, array(self::PATH_PREFIX, $user_id, hash('sha1', $filename.time()))); + } +} diff --git a/app/Model/Board.php b/app/Model/Board.php deleted file mode 100644 index 91acfb1b..00000000 --- a/app/Model/Board.php +++ /dev/null @@ -1,175 +0,0 @@ -config->get('board_columns', implode(',', $this->getDefaultColumns()))); - $columns = array(); - - foreach ($column_names as $column_name) { - $column_name = trim($column_name); - - if (! empty($column_name)) { - $columns[] = array('title' => $column_name, 'task_limit' => 0, 'description' => ''); - } - } - - return $columns; - } - - /** - * Create a board with default columns, must be executed inside a transaction - * - * @access public - * @param integer $project_id Project id - * @param array $columns Column parameters [ 'title' => 'boo', 'task_limit' => 2 ... ] - * @return boolean - */ - public function create($project_id, array $columns) - { - $position = 0; - - foreach ($columns as $column) { - $values = array( - 'title' => $column['title'], - 'position' => ++$position, - 'project_id' => $project_id, - 'task_limit' => $column['task_limit'], - 'description' => $column['description'], - ); - - if (! $this->db->table(Column::TABLE)->save($values)) { - return false; - } - } - - return true; - } - - /** - * Copy board columns from a project to another one - * - * @author Antonio Rabelo - * @param integer $project_from Project Template - * @param integer $project_to Project that receives the copy - * @return boolean - */ - public function duplicate($project_from, $project_to) - { - $columns = $this->db->table(Column::TABLE) - ->columns('title', 'task_limit', 'description') - ->eq('project_id', $project_from) - ->asc('position') - ->findAll(); - - return $this->board->create($project_to, $columns); - } - - /** - * Get all tasks sorted by columns and swimlanes - * - * @access public - * @param integer $project_id - * @param callable $callback - * @return array - */ - public function getBoard($project_id, $callback = null) - { - $swimlanes = $this->swimlane->getSwimlanes($project_id); - $columns = $this->column->getAll($project_id); - $nb_columns = count($columns); - - for ($i = 0, $ilen = count($swimlanes); $i < $ilen; $i++) { - $swimlanes[$i]['columns'] = $columns; - $swimlanes[$i]['nb_columns'] = $nb_columns; - $swimlanes[$i]['nb_tasks'] = 0; - $swimlanes[$i]['nb_swimlanes'] = $ilen; - - for ($j = 0; $j < $nb_columns; $j++) { - $column_id = $columns[$j]['id']; - $swimlane_id = $swimlanes[$i]['id']; - - if (! isset($swimlanes[0]['columns'][$j]['nb_column_tasks'])) { - $swimlanes[0]['columns'][$j]['nb_column_tasks'] = 0; - $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]['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']; - $swimlanes[0]['columns'][$j]['nb_column_tasks'] += $swimlanes[$i]['columns'][$j]['nb_tasks']; - $swimlanes[0]['columns'][$j]['total_score'] += $swimlanes[$i]['columns'][$j]['score']; - } - } - - return $swimlanes; - } - - /** - * Calculate the sum of the defined field for a list of tasks - * - * @access public - * @param array $tasks - * @param string $field - * @return integer - */ - public function getColumnSum(array &$tasks, $field) - { - $sum = 0; - - foreach ($tasks as $task) { - $sum += $task[$field]; - } - - return $sum; - } - - /** - * Get the total of tasks per column - * - * @access public - * @param integer $project_id - * @param boolean $prepend Prepend default value - * @return array - */ - public function getColumnStats($project_id, $prepend = false) - { - $listing = $this->db - ->hashtable(Task::TABLE) - ->eq('project_id', $project_id) - ->eq('is_active', 1) - ->groupBy('column_id') - ->getAll('column_id', 'COUNT(*) AS total'); - - return $prepend ? array(-1 => t('All columns')) + $listing : $listing; - } -} diff --git a/app/Model/BoardModel.php b/app/Model/BoardModel.php new file mode 100644 index 00000000..d2718b47 --- /dev/null +++ b/app/Model/BoardModel.php @@ -0,0 +1,175 @@ +configModel->get('board_columns', implode(',', $this->getDefaultColumns()))); + $columns = array(); + + foreach ($column_names as $column_name) { + $column_name = trim($column_name); + + if (! empty($column_name)) { + $columns[] = array('title' => $column_name, 'task_limit' => 0, 'description' => ''); + } + } + + return $columns; + } + + /** + * Create a board with default columns, must be executed inside a transaction + * + * @access public + * @param integer $project_id Project id + * @param array $columns Column parameters [ 'title' => 'boo', 'task_limit' => 2 ... ] + * @return boolean + */ + public function create($project_id, array $columns) + { + $position = 0; + + foreach ($columns as $column) { + $values = array( + 'title' => $column['title'], + 'position' => ++$position, + 'project_id' => $project_id, + 'task_limit' => $column['task_limit'], + 'description' => $column['description'], + ); + + if (! $this->db->table(ColumnModel::TABLE)->save($values)) { + return false; + } + } + + return true; + } + + /** + * Copy board columns from a project to another one + * + * @author Antonio Rabelo + * @param integer $project_from Project Template + * @param integer $project_to Project that receives the copy + * @return boolean + */ + public function duplicate($project_from, $project_to) + { + $columns = $this->db->table(ColumnModel::TABLE) + ->columns('title', 'task_limit', 'description') + ->eq('project_id', $project_from) + ->asc('position') + ->findAll(); + + return $this->boardModel->create($project_to, $columns); + } + + /** + * Get all tasks sorted by columns and swimlanes + * + * @access public + * @param integer $project_id + * @param callable $callback + * @return array + */ + public function getBoard($project_id, $callback = null) + { + $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++) { + $swimlanes[$i]['columns'] = $columns; + $swimlanes[$i]['nb_columns'] = $nb_columns; + $swimlanes[$i]['nb_tasks'] = 0; + $swimlanes[$i]['nb_swimlanes'] = $ilen; + + for ($j = 0; $j < $nb_columns; $j++) { + $column_id = $columns[$j]['id']; + $swimlane_id = $swimlanes[$i]['id']; + + if (! isset($swimlanes[0]['columns'][$j]['nb_column_tasks'])) { + $swimlanes[0]['columns'][$j]['nb_column_tasks'] = 0; + $swimlanes[0]['columns'][$j]['total_score'] = 0; + } + + $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']; + $swimlanes[0]['columns'][$j]['nb_column_tasks'] += $swimlanes[$i]['columns'][$j]['nb_tasks']; + $swimlanes[0]['columns'][$j]['total_score'] += $swimlanes[$i]['columns'][$j]['score']; + } + } + + return $swimlanes; + } + + /** + * Calculate the sum of the defined field for a list of tasks + * + * @access public + * @param array $tasks + * @param string $field + * @return integer + */ + public function getColumnSum(array &$tasks, $field) + { + $sum = 0; + + foreach ($tasks as $task) { + $sum += $task[$field]; + } + + return $sum; + } + + /** + * Get the total of tasks per column + * + * @access public + * @param integer $project_id + * @param boolean $prepend Prepend default value + * @return array + */ + public function getColumnStats($project_id, $prepend = false) + { + $listing = $this->db + ->hashtable(TaskModel::TABLE) + ->eq('project_id', $project_id) + ->eq('is_active', 1) + ->groupBy('column_id') + ->getAll('column_id', 'COUNT(*) AS total'); + + return $prepend ? array(-1 => t('All columns')) + $listing : $listing; + } +} diff --git a/app/Model/Category.php b/app/Model/Category.php deleted file mode 100644 index 00690a41..00000000 --- a/app/Model/Category.php +++ /dev/null @@ -1,218 +0,0 @@ -db->table(self::TABLE)->eq('id', $category_id)->exists(); - } - - /** - * Get a category by the id - * - * @access public - * @param integer $category_id Category id - * @return array - */ - public function getById($category_id) - { - return $this->db->table(self::TABLE)->eq('id', $category_id)->findOne(); - } - - /** - * Get the category name by the id - * - * @access public - * @param integer $category_id Category id - * @return string - */ - public function getNameById($category_id) - { - return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('name') ?: ''; - } - - /** - * Get a category id by the category name and project id - * - * @access public - * @param integer $project_id Project id - * @param string $category_name Category name - * @return integer - */ - public function getIdByName($project_id, $category_name) - { - return (int) $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('name', $category_name) - ->findOneColumn('id'); - } - - /** - * Return the list of all categories - * - * @access public - * @param integer $project_id Project id - * @param bool $prepend_none If true, prepend to the list the value 'None' - * @param bool $prepend_all If true, prepend to the list the value 'All' - * @return array - */ - public function getList($project_id, $prepend_none = true, $prepend_all = false) - { - $listing = $this->db->hashtable(self::TABLE) - ->eq('project_id', $project_id) - ->asc('name') - ->getAll('id', 'name'); - - $prepend = array(); - - if ($prepend_all) { - $prepend[-1] = t('All categories'); - } - - if ($prepend_none) { - $prepend[0] = t('No category'); - } - - return $prepend + $listing; - } - - /** - * Return all categories for a given project - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getAll($project_id) - { - return $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->asc('name') - ->findAll(); - } - - /** - * Create default categories during project creation (transaction already started in Project::create()) - * - * @access public - * @param integer $project_id - * @return boolean - */ - public function createDefaultCategories($project_id) - { - $results = array(); - $categories = explode(',', $this->config->get('project_categories')); - - foreach ($categories as $category) { - $category = trim($category); - - if (! empty($category)) { - $results[] = $this->db->table(self::TABLE)->insert(array( - 'project_id' => $project_id, - 'name' => $category, - )); - } - } - - return in_array(false, $results, true); - } - - /** - * Create a category (run inside a transaction) - * - * @access public - * @param array $values Form values - * @return bool|integer - */ - public function create(array $values) - { - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Update a category - * - * @access public - * @param array $values Form values - * @return bool - */ - public function update(array $values) - { - return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); - } - - /** - * Remove a category - * - * @access public - * @param integer $category_id Category id - * @return bool - */ - public function remove($category_id) - { - $this->db->startTransaction(); - - $this->db->table(Task::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(); - return false; - } - - $this->db->closeTransaction(); - - return true; - } - - /** - * Duplicate categories from a project to another one, must be executed inside a transaction - * - * @author Antonio Rabelo - * @param integer $src_project_id Source project id - * @param integer $dst_project_id Destination project id - * @return boolean - */ - public function duplicate($src_project_id, $dst_project_id) - { - $categories = $this->db - ->table(self::TABLE) - ->columns('name', 'description') - ->eq('project_id', $src_project_id) - ->asc('name') - ->findAll(); - - foreach ($categories as $category) { - $category['project_id'] = $dst_project_id; - - if (! $this->db->table(self::TABLE)->save($category)) { - return false; - } - } - - return true; - } -} diff --git a/app/Model/CategoryModel.php b/app/Model/CategoryModel.php new file mode 100644 index 00000000..62fb5611 --- /dev/null +++ b/app/Model/CategoryModel.php @@ -0,0 +1,218 @@ +db->table(self::TABLE)->eq('id', $category_id)->exists(); + } + + /** + * Get a category by the id + * + * @access public + * @param integer $category_id Category id + * @return array + */ + public function getById($category_id) + { + return $this->db->table(self::TABLE)->eq('id', $category_id)->findOne(); + } + + /** + * Get the category name by the id + * + * @access public + * @param integer $category_id Category id + * @return string + */ + public function getNameById($category_id) + { + return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('name') ?: ''; + } + + /** + * Get a category id by the category name and project id + * + * @access public + * @param integer $project_id Project id + * @param string $category_name Category name + * @return integer + */ + public function getIdByName($project_id, $category_name) + { + return (int) $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('name', $category_name) + ->findOneColumn('id'); + } + + /** + * Return the list of all categories + * + * @access public + * @param integer $project_id Project id + * @param bool $prepend_none If true, prepend to the list the value 'None' + * @param bool $prepend_all If true, prepend to the list the value 'All' + * @return array + */ + public function getList($project_id, $prepend_none = true, $prepend_all = false) + { + $listing = $this->db->hashtable(self::TABLE) + ->eq('project_id', $project_id) + ->asc('name') + ->getAll('id', 'name'); + + $prepend = array(); + + if ($prepend_all) { + $prepend[-1] = t('All categories'); + } + + if ($prepend_none) { + $prepend[0] = t('No category'); + } + + return $prepend + $listing; + } + + /** + * Return all categories for a given project + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getAll($project_id) + { + return $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->asc('name') + ->findAll(); + } + + /** + * Create default categories during project creation (transaction already started in Project::create()) + * + * @access public + * @param integer $project_id + * @return boolean + */ + public function createDefaultCategories($project_id) + { + $results = array(); + $categories = explode(',', $this->configModel->get('project_categories')); + + foreach ($categories as $category) { + $category = trim($category); + + if (! empty($category)) { + $results[] = $this->db->table(self::TABLE)->insert(array( + 'project_id' => $project_id, + 'name' => $category, + )); + } + } + + return in_array(false, $results, true); + } + + /** + * Create a category (run inside a transaction) + * + * @access public + * @param array $values Form values + * @return bool|integer + */ + public function create(array $values) + { + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Update a category + * + * @access public + * @param array $values Form values + * @return bool + */ + public function update(array $values) + { + return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); + } + + /** + * Remove a category + * + * @access public + * @param integer $category_id Category id + * @return bool + */ + public function remove($category_id) + { + $this->db->startTransaction(); + + $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(); + return false; + } + + $this->db->closeTransaction(); + + return true; + } + + /** + * Duplicate categories from a project to another one, must be executed inside a transaction + * + * @author Antonio Rabelo + * @param integer $src_project_id Source project id + * @param integer $dst_project_id Destination project id + * @return boolean + */ + public function duplicate($src_project_id, $dst_project_id) + { + $categories = $this->db + ->table(self::TABLE) + ->columns('name', 'description') + ->eq('project_id', $src_project_id) + ->asc('name') + ->findAll(); + + foreach ($categories as $category) { + $category['project_id'] = $dst_project_id; + + if (! $this->db->table(self::TABLE)->save($category)) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/Color.php b/app/Model/Color.php deleted file mode 100644 index 025ca669..00000000 --- a/app/Model/Color.php +++ /dev/null @@ -1,228 +0,0 @@ - array( - 'name' => 'Yellow', - 'background' => 'rgb(245, 247, 196)', - 'border' => 'rgb(223, 227, 45)', - ), - 'blue' => array( - 'name' => 'Blue', - 'background' => 'rgb(219, 235, 255)', - 'border' => 'rgb(168, 207, 255)', - ), - 'green' => array( - 'name' => 'Green', - 'background' => 'rgb(189, 244, 203)', - 'border' => 'rgb(74, 227, 113)', - ), - 'purple' => array( - 'name' => 'Purple', - 'background' => 'rgb(223, 176, 255)', - 'border' => 'rgb(205, 133, 254)', - ), - 'red' => array( - 'name' => 'Red', - 'background' => 'rgb(255, 187, 187)', - 'border' => 'rgb(255, 151, 151)', - ), - 'orange' => array( - 'name' => 'Orange', - 'background' => 'rgb(255, 215, 179)', - 'border' => 'rgb(255, 172, 98)', - ), - 'grey' => array( - 'name' => 'Grey', - 'background' => 'rgb(238, 238, 238)', - 'border' => 'rgb(204, 204, 204)', - ), - 'brown' => array( - 'name' => 'Brown', - 'background' => '#d7ccc8', - 'border' => '#4e342e', - ), - 'deep_orange' => array( - 'name' => 'Deep Orange', - 'background' => '#ffab91', - 'border' => '#e64a19', - ), - 'dark_grey' => array( - 'name' => 'Dark Grey', - 'background' => '#cfd8dc', - 'border' => '#455a64', - ), - 'pink' => array( - 'name' => 'Pink', - 'background' => '#f48fb1', - 'border' => '#d81b60', - ), - 'teal' => array( - 'name' => 'Teal', - 'background' => '#80cbc4', - 'border' => '#00695c', - ), - 'cyan' => array( - 'name' => 'Cyan', - 'background' => '#b2ebf2', - 'border' => '#00bcd4', - ), - 'lime' => array( - 'name' => 'Lime', - 'background' => '#e6ee9c', - 'border' => '#afb42b', - ), - 'light_green' => array( - 'name' => 'Light Green', - 'background' => '#dcedc8', - 'border' => '#689f38', - ), - 'amber' => array( - 'name' => 'Amber', - 'background' => '#ffe082', - 'border' => '#ffa000', - ), - ); - - /** - * Find a color id from the name or the id - * - * @access public - * @param string $color - * @return string - */ - public function find($color) - { - $color = strtolower($color); - - foreach ($this->default_colors as $color_id => $params) { - if ($color_id === $color) { - return $color_id; - } elseif ($color === strtolower($params['name'])) { - return $color_id; - } - } - - return ''; - } - - /** - * Get color properties - * - * @access public - * @param string $color_id - * @return array - */ - public function getColorProperties($color_id) - { - if (isset($this->default_colors[$color_id])) { - return $this->default_colors[$color_id]; - } - - return $this->default_colors[$this->getDefaultColor()]; - } - - /** - * Get available colors - * - * @access public - * @param bool $prepend - * @return array - */ - public function getList($prepend = false) - { - $listing = $prepend ? array('' => t('All colors')) : array(); - - foreach ($this->default_colors as $color_id => $color) { - $listing[$color_id] = t($color['name']); - } - - return $listing; - } - - /** - * Get the default color - * - * @access public - * @return string - */ - public function getDefaultColor() - { - return $this->config->get('default_color', 'yellow'); - } - - /** - * Get the default colors - * - * @access public - * @return array - */ - public function getDefaultColors() - { - return $this->default_colors; - } - - /** - * Get border color from string - * - * @access public - * @param string $color_id Color id - * @return string - */ - public function getBorderColor($color_id) - { - $color = $this->getColorProperties($color_id); - return $color['border']; - } - - /** - * Get background color from the color_id - * - * @access public - * @param string $color_id Color id - * @return string - */ - public function getBackgroundColor($color_id) - { - $color = $this->getColorProperties($color_id); - return $color['background']; - } - - /** - * Get CSS stylesheet of all colors - * - * @access public - * @return string - */ - public function getCss() - { - $buffer = ''; - - foreach ($this->default_colors as $color => $values) { - $buffer .= 'div.color-'.$color.' {'; - $buffer .= 'background-color: '.$values['background'].';'; - $buffer .= 'border-color: '.$values['border']; - $buffer .= '}'; - $buffer .= 'td.color-'.$color.' { background-color: '.$values['background'].'}'; - } - - return $buffer; - } -} diff --git a/app/Model/ColorModel.php b/app/Model/ColorModel.php new file mode 100644 index 00000000..9e69dda2 --- /dev/null +++ b/app/Model/ColorModel.php @@ -0,0 +1,228 @@ + array( + 'name' => 'Yellow', + 'background' => 'rgb(245, 247, 196)', + 'border' => 'rgb(223, 227, 45)', + ), + 'blue' => array( + 'name' => 'Blue', + 'background' => 'rgb(219, 235, 255)', + 'border' => 'rgb(168, 207, 255)', + ), + 'green' => array( + 'name' => 'Green', + 'background' => 'rgb(189, 244, 203)', + 'border' => 'rgb(74, 227, 113)', + ), + 'purple' => array( + 'name' => 'Purple', + 'background' => 'rgb(223, 176, 255)', + 'border' => 'rgb(205, 133, 254)', + ), + 'red' => array( + 'name' => 'Red', + 'background' => 'rgb(255, 187, 187)', + 'border' => 'rgb(255, 151, 151)', + ), + 'orange' => array( + 'name' => 'Orange', + 'background' => 'rgb(255, 215, 179)', + 'border' => 'rgb(255, 172, 98)', + ), + 'grey' => array( + 'name' => 'Grey', + 'background' => 'rgb(238, 238, 238)', + 'border' => 'rgb(204, 204, 204)', + ), + 'brown' => array( + 'name' => 'Brown', + 'background' => '#d7ccc8', + 'border' => '#4e342e', + ), + 'deep_orange' => array( + 'name' => 'Deep Orange', + 'background' => '#ffab91', + 'border' => '#e64a19', + ), + 'dark_grey' => array( + 'name' => 'Dark Grey', + 'background' => '#cfd8dc', + 'border' => '#455a64', + ), + 'pink' => array( + 'name' => 'Pink', + 'background' => '#f48fb1', + 'border' => '#d81b60', + ), + 'teal' => array( + 'name' => 'Teal', + 'background' => '#80cbc4', + 'border' => '#00695c', + ), + 'cyan' => array( + 'name' => 'Cyan', + 'background' => '#b2ebf2', + 'border' => '#00bcd4', + ), + 'lime' => array( + 'name' => 'Lime', + 'background' => '#e6ee9c', + 'border' => '#afb42b', + ), + 'light_green' => array( + 'name' => 'Light Green', + 'background' => '#dcedc8', + 'border' => '#689f38', + ), + 'amber' => array( + 'name' => 'Amber', + 'background' => '#ffe082', + 'border' => '#ffa000', + ), + ); + + /** + * Find a color id from the name or the id + * + * @access public + * @param string $color + * @return string + */ + public function find($color) + { + $color = strtolower($color); + + foreach ($this->default_colors as $color_id => $params) { + if ($color_id === $color) { + return $color_id; + } elseif ($color === strtolower($params['name'])) { + return $color_id; + } + } + + return ''; + } + + /** + * Get color properties + * + * @access public + * @param string $color_id + * @return array + */ + public function getColorProperties($color_id) + { + if (isset($this->default_colors[$color_id])) { + return $this->default_colors[$color_id]; + } + + return $this->default_colors[$this->getDefaultColor()]; + } + + /** + * Get available colors + * + * @access public + * @param bool $prepend + * @return array + */ + public function getList($prepend = false) + { + $listing = $prepend ? array('' => t('All colors')) : array(); + + foreach ($this->default_colors as $color_id => $color) { + $listing[$color_id] = t($color['name']); + } + + return $listing; + } + + /** + * Get the default color + * + * @access public + * @return string + */ + public function getDefaultColor() + { + return $this->configModel->get('default_color', 'yellow'); + } + + /** + * Get the default colors + * + * @access public + * @return array + */ + public function getDefaultColors() + { + return $this->default_colors; + } + + /** + * Get border color from string + * + * @access public + * @param string $color_id Color id + * @return string + */ + public function getBorderColor($color_id) + { + $color = $this->getColorProperties($color_id); + return $color['border']; + } + + /** + * Get background color from the color_id + * + * @access public + * @param string $color_id Color id + * @return string + */ + public function getBackgroundColor($color_id) + { + $color = $this->getColorProperties($color_id); + return $color['background']; + } + + /** + * Get CSS stylesheet of all colors + * + * @access public + * @return string + */ + public function getCss() + { + $buffer = ''; + + foreach ($this->default_colors as $color => $values) { + $buffer .= 'div.color-'.$color.' {'; + $buffer .= 'background-color: '.$values['background'].';'; + $buffer .= 'border-color: '.$values['border']; + $buffer .= '}'; + $buffer .= 'td.color-'.$color.' { background-color: '.$values['background'].'}'; + } + + return $buffer; + } +} diff --git a/app/Model/Column.php b/app/Model/Column.php deleted file mode 100644 index 329ff2d0..00000000 --- a/app/Model/Column.php +++ /dev/null @@ -1,211 +0,0 @@ -db->table(self::TABLE)->eq('id', $column_id)->findOne(); - } - - /** - * Get the first column id for a given project - * - * @access public - * @param integer $project_id Project id - * @return integer - */ - public function getFirstColumnId($project_id) - { - return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findOneColumn('id'); - } - - /** - * Get the last column id for a given project - * - * @access public - * @param integer $project_id Project id - * @return integer - */ - public function getLastColumnId($project_id) - { - return $this->db->table(self::TABLE)->eq('project_id', $project_id)->desc('position')->findOneColumn('id'); - } - - /** - * Get the position of the last column for a given project - * - * @access public - * @param integer $project_id Project id - * @return integer - */ - public function getLastColumnPosition($project_id) - { - return (int) $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->desc('position') - ->findOneColumn('position'); - } - - /** - * Get a column id by the name - * - * @access public - * @param integer $project_id - * @param string $title - * @return integer - */ - public function getColumnIdByTitle($project_id, $title) - { - return (int) $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('title', $title)->findOneColumn('id'); - } - - /** - * Get a column title by the id - * - * @access public - * @param integer $column_id - * @return integer - */ - public function getColumnTitleById($column_id) - { - return $this->db->table(self::TABLE)->eq('id', $column_id)->findOneColumn('title'); - } - - /** - * Get all columns sorted by position for a given project - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getAll($project_id) - { - return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findAll(); - } - - /** - * Get the list of columns sorted by position [ column_id => title ] - * - * @access public - * @param integer $project_id Project id - * @param boolean $prepend Prepend a default value - * @return array - */ - public function getList($project_id, $prepend = false) - { - $listing = $this->db->hashtable(self::TABLE)->eq('project_id', $project_id)->asc('position')->getAll('id', 'title'); - return $prepend ? array(-1 => t('All columns')) + $listing : $listing; - } - - /** - * Add a new column to the board - * - * @access public - * @param integer $project_id Project id - * @param string $title Column title - * @param integer $task_limit Task limit - * @param string $description Column description - * @return boolean|integer - */ - public function create($project_id, $title, $task_limit = 0, $description = '') - { - $values = array( - 'project_id' => $project_id, - 'title' => $title, - 'task_limit' => intval($task_limit), - 'position' => $this->getLastColumnPosition($project_id) + 1, - 'description' => $description, - ); - - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Update a column - * - * @access public - * @param integer $column_id Column id - * @param string $title Column title - * @param integer $task_limit Task limit - * @param string $description Optional description - * @return boolean - */ - public function update($column_id, $title, $task_limit = 0, $description = '') - { - return $this->db->table(self::TABLE)->eq('id', $column_id)->update(array( - 'title' => $title, - 'task_limit' => intval($task_limit), - 'description' => $description, - )); - } - - /** - * Remove a column and all tasks associated to this column - * - * @access public - * @param integer $column_id Column id - * @return boolean - */ - public function remove($column_id) - { - return $this->db->table(self::TABLE)->eq('id', $column_id)->remove(); - } - - /** - * Change column position - * - * @access public - * @param integer $project_id - * @param integer $column_id - * @param integer $position - * @return boolean - */ - public function changePosition($project_id, $column_id, $position) - { - if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('project_id', $project_id)->count()) { - return false; - } - - $column_ids = $this->db->table(self::TABLE)->eq('project_id', $project_id)->neq('id', $column_id)->asc('position')->findAllByColumn('id'); - $offset = 1; - $results = array(); - - foreach ($column_ids as $current_column_id) { - if ($offset == $position) { - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $current_column_id)->update(array('position' => $offset)); - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $column_id)->update(array('position' => $position)); - - return !in_array(false, $results, true); - } -} diff --git a/app/Model/ColumnModel.php b/app/Model/ColumnModel.php new file mode 100644 index 00000000..1adac0f2 --- /dev/null +++ b/app/Model/ColumnModel.php @@ -0,0 +1,211 @@ +db->table(self::TABLE)->eq('id', $column_id)->findOne(); + } + + /** + * Get the first column id for a given project + * + * @access public + * @param integer $project_id Project id + * @return integer + */ + public function getFirstColumnId($project_id) + { + return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findOneColumn('id'); + } + + /** + * Get the last column id for a given project + * + * @access public + * @param integer $project_id Project id + * @return integer + */ + public function getLastColumnId($project_id) + { + return $this->db->table(self::TABLE)->eq('project_id', $project_id)->desc('position')->findOneColumn('id'); + } + + /** + * Get the position of the last column for a given project + * + * @access public + * @param integer $project_id Project id + * @return integer + */ + public function getLastColumnPosition($project_id) + { + return (int) $this->db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->desc('position') + ->findOneColumn('position'); + } + + /** + * Get a column id by the name + * + * @access public + * @param integer $project_id + * @param string $title + * @return integer + */ + public function getColumnIdByTitle($project_id, $title) + { + return (int) $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('title', $title)->findOneColumn('id'); + } + + /** + * Get a column title by the id + * + * @access public + * @param integer $column_id + * @return integer + */ + public function getColumnTitleById($column_id) + { + return $this->db->table(self::TABLE)->eq('id', $column_id)->findOneColumn('title'); + } + + /** + * Get all columns sorted by position for a given project + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getAll($project_id) + { + return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findAll(); + } + + /** + * Get the list of columns sorted by position [ column_id => title ] + * + * @access public + * @param integer $project_id Project id + * @param boolean $prepend Prepend a default value + * @return array + */ + public function getList($project_id, $prepend = false) + { + $listing = $this->db->hashtable(self::TABLE)->eq('project_id', $project_id)->asc('position')->getAll('id', 'title'); + return $prepend ? array(-1 => t('All columns')) + $listing : $listing; + } + + /** + * Add a new column to the board + * + * @access public + * @param integer $project_id Project id + * @param string $title Column title + * @param integer $task_limit Task limit + * @param string $description Column description + * @return boolean|integer + */ + public function create($project_id, $title, $task_limit = 0, $description = '') + { + $values = array( + 'project_id' => $project_id, + 'title' => $title, + 'task_limit' => intval($task_limit), + 'position' => $this->getLastColumnPosition($project_id) + 1, + 'description' => $description, + ); + + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Update a column + * + * @access public + * @param integer $column_id Column id + * @param string $title Column title + * @param integer $task_limit Task limit + * @param string $description Optional description + * @return boolean + */ + public function update($column_id, $title, $task_limit = 0, $description = '') + { + return $this->db->table(self::TABLE)->eq('id', $column_id)->update(array( + 'title' => $title, + 'task_limit' => intval($task_limit), + 'description' => $description, + )); + } + + /** + * Remove a column and all tasks associated to this column + * + * @access public + * @param integer $column_id Column id + * @return boolean + */ + public function remove($column_id) + { + return $this->db->table(self::TABLE)->eq('id', $column_id)->remove(); + } + + /** + * Change column position + * + * @access public + * @param integer $project_id + * @param integer $column_id + * @param integer $position + * @return boolean + */ + public function changePosition($project_id, $column_id, $position) + { + if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('project_id', $project_id)->count()) { + return false; + } + + $column_ids = $this->db->table(self::TABLE)->eq('project_id', $project_id)->neq('id', $column_id)->asc('position')->findAllByColumn('id'); + $offset = 1; + $results = array(); + + foreach ($column_ids as $current_column_id) { + if ($offset == $position) { + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $current_column_id)->update(array('position' => $offset)); + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $column_id)->update(array('position' => $position)); + + return !in_array(false, $results, true); + } +} diff --git a/app/Model/Comment.php b/app/Model/Comment.php deleted file mode 100644 index 7d3e1d6e..00000000 --- a/app/Model/Comment.php +++ /dev/null @@ -1,158 +0,0 @@ -db - ->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.date_creation', - self::TABLE.'.task_id', - self::TABLE.'.user_id', - self::TABLE.'.comment', - User::TABLE.'.username', - User::TABLE.'.name', - User::TABLE.'.email', - User::TABLE.'.avatar_path' - ) - ->join(User::TABLE, 'id', 'user_id') - ->orderBy(self::TABLE.'.date_creation', $sorting) - ->eq(self::TABLE.'.task_id', $task_id) - ->findAll(); - } - - /** - * Get a comment - * - * @access public - * @param integer $comment_id Comment id - * @return array - */ - public function getById($comment_id) - { - return $this->db - ->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.task_id', - self::TABLE.'.user_id', - self::TABLE.'.date_creation', - self::TABLE.'.comment', - self::TABLE.'.reference', - User::TABLE.'.username', - User::TABLE.'.name', - User::TABLE.'.email', - User::TABLE.'.avatar_path' - ) - ->join(User::TABLE, 'id', 'user_id') - ->eq(self::TABLE.'.id', $comment_id) - ->findOne(); - } - - /** - * Get the number of comments for a given task - * - * @access public - * @param integer $task_id Task id - * @return integer - */ - public function count($task_id) - { - return $this->db - ->table(self::TABLE) - ->eq(self::TABLE.'.task_id', $task_id) - ->count(); - } - - /** - * Create a new comment - * - * @access public - * @param array $values Form values - * @return boolean|integer - */ - public function create(array $values) - { - $values['date_creation'] = time(); - $comment_id = $this->db->table(self::TABLE)->persist($values); - - if ($comment_id) { - $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); - } - - return $comment_id; - } - - /** - * Update a comment in the database - * - * @access public - * @param array $values Form values - * @return boolean - */ - public function update(array $values) - { - $result = $this->db - ->table(self::TABLE) - ->eq('id', $values['id']) - ->update(array('comment' => $values['comment'])); - - if ($result) { - $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new CommentEvent($values)); - } - - return $result; - } - - /** - * Remove a comment - * - * @access public - * @param integer $comment_id Comment id - * @return boolean - */ - public function remove($comment_id) - { - return $this->db->table(self::TABLE)->eq('id', $comment_id)->remove(); - } -} diff --git a/app/Model/CommentModel.php b/app/Model/CommentModel.php new file mode 100644 index 00000000..6e5fd9d8 --- /dev/null +++ b/app/Model/CommentModel.php @@ -0,0 +1,158 @@ +db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.date_creation', + self::TABLE.'.task_id', + self::TABLE.'.user_id', + self::TABLE.'.comment', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.email', + UserModel::TABLE.'.avatar_path' + ) + ->join(UserModel::TABLE, 'id', 'user_id') + ->orderBy(self::TABLE.'.date_creation', $sorting) + ->eq(self::TABLE.'.task_id', $task_id) + ->findAll(); + } + + /** + * Get a comment + * + * @access public + * @param integer $comment_id Comment id + * @return array + */ + public function getById($comment_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.task_id', + self::TABLE.'.user_id', + self::TABLE.'.date_creation', + self::TABLE.'.comment', + self::TABLE.'.reference', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + UserModel::TABLE.'.email', + UserModel::TABLE.'.avatar_path' + ) + ->join(UserModel::TABLE, 'id', 'user_id') + ->eq(self::TABLE.'.id', $comment_id) + ->findOne(); + } + + /** + * Get the number of comments for a given task + * + * @access public + * @param integer $task_id Task id + * @return integer + */ + public function count($task_id) + { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.task_id', $task_id) + ->count(); + } + + /** + * Create a new comment + * + * @access public + * @param array $values Form values + * @return boolean|integer + */ + public function create(array $values) + { + $values['date_creation'] = time(); + $comment_id = $this->db->table(self::TABLE)->persist($values); + + if ($comment_id) { + $event = new CommentEvent(array('id' => $comment_id) + $values); + $this->dispatcher->dispatch(self::EVENT_CREATE, $event); + $this->userMentionModel->fireEvents($values['comment'], self::EVENT_USER_MENTION, $event); + } + + return $comment_id; + } + + /** + * Update a comment in the database + * + * @access public + * @param array $values Form values + * @return boolean + */ + public function update(array $values) + { + $result = $this->db + ->table(self::TABLE) + ->eq('id', $values['id']) + ->update(array('comment' => $values['comment'])); + + if ($result) { + $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new CommentEvent($values)); + } + + return $result; + } + + /** + * Remove a comment + * + * @access public + * @param integer $comment_id Comment id + * @return boolean + */ + public function remove($comment_id) + { + return $this->db->table(self::TABLE)->eq('id', $comment_id)->remove(); + } +} diff --git a/app/Model/Config.php b/app/Model/Config.php deleted file mode 100644 index 1b14efa1..00000000 --- a/app/Model/Config.php +++ /dev/null @@ -1,89 +0,0 @@ -memoryCache->proxy($this, 'getAll'); - return isset($options[$name]) && $options[$name] !== '' ? $options[$name] : $default_value; - } - - /** - * Optimize the Sqlite database - * - * @access public - * @return boolean - */ - public function optimizeDatabase() - { - return $this->db->getConnection()->exec('VACUUM'); - } - - /** - * Compress the Sqlite database - * - * @access public - * @return string - */ - public function downloadDatabase() - { - return gzencode(file_get_contents(DB_FILENAME)); - } - - /** - * Get the Sqlite database size in bytes - * - * @access public - * @return integer - */ - public function getDatabaseSize() - { - return DB_DRIVER === 'sqlite' ? filesize(DB_FILENAME) : 0; - } - - /** - * Regenerate a token - * - * @access public - * @param string $option Parameter name - * @return boolean - */ - public function regenerateToken($option) - { - return $this->save(array($option => Token::getToken())); - } - - /** - * Prepare data before save - * - * @access public - * @param array $values - * @return array - */ - public function prepare(array $values) - { - if (! empty($values['application_url']) && substr($values['application_url'], -1) !== '/') { - $values['application_url'] = $values['application_url'].'/'; - } - - return $values; - } -} diff --git a/app/Model/ConfigModel.php b/app/Model/ConfigModel.php new file mode 100644 index 00000000..945c5e6f --- /dev/null +++ b/app/Model/ConfigModel.php @@ -0,0 +1,89 @@ +memoryCache->proxy($this, 'getAll'); + return isset($options[$name]) && $options[$name] !== '' ? $options[$name] : $default_value; + } + + /** + * Optimize the Sqlite database + * + * @access public + * @return boolean + */ + public function optimizeDatabase() + { + return $this->db->getConnection()->exec('VACUUM'); + } + + /** + * Compress the Sqlite database + * + * @access public + * @return string + */ + public function downloadDatabase() + { + return gzencode(file_get_contents(DB_FILENAME)); + } + + /** + * Get the Sqlite database size in bytes + * + * @access public + * @return integer + */ + public function getDatabaseSize() + { + return DB_DRIVER === 'sqlite' ? filesize(DB_FILENAME) : 0; + } + + /** + * Regenerate a token + * + * @access public + * @param string $option Parameter name + * @return boolean + */ + public function regenerateToken($option) + { + return $this->save(array($option => Token::getToken())); + } + + /** + * Prepare data before save + * + * @access public + * @param array $values + * @return array + */ + public function prepare(array $values) + { + if (! empty($values['application_url']) && substr($values['application_url'], -1) !== '/') { + $values['application_url'] = $values['application_url'].'/'; + } + + return $values; + } +} diff --git a/app/Model/Currency.php b/app/Model/Currency.php deleted file mode 100644 index 7c8cadd4..00000000 --- a/app/Model/Currency.php +++ /dev/null @@ -1,111 +0,0 @@ - t('USD - US Dollar'), - 'EUR' => t('EUR - Euro'), - 'GBP' => t('GBP - British Pound'), - 'CHF' => t('CHF - Swiss Francs'), - 'CAD' => t('CAD - Canadian Dollar'), - 'AUD' => t('AUD - Australian Dollar'), - 'NZD' => t('NZD - New Zealand Dollar'), - 'INR' => t('INR - Indian Rupee'), - 'JPY' => t('JPY - Japanese Yen'), - 'RSD' => t('RSD - Serbian dinar'), - 'SEK' => t('SEK - Swedish Krona'), - 'NOK' => t('NOK - Norwegian Krone'), - 'BAM' => t('BAM - Konvertible Mark'), - 'RUB' => t('RUB - Russian Ruble'), - ); - } - - /** - * Get all currency rates - * - * @access public - * @return array - */ - public function getAll() - { - return $this->db->table(self::TABLE)->findAll(); - } - - /** - * Calculate the price for the reference currency - * - * @access public - * @param string $currency - * @param double $price - * @return double - */ - public function getPrice($currency, $price) - { - static $rates = null; - $reference = $this->config->get('application_currency', 'USD'); - - if ($reference !== $currency) { - $rates = $rates === null ? $this->db->hashtable(self::TABLE)->getAll('currency', 'rate') : $rates; - $rate = isset($rates[$currency]) ? $rates[$currency] : 1; - - return $rate * $price; - } - - return $price; - } - - /** - * Add a new currency rate - * - * @access public - * @param string $currency - * @param float $rate - * @return boolean|integer - */ - public function create($currency, $rate) - { - if ($this->db->table(self::TABLE)->eq('currency', $currency)->exists()) { - return $this->update($currency, $rate); - } - - return $this->db->table(self::TABLE)->insert(array('currency' => $currency, 'rate' => $rate)); - } - - /** - * Update a currency rate - * - * @access public - * @param string $currency - * @param float $rate - * @return boolean - */ - public function update($currency, $rate) - { - return $this->db->table(self::TABLE)->eq('currency', $currency)->update(array('rate' => $rate)); - } -} diff --git a/app/Model/CurrencyModel.php b/app/Model/CurrencyModel.php new file mode 100644 index 00000000..bfd9697c --- /dev/null +++ b/app/Model/CurrencyModel.php @@ -0,0 +1,111 @@ + t('USD - US Dollar'), + 'EUR' => t('EUR - Euro'), + 'GBP' => t('GBP - British Pound'), + 'CHF' => t('CHF - Swiss Francs'), + 'CAD' => t('CAD - Canadian Dollar'), + 'AUD' => t('AUD - Australian Dollar'), + 'NZD' => t('NZD - New Zealand Dollar'), + 'INR' => t('INR - Indian Rupee'), + 'JPY' => t('JPY - Japanese Yen'), + 'RSD' => t('RSD - Serbian dinar'), + 'SEK' => t('SEK - Swedish Krona'), + 'NOK' => t('NOK - Norwegian Krone'), + 'BAM' => t('BAM - Konvertible Mark'), + 'RUB' => t('RUB - Russian Ruble'), + ); + } + + /** + * Get all currency rates + * + * @access public + * @return array + */ + public function getAll() + { + return $this->db->table(self::TABLE)->findAll(); + } + + /** + * Calculate the price for the reference currency + * + * @access public + * @param string $currency + * @param double $price + * @return double + */ + public function getPrice($currency, $price) + { + static $rates = null; + $reference = $this->configModel->get('application_currency', 'USD'); + + if ($reference !== $currency) { + $rates = $rates === null ? $this->db->hashtable(self::TABLE)->getAll('currency', 'rate') : $rates; + $rate = isset($rates[$currency]) ? $rates[$currency] : 1; + + return $rate * $price; + } + + return $price; + } + + /** + * Add a new currency rate + * + * @access public + * @param string $currency + * @param float $rate + * @return boolean|integer + */ + public function create($currency, $rate) + { + if ($this->db->table(self::TABLE)->eq('currency', $currency)->exists()) { + return $this->update($currency, $rate); + } + + return $this->db->table(self::TABLE)->insert(array('currency' => $currency, 'rate' => $rate)); + } + + /** + * Update a currency rate + * + * @access public + * @param string $currency + * @param float $rate + * @return boolean + */ + public function update($currency, $rate) + { + return $this->db->table(self::TABLE)->eq('currency', $currency)->update(array('rate' => $rate)); + } +} diff --git a/app/Model/CustomFilter.php b/app/Model/CustomFilter.php deleted file mode 100644 index 9d409bd4..00000000 --- a/app/Model/CustomFilter.php +++ /dev/null @@ -1,104 +0,0 @@ -db - ->table(self::TABLE) - ->columns( - User::TABLE.'.name as owner_name', - User::TABLE.'.username as owner_username', - self::TABLE.'.id', - self::TABLE.'.user_id', - self::TABLE.'.project_id', - self::TABLE.'.filter', - self::TABLE.'.name', - self::TABLE.'.is_shared', - self::TABLE.'.append' - ) - ->asc(self::TABLE.'.name') - ->join(User::TABLE, 'id', 'user_id') - ->beginOr() - ->eq('is_shared', 1) - ->eq('user_id', $user_id) - ->closeOr() - ->eq('project_id', $project_id) - ->findAll(); - } - - /** - * Get custom filter by id - * - * @access private - * @param integer $filter_id - * @return array - */ - public function getById($filter_id) - { - return $this->db->table(self::TABLE)->eq('id', $filter_id)->findOne(); - } - - /** - * Create a custom filter - * - * @access public - * @param array $values Form values - * @return bool|integer - */ - public function create(array $values) - { - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Update a custom filter - * - * @access public - * @param array $values Form values - * @return bool - */ - public function update(array $values) - { - return $this->db->table(self::TABLE) - ->eq('id', $values['id']) - ->update($values); - } - - /** - * Remove a custom filter - * - * @access public - * @param integer $filter_id - * @return bool - */ - public function remove($filter_id) - { - return $this->db->table(self::TABLE)->eq('id', $filter_id)->remove(); - } -} diff --git a/app/Model/CustomFilterModel.php b/app/Model/CustomFilterModel.php new file mode 100644 index 00000000..a4c23b5c --- /dev/null +++ b/app/Model/CustomFilterModel.php @@ -0,0 +1,104 @@ +db + ->table(self::TABLE) + ->columns( + UserModel::TABLE.'.name as owner_name', + UserModel::TABLE.'.username as owner_username', + self::TABLE.'.id', + self::TABLE.'.user_id', + self::TABLE.'.project_id', + self::TABLE.'.filter', + self::TABLE.'.name', + self::TABLE.'.is_shared', + self::TABLE.'.append' + ) + ->asc(self::TABLE.'.name') + ->join(UserModel::TABLE, 'id', 'user_id') + ->beginOr() + ->eq('is_shared', 1) + ->eq('user_id', $user_id) + ->closeOr() + ->eq('project_id', $project_id) + ->findAll(); + } + + /** + * Get custom filter by id + * + * @access private + * @param integer $filter_id + * @return array + */ + public function getById($filter_id) + { + return $this->db->table(self::TABLE)->eq('id', $filter_id)->findOne(); + } + + /** + * Create a custom filter + * + * @access public + * @param array $values Form values + * @return bool|integer + */ + public function create(array $values) + { + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Update a custom filter + * + * @access public + * @param array $values Form values + * @return bool + */ + public function update(array $values) + { + return $this->db->table(self::TABLE) + ->eq('id', $values['id']) + ->update($values); + } + + /** + * Remove a custom filter + * + * @access public + * @param integer $filter_id + * @return bool + */ + public function remove($filter_id) + { + return $this->db->table(self::TABLE)->eq('id', $filter_id)->remove(); + } +} diff --git a/app/Model/File.php b/app/Model/File.php deleted file mode 100644 index 92032110..00000000 --- a/app/Model/File.php +++ /dev/null @@ -1,341 +0,0 @@ -db - ->table(static::TABLE) - ->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' - ) - ->join(User::TABLE, 'id', 'user_id') - ->asc(static::TABLE.'.name'); - } - - /** - * Get a file by the id - * - * @access public - * @param integer $file_id File id - * @return array - */ - public function getById($file_id) - { - return $this->db->table(static::TABLE)->eq('id', $file_id)->findOne(); - } - - /** - * Get all files - * - * @access public - * @param integer $id - * @return array - */ - public function getAll($id) - { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->findAll(); - } - - /** - * Get all images - * - * @access public - * @param integer $id - * @return array - */ - public function getAllImages($id) - { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 1)->findAll(); - } - - /** - * Get all files without images - * - * @access public - * @param integer $id - * @return array - */ - public function getAllDocuments($id) - { - return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 0)->findAll(); - } - - /** - * Create a file entry in the database - * - * @access public - * @param integer $id Foreign key - * @param string $name Filename - * @param string $path Path on the disk - * @param integer $size File size - * @return bool|integer - */ - public function create($id, $name, $path, $size) - { - $values = array( - static::FOREIGN_KEY => $id, - 'name' => substr($name, 0, 255), - 'path' => $path, - 'is_image' => $this->isImage($name) ? 1 : 0, - 'size' => $size, - 'user_id' => $this->userSession->getId() ?: 0, - 'date' => time(), - ); - - $result = $this->db->table(static::TABLE)->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); - return $file_id; - } - - return false; - } - - /** - * Remove all files - * - * @access public - * @param integer $id - * @return bool - */ - public function removeAll($id) - { - $file_ids = $this->db->table(static::TABLE)->eq(static::FOREIGN_KEY, $id)->asc('id')->findAllByColumn('id'); - $results = array(); - - foreach ($file_ids as $file_id) { - $results[] = $this->remove($file_id); - } - - return ! in_array(false, $results, true); - } - - /** - * Remove a file - * - * @access public - * @param integer $file_id File id - * @return bool - */ - public function remove($file_id) - { - try { - $file = $this->getById($file_id); - $this->objectStorage->remove($file['path']); - - if ($file['is_image'] == 1) { - $this->objectStorage->remove($this->getThumbnailPath($file['path'])); - } - - return $this->db->table(static::TABLE)->eq('id', $file['id'])->remove(); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - /** - * Check if a filename is an image (file types that can be shown as thumbnail) - * - * @access public - * @param string $filename Filename - * @return bool - */ - public function isImage($filename) - { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { - case 'jpeg': - case 'jpg': - case 'png': - case 'gif': - return true; - } - - return false; - } - - /** - * Generate the path for a thumbnails - * - * @access public - * @param string $key Storage key - * @return string - */ - public function getThumbnailPath($key) - { - return 'thumbnails'.DIRECTORY_SEPARATOR.$key; - } - - /** - * Generate the path for a new filename - * - * @access public - * @param integer $id Foreign key - * @param string $filename Filename - * @return string - */ - public function generatePath($id, $filename) - { - return static::PATH_PREFIX.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.hash('sha1', $filename.time()); - } - - /** - * Upload multiple files - * - * @access public - * @param integer $id - * @param array $files - * @return bool - */ - public function uploadFiles($id, array $files) - { - try { - if (empty($files)) { - return false; - } - - foreach (array_keys($files['error']) as $key) { - $file = array( - 'name' => $files['name'][$key], - 'tmp_name' => $files['tmp_name'][$key], - 'size' => $files['size'][$key], - 'error' => $files['error'][$key], - ); - - $this->uploadFile($id, $file); - } - - return true; - } catch (Exception $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - /** - * Upload a file - * - * @access public - * @param integer $id - * @param array $file - */ - public function uploadFile($id, array $file) - { - if ($file['error'] == UPLOAD_ERR_OK && $file['size'] > 0) { - $destination_filename = $this->generatePath($id, $file['name']); - - if ($this->isImage($file['name'])) { - $this->generateThumbnailFromFile($file['tmp_name'], $destination_filename); - } - - $this->objectStorage->moveUploadedFile($file['tmp_name'], $destination_filename); - $this->create($id, $file['name'], $destination_filename, $file['size']); - } else { - throw new Exception('File not uploaded: '.var_export($file['error'], true)); - } - } - - /** - * Handle file upload (base64 encoded content) - * - * @access public - * @param integer $id - * @param string $original_filename - * @param string $blob - * @return bool|integer - */ - public function uploadContent($id, $original_filename, $blob) - { - try { - $data = base64_decode($blob); - - if (empty($data)) { - return false; - } - - $destination_filename = $this->generatePath($id, $original_filename); - $this->objectStorage->put($destination_filename, $data); - - if ($this->isImage($original_filename)) { - $this->generateThumbnailFromData($destination_filename, $data); - } - - return $this->create( - $id, - $original_filename, - $destination_filename, - strlen($data) - ); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - /** - * Generate thumbnail from a blob - * - * @access public - * @param string $destination_filename - * @param string $data - */ - public function generateThumbnailFromData($destination_filename, &$data) - { - $blob = Thumbnail::createFromString($data) - ->resize() - ->toString(); - - $this->objectStorage->put($this->getThumbnailPath($destination_filename), $blob); - } - - /** - * Generate thumbnail from a local file - * - * @access public - * @param string $uploaded_filename - * @param string $destination_filename - */ - public function generateThumbnailFromFile($uploaded_filename, $destination_filename) - { - $blob = Thumbnail::createFromFile($uploaded_filename) - ->resize() - ->toString(); - - $this->objectStorage->put($this->getThumbnailPath($destination_filename), $blob); - } -} diff --git a/app/Model/FileModel.php b/app/Model/FileModel.php new file mode 100644 index 00000000..ad839799 --- /dev/null +++ b/app/Model/FileModel.php @@ -0,0 +1,341 @@ +db + ->table(static::TABLE) + ->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', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name as user_name' + ) + ->join(UserModel::TABLE, 'id', 'user_id') + ->asc(static::TABLE.'.name'); + } + + /** + * Get a file by the id + * + * @access public + * @param integer $file_id File id + * @return array + */ + public function getById($file_id) + { + return $this->db->table(static::TABLE)->eq('id', $file_id)->findOne(); + } + + /** + * Get all files + * + * @access public + * @param integer $id + * @return array + */ + public function getAll($id) + { + return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->findAll(); + } + + /** + * Get all images + * + * @access public + * @param integer $id + * @return array + */ + public function getAllImages($id) + { + return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 1)->findAll(); + } + + /** + * Get all files without images + * + * @access public + * @param integer $id + * @return array + */ + public function getAllDocuments($id) + { + return $this->getQuery()->eq(static::FOREIGN_KEY, $id)->eq('is_image', 0)->findAll(); + } + + /** + * Create a file entry in the database + * + * @access public + * @param integer $id Foreign key + * @param string $name Filename + * @param string $path Path on the disk + * @param integer $size File size + * @return bool|integer + */ + public function create($id, $name, $path, $size) + { + $values = array( + static::FOREIGN_KEY => $id, + 'name' => substr($name, 0, 255), + 'path' => $path, + 'is_image' => $this->isImage($name) ? 1 : 0, + 'size' => $size, + 'user_id' => $this->userSession->getId() ?: 0, + 'date' => time(), + ); + + $result = $this->db->table(static::TABLE)->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); + return $file_id; + } + + return false; + } + + /** + * Remove all files + * + * @access public + * @param integer $id + * @return bool + */ + public function removeAll($id) + { + $file_ids = $this->db->table(static::TABLE)->eq(static::FOREIGN_KEY, $id)->asc('id')->findAllByColumn('id'); + $results = array(); + + foreach ($file_ids as $file_id) { + $results[] = $this->remove($file_id); + } + + return ! in_array(false, $results, true); + } + + /** + * Remove a file + * + * @access public + * @param integer $file_id File id + * @return bool + */ + public function remove($file_id) + { + try { + $file = $this->getById($file_id); + $this->objectStorage->remove($file['path']); + + if ($file['is_image'] == 1) { + $this->objectStorage->remove($this->getThumbnailPath($file['path'])); + } + + return $this->db->table(static::TABLE)->eq('id', $file['id'])->remove(); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + /** + * Check if a filename is an image (file types that can be shown as thumbnail) + * + * @access public + * @param string $filename Filename + * @return bool + */ + public function isImage($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'jpeg': + case 'jpg': + case 'png': + case 'gif': + return true; + } + + return false; + } + + /** + * Generate the path for a thumbnails + * + * @access public + * @param string $key Storage key + * @return string + */ + public function getThumbnailPath($key) + { + return 'thumbnails'.DIRECTORY_SEPARATOR.$key; + } + + /** + * Generate the path for a new filename + * + * @access public + * @param integer $id Foreign key + * @param string $filename Filename + * @return string + */ + public function generatePath($id, $filename) + { + return static::PATH_PREFIX.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.hash('sha1', $filename.time()); + } + + /** + * Upload multiple files + * + * @access public + * @param integer $id + * @param array $files + * @return bool + */ + public function uploadFiles($id, array $files) + { + try { + if (empty($files)) { + return false; + } + + foreach (array_keys($files['error']) as $key) { + $file = array( + 'name' => $files['name'][$key], + 'tmp_name' => $files['tmp_name'][$key], + 'size' => $files['size'][$key], + 'error' => $files['error'][$key], + ); + + $this->uploadFile($id, $file); + } + + return true; + } catch (Exception $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + /** + * Upload a file + * + * @access public + * @param integer $id + * @param array $file + */ + public function uploadFile($id, array $file) + { + if ($file['error'] == UPLOAD_ERR_OK && $file['size'] > 0) { + $destination_filename = $this->generatePath($id, $file['name']); + + if ($this->isImage($file['name'])) { + $this->generateThumbnailFromFile($file['tmp_name'], $destination_filename); + } + + $this->objectStorage->moveUploadedFile($file['tmp_name'], $destination_filename); + $this->create($id, $file['name'], $destination_filename, $file['size']); + } else { + throw new Exception('File not uploaded: '.var_export($file['error'], true)); + } + } + + /** + * Handle file upload (base64 encoded content) + * + * @access public + * @param integer $id + * @param string $original_filename + * @param string $blob + * @return bool|integer + */ + public function uploadContent($id, $original_filename, $blob) + { + try { + $data = base64_decode($blob); + + if (empty($data)) { + return false; + } + + $destination_filename = $this->generatePath($id, $original_filename); + $this->objectStorage->put($destination_filename, $data); + + if ($this->isImage($original_filename)) { + $this->generateThumbnailFromData($destination_filename, $data); + } + + return $this->create( + $id, + $original_filename, + $destination_filename, + strlen($data) + ); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + /** + * Generate thumbnail from a blob + * + * @access public + * @param string $destination_filename + * @param string $data + */ + public function generateThumbnailFromData($destination_filename, &$data) + { + $blob = Thumbnail::createFromString($data) + ->resize() + ->toString(); + + $this->objectStorage->put($this->getThumbnailPath($destination_filename), $blob); + } + + /** + * Generate thumbnail from a local file + * + * @access public + * @param string $uploaded_filename + * @param string $destination_filename + */ + public function generateThumbnailFromFile($uploaded_filename, $destination_filename) + { + $blob = Thumbnail::createFromFile($uploaded_filename) + ->resize() + ->toString(); + + $this->objectStorage->put($this->getThumbnailPath($destination_filename), $blob); + } +} diff --git a/app/Model/Group.php b/app/Model/Group.php deleted file mode 100644 index 25579206..00000000 --- a/app/Model/Group.php +++ /dev/null @@ -1,119 +0,0 @@ -db->table(self::TABLE); - } - - /** - * Get a specific group by id - * - * @access public - * @param integer $group_id - * @return array - */ - public function getById($group_id) - { - return $this->getQuery()->eq('id', $group_id)->findOne(); - } - - /** - * Get a specific group by external id - * - * @access public - * @param integer $external_id - * @return array - */ - public function getByExternalId($external_id) - { - return $this->getQuery()->eq('external_id', $external_id)->findOne(); - } - - /** - * Get all groups - * - * @access public - * @return array - */ - public function getAll() - { - return $this->getQuery()->asc('name')->findAll(); - } - - /** - * Search groups by name - * - * @access public - * @param string $input - * @return array - */ - public function search($input) - { - return $this->db->table(self::TABLE)->ilike('name', '%'.$input.'%')->asc('name')->findAll(); - } - - /** - * Remove a group - * - * @access public - * @param integer $group_id - * @return boolean - */ - public function remove($group_id) - { - return $this->db->table(self::TABLE)->eq('id', $group_id)->remove(); - } - - /** - * Create a new group - * - * @access public - * @param string $name - * @param string $external_id - * @return integer|boolean - */ - public function create($name, $external_id = '') - { - return $this->db->table(self::TABLE)->persist(array( - 'name' => $name, - 'external_id' => $external_id, - )); - } - - /** - * Update existing group - * - * @access public - * @param array $values - * @return boolean - */ - public function update(array $values) - { - return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); - } -} diff --git a/app/Model/GroupMember.php b/app/Model/GroupMember.php deleted file mode 100644 index a0bbb9f8..00000000 --- a/app/Model/GroupMember.php +++ /dev/null @@ -1,130 +0,0 @@ -db->table(self::TABLE) - ->join(User::TABLE, 'id', 'user_id') - ->eq('group_id', $group_id); - } - - /** - * Get all users - * - * @access public - * @param integer $group_id - * @return array - */ - public function getMembers($group_id) - { - return $this->getQuery($group_id)->findAll(); - } - - /** - * Get all not members - * - * @access public - * @param integer $group_id - * @return array - */ - public function getNotMembers($group_id) - { - $subquery = $this->db->table(self::TABLE) - ->columns('user_id') - ->eq('group_id', $group_id); - - return $this->db->table(User::TABLE) - ->notInSubquery('id', $subquery) - ->findAll(); - } - - /** - * Add user to a group - * - * @access public - * @param integer $group_id - * @param integer $user_id - * @return boolean - */ - public function addUser($group_id, $user_id) - { - return $this->db->table(self::TABLE)->insert(array( - 'group_id' => $group_id, - 'user_id' => $user_id, - )); - } - - /** - * Remove user from a group - * - * @access public - * @param integer $group_id - * @param integer $user_id - * @return boolean - */ - public function removeUser($group_id, $user_id) - { - return $this->db->table(self::TABLE) - ->eq('group_id', $group_id) - ->eq('user_id', $user_id) - ->remove(); - } - - /** - * Check if a user is member - * - * @access public - * @param integer $group_id - * @param integer $user_id - * @return boolean - */ - public function isMember($group_id, $user_id) - { - return $this->db->table(self::TABLE) - ->eq('group_id', $group_id) - ->eq('user_id', $user_id) - ->exists(); - } - - /** - * Get all groups for a given user - * - * @access public - * @param integer $user_id - * @return array - */ - 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') - ->eq(self::TABLE.'.user_id', $user_id) - ->asc(Group::TABLE.'.name') - ->findAll(); - } -} diff --git a/app/Model/GroupMemberModel.php b/app/Model/GroupMemberModel.php new file mode 100644 index 00000000..a2077789 --- /dev/null +++ b/app/Model/GroupMemberModel.php @@ -0,0 +1,130 @@ +db->table(self::TABLE) + ->join(UserModel::TABLE, 'id', 'user_id') + ->eq('group_id', $group_id); + } + + /** + * Get all users + * + * @access public + * @param integer $group_id + * @return array + */ + public function getMembers($group_id) + { + return $this->getQuery($group_id)->findAll(); + } + + /** + * Get all not members + * + * @access public + * @param integer $group_id + * @return array + */ + public function getNotMembers($group_id) + { + $subquery = $this->db->table(self::TABLE) + ->columns('user_id') + ->eq('group_id', $group_id); + + return $this->db->table(UserModel::TABLE) + ->notInSubquery('id', $subquery) + ->findAll(); + } + + /** + * Add user to a group + * + * @access public + * @param integer $group_id + * @param integer $user_id + * @return boolean + */ + public function addUser($group_id, $user_id) + { + return $this->db->table(self::TABLE)->insert(array( + 'group_id' => $group_id, + 'user_id' => $user_id, + )); + } + + /** + * Remove user from a group + * + * @access public + * @param integer $group_id + * @param integer $user_id + * @return boolean + */ + public function removeUser($group_id, $user_id) + { + return $this->db->table(self::TABLE) + ->eq('group_id', $group_id) + ->eq('user_id', $user_id) + ->remove(); + } + + /** + * Check if a user is member + * + * @access public + * @param integer $group_id + * @param integer $user_id + * @return boolean + */ + public function isMember($group_id, $user_id) + { + return $this->db->table(self::TABLE) + ->eq('group_id', $group_id) + ->eq('user_id', $user_id) + ->exists(); + } + + /** + * Get all groups for a given user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getGroups($user_id) + { + return $this->db->table(self::TABLE) + ->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(GroupModel::TABLE.'.name') + ->findAll(); + } +} diff --git a/app/Model/GroupModel.php b/app/Model/GroupModel.php new file mode 100644 index 00000000..0a975570 --- /dev/null +++ b/app/Model/GroupModel.php @@ -0,0 +1,119 @@ +db->table(self::TABLE); + } + + /** + * Get a specific group by id + * + * @access public + * @param integer $group_id + * @return array + */ + public function getById($group_id) + { + return $this->getQuery()->eq('id', $group_id)->findOne(); + } + + /** + * Get a specific group by external id + * + * @access public + * @param integer $external_id + * @return array + */ + public function getByExternalId($external_id) + { + return $this->getQuery()->eq('external_id', $external_id)->findOne(); + } + + /** + * Get all groups + * + * @access public + * @return array + */ + public function getAll() + { + return $this->getQuery()->asc('name')->findAll(); + } + + /** + * Search groups by name + * + * @access public + * @param string $input + * @return array + */ + public function search($input) + { + return $this->db->table(self::TABLE)->ilike('name', '%'.$input.'%')->asc('name')->findAll(); + } + + /** + * Remove a group + * + * @access public + * @param integer $group_id + * @return boolean + */ + public function remove($group_id) + { + return $this->db->table(self::TABLE)->eq('id', $group_id)->remove(); + } + + /** + * Create a new group + * + * @access public + * @param string $name + * @param string $external_id + * @return integer|boolean + */ + public function create($name, $external_id = '') + { + return $this->db->table(self::TABLE)->persist(array( + 'name' => $name, + 'external_id' => $external_id, + )); + } + + /** + * Update existing group + * + * @access public + * @param array $values + * @return boolean + */ + public function update(array $values) + { + return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); + } +} diff --git a/app/Model/Language.php b/app/Model/Language.php deleted file mode 100644 index 126dc5c0..00000000 --- a/app/Model/Language.php +++ /dev/null @@ -1,179 +0,0 @@ - 'Bahasa Indonesia', - 'bs_BA' => 'Bosanski', - 'cs_CZ' => 'Čeština', - 'da_DK' => 'Dansk', - 'de_DE' => 'Deutsch', - 'en_US' => 'English', - 'es_ES' => 'Español', - 'fr_FR' => 'Français', - 'el_GR' => 'Grec', - 'it_IT' => 'Italiano', - 'hu_HU' => 'Magyar', - 'my_MY' => 'Melayu', - 'nl_NL' => 'Nederlands', - 'nb_NO' => 'Norsk', - 'pl_PL' => 'Polski', - 'pt_PT' => 'Português', - 'pt_BR' => 'Português (Brasil)', - 'ru_RU' => 'Русский', - 'sr_Latn_RS' => 'Srpski', - 'fi_FI' => 'Suomi', - 'sv_SE' => 'Svenska', - 'tr_TR' => 'Türkçe', - 'ko_KR' => '한국어', - 'zh_CN' => '中文(简体)', - 'ja_JP' => '日本語', - 'th_TH' => 'ไทย', - ); - - if ($prepend) { - return array('' => t('Application default')) + $languages; - } - - return $languages; - } - - /** - * Get javascript language code - * - * @access public - * @return string - */ - public function getJsLanguageCode() - { - $languages = array( - 'cs_CZ' => 'cs', - 'da_DK' => 'da', - 'de_DE' => 'de', - 'en_US' => 'en', - 'es_ES' => 'es', - 'fr_FR' => 'fr', - 'it_IT' => 'it', - 'hu_HU' => 'hu', - 'nl_NL' => 'nl', - 'nb_NO' => 'nb', - 'pl_PL' => 'pl', - 'pt_PT' => 'pt', - 'pt_BR' => 'pt-br', - 'ru_RU' => 'ru', - 'sr_Latn_RS' => 'sr', - 'fi_FI' => 'fi', - 'sv_SE' => 'sv', - 'tr_TR' => 'tr', - 'ko_KR' => 'ko', - 'zh_CN' => 'zh-cn', - 'ja_JP' => 'ja', - 'th_TH' => 'th', - 'id_ID' => 'id', - 'el_GR' => 'el', - ); - - $lang = $this->getCurrentLanguage(); - - return isset($languages[$lang]) ? $languages[$lang] : 'en'; - } - - /** - * Get current language - * - * @access public - * @return string - */ - public function getCurrentLanguage() - { - if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) { - return $this->sessionStorage->user['language']; - } - - return $this->config->get('application_language', 'en_US'); - } - - /** - * Load translations for the current language - * - * @access public - */ - public function loadCurrentLanguage() - { - Translator::load($this->getCurrentLanguage()); - } -} diff --git a/app/Model/LanguageModel.php b/app/Model/LanguageModel.php new file mode 100644 index 00000000..eb6de004 --- /dev/null +++ b/app/Model/LanguageModel.php @@ -0,0 +1,179 @@ + 'Bahasa Indonesia', + 'bs_BA' => 'Bosanski', + 'cs_CZ' => 'Čeština', + 'da_DK' => 'Dansk', + 'de_DE' => 'Deutsch', + 'en_US' => 'English', + 'es_ES' => 'Español', + 'fr_FR' => 'Français', + 'el_GR' => 'Grec', + 'it_IT' => 'Italiano', + 'hu_HU' => 'Magyar', + 'my_MY' => 'Melayu', + 'nl_NL' => 'Nederlands', + 'nb_NO' => 'Norsk', + 'pl_PL' => 'Polski', + 'pt_PT' => 'Português', + 'pt_BR' => 'Português (Brasil)', + 'ru_RU' => 'Русский', + 'sr_Latn_RS' => 'Srpski', + 'fi_FI' => 'Suomi', + 'sv_SE' => 'Svenska', + 'tr_TR' => 'Türkçe', + 'ko_KR' => '한국어', + 'zh_CN' => '中文(简体)', + 'ja_JP' => '日本語', + 'th_TH' => 'ไทย', + ); + + if ($prepend) { + return array('' => t('Application default')) + $languages; + } + + return $languages; + } + + /** + * Get javascript language code + * + * @access public + * @return string + */ + public function getJsLanguageCode() + { + $languages = array( + 'cs_CZ' => 'cs', + 'da_DK' => 'da', + 'de_DE' => 'de', + 'en_US' => 'en', + 'es_ES' => 'es', + 'fr_FR' => 'fr', + 'it_IT' => 'it', + 'hu_HU' => 'hu', + 'nl_NL' => 'nl', + 'nb_NO' => 'nb', + 'pl_PL' => 'pl', + 'pt_PT' => 'pt', + 'pt_BR' => 'pt-br', + 'ru_RU' => 'ru', + 'sr_Latn_RS' => 'sr', + 'fi_FI' => 'fi', + 'sv_SE' => 'sv', + 'tr_TR' => 'tr', + 'ko_KR' => 'ko', + 'zh_CN' => 'zh-cn', + 'ja_JP' => 'ja', + 'th_TH' => 'th', + 'id_ID' => 'id', + 'el_GR' => 'el', + ); + + $lang = $this->getCurrentLanguage(); + + return isset($languages[$lang]) ? $languages[$lang] : 'en'; + } + + /** + * Get current language + * + * @access public + * @return string + */ + public function getCurrentLanguage() + { + if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) { + return $this->sessionStorage->user['language']; + } + + return $this->configModel->get('application_language', 'en_US'); + } + + /** + * Load translations for the current language + * + * @access public + */ + public function loadCurrentLanguage() + { + Translator::load($this->getCurrentLanguage()); + } +} diff --git a/app/Model/LastLogin.php b/app/Model/LastLogin.php deleted file mode 100644 index 35c7afc9..00000000 --- a/app/Model/LastLogin.php +++ /dev/null @@ -1,92 +0,0 @@ -cleanup($user_id); - - return $this->db - ->table(self::TABLE) - ->insert(array( - 'auth_type' => $auth_type, - 'user_id' => $user_id, - 'ip' => $ip, - 'user_agent' => substr($user_agent, 0, 255), - 'date_creation' => time(), - )); - } - - /** - * Cleanup login history - * - * @access public - * @param integer $user_id - */ - public function cleanup($user_id) - { - $connections = $this->db - ->table(self::TABLE) - ->eq('user_id', $user_id) - ->desc('id') - ->findAllByColumn('id'); - - if (count($connections) >= self::NB_LOGINS) { - $this->db->table(self::TABLE) - ->eq('user_id', $user_id) - ->notin('id', array_slice($connections, 0, self::NB_LOGINS - 1)) - ->remove(); - } - } - - /** - * Get the last connections for a given user - * - * @access public - * @param integer $user_id User id - * @return array - */ - public function getAll($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('user_id', $user_id) - ->desc('id') - ->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation') - ->findAll(); - } -} diff --git a/app/Model/LastLoginModel.php b/app/Model/LastLoginModel.php new file mode 100644 index 00000000..16821392 --- /dev/null +++ b/app/Model/LastLoginModel.php @@ -0,0 +1,92 @@ +cleanup($user_id); + + return $this->db + ->table(self::TABLE) + ->insert(array( + 'auth_type' => $auth_type, + 'user_id' => $user_id, + 'ip' => $ip, + 'user_agent' => substr($user_agent, 0, 255), + 'date_creation' => time(), + )); + } + + /** + * Cleanup login history + * + * @access public + * @param integer $user_id + */ + public function cleanup($user_id) + { + $connections = $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->desc('id') + ->findAllByColumn('id'); + + if (count($connections) >= self::NB_LOGINS) { + $this->db->table(self::TABLE) + ->eq('user_id', $user_id) + ->notin('id', array_slice($connections, 0, self::NB_LOGINS - 1)) + ->remove(); + } + } + + /** + * Get the last connections for a given user + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getAll($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->desc('id') + ->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation') + ->findAll(); + } +} diff --git a/app/Model/Link.php b/app/Model/Link.php deleted file mode 100644 index f275edae..00000000 --- a/app/Model/Link.php +++ /dev/null @@ -1,178 +0,0 @@ -db->table(self::TABLE)->eq('id', $link_id)->findOne(); - } - - /** - * Get a link by name - * - * @access public - * @param string $label - * @return array - */ - public function getByLabel($label) - { - return $this->db->table(self::TABLE)->eq('label', $label)->findOne(); - } - - /** - * Get the opposite link id - * - * @access public - * @param integer $link_id Link id - * @return integer - */ - public function getOppositeLinkId($link_id) - { - return $this->db->table(self::TABLE)->eq('id', $link_id)->findOneColumn('opposite_id') ?: $link_id; - } - - /** - * Get all links - * - * @access public - * @return array - */ - public function getAll() - { - return $this->db->table(self::TABLE)->findAll(); - } - - /** - * Get merged links - * - * @access public - * @return array - */ - public function getMergedList() - { - return $this->db - ->execute(' - SELECT - links.id, links.label, opposite.label as opposite_label - FROM links - LEFT JOIN links AS opposite ON opposite.id=links.opposite_id - ') - ->fetchAll(PDO::FETCH_ASSOC); - } - - /** - * Get label list - * - * @access public - * @param integer $exclude_id Exclude this link - * @param boolean $prepend Prepend default value - * @return array - */ - public function getList($exclude_id = 0, $prepend = true) - { - $labels = $this->db->hashtable(self::TABLE)->neq('id', $exclude_id)->asc('id')->getAll('id', 'label'); - - foreach ($labels as &$value) { - $value = t($value); - } - - return $prepend ? array('') + $labels : $labels; - } - - /** - * Create a new link label - * - * @access public - * @param string $label - * @param string $opposite_label - * @return boolean|integer - */ - public function create($label, $opposite_label = '') - { - $this->db->startTransaction(); - - if (! $this->db->table(self::TABLE)->insert(array('label' => $label))) { - $this->db->cancelTransaction(); - return false; - } - - $label_id = $this->db->getLastId(); - - if (! empty($opposite_label)) { - $this->db - ->table(self::TABLE) - ->insert(array( - 'label' => $opposite_label, - 'opposite_id' => $label_id, - )); - - $this->db - ->table(self::TABLE) - ->eq('id', $label_id) - ->update(array( - 'opposite_id' => $this->db->getLastId() - )); - } - - $this->db->closeTransaction(); - - return (int) $label_id; - } - - /** - * Update a link - * - * @access public - * @param array $values - * @return boolean - */ - public function update(array $values) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $values['id']) - ->update(array( - 'label' => $values['label'], - 'opposite_id' => $values['opposite_id'], - )); - } - - /** - * Remove a link a the relation to its opposite - * - * @access public - * @param integer $link_id - * @return boolean - */ - public function remove($link_id) - { - $this->db->table(self::TABLE)->eq('opposite_id', $link_id)->update(array('opposite_id' => 0)); - return $this->db->table(self::TABLE)->eq('id', $link_id)->remove(); - } -} diff --git a/app/Model/LinkModel.php b/app/Model/LinkModel.php new file mode 100644 index 00000000..b72c7532 --- /dev/null +++ b/app/Model/LinkModel.php @@ -0,0 +1,178 @@ +db->table(self::TABLE)->eq('id', $link_id)->findOne(); + } + + /** + * Get a link by name + * + * @access public + * @param string $label + * @return array + */ + public function getByLabel($label) + { + return $this->db->table(self::TABLE)->eq('label', $label)->findOne(); + } + + /** + * Get the opposite link id + * + * @access public + * @param integer $link_id Link id + * @return integer + */ + public function getOppositeLinkId($link_id) + { + return $this->db->table(self::TABLE)->eq('id', $link_id)->findOneColumn('opposite_id') ?: $link_id; + } + + /** + * Get all links + * + * @access public + * @return array + */ + public function getAll() + { + return $this->db->table(self::TABLE)->findAll(); + } + + /** + * Get merged links + * + * @access public + * @return array + */ + public function getMergedList() + { + return $this->db + ->execute(' + SELECT + links.id, links.label, opposite.label as opposite_label + FROM links + LEFT JOIN links AS opposite ON opposite.id=links.opposite_id + ') + ->fetchAll(PDO::FETCH_ASSOC); + } + + /** + * Get label list + * + * @access public + * @param integer $exclude_id Exclude this link + * @param boolean $prepend Prepend default value + * @return array + */ + public function getList($exclude_id = 0, $prepend = true) + { + $labels = $this->db->hashtable(self::TABLE)->neq('id', $exclude_id)->asc('id')->getAll('id', 'label'); + + foreach ($labels as &$value) { + $value = t($value); + } + + return $prepend ? array('') + $labels : $labels; + } + + /** + * Create a new link label + * + * @access public + * @param string $label + * @param string $opposite_label + * @return boolean|integer + */ + public function create($label, $opposite_label = '') + { + $this->db->startTransaction(); + + if (! $this->db->table(self::TABLE)->insert(array('label' => $label))) { + $this->db->cancelTransaction(); + return false; + } + + $label_id = $this->db->getLastId(); + + if (! empty($opposite_label)) { + $this->db + ->table(self::TABLE) + ->insert(array( + 'label' => $opposite_label, + 'opposite_id' => $label_id, + )); + + $this->db + ->table(self::TABLE) + ->eq('id', $label_id) + ->update(array( + 'opposite_id' => $this->db->getLastId() + )); + } + + $this->db->closeTransaction(); + + return (int) $label_id; + } + + /** + * Update a link + * + * @access public + * @param array $values + * @return boolean + */ + public function update(array $values) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $values['id']) + ->update(array( + 'label' => $values['label'], + 'opposite_id' => $values['opposite_id'], + )); + } + + /** + * Remove a link a the relation to its opposite + * + * @access public + * @param integer $link_id + * @return boolean + */ + public function remove($link_id) + { + $this->db->table(self::TABLE)->eq('opposite_id', $link_id)->update(array('opposite_id' => 0)); + return $this->db->table(self::TABLE)->eq('id', $link_id)->remove(); + } +} diff --git a/app/Model/Metadata.php b/app/Model/Metadata.php deleted file mode 100644 index b39ce098..00000000 --- a/app/Model/Metadata.php +++ /dev/null @@ -1,139 +0,0 @@ -db - ->hashtable($this->getTable()) - ->eq($this->getEntityKey(), $entity_id) - ->asc('name') - ->getAll('name', 'value'); - } - - /** - * Get a metadata for the given entity - * - * @access public - * @param integer $entity_id - * @param string $name - * @param string $default - * @return mixed - */ - public function get($entity_id, $name, $default = '') - { - return $this->db - ->table($this->getTable()) - ->eq($this->getEntityKey(), $entity_id) - ->eq('name', $name) - ->findOneColumn('value') ?: $default; - } - - /** - * Return true if a metadata exists - * - * @access public - * @param integer $entity_id - * @param string $name - * @return boolean - */ - public function exists($entity_id, $name) - { - return $this->db - ->table($this->getTable()) - ->eq($this->getEntityKey(), $entity_id) - ->eq('name', $name) - ->exists(); - } - - /** - * Update or insert new metadata - * - * @access public - * @param integer $entity_id - * @param array $values - * @return boolean - */ - public function save($entity_id, array $values) - { - $results = array(); - $user_id = $this->userSession->getId(); - $timestamp = time(); - - $this->db->startTransaction(); - - foreach ($values as $key => $value) { - if ($this->exists($entity_id, $key)) { - $results[] = $this->db->table($this->getTable()) - ->eq($this->getEntityKey(), $entity_id) - ->eq('name', $key)->update(array( - 'value' => $value, - 'changed_on' => $timestamp, - 'changed_by' => $user_id, - )); - } else { - $results[] = $this->db->table($this->getTable())->insert(array( - 'name' => $key, - 'value' => $value, - $this->getEntityKey() => $entity_id, - 'changed_on' => $timestamp, - 'changed_by' => $user_id, - )); - } - } - - $this->db->closeTransaction(); - return ! in_array(false, $results, true); - } - - /** - * Remove a metadata - * - * @access public - * @param integer $entity_id - * @param string $name - * @return bool - */ - public function remove($entity_id, $name) - { - return $this->db->table($this->getTable()) - ->eq($this->getEntityKey(), $entity_id) - ->eq('name', $name) - ->remove(); - } -} diff --git a/app/Model/MetadataModel.php b/app/Model/MetadataModel.php new file mode 100644 index 00000000..6177e5f3 --- /dev/null +++ b/app/Model/MetadataModel.php @@ -0,0 +1,139 @@ +db + ->hashtable($this->getTable()) + ->eq($this->getEntityKey(), $entity_id) + ->asc('name') + ->getAll('name', 'value'); + } + + /** + * Get a metadata for the given entity + * + * @access public + * @param integer $entity_id + * @param string $name + * @param string $default + * @return mixed + */ + public function get($entity_id, $name, $default = '') + { + return $this->db + ->table($this->getTable()) + ->eq($this->getEntityKey(), $entity_id) + ->eq('name', $name) + ->findOneColumn('value') ?: $default; + } + + /** + * Return true if a metadata exists + * + * @access public + * @param integer $entity_id + * @param string $name + * @return boolean + */ + public function exists($entity_id, $name) + { + return $this->db + ->table($this->getTable()) + ->eq($this->getEntityKey(), $entity_id) + ->eq('name', $name) + ->exists(); + } + + /** + * Update or insert new metadata + * + * @access public + * @param integer $entity_id + * @param array $values + * @return boolean + */ + public function save($entity_id, array $values) + { + $results = array(); + $user_id = $this->userSession->getId(); + $timestamp = time(); + + $this->db->startTransaction(); + + foreach ($values as $key => $value) { + if ($this->exists($entity_id, $key)) { + $results[] = $this->db->table($this->getTable()) + ->eq($this->getEntityKey(), $entity_id) + ->eq('name', $key)->update(array( + 'value' => $value, + 'changed_on' => $timestamp, + 'changed_by' => $user_id, + )); + } else { + $results[] = $this->db->table($this->getTable())->insert(array( + 'name' => $key, + 'value' => $value, + $this->getEntityKey() => $entity_id, + 'changed_on' => $timestamp, + 'changed_by' => $user_id, + )); + } + } + + $this->db->closeTransaction(); + return ! in_array(false, $results, true); + } + + /** + * Remove a metadata + * + * @access public + * @param integer $entity_id + * @param string $name + * @return bool + */ + public function remove($entity_id, $name) + { + return $this->db->table($this->getTable()) + ->eq($this->getEntityKey(), $entity_id) + ->eq('name', $name) + ->remove(); + } +} diff --git a/app/Model/Notification.php b/app/Model/Notification.php deleted file mode 100644 index 1e96a8b4..00000000 --- a/app/Model/Notification.php +++ /dev/null @@ -1,136 +0,0 @@ - 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']); - case Task::EVENT_USER_MENTION: - return e('You were mentioned in the task #%d', $event_data['task']['id']); - case Comment::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/NotificationModel.php b/app/Model/NotificationModel.php new file mode 100644 index 00000000..8937b77e --- /dev/null +++ b/app/Model/NotificationModel.php @@ -0,0 +1,136 @@ + 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']); + case TaskModel::EVENT_USER_MENTION: + return e('You were mentioned in the task #%d', $event_data['task']['id']); + 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/NotificationType.php deleted file mode 100644 index a4dffa09..00000000 --- a/app/Model/NotificationType.php +++ /dev/null @@ -1,128 +0,0 @@ -classes = new Container; - } - - /** - * Add a new notification type - * - * @access public - * @param string $type - * @param string $label - * @param string $class - * @param boolean $hidden - * @return NotificationType - */ - public function setType($type, $label, $class, $hidden = false) - { - $container = $this->container; - - if ($hidden) { - $this->hiddens[] = $type; - } else { - $this->labels[$type] = $label; - } - - $this->classes[$type] = function () use ($class, $container) { - return new $class($container); - }; - - return $this; - } - - /** - * Get mail notification type instance - * - * @access public - * @param string $type - * @return \Kanboard\Notification\NotificationInterface - */ - public function getType($type) - { - return $this->classes[$type]; - } - - /** - * Get all notification types with labels - * - * @access public - * @return array - */ - public function getTypes() - { - return $this->labels; - } - - /** - * Get all hidden notification types - * - * @access public - * @return array - */ - public function getHiddenTypes() - { - return $this->hiddens; - } - - /** - * Keep only loaded notification types - * - * @access public - * @param string[] $types - * @return array - */ - public function filterTypes(array $types) - { - $classes = $this->classes; - - return array_filter($types, function ($type) use ($classes) { - return isset($classes[$type]); - }); - } -} diff --git a/app/Model/NotificationTypeModel.php b/app/Model/NotificationTypeModel.php new file mode 100644 index 00000000..432832ee --- /dev/null +++ b/app/Model/NotificationTypeModel.php @@ -0,0 +1,128 @@ +classes = new Container; + } + + /** + * Add a new notification type + * + * @access public + * @param string $type + * @param string $label + * @param string $class + * @param boolean $hidden + * @return NotificationTypeModel + */ + public function setType($type, $label, $class, $hidden = false) + { + $container = $this->container; + + if ($hidden) { + $this->hiddens[] = $type; + } else { + $this->labels[$type] = $label; + } + + $this->classes[$type] = function () use ($class, $container) { + return new $class($container); + }; + + return $this; + } + + /** + * Get mail notification type instance + * + * @access public + * @param string $type + * @return \Kanboard\Core\Notification\NotificationInterface + */ + public function getType($type) + { + return $this->classes[$type]; + } + + /** + * Get all notification types with labels + * + * @access public + * @return array + */ + public function getTypes() + { + return $this->labels; + } + + /** + * Get all hidden notification types + * + * @access public + * @return array + */ + public function getHiddenTypes() + { + return $this->hiddens; + } + + /** + * Keep only loaded notification types + * + * @access public + * @param string[] $types + * @return array + */ + public function filterTypes(array $types) + { + $classes = $this->classes; + + return array_filter($types, function ($type) use ($classes) { + return isset($classes[$type]); + }); + } +} diff --git a/app/Model/PasswordReset.php b/app/Model/PasswordReset.php deleted file mode 100644 index 895acb07..00000000 --- a/app/Model/PasswordReset.php +++ /dev/null @@ -1,95 +0,0 @@ -db->table(self::TABLE)->eq('user_id', $user_id)->desc('date_creation')->limit(100)->findAll(); - } - - /** - * Generate a new reset token for a user - * - * @access public - * @param string $username - * @param integer $expiration - * @return boolean|string - */ - public function create($username, $expiration = 0) - { - $user_id = $this->db->table(User::TABLE)->eq('username', $username)->neq('email', '')->notNull('email')->findOneColumn('id'); - - if (! $user_id) { - return false; - } - - $token = $this->token->getToken(); - - $result = $this->db->table(self::TABLE)->insert(array( - 'token' => $token, - 'user_id' => $user_id, - 'date_expiration' => $expiration ?: time() + self::DURATION, - 'date_creation' => time(), - 'ip' => $this->request->getIpAddress(), - 'user_agent' => $this->request->getUserAgent(), - 'is_active' => 1, - )); - - return $result ? $token : false; - } - - /** - * Get user id from the token - * - * @access public - * @param string $token - * @return integer - */ - public function getUserIdByToken($token) - { - return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_active', 1)->gte('date_expiration', time())->findOneColumn('user_id'); - } - - /** - * Disable all tokens for a user - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function disable($user_id) - { - return $this->db->table(self::TABLE)->eq('user_id', $user_id)->update(array('is_active' => 0)); - } -} diff --git a/app/Model/PasswordResetModel.php b/app/Model/PasswordResetModel.php new file mode 100644 index 00000000..d7c74969 --- /dev/null +++ b/app/Model/PasswordResetModel.php @@ -0,0 +1,95 @@ +db->table(self::TABLE)->eq('user_id', $user_id)->desc('date_creation')->limit(100)->findAll(); + } + + /** + * Generate a new reset token for a user + * + * @access public + * @param string $username + * @param integer $expiration + * @return boolean|string + */ + public function create($username, $expiration = 0) + { + $user_id = $this->db->table(UserModel::TABLE)->eq('username', $username)->neq('email', '')->notNull('email')->findOneColumn('id'); + + if (! $user_id) { + return false; + } + + $token = $this->token->getToken(); + + $result = $this->db->table(self::TABLE)->insert(array( + 'token' => $token, + 'user_id' => $user_id, + 'date_expiration' => $expiration ?: time() + self::DURATION, + 'date_creation' => time(), + 'ip' => $this->request->getIpAddress(), + 'user_agent' => $this->request->getUserAgent(), + 'is_active' => 1, + )); + + return $result ? $token : false; + } + + /** + * Get user id from the token + * + * @access public + * @param string $token + * @return integer + */ + public function getUserIdByToken($token) + { + return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_active', 1)->gte('date_expiration', time())->findOneColumn('user_id'); + } + + /** + * Disable all tokens for a user + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function disable($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->update(array('is_active' => 0)); + } +} diff --git a/app/Model/Project.php b/app/Model/Project.php deleted file mode 100644 index 2cb0a431..00000000 --- a/app/Model/Project.php +++ /dev/null @@ -1,526 +0,0 @@ -db->table(self::TABLE)->eq('id', $project_id)->findOne(); - } - - /** - * Get a project by id with owner name - * - * @access public - * @param integer $project_id Project id - * @return array - */ - 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') - ->eq(self::TABLE.'.id', $project_id) - ->join(User::TABLE, 'id', 'owner_id') - ->findOne(); - } - - /** - * Get a project by the name - * - * @access public - * @param string $name Project name - * @return array - */ - public function getByName($name) - { - return $this->db->table(self::TABLE)->eq('name', $name)->findOne(); - } - - /** - * Get a project by the identifier (code) - * - * @access public - * @param string $identifier - * @return array|boolean - */ - public function getByIdentifier($identifier) - { - if (empty($identifier)) { - return false; - } - - return $this->db->table(self::TABLE)->eq('identifier', strtoupper($identifier))->findOne(); - } - - /** - * Fetch project data by using the token - * - * @access public - * @param string $token Token - * @return array|boolean - */ - public function getByToken($token) - { - if (empty($token)) { - return false; - } - - return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_public', 1)->findOne(); - } - - /** - * Return the first project from the database (no sorting) - * - * @access public - * @return array - */ - public function getFirst() - { - return $this->db->table(self::TABLE)->findOne(); - } - - /** - * Return true if the project is private - * - * @access public - * @param integer $project_id Project id - * @return boolean - */ - public function isPrivate($project_id) - { - return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists(); - } - - /** - * Get all projects - * - * @access public - * @return array - */ - public function getAll() - { - return $this->db->table(self::TABLE)->asc('name')->findAll(); - } - - /** - * Get all projects with given Ids - * - * @access public - * @param integer[] $project_ids - * @return array - */ - public function getAllByIds(array $project_ids) - { - if (empty($project_ids)) { - return array(); - } - - return $this->db->table(self::TABLE)->in('id', $project_ids)->asc('name')->findAll(); - } - - /** - * Get all project ids - * - * @access public - * @return array - */ - public function getAllIds() - { - return $this->db->table(self::TABLE)->asc('name')->findAllByColumn('id'); - } - - /** - * Return the list of all projects - * - * @access public - * @param bool $prepend If true, prepend to the list the value 'None' - * @return array - */ - public function getList($prepend = true) - { - if ($prepend) { - return array(t('None')) + $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); - } - - return $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); - } - - /** - * Get all projects with all its data for a given status - * - * @access public - * @param integer $status Project status: self::ACTIVE or self:INACTIVE - * @return array - */ - public function getAllByStatus($status) - { - return $this->db - ->table(self::TABLE) - ->asc('name') - ->eq('is_active', $status) - ->findAll(); - } - - /** - * Get a list of project by status - * - * @access public - * @param integer $status Project status: self::ACTIVE or self:INACTIVE - * @return array - */ - public function getListByStatus($status) - { - return $this->db - ->hashtable(self::TABLE) - ->asc('name') - ->eq('is_active', $status) - ->getAll('id', 'name'); - } - - /** - * Return the number of projects by status - * - * @access public - * @param integer $status Status: self::ACTIVE or self:INACTIVE - * @return integer - */ - public function countByStatus($status) - { - return $this->db - ->table(self::TABLE) - ->eq('is_active', $status) - ->count(); - } - - /** - * Get Priority range from a project - * - * @access public - * @param array $project - * @return array - */ - public function getPriorities(array $project) - { - $range = range($project['priority_start'], $project['priority_end']); - return array_combine($range, $range); - } - - /** - * Gather some task metrics for a given project - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getTaskStats($project_id) - { - $stats = array(); - $stats['nb_active_tasks'] = 0; - $columns = $this->column->getAll($project_id); - $column_stats = $this->board->getColumnStats($project_id); - - foreach ($columns as &$column) { - $column['nb_active_tasks'] = isset($column_stats[$column['id']]) ? $column_stats[$column['id']] : 0; - $stats['nb_active_tasks'] += $column['nb_active_tasks']; - } - - $stats['columns'] = $columns; - $stats['nb_tasks'] = $this->taskFinder->countByProjectId($project_id); - $stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks']; - - return $stats; - } - - /** - * Get stats for each column of a project - * - * @access public - * @param array $project - * @return array - */ - public function getColumnStats(array &$project) - { - $project['columns'] = $this->column->getAll($project['id']); - $stats = $this->board->getColumnStats($project['id']); - - foreach ($project['columns'] as &$column) { - $column['nb_tasks'] = isset($stats[$column['id']]) ? $stats[$column['id']] : 0; - } - - return $project; - } - - /** - * Apply column stats to a collection of projects (filter callback) - * - * @access public - * @param array $projects - * @return array - */ - public function applyColumnStats(array $projects) - { - foreach ($projects as &$project) { - $this->getColumnStats($project); - } - - return $projects; - } - - /** - * Get project summary for a list of project - * - * @access public - * @param array $project_ids List of project id - * @return \PicoDb\Table - */ - public function getQueryColumnStats(array $project_ids) - { - if (empty($project_ids)) { - return $this->db->table(Project::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') - ->in(self::TABLE.'.id', $project_ids) - ->callback(array($this, 'applyColumnStats')); - } - - /** - * Create a project - * - * @access public - * @param array $values Form values - * @param integer $user_id User who create the project - * @param bool $add_user Automatically add the user - * @return integer Project id - */ - public function create(array $values, $user_id = 0, $add_user = false) - { - $this->db->startTransaction(); - - $values['token'] = ''; - $values['last_modified'] = time(); - $values['is_private'] = empty($values['is_private']) ? 0 : 1; - $values['owner_id'] = $user_id; - - if (! empty($values['identifier'])) { - $values['identifier'] = strtoupper($values['identifier']); - } - - $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); - - if (! $this->db->table(self::TABLE)->save($values)) { - $this->db->cancelTransaction(); - return false; - } - - $project_id = $this->db->getLastId(); - - if (! $this->board->create($project_id, $this->board->getUserColumns())) { - $this->db->cancelTransaction(); - return false; - } - - if ($add_user && $user_id) { - $this->projectUserRole->addUser($project_id, $user_id, Role::PROJECT_MANAGER); - } - - $this->category->createDefaultCategories($project_id); - - $this->db->closeTransaction(); - - return (int) $project_id; - } - - /** - * Check if the project have been modified - * - * @access public - * @param integer $project_id Project id - * @param integer $timestamp Timestamp - * @return bool - */ - public function isModifiedSince($project_id, $timestamp) - { - return (bool) $this->db->table(self::TABLE) - ->eq('id', $project_id) - ->gt('last_modified', $timestamp) - ->count(); - } - - /** - * Update modification date - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function updateModificationDate($project_id) - { - return $this->db->table(self::TABLE)->eq('id', $project_id)->update(array( - 'last_modified' => time() - )); - } - - /** - * Update a project - * - * @access public - * @param array $values Form values - * @return bool - */ - public function update(array $values) - { - if (! empty($values['identifier'])) { - $values['identifier'] = strtoupper($values['identifier']); - } - - $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); - - return $this->exists($values['id']) && - $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); - } - - /** - * Remove a project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function remove($project_id) - { - return $this->db->table(self::TABLE)->eq('id', $project_id)->remove(); - } - - /** - * Return true if the project exists - * - * @access public - * @param integer $project_id Project id - * @return boolean - */ - public function exists($project_id) - { - return $this->db->table(self::TABLE)->eq('id', $project_id)->exists(); - } - - /** - * Enable a project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function enable($project_id) - { - return $this->exists($project_id) && - $this->db - ->table(self::TABLE) - ->eq('id', $project_id) - ->update(array('is_active' => 1)); - } - - /** - * Disable a project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function disable($project_id) - { - return $this->exists($project_id) && - $this->db - ->table(self::TABLE) - ->eq('id', $project_id) - ->update(array('is_active' => 0)); - } - - /** - * Enable public access for a project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function enablePublicAccess($project_id) - { - return $this->exists($project_id) && - $this->db - ->table(self::TABLE) - ->eq('id', $project_id) - ->save(array('is_public' => 1, 'token' => Token::getToken())); - } - - /** - * Disable public access for a project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function disablePublicAccess($project_id) - { - return $this->exists($project_id) && - $this->db - ->table(self::TABLE) - ->eq('id', $project_id) - ->save(array('is_public' => 0, 'token' => '')); - } -} diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php deleted file mode 100644 index f6bdbf92..00000000 --- a/app/Model/ProjectActivity.php +++ /dev/null @@ -1,94 +0,0 @@ - $project_id, - 'task_id' => $task_id, - 'creator_id' => $creator_id, - 'event_name' => $event_name, - 'date_creation' => time(), - 'data' => json_encode($data), - ); - - $this->cleanup(self::MAX_EVENTS - 1); - return $this->db->table(self::TABLE)->insert($values); - } - - /** - * Get query - * - * @access public - * @return Table - */ - public function getQuery() - { - return $this - ->db - ->table(ProjectActivity::TABLE) - ->columns( - ProjectActivity::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'); - } - - /** - * Remove old event entries to avoid large table - * - * @access public - * @param integer $max Maximum number of items to keep in the table - */ - public function cleanup($max) - { - $total = $this->db->table(self::TABLE)->count(); - - if ($total > $max) { - $ids = $this->db->table(self::TABLE)->asc('id')->limit($total - $max)->findAllByColumn('id'); - $this->db->table(self::TABLE)->in('id', $ids)->remove(); - } - } -} diff --git a/app/Model/ProjectActivityModel.php b/app/Model/ProjectActivityModel.php new file mode 100644 index 00000000..380ea125 --- /dev/null +++ b/app/Model/ProjectActivityModel.php @@ -0,0 +1,94 @@ + $project_id, + 'task_id' => $task_id, + 'creator_id' => $creator_id, + 'event_name' => $event_name, + 'date_creation' => time(), + 'data' => json_encode($data), + ); + + $this->cleanup(self::MAX_EVENTS - 1); + return $this->db->table(self::TABLE)->insert($values); + } + + /** + * Get query + * + * @access public + * @return Table + */ + public function getQuery() + { + return $this + ->db + ->table(ProjectActivityModel::TABLE) + ->columns( + ProjectActivityModel::TABLE.'.*', + 'uc.username AS author_username', + 'uc.name AS author_name', + 'uc.email', + 'uc.avatar_path' + ) + ->join(TaskModel::TABLE, 'id', 'task_id') + ->join(ProjectModel::TABLE, 'id', 'project_id') + ->left(UserModel::TABLE, 'uc', 'id', ProjectActivityModel::TABLE, 'creator_id'); + } + + /** + * Remove old event entries to avoid large table + * + * @access public + * @param integer $max Maximum number of items to keep in the table + */ + public function cleanup($max) + { + $total = $this->db->table(self::TABLE)->count(); + + if ($total > $max) { + $ids = $this->db->table(self::TABLE)->asc('id')->limit($total - $max)->findAllByColumn('id'); + $this->db->table(self::TABLE)->in('id', $ids)->remove(); + } + } +} diff --git a/app/Model/ProjectDailyColumnStats.php b/app/Model/ProjectDailyColumnStats.php deleted file mode 100644 index 38487c76..00000000 --- a/app/Model/ProjectDailyColumnStats.php +++ /dev/null @@ -1,254 +0,0 @@ -db->startTransaction(); - $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('day', $date)->remove(); - - foreach ($this->getStatsByColumns($project_id) as $column_id => $column) { - $this->db->table(self::TABLE)->insert(array( - 'day' => $date, - 'project_id' => $project_id, - 'column_id' => $column_id, - 'total' => $column['total'], - 'score' => $column['score'], - )); - } - - $this->db->closeTransaction(); - - return true; - } - - /** - * Count the number of recorded days for the data range - * - * @access public - * @param integer $project_id Project id - * @param string $from Start date (ISO format YYYY-MM-DD) - * @param string $to End date - * @return integer - */ - public function countDays($project_id, $from, $to) - { - return $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->gte('day', $from) - ->lte('day', $to) - ->findOneColumn('COUNT(DISTINCT day)'); - } - - /** - * Get aggregated metrics for the project within a data range - * - * [ - * ['Date', 'Column1', 'Column2'], - * ['2014-11-16', 2, 5], - * ['2014-11-17', 20, 15], - * ] - * - * @access public - * @param integer $project_id Project id - * @param string $from Start date (ISO format YYYY-MM-DD) - * @param string $to End date - * @param string $field Column to aggregate - * @return array - */ - public function getAggregatedMetrics($project_id, $from, $to, $field = 'total') - { - $columns = $this->column->getList($project_id); - $metrics = $this->getMetrics($project_id, $from, $to); - return $this->buildAggregate($metrics, $columns, $field); - } - - /** - * Fetch metrics - * - * @access public - * @param integer $project_id Project id - * @param string $from Start date (ISO format YYYY-MM-DD) - * @param string $to End date - * @return array - */ - public function getMetrics($project_id, $from, $to) - { - return $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->gte('day', $from) - ->lte('day', $to) - ->asc(self::TABLE.'.day') - ->findAll(); - } - - /** - * Build aggregate - * - * @access private - * @param array $metrics - * @param array $columns - * @param string $field - * @return array - */ - private function buildAggregate(array &$metrics, array &$columns, $field) - { - $column_ids = array_keys($columns); - $days = array_unique(array_column($metrics, 'day')); - $rows = array(array_merge(array(e('Date')), array_values($columns))); - - foreach ($days as $day) { - $rows[] = $this->buildRowAggregate($metrics, $column_ids, $day, $field); - } - - return $rows; - } - - /** - * Build one row of the aggregate - * - * @access private - * @param array $metrics - * @param array $column_ids - * @param string $day - * @param string $field - * @return array - */ - private function buildRowAggregate(array &$metrics, array &$column_ids, $day, $field) - { - $row = array($day); - - foreach ($column_ids as $column_id) { - $row[] = $this->findValueInMetrics($metrics, $day, $column_id, $field); - } - - return $row; - } - - /** - * Find the value in the metrics - * - * @access private - * @param array $metrics - * @param string $day - * @param string $column_id - * @param string $field - * @return integer - */ - private function findValueInMetrics(array &$metrics, $day, $column_id, $field) - { - foreach ($metrics as $metric) { - if ($metric['day'] === $day && $metric['column_id'] == $column_id) { - return (int) $metric[$field]; - } - } - - return 0; - } - - /** - * Get number of tasks and score by columns - * - * @access private - * @param integer $project_id - * @return array - */ - private function getStatsByColumns($project_id) - { - $totals = $this->getTotalByColumns($project_id); - $scores = $this->getScoreByColumns($project_id); - $columns = array(); - - foreach ($totals as $column_id => $total) { - $columns[$column_id] = array('total' => $total, 'score' => 0); - } - - foreach ($scores as $column_id => $score) { - $columns[$column_id]['score'] = (int) $score; - } - - return $columns; - } - - /** - * Get number of tasks and score by columns - * - * @access private - * @param integer $project_id - * @return array - */ - private function getScoreByColumns($project_id) - { - $stats = $this->db->table(Task::TABLE) - ->columns('column_id', 'SUM(score) AS score') - ->eq('project_id', $project_id) - ->eq('is_active', Task::STATUS_OPEN) - ->notNull('score') - ->groupBy('column_id') - ->findAll(); - - return array_column($stats, 'score', 'column_id'); - } - - /** - * Get number of tasks and score by columns - * - * @access private - * @param integer $project_id - * @return array - */ - private function getTotalByColumns($project_id) - { - $stats = $this->db->table(Task::TABLE) - ->columns('column_id', 'COUNT(*) AS total') - ->eq('project_id', $project_id) - ->in('is_active', $this->getTaskStatusConfig()) - ->groupBy('column_id') - ->findAll(); - - return array_column($stats, 'total', 'column_id'); - } - - /** - * Get task status to use for total calculation - * - * @access private - * @return array - */ - private function getTaskStatusConfig() - { - if ($this->config->get('cfd_include_closed_tasks') == 1) { - return array(Task::STATUS_OPEN, Task::STATUS_CLOSED); - } - - return array(Task::STATUS_OPEN); - } -} diff --git a/app/Model/ProjectDailyColumnStatsModel.php b/app/Model/ProjectDailyColumnStatsModel.php new file mode 100644 index 00000000..a0f14cf4 --- /dev/null +++ b/app/Model/ProjectDailyColumnStatsModel.php @@ -0,0 +1,254 @@ +db->startTransaction(); + $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('day', $date)->remove(); + + foreach ($this->getStatsByColumns($project_id) as $column_id => $column) { + $this->db->table(self::TABLE)->insert(array( + 'day' => $date, + 'project_id' => $project_id, + 'column_id' => $column_id, + 'total' => $column['total'], + 'score' => $column['score'], + )); + } + + $this->db->closeTransaction(); + + return true; + } + + /** + * Count the number of recorded days for the data range + * + * @access public + * @param integer $project_id Project id + * @param string $from Start date (ISO format YYYY-MM-DD) + * @param string $to End date + * @return integer + */ + public function countDays($project_id, $from, $to) + { + return $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->gte('day', $from) + ->lte('day', $to) + ->findOneColumn('COUNT(DISTINCT day)'); + } + + /** + * Get aggregated metrics for the project within a data range + * + * [ + * ['Date', 'Column1', 'Column2'], + * ['2014-11-16', 2, 5], + * ['2014-11-17', 20, 15], + * ] + * + * @access public + * @param integer $project_id Project id + * @param string $from Start date (ISO format YYYY-MM-DD) + * @param string $to End date + * @param string $field Column to aggregate + * @return array + */ + public function getAggregatedMetrics($project_id, $from, $to, $field = 'total') + { + $columns = $this->columnModel->getList($project_id); + $metrics = $this->getMetrics($project_id, $from, $to); + return $this->buildAggregate($metrics, $columns, $field); + } + + /** + * Fetch metrics + * + * @access public + * @param integer $project_id Project id + * @param string $from Start date (ISO format YYYY-MM-DD) + * @param string $to End date + * @return array + */ + public function getMetrics($project_id, $from, $to) + { + return $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->gte('day', $from) + ->lte('day', $to) + ->asc(self::TABLE.'.day') + ->findAll(); + } + + /** + * Build aggregate + * + * @access private + * @param array $metrics + * @param array $columns + * @param string $field + * @return array + */ + private function buildAggregate(array &$metrics, array &$columns, $field) + { + $column_ids = array_keys($columns); + $days = array_unique(array_column($metrics, 'day')); + $rows = array(array_merge(array(e('Date')), array_values($columns))); + + foreach ($days as $day) { + $rows[] = $this->buildRowAggregate($metrics, $column_ids, $day, $field); + } + + return $rows; + } + + /** + * Build one row of the aggregate + * + * @access private + * @param array $metrics + * @param array $column_ids + * @param string $day + * @param string $field + * @return array + */ + private function buildRowAggregate(array &$metrics, array &$column_ids, $day, $field) + { + $row = array($day); + + foreach ($column_ids as $column_id) { + $row[] = $this->findValueInMetrics($metrics, $day, $column_id, $field); + } + + return $row; + } + + /** + * Find the value in the metrics + * + * @access private + * @param array $metrics + * @param string $day + * @param string $column_id + * @param string $field + * @return integer + */ + private function findValueInMetrics(array &$metrics, $day, $column_id, $field) + { + foreach ($metrics as $metric) { + if ($metric['day'] === $day && $metric['column_id'] == $column_id) { + return (int) $metric[$field]; + } + } + + return 0; + } + + /** + * Get number of tasks and score by columns + * + * @access private + * @param integer $project_id + * @return array + */ + private function getStatsByColumns($project_id) + { + $totals = $this->getTotalByColumns($project_id); + $scores = $this->getScoreByColumns($project_id); + $columns = array(); + + foreach ($totals as $column_id => $total) { + $columns[$column_id] = array('total' => $total, 'score' => 0); + } + + foreach ($scores as $column_id => $score) { + $columns[$column_id]['score'] = (int) $score; + } + + return $columns; + } + + /** + * Get number of tasks and score by columns + * + * @access private + * @param integer $project_id + * @return array + */ + private function getScoreByColumns($project_id) + { + $stats = $this->db->table(TaskModel::TABLE) + ->columns('column_id', 'SUM(score) AS score') + ->eq('project_id', $project_id) + ->eq('is_active', TaskModel::STATUS_OPEN) + ->notNull('score') + ->groupBy('column_id') + ->findAll(); + + return array_column($stats, 'score', 'column_id'); + } + + /** + * Get number of tasks and score by columns + * + * @access private + * @param integer $project_id + * @return array + */ + private function getTotalByColumns($project_id) + { + $stats = $this->db->table(TaskModel::TABLE) + ->columns('column_id', 'COUNT(*) AS total') + ->eq('project_id', $project_id) + ->in('is_active', $this->getTaskStatusConfig()) + ->groupBy('column_id') + ->findAll(); + + return array_column($stats, 'total', 'column_id'); + } + + /** + * Get task status to use for total calculation + * + * @access private + * @return array + */ + private function getTaskStatusConfig() + { + if ($this->configModel->get('cfd_include_closed_tasks') == 1) { + return array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED); + } + + return array(TaskModel::STATUS_OPEN); + } +} diff --git a/app/Model/ProjectDailyStats.php b/app/Model/ProjectDailyStats.php deleted file mode 100644 index 08a0039e..00000000 --- a/app/Model/ProjectDailyStats.php +++ /dev/null @@ -1,76 +0,0 @@ -db->startTransaction(); - - $lead_cycle_time = $this->averageLeadCycleTimeAnalytic->build($project_id); - - $this->db->table(self::TABLE)->eq('day', $date)->eq('project_id', $project_id)->remove(); - - $this->db->table(self::TABLE)->insert(array( - 'day' => $date, - 'project_id' => $project_id, - 'avg_lead_time' => $lead_cycle_time['avg_lead_time'], - 'avg_cycle_time' => $lead_cycle_time['avg_cycle_time'], - )); - - $this->db->closeTransaction(); - - return true; - } - - /** - * Get raw metrics for the project within a data range - * - * @access public - * @param integer $project_id Project id - * @param string $from Start date (ISO format YYYY-MM-DD) - * @param string $to End date - * @return array - */ - public function getRawMetrics($project_id, $from, $to) - { - $metrics = $this->db->table(self::TABLE) - ->columns('day', 'avg_lead_time', 'avg_cycle_time') - ->eq('project_id', $project_id) - ->gte('day', $from) - ->lte('day', $to) - ->asc('day') - ->findAll(); - - foreach ($metrics as &$metric) { - $metric['avg_lead_time'] = (int) $metric['avg_lead_time']; - $metric['avg_cycle_time'] = (int) $metric['avg_cycle_time']; - } - - return $metrics; - } -} diff --git a/app/Model/ProjectDailyStatsModel.php b/app/Model/ProjectDailyStatsModel.php new file mode 100644 index 00000000..0754d263 --- /dev/null +++ b/app/Model/ProjectDailyStatsModel.php @@ -0,0 +1,76 @@ +db->startTransaction(); + + $lead_cycle_time = $this->averageLeadCycleTimeAnalytic->build($project_id); + + $this->db->table(self::TABLE)->eq('day', $date)->eq('project_id', $project_id)->remove(); + + $this->db->table(self::TABLE)->insert(array( + 'day' => $date, + 'project_id' => $project_id, + 'avg_lead_time' => $lead_cycle_time['avg_lead_time'], + 'avg_cycle_time' => $lead_cycle_time['avg_cycle_time'], + )); + + $this->db->closeTransaction(); + + return true; + } + + /** + * Get raw metrics for the project within a data range + * + * @access public + * @param integer $project_id Project id + * @param string $from Start date (ISO format YYYY-MM-DD) + * @param string $to End date + * @return array + */ + public function getRawMetrics($project_id, $from, $to) + { + $metrics = $this->db->table(self::TABLE) + ->columns('day', 'avg_lead_time', 'avg_cycle_time') + ->eq('project_id', $project_id) + ->gte('day', $from) + ->lte('day', $to) + ->asc('day') + ->findAll(); + + foreach ($metrics as &$metric) { + $metric['avg_lead_time'] = (int) $metric['avg_lead_time']; + $metric['avg_cycle_time'] = (int) $metric['avg_cycle_time']; + } + + return $metrics; + } +} diff --git a/app/Model/ProjectDuplication.php b/app/Model/ProjectDuplication.php deleted file mode 100644 index 871cadc8..00000000 --- a/app/Model/ProjectDuplication.php +++ /dev/null @@ -1,161 +0,0 @@ - $max_length) { - $name = substr($name, 0, $max_length - strlen($suffix)); - } - - return $name.$suffix; - } - - /** - * Clone a project with all settings - * - * @param integer $src_project_id Project Id - * @param array $selection Selection of optional project parts to duplicate - * @param integer $owner_id Owner of the project - * @param string $name Name of the project - * @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) - { - $this->db->startTransaction(); - - // Get the cloned project Id - $dst_project_id = $this->copy($src_project_id, $owner_id, $name, $private); - - if ($dst_project_id === false) { - $this->db->cancelTransaction(); - return false; - } - - // Clone Columns, Categories, Permissions and Actions - foreach ($this->getPossibleSelection() as $model) { - - // Skip if optional part has not been selected - if (in_array($model, $this->getOptionalSelection()) && ! in_array($model, $selection)) { - continue; - } - - // Skip permissions for private projects - if ($private && $model === 'projectPermission') { - continue; - } - - if (! $this->$model->duplicate($src_project_id, $dst_project_id)) { - $this->db->cancelTransaction(); - return false; - } - } - - if (! $this->makeOwnerManager($dst_project_id, $owner_id)) { - $this->db->cancelTransaction(); - return false; - } - - $this->db->closeTransaction(); - - return (int) $dst_project_id; - } - - /** - * Create a project from another one - * - * @access private - * @param integer $src_project_id - * @param integer $owner_id - * @param string $name - * @param boolean $private - * @return integer - */ - private function copy($src_project_id, $owner_id = 0, $name = null, $private = null) - { - $project = $this->project->getById($src_project_id); - $is_private = empty($project['is_private']) ? 0 : 1; - - $values = array( - 'name' => $name ?: $this->getClonedProjectName($project['name']), - 'is_active' => 1, - 'last_modified' => time(), - 'token' => '', - 'is_public' => 0, - 'is_private' => $private ? 1 : $is_private, - 'owner_id' => $owner_id, - ); - - if (! $this->db->table(Project::TABLE)->save($values)) { - return false; - } - - return $this->db->getLastId(); - } - - /** - * Make sure that the creator of the duplicated project is alsp owner - * - * @access private - * @param integer $dst_project_id - * @param integer $owner_id - * @return boolean - */ - private function makeOwnerManager($dst_project_id, $owner_id) - { - if ($owner_id > 0) { - $this->projectUserRole->removeUser($dst_project_id, $owner_id); - - if (! $this->projectUserRole->addUser($dst_project_id, $owner_id, Role::PROJECT_MANAGER)) { - return false; - } - } - - return true; - } -} diff --git a/app/Model/ProjectDuplicationModel.php b/app/Model/ProjectDuplicationModel.php new file mode 100644 index 00000000..b67f8302 --- /dev/null +++ b/app/Model/ProjectDuplicationModel.php @@ -0,0 +1,161 @@ + $max_length) { + $name = substr($name, 0, $max_length - strlen($suffix)); + } + + return $name.$suffix; + } + + /** + * Clone a project with all settings + * + * @param integer $src_project_id Project Id + * @param array $selection Selection of optional project parts to duplicate + * @param integer $owner_id Owner of the project + * @param string $name Name of the project + * @param boolean $private Force the project to be private + * @return integer Cloned Project Id + */ + public function duplicate($src_project_id, $selection = array('projectPermissionModel', 'categoryModel', 'actionModel'), $owner_id = 0, $name = null, $private = null) + { + $this->db->startTransaction(); + + // Get the cloned project Id + $dst_project_id = $this->copy($src_project_id, $owner_id, $name, $private); + + if ($dst_project_id === false) { + $this->db->cancelTransaction(); + return false; + } + + // Clone Columns, Categories, Permissions and Actions + foreach ($this->getPossibleSelection() as $model) { + + // Skip if optional part has not been selected + if (in_array($model, $this->getOptionalSelection()) && ! in_array($model, $selection)) { + continue; + } + + // Skip permissions for private projects + if ($private && $model === 'projectPermissionModel') { + continue; + } + + if (! $this->$model->duplicate($src_project_id, $dst_project_id)) { + $this->db->cancelTransaction(); + return false; + } + } + + if (! $this->makeOwnerManager($dst_project_id, $owner_id)) { + $this->db->cancelTransaction(); + return false; + } + + $this->db->closeTransaction(); + + return (int) $dst_project_id; + } + + /** + * Create a project from another one + * + * @access private + * @param integer $src_project_id + * @param integer $owner_id + * @param string $name + * @param boolean $private + * @return integer + */ + private function copy($src_project_id, $owner_id = 0, $name = null, $private = null) + { + $project = $this->projectModel->getById($src_project_id); + $is_private = empty($project['is_private']) ? 0 : 1; + + $values = array( + 'name' => $name ?: $this->getClonedProjectName($project['name']), + 'is_active' => 1, + 'last_modified' => time(), + 'token' => '', + 'is_public' => 0, + 'is_private' => $private ? 1 : $is_private, + 'owner_id' => $owner_id, + ); + + if (! $this->db->table(ProjectModel::TABLE)->save($values)) { + return false; + } + + return $this->db->getLastId(); + } + + /** + * Make sure that the creator of the duplicated project is alsp owner + * + * @access private + * @param integer $dst_project_id + * @param integer $owner_id + * @return boolean + */ + private function makeOwnerManager($dst_project_id, $owner_id) + { + if ($owner_id > 0) { + $this->projectUserRoleModel->removeUser($dst_project_id, $owner_id); + + if (! $this->projectUserRoleModel->addUser($dst_project_id, $owner_id, Role::PROJECT_MANAGER)) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/ProjectFile.php b/app/Model/ProjectFile.php deleted file mode 100644 index 75348e0c..00000000 --- a/app/Model/ProjectFile.php +++ /dev/null @@ -1,42 +0,0 @@ -db - ->hashtable(Project::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'); - } - - /** - * For a given project get the role of the specified user - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @return string - */ - 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) - ->eq(self::TABLE.'.project_id', $project_id) - ->findAllByColumn('role'); - - return $this->projectAccessMap->getHighestRole($roles); - } - - /** - * Get all groups associated directly to the project - * - * @access public - * @param integer $project_id - * @return array - */ - 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') - ->eq('project_id', $project_id) - ->asc('name') - ->findAll(); - } - - /** - * From groups get all users associated to the project - * - * @access public - * @param integer $project_id - * @return array - */ - 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) - ->eq(self::TABLE.'.project_id', $project_id) - ->asc(User::TABLE.'.username') - ->findAll(); - } - - /** - * From groups get all users assignable to tasks - * - * @access public - * @param integer $project_id - * @return array - */ - 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) - ->eq(self::TABLE.'.project_id', $project_id) - ->eq(User::TABLE.'.is_active', 1) - ->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER)) - ->asc(User::TABLE.'.username') - ->findAll(); - } - - /** - * Add a group to the project - * - * @access public - * @param integer $project_id - * @param integer $group_id - * @param string $role - * @return boolean - */ - public function addGroup($project_id, $group_id, $role) - { - return $this->db->table(self::TABLE)->insert(array( - 'group_id' => $group_id, - 'project_id' => $project_id, - 'role' => $role, - )); - } - - /** - * Remove a group from the project - * - * @access public - * @param integer $project_id - * @param integer $group_id - * @return boolean - */ - public function removeGroup($project_id, $group_id) - { - return $this->db->table(self::TABLE)->eq('group_id', $group_id)->eq('project_id', $project_id)->remove(); - } - - /** - * Change a group role for the project - * - * @access public - * @param integer $project_id - * @param integer $group_id - * @param string $role - * @return boolean - */ - public function changeGroupRole($project_id, $group_id, $role) - { - return $this->db->table(self::TABLE) - ->eq('group_id', $group_id) - ->eq('project_id', $project_id) - ->update(array( - 'role' => $role, - )); - } - - /** - * Copy group access from a project to another one - * - * @param integer $project_src_id Project Template - * @param integer $project_dst_id Project that receives the copy - * @return boolean - */ - public function duplicate($project_src_id, $project_dst_id) - { - $rows = $this->db->table(self::TABLE)->eq('project_id', $project_src_id)->findAll(); - - foreach ($rows as $row) { - $result = $this->db->table(self::TABLE)->save(array( - 'project_id' => $project_dst_id, - 'group_id' => $row['group_id'], - 'role' => $row['role'], - )); - - if (! $result) { - return false; - } - } - - return true; - } -} diff --git a/app/Model/ProjectGroupRoleModel.php b/app/Model/ProjectGroupRoleModel.php new file mode 100644 index 00000000..2729d5a6 --- /dev/null +++ b/app/Model/ProjectGroupRoleModel.php @@ -0,0 +1,191 @@ +db + ->hashtable(ProjectModel::TABLE) + ->join(self::TABLE, 'project_id', 'id') + ->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'); + } + + /** + * For a given project get the role of the specified user + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @return string + */ + public function getUserRole($project_id, $user_id) + { + $roles = $this->db->table(self::TABLE) + ->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'); + + return $this->projectAccessMap->getHighestRole($roles); + } + + /** + * Get all groups associated directly to the project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getGroups($project_id) + { + return $this->db->table(self::TABLE) + ->columns(GroupModel::TABLE.'.id', GroupModel::TABLE.'.name', self::TABLE.'.role') + ->join(GroupModel::TABLE, 'id', 'group_id') + ->eq('project_id', $project_id) + ->asc('name') + ->findAll(); + } + + /** + * From groups get all users associated to the project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getUsers($project_id) + { + return $this->db->table(self::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(UserModel::TABLE.'.username') + ->findAll(); + } + + /** + * From groups get all users assignable to tasks + * + * @access public + * @param integer $project_id + * @return array + */ + public function getAssignableUsers($project_id) + { + 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(UserModel::TABLE.'.is_active', 1) + ->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER)) + ->asc(UserModel::TABLE.'.username') + ->findAll(); + } + + /** + * Add a group to the project + * + * @access public + * @param integer $project_id + * @param integer $group_id + * @param string $role + * @return boolean + */ + public function addGroup($project_id, $group_id, $role) + { + return $this->db->table(self::TABLE)->insert(array( + 'group_id' => $group_id, + 'project_id' => $project_id, + 'role' => $role, + )); + } + + /** + * Remove a group from the project + * + * @access public + * @param integer $project_id + * @param integer $group_id + * @return boolean + */ + public function removeGroup($project_id, $group_id) + { + return $this->db->table(self::TABLE)->eq('group_id', $group_id)->eq('project_id', $project_id)->remove(); + } + + /** + * Change a group role for the project + * + * @access public + * @param integer $project_id + * @param integer $group_id + * @param string $role + * @return boolean + */ + public function changeGroupRole($project_id, $group_id, $role) + { + return $this->db->table(self::TABLE) + ->eq('group_id', $group_id) + ->eq('project_id', $project_id) + ->update(array( + 'role' => $role, + )); + } + + /** + * Copy group access from a project to another one + * + * @param integer $project_src_id Project Template + * @param integer $project_dst_id Project that receives the copy + * @return boolean + */ + public function duplicate($project_src_id, $project_dst_id) + { + $rows = $this->db->table(self::TABLE)->eq('project_id', $project_src_id)->findAll(); + + foreach ($rows as $row) { + $result = $this->db->table(self::TABLE)->save(array( + 'project_id' => $project_dst_id, + 'group_id' => $row['group_id'], + 'role' => $row['role'], + )); + + if (! $result) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/ProjectMetadata.php b/app/Model/ProjectMetadata.php deleted file mode 100644 index c8e4fe63..00000000 --- a/app/Model/ProjectMetadata.php +++ /dev/null @@ -1,56 +0,0 @@ -getAll($src_project_id); - - if (! $this->save($dst_project_id, $metadata)) { - return false; - } - - return true; - } -} diff --git a/app/Model/ProjectMetadataModel.php b/app/Model/ProjectMetadataModel.php new file mode 100644 index 00000000..760acd7d --- /dev/null +++ b/app/Model/ProjectMetadataModel.php @@ -0,0 +1,54 @@ +getAll($src_project_id); + + if (! $this->save($dst_project_id, $metadata)) { + return false; + } + + return true; + } +} diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php new file mode 100644 index 00000000..34e11c13 --- /dev/null +++ b/app/Model/ProjectModel.php @@ -0,0 +1,526 @@ +db->table(self::TABLE)->eq('id', $project_id)->findOne(); + } + + /** + * Get a project by id with owner name + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getByIdWithOwner($project_id) + { + return $this->db->table(self::TABLE) + ->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name') + ->eq(self::TABLE.'.id', $project_id) + ->join(UserModel::TABLE, 'id', 'owner_id') + ->findOne(); + } + + /** + * Get a project by the name + * + * @access public + * @param string $name Project name + * @return array + */ + public function getByName($name) + { + return $this->db->table(self::TABLE)->eq('name', $name)->findOne(); + } + + /** + * Get a project by the identifier (code) + * + * @access public + * @param string $identifier + * @return array|boolean + */ + public function getByIdentifier($identifier) + { + if (empty($identifier)) { + return false; + } + + return $this->db->table(self::TABLE)->eq('identifier', strtoupper($identifier))->findOne(); + } + + /** + * Fetch project data by using the token + * + * @access public + * @param string $token Token + * @return array|boolean + */ + public function getByToken($token) + { + if (empty($token)) { + return false; + } + + return $this->db->table(self::TABLE)->eq('token', $token)->eq('is_public', 1)->findOne(); + } + + /** + * Return the first project from the database (no sorting) + * + * @access public + * @return array + */ + public function getFirst() + { + return $this->db->table(self::TABLE)->findOne(); + } + + /** + * Return true if the project is private + * + * @access public + * @param integer $project_id Project id + * @return boolean + */ + public function isPrivate($project_id) + { + return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists(); + } + + /** + * Get all projects + * + * @access public + * @return array + */ + public function getAll() + { + return $this->db->table(self::TABLE)->asc('name')->findAll(); + } + + /** + * Get all projects with given Ids + * + * @access public + * @param integer[] $project_ids + * @return array + */ + public function getAllByIds(array $project_ids) + { + if (empty($project_ids)) { + return array(); + } + + return $this->db->table(self::TABLE)->in('id', $project_ids)->asc('name')->findAll(); + } + + /** + * Get all project ids + * + * @access public + * @return array + */ + public function getAllIds() + { + return $this->db->table(self::TABLE)->asc('name')->findAllByColumn('id'); + } + + /** + * Return the list of all projects + * + * @access public + * @param bool $prepend If true, prepend to the list the value 'None' + * @return array + */ + public function getList($prepend = true) + { + if ($prepend) { + return array(t('None')) + $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); + } + + return $this->db->hashtable(self::TABLE)->asc('name')->getAll('id', 'name'); + } + + /** + * Get all projects with all its data for a given status + * + * @access public + * @param integer $status Project status: self::ACTIVE or self:INACTIVE + * @return array + */ + public function getAllByStatus($status) + { + return $this->db + ->table(self::TABLE) + ->asc('name') + ->eq('is_active', $status) + ->findAll(); + } + + /** + * Get a list of project by status + * + * @access public + * @param integer $status Project status: self::ACTIVE or self:INACTIVE + * @return array + */ + public function getListByStatus($status) + { + return $this->db + ->hashtable(self::TABLE) + ->asc('name') + ->eq('is_active', $status) + ->getAll('id', 'name'); + } + + /** + * Return the number of projects by status + * + * @access public + * @param integer $status Status: self::ACTIVE or self:INACTIVE + * @return integer + */ + public function countByStatus($status) + { + return $this->db + ->table(self::TABLE) + ->eq('is_active', $status) + ->count(); + } + + /** + * Get Priority range from a project + * + * @access public + * @param array $project + * @return array + */ + public function getPriorities(array $project) + { + $range = range($project['priority_start'], $project['priority_end']); + return array_combine($range, $range); + } + + /** + * Gather some task metrics for a given project + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getTaskStats($project_id) + { + $stats = array(); + $stats['nb_active_tasks'] = 0; + $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; + $stats['nb_active_tasks'] += $column['nb_active_tasks']; + } + + $stats['columns'] = $columns; + $stats['nb_tasks'] = $this->taskFinderModel->countByProjectId($project_id); + $stats['nb_inactive_tasks'] = $stats['nb_tasks'] - $stats['nb_active_tasks']; + + return $stats; + } + + /** + * Get stats for each column of a project + * + * @access public + * @param array $project + * @return array + */ + public function getColumnStats(array &$project) + { + $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; + } + + return $project; + } + + /** + * Apply column stats to a collection of projects (filter callback) + * + * @access public + * @param array $projects + * @return array + */ + public function applyColumnStats(array $projects) + { + foreach ($projects as &$project) { + $this->getColumnStats($project); + } + + return $projects; + } + + /** + * Get project summary for a list of project + * + * @access public + * @param array $project_ids List of project id + * @return \PicoDb\Table + */ + public function getQueryColumnStats(array $project_ids) + { + if (empty($project_ids)) { + return $this->db->table(ProjectModel::TABLE)->limit(0); + } + + return $this->db + ->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')); + } + + /** + * Create a project + * + * @access public + * @param array $values Form values + * @param integer $user_id User who create the project + * @param bool $add_user Automatically add the user + * @return integer Project id + */ + public function create(array $values, $user_id = 0, $add_user = false) + { + $this->db->startTransaction(); + + $values['token'] = ''; + $values['last_modified'] = time(); + $values['is_private'] = empty($values['is_private']) ? 0 : 1; + $values['owner_id'] = $user_id; + + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + + $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); + + if (! $this->db->table(self::TABLE)->save($values)) { + $this->db->cancelTransaction(); + return false; + } + + $project_id = $this->db->getLastId(); + + if (! $this->boardModel->create($project_id, $this->boardModel->getUserColumns())) { + $this->db->cancelTransaction(); + return false; + } + + if ($add_user && $user_id) { + $this->projectUserRoleModel->addUser($project_id, $user_id, Role::PROJECT_MANAGER); + } + + $this->categoryModel->createDefaultCategories($project_id); + + $this->db->closeTransaction(); + + return (int) $project_id; + } + + /** + * Check if the project have been modified + * + * @access public + * @param integer $project_id Project id + * @param integer $timestamp Timestamp + * @return bool + */ + public function isModifiedSince($project_id, $timestamp) + { + return (bool) $this->db->table(self::TABLE) + ->eq('id', $project_id) + ->gt('last_modified', $timestamp) + ->count(); + } + + /** + * Update modification date + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function updateModificationDate($project_id) + { + return $this->db->table(self::TABLE)->eq('id', $project_id)->update(array( + 'last_modified' => time() + )); + } + + /** + * Update a project + * + * @access public + * @param array $values Form values + * @return bool + */ + public function update(array $values) + { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + + $this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end')); + + return $this->exists($values['id']) && + $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); + } + + /** + * Remove a project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function remove($project_id) + { + return $this->db->table(self::TABLE)->eq('id', $project_id)->remove(); + } + + /** + * Return true if the project exists + * + * @access public + * @param integer $project_id Project id + * @return boolean + */ + public function exists($project_id) + { + return $this->db->table(self::TABLE)->eq('id', $project_id)->exists(); + } + + /** + * Enable a project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function enable($project_id) + { + return $this->exists($project_id) && + $this->db + ->table(self::TABLE) + ->eq('id', $project_id) + ->update(array('is_active' => 1)); + } + + /** + * Disable a project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function disable($project_id) + { + return $this->exists($project_id) && + $this->db + ->table(self::TABLE) + ->eq('id', $project_id) + ->update(array('is_active' => 0)); + } + + /** + * Enable public access for a project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function enablePublicAccess($project_id) + { + return $this->exists($project_id) && + $this->db + ->table(self::TABLE) + ->eq('id', $project_id) + ->save(array('is_public' => 1, 'token' => Token::getToken())); + } + + /** + * Disable public access for a project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function disablePublicAccess($project_id) + { + return $this->exists($project_id) && + $this->db + ->table(self::TABLE) + ->eq('id', $project_id) + ->save(array('is_public' => 0, 'token' => '')); + } +} diff --git a/app/Model/ProjectNotification.php b/app/Model/ProjectNotification.php deleted file mode 100644 index 5df042ca..00000000 --- a/app/Model/ProjectNotification.php +++ /dev/null @@ -1,67 +0,0 @@ -project->getById($project_id); - - $types = array_merge( - $this->projectNotificationType->getHiddenTypes(), - $this->projectNotificationType->getSelectedTypes($project_id) - ); - - foreach ($types as $type) { - $this->projectNotificationType->getType($type)->notifyProject($project, $event_name, $event_data); - } - } - - /** - * Save settings for the given project - * - * @access public - * @param integer $project_id - * @param array $values - */ - public function saveSettings($project_id, array $values) - { - $this->db->startTransaction(); - - $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); - $this->projectNotificationType->saveSelectedTypes($project_id, $types); - - $this->db->closeTransaction(); - } - - /** - * Read user settings to display the form - * - * @access public - * @param integer $project_id - * @return array - */ - public function readSettings($project_id) - { - return array( - 'notification_types' => $this->projectNotificationType->getSelectedTypes($project_id), - ); - } -} diff --git a/app/Model/ProjectNotificationModel.php b/app/Model/ProjectNotificationModel.php new file mode 100644 index 00000000..aeeee4cd --- /dev/null +++ b/app/Model/ProjectNotificationModel.php @@ -0,0 +1,67 @@ +projectModel->getById($project_id); + + $types = array_merge( + $this->projectNotificationTypeModel->getHiddenTypes(), + $this->projectNotificationTypeModel->getSelectedTypes($project_id) + ); + + foreach ($types as $type) { + $this->projectNotificationTypeModel->getType($type)->notifyProject($project, $event_name, $event_data); + } + } + + /** + * Save settings for the given project + * + * @access public + * @param integer $project_id + * @param array $values + */ + public function saveSettings($project_id, array $values) + { + $this->db->startTransaction(); + + $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); + $this->projectNotificationTypeModel->saveSelectedTypes($project_id, $types); + + $this->db->closeTransaction(); + } + + /** + * Read user settings to display the form + * + * @access public + * @param integer $project_id + * @return array + */ + public function readSettings($project_id) + { + return array( + 'notification_types' => $this->projectNotificationTypeModel->getSelectedTypes($project_id), + ); + } +} diff --git a/app/Model/ProjectNotificationType.php b/app/Model/ProjectNotificationType.php deleted file mode 100644 index a00e465c..00000000 --- a/app/Model/ProjectNotificationType.php +++ /dev/null @@ -1,59 +0,0 @@ -db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->asc('notification_type') - ->findAllByColumn('notification_type'); - - return $this->filterTypes($types); - } - - /** - * Save notification types for a given project - * - * @access public - * @param integer $project_id - * @param string[] $types - * @return boolean - */ - public function saveSelectedTypes($project_id, array $types) - { - $results = array(); - $this->db->table(self::TABLE)->eq('project_id', $project_id)->remove(); - - foreach ($types as $type) { - $results[] = $this->db->table(self::TABLE)->insert(array('project_id' => $project_id, 'notification_type' => $type)); - } - - return ! in_array(false, $results, true); - } -} diff --git a/app/Model/ProjectNotificationTypeModel.php b/app/Model/ProjectNotificationTypeModel.php new file mode 100644 index 00000000..aeec77f2 --- /dev/null +++ b/app/Model/ProjectNotificationTypeModel.php @@ -0,0 +1,57 @@ +db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->asc('notification_type') + ->findAllByColumn('notification_type'); + + return $this->filterTypes($types); + } + + /** + * Save notification types for a given project + * + * @access public + * @param integer $project_id + * @param string[] $types + * @return boolean + */ + public function saveSelectedTypes($project_id, array $types) + { + $results = array(); + $this->db->table(self::TABLE)->eq('project_id', $project_id)->remove(); + + foreach ($types as $type) { + $results[] = $this->db->table(self::TABLE)->insert(array('project_id' => $project_id, 'notification_type' => $type)); + } + + return ! in_array(false, $results, true); + } +} diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php deleted file mode 100644 index bc35c956..00000000 --- a/app/Model/ProjectPermission.php +++ /dev/null @@ -1,166 +0,0 @@ -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) - ->columns( - User::TABLE.'.id', - User::TABLE.'.username', - User::TABLE.'.name', - Project::TABLE.'.name AS project_name', - Project::TABLE.'.id' - ); - } - - /** - * Get all usernames (fetch users from groups) - * - * @access public - * @param integer $project_id - * @param string $input - * @return array - */ - public function findUsernames($project_id, $input) - { - $userMembers = $this->projectUserRoleQuery - ->withFilter(new ProjectUserRoleProjectFilter($project_id)) - ->withFilter(new ProjectUserRoleUsernameFilter($input)) - ->getQuery() - ->findAllByColumn('username'); - - $groupMembers = $this->projectGroupRoleQuery - ->withFilter(new ProjectGroupRoleProjectFilter($project_id)) - ->withFilter(new ProjectGroupRoleUsernameFilter($input)) - ->getQuery() - ->findAllByColumn('username'); - - $members = array_unique(array_merge($userMembers, $groupMembers)); - - sort($members); - - return $members; - } - - /** - * Return true if everybody is allowed for the project - * - * @access public - * @param integer $project_id Project id - * @return bool - */ - public function isEverybodyAllowed($project_id) - { - return $this->db - ->table(Project::TABLE) - ->eq('id', $project_id) - ->eq('is_everybody_allowed', 1) - ->exists(); - } - - /** - * Return true if the user is allowed to access a project - * - * @param integer $project_id - * @param integer $user_id - * @return boolean - */ - public function isUserAllowed($project_id, $user_id) - { - if ($this->userSession->isAdmin()) { - return true; - } - - return in_array( - $this->projectUserRole->getUserRole($project_id, $user_id), - array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER, Role::PROJECT_VIEWER) - ); - } - - /** - * Return true if the user is assignable - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @return boolean - */ - 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 true if the user is member - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @return boolean - */ - 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)); - } - - /** - * Get active project ids by user - * - * @access public - * @param integer $user_id - * @return array - */ - public function getActiveProjectIds($user_id) - { - return array_keys($this->projectUserRole->getActiveProjectsByUser($user_id)); - } - - /** - * Copy permissions to another project - * - * @param integer $project_src_id Project Template - * @param integer $project_dst_id Project that receives the copy - * @return boolean - */ - 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); - } -} diff --git a/app/Model/ProjectPermissionModel.php b/app/Model/ProjectPermissionModel.php new file mode 100644 index 00000000..a7c1857c --- /dev/null +++ b/app/Model/ProjectPermissionModel.php @@ -0,0 +1,166 @@ +db + ->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( + UserModel::TABLE.'.id', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name', + ProjectModel::TABLE.'.name AS project_name', + ProjectModel::TABLE.'.id' + ); + } + + /** + * Get all usernames (fetch users from groups) + * + * @access public + * @param integer $project_id + * @param string $input + * @return array + */ + public function findUsernames($project_id, $input) + { + $userMembers = $this->projectUserRoleQuery + ->withFilter(new ProjectUserRoleProjectFilter($project_id)) + ->withFilter(new ProjectUserRoleUsernameFilter($input)) + ->getQuery() + ->findAllByColumn('username'); + + $groupMembers = $this->projectGroupRoleQuery + ->withFilter(new ProjectGroupRoleProjectFilter($project_id)) + ->withFilter(new ProjectGroupRoleUsernameFilter($input)) + ->getQuery() + ->findAllByColumn('username'); + + $members = array_unique(array_merge($userMembers, $groupMembers)); + + sort($members); + + return $members; + } + + /** + * Return true if everybody is allowed for the project + * + * @access public + * @param integer $project_id Project id + * @return bool + */ + public function isEverybodyAllowed($project_id) + { + return $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->eq('is_everybody_allowed', 1) + ->exists(); + } + + /** + * Return true if the user is allowed to access a project + * + * @param integer $project_id + * @param integer $user_id + * @return boolean + */ + public function isUserAllowed($project_id, $user_id) + { + if ($this->userSession->isAdmin()) { + return true; + } + + return in_array( + $this->projectUserRoleModel->getUserRole($project_id, $user_id), + array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER, Role::PROJECT_VIEWER) + ); + } + + /** + * Return true if the user is assignable + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @return boolean + */ + public function isAssignable($project_id, $user_id) + { + return $this->userModel->isActive($user_id) && + in_array($this->projectUserRoleModel->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER)); + } + + /** + * Return true if the user is member + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @return boolean + */ + public function isMember($project_id, $user_id) + { + return in_array($this->projectUserRoleModel->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER, Role::PROJECT_VIEWER)); + } + + /** + * Get active project ids by user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getActiveProjectIds($user_id) + { + return array_keys($this->projectUserRoleModel->getActiveProjectsByUser($user_id)); + } + + /** + * Copy permissions to another project + * + * @param integer $project_src_id Project Template + * @param integer $project_dst_id Project that receives the copy + * @return boolean + */ + public function 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/ProjectUserRole.php deleted file mode 100644 index 05f96c6e..00000000 --- a/app/Model/ProjectUserRole.php +++ /dev/null @@ -1,282 +0,0 @@ -getProjectsByUser($user_id, array(Project::ACTIVE)); - } - - /** - * Get the list of project visible for the given user - * - * @access public - * @param integer $user_id - * @param array $status - * @return array - */ - public function getProjectsByUser($user_id, $status = array(Project::ACTIVE, Project::INACTIVE)) - { - $userProjects = $this->db - ->hashtable(Project::TABLE) - ->beginOr() - ->eq(self::TABLE.'.user_id', $user_id) - ->eq(Project::TABLE.'.is_everybody_allowed', 1) - ->closeOr() - ->in(Project::TABLE.'.is_active', $status) - ->join(self::TABLE, 'project_id', 'id') - ->getAll(Project::TABLE.'.id', Project::TABLE.'.name'); - - $groupProjects = $this->projectGroupRole->getProjectsByUser($user_id, $status); - $projects = $userProjects + $groupProjects; - - asort($projects); - - return $projects; - } - - /** - * For a given project get the role of the specified user - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @return string - */ - public function getUserRole($project_id, $user_id) - { - $projectInfo = $this->db->table(Project::TABLE) - ->eq('id', $project_id) - ->columns('owner_id', 'is_everybody_allowed') - ->findOne(); - - if ($projectInfo['is_everybody_allowed'] == 1) { - return $projectInfo['owner_id'] == $user_id ? Role::PROJECT_MANAGER : Role::PROJECT_MEMBER; - } - - $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); - } - - return $role; - } - - /** - * Get all users associated directly to the project - * - * @access public - * @param integer $project_id - * @return array - */ - 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') - ->eq('project_id', $project_id) - ->asc(User::TABLE.'.username') - ->asc(User::TABLE.'.name') - ->findAll(); - } - - /** - * Get all users (fetch users from groups) - * - * @access public - * @param integer $project_id - * @return array - */ - public function getAllUsers($project_id) - { - $userMembers = $this->getUsers($project_id); - $groupMembers = $this->projectGroupRole->getUsers($project_id); - $members = array_merge($userMembers, $groupMembers); - - return $this->user->prepareList($members); - } - - /** - * Get users grouped by role - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getAllUsersGroupedByRole($project_id) - { - $users = array(); - - $userMembers = $this->getUsers($project_id); - $groupMembers = $this->projectGroupRole->getUsers($project_id); - $members = array_merge($userMembers, $groupMembers); - - foreach ($members as $user) { - if (! isset($users[$user['role']])) { - $users[$user['role']] = array(); - } - - $users[$user['role']][$user['id']] = $user['name'] ?: $user['username']; - } - - return $users; - } - - /** - * Get list of users that can be assigned to a task (only Manager and Member) - * - * @access public - * @param integer $project_id - * @return array - */ - public function getAssignableUsers($project_id) - { - if ($this->projectPermission->isEverybodyAllowed($project_id)) { - return $this->user->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) - ->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); - $members = array_merge($userMembers, $groupMembers); - - return $this->user->prepareList($members); - } - - /** - * Get list of users that can be assigned to a task (only Manager and Member) - * - * @access public - * @param integer $project_id Project id - * @param bool $unassigned Prepend the 'Unassigned' value - * @param bool $everybody Prepend the 'Everbody' value - * @param bool $singleUser If there is only one user return only this user - * @return array - */ - public function getAssignableUsersList($project_id, $unassigned = true, $everybody = false, $singleUser = false) - { - $users = $this->getAssignableUsers($project_id); - - if ($singleUser && count($users) === 1) { - return $users; - } - - if ($unassigned) { - $users = array(t('Unassigned')) + $users; - } - - if ($everybody) { - $users = array(User::EVERYBODY_ID => t('Everybody')) + $users; - } - - return $users; - } - - /** - * Add a user to the project - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @param string $role - * @return boolean - */ - public function addUser($project_id, $user_id, $role) - { - return $this->db->table(self::TABLE)->insert(array( - 'user_id' => $user_id, - 'project_id' => $project_id, - 'role' => $role, - )); - } - - /** - * Remove a user from the project - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @return boolean - */ - public function removeUser($project_id, $user_id) - { - return $this->db->table(self::TABLE)->eq('user_id', $user_id)->eq('project_id', $project_id)->remove(); - } - - /** - * Change a user role for the project - * - * @access public - * @param integer $project_id - * @param integer $user_id - * @param string $role - * @return boolean - */ - public function changeUserRole($project_id, $user_id, $role) - { - return $this->db->table(self::TABLE) - ->eq('user_id', $user_id) - ->eq('project_id', $project_id) - ->update(array( - 'role' => $role, - )); - } - - /** - * Copy user access from a project to another one - * - * @param integer $project_src_id - * @param integer $project_dst_id - * @return boolean - */ - public function duplicate($project_src_id, $project_dst_id) - { - $rows = $this->db->table(self::TABLE)->eq('project_id', $project_src_id)->findAll(); - - foreach ($rows as $row) { - $result = $this->db->table(self::TABLE)->save(array( - 'project_id' => $project_dst_id, - 'user_id' => $row['user_id'], - 'role' => $row['role'], - )); - - if (! $result) { - return false; - } - } - - return true; - } -} diff --git a/app/Model/ProjectUserRoleModel.php b/app/Model/ProjectUserRoleModel.php new file mode 100644 index 00000000..a0df0cfa --- /dev/null +++ b/app/Model/ProjectUserRoleModel.php @@ -0,0 +1,282 @@ +getProjectsByUser($user_id, array(ProjectModel::ACTIVE)); + } + + /** + * Get the list of project visible for the given user + * + * @access public + * @param integer $user_id + * @param array $status + * @return array + */ + public function getProjectsByUser($user_id, $status = array(ProjectModel::ACTIVE, ProjectModel::INACTIVE)) + { + $userProjects = $this->db + ->hashtable(ProjectModel::TABLE) + ->beginOr() + ->eq(self::TABLE.'.user_id', $user_id) + ->eq(ProjectModel::TABLE.'.is_everybody_allowed', 1) + ->closeOr() + ->in(ProjectModel::TABLE.'.is_active', $status) + ->join(self::TABLE, 'project_id', 'id') + ->getAll(ProjectModel::TABLE.'.id', ProjectModel::TABLE.'.name'); + + $groupProjects = $this->projectGroupRoleModel->getProjectsByUser($user_id, $status); + $projects = $userProjects + $groupProjects; + + asort($projects); + + return $projects; + } + + /** + * For a given project get the role of the specified user + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @return string + */ + public function getUserRole($project_id, $user_id) + { + $projectInfo = $this->db->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->columns('owner_id', 'is_everybody_allowed') + ->findOne(); + + if ($projectInfo['is_everybody_allowed'] == 1) { + return $projectInfo['owner_id'] == $user_id ? Role::PROJECT_MANAGER : Role::PROJECT_MEMBER; + } + + $role = $this->db->table(self::TABLE)->eq('user_id', $user_id)->eq('project_id', $project_id)->findOneColumn('role'); + + if (empty($role)) { + $role = $this->projectGroupRoleModel->getUserRole($project_id, $user_id); + } + + return $role; + } + + /** + * Get all users associated directly to the project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getUsers($project_id) + { + return $this->db->table(self::TABLE) + ->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(UserModel::TABLE.'.username') + ->asc(UserModel::TABLE.'.name') + ->findAll(); + } + + /** + * Get all users (fetch users from groups) + * + * @access public + * @param integer $project_id + * @return array + */ + public function getAllUsers($project_id) + { + $userMembers = $this->getUsers($project_id); + $groupMembers = $this->projectGroupRoleModel->getUsers($project_id); + $members = array_merge($userMembers, $groupMembers); + + return $this->userModel->prepareList($members); + } + + /** + * Get users grouped by role + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getAllUsersGroupedByRole($project_id) + { + $users = array(); + + $userMembers = $this->getUsers($project_id); + $groupMembers = $this->projectGroupRoleModel->getUsers($project_id); + $members = array_merge($userMembers, $groupMembers); + + foreach ($members as $user) { + if (! isset($users[$user['role']])) { + $users[$user['role']] = array(); + } + + $users[$user['role']][$user['id']] = $user['name'] ?: $user['username']; + } + + return $users; + } + + /** + * Get list of users that can be assigned to a task (only Manager and Member) + * + * @access public + * @param integer $project_id + * @return array + */ + public function getAssignableUsers($project_id) + { + if ($this->projectPermissionModel->isEverybodyAllowed($project_id)) { + return $this->userModel->getActiveUsersList(); + } + + $userMembers = $this->db->table(self::TABLE) + ->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->projectGroupRoleModel->getAssignableUsers($project_id); + $members = array_merge($userMembers, $groupMembers); + + return $this->userModel->prepareList($members); + } + + /** + * Get list of users that can be assigned to a task (only Manager and Member) + * + * @access public + * @param integer $project_id Project id + * @param bool $unassigned Prepend the 'Unassigned' value + * @param bool $everybody Prepend the 'Everbody' value + * @param bool $singleUser If there is only one user return only this user + * @return array + */ + public function getAssignableUsersList($project_id, $unassigned = true, $everybody = false, $singleUser = false) + { + $users = $this->getAssignableUsers($project_id); + + if ($singleUser && count($users) === 1) { + return $users; + } + + if ($unassigned) { + $users = array(t('Unassigned')) + $users; + } + + if ($everybody) { + $users = array(UserModel::EVERYBODY_ID => t('Everybody')) + $users; + } + + return $users; + } + + /** + * Add a user to the project + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @param string $role + * @return boolean + */ + public function addUser($project_id, $user_id, $role) + { + return $this->db->table(self::TABLE)->insert(array( + 'user_id' => $user_id, + 'project_id' => $project_id, + 'role' => $role, + )); + } + + /** + * Remove a user from the project + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @return boolean + */ + public function removeUser($project_id, $user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->eq('project_id', $project_id)->remove(); + } + + /** + * Change a user role for the project + * + * @access public + * @param integer $project_id + * @param integer $user_id + * @param string $role + * @return boolean + */ + public function changeUserRole($project_id, $user_id, $role) + { + return $this->db->table(self::TABLE) + ->eq('user_id', $user_id) + ->eq('project_id', $project_id) + ->update(array( + 'role' => $role, + )); + } + + /** + * Copy user access from a project to another one + * + * @param integer $project_src_id + * @param integer $project_dst_id + * @return boolean + */ + public function duplicate($project_src_id, $project_dst_id) + { + $rows = $this->db->table(self::TABLE)->eq('project_id', $project_src_id)->findAll(); + + foreach ($rows as $row) { + $result = $this->db->table(self::TABLE)->save(array( + 'project_id' => $project_dst_id, + 'user_id' => $row['user_id'], + 'role' => $row['role'], + )); + + if (! $result) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/RememberMeSession.php b/app/Model/RememberMeSession.php deleted file mode 100644 index e3f2f132..00000000 --- a/app/Model/RememberMeSession.php +++ /dev/null @@ -1,152 +0,0 @@ -db - ->table(self::TABLE) - ->eq('token', $token) - ->eq('sequence', $sequence) - ->gt('expiration', time()) - ->findOne(); - } - - /** - * Get all sessions for a given user - * - * @access public - * @param integer $user_id User id - * @return array - */ - public function getAll($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('user_id', $user_id) - ->desc('date_creation') - ->columns('id', 'ip', 'user_agent', 'date_creation', 'expiration') - ->findAll(); - } - - /** - * Create a new RememberMe session - * - * @access public - * @param integer $user_id User id - * @param string $ip IP Address - * @param string $user_agent User Agent - * @return array - */ - public function create($user_id, $ip, $user_agent) - { - $token = hash('sha256', $user_id.$user_agent.$ip.Token::getToken()); - $sequence = Token::getToken(); - $expiration = time() + self::EXPIRATION; - - $this->cleanup($user_id); - - $this - ->db - ->table(self::TABLE) - ->insert(array( - 'user_id' => $user_id, - 'ip' => $ip, - 'user_agent' => $user_agent, - 'token' => $token, - 'sequence' => $sequence, - 'expiration' => $expiration, - 'date_creation' => time(), - )); - - return array( - 'token' => $token, - 'sequence' => $sequence, - 'expiration' => $expiration, - ); - } - - /** - * Remove a session record - * - * @access public - * @param integer $session_id Session id - * @return mixed - */ - public function remove($session_id) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $session_id) - ->remove(); - } - - /** - * Remove old sessions for a given user - * - * @access public - * @param integer $user_id User id - * @return bool - */ - public function cleanup($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('user_id', $user_id) - ->lt('expiration', time()) - ->remove(); - } - - /** - * Return a new sequence token and update the database - * - * @access public - * @param string $token Session token - * @return string - */ - public function updateSequence($token) - { - $sequence = Token::getToken(); - - $this - ->db - ->table(self::TABLE) - ->eq('token', $token) - ->update(array('sequence' => $sequence)); - - return $sequence; - } -} diff --git a/app/Model/RememberMeSessionModel.php b/app/Model/RememberMeSessionModel.php new file mode 100644 index 00000000..f6c8d648 --- /dev/null +++ b/app/Model/RememberMeSessionModel.php @@ -0,0 +1,152 @@ +db + ->table(self::TABLE) + ->eq('token', $token) + ->eq('sequence', $sequence) + ->gt('expiration', time()) + ->findOne(); + } + + /** + * Get all sessions for a given user + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getAll($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->desc('date_creation') + ->columns('id', 'ip', 'user_agent', 'date_creation', 'expiration') + ->findAll(); + } + + /** + * Create a new RememberMe session + * + * @access public + * @param integer $user_id User id + * @param string $ip IP Address + * @param string $user_agent User Agent + * @return array + */ + public function create($user_id, $ip, $user_agent) + { + $token = hash('sha256', $user_id.$user_agent.$ip.Token::getToken()); + $sequence = Token::getToken(); + $expiration = time() + self::EXPIRATION; + + $this->cleanup($user_id); + + $this + ->db + ->table(self::TABLE) + ->insert(array( + 'user_id' => $user_id, + 'ip' => $ip, + 'user_agent' => $user_agent, + 'token' => $token, + 'sequence' => $sequence, + 'expiration' => $expiration, + 'date_creation' => time(), + )); + + return array( + 'token' => $token, + 'sequence' => $sequence, + 'expiration' => $expiration, + ); + } + + /** + * Remove a session record + * + * @access public + * @param integer $session_id Session id + * @return mixed + */ + public function remove($session_id) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $session_id) + ->remove(); + } + + /** + * Remove old sessions for a given user + * + * @access public + * @param integer $user_id User id + * @return bool + */ + public function cleanup($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->lt('expiration', time()) + ->remove(); + } + + /** + * Return a new sequence token and update the database + * + * @access public + * @param string $token Session token + * @return string + */ + public function updateSequence($token) + { + $sequence = Token::getToken(); + + $this + ->db + ->table(self::TABLE) + ->eq('token', $token) + ->update(array('sequence' => $sequence)); + + return $sequence; + } +} diff --git a/app/Model/Setting.php b/app/Model/Setting.php deleted file mode 100644 index 38af22e0..00000000 --- a/app/Model/Setting.php +++ /dev/null @@ -1,113 +0,0 @@ -db->hashtable(self::TABLE)->getAll('option', 'value'); - } - - /** - * Get a setting value - * - * @access public - * @param string $name - * @param string $default - * @return mixed - */ - public function getOption($name, $default = '') - { - $value = $this->db - ->table(self::TABLE) - ->eq('option', $name) - ->findOneColumn('value'); - - return $value === null || $value === false || $value === '' ? $default : $value; - } - - /** - * Return true if a setting exists - * - * @access public - * @param string $name - * @return boolean - */ - public function exists($name) - { - return $this->db - ->table(self::TABLE) - ->eq('option', $name) - ->exists(); - } - - /** - * Update or insert new settings - * - * @access public - * @param array $values - * @return boolean - */ - public function save(array $values) - { - $results = array(); - $values = $this->prepare($values); - $user_id = $this->userSession->getId(); - $timestamp = time(); - - $this->db->startTransaction(); - - foreach ($values as $option => $value) { - if ($this->exists($option)) { - $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array( - 'value' => $value, - 'changed_on' => $timestamp, - 'changed_by' => $user_id, - )); - } else { - $results[] = $this->db->table(self::TABLE)->insert(array( - 'option' => $option, - 'value' => $value, - 'changed_on' => $timestamp, - 'changed_by' => $user_id, - )); - } - } - - $this->db->closeTransaction(); - - return ! in_array(false, $results, true); - } -} diff --git a/app/Model/SettingModel.php b/app/Model/SettingModel.php new file mode 100644 index 00000000..5b2ee54f --- /dev/null +++ b/app/Model/SettingModel.php @@ -0,0 +1,113 @@ +db->hashtable(self::TABLE)->getAll('option', 'value'); + } + + /** + * Get a setting value + * + * @access public + * @param string $name + * @param string $default + * @return mixed + */ + public function getOption($name, $default = '') + { + $value = $this->db + ->table(self::TABLE) + ->eq('option', $name) + ->findOneColumn('value'); + + return $value === null || $value === false || $value === '' ? $default : $value; + } + + /** + * Return true if a setting exists + * + * @access public + * @param string $name + * @return boolean + */ + public function exists($name) + { + return $this->db + ->table(self::TABLE) + ->eq('option', $name) + ->exists(); + } + + /** + * Update or insert new settings + * + * @access public + * @param array $values + * @return boolean + */ + public function save(array $values) + { + $results = array(); + $values = $this->prepare($values); + $user_id = $this->userSession->getId(); + $timestamp = time(); + + $this->db->startTransaction(); + + foreach ($values as $option => $value) { + if ($this->exists($option)) { + $results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array( + 'value' => $value, + 'changed_on' => $timestamp, + 'changed_by' => $user_id, + )); + } else { + $results[] = $this->db->table(self::TABLE)->insert(array( + 'option' => $option, + 'value' => $value, + 'changed_on' => $timestamp, + 'changed_by' => $user_id, + )); + } + } + + $this->db->closeTransaction(); + + return ! in_array(false, $results, true); + } +} diff --git a/app/Model/Subtask.php b/app/Model/Subtask.php deleted file mode 100644 index 1d53d6de..00000000 --- a/app/Model/Subtask.php +++ /dev/null @@ -1,428 +0,0 @@ - t('Todo'), - self::STATUS_INPROGRESS => t('In progress'), - self::STATUS_DONE => t('Done'), - ); - } - - /** - * Add subtask status status to the resultset - * - * @access public - * @param array $subtasks Subtasks - * @return array - */ - public function addStatusName(array $subtasks) - { - $status = $this->getStatusList(); - - foreach ($subtasks as &$subtask) { - $subtask['status_name'] = $status[$subtask['status']]; - $subtask['timer_start_date'] = isset($subtask['timer_start_date']) ? $subtask['timer_start_date'] : 0; - $subtask['is_timer_started'] = ! empty($subtask['timer_start_date']); - } - - return $subtasks; - } - - /** - * Get the query to fetch subtasks assigned to a user - * - * @access public - * @param integer $user_id User id - * @param array $status List of status - * @return \PicoDb\Table - */ - public function getUserQuery($user_id, array $status) - { - return $this->db->table(Subtask::TABLE) - ->columns( - Subtask::TABLE.'.*', - Task::TABLE.'.project_id', - Task::TABLE.'.color_id', - Task::TABLE.'.title AS task_name', - Project::TABLE.'.name AS project_name' - ) - ->subquery($this->subtaskTimeTracking->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) - ->callback(array($this, 'addStatusName')); - } - - /** - * Get all subtasks for a given task - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getAll($task_id) - { - return $this->db - ->table(self::TABLE) - ->eq('task_id', $task_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') - ->asc(self::TABLE.'.position') - ->callback(array($this, 'addStatusName')) - ->findAll(); - } - - /** - * Get a subtask by the id - * - * @access public - * @param integer $subtask_id Subtask id - * @param bool $more Fetch more data - * @return array - */ - public function getById($subtask_id, $more = false) - { - if ($more) { - 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') - ->callback(array($this, 'addStatusName')) - ->findOne(); - } - - return $this->db->table(self::TABLE)->eq('id', $subtask_id)->findOne(); - } - - /** - * Prepare data before insert/update - * - * @access public - * @param array $values Form values - */ - public function prepare(array &$values) - { - $this->helper->model->removeFields($values, array('another_subtask')); - $this->helper->model->resetFields($values, array('time_estimated', 'time_spent')); - } - - /** - * Prepare data before insert - * - * @access public - * @param array $values Form values - */ - public function prepareCreation(array &$values) - { - $this->prepare($values); - - $values['position'] = $this->getLastPosition($values['task_id']) + 1; - $values['status'] = isset($values['status']) ? $values['status'] : self::STATUS_TODO; - $values['time_estimated'] = isset($values['time_estimated']) ? $values['time_estimated'] : 0; - $values['time_spent'] = isset($values['time_spent']) ? $values['time_spent'] : 0; - $values['user_id'] = isset($values['user_id']) ? $values['user_id'] : 0; - } - - /** - * Get the position of the last column for a given project - * - * @access public - * @param integer $task_id Task id - * @return integer - */ - public function getLastPosition($task_id) - { - return (int) $this->db - ->table(self::TABLE) - ->eq('task_id', $task_id) - ->desc('position') - ->findOneColumn('position'); - } - - /** - * Create a new subtask - * - * @access public - * @param array $values Form values - * @return bool|integer - */ - public function create(array $values) - { - $this->prepareCreation($values); - $subtask_id = $this->db->table(self::TABLE)->persist($values); - - if ($subtask_id) { - $this->container['dispatcher']->dispatch( - self::EVENT_CREATE, - new SubtaskEvent(array('id' => $subtask_id) + $values) - ); - } - - return $subtask_id; - } - - /** - * Update - * - * @access public - * @param array $values Form values - * @param bool $fire_events If true, will be called an event - * @return bool - */ - public function update(array $values, $fire_events = true) - { - $this->prepare($values); - $subtask = $this->getById($values['id']); - $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); - - if ($result && $fire_events) { - $event = $subtask; - $event['changes'] = array_diff_assoc($values, $subtask); - $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new SubtaskEvent($event)); - } - - return $result; - } - - /** - * Close all subtasks of a task - * - * @access public - * @param integer $task_id - * @return boolean - */ - public function closeAll($task_id) - { - return $this->db->table(self::TABLE)->eq('task_id', $task_id)->update(array('status' => self::STATUS_DONE)); - } - - /** - * Save subtask position - * - * @access public - * @param integer $task_id - * @param integer $subtask_id - * @param integer $position - * @return boolean - */ - public function changePosition($task_id, $subtask_id, $position) - { - if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('task_id', $task_id)->count()) { - return false; - } - - $subtask_ids = $this->db->table(self::TABLE)->eq('task_id', $task_id)->neq('id', $subtask_id)->asc('position')->findAllByColumn('id'); - $offset = 1; - $results = array(); - - foreach ($subtask_ids as $current_subtask_id) { - if ($offset == $position) { - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $current_subtask_id)->update(array('position' => $offset)); - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $subtask_id)->update(array('position' => $position)); - - return !in_array(false, $results, true); - } - - /** - * Change the status of subtask - * - * @access public - * @param integer $subtask_id - * @return boolean|integer - */ - public function toggleStatus($subtask_id) - { - $subtask = $this->getById($subtask_id); - $status = ($subtask['status'] + 1) % 3; - - $values = array( - 'id' => $subtask['id'], - 'status' => $status, - 'task_id' => $subtask['task_id'], - ); - - if (empty($subtask['user_id']) && $this->userSession->isLogged()) { - $values['user_id'] = $this->userSession->getId(); - } - - return $this->update($values) ? $status : false; - } - - /** - * Get the subtask in progress for this user - * - * @access public - * @param integer $user_id - * @return array - */ - public function getSubtaskInProgress($user_id) - { - return $this->db->table(self::TABLE) - ->eq('status', self::STATUS_INPROGRESS) - ->eq('user_id', $user_id) - ->findOne(); - } - - /** - * Return true if the user have a subtask in progress - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function hasSubtaskInProgress($user_id) - { - return $this->config->get('subtask_restriction') == 1 && - $this->db->table(self::TABLE) - ->eq('status', self::STATUS_INPROGRESS) - ->eq('user_id', $user_id) - ->exists(); - } - - /** - * Remove - * - * @access public - * @param integer $subtask_id Subtask id - * @return bool - */ - public function remove($subtask_id) - { - $subtask = $this->getById($subtask_id); - $result = $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove(); - - if ($result) { - $this->container['dispatcher']->dispatch(self::EVENT_DELETE, new SubtaskEvent($subtask)); - } - - return $result; - } - - /** - * Duplicate all subtasks to another task - * - * @access public - * @param integer $src_task_id Source task id - * @param integer $dst_task_id Destination task id - * @return bool - */ - public function duplicate($src_task_id, $dst_task_id) - { - return $this->db->transaction(function (Database $db) use ($src_task_id, $dst_task_id) { - - $subtasks = $db->table(Subtask::TABLE) - ->columns('title', 'time_estimated', 'position') - ->eq('task_id', $src_task_id) - ->asc('position') - ->findAll(); - - foreach ($subtasks as &$subtask) { - $subtask['task_id'] = $dst_task_id; - - if (! $db->table(Subtask::TABLE)->save($subtask)) { - return false; - } - } - }); - } - - /** - * Convert a subtask to a task - * - * @access public - * @param integer $project_id - * @param integer $subtask_id - * @return integer - */ - public function convertToTask($project_id, $subtask_id) - { - $subtask = $this->getById($subtask_id); - - $task_id = $this->taskCreation->create(array( - 'project_id' => $project_id, - 'title' => $subtask['title'], - 'time_estimated' => $subtask['time_estimated'], - 'time_spent' => $subtask['time_spent'], - 'owner_id' => $subtask['user_id'], - )); - - if ($task_id !== false) { - $this->remove($subtask_id); - } - - return $task_id; - } -} diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php new file mode 100644 index 00000000..b63cf0a1 --- /dev/null +++ b/app/Model/SubtaskModel.php @@ -0,0 +1,428 @@ + t('Todo'), + self::STATUS_INPROGRESS => t('In progress'), + self::STATUS_DONE => t('Done'), + ); + } + + /** + * Add subtask status status to the resultset + * + * @access public + * @param array $subtasks Subtasks + * @return array + */ + public function addStatusName(array $subtasks) + { + $status = $this->getStatusList(); + + foreach ($subtasks as &$subtask) { + $subtask['status_name'] = $status[$subtask['status']]; + $subtask['timer_start_date'] = isset($subtask['timer_start_date']) ? $subtask['timer_start_date'] : 0; + $subtask['is_timer_started'] = ! empty($subtask['timer_start_date']); + } + + return $subtasks; + } + + /** + * Get the query to fetch subtasks assigned to a user + * + * @access public + * @param integer $user_id User id + * @param array $status List of status + * @return \PicoDb\Table + */ + public function getUserQuery($user_id, array $status) + { + return $this->db->table(SubtaskModel::TABLE) + ->columns( + SubtaskModel::TABLE.'.*', + TaskModel::TABLE.'.project_id', + TaskModel::TABLE.'.color_id', + TaskModel::TABLE.'.title AS task_name', + ProjectModel::TABLE.'.name AS project_name' + ) + ->subquery($this->subtaskTimeTrackingModel->getTimerQuery($user_id), 'timer_start_date') + ->eq('user_id', $user_id) + ->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')); + } + + /** + * Get all subtasks for a given task + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAll($task_id) + { + return $this->db + ->table(self::TABLE) + ->eq('task_id', $task_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') + ->asc(self::TABLE.'.position') + ->callback(array($this, 'addStatusName')) + ->findAll(); + } + + /** + * Get a subtask by the id + * + * @access public + * @param integer $subtask_id Subtask id + * @param bool $more Fetch more data + * @return array + */ + public function getById($subtask_id, $more = false) + { + if ($more) { + return $this->db + ->table(self::TABLE) + ->eq(self::TABLE.'.id', $subtask_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(); + } + + return $this->db->table(self::TABLE)->eq('id', $subtask_id)->findOne(); + } + + /** + * Prepare data before insert/update + * + * @access public + * @param array $values Form values + */ + public function prepare(array &$values) + { + $this->helper->model->removeFields($values, array('another_subtask')); + $this->helper->model->resetFields($values, array('time_estimated', 'time_spent')); + } + + /** + * Prepare data before insert + * + * @access public + * @param array $values Form values + */ + public function prepareCreation(array &$values) + { + $this->prepare($values); + + $values['position'] = $this->getLastPosition($values['task_id']) + 1; + $values['status'] = isset($values['status']) ? $values['status'] : self::STATUS_TODO; + $values['time_estimated'] = isset($values['time_estimated']) ? $values['time_estimated'] : 0; + $values['time_spent'] = isset($values['time_spent']) ? $values['time_spent'] : 0; + $values['user_id'] = isset($values['user_id']) ? $values['user_id'] : 0; + } + + /** + * Get the position of the last column for a given project + * + * @access public + * @param integer $task_id Task id + * @return integer + */ + public function getLastPosition($task_id) + { + return (int) $this->db + ->table(self::TABLE) + ->eq('task_id', $task_id) + ->desc('position') + ->findOneColumn('position'); + } + + /** + * Create a new subtask + * + * @access public + * @param array $values Form values + * @return bool|integer + */ + public function create(array $values) + { + $this->prepareCreation($values); + $subtask_id = $this->db->table(self::TABLE)->persist($values); + + if ($subtask_id) { + $this->container['dispatcher']->dispatch( + self::EVENT_CREATE, + new SubtaskEvent(array('id' => $subtask_id) + $values) + ); + } + + return $subtask_id; + } + + /** + * Update + * + * @access public + * @param array $values Form values + * @param bool $fire_events If true, will be called an event + * @return bool + */ + public function update(array $values, $fire_events = true) + { + $this->prepare($values); + $subtask = $this->getById($values['id']); + $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); + + if ($result && $fire_events) { + $event = $subtask; + $event['changes'] = array_diff_assoc($values, $subtask); + $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new SubtaskEvent($event)); + } + + return $result; + } + + /** + * Close all subtasks of a task + * + * @access public + * @param integer $task_id + * @return boolean + */ + public function closeAll($task_id) + { + return $this->db->table(self::TABLE)->eq('task_id', $task_id)->update(array('status' => self::STATUS_DONE)); + } + + /** + * Save subtask position + * + * @access public + * @param integer $task_id + * @param integer $subtask_id + * @param integer $position + * @return boolean + */ + public function changePosition($task_id, $subtask_id, $position) + { + if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('task_id', $task_id)->count()) { + return false; + } + + $subtask_ids = $this->db->table(self::TABLE)->eq('task_id', $task_id)->neq('id', $subtask_id)->asc('position')->findAllByColumn('id'); + $offset = 1; + $results = array(); + + foreach ($subtask_ids as $current_subtask_id) { + if ($offset == $position) { + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $current_subtask_id)->update(array('position' => $offset)); + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $subtask_id)->update(array('position' => $position)); + + return !in_array(false, $results, true); + } + + /** + * Change the status of subtask + * + * @access public + * @param integer $subtask_id + * @return boolean|integer + */ + public function toggleStatus($subtask_id) + { + $subtask = $this->getById($subtask_id); + $status = ($subtask['status'] + 1) % 3; + + $values = array( + 'id' => $subtask['id'], + 'status' => $status, + 'task_id' => $subtask['task_id'], + ); + + if (empty($subtask['user_id']) && $this->userSession->isLogged()) { + $values['user_id'] = $this->userSession->getId(); + } + + return $this->update($values) ? $status : false; + } + + /** + * Get the subtask in progress for this user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getSubtaskInProgress($user_id) + { + return $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->findOne(); + } + + /** + * Return true if the user have a subtask in progress + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasSubtaskInProgress($user_id) + { + return $this->configModel->get('subtask_restriction') == 1 && + $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->exists(); + } + + /** + * Remove + * + * @access public + * @param integer $subtask_id Subtask id + * @return bool + */ + public function remove($subtask_id) + { + $subtask = $this->getById($subtask_id); + $result = $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove(); + + if ($result) { + $this->container['dispatcher']->dispatch(self::EVENT_DELETE, new SubtaskEvent($subtask)); + } + + return $result; + } + + /** + * Duplicate all subtasks to another task + * + * @access public + * @param integer $src_task_id Source task id + * @param integer $dst_task_id Destination task id + * @return bool + */ + public function duplicate($src_task_id, $dst_task_id) + { + return $this->db->transaction(function (Database $db) use ($src_task_id, $dst_task_id) { + + $subtasks = $db->table(SubtaskModel::TABLE) + ->columns('title', 'time_estimated', 'position') + ->eq('task_id', $src_task_id) + ->asc('position') + ->findAll(); + + foreach ($subtasks as &$subtask) { + $subtask['task_id'] = $dst_task_id; + + if (! $db->table(SubtaskModel::TABLE)->save($subtask)) { + return false; + } + } + }); + } + + /** + * Convert a subtask to a task + * + * @access public + * @param integer $project_id + * @param integer $subtask_id + * @return integer + */ + public function convertToTask($project_id, $subtask_id) + { + $subtask = $this->getById($subtask_id); + + $task_id = $this->taskCreationModel->create(array( + 'project_id' => $project_id, + 'title' => $subtask['title'], + 'time_estimated' => $subtask['time_estimated'], + 'time_spent' => $subtask['time_spent'], + 'owner_id' => $subtask['user_id'], + )); + + if ($task_id !== false) { + $this->remove($subtask_id); + } + + return $task_id; + } +} diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php deleted file mode 100644 index 8b5d2545..00000000 --- a/app/Model/SubtaskTimeTracking.php +++ /dev/null @@ -1,298 +0,0 @@ -db->escapeIdentifier('start'), - $this->db->escapeIdentifier(self::TABLE), - $this->db->escapeIdentifier('user_id'), - $user_id, - $this->db->escapeIdentifier('end'), - $this->db->escapeIdentifier('subtask_id'), - Subtask::TABLE.'.id' - ); - } - - /** - * Get query for user timesheet (pagination) - * - * @access public - * @param integer $user_id User id - * @return \PicoDb\Table - */ - public function getUserQuery($user_id) - { - return $this->db - ->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.subtask_id', - 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' - ) - ->join(Subtask::TABLE, 'id', 'subtask_id') - ->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE) - ->eq(self::TABLE.'.user_id', $user_id); - } - - /** - * Get query for task timesheet (pagination) - * - * @access public - * @param integer $task_id Task id - * @return \PicoDb\Table - */ - public function getTaskQuery($task_id) - { - return $this->db - ->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.subtask_id', - self::TABLE.'.end', - 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' - ) - ->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); - } - - /** - * Get query for project timesheet (pagination) - * - * @access public - * @param integer $project_id Project id - * @return \PicoDb\Table - */ - public function getProjectQuery($project_id) - { - return $this->db - ->table(self::TABLE) - ->columns( - self::TABLE.'.id', - self::TABLE.'.subtask_id', - self::TABLE.'.end', - 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' - ) - ->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) - ->asc(self::TABLE.'.id'); - } - - /** - * Get all recorded time slots for a given user - * - * @access public - * @param integer $user_id User id - * @return array - */ - public function getUserTimesheet($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('user_id', $user_id) - ->findAll(); - } - - /** - * Return true if a timer is started for this use and subtask - * - * @access public - * @param integer $subtask_id - * @param integer $user_id - * @return boolean - */ - public function hasTimer($subtask_id, $user_id) - { - return $this->db->table(self::TABLE)->eq('subtask_id', $subtask_id)->eq('user_id', $user_id)->eq('end', 0)->exists(); - } - - /** - * Log start time - * - * @access public - * @param integer $subtask_id - * @param integer $user_id - * @return boolean - */ - public function logStartTime($subtask_id, $user_id) - { - return - ! $this->hasTimer($subtask_id, $user_id) && - $this->db - ->table(self::TABLE) - ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0)); - } - - /** - * Log end time - * - * @access public - * @param integer $subtask_id - * @param integer $user_id - * @return boolean - */ - public function logEndTime($subtask_id, $user_id) - { - $time_spent = $this->getTimeSpent($subtask_id, $user_id); - - if ($time_spent > 0) { - $this->updateSubtaskTimeSpent($subtask_id, $time_spent); - } - - return $this->db - ->table(self::TABLE) - ->eq('subtask_id', $subtask_id) - ->eq('user_id', $user_id) - ->eq('end', 0) - ->update(array( - 'end' => time(), - 'time_spent' => $time_spent, - )); - } - - /** - * Calculate the time spent when the clock is stopped - * - * @access public - * @param integer $subtask_id - * @param integer $user_id - * @return float - */ - public function getTimeSpent($subtask_id, $user_id) - { - $hook = 'model:subtask-time-tracking:calculate:time-spent'; - $start_time = $this->db - ->table(self::TABLE) - ->eq('subtask_id', $subtask_id) - ->eq('user_id', $user_id) - ->eq('end', 0) - ->findOneColumn('start'); - - if (empty($start_time)) { - return 0; - } - - $end = new DateTime; - $start = new DateTime; - $start->setTimestamp($start_time); - - if ($this->hook->exists($hook)) { - return $this->hook->first($hook, array( - 'user_id' => $user_id, - 'start' => $start, - 'end' => $end, - )); - } - - return $this->dateParser->getHours($start, $end); - } - - /** - * Update subtask time spent - * - * @access public - * @param integer $subtask_id - * @param float $time_spent - * @return bool - */ - public function updateSubtaskTimeSpent($subtask_id, $time_spent) - { - $subtask = $this->subtask->getById($subtask_id); - - // Fire the event subtask.update - return $this->subtask->update(array( - 'id' => $subtask['id'], - 'time_spent' => $subtask['time_spent'] + $time_spent, - 'task_id' => $subtask['task_id'], - ), false); - } - - /** - * Update task time tracking based on subtasks time tracking - * - * @access public - * @param integer $task_id Task id - * @return bool - */ - public function updateTaskTimeTracking($task_id) - { - $values = $this->calculateSubtaskTime($task_id); - - return $this->db - ->table(Task::TABLE) - ->eq('id', $task_id) - ->update($values); - } - - /** - * Sum time spent and time estimated for all subtasks - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function calculateSubtaskTime($task_id) - { - return $this->db - ->table(Subtask::TABLE) - ->eq('task_id', $task_id) - ->columns( - 'SUM(time_spent) AS time_spent', - 'SUM(time_estimated) AS time_estimated' - ) - ->findOne(); - } -} diff --git a/app/Model/SubtaskTimeTrackingModel.php b/app/Model/SubtaskTimeTrackingModel.php new file mode 100644 index 00000000..062e594a --- /dev/null +++ b/app/Model/SubtaskTimeTrackingModel.php @@ -0,0 +1,298 @@ +db->escapeIdentifier('start'), + $this->db->escapeIdentifier(self::TABLE), + $this->db->escapeIdentifier('user_id'), + $user_id, + $this->db->escapeIdentifier('end'), + $this->db->escapeIdentifier('subtask_id'), + SubtaskModel::TABLE.'.id' + ); + } + + /** + * Get query for user timesheet (pagination) + * + * @access public + * @param integer $user_id User id + * @return \PicoDb\Table + */ + public function getUserQuery($user_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + self::TABLE.'.time_spent', + 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(SubtaskModel::TABLE, 'id', 'subtask_id') + ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE) + ->eq(self::TABLE.'.user_id', $user_id); + } + + /** + * Get query for task timesheet (pagination) + * + * @access public + * @param integer $task_id Task id + * @return \PicoDb\Table + */ + public function getTaskQuery($task_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + self::TABLE.'.time_spent', + self::TABLE.'.user_id', + SubtaskModel::TABLE.'.task_id', + SubtaskModel::TABLE.'.title AS subtask_title', + TaskModel::TABLE.'.project_id', + UserModel::TABLE.'.username', + UserModel::TABLE.'.name AS user_fullname' + ) + ->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); + } + + /** + * Get query for project timesheet (pagination) + * + * @access public + * @param integer $project_id Project id + * @return \PicoDb\Table + */ + public function getProjectQuery($project_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + self::TABLE.'.time_spent', + self::TABLE.'.user_id', + 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(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'); + } + + /** + * Get all recorded time slots for a given user + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getUserTimesheet($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->findAll(); + } + + /** + * Return true if a timer is started for this use and subtask + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function hasTimer($subtask_id, $user_id) + { + return $this->db->table(self::TABLE)->eq('subtask_id', $subtask_id)->eq('user_id', $user_id)->eq('end', 0)->exists(); + } + + /** + * Log start time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logStartTime($subtask_id, $user_id) + { + return + ! $this->hasTimer($subtask_id, $user_id) && + $this->db + ->table(self::TABLE) + ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0)); + } + + /** + * Log end time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logEndTime($subtask_id, $user_id) + { + $time_spent = $this->getTimeSpent($subtask_id, $user_id); + + if ($time_spent > 0) { + $this->updateSubtaskTimeSpent($subtask_id, $time_spent); + } + + return $this->db + ->table(self::TABLE) + ->eq('subtask_id', $subtask_id) + ->eq('user_id', $user_id) + ->eq('end', 0) + ->update(array( + 'end' => time(), + 'time_spent' => $time_spent, + )); + } + + /** + * Calculate the time spent when the clock is stopped + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return float + */ + public function getTimeSpent($subtask_id, $user_id) + { + $hook = 'model:subtask-time-tracking:calculate:time-spent'; + $start_time = $this->db + ->table(self::TABLE) + ->eq('subtask_id', $subtask_id) + ->eq('user_id', $user_id) + ->eq('end', 0) + ->findOneColumn('start'); + + if (empty($start_time)) { + return 0; + } + + $end = new DateTime; + $start = new DateTime; + $start->setTimestamp($start_time); + + if ($this->hook->exists($hook)) { + return $this->hook->first($hook, array( + 'user_id' => $user_id, + 'start' => $start, + 'end' => $end, + )); + } + + return $this->dateParser->getHours($start, $end); + } + + /** + * Update subtask time spent + * + * @access public + * @param integer $subtask_id + * @param float $time_spent + * @return bool + */ + public function updateSubtaskTimeSpent($subtask_id, $time_spent) + { + $subtask = $this->subtaskModel->getById($subtask_id); + + // Fire the event subtask.update + return $this->subtaskModel->update(array( + 'id' => $subtask['id'], + 'time_spent' => $subtask['time_spent'] + $time_spent, + 'task_id' => $subtask['task_id'], + ), false); + } + + /** + * Update task time tracking based on subtasks time tracking + * + * @access public + * @param integer $task_id Task id + * @return bool + */ + public function updateTaskTimeTracking($task_id) + { + $values = $this->calculateSubtaskTime($task_id); + + return $this->db + ->table(TaskModel::TABLE) + ->eq('id', $task_id) + ->update($values); + } + + /** + * Sum time spent and time estimated for all subtasks + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function calculateSubtaskTime($task_id) + { + return $this->db + ->table(SubtaskModel::TABLE) + ->eq('task_id', $task_id) + ->columns( + 'SUM(time_spent) AS time_spent', + 'SUM(time_estimated) AS time_estimated' + ) + ->findOne(); + } +} diff --git a/app/Model/Swimlane.php b/app/Model/Swimlane.php deleted file mode 100644 index 8efe68da..00000000 --- a/app/Model/Swimlane.php +++ /dev/null @@ -1,490 +0,0 @@ -db->table(self::TABLE)->eq('id', $swimlane_id)->findOne(); - } - - /** - * Get the swimlane name by the id - * - * @access public - * @param integer $swimlane_id Swimlane id - * @return string - */ - public function getNameById($swimlane_id) - { - return $this->db->table(self::TABLE)->eq('id', $swimlane_id)->findOneColumn('name') ?: ''; - } - - /** - * Get a swimlane id by the project and the name - * - * @access public - * @param integer $project_id Project id - * @param string $name Name - * @return integer - */ - public function getIdByName($project_id, $name) - { - return (int) $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('name', $name) - ->findOneColumn('id'); - } - - /** - * Get a swimlane by the project and the name - * - * @access public - * @param integer $project_id Project id - * @param string $name Swimlane name - * @return array - */ - public function getByName($project_id, $name) - { - return $this->db->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('name', $name) - ->findOne(); - } - - /** - * Get default swimlane properties - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getDefault($project_id) - { - $result = $this->db - ->table(Project::TABLE) - ->eq('id', $project_id) - ->columns('id', 'default_swimlane', 'show_default_swimlane') - ->findOne(); - - if ($result['default_swimlane'] === 'Default swimlane') { - $result['default_swimlane'] = t($result['default_swimlane']); - } - - return $result; - } - - /** - * Get all swimlanes for a given project - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getAll($project_id) - { - return $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->orderBy('position', 'asc') - ->findAll(); - } - - /** - * Get the list of swimlanes by status - * - * @access public - * @param integer $project_id Project id - * @param integer $status Status - * @return array - */ - public function getAllByStatus($project_id, $status = self::ACTIVE) - { - $query = $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('is_active', $status); - - if ($status == self::ACTIVE) { - $query->asc('position'); - } else { - $query->asc('name'); - } - - return $query->findAll(); - } - - /** - * Get active swimlanes - * - * @access public - * @param integer $project_id Project id - * @return array - */ - public function getSwimlanes($project_id) - { - $swimlanes = $this->db - ->table(self::TABLE) - ->columns('id', 'name', 'description') - ->eq('project_id', $project_id) - ->eq('is_active', self::ACTIVE) - ->orderBy('position', 'asc') - ->findAll(); - - $default_swimlane = $this->db - ->table(Project::TABLE) - ->eq('id', $project_id) - ->eq('show_default_swimlane', 1) - ->findOneColumn('default_swimlane'); - - if ($default_swimlane) { - if ($default_swimlane === 'Default swimlane') { - $default_swimlane = t($default_swimlane); - } - - array_unshift($swimlanes, array('id' => 0, 'name' => $default_swimlane)); - } - - return $swimlanes; - } - - /** - * Get list of all swimlanes - * - * @access public - * @param integer $project_id Project id - * @param boolean $prepend Prepend default value - * @param boolean $only_active Return only active swimlanes - * @return array - */ - 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'); - - if ($prepend) { - $swimlanes[-1] = t('All swimlanes'); - } - - if (! empty($default)) { - $swimlanes[0] = $default === 'Default swimlane' ? t($default) : $default; - } - - return $swimlanes + $this->db - ->hashtable(self::TABLE) - ->eq('project_id', $project_id) - ->in('is_active', $only_active ? array(self::ACTIVE) : array(self::ACTIVE, self::INACTIVE)) - ->orderBy('position', 'asc') - ->getAll('id', 'name'); - } - - /** - * Add a new swimlane - * - * @access public - * @param array $values Form values - * @return integer|boolean - */ - public function create($values) - { - if (! $this->project->exists($values['project_id'])) { - return 0; - } - - $values['position'] = $this->getLastPosition($values['project_id']); - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Update a swimlane - * - * @access public - * @param array $values Form values - * @return bool - */ - public function update(array $values) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $values['id']) - ->update($values); - } - - /** - * Update the default swimlane - * - * @access public - * @param array $values Form values - * @return bool - */ - public function updateDefault(array $values) - { - return $this->db - ->table(Project::TABLE) - ->eq('id', $values['id']) - ->update(array( - 'default_swimlane' => $values['default_swimlane'], - 'show_default_swimlane' => $values['show_default_swimlane'], - )); - } - - /** - * Enable the default swimlane - * - * @access public - * @param integer $project_id - * @return bool - */ - public function enableDefault($project_id) - { - return $this->db - ->table(Project::TABLE) - ->eq('id', $project_id) - ->update(array( - 'show_default_swimlane' => 1, - )); - } - - /** - * Disable the default swimlane - * - * @access public - * @param integer $project_id - * @return bool - */ - public function disableDefault($project_id) - { - return $this->db - ->table(Project::TABLE) - ->eq('id', $project_id) - ->update(array( - 'show_default_swimlane' => 0, - )); - } - - /** - * Get the last position of a swimlane - * - * @access public - * @param integer $project_id - * @return integer - */ - public function getLastPosition($project_id) - { - return $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('is_active', 1) - ->count() + 1; - } - - /** - * Disable a swimlane - * - * @access public - * @param integer $project_id Project id - * @param integer $swimlane_id Swimlane id - * @return bool - */ - public function disable($project_id, $swimlane_id) - { - $result = $this->db - ->table(self::TABLE) - ->eq('id', $swimlane_id) - ->update(array( - 'is_active' => self::INACTIVE, - 'position' => 0, - )); - - if ($result) { - // Re-order positions - $this->updatePositions($project_id); - } - - return $result; - } - - /** - * Enable a swimlane - * - * @access public - * @param integer $project_id Project id - * @param integer $swimlane_id Swimlane id - * @return bool - */ - public function enable($project_id, $swimlane_id) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $swimlane_id) - ->update(array( - 'is_active' => self::ACTIVE, - 'position' => $this->getLastPosition($project_id), - )); - } - - /** - * Remove a swimlane - * - * @access public - * @param integer $project_id Project id - * @param integer $swimlane_id Swimlane id - * @return bool - */ - public function remove($project_id, $swimlane_id) - { - $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)); - - if (! $this->db->table(self::TABLE)->eq('id', $swimlane_id)->remove()) { - $this->db->cancelTransaction(); - return false; - } - - // Re-order positions - $this->updatePositions($project_id); - - $this->db->closeTransaction(); - - return true; - } - - /** - * Update swimlane positions after disabling or removing a swimlane - * - * @access public - * @param integer $project_id Project id - * @return boolean - */ - public function updatePositions($project_id) - { - $position = 0; - $swimlanes = $this->db - ->table(self::TABLE) - ->eq('project_id', $project_id) - ->eq('is_active', 1) - ->asc('position') - ->asc('id') - ->findAllByColumn('id'); - - if (! $swimlanes) { - return false; - } - - foreach ($swimlanes as $swimlane_id) { - $this->db->table(self::TABLE) - ->eq('id', $swimlane_id) - ->update(array('position' => ++$position)); - } - - return true; - } - - /** - * Change swimlane position - * - * @access public - * @param integer $project_id - * @param integer $swimlane_id - * @param integer $position - * @return boolean - */ - public function changePosition($project_id, $swimlane_id, $position) - { - if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('project_id', $project_id)->count()) { - return false; - } - - $swimlane_ids = $this->db->table(self::TABLE) - ->eq('is_active', 1) - ->eq('project_id', $project_id) - ->neq('id', $swimlane_id) - ->asc('position') - ->findAllByColumn('id'); - - $offset = 1; - $results = array(); - - foreach ($swimlane_ids as $current_swimlane_id) { - if ($offset == $position) { - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $current_swimlane_id)->update(array('position' => $offset)); - $offset++; - } - - $results[] = $this->db->table(self::TABLE)->eq('id', $swimlane_id)->update(array('position' => $position)); - - return !in_array(false, $results, true); - } - - /** - * Duplicate Swimlane to project - * - * @access public - * @param integer $project_from Project Template - * @param integer $project_to Project that receives the copy - * @return integer|boolean - */ - - public function duplicate($project_from, $project_to) - { - $swimlanes = $this->getAll($project_from); - - foreach ($swimlanes as $swimlane) { - unset($swimlane['id']); - $swimlane['project_id'] = $project_to; - - if (! $this->db->table(self::TABLE)->save($swimlane)) { - return false; - } - } - - $default_swimlane = $this->getDefault($project_from); - $default_swimlane['id'] = $project_to; - - $this->updateDefault($default_swimlane); - - return true; - } -} diff --git a/app/Model/SwimlaneModel.php b/app/Model/SwimlaneModel.php new file mode 100644 index 00000000..87591b99 --- /dev/null +++ b/app/Model/SwimlaneModel.php @@ -0,0 +1,490 @@ +db->table(self::TABLE)->eq('id', $swimlane_id)->findOne(); + } + + /** + * Get the swimlane name by the id + * + * @access public + * @param integer $swimlane_id Swimlane id + * @return string + */ + public function getNameById($swimlane_id) + { + return $this->db->table(self::TABLE)->eq('id', $swimlane_id)->findOneColumn('name') ?: ''; + } + + /** + * Get a swimlane id by the project and the name + * + * @access public + * @param integer $project_id Project id + * @param string $name Name + * @return integer + */ + public function getIdByName($project_id, $name) + { + return (int) $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('name', $name) + ->findOneColumn('id'); + } + + /** + * Get a swimlane by the project and the name + * + * @access public + * @param integer $project_id Project id + * @param string $name Swimlane name + * @return array + */ + public function getByName($project_id, $name) + { + return $this->db->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('name', $name) + ->findOne(); + } + + /** + * Get default swimlane properties + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getDefault($project_id) + { + $result = $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->columns('id', 'default_swimlane', 'show_default_swimlane') + ->findOne(); + + if ($result['default_swimlane'] === 'Default swimlane') { + $result['default_swimlane'] = t($result['default_swimlane']); + } + + return $result; + } + + /** + * Get all swimlanes for a given project + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getAll($project_id) + { + return $this->db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->orderBy('position', 'asc') + ->findAll(); + } + + /** + * Get the list of swimlanes by status + * + * @access public + * @param integer $project_id Project id + * @param integer $status Status + * @return array + */ + public function getAllByStatus($project_id, $status = self::ACTIVE) + { + $query = $this->db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('is_active', $status); + + if ($status == self::ACTIVE) { + $query->asc('position'); + } else { + $query->asc('name'); + } + + return $query->findAll(); + } + + /** + * Get active swimlanes + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getSwimlanes($project_id) + { + $swimlanes = $this->db + ->table(self::TABLE) + ->columns('id', 'name', 'description') + ->eq('project_id', $project_id) + ->eq('is_active', self::ACTIVE) + ->orderBy('position', 'asc') + ->findAll(); + + $default_swimlane = $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->eq('show_default_swimlane', 1) + ->findOneColumn('default_swimlane'); + + if ($default_swimlane) { + if ($default_swimlane === 'Default swimlane') { + $default_swimlane = t($default_swimlane); + } + + array_unshift($swimlanes, array('id' => 0, 'name' => $default_swimlane)); + } + + return $swimlanes; + } + + /** + * Get list of all swimlanes + * + * @access public + * @param integer $project_id Project id + * @param boolean $prepend Prepend default value + * @param boolean $only_active Return only active swimlanes + * @return array + */ + public function getList($project_id, $prepend = false, $only_active = false) + { + $swimlanes = array(); + $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'); + } + + if (! empty($default)) { + $swimlanes[0] = $default === 'Default swimlane' ? t($default) : $default; + } + + return $swimlanes + $this->db + ->hashtable(self::TABLE) + ->eq('project_id', $project_id) + ->in('is_active', $only_active ? array(self::ACTIVE) : array(self::ACTIVE, self::INACTIVE)) + ->orderBy('position', 'asc') + ->getAll('id', 'name'); + } + + /** + * Add a new swimlane + * + * @access public + * @param array $values Form values + * @return integer|boolean + */ + public function create($values) + { + if (! $this->projectModel->exists($values['project_id'])) { + return 0; + } + + $values['position'] = $this->getLastPosition($values['project_id']); + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Update a swimlane + * + * @access public + * @param array $values Form values + * @return bool + */ + public function update(array $values) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $values['id']) + ->update($values); + } + + /** + * Update the default swimlane + * + * @access public + * @param array $values Form values + * @return bool + */ + public function updateDefault(array $values) + { + return $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $values['id']) + ->update(array( + 'default_swimlane' => $values['default_swimlane'], + 'show_default_swimlane' => $values['show_default_swimlane'], + )); + } + + /** + * Enable the default swimlane + * + * @access public + * @param integer $project_id + * @return bool + */ + public function enableDefault($project_id) + { + return $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->update(array( + 'show_default_swimlane' => 1, + )); + } + + /** + * Disable the default swimlane + * + * @access public + * @param integer $project_id + * @return bool + */ + public function disableDefault($project_id) + { + return $this->db + ->table(ProjectModel::TABLE) + ->eq('id', $project_id) + ->update(array( + 'show_default_swimlane' => 0, + )); + } + + /** + * Get the last position of a swimlane + * + * @access public + * @param integer $project_id + * @return integer + */ + public function getLastPosition($project_id) + { + return $this->db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('is_active', 1) + ->count() + 1; + } + + /** + * Disable a swimlane + * + * @access public + * @param integer $project_id Project id + * @param integer $swimlane_id Swimlane id + * @return bool + */ + public function disable($project_id, $swimlane_id) + { + $result = $this->db + ->table(self::TABLE) + ->eq('id', $swimlane_id) + ->update(array( + 'is_active' => self::INACTIVE, + 'position' => 0, + )); + + if ($result) { + // Re-order positions + $this->updatePositions($project_id); + } + + return $result; + } + + /** + * Enable a swimlane + * + * @access public + * @param integer $project_id Project id + * @param integer $swimlane_id Swimlane id + * @return bool + */ + public function enable($project_id, $swimlane_id) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $swimlane_id) + ->update(array( + 'is_active' => self::ACTIVE, + 'position' => $this->getLastPosition($project_id), + )); + } + + /** + * Remove a swimlane + * + * @access public + * @param integer $project_id Project id + * @param integer $swimlane_id Swimlane id + * @return bool + */ + public function remove($project_id, $swimlane_id) + { + $this->db->startTransaction(); + + // Tasks should not be assigned anymore to this swimlane + $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(); + return false; + } + + // Re-order positions + $this->updatePositions($project_id); + + $this->db->closeTransaction(); + + return true; + } + + /** + * Update swimlane positions after disabling or removing a swimlane + * + * @access public + * @param integer $project_id Project id + * @return boolean + */ + public function updatePositions($project_id) + { + $position = 0; + $swimlanes = $this->db + ->table(self::TABLE) + ->eq('project_id', $project_id) + ->eq('is_active', 1) + ->asc('position') + ->asc('id') + ->findAllByColumn('id'); + + if (! $swimlanes) { + return false; + } + + foreach ($swimlanes as $swimlane_id) { + $this->db->table(self::TABLE) + ->eq('id', $swimlane_id) + ->update(array('position' => ++$position)); + } + + return true; + } + + /** + * Change swimlane position + * + * @access public + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $position + * @return boolean + */ + public function changePosition($project_id, $swimlane_id, $position) + { + if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('project_id', $project_id)->count()) { + return false; + } + + $swimlane_ids = $this->db->table(self::TABLE) + ->eq('is_active', 1) + ->eq('project_id', $project_id) + ->neq('id', $swimlane_id) + ->asc('position') + ->findAllByColumn('id'); + + $offset = 1; + $results = array(); + + foreach ($swimlane_ids as $current_swimlane_id) { + if ($offset == $position) { + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $current_swimlane_id)->update(array('position' => $offset)); + $offset++; + } + + $results[] = $this->db->table(self::TABLE)->eq('id', $swimlane_id)->update(array('position' => $position)); + + return !in_array(false, $results, true); + } + + /** + * Duplicate Swimlane to project + * + * @access public + * @param integer $project_from Project Template + * @param integer $project_to Project that receives the copy + * @return integer|boolean + */ + + public function duplicate($project_from, $project_to) + { + $swimlanes = $this->getAll($project_from); + + foreach ($swimlanes as $swimlane) { + unset($swimlane['id']); + $swimlane['project_id'] = $project_to; + + if (! $this->db->table(self::TABLE)->save($swimlane)) { + return false; + } + } + + $default_swimlane = $this->getDefault($project_from); + $default_swimlane['id'] = $project_to; + + $this->updateDefault($default_swimlane); + + return true; + } +} diff --git a/app/Model/Task.php b/app/Model/Task.php deleted file mode 100644 index bdb55c46..00000000 --- a/app/Model/Task.php +++ /dev/null @@ -1,225 +0,0 @@ -taskFinder->exists($task_id)) { - return false; - } - - $this->taskFile->removeAll($task_id); - - return $this->db->table(self::TABLE)->eq('id', $task_id)->remove(); - } - - /** - * Get a the task id from a text - * - * Example: "Fix bug #1234" will return 1234 - * - * @access public - * @param string $message Text - * @return integer - */ - public function getTaskIdFromText($message) - { - if (preg_match('!#(\d+)!i', $message, $matches) && isset($matches[1])) { - return $matches[1]; - } - - return 0; - } - - /** - * Return the list user selectable recurrence status - * - * @access public - * @return array - */ - public function getRecurrenceStatusList() - { - return array( - Task::RECURRING_STATUS_NONE => t('No'), - Task::RECURRING_STATUS_PENDING => t('Yes'), - ); - } - - /** - * Return the list recurrence triggers - * - * @access public - * @return array - */ - 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'), - ); - } - - /** - * Return the list options to calculate recurrence due date - * - * @access public - * @return array - */ - public function getRecurrenceBasedateList() - { - return array( - Task::RECURRING_BASEDATE_DUEDATE => t('Existing due date'), - Task::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'), - ); - } - - /** - * Return the list recurrence timeframes - * - * @access public - * @return array - */ - 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)'), - ); - } - - /** - * Get task progress based on the column position - * - * @access public - * @param array $task - * @param array $columns - * @return integer - */ - public function getProgress(array $task, array $columns) - { - if ($task['is_active'] == self::STATUS_CLOSED) { - return 100; - } - - $position = 0; - - foreach ($columns as $column_id => $column_title) { - if ($column_id == $task['column_id']) { - break; - } - - $position++; - } - - return round(($position * 100) / count($columns), 1); - } - - /** - * Helper method to duplicate all tasks to another project - * - * @access public - * @param integer $src_project_id - * @param integer $dst_project_id - * @return boolean - */ - public function duplicate($src_project_id, $dst_project_id) - { - $task_ids = $this->taskFinder->getAllIds($src_project_id, array(Task::STATUS_OPEN, Task::STATUS_CLOSED)); - - foreach ($task_ids as $task_id) { - if (! $this->taskDuplication->duplicateToProject($task_id, $dst_project_id)) { - return false; - } - } - - return true; - } -} diff --git a/app/Model/TaskAnalytic.php b/app/Model/TaskAnalytic.php deleted file mode 100644 index bf118b4e..00000000 --- a/app/Model/TaskAnalytic.php +++ /dev/null @@ -1,72 +0,0 @@ -column->getList($task['project_id']); - $sums = $this->transition->getTimeSpentByTask($task['id']); - - foreach ($columns as $column_id => $column_title) { - $time_spent = isset($sums[$column_id]) ? $sums[$column_id] : 0; - - if ($task['column_id'] == $column_id) { - $time_spent += ($task['date_completed'] ?: time()) - $task['date_moved']; - } - - $result[] = array( - 'id' => $column_id, - 'title' => $column_title, - 'time_spent' => $time_spent, - ); - } - - return $result; - } -} diff --git a/app/Model/TaskAnalyticModel.php b/app/Model/TaskAnalyticModel.php new file mode 100644 index 00000000..3d6fe8a8 --- /dev/null +++ b/app/Model/TaskAnalyticModel.php @@ -0,0 +1,72 @@ +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; + + if ($task['column_id'] == $column_id) { + $time_spent += ($task['date_completed'] ?: time()) - $task['date_moved']; + } + + $result[] = array( + 'id' => $column_id, + 'title' => $column_title, + 'time_spent' => $time_spent, + ); + } + + return $result; + } +} diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php deleted file mode 100644 index 2abfd95c..00000000 --- a/app/Model/TaskCreation.php +++ /dev/null @@ -1,103 +0,0 @@ -project->exists($values['project_id'])) { - return 0; - } - - $position = empty($values['position']) ? 0 : $values['position']; - - $this->prepare($values); - $task_id = $this->db->table(Task::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->fireEvents($task_id, $values); - } - - return (int) $task_id; - } - - /** - * Prepare data - * - * @access public - * @param array $values Form values - */ - public function prepare(array &$values) - { - $values = $this->dateParser->convert($values, array('date_due')); - $values = $this->dateParser->convert($values, array('date_started'), true); - - $this->helper->model->removeFields($values, array('another_task')); - $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']); - } - - if (empty($values['color_id'])) { - $values['color_id'] = $this->color->getDefaultColor(); - } - - if (empty($values['title'])) { - $values['title'] = t('Untitled'); - } - - if ($this->userSession->isLogged()) { - $values['creator_id'] = $this->userSession->getId(); - } - - $values['swimlane_id'] = empty($values['swimlane_id']) ? 0 : $values['swimlane_id']; - $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; - } - - /** - * Fire events - * - * @access private - * @param integer $task_id Task id - * @param array $values Form values - */ - private function fireEvents($task_id, array $values) - { - $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->dispatcher->dispatch(Task::EVENT_CREATE_UPDATE, $event); - $this->dispatcher->dispatch(Task::EVENT_CREATE, $event); - - if (! empty($values['description'])) { - $this->userMention->fireEvents($values['description'], Task::EVENT_USER_MENTION, $event); - } - } -} diff --git a/app/Model/TaskCreationModel.php b/app/Model/TaskCreationModel.php new file mode 100644 index 00000000..3800f831 --- /dev/null +++ b/app/Model/TaskCreationModel.php @@ -0,0 +1,103 @@ +projectModel->exists($values['project_id'])) { + return 0; + } + + $position = empty($values['position']) ? 0 : $values['position']; + + $this->prepare($values); + $task_id = $this->db->table(TaskModel::TABLE)->persist($values); + + if ($task_id !== false) { + if ($position > 0 && $values['position'] > 1) { + $this->taskPositionModel->movePosition($values['project_id'], $task_id, $values['column_id'], $position, $values['swimlane_id'], false); + } + + $this->fireEvents($task_id, $values); + } + + return (int) $task_id; + } + + /** + * Prepare data + * + * @access public + * @param array $values Form values + */ + public function prepare(array &$values) + { + $values = $this->dateParser->convert($values, array('date_due')); + $values = $this->dateParser->convert($values, array('date_started'), true); + + $this->helper->model->removeFields($values, array('another_task')); + $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->columnModel->getFirstColumnId($values['project_id']); + } + + if (empty($values['color_id'])) { + $values['color_id'] = $this->colorModel->getDefaultColor(); + } + + if (empty($values['title'])) { + $values['title'] = t('Untitled'); + } + + if ($this->userSession->isLogged()) { + $values['creator_id'] = $this->userSession->getId(); + } + + $values['swimlane_id'] = empty($values['swimlane_id']) ? 0 : $values['swimlane_id']; + $values['date_creation'] = time(); + $values['date_modification'] = $values['date_creation']; + $values['date_moved'] = $values['date_creation']; + $values['position'] = $this->taskFinderModel->countByColumnAndSwimlaneId($values['project_id'], $values['column_id'], $values['swimlane_id']) + 1; + } + + /** + * Fire events + * + * @access private + * @param integer $task_id Task id + * @param array $values Form values + */ + private function fireEvents($task_id, array $values) + { + $event = new TaskEvent(array('task_id' => $task_id) + $values); + + $this->logger->debug('Event fired: '.TaskModel::EVENT_CREATE_UPDATE); + $this->logger->debug('Event fired: '.TaskModel::EVENT_CREATE); + + $this->dispatcher->dispatch(TaskModel::EVENT_CREATE_UPDATE, $event); + $this->dispatcher->dispatch(TaskModel::EVENT_CREATE, $event); + + if (! empty($values['description'])) { + $this->userMentionModel->fireEvents($values['description'], TaskModel::EVENT_USER_MENTION, $event); + } + } +} diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php deleted file mode 100644 index 56457a01..00000000 --- a/app/Model/TaskDuplication.php +++ /dev/null @@ -1,270 +0,0 @@ -save($task_id, $this->copyFields($task_id)); - } - - /** - * Duplicate recurring task - * - * @access public - * @param integer $task_id Task id - * @return boolean|integer Recurrence task id - */ - public function duplicateRecurringTask($task_id) - { - $values = $this->copyFields($task_id); - - if ($values['recurrence_status'] == Task::RECURRING_STATUS_PENDING) { - $values['recurrence_parent'] = $task_id; - $values['column_id'] = $this->column->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) - ->eq('id', $task_id) - ->update(array( - 'recurrence_status' => Task::RECURRING_STATUS_PROCESSED, - 'recurrence_child' => $recurring_task_id, - )); - - if ($parent_update) { - return $recurring_task_id; - } - } - } - - return false; - } - - /** - * Duplicate a task to another project - * - * @access public - * @param integer $task_id - * @param integer $project_id - * @param integer $swimlane_id - * @param integer $column_id - * @param integer $category_id - * @param integer $owner_id - * @return boolean|integer - */ - public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) - { - $values = $this->copyFields($task_id); - $values['project_id'] = $project_id; - $values['column_id'] = $column_id !== null ? $column_id : $values['column_id']; - $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id']; - $values['category_id'] = $category_id !== null ? $category_id : $values['category_id']; - $values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id']; - - $this->checkDestinationProjectValues($values); - - return $this->save($task_id, $values); - } - - /** - * Move a task to another project - * - * @access public - * @param integer $task_id - * @param integer $project_id - * @param integer $swimlane_id - * @param integer $column_id - * @param integer $category_id - * @param integer $owner_id - * @return boolean - */ - 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); - - $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['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)) { - $this->container['dispatcher']->dispatch( - Task::EVENT_MOVE_PROJECT, - new TaskEvent(array_merge($task, $values, array('task_id' => $task['id']))) - ); - } - - return true; - } - - /** - * Check if the assignee and the category are available in the destination project - * - * @access public - * @param array $values - * @return array - */ - 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'])) { - $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['project_id'], - $this->category->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['project_id'], - $this->swimlane->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['project_id'], - $this->column->getColumnTitleById($values['column_id']) - ); - - $values['column_id'] = $values['column_id'] ?: $this->column->getFirstColumnId($values['project_id']); - } - - return $values; - } - - /** - * Calculate new due date for new recurrence task - * - * @access public - * @param array $values Task fields - */ - public function calculateRecurringTaskDueDate(array &$values) - { - if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { - if ($values['recurrence_basedate'] == Task::RECURRING_BASEDATE_TRIGGERDATE) { - $values['date_due'] = time(); - } - - $factor = abs($values['recurrence_factor']); - $subtract = $values['recurrence_factor'] < 0; - - switch ($values['recurrence_timeframe']) { - case Task::RECURRING_TIMEFRAME_MONTHS: - $interval = 'P' . $factor . 'M'; - break; - case Task::RECURRING_TIMEFRAME_YEARS: - $interval = 'P' . $factor . 'Y'; - break; - default: - $interval = 'P' . $factor . 'D'; - } - - $date_due = new DateTime(); - $date_due->setTimestamp($values['date_due']); - - $subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval)); - - $values['date_due'] = $date_due->getTimestamp(); - } - } - - /** - * Duplicate fields for the new task - * - * @access private - * @param integer $task_id Task id - * @return array - */ - private function copyFields($task_id) - { - $task = $this->taskFinder->getById($task_id); - $values = array(); - - foreach ($this->fields_to_duplicate as $field) { - $values[$field] = $task[$field]; - } - - return $values; - } - - /** - * Create the new task and duplicate subtasks - * - * @access private - * @param integer $task_id Task id - * @param array $values Form values - * @return boolean|integer - */ - private function save($task_id, array $values) - { - $new_task_id = $this->taskCreation->create($values); - - if ($new_task_id) { - $this->subtask->duplicate($task_id, $new_task_id); - } - - return $new_task_id; - } -} diff --git a/app/Model/TaskDuplicationModel.php b/app/Model/TaskDuplicationModel.php new file mode 100644 index 00000000..9a4613e2 --- /dev/null +++ b/app/Model/TaskDuplicationModel.php @@ -0,0 +1,270 @@ +save($task_id, $this->copyFields($task_id)); + } + + /** + * Duplicate recurring task + * + * @access public + * @param integer $task_id Task id + * @return boolean|integer Recurrence task id + */ + public function duplicateRecurringTask($task_id) + { + $values = $this->copyFields($task_id); + + if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { + $values['recurrence_parent'] = $task_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(TaskModel::TABLE) + ->eq('id', $task_id) + ->update(array( + 'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED, + 'recurrence_child' => $recurring_task_id, + )); + + if ($parent_update) { + return $recurring_task_id; + } + } + } + + return false; + } + + /** + * Duplicate a task to another project + * + * @access public + * @param integer $task_id + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $column_id + * @param integer $category_id + * @param integer $owner_id + * @return boolean|integer + */ + public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + $values = $this->copyFields($task_id); + $values['project_id'] = $project_id; + $values['column_id'] = $column_id !== null ? $column_id : $values['column_id']; + $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id']; + $values['category_id'] = $category_id !== null ? $category_id : $values['category_id']; + $values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id']; + + $this->checkDestinationProjectValues($values); + + return $this->save($task_id, $values); + } + + /** + * Move a task to another project + * + * @access public + * @param integer $task_id + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $column_id + * @param integer $category_id + * @param integer $owner_id + * @return boolean + */ + public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + $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->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(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) { + $this->container['dispatcher']->dispatch( + TaskModel::EVENT_MOVE_PROJECT, + new TaskEvent(array_merge($task, $values, array('task_id' => $task['id']))) + ); + } + + return true; + } + + /** + * Check if the assignee and the category are available in the destination project + * + * @access public + * @param array $values + * @return array + */ + public function checkDestinationProjectValues(array &$values) + { + // Check if the assigned user is allowed for the destination project + 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->categoryModel->getIdByName( + $values['project_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->swimlaneModel->getIdByName( + $values['project_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->columnModel->getColumnIdByTitle( + $values['project_id'], + $this->columnModel->getColumnTitleById($values['column_id']) + ); + + $values['column_id'] = $values['column_id'] ?: $this->columnModel->getFirstColumnId($values['project_id']); + } + + return $values; + } + + /** + * Calculate new due date for new recurrence task + * + * @access public + * @param array $values Task fields + */ + public function calculateRecurringTaskDueDate(array &$values) + { + if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { + if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) { + $values['date_due'] = time(); + } + + $factor = abs($values['recurrence_factor']); + $subtract = $values['recurrence_factor'] < 0; + + switch ($values['recurrence_timeframe']) { + case TaskModel::RECURRING_TIMEFRAME_MONTHS: + $interval = 'P' . $factor . 'M'; + break; + case TaskModel::RECURRING_TIMEFRAME_YEARS: + $interval = 'P' . $factor . 'Y'; + break; + default: + $interval = 'P' . $factor . 'D'; + } + + $date_due = new DateTime(); + $date_due->setTimestamp($values['date_due']); + + $subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval)); + + $values['date_due'] = $date_due->getTimestamp(); + } + } + + /** + * Duplicate fields for the new task + * + * @access private + * @param integer $task_id Task id + * @return array + */ + private function copyFields($task_id) + { + $task = $this->taskFinderModel->getById($task_id); + $values = array(); + + foreach ($this->fields_to_duplicate as $field) { + $values[$field] = $task[$field]; + } + + return $values; + } + + /** + * Create the new task and duplicate subtasks + * + * @access private + * @param integer $task_id Task id + * @param array $values Form values + * @return boolean|integer + */ + private function save($task_id, array $values) + { + $new_task_id = $this->taskCreationModel->create($values); + + if ($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/TaskExternalLink.php deleted file mode 100644 index f77a72bf..00000000 --- a/app/Model/TaskExternalLink.php +++ /dev/null @@ -1,101 +0,0 @@ -externalLinkManager->getTypes(); - - $links = $this->db->table(self::TABLE) - ->columns(self::TABLE.'.*', User::TABLE.'.name AS creator_name', User::TABLE.'.username AS creator_username') - ->eq('task_id', $task_id) - ->asc('title') - ->join(User::TABLE, 'id', 'creator_id') - ->findAll(); - - foreach ($links as &$link) { - $link['dependency_label'] = $this->externalLinkManager->getDependencyLabel($link['link_type'], $link['dependency']); - $link['type'] = isset($types[$link['link_type']]) ? $types[$link['link_type']] : t('Unknown'); - } - - return $links; - } - - /** - * Get link - * - * @access public - * @param integer $link_id - * @return array - */ - public function getById($link_id) - { - return $this->db->table(self::TABLE)->eq('id', $link_id)->findOne(); - } - - /** - * Add a new link in the database - * - * @access public - * @param array $values Form values - * @return boolean|integer - */ - public function create(array $values) - { - unset($values['id']); - $values['creator_id'] = $this->userSession->getId(); - $values['date_creation'] = time(); - $values['date_modification'] = $values['date_creation']; - - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Modify external link - * - * @access public - * @param array $values Form values - * @return boolean - */ - public function update(array $values) - { - $values['date_modification'] = time(); - return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); - } - - /** - * Remove a link - * - * @access public - * @param integer $link_id - * @return boolean - */ - public function remove($link_id) - { - return $this->db->table(self::TABLE)->eq('id', $link_id)->remove(); - } -} diff --git a/app/Model/TaskExternalLinkModel.php b/app/Model/TaskExternalLinkModel.php new file mode 100644 index 00000000..220b9c6f --- /dev/null +++ b/app/Model/TaskExternalLinkModel.php @@ -0,0 +1,101 @@ +externalLinkManager->getTypes(); + + $links = $this->db->table(self::TABLE) + ->columns(self::TABLE.'.*', UserModel::TABLE.'.name AS creator_name', UserModel::TABLE.'.username AS creator_username') + ->eq('task_id', $task_id) + ->asc('title') + ->join(UserModel::TABLE, 'id', 'creator_id') + ->findAll(); + + foreach ($links as &$link) { + $link['dependency_label'] = $this->externalLinkManager->getDependencyLabel($link['link_type'], $link['dependency']); + $link['type'] = isset($types[$link['link_type']]) ? $types[$link['link_type']] : t('Unknown'); + } + + return $links; + } + + /** + * Get link + * + * @access public + * @param integer $link_id + * @return array + */ + public function getById($link_id) + { + return $this->db->table(self::TABLE)->eq('id', $link_id)->findOne(); + } + + /** + * Add a new link in the database + * + * @access public + * @param array $values Form values + * @return boolean|integer + */ + public function create(array $values) + { + unset($values['id']); + $values['creator_id'] = $this->userSession->getId(); + $values['date_creation'] = time(); + $values['date_modification'] = $values['date_creation']; + + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Modify external link + * + * @access public + * @param array $values Form values + * @return boolean + */ + public function update(array $values) + { + $values['date_modification'] = time(); + return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); + } + + /** + * Remove a link + * + * @access public + * @param integer $link_id + * @return boolean + */ + public function remove($link_id) + { + return $this->db->table(self::TABLE)->eq('id', $link_id)->remove(); + } +} 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 @@ -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..21d319b0 --- /dev/null +++ b/app/Model/TaskFileModel.php @@ -0,0 +1,54 @@ +helper->dt->datetime(time())).'.png'; + return $this->uploadContent($task_id, $original_filename, $blob); + } +} diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php deleted file mode 100644 index fed3a580..00000000 --- a/app/Model/TaskFinder.php +++ /dev/null @@ -1,476 +0,0 @@ -db - ->table(Task::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' - ) - ->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); - } - - /** - * Get query for assigned user tasks - * - * @access public - * @param integer $user_id User id - * @return \PicoDb\Table - */ - public function getUserQuery($user_id) - { - return $this->db - ->table(Task::TABLE) - ->columns( - 'tasks.id', - 'tasks.title', - 'tasks.date_due', - 'tasks.date_creation', - 'tasks.project_id', - 'tasks.color_id', - 'tasks.priority', - 'tasks.time_spent', - 'tasks.time_estimated', - 'tasks.is_active', - 'tasks.creator_id', - '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); - } - - /** - * Extended query - * - * @access public - * @return \PicoDb\Table - */ - public function getExtendedQuery() - { - return $this->db - ->table(Task::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', - 'tasks.id', - 'tasks.reference', - 'tasks.title', - 'tasks.description', - 'tasks.date_creation', - 'tasks.date_modification', - 'tasks.date_completed', - 'tasks.date_started', - 'tasks.date_due', - 'tasks.color_id', - 'tasks.project_id', - 'tasks.column_id', - 'tasks.swimlane_id', - 'tasks.owner_id', - 'tasks.creator_id', - 'tasks.position', - 'tasks.is_active', - 'tasks.score', - 'tasks.category_id', - 'tasks.priority', - 'tasks.date_moved', - 'tasks.recurrence_status', - 'tasks.recurrence_trigger', - 'tasks.recurrence_factor', - 'tasks.recurrence_timeframe', - 'tasks.recurrence_basedate', - 'tasks.recurrence_parent', - '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' - ) - ->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); - } - - /** - * Get all tasks shown on the board (sorted by position) - * - * @access public - * @param integer $project_id Project id - * @param integer $column_id Column id - * @param integer $swimlane_id Swimlane id - * @return array - */ - 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') - ->findAll(); - } - - /** - * Get all tasks for a given project and status - * - * @access public - * @param integer $project_id Project id - * @param integer $status_id Status id - * @return array - */ - public function getAll($project_id, $status_id = Task::STATUS_OPEN) - { - return $this->db - ->table(Task::TABLE) - ->eq(Task::TABLE.'.project_id', $project_id) - ->eq(Task::TABLE.'.is_active', $status_id) - ->findAll(); - } - - /** - * Get all tasks for a given project and status - * - * @access public - * @param integer $project_id - * @param array $status - * @return array - */ - public function getAllIds($project_id, array $status = array(Task::STATUS_OPEN)) - { - return $this->db - ->table(Task::TABLE) - ->eq(Task::TABLE.'.project_id', $project_id) - ->in(Task::TABLE.'.is_active', $status) - ->findAllByColumn('id'); - } - - /** - * Get overdue tasks query - * - * @access public - * @return \PicoDb\Table - */ - public function getOverdueTasksQuery() - { - return $this->db->table(Task::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' - ) - ->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)); - } - - /** - * Get a list of overdue tasks for all projects - * - * @access public - * @return array - */ - public function getOverdueTasks() - { - return $this->getOverdueTasksQuery()->findAll(); - } - - /** - * Get a list of overdue tasks by project - * - * @access public - * @param integer $project_id - * @return array - */ - public function getOverdueTasksByProject($project_id) - { - return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.project_id', $project_id)->findAll(); - } - - /** - * Get a list of overdue tasks by user - * - * @access public - * @param integer $user_id - * @return array - */ - public function getOverdueTasksByUser($user_id) - { - return $this->getOverdueTasksQuery()->eq(Task::TABLE.'.owner_id', $user_id)->findAll(); - } - - /** - * Get project id for a given task - * - * @access public - * @param integer $task_id Task id - * @return integer - */ - public function getProjectId($task_id) - { - return (int) $this->db->table(Task::TABLE)->eq('id', $task_id)->findOneColumn('project_id') ?: 0; - } - - /** - * Fetch a task by the id - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getById($task_id) - { - return $this->db->table(Task::TABLE)->eq('id', $task_id)->findOne(); - } - - /** - * Fetch a task by the reference (external id) - * - * @access public - * @param integer $project_id Project id - * @param string $reference Task reference - * @return array - */ - public function getByReference($project_id, $reference) - { - return $this->db->table(Task::TABLE)->eq('project_id', $project_id)->eq('reference', $reference)->findOne(); - } - - /** - * Get task details (fetch more information from other tables) - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getDetails($task_id) - { - $sql = ' - SELECT - tasks.id, - tasks.reference, - tasks.title, - tasks.description, - tasks.date_creation, - tasks.date_completed, - tasks.date_modification, - tasks.date_due, - tasks.date_started, - tasks.time_estimated, - tasks.time_spent, - tasks.color_id, - tasks.project_id, - tasks.column_id, - tasks.owner_id, - tasks.creator_id, - tasks.position, - tasks.is_active, - tasks.score, - tasks.category_id, - tasks.priority, - tasks.swimlane_id, - tasks.date_moved, - tasks.recurrence_status, - tasks.recurrence_trigger, - tasks.recurrence_factor, - tasks.recurrence_timeframe, - tasks.recurrence_basedate, - tasks.recurrence_parent, - tasks.recurrence_child, - project_has_categories.name AS category_name, - swimlanes.name AS swimlane_name, - projects.name AS project_name, - projects.default_swimlane, - columns.title AS column_title, - users.username AS assignee_username, - users.name AS assignee_name, - creators.username AS creator_username, - creators.name AS creator_name - FROM tasks - LEFT JOIN users ON users.id = tasks.owner_id - LEFT JOIN users AS creators ON creators.id = tasks.creator_id - LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id - LEFT JOIN projects ON projects.id = tasks.project_id - LEFT JOIN columns ON columns.id = tasks.column_id - LEFT JOIN swimlanes ON swimlanes.id = tasks.swimlane_id - WHERE tasks.id = ? - '; - - $rq = $this->db->execute($sql, array($task_id)); - return $rq->fetch(PDO::FETCH_ASSOC); - } - - /** - * Get iCal query - * - * @access public - * @return \PicoDb\Table - */ - 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') - ->columns( - Task::TABLE.'.*', - 'ua.email AS assignee_email', - 'ua.name AS assignee_name', - 'ua.username AS assignee_username', - 'uc.email AS creator_email', - 'uc.username AS creator_username' - ); - } - - /** - * Count all tasks for a given project and status - * - * @access public - * @param integer $project_id Project id - * @param array $status List of status id - * @return integer - */ - public function countByProjectId($project_id, array $status = array(Task::STATUS_OPEN, Task::STATUS_CLOSED)) - { - return $this->db - ->table(Task::TABLE) - ->eq('project_id', $project_id) - ->in('is_active', $status) - ->count(); - } - - /** - * Count the number of tasks for a given column and status - * - * @access public - * @param integer $project_id Project id - * @param integer $column_id Column id - * @return integer - */ - public function countByColumnId($project_id, $column_id) - { - return $this->db - ->table(Task::TABLE) - ->eq('project_id', $project_id) - ->eq('column_id', $column_id) - ->eq('is_active', 1) - ->count(); - } - - /** - * Count the number of tasks for a given column and swimlane - * - * @access public - * @param integer $project_id Project id - * @param integer $column_id Column id - * @param integer $swimlane_id Swimlane id - * @return integer - */ - public function countByColumnAndSwimlaneId($project_id, $column_id, $swimlane_id) - { - return $this->db - ->table(Task::TABLE) - ->eq('project_id', $project_id) - ->eq('column_id', $column_id) - ->eq('swimlane_id', $swimlane_id) - ->eq('is_active', 1) - ->count(); - } - - /** - * Return true if the task exists - * - * @access public - * @param integer $task_id Task id - * @return boolean - */ - public function exists($task_id) - { - return $this->db->table(Task::TABLE)->eq('id', $task_id)->exists(); - } - - /** - * Get project token - * - * @access public - * @param integer $task_id - * @return string - */ - 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'); - } -} diff --git a/app/Model/TaskFinderModel.php b/app/Model/TaskFinderModel.php new file mode 100644 index 00000000..8b636e28 --- /dev/null +++ b/app/Model/TaskFinderModel.php @@ -0,0 +1,476 @@ +db + ->table(TaskModel::TABLE) + ->columns( + 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(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); + } + + /** + * Get query for assigned user tasks + * + * @access public + * @param integer $user_id User id + * @return \PicoDb\Table + */ + public function getUserQuery($user_id) + { + return $this->db + ->table(TaskModel::TABLE) + ->columns( + 'tasks.id', + 'tasks.title', + 'tasks.date_due', + 'tasks.date_creation', + 'tasks.project_id', + 'tasks.color_id', + 'tasks.priority', + 'tasks.time_spent', + 'tasks.time_estimated', + 'tasks.is_active', + 'tasks.creator_id', + 'projects.name AS project_name', + 'columns.title AS column_title' + ) + ->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); + } + + /** + * Extended query + * + * @access public + * @return \PicoDb\Table + */ + public function getExtendedQuery() + { + return $this->db + ->table(TaskModel::TABLE) + ->columns( + '(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', + 'tasks.description', + 'tasks.date_creation', + 'tasks.date_modification', + 'tasks.date_completed', + 'tasks.date_started', + 'tasks.date_due', + 'tasks.color_id', + 'tasks.project_id', + 'tasks.column_id', + 'tasks.swimlane_id', + 'tasks.owner_id', + 'tasks.creator_id', + 'tasks.position', + 'tasks.is_active', + 'tasks.score', + 'tasks.category_id', + 'tasks.priority', + 'tasks.date_moved', + 'tasks.recurrence_status', + 'tasks.recurrence_trigger', + 'tasks.recurrence_factor', + 'tasks.recurrence_timeframe', + 'tasks.recurrence_basedate', + 'tasks.recurrence_parent', + 'tasks.recurrence_child', + 'tasks.time_estimated', + 'tasks.time_spent', + 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(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); + } + + /** + * Get all tasks shown on the board (sorted by position) + * + * @access public + * @param integer $project_id Project id + * @param integer $column_id Column id + * @param integer $swimlane_id Swimlane id + * @return array + */ + public function getTasksByColumnAndSwimlane($project_id, $column_id, $swimlane_id = 0) + { + return $this->getExtendedQuery() + ->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(); + } + + /** + * Get all tasks for a given project and status + * + * @access public + * @param integer $project_id Project id + * @param integer $status_id Status id + * @return array + */ + public function getAll($project_id, $status_id = TaskModel::STATUS_OPEN) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq(TaskModel::TABLE.'.project_id', $project_id) + ->eq(TaskModel::TABLE.'.is_active', $status_id) + ->findAll(); + } + + /** + * Get all tasks for a given project and status + * + * @access public + * @param integer $project_id + * @param array $status + * @return array + */ + public function getAllIds($project_id, array $status = array(TaskModel::STATUS_OPEN)) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq(TaskModel::TABLE.'.project_id', $project_id) + ->in(TaskModel::TABLE.'.is_active', $status) + ->findAllByColumn('id'); + } + + /** + * Get overdue tasks query + * + * @access public + * @return \PicoDb\Table + */ + public function getOverdueTasksQuery() + { + return $this->db->table(TaskModel::TABLE) + ->columns( + 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(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)); + } + + /** + * Get a list of overdue tasks for all projects + * + * @access public + * @return array + */ + public function getOverdueTasks() + { + return $this->getOverdueTasksQuery()->findAll(); + } + + /** + * Get a list of overdue tasks by project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getOverdueTasksByProject($project_id) + { + return $this->getOverdueTasksQuery()->eq(TaskModel::TABLE.'.project_id', $project_id)->findAll(); + } + + /** + * Get a list of overdue tasks by user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getOverdueTasksByUser($user_id) + { + return $this->getOverdueTasksQuery()->eq(TaskModel::TABLE.'.owner_id', $user_id)->findAll(); + } + + /** + * Get project id for a given task + * + * @access public + * @param integer $task_id Task id + * @return integer + */ + public function getProjectId($task_id) + { + return (int) $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOneColumn('project_id') ?: 0; + } + + /** + * Fetch a task by the id + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getById($task_id) + { + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOne(); + } + + /** + * Fetch a task by the reference (external id) + * + * @access public + * @param integer $project_id Project id + * @param string $reference Task reference + * @return array + */ + public function getByReference($project_id, $reference) + { + return $this->db->table(TaskModel::TABLE)->eq('project_id', $project_id)->eq('reference', $reference)->findOne(); + } + + /** + * Get task details (fetch more information from other tables) + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getDetails($task_id) + { + $sql = ' + SELECT + tasks.id, + tasks.reference, + tasks.title, + tasks.description, + tasks.date_creation, + tasks.date_completed, + tasks.date_modification, + tasks.date_due, + tasks.date_started, + tasks.time_estimated, + tasks.time_spent, + tasks.color_id, + tasks.project_id, + tasks.column_id, + tasks.owner_id, + tasks.creator_id, + tasks.position, + tasks.is_active, + tasks.score, + tasks.category_id, + tasks.priority, + tasks.swimlane_id, + tasks.date_moved, + tasks.recurrence_status, + tasks.recurrence_trigger, + tasks.recurrence_factor, + tasks.recurrence_timeframe, + tasks.recurrence_basedate, + tasks.recurrence_parent, + tasks.recurrence_child, + project_has_categories.name AS category_name, + swimlanes.name AS swimlane_name, + projects.name AS project_name, + projects.default_swimlane, + columns.title AS column_title, + users.username AS assignee_username, + users.name AS assignee_name, + creators.username AS creator_username, + creators.name AS creator_name + FROM tasks + LEFT JOIN users ON users.id = tasks.owner_id + LEFT JOIN users AS creators ON creators.id = tasks.creator_id + LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id + LEFT JOIN projects ON projects.id = tasks.project_id + LEFT JOIN columns ON columns.id = tasks.column_id + LEFT JOIN swimlanes ON swimlanes.id = tasks.swimlane_id + WHERE tasks.id = ? + '; + + $rq = $this->db->execute($sql, array($task_id)); + return $rq->fetch(PDO::FETCH_ASSOC); + } + + /** + * Get iCal query + * + * @access public + * @return \PicoDb\Table + */ + public function getICalQuery() + { + 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( + TaskModel::TABLE.'.*', + 'ua.email AS assignee_email', + 'ua.name AS assignee_name', + 'ua.username AS assignee_username', + 'uc.email AS creator_email', + 'uc.username AS creator_username' + ); + } + + /** + * Count all tasks for a given project and status + * + * @access public + * @param integer $project_id Project id + * @param array $status List of status id + * @return integer + */ + public function countByProjectId($project_id, array $status = array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq('project_id', $project_id) + ->in('is_active', $status) + ->count(); + } + + /** + * Count the number of tasks for a given column and status + * + * @access public + * @param integer $project_id Project id + * @param integer $column_id Column id + * @return integer + */ + public function countByColumnId($project_id, $column_id) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq('project_id', $project_id) + ->eq('column_id', $column_id) + ->eq('is_active', 1) + ->count(); + } + + /** + * Count the number of tasks for a given column and swimlane + * + * @access public + * @param integer $project_id Project id + * @param integer $column_id Column id + * @param integer $swimlane_id Swimlane id + * @return integer + */ + public function countByColumnAndSwimlaneId($project_id, $column_id, $swimlane_id) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq('project_id', $project_id) + ->eq('column_id', $column_id) + ->eq('swimlane_id', $swimlane_id) + ->eq('is_active', 1) + ->count(); + } + + /** + * Return true if the task exists + * + * @access public + * @param integer $task_id Task id + * @return boolean + */ + public function exists($task_id) + { + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->exists(); + } + + /** + * Get project token + * + * @access public + * @param integer $task_id + * @return string + */ + public function getProjectToken($task_id) + { + return $this->db + ->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/TaskLink.php deleted file mode 100644 index 9c5b3ca3..00000000 --- a/app/Model/TaskLink.php +++ /dev/null @@ -1,265 +0,0 @@ -db->table(self::TABLE)->eq('id', $task_link_id)->findOne(); - } - - /** - * Get the opposite task link (use the unique index task_has_links_unique) - * - * @access public - * @param array $task_link - * @return array - */ - public function getOppositeTaskLink(array $task_link) - { - $opposite_link_id = $this->link->getOppositeLinkId($task_link['link_id']); - - return $this->db->table(self::TABLE) - ->eq('opposite_task_id', $task_link['task_id']) - ->eq('task_id', $task_link['opposite_task_id']) - ->eq('link_id', $opposite_link_id) - ->findOne(); - } - - /** - * Get all links attached to a task - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getAll($task_id) - { - return $this->db - ->table(self::TABLE) - ->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' - ) - ->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') - ->findAll(); - } - - /** - * Get all links attached to a task grouped by label - * - * @access public - * @param integer $task_id Task id - * @return array - */ - public function getAllGroupedByLabel($task_id) - { - $links = $this->getAll($task_id); - $result = array(); - - foreach ($links as $link) { - if (! isset($result[$link['label']])) { - $result[$link['label']] = array(); - } - - $result[$link['label']][] = $link; - } - - return $result; - } - - /** - * Publish events - * - * @access private - * @param array $events - */ - private function fireEvents(array $events) - { - foreach ($events as $event) { - $event['project_id'] = $this->taskFinder->getProjectId($event['task_id']); - $this->container['dispatcher']->dispatch(self::EVENT_CREATE_UPDATE, new TaskLinkEvent($event)); - } - } - - /** - * Create a new link - * - * @access public - * @param integer $task_id Task id - * @param integer $opposite_task_id Opposite task id - * @param integer $link_id Link id - * @return integer Task link id - */ - public function create($task_id, $opposite_task_id, $link_id) - { - $events = array(); - $this->db->startTransaction(); - - // Get opposite link - $opposite_link_id = $this->link->getOppositeLinkId($link_id); - - $values = array( - 'task_id' => $task_id, - 'opposite_task_id' => $opposite_task_id, - 'link_id' => $link_id, - ); - - // Create the original task link - $this->db->table(self::TABLE)->insert($values); - $task_link_id = $this->db->getLastId(); - $events[] = $values; - - // Create the opposite task link - $values = array( - 'task_id' => $opposite_task_id, - 'opposite_task_id' => $task_id, - 'link_id' => $opposite_link_id, - ); - - $this->db->table(self::TABLE)->insert($values); - $events[] = $values; - - $this->db->closeTransaction(); - - $this->fireEvents($events); - - return (int) $task_link_id; - } - - /** - * Update a task link - * - * @access public - * @param integer $task_link_id Task link id - * @param integer $task_id Task id - * @param integer $opposite_task_id Opposite task id - * @param integer $link_id Link id - * @return boolean - */ - public function update($task_link_id, $task_id, $opposite_task_id, $link_id) - { - $events = array(); - $this->db->startTransaction(); - - // Get original task link - $task_link = $this->getById($task_link_id); - - // Find opposite task link - $opposite_task_link = $this->getOppositeTaskLink($task_link); - - // Get opposite link - $opposite_link_id = $this->link->getOppositeLinkId($link_id); - - // Update the original task link - $values = array( - 'task_id' => $task_id, - 'opposite_task_id' => $opposite_task_id, - 'link_id' => $link_id, - ); - - $rs1 = $this->db->table(self::TABLE)->eq('id', $task_link_id)->update($values); - $events[] = $values; - - // Update the opposite link - $values = array( - 'task_id' => $opposite_task_id, - 'opposite_task_id' => $task_id, - 'link_id' => $opposite_link_id, - ); - - $rs2 = $this->db->table(self::TABLE)->eq('id', $opposite_task_link['id'])->update($values); - $events[] = $values; - - $this->db->closeTransaction(); - - if ($rs1 && $rs2) { - $this->fireEvents($events); - return true; - } - - return false; - } - - /** - * Remove a link between two tasks - * - * @access public - * @param integer $task_link_id - * @return boolean - */ - public function remove($task_link_id) - { - $this->db->startTransaction(); - - $link = $this->getById($task_link_id); - $link_id = $this->link->getOppositeLinkId($link['link_id']); - - $this->db->table(self::TABLE)->eq('id', $task_link_id)->remove(); - - $this->db - ->table(self::TABLE) - ->eq('opposite_task_id', $link['task_id']) - ->eq('task_id', $link['opposite_task_id']) - ->eq('link_id', $link_id)->remove(); - - $this->db->closeTransaction(); - - return true; - } -} diff --git a/app/Model/TaskLinkModel.php b/app/Model/TaskLinkModel.php new file mode 100644 index 00000000..45225e35 --- /dev/null +++ b/app/Model/TaskLinkModel.php @@ -0,0 +1,265 @@ +db->table(self::TABLE)->eq('id', $task_link_id)->findOne(); + } + + /** + * Get the opposite task link (use the unique index task_has_links_unique) + * + * @access public + * @param array $task_link + * @return array + */ + public function getOppositeTaskLink(array $task_link) + { + $opposite_link_id = $this->linkModel->getOppositeLinkId($task_link['link_id']); + + return $this->db->table(self::TABLE) + ->eq('opposite_task_id', $task_link['task_id']) + ->eq('task_id', $task_link['opposite_task_id']) + ->eq('link_id', $opposite_link_id) + ->findOne(); + } + + /** + * Get all links attached to a task + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAll($task_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.opposite_task_id AS task_id', + 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(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(); + } + + /** + * Get all links attached to a task grouped by label + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAllGroupedByLabel($task_id) + { + $links = $this->getAll($task_id); + $result = array(); + + foreach ($links as $link) { + if (! isset($result[$link['label']])) { + $result[$link['label']] = array(); + } + + $result[$link['label']][] = $link; + } + + return $result; + } + + /** + * Publish events + * + * @access private + * @param array $events + */ + private function fireEvents(array $events) + { + foreach ($events as $event) { + $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']); + $this->container['dispatcher']->dispatch(self::EVENT_CREATE_UPDATE, new TaskLinkEvent($event)); + } + } + + /** + * Create a new link + * + * @access public + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return integer Task link id + */ + public function create($task_id, $opposite_task_id, $link_id) + { + $events = array(); + $this->db->startTransaction(); + + // Get opposite link + $opposite_link_id = $this->linkModel->getOppositeLinkId($link_id); + + $values = array( + 'task_id' => $task_id, + 'opposite_task_id' => $opposite_task_id, + 'link_id' => $link_id, + ); + + // Create the original task link + $this->db->table(self::TABLE)->insert($values); + $task_link_id = $this->db->getLastId(); + $events[] = $values; + + // Create the opposite task link + $values = array( + 'task_id' => $opposite_task_id, + 'opposite_task_id' => $task_id, + 'link_id' => $opposite_link_id, + ); + + $this->db->table(self::TABLE)->insert($values); + $events[] = $values; + + $this->db->closeTransaction(); + + $this->fireEvents($events); + + return (int) $task_link_id; + } + + /** + * Update a task link + * + * @access public + * @param integer $task_link_id Task link id + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return boolean + */ + public function update($task_link_id, $task_id, $opposite_task_id, $link_id) + { + $events = array(); + $this->db->startTransaction(); + + // Get original task link + $task_link = $this->getById($task_link_id); + + // Find opposite task link + $opposite_task_link = $this->getOppositeTaskLink($task_link); + + // Get opposite link + $opposite_link_id = $this->linkModel->getOppositeLinkId($link_id); + + // Update the original task link + $values = array( + 'task_id' => $task_id, + 'opposite_task_id' => $opposite_task_id, + 'link_id' => $link_id, + ); + + $rs1 = $this->db->table(self::TABLE)->eq('id', $task_link_id)->update($values); + $events[] = $values; + + // Update the opposite link + $values = array( + 'task_id' => $opposite_task_id, + 'opposite_task_id' => $task_id, + 'link_id' => $opposite_link_id, + ); + + $rs2 = $this->db->table(self::TABLE)->eq('id', $opposite_task_link['id'])->update($values); + $events[] = $values; + + $this->db->closeTransaction(); + + if ($rs1 && $rs2) { + $this->fireEvents($events); + return true; + } + + return false; + } + + /** + * Remove a link between two tasks + * + * @access public + * @param integer $task_link_id + * @return boolean + */ + public function remove($task_link_id) + { + $this->db->startTransaction(); + + $link = $this->getById($task_link_id); + $link_id = $this->linkModel->getOppositeLinkId($link['link_id']); + + $this->db->table(self::TABLE)->eq('id', $task_link_id)->remove(); + + $this->db + ->table(self::TABLE) + ->eq('opposite_task_id', $link['task_id']) + ->eq('task_id', $link['opposite_task_id']) + ->eq('link_id', $link_id)->remove(); + + $this->db->closeTransaction(); + + return true; + } +} diff --git a/app/Model/TaskMetadata.php b/app/Model/TaskMetadata.php deleted file mode 100644 index d9d024bf..00000000 --- a/app/Model/TaskMetadata.php +++ /dev/null @@ -1,35 +0,0 @@ -taskFinderModel->exists($task_id)) { + return false; + } + + $this->taskFileModel->removeAll($task_id); + + return $this->db->table(self::TABLE)->eq('id', $task_id)->remove(); + } + + /** + * Get a the task id from a text + * + * Example: "Fix bug #1234" will return 1234 + * + * @access public + * @param string $message Text + * @return integer + */ + public function getTaskIdFromText($message) + { + if (preg_match('!#(\d+)!i', $message, $matches) && isset($matches[1])) { + return $matches[1]; + } + + return 0; + } + + /** + * Return the list user selectable recurrence status + * + * @access public + * @return array + */ + public function getRecurrenceStatusList() + { + return array( + TaskModel::RECURRING_STATUS_NONE => t('No'), + TaskModel::RECURRING_STATUS_PENDING => t('Yes'), + ); + } + + /** + * Return the list recurrence triggers + * + * @access public + * @return array + */ + public function getRecurrenceTriggerList() + { + return array( + 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'), + ); + } + + /** + * Return the list options to calculate recurrence due date + * + * @access public + * @return array + */ + public function getRecurrenceBasedateList() + { + return array( + TaskModel::RECURRING_BASEDATE_DUEDATE => t('Existing due date'), + TaskModel::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'), + ); + } + + /** + * Return the list recurrence timeframes + * + * @access public + * @return array + */ + public function getRecurrenceTimeframeList() + { + return array( + TaskModel::RECURRING_TIMEFRAME_DAYS => t('Day(s)'), + TaskModel::RECURRING_TIMEFRAME_MONTHS => t('Month(s)'), + TaskModel::RECURRING_TIMEFRAME_YEARS => t('Year(s)'), + ); + } + + /** + * Get task progress based on the column position + * + * @access public + * @param array $task + * @param array $columns + * @return integer + */ + public function getProgress(array $task, array $columns) + { + if ($task['is_active'] == self::STATUS_CLOSED) { + return 100; + } + + $position = 0; + + foreach ($columns as $column_id => $column_title) { + if ($column_id == $task['column_id']) { + break; + } + + $position++; + } + + return round(($position * 100) / count($columns), 1); + } + + /** + * Helper method to duplicate all tasks to another project + * + * @access public + * @param integer $src_project_id + * @param integer $dst_project_id + * @return boolean + */ + public function duplicate($src_project_id, $dst_project_id) + { + $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); + + foreach ($task_ids as $task_id) { + if (! $this->taskDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { + return false; + } + } + + return true; + } +} diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php deleted file mode 100644 index 7e0ea8b2..00000000 --- a/app/Model/TaskModification.php +++ /dev/null @@ -1,97 +0,0 @@ -taskFinder->getById($values['id']); - - $this->prepare($values); - $result = $this->db->table(Task::TABLE)->eq('id', $original_task['id'])->update($values); - - if ($fire_events && $result) { - $this->fireEvents($original_task, $values); - } - - return $result; - } - - /** - * Fire events - * - * @access public - * @param array $task - * @param array $new_values - */ - public function fireEvents(array $task, array $new_values) - { - $events = array(); - $event_data = array_merge($task, $new_values, array('task_id' => $task['id'])); - - // Values changed - $event_data['changes'] = array_diff_assoc($new_values, $task); - unset($event_data['changes']['date_modification']); - - if ($this->isFieldModified('owner_id', $event_data['changes'])) { - $events[] = Task::EVENT_ASSIGNEE_CHANGE; - } elseif (! empty($event_data['changes'])) { - $events[] = Task::EVENT_CREATE_UPDATE; - $events[] = Task::EVENT_UPDATE; - } - - foreach ($events as $event) { - $this->logger->debug('Event fired: '.$event); - $this->dispatcher->dispatch($event, new TaskEvent($event_data)); - } - } - - /** - * Return true if the field is the only modified value - * - * @access public - * @param string $field - * @param array $changes - * @return boolean - */ - public function isFieldModified($field, array $changes) - { - return isset($changes[$field]) && count($changes) === 1; - } - - /** - * Prepare data before task modification - * - * @access public - * @param array $values Form values - */ - public function prepare(array &$values) - { - $values = $this->dateParser->convert($values, array('date_due')); - $values = $this->dateParser->convert($values, array('date_started'), true); - - $this->helper->model->removeFields($values, array('another_task', 'id')); - $this->helper->model->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); - $this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); - - $values['date_modification'] = time(); - } -} diff --git a/app/Model/TaskModificationModel.php b/app/Model/TaskModificationModel.php new file mode 100644 index 00000000..762af2c5 --- /dev/null +++ b/app/Model/TaskModificationModel.php @@ -0,0 +1,97 @@ +taskFinderModel->getById($values['id']); + + $this->prepare($values); + $result = $this->db->table(TaskModel::TABLE)->eq('id', $original_task['id'])->update($values); + + if ($fire_events && $result) { + $this->fireEvents($original_task, $values); + } + + return $result; + } + + /** + * Fire events + * + * @access public + * @param array $task + * @param array $new_values + */ + public function fireEvents(array $task, array $new_values) + { + $events = array(); + $event_data = array_merge($task, $new_values, array('task_id' => $task['id'])); + + // Values changed + $event_data['changes'] = array_diff_assoc($new_values, $task); + unset($event_data['changes']['date_modification']); + + if ($this->isFieldModified('owner_id', $event_data['changes'])) { + $events[] = TaskModel::EVENT_ASSIGNEE_CHANGE; + } elseif (! empty($event_data['changes'])) { + $events[] = TaskModel::EVENT_CREATE_UPDATE; + $events[] = TaskModel::EVENT_UPDATE; + } + + foreach ($events as $event) { + $this->logger->debug('Event fired: '.$event); + $this->dispatcher->dispatch($event, new TaskEvent($event_data)); + } + } + + /** + * Return true if the field is the only modified value + * + * @access public + * @param string $field + * @param array $changes + * @return boolean + */ + public function isFieldModified($field, array $changes) + { + return isset($changes[$field]) && count($changes) === 1; + } + + /** + * Prepare data before task modification + * + * @access public + * @param array $values Form values + */ + public function prepare(array &$values) + { + $values = $this->dateParser->convert($values, array('date_due')); + $values = $this->dateParser->convert($values, array('date_started'), true); + + $this->helper->model->removeFields($values, array('another_task', 'id')); + $this->helper->model->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent')); + $this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); + + $values['date_modification'] = time(); + } +} diff --git a/app/Model/TaskPosition.php b/app/Model/TaskPosition.php deleted file mode 100644 index 5b794795..00000000 --- a/app/Model/TaskPosition.php +++ /dev/null @@ -1,239 +0,0 @@ -= 1) - * @param integer $swimlane_id Swimlane id - * @param boolean $fire_events Fire events - * @return boolean - */ - public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true) - { - if ($position < 1) { - return false; - } - - $task = $this->taskFinder->getById($task_id); - - if ($task['is_active'] == Task::STATUS_CLOSED) { - return true; - } - - $result = false; - - if ($task['swimlane_id'] != $swimlane_id) { - $result = $this->saveSwimlaneChange($project_id, $task_id, $position, $task['column_id'], $column_id, $task['swimlane_id'], $swimlane_id); - } elseif ($task['column_id'] != $column_id) { - $result = $this->saveColumnChange($project_id, $task_id, $position, $swimlane_id, $task['column_id'], $column_id); - } elseif ($task['position'] != $position) { - $result = $this->savePositionChange($project_id, $task_id, $position, $column_id, $swimlane_id); - } - - if ($result && $fire_events) { - $this->fireEvents($task, $column_id, $position, $swimlane_id); - } - - return $result; - } - - /** - * Move a task to another swimlane - * - * @access private - * @param integer $project_id - * @param integer $task_id - * @param integer $position - * @param integer $original_column_id - * @param integer $new_column_id - * @param integer $original_swimlane_id - * @param integer $new_swimlane_id - * @return boolean - */ - private function saveSwimlaneChange($project_id, $task_id, $position, $original_column_id, $new_column_id, $original_swimlane_id, $new_swimlane_id) - { - $this->db->startTransaction(); - $r1 = $this->saveTaskPositions($project_id, $task_id, 0, $original_column_id, $original_swimlane_id); - $r2 = $this->saveTaskPositions($project_id, $task_id, $position, $new_column_id, $new_swimlane_id); - $this->db->closeTransaction(); - - return $r1 && $r2; - } - - /** - * Move a task to another column - * - * @access private - * @param integer $project_id - * @param integer $task_id - * @param integer $position - * @param integer $swimlane_id - * @param integer $original_column_id - * @param integer $new_column_id - * @return boolean - */ - private function saveColumnChange($project_id, $task_id, $position, $swimlane_id, $original_column_id, $new_column_id) - { - $this->db->startTransaction(); - $r1 = $this->saveTaskPositions($project_id, $task_id, 0, $original_column_id, $swimlane_id); - $r2 = $this->saveTaskPositions($project_id, $task_id, $position, $new_column_id, $swimlane_id); - $this->db->closeTransaction(); - - return $r1 && $r2; - } - - /** - * Move a task to another position in the same column - * - * @access private - * @param integer $project_id - * @param integer $task_id - * @param integer $position - * @param integer $column_id - * @param integer $swimlane_id - * @return boolean - */ - private function savePositionChange($project_id, $task_id, $position, $column_id, $swimlane_id) - { - $this->db->startTransaction(); - $result = $this->saveTaskPositions($project_id, $task_id, $position, $column_id, $swimlane_id); - $this->db->closeTransaction(); - - return $result; - } - - /** - * Save all task positions for one column - * - * @access private - * @param integer $project_id - * @param integer $task_id - * @param integer $position - * @param integer $column_id - * @param integer $swimlane_id - * @return boolean - */ - private function saveTaskPositions($project_id, $task_id, $position, $column_id, $swimlane_id) - { - $tasks_ids = $this->db->table(Task::TABLE) - ->eq('is_active', 1) - ->eq('swimlane_id', $swimlane_id) - ->eq('project_id', $project_id) - ->eq('column_id', $column_id) - ->neq('id', $task_id) - ->asc('position') - ->asc('id') - ->findAllByColumn('id'); - - $offset = 1; - - foreach ($tasks_ids as $current_task_id) { - - // Insert the new task - if ($position == $offset) { - if (! $this->saveTaskPosition($task_id, $offset, $column_id, $swimlane_id)) { - return false; - } - $offset++; - } - - // Rewrite other tasks position - if (! $this->saveTaskPosition($current_task_id, $offset, $column_id, $swimlane_id)) { - return false; - } - - $offset++; - } - - // Insert the new task at the bottom and normalize bad position - if ($position >= $offset && ! $this->saveTaskPosition($task_id, $offset, $column_id, $swimlane_id)) { - return false; - } - - $now = time(); - - return $this->db->table(Task::TABLE)->eq('id', $task_id)->update(array( - 'date_moved' => $now, - 'date_modification' => $now, - )); - } - - /** - * Save new task position - * - * @access private - * @param integer $task_id - * @param integer $position - * @param integer $column_id - * @param integer $swimlane_id - * @return boolean - */ - private function saveTaskPosition($task_id, $position, $column_id, $swimlane_id) - { - $result = $this->db->table(Task::TABLE)->eq('id', $task_id)->update(array( - 'position' => $position, - 'column_id' => $column_id, - 'swimlane_id' => $swimlane_id, - )); - - if (! $result) { - $this->db->cancelTransaction(); - return false; - } - - return true; - } - - /** - * Fire events - * - * @access private - * @param array $task - * @param integer $new_column_id - * @param integer $new_position - * @param integer $new_swimlane_id - */ - private function fireEvents(array $task, $new_column_id, $new_position, $new_swimlane_id) - { - $event_data = array( - 'task_id' => $task['id'], - 'project_id' => $task['project_id'], - 'position' => $new_position, - 'column_id' => $new_column_id, - 'swimlane_id' => $new_swimlane_id, - 'src_column_id' => $task['column_id'], - 'dst_column_id' => $new_column_id, - 'date_moved' => $task['date_moved'], - 'recurrence_status' => $task['recurrence_status'], - 'recurrence_trigger' => $task['recurrence_trigger'], - ); - - 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)); - } 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)); - } 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)); - } - } -} diff --git a/app/Model/TaskPositionModel.php b/app/Model/TaskPositionModel.php new file mode 100644 index 00000000..9fdb8f7d --- /dev/null +++ b/app/Model/TaskPositionModel.php @@ -0,0 +1,239 @@ += 1) + * @param integer $swimlane_id Swimlane id + * @param boolean $fire_events Fire events + * @return boolean + */ + public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true) + { + if ($position < 1) { + return false; + } + + $task = $this->taskFinderModel->getById($task_id); + + if ($task['is_active'] == TaskModel::STATUS_CLOSED) { + return true; + } + + $result = false; + + if ($task['swimlane_id'] != $swimlane_id) { + $result = $this->saveSwimlaneChange($project_id, $task_id, $position, $task['column_id'], $column_id, $task['swimlane_id'], $swimlane_id); + } elseif ($task['column_id'] != $column_id) { + $result = $this->saveColumnChange($project_id, $task_id, $position, $swimlane_id, $task['column_id'], $column_id); + } elseif ($task['position'] != $position) { + $result = $this->savePositionChange($project_id, $task_id, $position, $column_id, $swimlane_id); + } + + if ($result && $fire_events) { + $this->fireEvents($task, $column_id, $position, $swimlane_id); + } + + return $result; + } + + /** + * Move a task to another swimlane + * + * @access private + * @param integer $project_id + * @param integer $task_id + * @param integer $position + * @param integer $original_column_id + * @param integer $new_column_id + * @param integer $original_swimlane_id + * @param integer $new_swimlane_id + * @return boolean + */ + private function saveSwimlaneChange($project_id, $task_id, $position, $original_column_id, $new_column_id, $original_swimlane_id, $new_swimlane_id) + { + $this->db->startTransaction(); + $r1 = $this->saveTaskPositions($project_id, $task_id, 0, $original_column_id, $original_swimlane_id); + $r2 = $this->saveTaskPositions($project_id, $task_id, $position, $new_column_id, $new_swimlane_id); + $this->db->closeTransaction(); + + return $r1 && $r2; + } + + /** + * Move a task to another column + * + * @access private + * @param integer $project_id + * @param integer $task_id + * @param integer $position + * @param integer $swimlane_id + * @param integer $original_column_id + * @param integer $new_column_id + * @return boolean + */ + private function saveColumnChange($project_id, $task_id, $position, $swimlane_id, $original_column_id, $new_column_id) + { + $this->db->startTransaction(); + $r1 = $this->saveTaskPositions($project_id, $task_id, 0, $original_column_id, $swimlane_id); + $r2 = $this->saveTaskPositions($project_id, $task_id, $position, $new_column_id, $swimlane_id); + $this->db->closeTransaction(); + + return $r1 && $r2; + } + + /** + * Move a task to another position in the same column + * + * @access private + * @param integer $project_id + * @param integer $task_id + * @param integer $position + * @param integer $column_id + * @param integer $swimlane_id + * @return boolean + */ + private function savePositionChange($project_id, $task_id, $position, $column_id, $swimlane_id) + { + $this->db->startTransaction(); + $result = $this->saveTaskPositions($project_id, $task_id, $position, $column_id, $swimlane_id); + $this->db->closeTransaction(); + + return $result; + } + + /** + * Save all task positions for one column + * + * @access private + * @param integer $project_id + * @param integer $task_id + * @param integer $position + * @param integer $column_id + * @param integer $swimlane_id + * @return boolean + */ + private function saveTaskPositions($project_id, $task_id, $position, $column_id, $swimlane_id) + { + $tasks_ids = $this->db->table(TaskModel::TABLE) + ->eq('is_active', 1) + ->eq('swimlane_id', $swimlane_id) + ->eq('project_id', $project_id) + ->eq('column_id', $column_id) + ->neq('id', $task_id) + ->asc('position') + ->asc('id') + ->findAllByColumn('id'); + + $offset = 1; + + foreach ($tasks_ids as $current_task_id) { + + // Insert the new task + if ($position == $offset) { + if (! $this->saveTaskPosition($task_id, $offset, $column_id, $swimlane_id)) { + return false; + } + $offset++; + } + + // Rewrite other tasks position + if (! $this->saveTaskPosition($current_task_id, $offset, $column_id, $swimlane_id)) { + return false; + } + + $offset++; + } + + // Insert the new task at the bottom and normalize bad position + if ($position >= $offset && ! $this->saveTaskPosition($task_id, $offset, $column_id, $swimlane_id)) { + return false; + } + + $now = time(); + + return $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(array( + 'date_moved' => $now, + 'date_modification' => $now, + )); + } + + /** + * Save new task position + * + * @access private + * @param integer $task_id + * @param integer $position + * @param integer $column_id + * @param integer $swimlane_id + * @return boolean + */ + private function saveTaskPosition($task_id, $position, $column_id, $swimlane_id) + { + $result = $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(array( + 'position' => $position, + 'column_id' => $column_id, + 'swimlane_id' => $swimlane_id, + )); + + if (! $result) { + $this->db->cancelTransaction(); + return false; + } + + return true; + } + + /** + * Fire events + * + * @access private + * @param array $task + * @param integer $new_column_id + * @param integer $new_position + * @param integer $new_swimlane_id + */ + private function fireEvents(array $task, $new_column_id, $new_position, $new_swimlane_id) + { + $event_data = array( + 'task_id' => $task['id'], + 'project_id' => $task['project_id'], + 'position' => $new_position, + 'column_id' => $new_column_id, + 'swimlane_id' => $new_swimlane_id, + 'src_column_id' => $task['column_id'], + 'dst_column_id' => $new_column_id, + 'date_moved' => $task['date_moved'], + 'recurrence_status' => $task['recurrence_status'], + 'recurrence_trigger' => $task['recurrence_trigger'], + ); + + if ($task['swimlane_id'] != $new_swimlane_id) { + $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: '.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: '.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/TaskStatus.php deleted file mode 100644 index 4ba13a60..00000000 --- a/app/Model/TaskStatus.php +++ /dev/null @@ -1,146 +0,0 @@ -checkStatus($task_id, Task::STATUS_CLOSED); - } - - /** - * Return true if the task is open - * - * @access public - * @param integer $task_id Task id - * @return boolean - */ - public function isOpen($task_id) - { - return $this->checkStatus($task_id, Task::STATUS_OPEN); - } - - /** - * Mark a task closed - * - * @access public - * @param integer $task_id Task id - * @return boolean - */ - public function close($task_id) - { - $this->subtask->closeAll($task_id); - return $this->changeStatus($task_id, Task::STATUS_CLOSED, time(), Task::EVENT_CLOSE); - } - - /** - * Mark a task open - * - * @access public - * @param integer $task_id Task id - * @return boolean - */ - public function open($task_id) - { - return $this->changeStatus($task_id, Task::STATUS_OPEN, 0, Task::EVENT_OPEN); - } - - /** - * Close multiple tasks - * - * @access public - * @param array $task_ids - */ - public function closeMultipleTasks(array $task_ids) - { - foreach ($task_ids as $task_id) { - $this->close($task_id); - } - } - - /** - * Close all tasks within a column/swimlane - * - * @access public - * @param integer $swimlane_id - * @param integer $column_id - */ - public function closeTasksBySwimlaneAndColumn($swimlane_id, $column_id) - { - $task_ids = $this->db - ->table(Task::TABLE) - ->eq('swimlane_id', $swimlane_id) - ->eq('column_id', $column_id) - ->eq(Task::TABLE.'.is_active', Task::STATUS_OPEN) - ->findAllByColumn('id'); - - $this->closeMultipleTasks($task_ids); - } - - /** - * Common method to change the status of task - * - * @access private - * @param integer $task_id Task id - * @param integer $status Task status - * @param integer $date_completed Timestamp - * @param string $event Event name - * @return boolean - */ - private function changeStatus($task_id, $status, $date_completed, $event) - { - if (! $this->taskFinder->exists($task_id)) { - return false; - } - - $result = $this->db - ->table(Task::TABLE) - ->eq('id', $task_id) - ->update(array( - 'is_active' => $status, - 'date_completed' => $date_completed, - 'date_modification' => time(), - )); - - if ($result) { - $this->logger->debug('Event fired: '.$event); - $this->dispatcher->dispatch($event, new TaskEvent(array('task_id' => $task_id) + $this->taskFinder->getById($task_id))); - } - - return $result; - } - - /** - * Check the status of a task - * - * @access private - * @param integer $task_id Task id - * @param integer $status Task status - * @return boolean - */ - private function checkStatus($task_id, $status) - { - return $this->db - ->table(Task::TABLE) - ->eq('id', $task_id) - ->eq('is_active', $status) - ->count() === 1; - } -} diff --git a/app/Model/TaskStatusModel.php b/app/Model/TaskStatusModel.php new file mode 100644 index 00000000..4d573f0e --- /dev/null +++ b/app/Model/TaskStatusModel.php @@ -0,0 +1,146 @@ +checkStatus($task_id, TaskModel::STATUS_CLOSED); + } + + /** + * Return true if the task is open + * + * @access public + * @param integer $task_id Task id + * @return boolean + */ + public function isOpen($task_id) + { + return $this->checkStatus($task_id, TaskModel::STATUS_OPEN); + } + + /** + * Mark a task closed + * + * @access public + * @param integer $task_id Task id + * @return boolean + */ + public function close($task_id) + { + $this->subtaskModel->closeAll($task_id); + return $this->changeStatus($task_id, TaskModel::STATUS_CLOSED, time(), TaskModel::EVENT_CLOSE); + } + + /** + * Mark a task open + * + * @access public + * @param integer $task_id Task id + * @return boolean + */ + public function open($task_id) + { + return $this->changeStatus($task_id, TaskModel::STATUS_OPEN, 0, TaskModel::EVENT_OPEN); + } + + /** + * Close multiple tasks + * + * @access public + * @param array $task_ids + */ + public function closeMultipleTasks(array $task_ids) + { + foreach ($task_ids as $task_id) { + $this->close($task_id); + } + } + + /** + * Close all tasks within a column/swimlane + * + * @access public + * @param integer $swimlane_id + * @param integer $column_id + */ + public function closeTasksBySwimlaneAndColumn($swimlane_id, $column_id) + { + $task_ids = $this->db + ->table(TaskModel::TABLE) + ->eq('swimlane_id', $swimlane_id) + ->eq('column_id', $column_id) + ->eq(TaskModel::TABLE.'.is_active', TaskModel::STATUS_OPEN) + ->findAllByColumn('id'); + + $this->closeMultipleTasks($task_ids); + } + + /** + * Common method to change the status of task + * + * @access private + * @param integer $task_id Task id + * @param integer $status Task status + * @param integer $date_completed Timestamp + * @param string $event Event name + * @return boolean + */ + private function changeStatus($task_id, $status, $date_completed, $event) + { + if (! $this->taskFinderModel->exists($task_id)) { + return false; + } + + $result = $this->db + ->table(TaskModel::TABLE) + ->eq('id', $task_id) + ->update(array( + 'is_active' => $status, + 'date_completed' => $date_completed, + 'date_modification' => time(), + )); + + if ($result) { + $this->logger->debug('Event fired: '.$event); + $this->dispatcher->dispatch($event, new TaskEvent(array('task_id' => $task_id) + $this->taskFinderModel->getById($task_id))); + } + + return $result; + } + + /** + * Check the status of a task + * + * @access private + * @param integer $task_id Task id + * @param integer $status Task status + * @return boolean + */ + private function checkStatus($task_id, $status) + { + return $this->db + ->table(TaskModel::TABLE) + ->eq('id', $task_id) + ->eq('is_active', $status) + ->count() === 1; + } +} diff --git a/app/Model/Timezone.php b/app/Model/Timezone.php deleted file mode 100644 index de426e79..00000000 --- a/app/Model/Timezone.php +++ /dev/null @@ -1,58 +0,0 @@ - t('Application default')) + $listing; - } - - return $listing; - } - - /** - * Get current timezone - * - * @access public - * @return string - */ - public function getCurrentTimezone() - { - if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) { - return $this->sessionStorage->user['timezone']; - } - - return $this->config->get('application_timezone', 'UTC'); - } - - /** - * Set timezone - * - * @access public - */ - public function setCurrentTimezone() - { - date_default_timezone_set($this->getCurrentTimezone()); - } -} diff --git a/app/Model/TimezoneModel.php b/app/Model/TimezoneModel.php new file mode 100644 index 00000000..8b3e895a --- /dev/null +++ b/app/Model/TimezoneModel.php @@ -0,0 +1,58 @@ + t('Application default')) + $listing; + } + + return $listing; + } + + /** + * Get current timezone + * + * @access public + * @return string + */ + public function getCurrentTimezone() + { + if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) { + return $this->sessionStorage->user['timezone']; + } + + return $this->configModel->get('application_timezone', 'UTC'); + } + + /** + * Set timezone + * + * @access public + */ + public function setCurrentTimezone() + { + date_default_timezone_set($this->getCurrentTimezone()); + } +} diff --git a/app/Model/Transition.php b/app/Model/Transition.php deleted file mode 100644 index 2bc622b0..00000000 --- a/app/Model/Transition.php +++ /dev/null @@ -1,130 +0,0 @@ -db->table(self::TABLE)->insert(array( - 'user_id' => $user_id, - 'project_id' => $task_event['project_id'], - 'task_id' => $task_event['task_id'], - 'src_column_id' => $task_event['src_column_id'], - 'dst_column_id' => $task_event['dst_column_id'], - 'date' => $time, - 'time_spent' => $time - $task_event['date_moved'] - )); - } - - /** - * Get time spent by task for each column - * - * @access public - * @param integer $task_id - * @return array - */ - public function getTimeSpentByTask($task_id) - { - return $this->db - ->hashtable(self::TABLE) - ->groupBy('src_column_id') - ->eq('task_id', $task_id) - ->getAll('src_column_id', 'SUM(time_spent) AS time_spent'); - } - - /** - * Get all transitions by task - * - * @access public - * @param integer $task_id - * @return array - */ - public function getAllByTask($task_id) - { - return $this->db->table(self::TABLE) - ->columns( - 'src.title as src_column', - 'dst.title as dst_column', - User::TABLE.'.name', - User::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') - ->findAll(); - } - - /** - * Get all transitions by project - * - * @access public - * @param integer $project_id - * @param mixed $from Start date (timestamp or user formatted date) - * @param mixed $to End date (timestamp or user formatted date) - * @return array - */ - public function getAllByProjectAndDate($project_id, $from, $to) - { - if (! is_numeric($from)) { - $from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from)); - } - - if (! is_numeric($to)) { - $to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to))); - } - - return $this->db->table(self::TABLE) - ->columns( - Task::TABLE.'.id', - Task::TABLE.'.title', - 'src.title as src_column', - 'dst.title as dst_column', - User::TABLE.'.name', - User::TABLE.'.username', - self::TABLE.'.user_id', - self::TABLE.'.date', - self::TABLE.'.time_spent' - ) - ->gte('date', $from) - ->lte('date', $to) - ->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') - ->findAll(); - } -} diff --git a/app/Model/TransitionModel.php b/app/Model/TransitionModel.php new file mode 100644 index 00000000..a4a58472 --- /dev/null +++ b/app/Model/TransitionModel.php @@ -0,0 +1,130 @@ +db->table(self::TABLE)->insert(array( + 'user_id' => $user_id, + 'project_id' => $task_event['project_id'], + 'task_id' => $task_event['task_id'], + 'src_column_id' => $task_event['src_column_id'], + 'dst_column_id' => $task_event['dst_column_id'], + 'date' => $time, + 'time_spent' => $time - $task_event['date_moved'] + )); + } + + /** + * Get time spent by task for each column + * + * @access public + * @param integer $task_id + * @return array + */ + public function getTimeSpentByTask($task_id) + { + return $this->db + ->hashtable(self::TABLE) + ->groupBy('src_column_id') + ->eq('task_id', $task_id) + ->getAll('src_column_id', 'SUM(time_spent) AS time_spent'); + } + + /** + * Get all transitions by task + * + * @access public + * @param integer $task_id + * @return array + */ + public function getAllByTask($task_id) + { + return $this->db->table(self::TABLE) + ->columns( + 'src.title as src_column', + 'dst.title as dst_column', + 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(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(); + } + + /** + * Get all transitions by project + * + * @access public + * @param integer $project_id + * @param mixed $from Start date (timestamp or user formatted date) + * @param mixed $to End date (timestamp or user formatted date) + * @return array + */ + public function getAllByProjectAndDate($project_id, $from, $to) + { + if (! is_numeric($from)) { + $from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from)); + } + + if (! is_numeric($to)) { + $to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to))); + } + + return $this->db->table(self::TABLE) + ->columns( + TaskModel::TABLE.'.id', + TaskModel::TABLE.'.title', + 'src.title as src_column', + 'dst.title as dst_column', + UserModel::TABLE.'.name', + UserModel::TABLE.'.username', + self::TABLE.'.user_id', + self::TABLE.'.date', + self::TABLE.'.time_spent' + ) + ->gte('date', $from) + ->lte('date', $to) + ->eq(self::TABLE.'.project_id', $project_id) + ->desc('date') + ->desc(self::TABLE.'.id') + ->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/User.php b/app/Model/User.php deleted file mode 100644 index cbfca0ac..00000000 --- a/app/Model/User.php +++ /dev/null @@ -1,390 +0,0 @@ -db->table(self::TABLE)->eq('id', $user_id)->exists(); - } - - /** - * Return true if the user is active - * - * @access public - * @param integer $user_id User id - * @return boolean - */ - public function isActive($user_id) - { - return $this->db->table(self::TABLE)->eq('id', $user_id)->eq('is_active', 1)->exists(); - } - - /** - * Get query to fetch all users - * - * @access public - * @return \PicoDb\Table - */ - public function getQuery() - { - return $this->db->table(self::TABLE); - } - - /** - * Return the full name - * - * @param array $user User properties - * @return string - */ - public function getFullname(array $user) - { - return $user['name'] ?: $user['username']; - } - - /** - * Return true is the given user id is administrator - * - * @access public - * @param integer $user_id User id - * @return boolean - */ - public function isAdmin($user_id) - { - return $this->userSession->isAdmin() || // Avoid SQL query if connected - $this->db - ->table(User::TABLE) - ->eq('id', $user_id) - ->eq('role', Role::APP_ADMIN) - ->exists(); - } - - /** - * Get a specific user by id - * - * @access public - * @param integer $user_id User id - * @return array - */ - public function getById($user_id) - { - return $this->db->table(self::TABLE)->eq('id', $user_id)->findOne(); - } - - /** - * Get a specific user by the Google id - * - * @access public - * @param string $column - * @param string $id - * @return array|boolean - */ - public function getByExternalId($column, $id) - { - if (empty($id)) { - return false; - } - - return $this->db->table(self::TABLE)->eq($column, $id)->findOne(); - } - - /** - * Get a specific user by the username - * - * @access public - * @param string $username Username - * @return array - */ - public function getByUsername($username) - { - return $this->db->table(self::TABLE)->eq('username', $username)->findOne(); - } - - /** - * Get user_id by username - * - * @access public - * @param string $username Username - * @return integer - */ - public function getIdByUsername($username) - { - return $this->db->table(self::TABLE)->eq('username', $username)->findOneColumn('id'); - } - - /** - * Get a specific user by the email address - * - * @access public - * @param string $email Email - * @return array|boolean - */ - public function getByEmail($email) - { - if (empty($email)) { - return false; - } - - return $this->db->table(self::TABLE)->eq('email', $email)->findOne(); - } - - /** - * Fetch user by using the token - * - * @access public - * @param string $token Token - * @return array|boolean - */ - public function getByToken($token) - { - if (empty($token)) { - return false; - } - - return $this->db->table(self::TABLE)->eq('token', $token)->findOne(); - } - - /** - * Get all users - * - * @access public - * @return array - */ - public function getAll() - { - return $this->getQuery()->asc('username')->findAll(); - } - - /** - * Get the number of users - * - * @access public - * @return integer - */ - public function count() - { - return $this->db->table(self::TABLE)->count(); - } - - /** - * List all users (key-value pairs with id/username) - * - * @access public - * @param boolean $prepend Prepend "All users" - * @return array - */ - public function getActiveUsersList($prepend = false) - { - $users = $this->db->table(self::TABLE)->eq('is_active', 1)->columns('id', 'username', 'name')->findAll(); - $listing = $this->prepareList($users); - - if ($prepend) { - return array(User::EVERYBODY_ID => t('Everybody')) + $listing; - } - - return $listing; - } - - /** - * Common method to prepare a user list - * - * @access public - * @param array $users Users list (from database) - * @return array Formated list - */ - public function prepareList(array $users) - { - $result = array(); - - foreach ($users as $user) { - $result[$user['id']] = $this->getFullname($user); - } - - asort($result); - - return $result; - } - - /** - * Prepare values before an update or a create - * - * @access public - * @param array $values Form values - */ - public function prepare(array &$values) - { - if (isset($values['password'])) { - if (! empty($values['password'])) { - $values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT); - } else { - unset($values['password']); - } - } - - $this->helper->model->removeFields($values, array('confirmation', 'current_password')); - $this->helper->model->resetFields($values, array('is_ldap_user', 'disable_login_form')); - $this->helper->model->convertNullFields($values, array('gitlab_id')); - $this->helper->model->convertIntegerFields($values, array('gitlab_id')); - } - - /** - * Add a new user in the database - * - * @access public - * @param array $values Form values - * @return boolean|integer - */ - public function create(array $values) - { - $this->prepare($values); - return $this->db->table(self::TABLE)->persist($values); - } - - /** - * Modify a new user - * - * @access public - * @param array $values Form values - * @return boolean - */ - public function update(array $values) - { - $this->prepare($values); - $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); - $this->userSession->refresh($values['id']); - return $result; - } - - /** - * Disable a specific user - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function disable($user_id) - { - return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 0)); - } - - /** - * Enable a specific user - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function enable($user_id) - { - return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 1)); - } - - /** - * Remove a specific user - * - * @access public - * @param integer $user_id User id - * @return boolean - */ - public function remove($user_id) - { - $this->avatarFile->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))) { - 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))) { - 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))) { - return false; - } - - // All private projects are removed - $project_ids = $db->table(Project::TABLE) - ->eq('is_private', 1) - ->eq(ProjectUserRole::TABLE.'.user_id', $user_id) - ->join(ProjectUserRole::TABLE, 'project_id', 'id') - ->findAllByColumn(Project::TABLE.'.id'); - - if (! empty($project_ids)) { - $db->table(Project::TABLE)->in('id', $project_ids)->remove(); - } - - // Finally remove the user - if (! $db->table(User::TABLE)->eq('id', $user_id)->remove()) { - return false; - } - }); - } - - /** - * Enable public access for a user - * - * @access public - * @param integer $user_id User id - * @return bool - */ - public function enablePublicAccess($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $user_id) - ->save(array('token' => Token::getToken())); - } - - /** - * Disable public access for a user - * - * @access public - * @param integer $user_id User id - * @return bool - */ - public function disablePublicAccess($user_id) - { - return $this->db - ->table(self::TABLE) - ->eq('id', $user_id) - ->save(array('token' => '')); - } -} diff --git a/app/Model/UserLocking.php b/app/Model/UserLocking.php deleted file mode 100644 index ccaf402c..00000000 --- a/app/Model/UserLocking.php +++ /dev/null @@ -1,105 +0,0 @@ -db->table(User::TABLE) - ->eq('username', $username) - ->findOneColumn('nb_failed_login'); - } - - /** - * Reset to 0 the counter of failed login - * - * @access public - * @param string $username - * @return boolean - */ - public function resetFailedLogin($username) - { - return $this->db->table(User::TABLE) - ->eq('username', $username) - ->update(array( - 'nb_failed_login' => 0, - 'lock_expiration_date' => 0, - )); - } - - /** - * Increment failed login counter - * - * @access public - * @param string $username - * @return boolean - */ - public function incrementFailedLogin($username) - { - return $this->db->table(User::TABLE) - ->eq('username', $username) - ->increment('nb_failed_login', 1); - } - - /** - * Check if the account is locked - * - * @access public - * @param string $username - * @return boolean - */ - public function isLocked($username) - { - return $this->db->table(User::TABLE) - ->eq('username', $username) - ->neq('lock_expiration_date', 0) - ->gte('lock_expiration_date', time()) - ->exists(); - } - - /** - * Lock the account for the specified duration - * - * @access public - * @param string $username Username - * @param integer $duration Duration in minutes - * @return boolean - */ - public function lock($username, $duration = 15) - { - return $this->db->table(User::TABLE) - ->eq('username', $username) - ->update(array( - 'lock_expiration_date' => time() + $duration * 60 - )); - } - - /** - * Return true if the captcha must be shown - * - * @access public - * @param string $username - * @param integer $tries - * @return boolean - */ - public function hasCaptcha($username, $tries = BRUTEFORCE_CAPTCHA) - { - return $this->getFailedLogin($username) >= $tries; - } -} diff --git a/app/Model/UserLockingModel.php b/app/Model/UserLockingModel.php new file mode 100644 index 00000000..1d4d994c --- /dev/null +++ b/app/Model/UserLockingModel.php @@ -0,0 +1,105 @@ +db->table(UserModel::TABLE) + ->eq('username', $username) + ->findOneColumn('nb_failed_login'); + } + + /** + * Reset to 0 the counter of failed login + * + * @access public + * @param string $username + * @return boolean + */ + public function resetFailedLogin($username) + { + return $this->db->table(UserModel::TABLE) + ->eq('username', $username) + ->update(array( + 'nb_failed_login' => 0, + 'lock_expiration_date' => 0, + )); + } + + /** + * Increment failed login counter + * + * @access public + * @param string $username + * @return boolean + */ + public function incrementFailedLogin($username) + { + return $this->db->table(UserModel::TABLE) + ->eq('username', $username) + ->increment('nb_failed_login', 1); + } + + /** + * Check if the account is locked + * + * @access public + * @param string $username + * @return boolean + */ + public function isLocked($username) + { + return $this->db->table(UserModel::TABLE) + ->eq('username', $username) + ->neq('lock_expiration_date', 0) + ->gte('lock_expiration_date', time()) + ->exists(); + } + + /** + * Lock the account for the specified duration + * + * @access public + * @param string $username Username + * @param integer $duration Duration in minutes + * @return boolean + */ + public function lock($username, $duration = 15) + { + return $this->db->table(UserModel::TABLE) + ->eq('username', $username) + ->update(array( + 'lock_expiration_date' => time() + $duration * 60 + )); + } + + /** + * Return true if the captcha must be shown + * + * @access public + * @param string $username + * @param integer $tries + * @return boolean + */ + public function hasCaptcha($username, $tries = BRUTEFORCE_CAPTCHA) + { + return $this->getFailedLogin($username) >= $tries; + } +} diff --git a/app/Model/UserMention.php b/app/Model/UserMention.php deleted file mode 100644 index 42b81840..00000000 --- a/app/Model/UserMention.php +++ /dev/null @@ -1,62 +0,0 @@ -db->table(User::TABLE) - ->columns('id', 'username', 'name', 'email', 'language') - ->eq('notifications_enabled', 1) - ->neq('id', $this->userSession->getId()) - ->in('username', array_unique($matches[1])) - ->findAll(); - } - - return $users; - } - - /** - * Fire events for user mentions - * - * @access public - * @param string $content - * @param string $eventName - * @param GenericEvent $event - */ - public function fireEvents($content, $eventName, GenericEvent $event) - { - if (empty($event['project_id'])) { - $event['project_id'] = $this->taskFinder->getProjectId($event['task_id']); - } - - $users = $this->getMentionedUsers($content); - - foreach ($users as $user) { - if ($this->projectPermission->isMember($event['project_id'], $user['id'])) { - $event['mention'] = $user; - $this->dispatcher->dispatch($eventName, $event); - } - } - } -} diff --git a/app/Model/UserMentionModel.php b/app/Model/UserMentionModel.php new file mode 100644 index 00000000..cdb9949e --- /dev/null +++ b/app/Model/UserMentionModel.php @@ -0,0 +1,62 @@ +db->table(UserModel::TABLE) + ->columns('id', 'username', 'name', 'email', 'language') + ->eq('notifications_enabled', 1) + ->neq('id', $this->userSession->getId()) + ->in('username', array_unique($matches[1])) + ->findAll(); + } + + return $users; + } + + /** + * Fire events for user mentions + * + * @access public + * @param string $content + * @param string $eventName + * @param GenericEvent $event + */ + public function fireEvents($content, $eventName, GenericEvent $event) + { + if (empty($event['project_id'])) { + $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']); + } + + $users = $this->getMentionedUsers($content); + + foreach ($users as $user) { + 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/UserMetadata.php deleted file mode 100644 index 491c1575..00000000 --- a/app/Model/UserMetadata.php +++ /dev/null @@ -1,37 +0,0 @@ -db->table(self::TABLE)->eq('id', $user_id)->exists(); + } + + /** + * Return true if the user is active + * + * @access public + * @param integer $user_id User id + * @return boolean + */ + public function isActive($user_id) + { + return $this->db->table(self::TABLE)->eq('id', $user_id)->eq('is_active', 1)->exists(); + } + + /** + * Get query to fetch all users + * + * @access public + * @return \PicoDb\Table + */ + public function getQuery() + { + return $this->db->table(self::TABLE); + } + + /** + * Return the full name + * + * @param array $user User properties + * @return string + */ + public function getFullname(array $user) + { + return $user['name'] ?: $user['username']; + } + + /** + * Return true is the given user id is administrator + * + * @access public + * @param integer $user_id User id + * @return boolean + */ + public function isAdmin($user_id) + { + return $this->userSession->isAdmin() || // Avoid SQL query if connected + $this->db + ->table(UserModel::TABLE) + ->eq('id', $user_id) + ->eq('role', Role::APP_ADMIN) + ->exists(); + } + + /** + * Get a specific user by id + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getById($user_id) + { + return $this->db->table(self::TABLE)->eq('id', $user_id)->findOne(); + } + + /** + * Get a specific user by the Google id + * + * @access public + * @param string $column + * @param string $id + * @return array|boolean + */ + public function getByExternalId($column, $id) + { + if (empty($id)) { + return false; + } + + return $this->db->table(self::TABLE)->eq($column, $id)->findOne(); + } + + /** + * Get a specific user by the username + * + * @access public + * @param string $username Username + * @return array + */ + public function getByUsername($username) + { + return $this->db->table(self::TABLE)->eq('username', $username)->findOne(); + } + + /** + * Get user_id by username + * + * @access public + * @param string $username Username + * @return integer + */ + public function getIdByUsername($username) + { + return $this->db->table(self::TABLE)->eq('username', $username)->findOneColumn('id'); + } + + /** + * Get a specific user by the email address + * + * @access public + * @param string $email Email + * @return array|boolean + */ + public function getByEmail($email) + { + if (empty($email)) { + return false; + } + + return $this->db->table(self::TABLE)->eq('email', $email)->findOne(); + } + + /** + * Fetch user by using the token + * + * @access public + * @param string $token Token + * @return array|boolean + */ + public function getByToken($token) + { + if (empty($token)) { + return false; + } + + return $this->db->table(self::TABLE)->eq('token', $token)->findOne(); + } + + /** + * Get all users + * + * @access public + * @return array + */ + public function getAll() + { + return $this->getQuery()->asc('username')->findAll(); + } + + /** + * Get the number of users + * + * @access public + * @return integer + */ + public function count() + { + return $this->db->table(self::TABLE)->count(); + } + + /** + * List all users (key-value pairs with id/username) + * + * @access public + * @param boolean $prepend Prepend "All users" + * @return array + */ + public function getActiveUsersList($prepend = false) + { + $users = $this->db->table(self::TABLE)->eq('is_active', 1)->columns('id', 'username', 'name')->findAll(); + $listing = $this->prepareList($users); + + if ($prepend) { + return array(UserModel::EVERYBODY_ID => t('Everybody')) + $listing; + } + + return $listing; + } + + /** + * Common method to prepare a user list + * + * @access public + * @param array $users Users list (from database) + * @return array Formated list + */ + public function prepareList(array $users) + { + $result = array(); + + foreach ($users as $user) { + $result[$user['id']] = $this->getFullname($user); + } + + asort($result); + + return $result; + } + + /** + * Prepare values before an update or a create + * + * @access public + * @param array $values Form values + */ + public function prepare(array &$values) + { + if (isset($values['password'])) { + if (! empty($values['password'])) { + $values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT); + } else { + unset($values['password']); + } + } + + $this->helper->model->removeFields($values, array('confirmation', 'current_password')); + $this->helper->model->resetFields($values, array('is_ldap_user', 'disable_login_form')); + $this->helper->model->convertNullFields($values, array('gitlab_id')); + $this->helper->model->convertIntegerFields($values, array('gitlab_id')); + } + + /** + * Add a new user in the database + * + * @access public + * @param array $values Form values + * @return boolean|integer + */ + public function create(array $values) + { + $this->prepare($values); + return $this->db->table(self::TABLE)->persist($values); + } + + /** + * Modify a new user + * + * @access public + * @param array $values Form values + * @return boolean + */ + public function update(array $values) + { + $this->prepare($values); + $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); + $this->userSession->refresh($values['id']); + return $result; + } + + /** + * Disable a specific user + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function disable($user_id) + { + return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 0)); + } + + /** + * Enable a specific user + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function enable($user_id) + { + return $this->db->table(self::TABLE)->eq('id', $user_id)->update(array('is_active' => 1)); + } + + /** + * Remove a specific user + * + * @access public + * @param integer $user_id User id + * @return boolean + */ + public function 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(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(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(CommentModel::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) { + return false; + } + + // All private projects are removed + $project_ids = $db->table(ProjectModel::TABLE) + ->eq('is_private', 1) + ->eq(ProjectUserRoleModel::TABLE.'.user_id', $user_id) + ->join(ProjectUserRoleModel::TABLE, 'project_id', 'id') + ->findAllByColumn(ProjectModel::TABLE.'.id'); + + if (! empty($project_ids)) { + $db->table(ProjectModel::TABLE)->in('id', $project_ids)->remove(); + } + + // Finally remove the user + if (! $db->table(UserModel::TABLE)->eq('id', $user_id)->remove()) { + return false; + } + }); + } + + /** + * Enable public access for a user + * + * @access public + * @param integer $user_id User id + * @return bool + */ + public function enablePublicAccess($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $user_id) + ->save(array('token' => Token::getToken())); + } + + /** + * Disable public access for a user + * + * @access public + * @param integer $user_id User id + * @return bool + */ + public function disablePublicAccess($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('id', $user_id) + ->save(array('token' => '')); + } +} diff --git a/app/Model/UserNotification.php b/app/Model/UserNotification.php deleted file mode 100644 index ef90bb63..00000000 --- a/app/Model/UserNotification.php +++ /dev/null @@ -1,204 +0,0 @@ -getUsersWithNotificationEnabled($event_data['task']['project_id'], $this->userSession->getId()); - - foreach ($users as $user) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, $event_data)) { - $this->sendUserNotification($user, $event_name, $event_data); - } - } - } - - /** - * Send notification to someone - * - * @access public - * @param array $user User - * @param string $event_name - * @param array $event_data - */ - public function sendUserNotification(array $user, $event_name, array $event_data) - { - Translator::unload(); - - // Use the user language otherwise use the application language (do not use the session language) - if (! empty($user['language'])) { - Translator::load($user['language']); - } else { - Translator::load($this->config->get('application_language', 'en_US')); - } - - foreach ($this->userNotificationType->getSelectedTypes($user['id']) as $type) { - $this->userNotificationType->getType($type)->notifyUser($user, $event_name, $event_data); - } - - // Restore locales - $this->language->loadCurrentLanguage(); - } - - /** - * Get a list of people with notifications enabled - * - * @access public - * @param integer $project_id Project id - * @param integer $exclude_user_id User id to exclude - * @return array - */ - public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) - { - if ($this->projectPermission->isEverybodyAllowed($project_id)) { - return $this->getEverybodyWithNotificationEnabled($exclude_user_id); - } - - $users = array(); - $members = $this->getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id); - $groups = $this->getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id); - - foreach (array_merge($members, $groups) as $user) { - if (! isset($users[$user['id']])) { - $users[$user['id']] = $user; - } - } - - return array_values($users); - } - - /** - * Enable notification for someone - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function enableNotification($user_id) - { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 1)); - } - - /** - * Disable notification for someone - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function disableNotification($user_id) - { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 0)); - } - - /** - * Save settings for the given user - * - * @access public - * @param integer $user_id User id - * @param array $values Form values - */ - public function saveSettings($user_id, array $values) - { - $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); - - if (! empty($types)) { - $this->enableNotification($user_id); - } else { - $this->disableNotification($user_id); - } - - $filter = empty($values['notifications_filter']) ? UserNotificationFilter::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); - } - - /** - * Read user settings to display the form - * - * @access public - * @param integer $user_id User id - * @return array - */ - 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); - return $values; - } - - /** - * Get a list of group members with notification enabled - * - * @access private - * @param integer $project_id Project id - * @param integer $exclude_user_id User id to exclude - * @return array - */ - 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) - ->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) - ->findAll(); - } - - /** - * Get a list of project members with notification enabled - * - * @access private - * @param integer $exclude_user_id User id to exclude - * @return array - */ - 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') - ->eq('notifications_enabled', '1') - ->neq(User::TABLE.'.id', $exclude_user_id) - ->eq(User::TABLE.'.is_active', 1) - ->findAll(); - } -} diff --git a/app/Model/UserNotificationFilter.php b/app/Model/UserNotificationFilter.php deleted file mode 100644 index d885da04..00000000 --- a/app/Model/UserNotificationFilter.php +++ /dev/null @@ -1,206 +0,0 @@ - t('All tasks'), - self::FILTER_ASSIGNEE => t('Only for tasks assigned to me'), - self::FILTER_CREATOR => t('Only for tasks created by me'), - self::FILTER_BOTH => t('Only for tasks created by me and assigned to me'), - ); - } - - /** - * Get user selected filter - * - * @access public - * @param integer $user_id - * @return integer - */ - public function getSelectedFilter($user_id) - { - return $this->db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); - } - - /** - * Save selected filter for a user - * - * @access public - * @param integer $user_id - * @param string $filter - * @return boolean - */ - public function saveFilter($user_id, $filter) - { - return $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( - 'notifications_filter' => $filter, - )); - } - - /** - * Get user selected projects - * - * @access public - * @param integer $user_id - * @return array - */ - public function getSelectedProjects($user_id) - { - return $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->findAllByColumn('project_id'); - } - - /** - * Save selected projects for a user - * - * @access public - * @param integer $user_id - * @param integer[] $project_ids - * @return boolean - */ - public function saveSelectedProjects($user_id, array $project_ids) - { - $results = array(); - $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove(); - - foreach ($project_ids as $project_id) { - $results[] = $this->db->table(self::PROJECT_TABLE)->insert(array( - 'user_id' => $user_id, - 'project_id' => $project_id, - )); - } - - return !in_array(false, $results, true); - } - - /** - * Return true if the user should receive notification - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function shouldReceiveNotification(array $user, array $event_data) - { - $filters = array( - 'filterNone', - 'filterAssignee', - 'filterCreator', - 'filterBoth', - ); - - foreach ($filters as $filter) { - if ($this->$filter($user, $event_data)) { - return $this->filterProject($user, $event_data); - } - } - - return false; - } - - /** - * Return true if the user will receive all notifications - * - * @access public - * @param array $user - * @return boolean - */ - public function filterNone(array $user) - { - return $user['notifications_filter'] == self::FILTER_NONE; - } - - /** - * Return true if the user is the assignee and selected the filter "assignee" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterAssignee(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_ASSIGNEE && $event_data['task']['owner_id'] == $user['id']; - } - - /** - * Return true if the user is the creator and enabled the filter "creator" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterCreator(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_CREATOR && $event_data['task']['creator_id'] == $user['id']; - } - - /** - * Return true if the user is the assignee or the creator and selected the filter "both" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterBoth(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_BOTH && - ($event_data['task']['creator_id'] == $user['id'] || $event_data['task']['owner_id'] == $user['id']); - } - - /** - * Return true if the user want to receive notification for the selected project - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterProject(array $user, array $event_data) - { - $projects = $this->getSelectedProjects($user['id']); - - if (! empty($projects)) { - return in_array($event_data['task']['project_id'], $projects); - } - - return true; - } -} diff --git a/app/Model/UserNotificationFilterModel.php b/app/Model/UserNotificationFilterModel.php new file mode 100644 index 00000000..112ba290 --- /dev/null +++ b/app/Model/UserNotificationFilterModel.php @@ -0,0 +1,206 @@ + t('All tasks'), + self::FILTER_ASSIGNEE => t('Only for tasks assigned to me'), + self::FILTER_CREATOR => t('Only for tasks created by me'), + self::FILTER_BOTH => t('Only for tasks created by me and assigned to me'), + ); + } + + /** + * Get user selected filter + * + * @access public + * @param integer $user_id + * @return integer + */ + public function getSelectedFilter($user_id) + { + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); + } + + /** + * Save selected filter for a user + * + * @access public + * @param integer $user_id + * @param string $filter + * @return boolean + */ + public function saveFilter($user_id, $filter) + { + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array( + 'notifications_filter' => $filter, + )); + } + + /** + * Get user selected projects + * + * @access public + * @param integer $user_id + * @return array + */ + public function getSelectedProjects($user_id) + { + return $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->findAllByColumn('project_id'); + } + + /** + * Save selected projects for a user + * + * @access public + * @param integer $user_id + * @param integer[] $project_ids + * @return boolean + */ + public function saveSelectedProjects($user_id, array $project_ids) + { + $results = array(); + $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove(); + + foreach ($project_ids as $project_id) { + $results[] = $this->db->table(self::PROJECT_TABLE)->insert(array( + 'user_id' => $user_id, + 'project_id' => $project_id, + )); + } + + return !in_array(false, $results, true); + } + + /** + * Return true if the user should receive notification + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function shouldReceiveNotification(array $user, array $event_data) + { + $filters = array( + 'filterNone', + 'filterAssignee', + 'filterCreator', + 'filterBoth', + ); + + foreach ($filters as $filter) { + if ($this->$filter($user, $event_data)) { + return $this->filterProject($user, $event_data); + } + } + + return false; + } + + /** + * Return true if the user will receive all notifications + * + * @access public + * @param array $user + * @return boolean + */ + public function filterNone(array $user) + { + return $user['notifications_filter'] == self::FILTER_NONE; + } + + /** + * Return true if the user is the assignee and selected the filter "assignee" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterAssignee(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_ASSIGNEE && $event_data['task']['owner_id'] == $user['id']; + } + + /** + * Return true if the user is the creator and enabled the filter "creator" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterCreator(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_CREATOR && $event_data['task']['creator_id'] == $user['id']; + } + + /** + * Return true if the user is the assignee or the creator and selected the filter "both" + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterBoth(array $user, array $event_data) + { + return $user['notifications_filter'] == self::FILTER_BOTH && + ($event_data['task']['creator_id'] == $user['id'] || $event_data['task']['owner_id'] == $user['id']); + } + + /** + * Return true if the user want to receive notification for the selected project + * + * @access public + * @param array $user + * @param array $event_data + * @return boolean + */ + public function filterProject(array $user, array $event_data) + { + $projects = $this->getSelectedProjects($user['id']); + + if (! empty($projects)) { + return in_array($event_data['task']['project_id'], $projects); + } + + return true; + } +} diff --git a/app/Model/UserNotificationModel.php b/app/Model/UserNotificationModel.php new file mode 100644 index 00000000..d77526f6 --- /dev/null +++ b/app/Model/UserNotificationModel.php @@ -0,0 +1,204 @@ +getUsersWithNotificationEnabled($event_data['task']['project_id'], $this->userSession->getId()); + + foreach ($users as $user) { + if ($this->userNotificationFilterModel->shouldReceiveNotification($user, $event_data)) { + $this->sendUserNotification($user, $event_name, $event_data); + } + } + } + + /** + * Send notification to someone + * + * @access public + * @param array $user User + * @param string $event_name + * @param array $event_data + */ + public function sendUserNotification(array $user, $event_name, array $event_data) + { + Translator::unload(); + + // Use the user language otherwise use the application language (do not use the session language) + if (! empty($user['language'])) { + Translator::load($user['language']); + } else { + Translator::load($this->configModel->get('application_language', 'en_US')); + } + + foreach ($this->userNotificationTypeModel->getSelectedTypes($user['id']) as $type) { + $this->userNotificationTypeModel->getType($type)->notifyUser($user, $event_name, $event_data); + } + + // Restore locales + $this->languageModel->loadCurrentLanguage(); + } + + /** + * Get a list of people with notifications enabled + * + * @access public + * @param integer $project_id Project id + * @param integer $exclude_user_id User id to exclude + * @return array + */ + public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0) + { + if ($this->projectPermissionModel->isEverybodyAllowed($project_id)) { + return $this->getEverybodyWithNotificationEnabled($exclude_user_id); + } + + $users = array(); + $members = $this->getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id); + $groups = $this->getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id); + + foreach (array_merge($members, $groups) as $user) { + if (! isset($users[$user['id']])) { + $users[$user['id']] = $user; + } + } + + return array_values($users); + } + + /** + * Enable notification for someone + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function enableNotification($user_id) + { + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 1)); + } + + /** + * Disable notification for someone + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function disableNotification($user_id) + { + return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(array('notifications_enabled' => 0)); + } + + /** + * Save settings for the given user + * + * @access public + * @param integer $user_id User id + * @param array $values Form values + */ + public function saveSettings($user_id, array $values) + { + $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']); + + if (! empty($types)) { + $this->enableNotification($user_id); + } else { + $this->disableNotification($user_id); + } + + $filter = empty($values['notifications_filter']) ? UserNotificationFilterModel::FILTER_BOTH : $values['notifications_filter']; + $project_ids = empty($values['notification_projects']) ? array() : array_keys($values['notification_projects']); + + $this->userNotificationFilterModel->saveFilter($user_id, $filter); + $this->userNotificationFilterModel->saveSelectedProjects($user_id, $project_ids); + $this->userNotificationTypeModel->saveSelectedTypes($user_id, $types); + } + + /** + * Read user settings to display the form + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function readSettings($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; + } + + /** + * Get a list of group members with notification enabled + * + * @access private + * @param integer $project_id Project id + * @param integer $exclude_user_id User id to exclude + * @return array + */ + private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id) + { + return $this->db + ->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(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(); + } + + /** + * Get a list of project members with notification enabled + * + * @access private + * @param integer $exclude_user_id User id to exclude + * @return array + */ + private function getEverybodyWithNotificationEnabled($exclude_user_id) + { + return $this->db + ->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(UserModel::TABLE.'.id', $exclude_user_id) + ->eq(UserModel::TABLE.'.is_active', 1) + ->findAll(); + } +} diff --git a/app/Model/UserNotificationType.php b/app/Model/UserNotificationType.php deleted file mode 100644 index d84cc690..00000000 --- a/app/Model/UserNotificationType.php +++ /dev/null @@ -1,54 +0,0 @@ -db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type'); - return $this->filterTypes($types); - } - - /** - * Save notification types for a given user - * - * @access public - * @param integer $user_id - * @param string[] $types - * @return boolean - */ - public function saveSelectedTypes($user_id, array $types) - { - $results = array(); - $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); - - foreach ($types as $type) { - $results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type)); - } - - return ! in_array(false, $results, true); - } -} diff --git a/app/Model/UserNotificationTypeModel.php b/app/Model/UserNotificationTypeModel.php new file mode 100644 index 00000000..0f377220 --- /dev/null +++ b/app/Model/UserNotificationTypeModel.php @@ -0,0 +1,52 @@ +db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type'); + return $this->filterTypes($types); + } + + /** + * Save notification types for a given user + * + * @access public + * @param integer $user_id + * @param string[] $types + * @return boolean + */ + public function saveSelectedTypes($user_id, array $types) + { + $results = array(); + $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); + + foreach ($types as $type) { + $results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type)); + } + + return ! in_array(false, $results, true); + } +} diff --git a/app/Model/UserUnreadNotification.php b/app/Model/UserUnreadNotification.php deleted file mode 100644 index f3fcd601..00000000 --- a/app/Model/UserUnreadNotification.php +++ /dev/null @@ -1,117 +0,0 @@ -db->table(self::TABLE)->insert(array( - 'user_id' => $user_id, - 'date_creation' => time(), - 'event_name' => $event_name, - 'event_data' => json_encode($event_data), - )); - } - - /** - * 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 - * @param integer $user_id - * @return array - */ - public function getAll($user_id) - { - $events = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('date_creation')->findAll(); - - foreach ($events as &$event) { - $this->unserialize($event); - } - - return $events; - } - - /** - * Mark a notification as read - * - * @access public - * @param integer $user_id - * @param integer $notification_id - * @return boolean - */ - public function markAsRead($user_id, $notification_id) - { - return $this->db->table(self::TABLE)->eq('id', $notification_id)->eq('user_id', $user_id)->remove(); - } - - /** - * Mark all notifications as read for a user - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function markAllAsRead($user_id) - { - return $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); - } - - /** - * Return true if the user as unread notifications - * - * @access public - * @param integer $user_id - * @return boolean - */ - public function hasNotifications($user_id) - { - 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->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']); - } -} diff --git a/app/Model/UserUnreadNotificationModel.php b/app/Model/UserUnreadNotificationModel.php new file mode 100644 index 00000000..6c930eef --- /dev/null +++ b/app/Model/UserUnreadNotificationModel.php @@ -0,0 +1,117 @@ +db->table(self::TABLE)->insert(array( + 'user_id' => $user_id, + 'date_creation' => time(), + 'event_name' => $event_name, + 'event_data' => json_encode($event_data), + )); + } + + /** + * 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 + * @param integer $user_id + * @return array + */ + public function getAll($user_id) + { + $events = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('date_creation')->findAll(); + + foreach ($events as &$event) { + $this->unserialize($event); + } + + return $events; + } + + /** + * Mark a notification as read + * + * @access public + * @param integer $user_id + * @param integer $notification_id + * @return boolean + */ + public function markAsRead($user_id, $notification_id) + { + return $this->db->table(self::TABLE)->eq('id', $notification_id)->eq('user_id', $user_id)->remove(); + } + + /** + * Mark all notifications as read for a user + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function markAllAsRead($user_id) + { + return $this->db->table(self::TABLE)->eq('user_id', $user_id)->remove(); + } + + /** + * Return true if the user as unread notifications + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasNotifications($user_id) + { + 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']); + } +} diff --git a/app/Notification/ActivityStreamNotification.php b/app/Notification/ActivityStreamNotification.php index 8ac265d3..9f23c88a 100644 --- a/app/Notification/ActivityStreamNotification.php +++ b/app/Notification/ActivityStreamNotification.php @@ -36,7 +36,7 @@ class ActivityStreamNotification extends Base implements NotificationInterface public function notifyProject(array $project, $event_name, array $event_data) { if ($this->userSession->isLogged()) { - $this->projectActivity->createEvent( + $this->projectActivityModel->createEvent( $project['id'], $event_data['task']['id'], $this->userSession->getId(), diff --git a/app/Notification/MailNotification.php b/app/Notification/MailNotification.php index 0ba06715..2d27179c 100644 --- a/app/Notification/MailNotification.php +++ b/app/Notification/MailNotification.php @@ -4,10 +4,10 @@ namespace Kanboard\Notification; use Kanboard\Core\Base; use Kanboard\Core\Notification\NotificationInterface; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFile; -use Kanboard\Model\Comment; -use Kanboard\Model\Subtask; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\SubtaskModel; /** * Email Notification @@ -68,7 +68,7 @@ class MailNotification extends Base implements NotificationInterface { return $this->template->render( 'notification/'.str_replace('.', '_', $event_name), - $event_data + array('application_url' => $this->config->get('application_url')) + $event_data + array('application_url' => $this->configModel->get('application_url')) ); } @@ -83,50 +83,50 @@ class MailNotification extends Base implements NotificationInterface public function getMailSubject($event_name, array $event_data) { switch ($event_name) { - case TaskFile::EVENT_CREATE: + case TaskFileModel::EVENT_CREATE: $subject = $this->getStandardMailSubject(e('New attachment'), $event_data); break; - case Comment::EVENT_CREATE: + case CommentModel::EVENT_CREATE: $subject = $this->getStandardMailSubject(e('New comment'), $event_data); break; - case Comment::EVENT_UPDATE: + case CommentModel::EVENT_UPDATE: $subject = $this->getStandardMailSubject(e('Comment updated'), $event_data); break; - case Subtask::EVENT_CREATE: + case SubtaskModel::EVENT_CREATE: $subject = $this->getStandardMailSubject(e('New subtask'), $event_data); break; - case Subtask::EVENT_UPDATE: + case SubtaskModel::EVENT_UPDATE: $subject = $this->getStandardMailSubject(e('Subtask updated'), $event_data); break; - case Task::EVENT_CREATE: + case TaskModel::EVENT_CREATE: $subject = $this->getStandardMailSubject(e('New task'), $event_data); break; - case Task::EVENT_UPDATE: + case TaskModel::EVENT_UPDATE: $subject = $this->getStandardMailSubject(e('Task updated'), $event_data); break; - case Task::EVENT_CLOSE: + case TaskModel::EVENT_CLOSE: $subject = $this->getStandardMailSubject(e('Task closed'), $event_data); break; - case Task::EVENT_OPEN: + case TaskModel::EVENT_OPEN: $subject = $this->getStandardMailSubject(e('Task opened'), $event_data); break; - case Task::EVENT_MOVE_COLUMN: + case TaskModel::EVENT_MOVE_COLUMN: $subject = $this->getStandardMailSubject(e('Column change'), $event_data); break; - case Task::EVENT_MOVE_POSITION: + case TaskModel::EVENT_MOVE_POSITION: $subject = $this->getStandardMailSubject(e('Position change'), $event_data); break; - case Task::EVENT_MOVE_SWIMLANE: + case TaskModel::EVENT_MOVE_SWIMLANE: $subject = $this->getStandardMailSubject(e('Swimlane change'), $event_data); break; - case Task::EVENT_ASSIGNEE_CHANGE: + case TaskModel::EVENT_ASSIGNEE_CHANGE: $subject = $this->getStandardMailSubject(e('Assignee change'), $event_data); break; - case Task::EVENT_USER_MENTION: - case Comment::EVENT_USER_MENTION: + case TaskModel::EVENT_USER_MENTION: + case CommentModel::EVENT_USER_MENTION: $subject = $this->getStandardMailSubject(e('Mentioned'), $event_data); break; - case Task::EVENT_OVERDUE: + case TaskModel::EVENT_OVERDUE: $subject = e('[%s] Overdue tasks', $event_data['project_name']); break; default: diff --git a/app/Notification/WebNotification.php b/app/Notification/WebNotification.php index 99c0c903..d8818828 100644 --- a/app/Notification/WebNotification.php +++ b/app/Notification/WebNotification.php @@ -30,7 +30,7 @@ class WebNotification extends Base implements NotificationInterface */ public function notifyUser(array $user, $event_name, array $event_data) { - $this->userUnreadNotification->create($user['id'], $event_name, $event_data); + $this->userUnreadNotificationModel->create($user['id'], $event_name, $event_data); } /** diff --git a/app/Notification/WebhookNotification.php b/app/Notification/WebhookNotification.php index 25d59251..16045535 100644 --- a/app/Notification/WebhookNotification.php +++ b/app/Notification/WebhookNotification.php @@ -35,8 +35,8 @@ class WebhookNotification extends Base implements NotificationInterface */ public function notifyProject(array $project, $event_name, array $event_data) { - $url = $this->config->get('webhook_url'); - $token = $this->config->get('webhook_token'); + $url = $this->configModel->get('webhook_url'); + $token = $this->configModel->get('webhook_token'); if (! empty($url)) { if (strpos($url, '?') !== false) { diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index aa0f1111..3e6efb02 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -27,60 +27,60 @@ class ClassProvider implements ServiceProviderInterface 'AverageTimeSpentColumnAnalytic', ), 'Model' => array( - 'Action', - 'ActionParameter', - 'AvatarFile', - 'Board', - 'Category', - 'Color', - 'Column', - 'Comment', - 'Config', - 'Currency', - 'CustomFilter', - 'Group', - 'GroupMember', - 'Language', - 'LastLogin', - 'Link', - 'Notification', - 'PasswordReset', - 'Project', - 'ProjectFile', - 'ProjectActivity', - 'ProjectDuplication', - 'ProjectDailyColumnStats', - 'ProjectDailyStats', - 'ProjectPermission', - 'ProjectNotification', - 'ProjectMetadata', - 'ProjectGroupRole', - 'ProjectUserRole', - 'RememberMeSession', - 'Subtask', - 'SubtaskTimeTracking', - 'Swimlane', - 'Task', - 'TaskAnalytic', - 'TaskCreation', - 'TaskDuplication', - 'TaskExternalLink', - 'TaskFinder', - 'TaskFile', - 'TaskLink', - 'TaskModification', - 'TaskPosition', - 'TaskStatus', - 'TaskMetadata', - 'Timezone', - 'Transition', - 'User', - 'UserLocking', - 'UserMention', - 'UserNotification', - 'UserNotificationFilter', - 'UserUnreadNotification', - 'UserMetadata', + 'ActionModel', + 'ActionParameterModel', + 'AvatarFileModel', + 'BoardModel', + 'CategoryModel', + 'ColorModel', + 'ColumnModel', + 'CommentModel', + 'ConfigModel', + 'CurrencyModel', + 'CustomFilterModel', + 'GroupModel', + 'GroupMemberModel', + 'LanguageModel', + 'LastLoginModel', + 'LinkModel', + 'NotificationModel', + 'PasswordResetModel', + 'ProjectModel', + 'ProjectFileModel', + 'ProjectActivityModel', + 'ProjectDuplicationModel', + 'ProjectDailyColumnStatsModel', + 'ProjectDailyStatsModel', + 'ProjectPermissionModel', + 'ProjectNotificationModel', + 'ProjectMetadataModel', + 'ProjectGroupRoleModel', + 'ProjectUserRoleModel', + 'RememberMeSessionModel', + 'SubtaskModel', + 'SubtaskTimeTrackingModel', + 'SwimlaneModel', + 'TaskModel', + 'TaskAnalyticModel', + 'TaskCreationModel', + 'TaskDuplicationModel', + 'TaskExternalLinkModel', + 'TaskFinderModel', + 'TaskFileModel', + 'TaskLinkModel', + 'TaskModificationModel', + 'TaskPositionModel', + 'TaskStatusModel', + 'TaskMetadataModel', + 'TimezoneModel', + 'TransitionModel', + 'UserModel', + 'UserLockingModel', + 'UserMentionModel', + 'UserNotificationModel', + 'UserNotificationFilterModel', + 'UserUnreadNotificationModel', + 'UserMetadataModel', ), 'Validator' => array( 'ActionValidator', diff --git a/app/ServiceProvider/FilterProvider.php b/app/ServiceProvider/FilterProvider.php index b79c5185..cdef9ed8 100644 --- a/app/ServiceProvider/FilterProvider.php +++ b/app/ServiceProvider/FilterProvider.php @@ -27,10 +27,10 @@ use Kanboard\Filter\TaskStatusFilter; use Kanboard\Filter\TaskSubtaskAssigneeFilter; use Kanboard\Filter\TaskSwimlaneFilter; use Kanboard\Filter\TaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Pimple\Container; use Pimple\ServiceProviderInterface; @@ -61,7 +61,7 @@ class FilterProvider implements ServiceProviderInterface { $container['userQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['db']->table(User::TABLE)); + $builder->withQuery($c['db']->table(UserModel::TABLE)); return $builder; }); @@ -72,26 +72,26 @@ class FilterProvider implements ServiceProviderInterface { $container['projectGroupRoleQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['db']->table(ProjectGroupRole::TABLE)); + $builder->withQuery($c['db']->table(ProjectGroupRoleModel::TABLE)); return $builder; }); $container['projectUserRoleQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['db']->table(ProjectUserRole::TABLE)); + $builder->withQuery($c['db']->table(ProjectUserRoleModel::TABLE)); return $builder; }); $container['projectQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['db']->table(Project::TABLE)); + $builder->withQuery($c['db']->table(ProjectModel::TABLE)); return $builder; }); $container['projectActivityLexer'] = $container->factory(function ($c) { $builder = new LexerBuilder(); $builder - ->withQuery($c['projectActivity']->getQuery()) + ->withQuery($c['projectActivityModel']->getQuery()) ->withFilter(new ProjectActivityTaskTitleFilter(), true) ->withFilter(new ProjectActivityTaskStatusFilter()) ->withFilter(new ProjectActivityProjectNameFilter()) @@ -108,7 +108,7 @@ class FilterProvider implements ServiceProviderInterface $container['projectActivityQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['projectActivity']->getQuery()); + $builder->withQuery($c['projectActivityModel']->getQuery()); return $builder; }); @@ -120,7 +120,7 @@ class FilterProvider implements ServiceProviderInterface { $container['taskQuery'] = $container->factory(function ($c) { $builder = new QueryBuilder(); - $builder->withQuery($c['taskFinder']->getExtendedQuery()); + $builder->withQuery($c['taskFinderModel']->getExtendedQuery()); return $builder; }); @@ -128,13 +128,13 @@ class FilterProvider implements ServiceProviderInterface $builder = new LexerBuilder(); $builder - ->withQuery($c['taskFinder']->getExtendedQuery()) + ->withQuery($c['taskFinderModel']->getExtendedQuery()) ->withFilter(TaskAssigneeFilter::getInstance() ->setCurrentUserId($c['userSession']->getId()) ) ->withFilter(new TaskCategoryFilter()) ->withFilter(TaskColorFilter::getInstance() - ->setColorModel($c['color']) + ->setColorModel($c['colorModel']) ) ->withFilter(new TaskColumnFilter()) ->withFilter(new TaskCommentFilter()) diff --git a/app/ServiceProvider/NotificationProvider.php b/app/ServiceProvider/NotificationProvider.php index 2cb01576..a0571209 100644 --- a/app/ServiceProvider/NotificationProvider.php +++ b/app/ServiceProvider/NotificationProvider.php @@ -4,8 +4,8 @@ namespace Kanboard\ServiceProvider; use Pimple\Container; use Pimple\ServiceProviderInterface; -use Kanboard\Model\UserNotificationType; -use Kanboard\Model\ProjectNotificationType; +use Kanboard\Model\UserNotificationTypeModel; +use Kanboard\Model\ProjectNotificationTypeModel; use Kanboard\Notification\MailNotification as MailNotification; use Kanboard\Notification\WebNotification as WebNotification; @@ -26,15 +26,15 @@ class NotificationProvider implements ServiceProviderInterface */ public function register(Container $container) { - $container['userNotificationType'] = function ($container) { - $type = new UserNotificationType($container); + $container['userNotificationTypeModel'] = function ($container) { + $type = new UserNotificationTypeModel($container); $type->setType(MailNotification::TYPE, t('Email'), '\Kanboard\Notification\MailNotification'); $type->setType(WebNotification::TYPE, t('Web'), '\Kanboard\Notification\WebNotification'); return $type; }; - $container['projectNotificationType'] = function ($container) { - $type = new ProjectNotificationType($container); + $container['projectNotificationTypeModel'] = function ($container) { + $type = new ProjectNotificationTypeModel($container); $type->setType('webhook', 'Webhook', '\Kanboard\Notification\WebhookNotification', true); $type->setType('activity_stream', 'ActivityStream', '\Kanboard\Notification\ActivityStreamNotification', true); return $type; diff --git a/app/Subscriber/AuthSubscriber.php b/app/Subscriber/AuthSubscriber.php index dfb95a00..0097c407 100644 --- a/app/Subscriber/AuthSubscriber.php +++ b/app/Subscriber/AuthSubscriber.php @@ -45,9 +45,9 @@ class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface $userAgent = $this->request->getUserAgent(); $ipAddress = $this->request->getIpAddress(); - $this->userLocking->resetFailedLogin($this->userSession->getUsername()); + $this->userLockingModel->resetFailedLogin($this->userSession->getUsername()); - $this->lastLogin->create( + $this->lastLoginModel->create( $event->getAuthType(), $this->userSession->getId(), $ipAddress, @@ -59,7 +59,7 @@ class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface } if (isset($this->sessionStorage->hasRememberMe) && $this->sessionStorage->hasRememberMe) { - $session = $this->rememberMeSession->create($this->userSession->getId(), $ipAddress, $userAgent); + $session = $this->rememberMeSessionModel->create($this->userSession->getId(), $ipAddress, $userAgent); $this->rememberMeCookie->write($session['token'], $session['sequence'], $session['expiration']); } } @@ -75,10 +75,10 @@ class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface $credentials = $this->rememberMeCookie->read(); if ($credentials !== false) { - $session = $this->rememberMeSession->find($credentials['token'], $credentials['sequence']); + $session = $this->rememberMeSessionModel->find($credentials['token'], $credentials['sequence']); if (! empty($session)) { - $this->rememberMeSession->remove($session['id']); + $this->rememberMeSessionModel->remove($session['id']); } $this->rememberMeCookie->remove(); @@ -97,10 +97,10 @@ class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface $username = $event->getUsername(); if (! empty($username)) { - $this->userLocking->incrementFailedLogin($username); + $this->userLockingModel->incrementFailedLogin($username); - if ($this->userLocking->getFailedLogin($username) > BRUTEFORCE_LOCKDOWN) { - $this->userLocking->lock($username, BRUTEFORCE_LOCKDOWN_DURATION); + if ($this->userLockingModel->getFailedLogin($username) > BRUTEFORCE_LOCKDOWN) { + $this->userLockingModel->lock($username, BRUTEFORCE_LOCKDOWN_DURATION); } } } diff --git a/app/Subscriber/BootstrapSubscriber.php b/app/Subscriber/BootstrapSubscriber.php index e60840f1..7d12e9ae 100644 --- a/app/Subscriber/BootstrapSubscriber.php +++ b/app/Subscriber/BootstrapSubscriber.php @@ -16,12 +16,12 @@ class BootstrapSubscriber extends BaseSubscriber implements EventSubscriberInter public function execute() { $this->logger->debug('Subscriber executed: '.__METHOD__); - $this->language->loadCurrentLanguage(); - $this->timezone->setCurrentTimezone(); + $this->languageModel->loadCurrentLanguage(); + $this->timezoneModel->setCurrentTimezone(); $this->actionManager->attachEvents(); if ($this->userSession->isLogged()) { - $this->sessionStorage->hasSubtaskInProgress = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); + $this->sessionStorage->hasSubtaskInProgress = $this->subtaskModel->hasSubtaskInProgress($this->userSession->getId()); } } diff --git a/app/Subscriber/LdapUserPhotoSubscriber.php b/app/Subscriber/LdapUserPhotoSubscriber.php index 3cf46077..93672cd1 100644 --- a/app/Subscriber/LdapUserPhotoSubscriber.php +++ b/app/Subscriber/LdapUserPhotoSubscriber.php @@ -42,7 +42,7 @@ class LdapUserPhotoSubscriber extends BaseSubscriber implements EventSubscriberI if (empty($profile['avatar_path']) && ! empty($photo)) { $this->logger->info('Saving user photo from LDAP profile'); - $this->avatarFile->uploadImageContent($profile['id'], $photo); + $this->avatarFileModel->uploadImageContent($profile['id'], $photo); } } } diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php index 2a1fe6c7..db11e585 100644 --- a/app/Subscriber/NotificationSubscriber.php +++ b/app/Subscriber/NotificationSubscriber.php @@ -4,10 +4,10 @@ namespace Kanboard\Subscriber; use Kanboard\Event\GenericEvent; use Kanboard\Job\NotificationJob; -use Kanboard\Model\Task; -use Kanboard\Model\Comment; -use Kanboard\Model\Subtask; -use Kanboard\Model\TaskFile; +use Kanboard\Model\TaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\TaskFileModel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class NotificationSubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -15,21 +15,21 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn public static function getSubscribedEvents() { return array( - Task::EVENT_USER_MENTION => 'handleEvent', - Task::EVENT_CREATE => 'handleEvent', - Task::EVENT_UPDATE => 'handleEvent', - Task::EVENT_CLOSE => 'handleEvent', - Task::EVENT_OPEN => 'handleEvent', - Task::EVENT_MOVE_COLUMN => 'handleEvent', - Task::EVENT_MOVE_POSITION => 'handleEvent', - Task::EVENT_MOVE_SWIMLANE => 'handleEvent', - Task::EVENT_ASSIGNEE_CHANGE => 'handleEvent', - Subtask::EVENT_CREATE => 'handleEvent', - Subtask::EVENT_UPDATE => 'handleEvent', - Comment::EVENT_CREATE => 'handleEvent', - Comment::EVENT_UPDATE => 'handleEvent', - Comment::EVENT_USER_MENTION => 'handleEvent', - TaskFile::EVENT_CREATE => 'handleEvent', + TaskModel::EVENT_USER_MENTION => 'handleEvent', + TaskModel::EVENT_CREATE => 'handleEvent', + TaskModel::EVENT_UPDATE => 'handleEvent', + TaskModel::EVENT_CLOSE => 'handleEvent', + TaskModel::EVENT_OPEN => 'handleEvent', + TaskModel::EVENT_MOVE_COLUMN => 'handleEvent', + TaskModel::EVENT_MOVE_POSITION => 'handleEvent', + TaskModel::EVENT_MOVE_SWIMLANE => 'handleEvent', + TaskModel::EVENT_ASSIGNEE_CHANGE => 'handleEvent', + SubtaskModel::EVENT_CREATE => 'handleEvent', + SubtaskModel::EVENT_UPDATE => 'handleEvent', + CommentModel::EVENT_CREATE => 'handleEvent', + CommentModel::EVENT_UPDATE => 'handleEvent', + CommentModel::EVENT_USER_MENTION => 'handleEvent', + TaskFileModel::EVENT_CREATE => 'handleEvent', ); } diff --git a/app/Subscriber/ProjectDailySummarySubscriber.php b/app/Subscriber/ProjectDailySummarySubscriber.php index 982240c1..6971a121 100644 --- a/app/Subscriber/ProjectDailySummarySubscriber.php +++ b/app/Subscriber/ProjectDailySummarySubscriber.php @@ -4,7 +4,7 @@ namespace Kanboard\Subscriber; use Kanboard\Event\TaskEvent; use Kanboard\Job\ProjectMetricJob; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ProjectDailySummarySubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -12,11 +12,11 @@ class ProjectDailySummarySubscriber extends BaseSubscriber implements EventSubsc public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE_UPDATE => 'execute', - Task::EVENT_CLOSE => 'execute', - Task::EVENT_OPEN => 'execute', - Task::EVENT_MOVE_COLUMN => 'execute', - Task::EVENT_MOVE_SWIMLANE => 'execute', + TaskModel::EVENT_CREATE_UPDATE => 'execute', + TaskModel::EVENT_CLOSE => 'execute', + TaskModel::EVENT_OPEN => 'execute', + TaskModel::EVENT_MOVE_COLUMN => 'execute', + TaskModel::EVENT_MOVE_SWIMLANE => 'execute', ); } diff --git a/app/Subscriber/ProjectModificationDateSubscriber.php b/app/Subscriber/ProjectModificationDateSubscriber.php index 62804a84..fee04eaa 100644 --- a/app/Subscriber/ProjectModificationDateSubscriber.php +++ b/app/Subscriber/ProjectModificationDateSubscriber.php @@ -3,7 +3,7 @@ namespace Kanboard\Subscriber; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ProjectModificationDateSubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -11,14 +11,14 @@ class ProjectModificationDateSubscriber extends BaseSubscriber implements EventS public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE_UPDATE => 'execute', - Task::EVENT_CLOSE => 'execute', - Task::EVENT_OPEN => 'execute', - Task::EVENT_MOVE_SWIMLANE => 'execute', - Task::EVENT_MOVE_COLUMN => 'execute', - Task::EVENT_MOVE_POSITION => 'execute', - Task::EVENT_MOVE_PROJECT => 'execute', - Task::EVENT_ASSIGNEE_CHANGE => 'execute', + TaskModel::EVENT_CREATE_UPDATE => 'execute', + TaskModel::EVENT_CLOSE => 'execute', + TaskModel::EVENT_OPEN => 'execute', + TaskModel::EVENT_MOVE_SWIMLANE => 'execute', + TaskModel::EVENT_MOVE_COLUMN => 'execute', + TaskModel::EVENT_MOVE_POSITION => 'execute', + TaskModel::EVENT_MOVE_PROJECT => 'execute', + TaskModel::EVENT_ASSIGNEE_CHANGE => 'execute', ); } @@ -26,7 +26,7 @@ class ProjectModificationDateSubscriber extends BaseSubscriber implements EventS { if (isset($event['project_id']) && !$this->isExecuted()) { $this->logger->debug('Subscriber executed: '.__METHOD__); - $this->project->updateModificationDate($event['project_id']); + $this->projectModel->updateModificationDate($event['project_id']); } } } diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php index 09a5665a..75b7ff76 100644 --- a/app/Subscriber/RecurringTaskSubscriber.php +++ b/app/Subscriber/RecurringTaskSubscriber.php @@ -3,7 +3,7 @@ namespace Kanboard\Subscriber; use Kanboard\Event\TaskEvent; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -11,8 +11,8 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => 'onMove', - Task::EVENT_CLOSE => 'onClose', + TaskModel::EVENT_MOVE_COLUMN => 'onMove', + TaskModel::EVENT_CLOSE => 'onClose', ); } @@ -20,11 +20,11 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI { $this->logger->debug('Subscriber executed: '.__METHOD__); - if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING) { - if ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_FIRST_COLUMN && $this->column->getFirstColumnId($event['project_id']) == $event['src_column_id']) { - $this->taskDuplication->duplicateRecurringTask($event['task_id']); - } elseif ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_LAST_COLUMN && $this->column->getLastColumnId($event['project_id']) == $event['dst_column_id']) { - $this->taskDuplication->duplicateRecurringTask($event['task_id']); + if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { + if ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($event['project_id']) == $event['src_column_id']) { + $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); + } elseif ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($event['project_id']) == $event['dst_column_id']) { + $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); } } } @@ -33,8 +33,8 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI { $this->logger->debug('Subscriber executed: '.__METHOD__); - if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == Task::RECURRING_TRIGGER_CLOSE) { - $this->taskDuplication->duplicateRecurringTask($event['task_id']); + if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) { + $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); } } } diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php index c0852bc8..7e39c126 100644 --- a/app/Subscriber/SubtaskTimeTrackingSubscriber.php +++ b/app/Subscriber/SubtaskTimeTrackingSubscriber.php @@ -3,7 +3,7 @@ namespace Kanboard\Subscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Kanboard\Model\Subtask; +use Kanboard\Model\SubtaskModel; use Kanboard\Event\SubtaskEvent; class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -11,9 +11,9 @@ class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubsc public static function getSubscribedEvents() { return array( - Subtask::EVENT_CREATE => 'updateTaskTime', - Subtask::EVENT_DELETE => 'updateTaskTime', - Subtask::EVENT_UPDATE => array( + SubtaskModel::EVENT_CREATE => 'updateTaskTime', + SubtaskModel::EVENT_DELETE => 'updateTaskTime', + SubtaskModel::EVENT_UPDATE => array( array('logStartEnd', 10), array('updateTaskTime', 0), ) @@ -24,24 +24,24 @@ class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubsc { if (isset($event['task_id'])) { $this->logger->debug('Subscriber executed: '.__METHOD__); - $this->subtaskTimeTracking->updateTaskTimeTracking($event['task_id']); + $this->subtaskTimeTrackingModel->updateTaskTimeTracking($event['task_id']); } } public function logStartEnd(SubtaskEvent $event) { - if (isset($event['status']) && $this->config->get('subtask_time_tracking') == 1) { + if (isset($event['status']) && $this->configModel->get('subtask_time_tracking') == 1) { $this->logger->debug('Subscriber executed: '.__METHOD__); - $subtask = $this->subtask->getById($event['id']); + $subtask = $this->subtaskModel->getById($event['id']); if (empty($subtask['user_id'])) { return false; } - if ($subtask['status'] == Subtask::STATUS_INPROGRESS) { - return $this->subtaskTimeTracking->logStartTime($subtask['id'], $subtask['user_id']); + if ($subtask['status'] == SubtaskModel::STATUS_INPROGRESS) { + return $this->subtaskTimeTrackingModel->logStartTime($subtask['id'], $subtask['user_id']); } else { - return $this->subtaskTimeTracking->logEndTime($subtask['id'], $subtask['user_id']); + return $this->subtaskTimeTrackingModel->logEndTime($subtask['id'], $subtask['user_id']); } } } diff --git a/app/Subscriber/TransitionSubscriber.php b/app/Subscriber/TransitionSubscriber.php index bd537484..26d08f88 100644 --- a/app/Subscriber/TransitionSubscriber.php +++ b/app/Subscriber/TransitionSubscriber.php @@ -3,7 +3,7 @@ namespace Kanboard\Subscriber; use Kanboard\Event\TaskEvent; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class TransitionSubscriber extends BaseSubscriber implements EventSubscriberInterface @@ -11,7 +11,7 @@ class TransitionSubscriber extends BaseSubscriber implements EventSubscriberInte public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => 'execute', + TaskModel::EVENT_MOVE_COLUMN => 'execute', ); } @@ -22,7 +22,7 @@ class TransitionSubscriber extends BaseSubscriber implements EventSubscriberInte $user_id = $this->userSession->getId(); if (! empty($user_id)) { - $this->transition->save($user_id, $event->getAll()); + $this->transitionModel->save($user_id, $event->getAll()); } } } diff --git a/app/Template/analytic/compare_hours.php b/app/Template/analytic/compare_hours.php index 03a2981a..70d8d02b 100644 --- a/app/Template/analytic/compare_hours.php +++ b/app/Template/analytic/compare_hours.php @@ -40,7 +40,7 @@ url->link($this->text->e($task['title']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?> - + diff --git a/app/Template/board/task_footer.php b/app/Template/board/task_footer.php index 8cf3e709..11df8962 100644 --- a/app/Template/board/task_footer.php +++ b/app/Template/board/task_footer.php @@ -33,11 +33,11 @@ - + - + diff --git a/app/Template/dashboard/projects.php b/app/Template/dashboard/projects.php index 4aa40621..5bf92980 100644 --- a/app/Template/dashboard/projects.php +++ b/app/Template/dashboard/projects.php @@ -8,7 +8,7 @@ order('Id', 'id') ?> order('', 'is_private') ?> - order(t('Project'), \Kanboard\Model\Project::TABLE.'.name') ?> + order(t('Project'), \Kanboard\Model\ProjectModel::TABLE.'.name') ?> getCollection() as $project): ?> diff --git a/app/Template/project_creation/create.php b/app/Template/project_creation/create.php index fb892012..01d06bab 100644 --- a/app/Template/project_creation/create.php +++ b/app/Template/project_creation/create.php @@ -22,10 +22,10 @@ form->checkbox('projectPermission', t('Permissions'), 1, true) ?> - form->checkbox('category', t('Categories'), 1, true) ?> - form->checkbox('action', t('Actions'), 1, true) ?> - form->checkbox('swimlane', t('Swimlanes'), 1, true) ?> - form->checkbox('task', t('Tasks'), 1, false) ?> + form->checkbox('categoryModel', t('Categories'), 1, true) ?> + form->checkbox('actionModel', t('Actions'), 1, true) ?> + form->checkbox('swimlaneModel', t('Swimlanes'), 1, true) ?> + form->checkbox('taskModel', t('Tasks'), 1, false) ?>
diff --git a/app/Template/project_view/duplicate.php b/app/Template/project_view/duplicate.php index 41ae39df..d2cd127a 100644 --- a/app/Template/project_view/duplicate.php +++ b/app/Template/project_view/duplicate.php @@ -14,11 +14,11 @@ form->checkbox('projectPermission', t('Permissions'), 1, true) ?> - form->checkbox('category', t('Categories'), 1, true) ?> - form->checkbox('action', t('Actions'), 1, true) ?> - form->checkbox('swimlane', t('Swimlanes'), 1, false) ?> - form->checkbox('task', t('Tasks'), 1, false) ?> - form->checkbox('projectMetadata', t('Metadata'), 1, false) ?> + form->checkbox('categoryModel', t('Categories'), 1, true) ?> + form->checkbox('actionModel', t('Actions'), 1, true) ?> + form->checkbox('swimlaneModel', t('Swimlanes'), 1, false) ?> + form->checkbox('taskModel', t('Tasks'), 1, false) ?> + form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?>
diff --git a/app/Template/search/results.php b/app/Template/search/results.php index 97667c75..8376b9e8 100644 --- a/app/Template/search/results.php +++ b/app/Template/search/results.php @@ -41,7 +41,7 @@ dt->date($task['date_due']) ?> - + diff --git a/app/Template/task/time_tracking_details.php b/app/Template/task/time_tracking_details.php index d86273c5..1a179522 100644 --- a/app/Template/task/time_tracking_details.php +++ b/app/Template/task/time_tracking_details.php @@ -14,7 +14,7 @@ order(t('Subtask'), 'subtask_title') ?> order(t('Start'), 'start') ?> order(t('End'), 'end') ?> - order(t('Time spent'), \Kanboard\Model\SubtaskTimeTracking::TABLE.'.time_spent') ?> + order(t('Time spent'), \Kanboard\Model\SubtaskTimeTrackingModel::TABLE.'.time_spent') ?> getCollection() as $record): ?> diff --git a/app/Template/task_list/show.php b/app/Template/task_list/show.php index 9ffcb2e8..bb95b6a3 100644 --- a/app/Template/task_list/show.php +++ b/app/Template/task_list/show.php @@ -47,7 +47,7 @@ dt->date($task['date_due']) ?> - + diff --git a/app/Template/task_recurrence/edit.php b/app/Template/task_recurrence/edit.php index 550db2f8..09d14826 100644 --- a/app/Template/task_recurrence/edit.php +++ b/app/Template/task_recurrence/edit.php @@ -2,7 +2,7 @@

- +
render('task_recurrence/info', array( 'task' => $task, @@ -13,7 +13,7 @@
- +
diff --git a/app/Template/task_recurrence/info.php b/app/Template/task_recurrence/info.php index 97794604..04d58c7f 100644 --- a/app/Template/task_recurrence/info.php +++ b/app/Template/task_recurrence/info.php @@ -1,7 +1,7 @@
    - +
  • - +
    • diff --git a/app/User/Avatar/GravatarProvider.php b/app/User/Avatar/GravatarProvider.php index 87ca51b1..e066d766 100644 --- a/app/User/Avatar/GravatarProvider.php +++ b/app/User/Avatar/GravatarProvider.php @@ -37,6 +37,6 @@ class GravatarProvider extends Base implements AvatarProviderInterface */ public function isActive(array $user) { - return !empty($user['email']) && $this->config->get('integration_gravatar') == 1; + return !empty($user['email']) && $this->configModel->get('integration_gravatar') == 1; } } diff --git a/app/User/LdapUserProvider.php b/app/User/LdapUserProvider.php index 74cf4cd5..274d7665 100644 --- a/app/User/LdapUserProvider.php +++ b/app/User/LdapUserProvider.php @@ -3,7 +3,7 @@ namespace Kanboard\User; use Kanboard\Core\User\UserProviderInterface; -use Kanboard\Model\Language; +use Kanboard\Model\LanguageModel; /** * LDAP User Provider @@ -211,7 +211,7 @@ class LdapUserProvider implements UserProviderInterface $attributes = array('is_ldap_user' => 1); if (! empty($this->language)) { - $attributes['language'] = Language::findCode($this->language); + $attributes['language'] = LanguageModel::findCode($this->language); } return $attributes; diff --git a/app/Validator/AuthValidator.php b/app/Validator/AuthValidator.php index cd6e04d5..14d66ee4 100644 --- a/app/Validator/AuthValidator.php +++ b/app/Validator/AuthValidator.php @@ -59,7 +59,7 @@ class AuthValidator extends Base $result = true; $errors = array(); - if ($this->userLocking->isLocked($values['username'])) { + if ($this->userLockingModel->isLocked($values['username'])) { $result = false; $errors['login'] = t('Your account is locked for %d minutes', BRUTEFORCE_LOCKDOWN_DURATION); $this->logger->error('Account locked: '.$values['username']); @@ -100,7 +100,7 @@ class AuthValidator extends Base $result = true; $errors = array(); - if ($this->userLocking->hasCaptcha($values['username'])) { + if ($this->userLockingModel->hasCaptcha($values['username'])) { if (! isset($this->sessionStorage->captcha)) { $result = false; } else { diff --git a/app/Validator/GroupValidator.php b/app/Validator/GroupValidator.php index 2226abd3..2946ca23 100644 --- a/app/Validator/GroupValidator.php +++ b/app/Validator/GroupValidator.php @@ -4,7 +4,7 @@ namespace Kanboard\Validator; use SimpleValidator\Validator; use SimpleValidator\Validators; -use Kanboard\Model\Group; +use Kanboard\Model\GroupModel; /** * Group Validator @@ -63,7 +63,7 @@ class GroupValidator extends Base return array( new Validators\Required('name', t('The name is required')), new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100), - new Validators\Unique('name', t('The name must be unique'), $this->db->getConnection(), Group::TABLE, 'id'), + new Validators\Unique('name', t('The name must be unique'), $this->db->getConnection(), GroupModel::TABLE, 'id'), new Validators\MaxLength('external_id', t('The maximum length is %d characters', 255), 255), new Validators\Integer('id', t('This value must be an integer')), ); diff --git a/app/Validator/LinkValidator.php b/app/Validator/LinkValidator.php index 10a826da..2a9967a2 100644 --- a/app/Validator/LinkValidator.php +++ b/app/Validator/LinkValidator.php @@ -4,7 +4,7 @@ namespace Kanboard\Validator; use SimpleValidator\Validator; use SimpleValidator\Validators; -use Kanboard\Model\Link; +use Kanboard\Model\LinkModel; /** * Link Validator @@ -25,7 +25,7 @@ class LinkValidator extends Base { $v = new Validator($values, array( new Validators\Required('label', t('Field required')), - new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), Link::TABLE), + new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), LinkModel::TABLE), new Validators\NotEquals('label', 'opposite_label', t('The labels must be different')), )); @@ -48,7 +48,7 @@ class LinkValidator extends Base new Validators\Required('id', t('Field required')), new Validators\Required('opposite_id', t('Field required')), new Validators\Required('label', t('Field required')), - new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), Link::TABLE), + new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), LinkModel::TABLE), )); return array( diff --git a/app/Validator/ProjectValidator.php b/app/Validator/ProjectValidator.php index 1c6c90f8..b1406a2f 100644 --- a/app/Validator/ProjectValidator.php +++ b/app/Validator/ProjectValidator.php @@ -4,7 +4,7 @@ namespace Kanboard\Validator; use SimpleValidator\Validator; use SimpleValidator\Validators; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; /** * Project Validator @@ -34,7 +34,7 @@ class ProjectValidator extends Base new Validators\MaxLength('start_date', t('The maximum length is %d characters', 10), 10), new Validators\MaxLength('end_date', t('The maximum length is %d characters', 10), 10), new Validators\AlphaNumeric('identifier', t('This value must be alphanumeric')) , - new Validators\Unique('identifier', t('The identifier must be unique'), $this->db->getConnection(), Project::TABLE), + new Validators\Unique('identifier', t('The identifier must be unique'), $this->db->getConnection(), ProjectModel::TABLE), ); } diff --git a/app/Validator/TaskLinkValidator.php b/app/Validator/TaskLinkValidator.php index c88c2b16..1c167e4c 100644 --- a/app/Validator/TaskLinkValidator.php +++ b/app/Validator/TaskLinkValidator.php @@ -4,7 +4,7 @@ namespace Kanboard\Validator; use SimpleValidator\Validator; use SimpleValidator\Validators; -use Kanboard\Model\Task; +use Kanboard\Model\TaskModel; /** * Task Link Validator @@ -27,7 +27,7 @@ class TaskLinkValidator extends Base new Validators\Required('opposite_task_id', t('Field required')), new Validators\Required('link_id', t('Field required')), new Validators\NotEquals('opposite_task_id', 'task_id', t('A task cannot be linked to itself')), - new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), Task::TABLE, 'id') + new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), TaskModel::TABLE, 'id') ); } diff --git a/app/Validator/UserValidator.php b/app/Validator/UserValidator.php index e5953f30..1a24f23e 100644 --- a/app/Validator/UserValidator.php +++ b/app/Validator/UserValidator.php @@ -4,7 +4,7 @@ namespace Kanboard\Validator; use SimpleValidator\Validator; use SimpleValidator\Validators; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; /** * User Validator @@ -25,7 +25,7 @@ class UserValidator extends Base return array( new Validators\MaxLength('role', t('The maximum length is %d characters', 25), 25), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), - new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), User::TABLE, 'id'), + new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), UserModel::TABLE, 'id'), new Validators\Email('email', t('Email address invalid')), new Validators\Integer('is_ldap_user', t('This value must be an integer')), ); diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php index 5fed0368..f552bea9 100644 --- a/tests/integration/ApiTest.php +++ b/tests/integration/ApiTest.php @@ -51,9 +51,9 @@ class Api extends PHPUnit_Framework_TestCase if ($projects) { foreach ($projects as $project) { - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); $this->assertTrue($this->client->removeProject($project['id'])); } } @@ -71,9 +71,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); } public function testGetProjectByName() @@ -81,9 +81,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectByName('API test'); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); $project = $this->client->getProjectByName(array('name' => 'API test')); $this->assertNotEmpty($project); @@ -100,9 +100,9 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEmpty($projects); foreach ($projects as $project) { - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); } } @@ -235,7 +235,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($task); $this->assertTrue(is_array($task)); $this->assertEquals('Task #1', $task['title']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } public function testGetAllTasks() @@ -245,7 +245,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($tasks); $this->assertTrue(is_array($tasks)); $this->assertEquals('Task #1', $tasks[0]['title']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); $tasks = $this->client->getAllTasks(2, 0); @@ -896,7 +896,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEmpty($task); $this->assertEquals('Task with external ticket number', $task['title']); $this->assertEquals('TICKET-1234', $task['reference']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } public function testCreateOverdueTask() diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php index 9615865d..5eaf515e 100644 --- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php +++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php @@ -3,10 +3,10 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Comment; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\CommentCreationMoveTaskColumn; class CommentCreationMoveTaskColumnTest extends Base @@ -15,9 +15,9 @@ class CommentCreationMoveTaskColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -28,7 +28,7 @@ class CommentCreationMoveTaskColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); @@ -39,8 +39,8 @@ class CommentCreationMoveTaskColumnTest extends Base public function testWithUserNotLogged() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -51,6 +51,6 @@ class CommentCreationMoveTaskColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php index a2e52dc6..4a2fc386 100644 --- a/tests/units/Action/CommentCreationTest.php +++ b/tests/units/Action/CommentCreationTest.php @@ -3,11 +3,11 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Comment; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Action\CommentCreation; use Kanboard\Core\Security\Role; @@ -15,11 +15,11 @@ class CommentCreationTest extends Base { public function testSuccess() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -44,10 +44,10 @@ class CommentCreationTest extends Base public function testWithUserNotAssignable() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -71,9 +71,9 @@ class CommentCreationTest extends Base public function testWithNoComment() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php index b386d9bf..09c08264 100644 --- a/tests/units/Action/TaskAssignCategoryColorTest.php +++ b/tests/units/Action/TaskAssignCategoryColorTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCategoryColor; class TaskAssignCategoryColorTest extends Base { public function testChangeCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -30,7 +30,7 @@ class TaskAssignCategoryColorTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,9 +39,9 @@ class TaskAssignCategoryColorTest extends Base public function testWithWrongColor() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -54,6 +54,6 @@ class TaskAssignCategoryColorTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignCategoryLabelTest.php b/tests/units/Action/TaskAssignCategoryLabelTest.php index ba988a72..1ddb1f7a 100644 --- a/tests/units/Action/TaskAssignCategoryLabelTest.php +++ b/tests/units/Action/TaskAssignCategoryLabelTest.php @@ -3,20 +3,20 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskAssignCategoryLabel; class TaskAssignCategoryLabelTest extends Base { public function testChangeCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -39,9 +39,9 @@ class TaskAssignCategoryLabelTest extends Base public function testWithWrongLabel() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -60,9 +60,9 @@ class TaskAssignCategoryLabelTest extends Base public function testWithExistingCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php index ba0e7152..712c3c02 100644 --- a/tests/units/Action/TaskAssignCategoryLinkTest.php +++ b/tests/units/Action/TaskAssignCategoryLinkTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\TaskLink; -use Kanboard\Model\Category; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\CategoryModel; use Kanboard\Event\TaskLinkEvent; use Kanboard\Action\TaskAssignCategoryLink; @@ -14,10 +14,10 @@ class TaskAssignCategoryLinkTest extends Base { public function testAssignCategory() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -35,7 +35,7 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); $task = $tf->getById(1); $this->assertEquals(1, $task['category_id']); @@ -43,10 +43,10 @@ class TaskAssignCategoryLinkTest extends Base public function testWhenLinkDontMatch() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -64,14 +64,14 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } public function testThatExistingCategoryWillNotChange() { - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -90,6 +90,6 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php index 86c855d1..6502035f 100644 --- a/tests/units/Action/TaskAssignColorCategoryTest.php +++ b/tests/units/Action/TaskAssignColorCategoryTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorCategory; class TaskAssignColorCategoryTest extends Base { public function testChangeColor() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -30,7 +30,7 @@ class TaskAssignColorCategoryTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,8 +39,8 @@ class TaskAssignColorCategoryTest extends Base public function testWithWrongCategory() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -52,6 +52,6 @@ class TaskAssignColorCategoryTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php index 130422b5..d4ba8e01 100644 --- a/tests/units/Action/TaskAssignColorColumnTest.php +++ b/tests/units/Action/TaskAssignColorColumnTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorColumn; class TaskAssignColorColumnTest extends Base { public function testChangeColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorColumnTest extends Base $action->setParam('color_id', 'red'); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,8 +36,8 @@ class TaskAssignColorColumnTest extends Base public function testWithWrongCategory() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -49,6 +49,6 @@ class TaskAssignColorColumnTest extends Base $action->setParam('color_id', 'red'); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php index 6df029d3..07d0969b 100644 --- a/tests/units/Action/TaskAssignColorLinkTest.php +++ b/tests/units/Action/TaskAssignColorLinkTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskLinkModel; use Kanboard\Action\TaskAssignColorLink; class TaskAssignColorLinkTest extends Base { public function testChangeColor() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorLinkTest extends Base $action->setParam('color_id', 'red'); $action->setParam('link_id', 1); - $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,8 +36,8 @@ class TaskAssignColorLinkTest extends Base public function testWithWrongLink() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -49,6 +49,6 @@ class TaskAssignColorLinkTest extends Base $action->setParam('color_id', 'red'); $action->setParam('link_id', 1); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorPriorityTest.php b/tests/units/Action/TaskAssignColorPriorityTest.php index be6d8727..2fce8e66 100644 --- a/tests/units/Action/TaskAssignColorPriorityTest.php +++ b/tests/units/Action/TaskAssignColorPriorityTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorPriority; class TaskAssignColorPriorityTest extends Base { public function testChangeColor() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -30,7 +30,7 @@ class TaskAssignColorPriorityTest extends Base $action->setParam('color_id', 'red'); $action->setParam('priority', 1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,8 +39,8 @@ class TaskAssignColorPriorityTest extends Base public function testWithWrongPriority() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -52,6 +52,6 @@ class TaskAssignColorPriorityTest extends Base $action->setParam('color_id', 'red'); $action->setParam('priority', 1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php index 76e2282c..370f9070 100644 --- a/tests/units/Action/TaskAssignColorUserTest.php +++ b/tests/units/Action/TaskAssignColorUserTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorUser; class TaskAssignColorUserTest extends Base { public function testChangeColor() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorUserTest extends Base $action->setParam('color_id', 'red'); $action->setParam('user_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,8 +36,8 @@ class TaskAssignColorUserTest extends Base public function testWithWrongUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -49,6 +49,6 @@ class TaskAssignColorUserTest extends Base $action->setParam('color_id', 'red'); $action->setParam('user_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php index a741076b..6fdbda63 100644 --- a/tests/units/Action/TaskAssignCurrentUserColumnTest.php +++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php @@ -3,10 +3,10 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCurrentUserColumn; class TaskAssignCurrentUserColumnTest extends Base @@ -15,9 +15,9 @@ class TaskAssignCurrentUserColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -28,7 +28,7 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,8 +39,8 @@ class TaskAssignCurrentUserColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -51,13 +51,13 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } public function testWithNoUserSession() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -68,6 +68,6 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php index 2f4b235f..5569a191 100644 --- a/tests/units/Action/TaskAssignCurrentUserTest.php +++ b/tests/units/Action/TaskAssignCurrentUserTest.php @@ -3,10 +3,10 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCurrentUser; class TaskAssignCurrentUserTest extends Base @@ -15,9 +15,9 @@ class TaskAssignCurrentUserTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignCurrentUserTest extends Base $action = new TaskAssignCurrentUser($this->container); $action->setProjectId(1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,8 +36,8 @@ class TaskAssignCurrentUserTest extends Base public function testWithNoUserSession() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -47,6 +47,6 @@ class TaskAssignCurrentUserTest extends Base $action = new TaskAssignCurrentUser($this->container); $action->setProjectId(1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE)); } } diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php index 7741e983..78ec314f 100644 --- a/tests/units/Action/TaskAssignSpecificUserTest.php +++ b/tests/units/Action/TaskAssignSpecificUserTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignSpecificUser; class TaskAssignSpecificUserTest extends Base { public function testChangeUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); @@ -27,7 +27,7 @@ class TaskAssignSpecificUserTest extends Base $action->setParam('column_id', 2); $action->setParam('user_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,8 +36,8 @@ class TaskAssignSpecificUserTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -49,6 +49,6 @@ class TaskAssignSpecificUserTest extends Base $action->setParam('column_id', 2); $action->setParam('user_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignUserTest.php b/tests/units/Action/TaskAssignUserTest.php index d723ed2b..060128eb 100644 --- a/tests/units/Action/TaskAssignUserTest.php +++ b/tests/units/Action/TaskAssignUserTest.php @@ -3,11 +3,11 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskAssignUser; use Kanboard\Core\Security\Role; @@ -15,11 +15,11 @@ class TaskAssignUserTest extends Base { public function testChangeUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); @@ -41,8 +41,8 @@ class TaskAssignUserTest extends Base public function testWithNotAssignableUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php index 654aeec1..f9a938f0 100644 --- a/tests/units/Action/TaskCloseColumnTest.php +++ b/tests/units/Action/TaskCloseColumnTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskCloseColumn; class TaskCloseColumnTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -26,7 +26,7 @@ class TaskCloseColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -35,8 +35,8 @@ class TaskCloseColumnTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -47,6 +47,6 @@ class TaskCloseColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskCloseNoActivityTest.php b/tests/units/Action/TaskCloseNoActivityTest.php index b6e04c47..707d8585 100644 --- a/tests/units/Action/TaskCloseNoActivityTest.php +++ b/tests/units/Action/TaskCloseNoActivityTest.php @@ -3,25 +3,25 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\TaskListEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskCloseNoActivity; class TaskCloseNoActivityTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -30,7 +30,7 @@ class TaskCloseNoActivityTest extends Base $action->setProjectId(1); $action->setParam('duration', 2); - $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php index 536d79ca..3df10cb8 100644 --- a/tests/units/Action/TaskCloseTest.php +++ b/tests/units/Action/TaskCloseTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskClose; class TaskCloseTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -34,8 +34,8 @@ class TaskCloseTest extends Base public function testWithNoTaskId() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskCreationTest.php b/tests/units/Action/TaskCreationTest.php index 57a3ee46..fb3d334f 100644 --- a/tests/units/Action/TaskCreationTest.php +++ b/tests/units/Action/TaskCreationTest.php @@ -3,16 +3,16 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskCreation as TaskCreationAction; class TaskCreationActionTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -33,7 +33,7 @@ class TaskCreationActionTest extends Base public function testWithNoTitle() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php index d5f99ec9..98ff187f 100644 --- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php +++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskDuplicateAnotherProject; class TaskDuplicateAnotherProjectTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskDuplicateAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); $task = $taskFinderModel->getById(2); $this->assertNotEmpty($task); @@ -38,7 +38,7 @@ class TaskDuplicateAnotherProjectTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -50,6 +50,6 @@ class TaskDuplicateAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskEmailNoActivityTest.php b/tests/units/Action/TaskEmailNoActivityTest.php index af4baed5..c4d489d8 100644 --- a/tests/units/Action/TaskEmailNoActivityTest.php +++ b/tests/units/Action/TaskEmailNoActivityTest.php @@ -3,28 +3,28 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\TaskListEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskEmailNoActivity; class TaskEmailNoActivityTest extends Base { public function testSendEmail() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -40,22 +40,22 @@ class TaskEmailNoActivityTest extends Base ->method('send') ->with('chuck@norris', 'Chuck Norris', 'Old tasks', $this->anything()); - $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } public function testUserWithNoEmail() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -70,15 +70,15 @@ class TaskEmailNoActivityTest extends Base ->expects($this->never()) ->method('send'); - $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } public function testTooRecent() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -98,6 +98,6 @@ class TaskEmailNoActivityTest extends Base ->expects($this->never()) ->method('send'); - $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } } diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php index 93b7b559..df71aaf8 100644 --- a/tests/units/Action/TaskEmailTest.php +++ b/tests/units/Action/TaskEmailTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\User; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskEmail; class TaskEmailTest extends Base { public function testSuccess() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -38,12 +38,12 @@ class TaskEmailTest extends Base $this->stringContains('test') ); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); } public function testWithWrongColumn() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -55,6 +55,6 @@ class TaskEmailTest extends Base $action->setParam('user_id', 1); $action->setParam('subject', 'My email subject'); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php index ec48f0a4..d36df47b 100644 --- a/tests/units/Action/TaskMoveAnotherProjectTest.php +++ b/tests/units/Action/TaskMoveAnotherProjectTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveAnotherProject; class TaskMoveAnotherProjectTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,7 +39,7 @@ class TaskMoveAnotherProjectTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -51,6 +51,6 @@ class TaskMoveAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php index 3b325505..f8982969 100644 --- a/tests/units/Action/TaskMoveColumnAssignedTest.php +++ b/tests/units/Action/TaskMoveColumnAssignedTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnAssigned; class TaskMoveColumnAssignedTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveColumnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -38,7 +38,7 @@ class TaskMoveColumnAssignedTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -50,6 +50,6 @@ class TaskMoveColumnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php index 8783c679..c42383f8 100644 --- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php +++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnCategoryChange; class TaskMoveColumnCategoryChangeTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -31,7 +31,7 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -41,9 +41,9 @@ class TaskMoveColumnCategoryChangeTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -57,14 +57,14 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_UPDATE)); } public function testWithWrongCategory() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -79,6 +79,6 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_UPDATE)); } } diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php index cf2333cc..befae36b 100644 --- a/tests/units/Action/TaskMoveColumnUnAssignedTest.php +++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnUnAssigned; class TaskMoveColumnUnAssignedTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -38,7 +38,7 @@ class TaskMoveColumnUnAssignedTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -50,12 +50,12 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } public function testWithWrongUser() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -67,6 +67,6 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php index 01290a64..1018e2ea 100644 --- a/tests/units/Action/TaskOpenTest.php +++ b/tests/units/Action/TaskOpenTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskOpen; class TaskOpenTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0))); @@ -34,8 +34,8 @@ class TaskOpenTest extends Base public function testWithNoTaskId() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php index adf5bd9d..ddd9eafd 100644 --- a/tests/units/Action/TaskUpdateStartDateTest.php +++ b/tests/units/Action/TaskUpdateStartDateTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskUpdateStartDate; class TaskUpdateStartDateTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -26,7 +26,7 @@ class TaskUpdateStartDateTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -35,8 +35,8 @@ class TaskUpdateStartDateTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -47,6 +47,6 @@ class TaskUpdateStartDateTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php index b87e9573..831ec960 100644 --- a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php +++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Analytic\AverageLeadCycleTimeAnalytic; class AverageLeadCycleTimeAnalyticTest extends Base { public function testBuild() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); $now = time(); @@ -26,19 +26,19 @@ class AverageLeadCycleTimeAnalyticTest extends Base $this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); // LT=3600 CT=1800 - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); // LT=1800 CT=900 - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); // LT=3600 CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); // LT=2*3600 CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); // CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 5)->update(array('date_started' => $now + 900)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 5)->update(array('date_started' => $now + 900)); $stats = $averageLeadCycleTimeAnalytic->build(1); @@ -51,7 +51,7 @@ class AverageLeadCycleTimeAnalyticTest extends Base public function testBuildWithNoTasks() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php index 4e01bfa9..1da425fb 100644 --- a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php +++ b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Transition; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TransitionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Analytic\AverageTimeSpentColumnAnalytic; class AverageTimeSpentColumnAnalyticTest extends Base { public function testAverageWithNoTransitions() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -24,8 +24,8 @@ class AverageTimeSpentColumnAnalyticTest extends Base $now = time(); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); $stats = $averageLeadCycleTimeAnalytic->build(1); @@ -52,10 +52,10 @@ class AverageTimeSpentColumnAnalyticTest extends Base public function testAverageWithTransitions() { - $transitionModel = new Transition($this->container); - $taskFinderModel = new TaskFinder($this->container); - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $transitionModel = new TransitionModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -64,8 +64,8 @@ class AverageTimeSpentColumnAnalyticTest extends Base $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $now = time(); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); foreach (array(1, 2) as $task_id) { $task = $taskFinderModel->getById($task_id); diff --git a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php index 2ca631b1..29bf88a3 100644 --- a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php +++ b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Analytic\EstimatedTimeComparisonAnalytic; class EstimatedTimeComparisonAnalyticTest extends Base { public function testBuild() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -41,8 +41,8 @@ class EstimatedTimeComparisonAnalyticTest extends Base public function testBuildWithNoClosedTask() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -70,8 +70,8 @@ class EstimatedTimeComparisonAnalyticTest extends Base public function testBuildWithOnlyClosedTask() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Analytic/TaskDistributionAnalyticTest.php b/tests/units/Analytic/TaskDistributionAnalyticTest.php index 531101ef..0d600b8b 100644 --- a/tests/units/Analytic/TaskDistributionAnalyticTest.php +++ b/tests/units/Analytic/TaskDistributionAnalyticTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Analytic\TaskDistributionAnalytic; class TaskDistributionAnalyticTest extends Base { public function testBuild() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $taskDistributionModel = new TaskDistributionAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -49,7 +49,7 @@ class TaskDistributionAnalyticTest extends Base private function createTasks($column_id, $nb_active, $nb_inactive) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); for ($i = 0; $i < $nb_active; $i++) { $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 1))); diff --git a/tests/units/Analytic/UserDistributionAnalyticTest.php b/tests/units/Analytic/UserDistributionAnalyticTest.php index bdc136e1..f4514899 100644 --- a/tests/units/Analytic/UserDistributionAnalyticTest.php +++ b/tests/units/Analytic/UserDistributionAnalyticTest.php @@ -2,10 +2,10 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Analytic\UserDistributionAnalytic; use Kanboard\Core\Security\Role; @@ -13,9 +13,9 @@ class UserDistributionAnalyticTest extends Base { public function testBuild() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); $userDistributionModel = new UserDistributionAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -70,7 +70,7 @@ class UserDistributionAnalyticTest extends Base private function createTasks($user_id, $nb_active, $nb_inactive) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); for ($i = 0; $i < $nb_active; $i++) { $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 1))); diff --git a/tests/units/Auth/DatabaseAuthTest.php b/tests/units/Auth/DatabaseAuthTest.php index ac099a7e..97c75bd2 100644 --- a/tests/units/Auth/DatabaseAuthTest.php +++ b/tests/units/Auth/DatabaseAuthTest.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Auth\DatabaseAuth; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; class DatabaseAuthTest extends Base { @@ -41,7 +41,7 @@ class DatabaseAuthTest extends Base public function testIsvalidSession() { - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $provider = new DatabaseAuth($this->container); $this->assertFalse($provider->isValidSession()); diff --git a/tests/units/Base.php b/tests/units/Base.php index 16c34573..c7e066d1 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -63,8 +63,8 @@ abstract class Base extends PHPUnit_Framework_TestCase ->setMethods(array('send')) ->getMock(); - $this->container['userNotificationType'] = $this - ->getMockBuilder('\Kanboard\Model\UserNotificationType') + $this->container['userNotificationTypeModel'] = $this + ->getMockBuilder('\Kanboard\Model\UserNotificationTypeModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('getType', 'getSelectedTypes')) ->getMock(); diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php index aae5bd2d..e7c2071f 100644 --- a/tests/units/Core/Action/ActionManagerTest.php +++ b/tests/units/Core/Action/ActionManagerTest.php @@ -7,10 +7,10 @@ use Kanboard\Action\TaskAssignColorColumn; use Kanboard\Action\TaskClose; use Kanboard\Action\TaskCloseColumn; use Kanboard\Action\TaskUpdateStartDate; -use Kanboard\Model\Action; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ActionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ActionManagerTest extends Base @@ -79,16 +79,16 @@ class ActionManagerTest extends Base $events = $actionManager->getCompatibleEvents('\\'.get_class($actionTaskAssignColorColumn)); $this->assertCount(2, $events); - $this->assertArrayHasKey(Task::EVENT_CREATE, $events); - $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events); - $this->assertNotEmpty($events[Task::EVENT_CREATE]); - $this->assertNotEmpty($events[Task::EVENT_MOVE_COLUMN]); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE, $events); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN, $events); + $this->assertNotEmpty($events[TaskModel::EVENT_CREATE]); + $this->assertNotEmpty($events[TaskModel::EVENT_MOVE_COLUMN]); } public function testAttachEventsWithoutUserSession() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -101,13 +101,13 @@ class ActionManagerTest extends Base $this->assertEquals(1, $projectModel->create(array('name' =>'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_CREATE); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -118,9 +118,9 @@ class ActionManagerTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -134,21 +134,21 @@ class ActionManagerTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -157,9 +157,9 @@ class ActionManagerTest extends Base public function testThatEachListenerAreDifferentInstance() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -169,21 +169,21 @@ class ActionManagerTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 2, 'color_id' => 'green'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(2, $listeners); $this->assertFalse($listeners[0][0] === $listeners[1][0]); diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php index ac5315bb..23726f32 100644 --- a/tests/units/Core/Filter/LexerBuilderTest.php +++ b/tests/units/Core/Filter/LexerBuilderTest.php @@ -5,17 +5,17 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\Filter\LexerBuilder; use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; class LexerBuilderTest extends Base { public function testBuilderThatReturnResult() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -33,9 +33,9 @@ class LexerBuilderTest extends Base public function testBuilderThatReturnNothing() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -52,9 +52,9 @@ class LexerBuilderTest extends Base public function testBuilderWithEmptyInput() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -71,9 +71,9 @@ class LexerBuilderTest extends Base public function testBuilderWithMultipleMatches() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -91,7 +91,7 @@ class LexerBuilderTest extends Base public function testClone() { - $taskFinder = new TaskFinder($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $builder = new LexerBuilder(); diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php index 787d3461..a46726c3 100644 --- a/tests/units/Core/Filter/OrCriteriaTest.php +++ b/tests/units/Core/Filter/OrCriteriaTest.php @@ -3,10 +3,10 @@ use Kanboard\Core\Filter\OrCriteria; use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\User; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\UserModel; require_once __DIR__.'/../../Base.php'; @@ -14,10 +14,10 @@ class OrCriteriaTest extends Base { public function testWithSameFilter() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -36,10 +36,10 @@ class OrCriteriaTest extends Base public function testWithDifferentFilter() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); diff --git a/tests/units/Core/Group/GroupManagerTest.php b/tests/units/Core/Group/GroupManagerTest.php index faf5501f..e89ad15b 100644 --- a/tests/units/Core/Group/GroupManagerTest.php +++ b/tests/units/Core/Group/GroupManagerTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../../Base.php'; -use Kanboard\Model\Group; +use Kanboard\Model\GroupModel; use Kanboard\Core\Group\GroupManager; use Kanboard\Group\DatabaseBackendGroupProvider; @@ -10,7 +10,7 @@ class GroupManagerTest extends Base { public function testFind() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $groupManager = new GroupManager; $this->assertEquals(1, $groupModel->create('Group 1')); diff --git a/tests/units/Core/User/GroupSyncTest.php b/tests/units/Core/User/GroupSyncTest.php index decb2fdc..d3df71bb 100644 --- a/tests/units/Core/User/GroupSyncTest.php +++ b/tests/units/Core/User/GroupSyncTest.php @@ -3,15 +3,15 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\User\GroupSync; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; class GroupSyncTest extends Base { public function testAddGroups() { - $group = new Group($this->container); - $groupMember = new GroupMember($this->container); + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); $groupSync = new GroupSync($this->container); $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); @@ -30,8 +30,8 @@ class GroupSyncTest extends Base public function testRemoveGroups() { - $group = new Group($this->container); - $groupMember = new GroupMember($this->container); + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); $groupSync = new GroupSync($this->container); $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); @@ -50,8 +50,8 @@ class GroupSyncTest extends Base public function testBoth() { - $group = new Group($this->container); - $groupMember = new GroupMember($this->container); + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); $groupSync = new GroupSync($this->container); $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); @@ -74,8 +74,8 @@ class GroupSyncTest extends Base public function testThatInternalGroupsAreNotTouched() { - $group = new Group($this->container); - $groupMember = new GroupMember($this->container); + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); $groupSync = new GroupSync($this->container); $this->assertEquals(1, $group->create('My Group 1')); diff --git a/tests/units/Export/TaskExportTest.php b/tests/units/Export/TaskExportTest.php index f0637c25..c142cde9 100644 --- a/tests/units/Export/TaskExportTest.php +++ b/tests/units/Export/TaskExportTest.php @@ -2,21 +2,21 @@ require_once __DIR__ . '/../Base.php'; -use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskCreationModel; use Kanboard\Export\TaskExport; -use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\SwimlaneModel; class TaskExportTest extends Base { public function testExport() { - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $e = new TaskExport($this->container); - $s = new Swimlane($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Export Project'))); diff --git a/tests/units/Export/TransitionExportTest.php b/tests/units/Export/TransitionExportTest.php index 7ff3082e..ee195ad1 100644 --- a/tests/units/Export/TransitionExportTest.php +++ b/tests/units/Export/TransitionExportTest.php @@ -2,18 +2,18 @@ require_once __DIR__ . '/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Transition; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TransitionModel; use Kanboard\Export\TransitionExport; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; class TransitionExportTest extends Base { public function testExport() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $transitionExportModel = new TransitionExport($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); diff --git a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php index 1dce4451..716d58bd 100644 --- a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php +++ b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('today'); @@ -33,14 +33,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithYesterday() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('yesterday'); @@ -53,14 +53,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithStrtotimeString() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('<=last week'); @@ -73,14 +73,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithIsoDate() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter(date('Y-m-d')); @@ -93,14 +93,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithOperatorAndIsoDate() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d')); diff --git a/tests/units/Filter/ProjectActivityCreatorFilterTest.php b/tests/units/Filter/ProjectActivityCreatorFilterTest.php index 99c70322..65281d06 100644 --- a/tests/units/Filter/ProjectActivityCreatorFilterTest.php +++ b/tests/units/Filter/ProjectActivityCreatorFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('admin'); @@ -32,14 +32,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithAnotherUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('John Doe'); @@ -51,14 +51,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('me'); @@ -71,14 +71,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithAnotherCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('me'); diff --git a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php index 193852e1..75e6fa70 100644 --- a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -25,8 +25,8 @@ class ProjectActivityProjectIdFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityProjectIdFilter(1); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php index e99d2e2f..b5c4683d 100644 --- a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -27,9 +27,9 @@ class ProjectActivityProjectIdsFilterTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $filter = new ProjectActivityProjectIdsFilter(array(1, 2)); $filter->withQuery($query)->apply(); @@ -38,10 +38,10 @@ class ProjectActivityProjectIdsFilterTest extends Base public function testWithEmptyArgument() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -52,9 +52,9 @@ class ProjectActivityProjectIdsFilterTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, $taskFinder->getById(1))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, $taskFinder->getById(2))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, $taskFinder->getById(3))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(1))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(2))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(3))); $filter = new ProjectActivityProjectIdsFilter(array()); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php index de9d7d59..3ec01bc0 100644 --- a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -25,8 +25,8 @@ class ProjectActivityProjectNameFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityProjectNameFilter('P1'); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php index 646cab1b..940d1c6f 100644 --- a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,8 +24,8 @@ class ProjectActivityTaskIdFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskIdFilter(1); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php index b8df6338..673a4990 100644 --- a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php @@ -1,12 +1,12 @@ container); - $taskCreation = new TaskCreation($this->container); - $taskStatus = new TaskStatus($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskStatus = new TaskStatusModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $this->assertTrue($taskStatus->close(1)); diff --git a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php index 925a1ab2..f6217dba 100644 --- a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,8 +24,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('test2'); $filter->withQuery($query)->apply(); @@ -34,10 +34,10 @@ class ProjectActivityTaskTitleFilterTest extends Base public function testWithPartialTitle() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -45,8 +45,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('test'); $filter->withQuery($query)->apply(); @@ -55,10 +55,10 @@ class ProjectActivityTaskTitleFilterTest extends Base public function testWithId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -66,8 +66,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('#2'); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/TaskAssigneeFilterTest.php b/tests/units/Filter/TaskAssigneeFilterTest.php index 356342c5..dec3824e 100644 --- a/tests/units/Filter/TaskAssigneeFilterTest.php +++ b/tests/units/Filter/TaskAssigneeFilterTest.php @@ -1,10 +1,10 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -37,9 +37,9 @@ class TaskAssigneeFilterTest extends Base public function testWithStringAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -62,9 +62,9 @@ class TaskAssigneeFilterTest extends Base public function testWithUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -87,10 +87,10 @@ class TaskAssigneeFilterTest extends Base public function testWithName() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -114,9 +114,9 @@ class TaskAssigneeFilterTest extends Base public function testWithNobody() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -132,9 +132,9 @@ class TaskAssigneeFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Filter/TaskCommentFilterTest.php b/tests/units/Filter/TaskCommentFilterTest.php index 8d1b7f44..95ffb32f 100644 --- a/tests/units/Filter/TaskCommentFilterTest.php +++ b/tests/units/Filter/TaskCommentFilterTest.php @@ -1,10 +1,10 @@ container); - $taskCreation = new TaskCreation($this->container); - $commentModel = new Comment($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $commentModel = new CommentModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -32,10 +32,10 @@ class TaskCommentFilterTest extends Base public function testNoMatch() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $commentModel = new Comment($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $commentModel = new CommentModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Filter/TaskCreatorFilterTest.php b/tests/units/Filter/TaskCreatorFilterTest.php index 1c344de7..b5abe6cf 100644 --- a/tests/units/Filter/TaskCreatorFilterTest.php +++ b/tests/units/Filter/TaskCreatorFilterTest.php @@ -1,10 +1,10 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -37,9 +37,9 @@ class TaskCreatorFilterTest extends Base public function testWithStringAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -62,9 +62,9 @@ class TaskCreatorFilterTest extends Base public function testWithUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -87,10 +87,10 @@ class TaskCreatorFilterTest extends Base public function testWithName() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -114,9 +114,9 @@ class TaskCreatorFilterTest extends Base public function testWithNobody() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -132,9 +132,9 @@ class TaskCreatorFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php index 6ef5accd..da780c4b 100644 --- a/tests/units/Helper/AssetHelperTest.php +++ b/tests/units/Helper/AssetHelperTest.php @@ -3,14 +3,14 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\AssetHelper; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; class AssetHelperTest extends Base { public function testCustomCss() { $h = new AssetHelper($this->container); - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEmpty($h->customCss()); diff --git a/tests/units/Helper/ProjectActivityHelperTest.php b/tests/units/Helper/ProjectActivityHelperTest.php index 88b2d352..1ad95699 100644 --- a/tests/units/Helper/ProjectActivityHelperTest.php +++ b/tests/units/Helper/ProjectActivityHelperTest.php @@ -1,11 +1,11 @@ container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,9 +24,9 @@ class ProjectActivityHelperTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getProjectEvents(1); @@ -41,10 +41,10 @@ class ProjectActivityHelperTest extends Base public function testGetProjectsEvents() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); @@ -54,9 +54,9 @@ class ProjectActivityHelperTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getProjectsEvents(array(1, 2)); @@ -71,18 +71,18 @@ class ProjectActivityHelperTest extends Base public function testGetTaskEvents() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getTaskEvents(1); diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index 8f596541..c9447abb 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -3,16 +3,16 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\TextHelper; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; class TextHelperTest extends Base { public function testMarkdownTaskLink() { $helper = new TextHelper($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertTrue($projectModel->enablePublicAccess(1)); diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php index 34ab7604..b1f0a032 100644 --- a/tests/units/Helper/UrlHelperTest.php +++ b/tests/units/Helper/UrlHelperTest.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\UrlHelper; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; use Kanboard\Core\Http\Request; class UrlHelperTest extends Base @@ -115,7 +115,7 @@ class UrlHelperTest extends Base $h = new UrlHelper($this->container); $this->assertEquals('http://kb:1234/', $h->base()); - $c = new Config($this->container); + $c = new ConfigModel($this->container); $c->save(array('application_url' => 'https://mykanboard/')); $this->container['memoryCache']->flush(); diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index be563b47..c149e663 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -4,13 +4,12 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\User\UserSession; use Kanboard\Helper\UserHelper; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\User as UserModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Core\Security\Role; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; class UserHelperTest extends Base { @@ -76,7 +75,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForAdmins() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -92,7 +91,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForManagers() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -108,7 +107,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForUsers() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -125,8 +124,8 @@ class UserHelperTest extends Base { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -153,8 +152,8 @@ class UserHelperTest extends Base { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -181,8 +180,8 @@ class UserHelperTest extends Base { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -209,8 +208,8 @@ class UserHelperTest extends Base { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -235,11 +234,11 @@ class UserHelperTest extends Base public function testCanRemoveTask() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $helper = new UserHelper($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $userSessionModel = new UserSession($this->container); $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456'))); @@ -278,7 +277,7 @@ class UserHelperTest extends Base $this->assertTrue($helper->canRemoveTask($task)); // User #2 can remove his own TaskViewController - $user = $userModel->getbyId(2); + $user = $userModel->getById(2); $this->assertNotEmpty($user); $userSessionModel->initialize($user); diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php index ed687846..5db18983 100644 --- a/tests/units/Model/ActionTest.php +++ b/tests/units/Model/ActionTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Action; -use Kanboard\Model\Project; -use Kanboard\Model\Task; -use Kanboard\Model\User; -use Kanboard\Model\Column; -use Kanboard\Model\Category; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ActionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ActionTest extends Base { public function testCreate() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -30,14 +30,14 @@ class ActionTest extends Base public function testRemove() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -49,14 +49,14 @@ class ActionTest extends Base public function testGetById() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -65,28 +65,28 @@ class ActionTest extends Base $this->assertNotEmpty($action); $this->assertEquals(1, $action['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $action['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $action['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']); } public function testGetAll() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); @@ -96,33 +96,33 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); $this->assertEquals(2, $actions[1]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[1]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[1]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']); } public function testGetAllByProject() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); @@ -132,7 +132,7 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); @@ -141,16 +141,16 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } public function testGetAllByUser() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -165,21 +165,21 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); $this->assertEquals(3, $actionModel->create(array( 'project_id' => 3, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 10, 'color_id' => 'green'), ))); @@ -192,7 +192,7 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); $actions = $actionModel->getAllByUser(3); @@ -200,21 +200,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } public function testDuplicateWithColumnAndColorParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -226,21 +226,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); } public function testDuplicateWithColumnsParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3), ))); @@ -252,15 +252,15 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']); } public function testDuplicateWithColumnParameterNotfound() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -269,14 +269,14 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 2, 'color_id' => 'green'), ))); @@ -288,14 +288,14 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); } public function testDuplicateWithProjectParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -303,7 +303,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CLOSE, + 'event_name' => TaskModel::EVENT_CLOSE, 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', 'params' => array('column_id' => 1, 'project_id' => 3), ))); @@ -315,21 +315,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CLOSE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CLOSE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']); } public function testDuplicateWithProjectParameterIdenticalToDestination() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CLOSE, + 'event_name' => TaskModel::EVENT_CLOSE, 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', 'params' => array('column_id' => 1, 'project_id' => 2), ))); @@ -342,10 +342,10 @@ class ActionTest extends Base public function testDuplicateWithUserParameter() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -357,7 +357,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2), ))); @@ -369,16 +369,16 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']); } public function testDuplicateWithUserParameterButNotAssignable() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -390,7 +390,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2), ))); @@ -403,10 +403,10 @@ class ActionTest extends Base public function testDuplicateWithUserParameterButNotAvailable() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -417,7 +417,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'owner_id' => 2), ))); @@ -430,9 +430,9 @@ class ActionTest extends Base public function testDuplicateWithCategoryParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -442,7 +442,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); @@ -454,15 +454,15 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE_UPDATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE_UPDATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']); } public function testDuplicateWithCategoryParameterButDifferentName() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -472,7 +472,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); @@ -485,9 +485,9 @@ class ActionTest extends Base public function testDuplicateWithCategoryParameterButNotFound() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -496,7 +496,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php index 20665ac2..80587d89 100644 --- a/tests/units/Model/BoardTest.php +++ b/tests/units/Model/BoardTest.php @@ -2,21 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\Board; -use Kanboard\Model\Column; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\BoardModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\SwimlaneModel; class BoardTest extends Base { public function testCreation() { - $p = new Project($this->container); - $columnModel = new Column($this->container); - $c = new Config($this->container); + $p = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); + $c = new ConfigModel($this->container); // Default columns @@ -48,8 +48,8 @@ class BoardTest extends Base public function testGetBoard() { - $p = new Project($this->container); - $b = new Board($this->container); + $p = new ProjectModel($this->container); + $b = new BoardModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); @@ -69,11 +69,11 @@ class BoardTest extends Base public function testGetBoardWithSwimlane() { - $b = new Board($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $b = new BoardModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php index 600007d0..1fdc51f6 100644 --- a/tests/units/Model/CategoryTest.php +++ b/tests/units/Model/CategoryTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Category; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; class CategoryTest extends Base { public function testCreation() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -33,8 +33,8 @@ class CategoryTest extends Base public function testExists() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -44,8 +44,8 @@ class CategoryTest extends Base public function testGetById() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); @@ -59,8 +59,8 @@ class CategoryTest extends Base public function testGetNameById() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); @@ -71,8 +71,8 @@ class CategoryTest extends Base public function testGetIdByName() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); @@ -83,8 +83,8 @@ class CategoryTest extends Base public function testGetList() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); @@ -117,8 +117,8 @@ class CategoryTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); @@ -140,9 +140,9 @@ class CategoryTest extends Base public function testCreateDefaultCategories() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); - $configModel = new Config($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + $configModel = new ConfigModel($this->container); $this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3'))); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); @@ -157,8 +157,8 @@ class CategoryTest extends Base public function testUpdate() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -172,10 +172,10 @@ class CategoryTest extends Base public function testRemove() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -195,8 +195,8 @@ class CategoryTest extends Base public function testDuplicate() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); diff --git a/tests/units/Model/ColorTest.php b/tests/units/Model/ColorTest.php index e96ecb6b..2a2c4b87 100644 --- a/tests/units/Model/ColorTest.php +++ b/tests/units/Model/ColorTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Color; -use Kanboard\Model\Config; +use Kanboard\Model\ColorModel; +use Kanboard\Model\ConfigModel; class ColorTest extends Base { public function testFind() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('yellow', $colorModel->find('yellow')); $this->assertEquals('yellow', $colorModel->find('Yellow')); $this->assertEquals('dark_grey', $colorModel->find('Dark Grey')); @@ -18,7 +18,7 @@ class ColorTest extends Base public function testGetColorProperties() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $expected = array( 'name' => 'Light Green', 'background' => '#dcedc8', @@ -38,7 +38,7 @@ class ColorTest extends Base public function testGetList() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $colors = $colorModel->getList(); $this->assertCount(16, $colors); @@ -52,8 +52,8 @@ class ColorTest extends Base public function testGetDefaultColor() { - $colorModel = new Color($this->container); - $configModel = new Config($this->container); + $colorModel = new ColorModel($this->container); + $configModel = new ConfigModel($this->container); $this->assertEquals('yellow', $colorModel->getDefaultColor()); @@ -64,7 +64,7 @@ class ColorTest extends Base public function testGetDefaultColors() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $colors = $colorModel->getDefaultColors(); $this->assertCount(16, $colors); @@ -72,19 +72,19 @@ class ColorTest extends Base public function testGetBorderColor() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('rgb(74, 227, 113)', $colorModel->getBorderColor('green')); } public function testGetBackgroundColor() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('rgb(189, 244, 203)', $colorModel->getBackgroundColor('green')); } public function testGetCss() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $css = $colorModel->getCss(); $this->assertStringStartsWith('div.color-yellow {', $css); diff --git a/tests/units/Model/ColumnTest.php b/tests/units/Model/ColumnTest.php index e40f89c6..7340a274 100644 --- a/tests/units/Model/ColumnTest.php +++ b/tests/units/Model/ColumnTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\Column; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ColumnModel; class ColumnTest extends Base { public function testGetColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -24,8 +24,8 @@ class ColumnTest extends Base public function testGetFirstColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $columnModel->getFirstColumnId(1)); @@ -33,8 +33,8 @@ class ColumnTest extends Base public function testGetLastColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(4, $columnModel->getLastColumnId(1)); @@ -42,8 +42,8 @@ class ColumnTest extends Base public function testGetLastColumnPosition() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(4, $columnModel->getLastColumnPosition(1)); @@ -51,8 +51,8 @@ class ColumnTest extends Base public function testGetColumnIdByTitle() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $columnModel->getColumnIdByTitle(1, 'Ready')); @@ -60,8 +60,8 @@ class ColumnTest extends Base public function testGetTitleByColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals('Work in progress', $columnModel->getColumnTitleById(3)); @@ -69,8 +69,8 @@ class ColumnTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -96,8 +96,8 @@ class ColumnTest extends Base public function testGetList() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -119,8 +119,8 @@ class ColumnTest extends Base public function testAddColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertNotFalse($columnModel->create(1, 'another column')); @@ -142,8 +142,8 @@ class ColumnTest extends Base public function testUpdateColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -163,8 +163,8 @@ class ColumnTest extends Base public function testRemoveColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($columnModel->remove(3)); @@ -177,8 +177,8 @@ class ColumnTest extends Base public function testChangePosition() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php index bb96e4f4..7250ae0b 100644 --- a/tests/units/Model/CommentTest.php +++ b/tests/units/Model/CommentTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Comment; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CommentModel; class CommentTest extends Base { public function testCreate() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -38,9 +38,9 @@ class CommentTest extends Base public function testGetAll() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -61,9 +61,9 @@ class CommentTest extends Base public function testUpdate() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -77,9 +77,9 @@ class CommentTest extends Base public function validateRemove() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php index ad74ad50..3345ee3e 100644 --- a/tests/units/Model/ConfigTest.php +++ b/tests/units/Model/ConfigTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; class ConfigTest extends Base { public function testRegenerateToken() { - $configModel = new Config($this->container); + $configModel = new ConfigModel($this->container); $token = $configModel->getOption('api_token'); $this->assertTrue($configModel->regenerateToken('api_token')); $this->assertNotEquals($token, $configModel->getOption('api_token')); @@ -16,7 +16,7 @@ class ConfigTest extends Base public function testCRUDOperations() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertTrue($c->save(array('key1' => 'value1'))); $this->assertTrue($c->save(array('key1' => 'value2'))); @@ -41,7 +41,7 @@ class ConfigTest extends Base public function testSaveApplicationUrl() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertTrue($c->save(array('application_url' => 'http://localhost/'))); $this->assertEquals('http://localhost/', $c->getOption('application_url')); @@ -55,7 +55,7 @@ class ConfigTest extends Base public function testDefaultValues() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals(172800, $c->getOption('board_highlight_period')); $this->assertEquals(60, $c->getOption('board_public_refresh_interval')); @@ -92,7 +92,7 @@ class ConfigTest extends Base public function testGetOption() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals('', $c->getOption('board_columns')); $this->assertEquals('test', $c->getOption('board_columns', 'test')); @@ -101,7 +101,7 @@ class ConfigTest extends Base public function testGetWithCaching() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals('UTC', $c->get('application_timezone')); $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris'))); diff --git a/tests/units/Model/CurrencyTest.php b/tests/units/Model/CurrencyTest.php index 0bc71da6..162cdfc1 100644 --- a/tests/units/Model/CurrencyTest.php +++ b/tests/units/Model/CurrencyTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Currency; +use Kanboard\Model\CurrencyModel; class CurrencyTest extends Base { public function testGetCurrencies() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $currencies = $currencyModel->getCurrencies(); $this->assertArrayHasKey('EUR', $currencies); } public function testGetAll() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $currencies = $currencyModel->getAll(); $this->assertCount(0, $currencies); @@ -28,21 +28,21 @@ class CurrencyTest extends Base public function testCreate() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertNotFalse($currencyModel->create('EUR', 1.2)); $this->assertNotFalse($currencyModel->create('EUR', 1.5)); } public function testUpdate() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertNotFalse($currencyModel->create('EUR', 1.1)); $this->assertNotFalse($currencyModel->update('EUR', 2.2)); } public function testGetPrice() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertEquals(123, $currencyModel->getPrice('USD', 123)); diff --git a/tests/units/Model/CustomFilterTest.php b/tests/units/Model/CustomFilterTest.php index a73bc401..463a1c91 100644 --- a/tests/units/Model/CustomFilterTest.php +++ b/tests/units/Model/CustomFilterTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\CustomFilter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\CustomFilterModel; class CustomFilterTest extends Base { public function testCreation() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); @@ -36,8 +36,8 @@ class CustomFilterTest extends Base public function testModification() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); @@ -54,9 +54,9 @@ class CustomFilterTest extends Base public function testGetAll() { - $u = new User($this->container); - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest 1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest 2'))); @@ -128,8 +128,8 @@ class CustomFilterTest extends Base public function testRemove() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php index 0ff9fdf6..edc9d98c 100644 --- a/tests/units/Model/GroupMemberTest.php +++ b/tests/units/Model/GroupMemberTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Group; -use Kanboard\Model\User; -use Kanboard\Model\GroupMember; +use Kanboard\Model\GroupModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupMemberModel; class GroupMemberTest extends Base { public function testAddRemove() { - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); @@ -32,9 +32,9 @@ class GroupMemberTest extends Base public function testMembers() { - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $groupModel->create('Group A')); $this->assertEquals(2, $groupModel->create('Group B')); diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupTest.php index 36b47dc5..85c2c5d9 100644 --- a/tests/units/Model/GroupTest.php +++ b/tests/units/Model/GroupTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Group; +use Kanboard\Model\GroupModel; class GroupTest extends Base { public function testCreation() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertFalse($groupModel->create('Test')); } public function testGetById() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $group = $groupModel->getById(1); @@ -27,7 +27,7 @@ class GroupTest extends Base public function testGetAll() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('B')); $this->assertEquals(2, $groupModel->create('A', 'uuid')); @@ -41,7 +41,7 @@ class GroupTest extends Base public function testUpdate() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test'))); @@ -52,7 +52,7 @@ class GroupTest extends Base public function testRemove() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertTrue($groupModel->remove(1)); $this->assertEmpty($groupModel->getById(1)); diff --git a/tests/units/Model/LanguageTest.php b/tests/units/Model/LanguageTest.php index dff98a83..4330c3c8 100644 --- a/tests/units/Model/LanguageTest.php +++ b/tests/units/Model/LanguageTest.php @@ -1,6 +1,6 @@ assertContains('fr_FR', $codes); $this->assertContains('en_US', $codes); } public function testFindCode() { - $this->assertSame('', Language::findCode('xx-XX')); - $this->assertSame('fr_FR', Language::findCode('fr-FR')); - $this->assertSame('en_US', Language::findCode('en-US')); + $this->assertSame('', LanguageModel::findCode('xx-XX')); + $this->assertSame('fr_FR', LanguageModel::findCode('fr-FR')); + $this->assertSame('en_US', LanguageModel::findCode('en-US')); } public function testGetJsLanguage() { - $languageModel = new Language($this->container); + $languageModel = new LanguageModel($this->container); $this->assertEquals('en', $languageModel->getJsLanguageCode()); $this->container['sessionStorage']->user = array('language' => 'fr_FR'); @@ -34,7 +34,7 @@ class LanguageTest extends Base public function testGetCurrentLanguage() { - $languageModel = new Language($this->container); + $languageModel = new LanguageModel($this->container); $this->assertEquals('en_US', $languageModel->getCurrentLanguage()); $this->container['sessionStorage']->user = array('language' => 'fr_FR'); @@ -46,7 +46,7 @@ class LanguageTest extends Base public function testGetLanguages() { - $languageModel = new Language($this->container); + $languageModel = new LanguageModel($this->container); $this->assertNotEmpty($languageModel->getLanguages()); $this->assertArrayHasKey('fr_FR', $languageModel->getLanguages()); $this->assertContains('Français', $languageModel->getLanguages()); diff --git a/tests/units/Model/LastLoginTest.php b/tests/units/Model/LastLoginTest.php index fc5ea1e5..8c291e15 100644 --- a/tests/units/Model/LastLoginTest.php +++ b/tests/units/Model/LastLoginTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\LastLogin; +use Kanboard\Model\LastLoginModel; class LastLoginTest extends Base { public function testCreate() { - $lastLoginModel = new LastLogin($this->container); + $lastLoginModel = new LastLoginModel($this->container); $this->assertTrue($lastLoginModel->create('Test1', 1, '127.0.0.1', 'My browser')); $this->assertTrue($lastLoginModel->create('Test2', 1, '127.0.0.1', str_repeat('Too long', 50))); @@ -29,7 +29,7 @@ class LastLoginTest extends Base public function testCleanup() { - $lastLoginModel = new LastLogin($this->container); + $lastLoginModel = new LastLoginModel($this->container); for ($i = 0; $i < $lastLoginModel::NB_LOGINS + 5; $i++) { $this->assertTrue($lastLoginModel->create('Test' . $i, 1, '127.0.0.1', 'My browser')); diff --git a/tests/units/Model/LinkTest.php b/tests/units/Model/LinkTest.php index b102646d..600c09f3 100644 --- a/tests/units/Model/LinkTest.php +++ b/tests/units/Model/LinkTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Link; +use Kanboard\Model\LinkModel; class LinkTest extends Base { public function testCreateLink() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertNotFalse($l->create('Link A')); $this->assertFalse($l->create('Link A')); @@ -38,7 +38,7 @@ class LinkTest extends Base public function testGetOppositeLinkId() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertNotFalse($l->create('Link A')); $this->assertNotFalse($l->create('Link B', 'Link C')); @@ -50,7 +50,7 @@ class LinkTest extends Base public function testUpdate() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0))); @@ -62,7 +62,7 @@ class LinkTest extends Base public function testRemove() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $link = $l->getById(3); $this->assertNotEmpty($link); @@ -82,7 +82,7 @@ class LinkTest extends Base public function testGetMergedList() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $links = $l->getMergedList(); $this->assertNotEmpty($links); @@ -93,7 +93,7 @@ class LinkTest extends Base public function testGetList() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $links = $l->getList(); $this->assertNotEmpty($links); diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php index d5ec7735..96ee5f4e 100644 --- a/tests/units/Model/NotificationTest.php +++ b/tests/units/Model/NotificationTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\TaskFile; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\Notification; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\NotificationModel; use Kanboard\Subscriber\NotificationSubscriber; class NotificationTest extends Base { public function testGetTitle() { - $wn = new Notification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); - $f = new TaskFile($this->container); + $wn = new NotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); + $f = new TaskFileModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -62,7 +62,7 @@ class NotificationTest extends Base $this->assertNotEmpty($title); } - $this->assertNotEmpty($wn->getTitleWithoutAuthor(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); + $this->assertNotEmpty($wn->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); $this->assertNotEmpty($wn->getTitleWithoutAuthor('unkown', array())); } } diff --git a/tests/units/Model/PasswordResetTest.php b/tests/units/Model/PasswordResetTest.php index f88d24fb..01ca1d12 100644 --- a/tests/units/Model/PasswordResetTest.php +++ b/tests/units/Model/PasswordResetTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\PasswordReset; +use Kanboard\Model\UserModel; +use Kanboard\Model\PasswordResetModel; class PasswordResetTest extends Base { public function testCreate() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -22,8 +22,8 @@ class PasswordResetTest extends Base public function testGetUserIdByToken() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -33,8 +33,8 @@ class PasswordResetTest extends Base public function testGetUserIdByTokenWhenExpired() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -44,8 +44,8 @@ class PasswordResetTest extends Base public function testDisableTokens() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -63,8 +63,8 @@ class PasswordResetTest extends Base public function testGetAll() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); $this->assertNotFalse($passwordResetModel->create('user2')); diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php index 16036cd4..0b87b515 100644 --- a/tests/units/Model/ProjectActivityTest.php +++ b/tests/units/Model/ProjectActivityTest.php @@ -2,43 +2,43 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\ProjectModel; class ProjectActivityTest extends Base { public function testCreation() { - $projectActivity = new ProjectActivity($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); - $projectModel = new Project($this->container); + $projectActivity = new ProjectActivityModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Task #2', 'project_id' => 1))); - $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $taskFinder->getById(1)))); - $this->assertTrue($projectActivity->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $taskFinder->getById(2)))); - $this->assertFalse($projectActivity->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $taskFinder->getById(1)))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, TaskModel::EVENT_CLOSE, array('task' => $taskFinder->getById(1)))); + $this->assertTrue($projectActivity->createEvent(1, 2, 1, TaskModel::EVENT_UPDATE, array('task' => $taskFinder->getById(2)))); + $this->assertFalse($projectActivity->createEvent(1, 1, 0, TaskModel::EVENT_OPEN, array('task' => $taskFinder->getById(1)))); $events = $projectActivity->getQuery()->desc('id')->findAll(); $this->assertCount(2, $events); $this->assertEquals(time(), $events[0]['date_creation'], '', 1); - $this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']); - $this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']); + $this->assertEquals(TaskModel::EVENT_UPDATE, $events[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CLOSE, $events[1]['event_name']); } public function testCleanup() { - $projectActivity = new ProjectActivity($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); - $projectModel = new Project($this->container); + $projectActivity = new ProjectActivityModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); @@ -48,7 +48,7 @@ class ProjectActivityTest extends Base $task = $taskFinder->getById(1); for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, TaskModel::EVENT_CLOSE, array('task' => $task))); } $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count()); diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php index 4f92ad2b..5e500340 100644 --- a/tests/units/Model/ProjectDailyColumnStatsTest.php +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -2,29 +2,29 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectDailyColumnStats; -use Kanboard\Model\Config; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectDailyColumnStatsModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; class ProjectDailyColumnStatsTest extends Base { public function testUpdateTotalsWithScoreAtNull() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $projectDailyColumnStats->updateTotals(1, '2016-01-16'); - $task = $this->container['db']->table(Task::TABLE)->findOne(); + $task = $this->container['db']->table(TaskModel::TABLE)->findOne(); $this->assertNull($task['score']); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -45,8 +45,8 @@ class ProjectDailyColumnStatsTest extends Base public function testUpdateTotals() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->createTasks(1, 2, 1); @@ -68,7 +68,7 @@ class ProjectDailyColumnStatsTest extends Base $projectDailyColumnStats->updateTotals(1, '2016-01-17'); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -117,9 +117,9 @@ class ProjectDailyColumnStatsTest extends Base public function testUpdateTotalsWithOnlyOpenTasks() { - $configModel = new Config($this->container); - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $configModel = new ConfigModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($configModel->save(array('cfd_include_closed_tasks' => 0))); @@ -144,7 +144,7 @@ class ProjectDailyColumnStatsTest extends Base $projectDailyColumnStats->updateTotals(1, '2016-01-17'); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -193,8 +193,8 @@ class ProjectDailyColumnStatsTest extends Base public function testCountDays() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -208,8 +208,8 @@ class ProjectDailyColumnStatsTest extends Base public function testGetAggregatedMetrics() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->createTasks(1, 2, 1); @@ -258,7 +258,7 @@ class ProjectDailyColumnStatsTest extends Base private function createTasks($column_id, $score, $is_active) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'score' => $score, 'is_active' => $is_active))); } } diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php index c3b20cb9..851af985 100644 --- a/tests/units/Model/ProjectDailyStatsTest.php +++ b/tests/units/Model/ProjectDailyStatsTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectDailyStats; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskStatus; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectDailyStatsModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskStatusModel; class ProjectDailyStatsTest extends Base { public function testUpdateTotals() { - $p = new Project($this->container); - $pds = new ProjectDailyStats($this->container); - $tc = new TaskCreation($this->container); - $ts = new TaskStatus($this->container); + $p = new ProjectModel($this->container); + $pds = new ProjectDailyStatsModel($this->container); + $tc = new TaskCreationModel($this->container); + $ts = new TaskStatusModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php index 4023a28f..312c7168 100644 --- a/tests/units/Model/ProjectDuplicationTest.php +++ b/tests/units/Model/ProjectDuplicationTest.php @@ -2,33 +2,33 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Action; -use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectDuplication; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\Swimlane; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\ActionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectDuplicationModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Core\Security\Role; class ProjectDuplicationTest extends Base { public function testGetSelections() { - $projectDuplicationModel = new ProjectDuplication($this->container); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); $this->assertCount(6, $projectDuplicationModel->getOptionalSelection()); $this->assertCount(7, $projectDuplicationModel->getPossibleSelection()); } public function testGetClonedProjectName() { - $pd = new ProjectDuplication($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test')); @@ -41,8 +41,8 @@ class ProjectDuplicationTest extends Base public function testClonePublicProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Public'))); $this->assertEquals(2, $pd->duplicate(1)); @@ -59,9 +59,9 @@ class ProjectDuplicationTest extends Base public function testClonePrivateProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $pp = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); $this->assertEquals(2, $pd->duplicate(1)); @@ -80,8 +80,8 @@ class ProjectDuplicationTest extends Base public function testCloneSharedProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Shared'))); $this->assertTrue($p->update(array('id' => 1, 'is_public' => 1, 'token' => 'test'))); @@ -101,8 +101,8 @@ class ProjectDuplicationTest extends Base public function testCloneInactiveProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Inactive'))); $this->assertTrue($p->update(array('id' => 1, 'is_active' => 0))); @@ -120,16 +120,16 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithOwner() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); $project = $p->getById(1); $this->assertEquals(0, $project['owner_id']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -141,15 +141,15 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithDifferentName() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); $project = $p->getById(1); $this->assertEquals(0, $project['owner_id']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar')); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar')); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -159,8 +159,8 @@ class ProjectDuplicationTest extends Base public function testCloneProjectAndForceItToBePrivate() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); @@ -168,7 +168,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(0, $project['owner_id']); $this->assertEquals(0, $project['is_private']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar', true)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -179,9 +179,9 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithCategories() { - $p = new Project($this->container); - $c = new Category($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -204,10 +204,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithUsers() { - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2'))); @@ -229,10 +229,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithUsersAndOverrideOwner() { - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); @@ -243,7 +243,7 @@ class ProjectDuplicationTest extends Base $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1)); $this->assertCount(2, $pp->getUsers(2)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); @@ -255,10 +255,10 @@ class ProjectDuplicationTest extends Base public function testCloneTeamProjectToPrivatProject() { - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2'))); @@ -271,7 +271,7 @@ class ProjectDuplicationTest extends Base $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 3, 'My private project', true)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true)); $this->assertCount(1, $pp->getUsers(2)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3)); @@ -283,13 +283,13 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithGroups() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $projectGroupRoleModel = new ProjectGroupRole($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $projectGroupRoleModel = new ProjectGroupRoleModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -319,15 +319,15 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithActionTaskAssignCurrentUser() { - $p = new Project($this->container); - $a = new Action($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $a = new ActionModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); $this->assertEquals(1, $a->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => 'TaskAssignCurrentUser', 'params' => array('column_id' => 2), ))); @@ -344,10 +344,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithActionTaskAssignColorCategory() { - $p = new Project($this->container); - $a = new Action($this->container); - $c = new Category($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $a = new ActionModel($this->container); + $c = new CategoryModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -357,7 +357,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(1, $a->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignColorCategory', 'params' => array('color_id' => 'blue', 'category_id' => 2), ))); @@ -375,11 +375,11 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithSwimlanes() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); @@ -394,7 +394,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(3, $tc->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2))); $this->assertEquals(4, $tc->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3))); - $this->assertEquals(2, $pd->duplicate(1, array('category', 'swimlane'))); + $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'swimlaneModel'))); $swimlanes = $s->getAll(2); $this->assertCount(3, $swimlanes); @@ -414,10 +414,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithTasks() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -426,7 +426,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); - $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task'))); + $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'actionModel', 'taskModel'))); // Check if Tasks have been duplicated $tasks = $tf->getAll(2); @@ -438,11 +438,11 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithSwimlanesAndTasks() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); @@ -456,7 +456,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission', 'swimlane', 'task'))); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel'))); // Check if Swimlanes have been duplicated $swimlanes = $s->getAll(2); diff --git a/tests/units/Model/ProjectFileTest.php b/tests/units/Model/ProjectFileTest.php index 0d7a9377..116dd3d2 100644 --- a/tests/units/Model/ProjectFileTest.php +++ b/tests/units/Model/ProjectFileTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\ProjectFile; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectFileModel; +use Kanboard\Model\ProjectModel; class ProjectFileTest extends Base { public function testCreation() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); @@ -34,8 +34,8 @@ class ProjectFileTest extends Base public function testCreationWithFileNameTooLong() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -54,8 +54,8 @@ class ProjectFileTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); @@ -67,8 +67,8 @@ class ProjectFileTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -100,13 +100,13 @@ class ProjectFileTest extends Base public function testGetThumbnailPath() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); } public function testGeneratePath() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertStringStartsWith('projects'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); @@ -115,12 +115,12 @@ class ProjectFileTest extends Base public function testUploadFiles() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -181,7 +181,7 @@ class ProjectFileTest extends Base public function testUploadFilesWithEmptyFiles() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, array())); } @@ -206,7 +206,7 @@ class ProjectFileTest extends Base ), ); - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } @@ -237,19 +237,19 @@ class ProjectFileTest extends Base ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } public function testUploadFileContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -276,12 +276,12 @@ class ProjectFileTest extends Base public function testUploadImageContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromData')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); diff --git a/tests/units/Model/ProjectGroupRoleTest.php b/tests/units/Model/ProjectGroupRoleTest.php index e38e812a..e703d4a9 100644 --- a/tests/units/Model/ProjectGroupRoleTest.php +++ b/tests/units/Model/ProjectGroupRoleTest.php @@ -2,21 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; use Kanboard\Core\Security\Role; class ProjectGroupRoleTest extends Base { public function testGetUserRole() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group A')); @@ -30,9 +30,9 @@ class ProjectGroupRoleTest extends Base public function testAddGroup() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -49,9 +49,9 @@ class ProjectGroupRoleTest extends Base public function testRemoveGroup() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -65,9 +65,9 @@ class ProjectGroupRoleTest extends Base public function testChangeRole() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -84,9 +84,9 @@ class ProjectGroupRoleTest extends Base public function testGetGroups() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group C')); @@ -115,11 +115,11 @@ class ProjectGroupRoleTest extends Base public function testGetUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -164,11 +164,11 @@ class ProjectGroupRoleTest extends Base public function testGetAssignableUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -206,11 +206,11 @@ class ProjectGroupRoleTest extends Base public function testGetAssignableUsersWithDisabledUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -244,11 +244,11 @@ class ProjectGroupRoleTest extends Base public function testGetProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -290,11 +290,11 @@ class ProjectGroupRoleTest extends Base public function testGetActiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -317,27 +317,27 @@ class ProjectGroupRoleTest extends Base $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); - $projects = $groupRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(2, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(3, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(4, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(5, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); } public function testGetInactiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -360,29 +360,29 @@ class ProjectGroupRoleTest extends Base $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); - $projects = $groupRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(2, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(3, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(4, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(5, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); } public function testUserInMultipleGroupsShouldReturnHighestRole() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'My user'))); diff --git a/tests/units/Model/ProjectMetadataTest.php b/tests/units/Model/ProjectMetadataTest.php index 16f49033..2f6d111a 100644 --- a/tests/units/Model/ProjectMetadataTest.php +++ b/tests/units/Model/ProjectMetadataTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectMetadata; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectMetadataModel; class ProjectMetadataTest extends Base { public function testOperations() { - $projectModel = new Project($this->container); - $projectMetadataModel = new ProjectMetadata($this->container); + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'project #2'))); @@ -39,8 +39,8 @@ class ProjectMetadataTest extends Base public function testAutomaticRemove() { - $projectModel = new Project($this->container); - $projectMetadataModel = new ProjectMetadata($this->container); + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1'))); @@ -52,8 +52,8 @@ class ProjectMetadataTest extends Base public function testDuplicate() { - $projectModel = new Project($this->container); - $projectMetadataModel = new ProjectMetadata($this->container); + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'project #2'))); diff --git a/tests/units/Model/ProjectNotificationTypeTest.php b/tests/units/Model/ProjectNotificationTypeTest.php index 71e2b964..7f735828 100644 --- a/tests/units/Model/ProjectNotificationTypeTest.php +++ b/tests/units/Model/ProjectNotificationTypeTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectNotificationType; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectNotificationTypeModel; class ProjectNotificationTypeTest extends Base { public function testGetTypes() { - $nt = new ProjectNotificationType($this->container); + $nt = new ProjectNotificationTypeModel($this->container); $this->assertEmpty($nt->getTypes()); $nt->setType('foo', 'Foo', 'Something1'); @@ -22,8 +22,8 @@ class ProjectNotificationTypeTest extends Base public function testGetSelectedTypes() { - $nt = new ProjectNotificationType($this->container); - $p = new Project($this->container); + $nt = new ProjectNotificationTypeModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index f88796b4..c9e0a481 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -2,26 +2,26 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectPermissionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ProjectPermissionTest extends Base { public function testFindByUsernames() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermissionModel = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermissionModel = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); @@ -42,10 +42,10 @@ class ProjectPermissionTest extends Base public function testGetQueryByRole() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -105,8 +105,8 @@ class ProjectPermissionTest extends Base public function testEverybodyAllowed() { - $projectModel = new Project($this->container); - $projectPermission = new ProjectPermission($this->container); + $projectModel = new ProjectModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_everybody_allowed' => 1))); @@ -117,13 +117,13 @@ class ProjectPermissionTest extends Base public function testIsUserAllowed() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -154,13 +154,13 @@ class ProjectPermissionTest extends Base public function testIsAssignable() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -191,10 +191,10 @@ class ProjectPermissionTest extends Base public function testIsAssignableWhenUserIsDisabled() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0))); @@ -210,13 +210,13 @@ class ProjectPermissionTest extends Base public function testIsMember() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -247,10 +247,10 @@ class ProjectPermissionTest extends Base public function testGetActiveProjectIds() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -269,13 +269,13 @@ class ProjectPermissionTest extends Base public function testDuplicate() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 6c50744b..472d7351 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -4,20 +4,20 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Translator; use Kanboard\Subscriber\ProjectModificationDateSubscriber; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Config; -use Kanboard\Model\Category; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\CategoryModel; class ProjectTest extends Base { public function testCreationForAllLanguages() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); - foreach ($this->container['language']->getLanguages() as $locale => $language) { + foreach ($this->container['languageModel']->getLanguages() as $locale => $language) { Translator::unload(); Translator::load($locale); $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); @@ -28,7 +28,7 @@ class ProjectTest extends Base public function testCreation() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); @@ -43,7 +43,7 @@ class ProjectTest extends Base public function testCreationWithDuplicateName() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); @@ -51,7 +51,7 @@ class ProjectTest extends Base public function testCreationWithStartAndDate() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31'))); @@ -63,9 +63,9 @@ class ProjectTest extends Base public function testCreationWithDefaultCategories() { - $p = new Project($this->container); - $c = new Config($this->container); - $cat = new Category($this->container); + $p = new ProjectModel($this->container); + $c = new ConfigModel($this->container); + $cat = new CategoryModel($this->container); // Multiple categories correctly formatted @@ -124,7 +124,7 @@ class ProjectTest extends Base public function testUpdateLastModifiedDate() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $now = time(); @@ -143,7 +143,7 @@ class ProjectTest extends Base public function testGetAllIds() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); @@ -154,8 +154,8 @@ class ProjectTest extends Base public function testIsLastModified() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $now = time(); @@ -168,12 +168,12 @@ class ProjectTest extends Base sleep(1); $listener = new ProjectModificationDateSubscriber($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($listener, 'execute')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute')); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); $project = $p->getById(1); $this->assertNotEmpty($project); @@ -182,7 +182,7 @@ class ProjectTest extends Base public function testRemove() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->remove(1)); @@ -191,7 +191,7 @@ class ProjectTest extends Base public function testEnable() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->disable(1)); @@ -205,7 +205,7 @@ class ProjectTest extends Base public function testDisable() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->disable(1)); @@ -220,7 +220,7 @@ class ProjectTest extends Base public function testEnablePublicAccess() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->enablePublicAccess(1)); @@ -235,7 +235,7 @@ class ProjectTest extends Base public function testDisablePublicAccess() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->enablePublicAccess(1)); @@ -251,7 +251,7 @@ class ProjectTest extends Base public function testIdentifier() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); // Creation $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); @@ -282,8 +282,8 @@ class ProjectTest extends Base public function testThatProjectCreatorAreAlsoOwner() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'Me'))); $this->assertEquals(1, $projectModel->create(array('name' => 'My project 1'), 2)); @@ -306,7 +306,7 @@ class ProjectTest extends Base public function testPriority() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); $project = $projectModel->getById(1); diff --git a/tests/units/Model/ProjectUserRoleTest.php b/tests/units/Model/ProjectUserRoleTest.php index 0e06ac5e..d59b15c9 100644 --- a/tests/units/Model/ProjectUserRoleTest.php +++ b/tests/units/Model/ProjectUserRoleTest.php @@ -2,21 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectPermissionModel; use Kanboard\Core\Security\Role; class ProjectUserRoleTest extends Base { public function testAddUser() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -33,8 +33,8 @@ class ProjectUserRoleTest extends Base public function testRemoveUser() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -47,8 +47,8 @@ class ProjectUserRoleTest extends Base public function testChangeRole() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -65,8 +65,8 @@ class ProjectUserRoleTest extends Base public function testGetRole() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEmpty($userRoleModel->getUserRole(1, 1)); @@ -85,11 +85,11 @@ class ProjectUserRoleTest extends Base public function testGetRoleWithGroups() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group A')); @@ -103,9 +103,9 @@ class ProjectUserRoleTest extends Base public function testGetRoleWithPublicProject() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); @@ -123,9 +123,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithDisabledUsers() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); @@ -153,9 +153,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithoutGroups() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); @@ -174,12 +174,12 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithGroups() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -211,9 +211,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersList() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Test2'))); @@ -249,9 +249,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithEverybodyAllowed() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test', 'is_everybody_allowed' => 1))); @@ -272,10 +272,10 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithDisabledUsersAndEverybodyAllowed() { - $projectModel = new Project($this->container); - $projectPermission = new ProjectPermission($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); @@ -302,12 +302,12 @@ class ProjectUserRoleTest extends Base public function testGetProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -364,12 +364,12 @@ class ProjectUserRoleTest extends Base public function testGetActiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -398,36 +398,36 @@ class ProjectUserRoleTest extends Base $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); - $projects = $userRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(2, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(3, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(4, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(5, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); - $projects = $userRoleModel->getProjectsByUser(6, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(6, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); - $projects = $userRoleModel->getProjectsByUser(7, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(7, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); } public function testGetInactiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -456,26 +456,26 @@ class ProjectUserRoleTest extends Base $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); - $projects = $userRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(2, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(3, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(4, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(5, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(6, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(6, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(7, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(7, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); } } diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index 20186452..b65ee609 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\ProjectModel; use Kanboard\Core\User\UserSession; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskFinderModel; class SubtaskTest extends Base { @@ -46,7 +46,7 @@ class SubtaskTest extends Base $this->assertArrayHasKey('user_id', $data['changes']); $this->assertArrayHasKey('status', $data['changes']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $data['changes']['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']); $this->assertEquals(1, $data['changes']['user_id']); } @@ -70,14 +70,14 @@ class SubtaskTest extends Base public function testCreation() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_CREATE, array($this, 'onSubtaskCreated')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated')); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); @@ -86,7 +86,7 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtask['id']); $this->assertEquals(1, $subtask['task_id']); $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['time_estimated']); $this->assertEquals(0, $subtask['time_spent']); $this->assertEquals(0, $subtask['user_id']); @@ -95,24 +95,24 @@ class SubtaskTest extends Base public function testModification() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => Subtask::STATUS_INPROGRESS))); + $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS))); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); $this->assertEquals(1, $subtask['id']); $this->assertEquals(1, $subtask['task_id']); $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(0, $subtask['time_estimated']); $this->assertEquals(0, $subtask['time_spent']); $this->assertEquals(1, $subtask['user_id']); @@ -121,15 +121,15 @@ class SubtaskTest extends Base public function testRemove() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_DELETE, array($this, 'onSubtaskDeleted')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted')); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -142,9 +142,9 @@ class SubtaskTest extends Base public function testToggleStatusWithoutSession() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -153,40 +153,40 @@ class SubtaskTest extends Base $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); } public function testToggleStatusWithSession() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $us = new UserSession($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -196,43 +196,43 @@ class SubtaskTest extends Base $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); // Set the current logged user $this->container['sessionStorage']->user = array('id' => 1); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); } public function testCloseAll() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -246,15 +246,15 @@ class SubtaskTest extends Base $this->assertNotEmpty($subtasks); foreach ($subtasks as $subtask) { - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); } } public function testDuplicate() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); // We create a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -299,9 +299,9 @@ class SubtaskTest extends Base public function testChangePosition() { - $taskCreationModel = new TaskCreation($this->container); - $subtaskModel = new Subtask($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); @@ -364,10 +364,10 @@ class SubtaskTest extends Base public function testConvertToTask() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $subtaskModel = new Subtask($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index dead3887..d5ae62ae 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\SubtaskTimeTracking; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\SubtaskTimeTrackingModel; +use Kanboard\Model\ProjectModel; class SubtaskTimeTrackingTest extends Base { public function testHasTimer() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -31,10 +31,10 @@ class SubtaskTimeTrackingTest extends Base public function testGetTimerStatus() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->container['sessionStorage']->user = array('id' => 1); @@ -81,10 +81,10 @@ class SubtaskTimeTrackingTest extends Base public function testLogStartTime() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -103,10 +103,10 @@ class SubtaskTimeTrackingTest extends Base public function testLogStartEnd() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -134,10 +134,10 @@ class SubtaskTimeTrackingTest extends Base public function testCalculateSubtaskTime() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -152,10 +152,10 @@ class SubtaskTimeTrackingTest extends Base public function testUpdateSubtaskTimeSpent() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -166,7 +166,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertTrue($st->logStartTime(2, 1)); // Fake start time - $this->container['db']->table(SubtaskTimeTracking::TABLE)->update(array('start' => time() - 3600)); + $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600)); $this->assertTrue($st->logEndTime(1, 1)); $this->assertTrue($st->logEndTime(2, 1)); @@ -188,11 +188,11 @@ class SubtaskTimeTrackingTest extends Base public function testUpdateTaskTimeTracking() { - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php index 380d8c77..2594b17a 100644 --- a/tests/units/Model/SwimlaneTest.php +++ b/tests/units/Model/SwimlaneTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\SwimlaneModel; class SwimlaneTest extends Base { public function testCreation() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -32,8 +32,8 @@ class SwimlaneTest extends Base public function testGetList() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -47,8 +47,8 @@ class SwimlaneTest extends Base public function testUpdate() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -66,8 +66,8 @@ class SwimlaneTest extends Base public function testUpdateDefaultSwimlane() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 1))); @@ -87,8 +87,8 @@ class SwimlaneTest extends Base public function testDisableEnableDefaultSwimlane() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -103,8 +103,8 @@ class SwimlaneTest extends Base public function testDisableEnable() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -143,10 +143,10 @@ class SwimlaneTest extends Base public function testRemove() { - $p = new Project($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -167,8 +167,8 @@ class SwimlaneTest extends Base public function testUpdatePositions() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -227,8 +227,8 @@ class SwimlaneTest extends Base public function testDuplicateSwimlane() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); $this->assertEquals(2, $p->create(array('name' => 'P2'))); @@ -258,8 +258,8 @@ class SwimlaneTest extends Base public function testChangePosition() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -321,8 +321,8 @@ class SwimlaneTest extends Base public function testChangePositionWithInactiveSwimlane() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php index d6860b30..aba52ae2 100644 --- a/tests/units/Model/TaskCreationTest.php +++ b/tests/units/Model/TaskCreationTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskCreationTest extends Base { @@ -22,36 +22,36 @@ class TaskCreationTest extends Base public function testNoProjectId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE.'.closure', $called); } public function testNoTitle() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -62,19 +62,19 @@ class TaskCreationTest extends Base public function testMinimum() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, array($this, 'onCreate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, array($this, 'onCreate')); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.TaskCreationTest::onCreate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.TaskCreationTest::onCreate', $called); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -108,9 +108,9 @@ class TaskCreationTest extends Base public function testColorId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue'))); @@ -124,9 +124,9 @@ class TaskCreationTest extends Base public function testOwnerId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1))); @@ -140,9 +140,9 @@ class TaskCreationTest extends Base public function testCategoryId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1))); @@ -156,9 +156,9 @@ class TaskCreationTest extends Base public function testCreatorId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1))); @@ -172,9 +172,9 @@ class TaskCreationTest extends Base public function testThatCreatorIsDefined() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->container['sessionStorage']->user = array('id' => 1); @@ -190,9 +190,9 @@ class TaskCreationTest extends Base public function testColumnId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); @@ -207,9 +207,9 @@ class TaskCreationTest extends Base public function testPosition() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); @@ -233,9 +233,9 @@ class TaskCreationTest extends Base public function testDescription() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test'))); @@ -249,9 +249,9 @@ class TaskCreationTest extends Base public function testReference() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test'))); @@ -267,9 +267,9 @@ class TaskCreationTest extends Base { $date = '2014-11-23'; $timestamp = strtotime('+2days'); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date))); @@ -293,9 +293,9 @@ class TaskCreationTest extends Base public function testDateStarted() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); @@ -331,9 +331,9 @@ class TaskCreationTest extends Base public function testTime() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3))); @@ -348,9 +348,9 @@ class TaskCreationTest extends Base public function testStripColumn() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1'))); @@ -361,9 +361,9 @@ class TaskCreationTest extends Base public function testScore() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3'))); @@ -376,10 +376,10 @@ class TaskCreationTest extends Base public function testDefaultColor() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $c = new Config($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $c = new ConfigModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test1'))); @@ -400,9 +400,9 @@ class TaskCreationTest extends Base public function testDueDateYear2038TimestampBug() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => strtotime('2050-01-10 12:30')))); diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index 8c5f5cec..79b75e54 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -3,25 +3,25 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\DateParser; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskDuplication; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\Category; -use Kanboard\Model\User; -use Kanboard\Model\Swimlane; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskDuplicationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\SwimlaneModel; use Kanboard\Core\Security\Role; class TaskDuplicationTest extends Base { public function testThatDuplicateDefineCreator() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -45,11 +45,11 @@ class TaskDuplicationTest extends Base public function testDuplicateSameProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create a task and a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -73,20 +73,20 @@ class TaskDuplicationTest extends Base $this->assertEquals(2, $task['category_id']); $this->assertEquals(4.4, $task['time_spent']); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); // We duplicate our task $this->assertEquals(2, $td->duplicate(1)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); // Check the values of the duplicated task $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(1, $task['project_id']); $this->assertEquals(1, $task['owner_id']); $this->assertEquals(2, $task['category_id']); @@ -99,11 +99,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -115,15 +115,15 @@ class TaskDuplicationTest extends Base // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); // We duplicate our task to the 2nd project $this->assertEquals(2, $td->duplicateToProject(1, 2)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); // Check the values of the duplicated task $task = $tf->getById(2); @@ -139,11 +139,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -174,11 +174,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -213,11 +213,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -246,11 +246,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithoutSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -279,11 +279,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -307,10 +307,10 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedColumn() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -330,11 +330,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -356,7 +356,7 @@ class TaskDuplicationTest extends Base $this->assertEquals('test', $task['title']); // We create a new user for our project - $user = new User($this->container); + $user = new UserModel($this->container); $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); @@ -386,11 +386,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pr = new ProjectUserRole($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pr = new ProjectUserRoleModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -421,11 +421,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -434,13 +434,13 @@ class TaskDuplicationTest extends Base // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); // We duplicate our task to the 2nd project $this->assertTrue($td->moveToProject(1, 2)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called); // Check the values of the moved task $task = $tf->getById(1); @@ -456,11 +456,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -491,12 +491,12 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -524,12 +524,12 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithForbiddenUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -557,11 +557,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -590,11 +590,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithoutSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -623,47 +623,47 @@ class TaskDuplicationTest extends Base public function testCalculateRecurringTaskDueDate() { - $td = new TaskDuplication($this->container); + $td = new TaskDuplicationModel($this->container); $values = array('date_due' => 0); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(0, $values['date_due']); - $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(0, $values['date_due']); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(time() + 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_MONTHS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1436561776, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_YEARS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1494449776, $values['date_due'], '', 1); } public function testDuplicateRecurringTask() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $dp = new DateParser($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -672,27 +672,27 @@ class TaskDuplicationTest extends Base 'title' => 'test', 'project_id' => 1, 'date_due' => 1436561776, - 'recurrence_status' => Task::RECURRING_STATUS_PENDING, - 'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE, + 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING, + 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE, 'recurrence_factor' => 2, - 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS, - 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, + 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS, + 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, ))); $this->assertEquals(2, $td->duplicateRecurringTask(1)); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); $this->assertEquals(2, $task['recurrence_child']); $this->assertEquals(1436486400, $task['date_due'], '', 2); $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']); - $this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); - $this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); - $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); + $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); + $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); $this->assertEquals(1, $task['recurrence_parent']); $this->assertEquals(2, $task['recurrence_factor']); $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); diff --git a/tests/units/Model/TaskExternalLinkTest.php b/tests/units/Model/TaskExternalLinkTest.php index 3a79ff82..1327b6e1 100644 --- a/tests/units/Model/TaskExternalLinkTest.php +++ b/tests/units/Model/TaskExternalLinkTest.php @@ -2,9 +2,9 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\TaskExternalLink; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskExternalLinkModel; use Kanboard\Core\ExternalLink\ExternalLinkManager; use Kanboard\ExternalLink\WebLinkProvider; @@ -12,9 +12,9 @@ class TaskExternalLinkTest extends Base { public function testCreate() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); @@ -35,9 +35,9 @@ class TaskExternalLinkTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); @@ -56,9 +56,9 @@ class TaskExternalLinkTest extends Base public function testModification() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); @@ -76,9 +76,9 @@ class TaskExternalLinkTest extends Base public function testRemove() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); @@ -95,9 +95,9 @@ class TaskExternalLinkTest extends Base $this->container['sessionStorage']->user = array('id' => 1); $this->container['externalLinkManager'] = new ExternalLinkManager($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $webLinkProvider = new WebLinkProvider($this->container); $this->container['externalLinkManager']->register($webLinkProvider); diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php index e44e092d..2faee95c 100644 --- a/tests/units/Model/TaskFileTest.php +++ b/tests/units/Model/TaskFileTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFile; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskFileTest extends Base { public function testCreation() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -38,9 +38,9 @@ class TaskFileTest extends Base public function testCreationWithFileNameTooLong() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -60,9 +60,9 @@ class TaskFileTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -75,9 +75,9 @@ class TaskFileTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -110,7 +110,7 @@ class TaskFileTest extends Base public function testIsImage() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertTrue($fileModel->isImage('test.png')); $this->assertTrue($fileModel->isImage('test.jpeg')); @@ -125,13 +125,13 @@ class TaskFileTest extends Base public function testGetThumbnailPath() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); } public function testGeneratePath() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); @@ -140,13 +140,13 @@ class TaskFileTest extends Base public function testUploadFiles() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -208,7 +208,7 @@ class TaskFileTest extends Base public function testUploadFilesWithEmptyFiles() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, array())); } @@ -233,7 +233,7 @@ class TaskFileTest extends Base ), ); - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } @@ -264,20 +264,20 @@ class TaskFileTest extends Base ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } public function testUploadFileContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -305,13 +305,13 @@ class TaskFileTest extends Base public function testUploadFileContentWithObjectStorageError() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -329,13 +329,13 @@ class TaskFileTest extends Base public function testUploadScreenshot() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromData')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -366,9 +366,9 @@ class TaskFileTest extends Base public function testRemove() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -384,9 +384,9 @@ class TaskFileTest extends Base public function testRemoveWithObjectStorageError() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -403,9 +403,9 @@ class TaskFileTest extends Base public function testRemoveImage() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -426,9 +426,9 @@ class TaskFileTest extends Base public function testRemoveAll() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index ef9d7830..46792baf 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskFinderTest extends Base { public function testGetOverdueTasks() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); @@ -29,9 +29,9 @@ class TaskFinderTest extends Base public function testGetOverdueTasksByProject() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -50,9 +50,9 @@ class TaskFinderTest extends Base public function testGetOverdueTasksByUser() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -80,9 +80,9 @@ class TaskFinderTest extends Base public function testCountByProject() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -96,9 +96,9 @@ class TaskFinderTest extends Base public function testGetProjectToken() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index 8dd71830..bc574731 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskLink; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskLinkTest extends Base { // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression" public function testGetTaskWithMultipleMilestoneLink() { - $tf = new TaskFinder($this->container); - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tf = new TaskFinderModel($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -31,9 +31,9 @@ class TaskLinkTest extends Base public function testCreateTaskLinkWithNoOpposite() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -73,9 +73,9 @@ class TaskLinkTest extends Base public function testCreateTaskLinkWithOpposite() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -115,9 +115,9 @@ class TaskLinkTest extends Base public function testGroupByLabel() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); @@ -139,9 +139,9 @@ class TaskLinkTest extends Base public function testUpdate() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2'))); @@ -172,9 +172,9 @@ class TaskLinkTest extends Base public function testRemove() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); diff --git a/tests/units/Model/TaskMetadataTest.php b/tests/units/Model/TaskMetadataTest.php index 2683c297..b1e7eee8 100644 --- a/tests/units/Model/TaskMetadataTest.php +++ b/tests/units/Model/TaskMetadataTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskMetadata; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskMetadataModel; class TaskMetadataTest extends Base { public function testOperations() { - $p = new Project($this->container); - $tm = new TaskMetadata($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tm = new TaskMetadataModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'task #1', 'project_id' => 1))); diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index 315125d5..022fb49b 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskModification; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskModificationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskModificationTest extends Base { @@ -42,16 +42,16 @@ class TaskModificationTest extends Base public function testThatNoEventAreFiredWhenNoChanges() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); - $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate')); $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test'))); @@ -60,22 +60,22 @@ class TaskModificationTest extends Base public function testChangeTitle() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); - $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate')); $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1'))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called); - $this->assertArrayHasKey(Task::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called); $task = $tf->getById(1); $this->assertEquals('Task #1', $task['title']); @@ -83,10 +83,10 @@ class TaskModificationTest extends Base public function testChangeAssignee() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -94,12 +94,12 @@ class TaskModificationTest extends Base $task = $tf->getById(1); $this->assertEquals(0, $task['owner_id']); - $this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange')); $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called); + $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called); $task = $tf->getById(1); $this->assertEquals(1, $task['owner_id']); @@ -107,10 +107,10 @@ class TaskModificationTest extends Base public function testChangeDescription() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -126,10 +126,10 @@ class TaskModificationTest extends Base public function testChangeCategory() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -145,10 +145,10 @@ class TaskModificationTest extends Base public function testChangeColor() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -164,10 +164,10 @@ class TaskModificationTest extends Base public function testChangeScore() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -183,10 +183,10 @@ class TaskModificationTest extends Base public function testChangeDueDate() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -207,10 +207,10 @@ class TaskModificationTest extends Base public function testChangeStartedDate() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -245,10 +245,10 @@ class TaskModificationTest extends Base public function testChangeTimeEstimated() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -264,10 +264,10 @@ class TaskModificationTest extends Base public function testChangeTimeSpent() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionTest.php index 0f2e4b88..7ab6950e 100644 --- a/tests/units/Model/TaskPositionTest.php +++ b/tests/units/Model/TaskPositionTest.php @@ -2,26 +2,26 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\Column; -use Kanboard\Model\TaskStatus; -use Kanboard\Model\TaskPosition; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Swimlane; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\TaskStatusModel; +use Kanboard\Model\TaskPositionModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\SwimlaneModel; class TaskPositionTest extends Base { public function testGetTaskProgression() { - $t = new Task($this->container); - $ts = new TaskStatus($this->container); - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $columnModel = new Column($this->container); + $t = new TaskModel($this->container); + $ts = new TaskStatusModel($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -42,10 +42,10 @@ class TaskPositionTest extends Base public function testMoveTaskToWrongPosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -69,10 +69,10 @@ class TaskPositionTest extends Base public function testMoveTaskToGreaterPosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -96,10 +96,10 @@ class TaskPositionTest extends Base public function testMoveTaskToEmptyColumn() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -123,10 +123,10 @@ class TaskPositionTest extends Base public function testMoveTaskToAnotherColumn() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -186,10 +186,10 @@ class TaskPositionTest extends Base public function testMoveTaskTop() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -224,10 +224,10 @@ class TaskPositionTest extends Base public function testMoveTaskBottom() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -262,10 +262,10 @@ class TaskPositionTest extends Base public function testMovePosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $counter = 1; @@ -415,11 +415,11 @@ class TaskPositionTest extends Base public function testMoveTaskSwimlane() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); @@ -522,11 +522,11 @@ class TaskPositionTest extends Base public function testEvents() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); @@ -534,9 +534,9 @@ class TaskPositionTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2))); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn')); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition')); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, array($this, 'onMovePosition')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane')); // We move the task 1 to the column 2 $this->assertTrue($tp->movePosition(1, 1, 2, 1)); @@ -552,7 +552,7 @@ class TaskPositionTest extends Base $this->assertEquals(2, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called); $this->assertEquals(1, count($called)); // We move the task 1 to the position 2 @@ -569,7 +569,7 @@ class TaskPositionTest extends Base $this->assertEquals(1, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called); $this->assertEquals(2, count($called)); // Move to another swimlane @@ -588,7 +588,7 @@ class TaskPositionTest extends Base $this->assertEquals(0, $task['swimlane_id']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called); $this->assertEquals(3, count($called)); } diff --git a/tests/units/Model/TaskStatusTest.php b/tests/units/Model/TaskStatusTest.php index aa48be5e..f011409d 100644 --- a/tests/units/Model/TaskStatusTest.php +++ b/tests/units/Model/TaskStatusTest.php @@ -2,23 +2,23 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Swimlane; -use Kanboard\Model\Subtask; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; -use Kanboard\Model\Project; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskStatusModel; +use Kanboard\Model\ProjectModel; class TaskStatusTest extends Base { public function testCloseBySwimlaneAndColumn() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $ts = new TaskStatus($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $ts = new TaskStatusModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $s->create(array('name' => 'test', 'project_id' => 1))); @@ -56,10 +56,10 @@ class TaskStatusTest extends Base public function testStatus() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $ts = new TaskStatus($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $ts = new TaskStatusModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -70,21 +70,21 @@ class TaskStatusTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(0, $task['date_completed']); $this->assertEquals(time(), $task['date_modification'], '', 1); // We close the task - $this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose')); - $this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, array($this, 'onTaskClose')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, array($this, 'onTaskOpen')); $this->assertTrue($ts->close(1)); $this->assertTrue($ts->isClosed(1)); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_CLOSED, $task['is_active']); $this->assertEquals(time(), $task['date_completed'], 'Bad completion timestamp', 1); $this->assertEquals(time(), $task['date_modification'], 'Bad modification timestamp', 1); @@ -95,7 +95,7 @@ class TaskStatusTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(0, $task['date_completed']); $this->assertEquals(time(), $task['date_modification'], '', 1); @@ -120,10 +120,10 @@ class TaskStatusTest extends Base public function testThatAllSubtasksAreClosed() { - $ts = new TaskStatus($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $ts = new TaskStatusModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -137,7 +137,7 @@ class TaskStatusTest extends Base $this->assertNotEmpty($subtasks); foreach ($subtasks as $subtask) { - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); } } } diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php index e9815b83..89fc4dc1 100644 --- a/tests/units/Model/TaskTest.php +++ b/tests/units/Model/TaskTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskTest extends Base { public function testRemove() { - $t = new Task($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $t = new TaskModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); @@ -23,36 +23,36 @@ class TaskTest extends Base public function testGetTaskIdFromText() { - $t = new Task($this->container); + $t = new TaskModel($this->container); $this->assertEquals(123, $t->getTaskIdFromText('My task #123')); $this->assertEquals(0, $t->getTaskIdFromText('My task 123')); } public function testRecurrenceSettings() { - $t = new Task($this->container); + $t = new TaskModel($this->container); $statuses = $t->getRecurrenceStatusList(); $this->assertCount(2, $statuses); - $this->assertArrayHasKey(Task::RECURRING_STATUS_NONE, $statuses); - $this->assertArrayHasKey(Task::RECURRING_STATUS_PENDING, $statuses); - $this->assertArrayNotHasKey(Task::RECURRING_STATUS_PROCESSED, $statuses); + $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_NONE, $statuses); + $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_PENDING, $statuses); + $this->assertArrayNotHasKey(TaskModel::RECURRING_STATUS_PROCESSED, $statuses); $triggers = $t->getRecurrenceTriggerList(); $this->assertCount(3, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_FIRST_COLUMN, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_LAST_COLUMN, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_CLOSE, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_LAST_COLUMN, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_CLOSE, $triggers); $dates = $t->getRecurrenceBasedateList(); $this->assertCount(2, $dates); - $this->assertArrayHasKey(Task::RECURRING_BASEDATE_DUEDATE, $dates); - $this->assertArrayHasKey(Task::RECURRING_BASEDATE_TRIGGERDATE, $dates); + $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates); + $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates); $timeframes = $t->getRecurrenceTimeframeList(); $this->assertCount(3, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_DAYS, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_MONTHS, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_YEARS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_DAYS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_MONTHS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_YEARS, $timeframes); } } diff --git a/tests/units/Model/TimezoneTest.php b/tests/units/Model/TimezoneTest.php index ac2cd6a1..8e7103d8 100644 --- a/tests/units/Model/TimezoneTest.php +++ b/tests/units/Model/TimezoneTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Timezone; +use Kanboard\Model\TimezoneModel; class TimezoneTest extends Base { public function testGetTimezones() { - $timezoneModel = new Timezone($this->container); + $timezoneModel = new TimezoneModel($this->container); $this->assertNotEmpty($timezoneModel->getTimezones()); $this->assertArrayHasKey('Europe/Paris', $timezoneModel->getTimezones()); $this->assertContains('Europe/Paris', $timezoneModel->getTimezones()); @@ -20,7 +20,7 @@ class TimezoneTest extends Base public function testGetCurrentTimezone() { - $timezoneModel = new Timezone($this->container); + $timezoneModel = new TimezoneModel($this->container); $this->assertEquals('UTC', $timezoneModel->getCurrentTimezone()); $this->container['sessionStorage']->user = array('timezone' => 'Europe/Paris'); diff --git a/tests/units/Model/TransitionTest.php b/tests/units/Model/TransitionTest.php index 0c262e78..2edf9c43 100644 --- a/tests/units/Model/TransitionTest.php +++ b/tests/units/Model/TransitionTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Transition; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TransitionModel; +use Kanboard\Model\ProjectModel; class TransitionTest extends Base { public function testSave() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -40,9 +40,9 @@ class TransitionTest extends Base public function testGetTimeSpentByTask() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -77,9 +77,9 @@ class TransitionTest extends Base public function testGetAllByProject() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1'))); diff --git a/tests/units/Model/UserLockingTest.php b/tests/units/Model/UserLockingTest.php index c743f8eb..1fcb97fe 100644 --- a/tests/units/Model/UserLockingTest.php +++ b/tests/units/Model/UserLockingTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\UserLocking; +use Kanboard\Model\UserLockingModel; class UserLockingTest extends Base { public function testFailedLogin() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertEquals(0, $u->getFailedLogin('admin')); $this->assertEquals(0, $u->getFailedLogin('not_found')); @@ -23,7 +23,7 @@ class UserLockingTest extends Base public function testLocking() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertFalse($u->isLocked('admin')); $this->assertFalse($u->isLocked('not_found')); @@ -33,7 +33,7 @@ class UserLockingTest extends Base public function testCaptcha() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertTrue($u->incrementFailedLogin('admin')); $this->assertFalse($u->hasCaptcha('admin', 2)); diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Model/UserMentionTest.php index d50c9285..b41c92cd 100644 --- a/tests/units/Model/UserMentionTest.php +++ b/tests/units/Model/UserMentionTest.php @@ -4,19 +4,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Security\Role; use Kanboard\Event\GenericEvent; -use Kanboard\Model\User; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\UserMention; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserMentionModel; class UserMentionTest extends Base { public function testGetMentionedUsersWithNoMentions() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertEmpty($userMentionModel->getMentionedUsers('test')); @@ -24,8 +24,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationDisabled() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1')); @@ -33,8 +33,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationEnabled() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); @@ -50,8 +50,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() { $this->container['sessionStorage']->user = array('id' => 3); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); @@ -61,10 +61,10 @@ class UserMentionTest extends Base public function testFireEventsWithMultipleMentions() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $event = new GenericEvent(array('project_id' => 1)); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); @@ -73,21 +73,21 @@ class UserMentionTest extends Base $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); - $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); - $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); } public function testFireEventsWithNoProjectId() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $event = new GenericEvent(array('task_id' => 1)); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); @@ -98,12 +98,12 @@ class UserMentionTest extends Base $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1'))); - $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); - $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); } public function onUserMention($event) diff --git a/tests/units/Model/UserMetadataTest.php b/tests/units/Model/UserMetadataTest.php index 457f1fb2..fb427371 100644 --- a/tests/units/Model/UserMetadataTest.php +++ b/tests/units/Model/UserMetadataTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\UserMetadata; +use Kanboard\Model\UserModel; +use Kanboard\Model\UserMetadataModel; class UserMetadataTest extends Base { public function testOperations() { - $m = new UserMetadata($this->container); - $u = new User($this->container); + $m = new UserMetadataModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'foobar'))); diff --git a/tests/units/Model/UserNotificationFilterTest.php b/tests/units/Model/UserNotificationFilterTest.php index 73c7d905..49c7aa0a 100644 --- a/tests/units/Model/UserNotificationFilterTest.php +++ b/tests/units/Model/UserNotificationFilterTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\Project; -use Kanboard\Model\UserNotificationFilter; -use Kanboard\Model\UserNotification; +use Kanboard\Model\UserModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserNotificationFilterModel; +use Kanboard\Model\UserNotificationModel; class UserNotificationFilterTest extends Base { public function testGetFilters() { - $nf = new UserNotificationFilter($this->container); + $nf = new UserNotificationFilterModel($this->container); $filters = $nf->getFilters(); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_NONE, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_BOTH, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_CREATOR, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_ASSIGNEE, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_NONE, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_BOTH, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_CREATOR, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_ASSIGNEE, $filters); } public function testSaveProjectFilter() { - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -35,78 +35,78 @@ class UserNotificationFilterTest extends Base public function testSaveUserFilter() { - $nf = new UserNotificationFilter($this->container); + $nf = new UserNotificationFilterModel($this->container); - $this->assertEquals(UserNotificationFilter::FILTER_BOTH, $nf->getSelectedFilter(1)); - $nf->saveFilter(1, UserNotificationFilter::FILTER_CREATOR); - $this->assertEquals(UserNotificationFilter::FILTER_CREATOR, $nf->getSelectedFilter(1)); + $this->assertEquals(UserNotificationFilterModel::FILTER_BOTH, $nf->getSelectedFilter(1)); + $nf->saveFilter(1, UserNotificationFilterModel::FILTER_CREATOR); + $this->assertEquals(UserNotificationFilterModel::FILTER_CREATOR, $nf->getSelectedFilter(1)); } public function testFilterNone() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertTrue($n->filterNone($u->getById(2))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertFalse($n->filterNone($u->getById(3))); } public function testFilterCreator() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2)))); } public function testFilterAssignee() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2)))); } public function testFilterBoth() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1)))); $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); } public function testFilterProject() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -115,7 +115,7 @@ class UserNotificationFilterTest extends Base $this->assertTrue($nf->filterProject($u->getById(1), array())); // User that select only some projects - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); $this->assertFalse($nf->filterProject($u->getById(2), array('task' => array('project_id' => 1)))); @@ -124,20 +124,20 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithNoFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1)))); } public function testFilterUserWithAssigneeFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2)))); $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1)))); @@ -145,10 +145,10 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithCreatorFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2)))); $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1)))); @@ -156,10 +156,10 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithBothFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); @@ -169,15 +169,15 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithBothFilterAndProjectSelected() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index a15fe226..6ee5c875 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -2,28 +2,28 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\Task; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\UserNotification; -use Kanboard\Model\UserNotificationFilter; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectPermissionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\UserNotificationModel; +use Kanboard\Model\UserNotificationFilterModel; use Kanboard\Core\Security\Role; class UserNotificationTest extends Base { public function testEnableDisableNotification() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectUserRole($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $u->create(array('username' => 'user1'))); @@ -38,29 +38,29 @@ class UserNotificationTest extends Base public function testReadWriteSettings() { - $n = new UserNotification($this->container); - $p = new Project($this->container); + $n = new UserNotificationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR, + 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR, 'notification_types' => array('email' => 1), 'notification_projects' => array(), )); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(0)) ->method('getSelectedTypes') ->will($this->returnValue(array('email'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(1)) ->method('getSelectedTypes') ->will($this->returnValue(array('email'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(2)) ->method('getSelectedTypes') ->with($this->equalTo(1)) @@ -69,7 +69,7 @@ class UserNotificationTest extends Base $settings = $n->readSettings(1); $this->assertNotEmpty($settings); $this->assertEquals(1, $settings['notifications_enabled']); - $this->assertEquals(UserNotificationFilter::FILTER_CREATOR, $settings['notifications_filter']); + $this->assertEquals(UserNotificationFilterModel::FILTER_CREATOR, $settings['notifications_filter']); $this->assertEquals(array('email'), $settings['notification_types']); $this->assertEmpty($settings['notification_projects']); @@ -83,7 +83,7 @@ class UserNotificationTest extends Base $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE, + 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE, 'notification_types' => array('web' => 1, 'email' => 1), 'notification_projects' => array(1 => 1), )); @@ -91,20 +91,20 @@ class UserNotificationTest extends Base $settings = $n->readSettings(1); $this->assertNotEmpty($settings); $this->assertEquals(1, $settings['notifications_enabled']); - $this->assertEquals(UserNotificationFilter::FILTER_ASSIGNEE, $settings['notifications_filter']); + $this->assertEquals(UserNotificationFilterModel::FILTER_ASSIGNEE, $settings['notifications_filter']); $this->assertEquals(array('email', 'web'), $settings['notification_types']); $this->assertEquals(array(1), $settings['notification_projects']); } public function testGetGroupMembersWithNotificationEnabled() { - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $projectModel = new Project($this->container); - $userNotificationModel = new UserNotification($this->container); - $projectGroupRole = new ProjectGroupRole($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $projectModel = new ProjectModel($this->container); + $userNotificationModel = new UserNotificationModel($this->container); + $projectGroupRole = new ProjectGroupRoleModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); @@ -136,10 +136,10 @@ class UserNotificationTest extends Base public function testGetProjectMembersWithNotifications() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectUserRole($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); @@ -181,10 +181,10 @@ class UserNotificationTest extends Base public function testGetUsersWithNotificationsWhenEverybodyAllowed() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectPermission($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectPermissionModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertTrue($pp->isEverybodyAllowed(1)); @@ -215,12 +215,12 @@ class UserNotificationTest extends Base public function testSendNotifications() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $pp = new ProjectPermission($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $pp = new ProjectPermissionModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -229,7 +229,7 @@ class UserNotificationTest extends Base $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_NONE, + 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE, 'notification_types' => array('web' => 1, 'email' => 1), )); @@ -242,23 +242,23 @@ class UserNotificationTest extends Base ->expects($this->exactly(2)) ->method('notifyUser'); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(0)) ->method('getSelectedTypes') ->will($this->returnValue(array('email', 'web'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(1)) ->method('getType') ->with($this->equalTo('email')) ->will($this->returnValue($notifier)); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(2)) ->method('getType') ->with($this->equalTo('web')) ->will($this->returnValue($notifier)); - $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $n->sendNotifications(TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } } diff --git a/tests/units/Model/UserNotificationTypeTest.php b/tests/units/Model/UserNotificationTypeTest.php index da22afef..29223c18 100644 --- a/tests/units/Model/UserNotificationTypeTest.php +++ b/tests/units/Model/UserNotificationTypeTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\UserNotificationType; +use Kanboard\Model\UserNotificationTypeModel; class UserNotificationTypeTest extends Base { public function testGetTypes() { - $nt = new UserNotificationType($this->container); + $nt = new UserNotificationTypeModel($this->container); $this->assertEmpty($nt->getTypes()); $nt->setType('email', 'Email', 'Something'); @@ -18,7 +18,7 @@ class UserNotificationTypeTest extends Base public function testGetSelectedTypes() { - $nt = new UserNotificationType($this->container); + $nt = new UserNotificationTypeModel($this->container); // No type defined $this->assertEmpty($nt->getSelectedTypes(1)); diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php index b53acb7d..0be6172e 100644 --- a/tests/units/Model/UserTest.php +++ b/tests/units/Model/UserTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\UserModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Core\Security\Role; class UserTest extends Base { public function testGetByEmail() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost'))); $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => ''))); @@ -24,20 +24,20 @@ class UserTest extends Base public function testGetByExternalId() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234'))); $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234')); $this->assertEmpty($u->getByExternalId('gitlab_id', '')); - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop'))); $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => ''))); $this->assertNotEmpty($u->getByExternalId('github_id', 'plop')); $this->assertEmpty($u->getByExternalId('github_id', '')); - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234'))); $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => ''))); @@ -47,7 +47,7 @@ class UserTest extends Base public function testGetByToken() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'token' => 'random'))); $this->assertNotFalse($u->create(array('username' => 'user2', 'token' => ''))); @@ -57,7 +57,7 @@ class UserTest extends Base public function testGetByUsername() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertNotEmpty($u->getByUsername('user1')); @@ -67,7 +67,7 @@ class UserTest extends Base public function testExists() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertTrue($u->exists(1)); @@ -77,14 +77,14 @@ class UserTest extends Base public function testCount() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertEquals(2, $u->count()); } public function testGetAll() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'you'))); $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me'))); @@ -97,7 +97,7 @@ class UserTest extends Base public function testGetActiveUsersList() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'you'))); $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too'))); $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0))); @@ -115,10 +115,10 @@ class UserTest extends Base $users = $u->getActiveUsersList(true); $expected = array( - User::EVERYBODY_ID => 'Everybody', - 1 => 'admin', - 3 => 'Me too', - 2 => 'you', + UserModel::EVERYBODY_ID => 'Everybody', + 1 => 'admin', + 3 => 'Me too', + 2 => 'you', ); $this->assertEquals($expected, $users); @@ -126,7 +126,7 @@ class UserTest extends Base public function testGetFullname() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2', 'name' => 'User #2'))); @@ -142,7 +142,7 @@ class UserTest extends Base public function testIsAdmin() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertTrue($u->isAdmin(1)); @@ -160,7 +160,7 @@ class UserTest extends Base public function testPrepare() { - $u = new User($this->container); + $u = new UserModel($this->container); $input = array( 'username' => 'user1', @@ -237,7 +237,7 @@ class UserTest extends Base public function testCreate() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User'))); $this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1))); $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER))); @@ -280,7 +280,7 @@ class UserTest extends Base public function testUpdate() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123'))); @@ -300,12 +300,12 @@ class UserTest extends Base public function testRemove() { - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); + $u = new UserModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -355,7 +355,7 @@ class UserTest extends Base public function testEnableDisablePublicAccess() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); $user = $u->getById(2); @@ -380,7 +380,7 @@ class UserTest extends Base public function testEnableDisable() { - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'toto'))); $this->assertTrue($userModel->isActive(2)); diff --git a/tests/units/Model/UserUnreadNotificationTest.php b/tests/units/Model/UserUnreadNotificationTest.php index eb162a40..e6716e6c 100644 --- a/tests/units/Model/UserUnreadNotificationTest.php +++ b/tests/units/Model/UserUnreadNotificationTest.php @@ -2,42 +2,42 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\UserUnreadNotification; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserUnreadNotificationModel; class UserUnreadNotificationTest extends Base { public function testHasNotification() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertFalse($wn->hasNotifications(1)); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); } public function testMarkAllAsRead() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); $this->assertTrue($wn->markAllAsRead(1)); @@ -48,15 +48,15 @@ class UserUnreadNotificationTest extends Base public function testMarkAsRead() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); @@ -69,16 +69,16 @@ class UserUnreadNotificationTest extends Base public function testGetAll() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertEmpty($wn->getAll(2)); @@ -90,16 +90,16 @@ class UserUnreadNotificationTest extends Base public function testGetOne() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertEmpty($wn->getAll(2)); diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php index 8d32b497..9f077ac8 100644 --- a/tests/units/Notification/MailTest.php +++ b/tests/units/Notification/MailTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\User; -use Kanboard\Model\TaskFile; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Notification\MailNotification; use Kanboard\Subscriber\NotificationSubscriber; @@ -18,12 +18,12 @@ class MailTest extends Base public function testGetMailContent() { $en = new MailNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); - $f = new TaskFile($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); + $f = new TaskFileModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -63,10 +63,10 @@ class MailTest extends Base public function testSendWithEmailAddress() { $en = new MailNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -88,16 +88,16 @@ class MailTest extends Base $this->stringContains('test') ); - $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } public function testSendWithoutEmailAddress() { $en = new MailNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -112,6 +112,6 @@ class MailTest extends Base ->expects($this->never()) ->method('send'); - $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } } diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookTest.php index 5984f303..5a9eb1c7 100644 --- a/tests/units/Notification/WebhookTest.php +++ b/tests/units/Notification/WebhookTest.php @@ -2,18 +2,18 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Subscriber\NotificationSubscriber; class WebhookTest extends Base { public function testTaskCreation() { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $c = new ConfigModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container)); $c->save(array('webhook_url' => 'http://localhost/?task-creation')); diff --git a/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php index df44d232..41f40844 100644 --- a/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php +++ b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php @@ -2,7 +2,7 @@ use Kanboard\Core\Security\Role; use Kanboard\Event\UserProfileSyncEvent; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; use Kanboard\Subscriber\LdapUserPhotoSubscriber; use Kanboard\User\DatabaseUserProvider; use Kanboard\User\LdapUserProvider; @@ -15,7 +15,7 @@ class LdapUserPhotoSubscriberTest extends Base { $userProvider = new DatabaseUserProvider(array()); $subscriber = new LdapUserPhotoSubscriber($this->container); - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); $user = $userModel->getById(1); @@ -30,7 +30,7 @@ class LdapUserPhotoSubscriberTest extends Base { $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); $subscriber = new LdapUserPhotoSubscriber($this->container); - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $user = $userModel->getById(1); $this->container['objectStorage'] @@ -49,7 +49,7 @@ class LdapUserPhotoSubscriberTest extends Base { $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array()); $subscriber = new LdapUserPhotoSubscriber($this->container); - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $user = $userModel->getById(1); $this->container['objectStorage'] @@ -66,7 +66,7 @@ class LdapUserPhotoSubscriberTest extends Base { $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); $subscriber = new LdapUserPhotoSubscriber($this->container); - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); $user = $userModel->getById(1); diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php index a73e8247..07de6c25 100644 --- a/tests/units/Validator/ProjectValidatorTest.php +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -3,14 +3,14 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Validator\ProjectValidator; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; class ProjectValidatorTest extends Base { public function testValidateCreation() { $validator = new ProjectValidator($this->container); - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -39,7 +39,7 @@ class ProjectValidatorTest extends Base public function testValidateModification() { $validator = new ProjectValidator($this->container); - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php index 5ac4588e..5fc50e3e 100644 --- a/tests/units/Validator/TaskLinkValidatorTest.php +++ b/tests/units/Validator/TaskLinkValidatorTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Validator\TaskLinkValidator; -use Kanboard\Model\TaskLink; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskLinkValidatorTest extends Base { public function testValidateCreation() { $validator = new TaskLinkValidator($this->container); - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -46,8 +46,8 @@ class TaskLinkValidatorTest extends Base public function testValidateModification() { $validator = new TaskLinkValidator($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); -- cgit v1.2.3