summaryrefslogtreecommitdiff
path: root/plugins/Group_assign/Plugin.php
blob: 6f69388c23a104d0ebaa5f69600b570abf459ff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php

namespace Kanboard\Plugin\Group_assign;

use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Model\TaskModel;
use Kanboard\Model\ProjectGroupRoleModel;
use Kanboard\Plugin\Group_assign\Model\NewTaskFinderModel;
use Kanboard\Plugin\Group_assign\Model\NewUserNotificationFilterModel;
use Kanboard\Plugin\Group_assign\Model\MultiselectModel;
use Kanboard\Plugin\Group_assign\Model\MultiselectMemberModel;
use Kanboard\Plugin\Group_assign\Model\OldTaskFinderModel;
use Kanboard\Plugin\Group_assign\Helper\NewTaskHelper;
use Kanboard\Plugin\Group_assign\Filter\TaskAllAssigneeFilter;
use Kanboard\Plugin\Group_assign\Action\EmailGroup;
use Kanboard\Plugin\Group_assign\Action\EmailGroupDue;
use Kanboard\Plugin\Group_assign\Action\EmailOtherAssignees;
use Kanboard\Plugin\Group_assign\Action\EmailOtherAssigneesDue;
use Kanboard\Plugin\Group_assign\Action\AssignGroup;
use Kanboard\Plugin\Group_assign\Model\GroupAssignCalendarModel;
use Kanboard\Plugin\Group_assign\Model\GroupAssignTaskDuplicationModel;
use Kanboard\Plugin\Group_assign\Model\TaskProjectDuplicationModel;
use Kanboard\Plugin\Group_assign\Model\TaskProjectMoveModel;
use Kanboard\Plugin\Group_assign\Model\TaskRecurrenceModel;
use Kanboard\Plugin\Group_assign\Model\NewMetaMagikSubquery;
use Kanboard\Plugin\Group_assign\Model\OldMetaMagikSubquery;
use PicoDb\Table;
use PicoDb\Database;
use Kanboard\Core\Security\Role;

class Plugin extends Base
{
    
    public function initialize()
    {
        //Events & Changes        
        $this->template->setTemplateOverride('task/changes', 'group_assign:task/changes');
        
        //Notifications
        $this->container['userNotificationFilterModel'] = $this->container->factory(function ($c) {
                return new NewUserNotificationFilterModel($c);
        });

        //Helpers
        $this->helper->register('newTaskHelper', '\Kanboard\Plugin\Group_assign\Helper\NewTaskHelper');
        $this->helper->register('smallAvatarHelperExtend', '\Kanboard\Plugin\Group_assign\Helper\SmallAvatarHelperExtend');
        
        
        //Models and backward compatibility
        
        $applications_version = str_replace('v', '', APP_VERSION);
        if (strpos(APP_VERSION, 'master') !== false && file_exists('ChangeLog')) { $applications_version = trim(file_get_contents('ChangeLog', false, null, 8, 6), ' '); }
        $clean_appversion = preg_replace('/\s+/', '', $applications_version);
        
        if (version_compare($clean_appversion, '1.2.5', '>')) {
            if (file_exists('plugins/MetaMagik')){
                $this->container['taskFinderModel'] = $this->container->factory(function ($c) {
                    return new NewMetaMagikSubquery($c);
                });
            } else {
                $this->container['taskFinderModel'] = $this->container->factory(function ($c) {
                    return new NewTaskFinderModel($c);
                });
            }
            $this->container['taskDuplicationModel'] = $this->container->factory(function ($c) {
                return new GroupAssignTaskDuplicationModel($c);
            });
            $this->container['taskProjectDuplicationModel '] = $this->container->factory(function ($c) {
                return new TaskProjectDuplicationModel ($c);
            });
            $this->container['taskProjectMoveModel '] = $this->container->factory(function ($c) {
                return new TaskProjectMoveModel ($c);
            });
            $this->container['taskRecurrenceModel '] = $this->container->factory(function ($c) {
                return new TaskRecurrenceModel ($c);
            });
        } else {
            if (file_exists('plugins/MetaMagik')){
                $this->container['taskFinderModel'] = $this->container->factory(function ($c) {
                    return new OldMetaMagikSubquery($c);
                });
            } else {
                $this->container['taskFinderModel'] = $this->container->factory(function ($c) {
                    return new OldTaskFinderModel($c);
                });
            }
            $this->container['taskDuplicationModel'] = $this->container->factory(function ($c) {
                return new GroupAssignTaskDuplicationModel($c);
            });
            $this->container['taskProjectDuplicationModel '] = $this->container->factory(function ($c) {
                return new TaskProjectDuplicationModel ($c);
            });
            $this->container['taskProjectMoveModel '] = $this->container->factory(function ($c) {
                return new TaskProjectMoveModel ($c);
            });
            $this->container['taskRecurrenceModel '] = $this->container->factory(function ($c) {
                return new TaskRecurrenceModel ($c);
            });
        }
        
        //Task - Template - details.php
        $this->template->hook->attach('template:task:details:third-column', 'group_assign:task/details');
        $this->template->hook->attach('template:task:details:third-column', 'group_assign:task/multi');
        
        //Forms - task_creation.php and task_modification.php
        $this->template->setTemplateOverride('task_creation/show', 'group_assign:task_creation/show');
        $this->template->setTemplateOverride('task_modification/show', 'group_assign:task_modification/show');
        
        //Board
        $this->template->hook->attach('template:board:private:task:before-title', 'group_assign:board/group');
        $this->template->hook->attach('template:board:private:task:before-title', 'group_assign:board/multi');
        $groupmodel = $this->projectGroupRoleModel;
        $this->template->hook->attachCallable('template:app:filters-helper:after', 'group_assign:board/filter', function($array = array()) use ($groupmodel) {
            if(!empty($array) && $array['id'] >= 1){
                return ['grouplist' => array_column($groupmodel->getGroups($array['id']), 'name')];
            } else {
                return ['grouplist' => array()];
            }
        });  
        
        //Filter
        $this->container->extend('taskLexer', function($taskLexer, $c) {
            $taskLexer->withFilter(TaskAllAssigneeFilter::getInstance()->setDatabase($c['db'])
                                                                    ->setCurrentUserId($c['userSession']->getId()));
            return $taskLexer;
        });
        
        //Actions
        $this->actionManager->register(new EmailGroup($this->container));
        $this->actionManager->register(new EmailGroupDue($this->container));
        $this->actionManager->register(new EmailOtherAssignees($this->container));
        $this->actionManager->register(new EmailOtherAssigneesDue($this->container));
        $this->actionManager->register(new AssignGroup($this->container));
        
        //Params
        $this->template->setTemplateOverride('action_creation/params', 'group_assign:action_creation/params');
        
        //CSS
        $this->hook->on('template:layout:css', array('template' => 'plugins/Group_assign/Assets/css/group_assign.css'));

        //JS
        $this->hook->on('template:layout:js', array('template' => 'plugins/Group_assign/Assets/js/group_assign.js'));

        //Calendar Events
        $container = $this->container;
        
        $this->hook->on('controller:calendar:user:events', function($user_id, $start, $end) use ($container) {
            $model = new GroupAssignCalendarModel($container);
            return $model->getUserCalendarEvents($user_id, $start, $end); // Return new events
        });
        
        //Roles

        $this->template->hook->attach('template:config:application', 'group_assign:config/toggle');
    
        if ($this->configModel->get('enable_am_group_management', '2') == 1) { 
            $this->applicationAccessMap->add('GroupListController', '*', Role::APP_MANAGER);
            $this->applicationAccessMap->add('GroupCreationController', '*', Role::APP_MANAGER);
            $this->template->setTemplateOverride('header/user_dropdown', 'group_assign:header/user_dropdown'); 
        }


    }
    
    public function onStartup()
    {
        Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
    }
    
    public function getClasses()
    {
        return [
            'Plugin\Group_assign\Model' => [
                'MultiselectMemberModel', 'MultiselectModel', 'GroupColorExtension', 'TaskProjectDuplicationModel', 'TaskProjectMoveModel', 'TaskRecurrenceModel',
            ],
        ];
    }

    public function getPluginName()
    {
        return 'Group_assign';
    }
    public function getPluginDescription()
    {
        return t('Add group assignment to tasks');
    }
    public function getPluginAuthor()
    {
        return 'Craig Crosby';
    }
    public function getPluginVersion()
    {
        return '1.7.8';
    }
    public function getPluginHomepage()
    {
        return 'https://github.com/creecros/group_assign';
    }
}