Proyectos de Subversion LeadersLinked - Services

Rev

Rev 338 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 338 Rev 352
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 20... Línea 21...
20
    /**
21
    /**
21
     *
22
     *
22
     * @var \Laminas\Db\Adapter\AdapterInterface
23
     * @var \Laminas\Db\Adapter\AdapterInterface
23
     */
24
     */
24
    private $adapter;
25
    private $adapter;
25
    
26
 
26
    /**
27
    /**
27
     *
28
     *
28
     * @var \LeadersLinked\Cache\CacheInterface
29
     * @var \LeadersLinked\Cache\CacheInterface
29
     */
30
     */
30
    private $cache;
31
    private $cache;
31
    
32
 
32
    
33
 
33
    /**
34
    /**
34
     *
35
     *
35
     * @var \Laminas\Log\LoggerInterface
36
     * @var \Laminas\Log\LoggerInterface
36
     */
37
     */
37
    private $logger;
38
    private $logger;
38
    
39
 
39
    /**
40
    /**
40
     *
41
     *
41
     * @var array
42
     * @var array
42
     */
43
     */
43
    private $config;
44
    private $config;
44
    
45
 
45
    
46
 
46
    /**
47
    /**
47
     *
48
     *
48
     * @var \Laminas\Mvc\I18n\Translator
49
     * @var \Laminas\Mvc\I18n\Translator
49
     */
50
     */
50
    private $translator;
51
    private $translator;
51
    
52
 
52
    
53
 
53
    /**
54
    /**
54
     *
55
     *
55
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
56
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
56
     * @param \LeadersLinked\Cache\CacheInterface $cache
57
     * @param \LeadersLinked\Cache\CacheInterface $cache
57
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
58
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
Línea 64... Línea 65...
64
        $this->cache        = $cache;
65
        $this->cache        = $cache;
65
        $this->logger       = $logger;
66
        $this->logger       = $logger;
66
        $this->config       = $config;
67
        $this->config       = $config;
67
        $this->translator   = $translator;
68
        $this->translator   = $translator;
68
    }
69
    }
69
    
70
 
70
    public function indexAction()
71
    public function indexAction()
71
    {
72
    {
Línea 72... Línea 73...
72
 
73
 
Línea 73... Línea 74...
73
        
74
 
74
 
75
 
75
        $request = $this->getRequest();
76
        $request = $this->getRequest();
76
        
77
 
77
        
78
 
78
        $request = $this->getRequest();
79
        $request = $this->getRequest();
79
        if($request->isGet()) {
80
        if ($request->isGet()) {
80
            $currentUserPlugin = $this->plugin('currentUserPlugin');
81
            $currentUserPlugin = $this->plugin('currentUserPlugin');
81
            $currentUser = $currentUserPlugin->getUser();
82
            $currentUser = $currentUserPlugin->getUser();
82
            
83
 
83
            $companyMapper = \LeadersLinked\Mapper\CompanyMapper::getInstance($this->adapter);
84
            $companyMapper = \LeadersLinked\Mapper\CompanyMapper::getInstance($this->adapter);
84
            $company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentUser->network_id);
85
            $company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentUser->network_id);
85
            
86
 
86
            
87
 
87
            $habitCategoryMapper = \LeadersLinked\Mapper\HabitCategoryMapper::getInstance($this->adapter);
88
            $habitCategoryMapper = \LeadersLinked\Mapper\HabitCategoryMapper::getInstance($this->adapter);
88
            $habitUserLogCategoryMapper = \LeadersLinked\Mapper\HabitUserLogCategoryMapper::getInstance($this->adapter);
89
            $habitUserLogCategoryMapper = \LeadersLinked\Mapper\HabitUserLogCategoryMapper::getInstance($this->adapter);
89
            
90
 
90
            $categories = [];
91
            $categories = [];
91
            $records = $habitCategoryMapper->fetchAllActiveByCompanyId($company->id);
92
            $records = $habitCategoryMapper->fetchAllActiveByCompanyId($company->id);
92
            
93
 
93
            $date = date('Y-m-d');
-
 
94
            foreach($records as $record)
94
            $date = date('Y-m-d');
95
            {
95
            foreach ($records as $record) {
96
                $habitUserLogCategory = $habitUserLogCategoryMapper->fetchOneByUserIdAndCategoryIdAndDate($currentUser->id, $record->id, $date);
96
                $habitUserLogCategory = $habitUserLogCategoryMapper->fetchOneByUserIdAndCategoryIdAndDate($currentUser->id, $record->id, $date);
97
                if($habitUserLogCategory) {
97
                if ($habitUserLogCategory) {
98
                    $code = $habitUserLogCategory->code;
98
                    $code = $habitUserLogCategory->code;
99
                } else {
99
                } else {
100
                    $code = '';
100
                    $code = '';
101
                }
101
                }
102
                
102
 
103
                array_push($categories, [
103
                array_push($categories, [
104
                    'uuid' => $record->uuid, 
104
                    'uuid' => $record->uuid,
105
                    'name' => $record->name,
105
                    'name' => $record->name,
106
                    'selected' => $code
-
 
107
                ]);
-
 
108
                
106
                    'selected' => $code
109
                
107
                ]);
110
            }
108
            }
111
            
109
 
112
            $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
110
            $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
113
            $path = $storage->getPathHabitEmoji();
111
            $path = $storage->getPathHabitEmoji();
114
            
112
 
115
            $emojis = [];
113
            $emojis = [];
116
            $habitEmojiMapper = \LeadersLinked\Mapper\HabitEmojiMapper::getInstance($this->adapter);
114
            $habitEmojiMapper = \LeadersLinked\Mapper\HabitEmojiMapper::getInstance($this->adapter);
117
            $records = $habitEmojiMapper->fetchAllActiveByCompanyId($company->id);
115
            $records = $habitEmojiMapper->fetchAllActiveByCompanyId($company->id);
118
            
116
 
119
         
117
 
120
           
118
 
121
            
-
 
122
            foreach($records as $record)
119
 
123
            {
120
            foreach ($records as $record) {
124
                
121
 
125
                
122
 
126
                array_push($emojis, [
123
                array_push($emojis, [
127
                    'code' => $record->code, 
124
                    'code' => $record->code,
128
                    'name' => $record->name, 
125
                    'name' => $record->name,
129
                    'image' => $storage->getGenericImage($path, $record->uuid, $record->image)
126
                    'image' => $storage->getGenericImage($path, $record->uuid, $record->image)
130
                ]);
127
                ]);
131
            }
128
            }
132
            
129
 
133
            
130
 
134
            
131
 
135
            
132
 
136
            $acl = $this->getEvent()->getViewModel()->getVariable('acl');
133
            $acl = $this->getEvent()->getViewModel()->getVariable('acl');
137
            $allowValues = $acl->isAllowed($currentUser->usertype_id, 'habits/values');
134
            $allowValues = $acl->isAllowed($currentUser->usertype_id, 'habits/values');
138
            $allowParadigms = $acl->isAllowed($currentUser->usertype_id, 'habits/paradigms');
135
            $allowParadigms = $acl->isAllowed($currentUser->usertype_id, 'habits/paradigms');
139
            $allowPurposes = $acl->isAllowed($currentUser->usertype_id, 'habits/purposes');
136
            $allowPurposes = $acl->isAllowed($currentUser->usertype_id, 'habits/purposes');
140
            $allowSkills = $acl->isAllowed($currentUser->usertype_id, 'habits/skills');
137
            $allowSkills = $acl->isAllowed($currentUser->usertype_id, 'habits/skills');
141
            $allowGoals = $acl->isAllowed($currentUser->usertype_id, 'habits/goals');
138
            $allowGoals = $acl->isAllowed($currentUser->usertype_id, 'habits/goals');
142
            $allowAspectDailyLog = $acl->isAllowed($currentUser->usertype_id, 'habits/aspect-daily-log');
139
            $allowAspectDailyLog = $acl->isAllowed($currentUser->usertype_id, 'habits/aspect-daily-log');
143
            
140
 
144
           return new JsonModel([
141
            return new JsonModel([
145
               'success' => true,
142
                'success' => true,
146
                'data' => [
143
                'data' => [
147
                    'categories' => $categories, 
144
                    'categories' => $categories,
148
                    'emojis' => $emojis,
145
                    'emojis' => $emojis,
149
                    'link_aspect_daily_log' => $allowAspectDailyLog ? $this->url()->fromRoute('habits/aspect-daily-log', [], ['force_canonical' => true]) : '',
146
                    'link_aspect_daily_log' => $allowAspectDailyLog ? $this->url()->fromRoute('habits/aspect-daily-log', [], ['force_canonical' => true]) : '',
150
                    'link_values' => $allowValues ? $this->url()->fromRoute('habits/values', [], ['force_canonical' => true]) : '',
147
                    'link_values' => $allowValues ? $this->url()->fromRoute('habits/values', [], ['force_canonical' => true]) : '',
151
                    'link_paradigms' => $allowParadigms ? $this->url()->fromRoute('habits/paradigms', [], ['force_canonical' => true]) : '',
148
                    'link_paradigms' => $allowParadigms ? $this->url()->fromRoute('habits/paradigms', [], ['force_canonical' => true]) : '',
152
                    'link_purposes' => $allowPurposes ? $this->url()->fromRoute('habits/purposes', [], ['force_canonical' => true]) : '',
149
                    'link_purposes' => $allowPurposes ? $this->url()->fromRoute('habits/purposes', [], ['force_canonical' => true]) : '',
153
                    'link_skills' => $allowSkills ? $this->url()->fromRoute('habits/skills', [], ['force_canonical' => true]) : '',
150
                    'link_skills' => $allowSkills ? $this->url()->fromRoute('habits/skills', [], ['force_canonical' => true]) : '',
154
                    'link_goals' => $allowGoals ? $this->url()->fromRoute('habits/goals', [], ['force_canonical' => true]) : '',
151
                    'link_goals' => $allowGoals ? $this->url()->fromRoute('habits/goals', [], ['force_canonical' => true]) : '',
155
                ]
-
 
156
            ]);
-
 
157
 
152
                ]
158
      
153
            ]);
159
        } else {
154
        } else {
160
            return new JsonModel([
155
            return new JsonModel([
161
                'success' => false,
156
                'success' => false,
162
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
157
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
163
            ]);;
158
            ]);;
164
        }
159
        }
165
    }
160
    }
166
    
161
 
167
    
162
 
168
    public function aspectDailyLogAction()
163
    public function aspectDailyLogAction()
169
    {
164
    {
170
        $request = $this->getRequest();
165
        $request = $this->getRequest();
171
        
166
 
172
        
167
 
173
        $request = $this->getRequest();
168
        $request = $this->getRequest();
174
        if($request->isPost()) {
169
        if ($request->isPost()) {
175
            $currentUserPlugin = $this->plugin('currentUserPlugin');
170
            $currentUserPlugin = $this->plugin('currentUserPlugin');
176
            $currentUser = $currentUserPlugin->getUser();
171
            $currentUser = $currentUserPlugin->getUser();
177
            
172
 
178
            $companyMapper = \LeadersLinked\Mapper\CompanyMapper::getInstance($this->adapter);
173
            $companyMapper = \LeadersLinked\Mapper\CompanyMapper::getInstance($this->adapter);
179
            $company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentUser->network_id);
174
            $company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentUser->network_id);
180
            
175
 
181
            $codes = [];
176
            $codes = [];
182
            
177
 
183
            $habitEmojiMapper = \LeadersLinked\Mapper\HabitEmojiMapper::getInstance($this->adapter);
178
            $habitEmojiMapper = \LeadersLinked\Mapper\HabitEmojiMapper::getInstance($this->adapter);
184
            $records = $habitEmojiMapper->fetchAllActiveByCompanyId($company->id);
-
 
185
            foreach($records as $record)
179
            $records = $habitEmojiMapper->fetchAllActiveByCompanyId($company->id);
186
            {
180
            foreach ($records as $record) {
187
                $codes[ $record->code ] = $record->id;
181
                $codes[$record->code] = $record->id;
188
            }
182
            }
189
            
183
 
190
            $habitCategoryMapper = \LeadersLinked\Mapper\HabitCategoryMapper::getInstance($this->adapter);
184
            $habitCategoryMapper = \LeadersLinked\Mapper\HabitCategoryMapper::getInstance($this->adapter);
191
            
185
 
192
            $habitUserLogCategoryMapper = \LeadersLinked\Mapper\HabitUserLogCategoryMapper::getInstance($this->adapter);
186
            $habitUserLogCategoryMapper = \LeadersLinked\Mapper\HabitUserLogCategoryMapper::getInstance($this->adapter);
193
        
187
 
194
            $records = $habitCategoryMapper->fetchAllActiveByCompanyId($company->id);
188
            $records = $habitCategoryMapper->fetchAllActiveByCompanyId($company->id);
195
            
189
 
196
            $date = date('Y-m-d');
190
            $date = date('Y-m-d');
197
            $time = date('H:i:s');
-
 
198
            foreach($records as $record)
191
            $time = date('H:i:s');
199
            {
192
            foreach ($records as $record) {
200
                $code = trim($this->params()->fromPost($record->uuid, ''));
193
                $code = trim($this->params()->fromPost($record->uuid, ''));
201
                if(isset($codes[$code])) {
194
                if (isset($codes[$code])) {
202
                    $habitUserLogCategory = $habitUserLogCategoryMapper->fetchOneByUserIdAndCategoryIdAndDate($currentUser->id, $record->id, $date);
195
                    $habitUserLogCategory = $habitUserLogCategoryMapper->fetchOneByUserIdAndCategoryIdAndDate($currentUser->id, $record->id, $date);
203
                    if($habitUserLogCategory) {
196
                    if ($habitUserLogCategory) {
204
                        $habitUserLogCategory->code     = $code;
197
                        $habitUserLogCategory->code     = $code;
205
                        
198
 
206
                        $habitUserLogCategoryMapper->update($habitUserLogCategory);
199
                        $habitUserLogCategoryMapper->update($habitUserLogCategory);
207
                    } else {
200
                    } else {
208
                        $habitUserLogCategory = new \LeadersLinked\Model\HabitUserLogCategory();
201
                        $habitUserLogCategory = new \LeadersLinked\Model\HabitUserLogCategory();
209
                        $habitUserLogCategory->company_id = $company->id;
202
                        $habitUserLogCategory->company_id = $company->id;
210
                        $habitUserLogCategory->date = $date;
203
                        $habitUserLogCategory->date = $date;
211
                        $habitUserLogCategory->time = $time;
204
                        $habitUserLogCategory->time = $time;
212
                        $habitUserLogCategory->user_id = $currentUser->id;
205
                        $habitUserLogCategory->user_id = $currentUser->id;
213
                        $habitUserLogCategory->category_id = $record->id;
206
                        $habitUserLogCategory->category_id = $record->id;
214
                        $habitUserLogCategory->code = $code; 
207
                        $habitUserLogCategory->code = $code;
215
                        
208
 
216
                        $habitUserLogCategoryMapper->insert($habitUserLogCategory);
-
 
217
                    }
209
                        $habitUserLogCategoryMapper->insert($habitUserLogCategory);
218
                    
210
                    }
219
                }
211
                }
220
            }
212
            }
221
            
213
 
222
           
214
 
223
            
215
 
224
            $userLogContentMapper = \LeadersLinked\Mapper\HabitUserLogContentMapper::getInstance($this->adapter);
216
            $userLogContentMapper = \LeadersLinked\Mapper\HabitUserLogContentMapper::getInstance($this->adapter);
225
            $userLogContent = $userLogContentMapper->fetchOneMaxByCompanyIdAndUserId($company->id, $currentUser->id);
217
            $userLogContent = $userLogContentMapper->fetchOneMaxByCompanyIdAndUserId($company->id, $currentUser->id);
226
            
218
 
227
            $contentMapper = \LeadersLinked\Mapper\HabitContentMapper::getInstance($this->adapter);
219
            $contentMapper = \LeadersLinked\Mapper\HabitContentMapper::getInstance($this->adapter);
228
            
220
 
229
            $order = 0;
221
            $order = 0;
230
            if($userLogContent) {
222
            if ($userLogContent) {
231
               
223
 
232
                $habitContent = $contentMapper->fetchOne($userLogContent->content_id);
224
                $habitContent = $contentMapper->fetchOne($userLogContent->content_id);
233
                if($habitContent) {
225
                if ($habitContent) {
234
                    $order = $habitContent->order;
-
 
235
                }
226
                    $order = $habitContent->order;
236
                
227
                }
237
            }
228
            }
238
            
229
 
239
            
230
 
240
            
231
 
241
            $link = '';
232
            $link = '';
242
            $type = '';
233
            $type = '';
243
            $habitContent = $contentMapper->fetchOneNextAvailableForOrderByCompanyId($company->id, $order);
234
            $habitContent = $contentMapper->fetchOneNextAvailableForOrderByCompanyId($company->id, $order);
244
            if($habitContent) {
235
            if ($habitContent) {
245
                $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
236
                $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
246
                $path = $storage->getPathHabitContent();
237
                $path = $storage->getPathHabitContent();
247
                
238
 
248
                
239
 
249
                $type = $habitContent->type;
240
                $type = $habitContent->type;
250
                $link = $storage->getGenericFile($path, $habitContent->uuid, $habitContent->file);
241
                $link = $storage->getGenericFile($path, $habitContent->uuid, $habitContent->file);
251
                
242
 
252
                
243
 
253
                $userLogContent = new \LeadersLinked\Model\HabitUserLogContent();
244
                $userLogContent = new \LeadersLinked\Model\HabitUserLogContent();
254
                $userLogContent->company_id = $company->id;
245
                $userLogContent->company_id = $company->id;
255
                $userLogContent->content_id = $habitContent->id;
246
                $userLogContent->content_id = $habitContent->id;
256
                $userLogContent->user_id    = $currentUser->id;
247
                $userLogContent->user_id    = $currentUser->id;
257
                $userLogContent->date       = $date;
248
                $userLogContent->date       = $date;
258
                $userLogContent->time       = $time;
249
                $userLogContent->time       = $time;
259
                
-
 
260
                $userLogContentMapper->insert($userLogContent);
250
 
261
                
251
                $userLogContentMapper->insert($userLogContent);
262
            };
252
            };
263
            
253
 
264
            
254
 
265
    
255
 
266
            
256
 
267
           
257
 
268
            
258
 
269
            return new JsonModel([
259
            return new JsonModel([
270
                'success' => true,
260
                'success' => true,
271
                'data' => [
261
                'data' => [
272
                    'type' => $type, 
262
                    'type' => $type,
273
                    'link' => $link
263
                    'link' => $link
274
                ] 
-
 
275
            ]);
-
 
276
            
264
                ]
277
            
265
            ]);
278
        } else {
266
        } else {
279
            return new JsonModel([
267
            return new JsonModel([
280
                'success' => false,
268
                'success' => false,
281
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
269
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
282
            ]);
270
            ]);
283
        }
-
 
284
    }
-
 
285
    
271
        }