Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 324 Rev 325
Línea 155... Línea 155...
155
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
155
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
156
            ]);;
156
            ]);;
157
        }
157
        }
158
    }
158
    }
Línea -... Línea 159...
-
 
159
    
-
 
160
    
-
 
161
    public function aspectDailyLogAction()
-
 
162
    {
-
 
163
        $request = $this->getRequest();
-
 
164
        
-
 
165
        
-
 
166
        $request = $this->getRequest();
-
 
167
        if($request->isPost()) {
-
 
168
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
169
            $currentUser = $currentUserPlugin->getUser();
-
 
170
            
-
 
171
            $companyMapper = \LeadersLinked\Mapper\CompanyMapper::getInstance($this->adapter);
-
 
172
            $company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentUser->network_id);
-
 
173
            
-
 
174
            $codes = [];
-
 
175
            
-
 
176
            $habitEmojiMapper = \LeadersLinked\Mapper\HabitEmojiMapper::getInstance($this->adapter);
-
 
177
            $records = $habitEmojiMapper->fetchAllActiveByCompanyId($company->id);
-
 
178
            foreach($records as $record)
-
 
179
            {
-
 
180
                $codes[ $record->code ] = $record->id;
-
 
181
            }
-
 
182
            
-
 
183
            $habitCategoryMapper = \LeadersLinked\Mapper\HabitCategoryMapper::getInstance($this->adapter);
-
 
184
            
-
 
185
            $habitUserLogCategoryMapper = \LeadersLinked\Mapper\HabitUserLogCategoryMapper::getInstance($this->adapter);
-
 
186
            
-
 
187
            $categories = [];
-
 
188
            $records = $habitCategoryMapper->fetchAllActiveByCompanyId($company->id);
-
 
189
            
-
 
190
            $date = date('Y-m-d');
-
 
191
            $time = date('H:i:s');
-
 
192
            foreach($records as $record)
-
 
193
            {
-
 
194
                $code = trim($this->params()->fromPost('cat_' . $record->uuid, ''));
-
 
195
                if(isset($codes[$code])) {
-
 
196
                    $habitUserLogCategory = $habitUserLogCategoryMapper->fetchOneByUserIdAndCategoryIdAndDate($currentUser->id, $record->id, $date);
-
 
197
                    if($habitUserLogCategory) {
-
 
198
                        $habitUserLogCategory->emoji_id = $codes[$code];
-
 
199
                        $habitUserLogCategory->code     = $code;
-
 
200
                        
-
 
201
                        $habitUserLogCategoryMapper->update($habitUserLogCategory);
-
 
202
                    } else {
-
 
203
                        $habitUserLogCategory = new \LeadersLinked\Model\HabitUserLogCategory();
-
 
204
                        $habitUserLogCategory->company_id = $company->id;
-
 
205
                        $habitUserLogCategory->date = $date;
-
 
206
                        $habitUserLogCategory->time = $time;
-
 
207
                        $habitUserLogCategory->user_id = $currentUser->id;
-
 
208
                        $habitUserLogCategory->emoji_id = $codes[$code];
-
 
209
                        $habitUserLogCategory->code = $code; 
-
 
210
                        
-
 
211
                        $habitUserLogCategoryMapper->insert($habitUserLogCategory);
-
 
212
                    }
-
 
213
                    
-
 
214
                }
-
 
215
            }
-
 
216
            
-
 
217
           
-
 
218
            
-
 
219
            $userLogContentMapper = \LeadersLinked\Mapper\HabitUserLogContentMapper::getInstance($this->adapter);
-
 
220
            $userLogContent = $userLogContentMapper->fetchOneMaxByCompanyIdAndUserId($company->id, $currentUser->id);
-
 
221
            
-
 
222
            $contentMapper = \LeadersLinked\Mapper\HabitContentMapper::getInstance($this->adapter);
-
 
223
            
-
 
224
            $order = 0;
-
 
225
            if($userLogContent) {
-
 
226
               
-
 
227
                $habitContent = $contentMapper->fetchOne($userLogContent->content_id);
-
 
228
                if($habitContent) {
-
 
229
                    $order = $habitContent->order;
-
 
230
                }
-
 
231
                
-
 
232
            }
-
 
233
            
-
 
234
            
-
 
235
            
-
 
236
            $link = '';
-
 
237
            $habitContent = $contentMapper->fetchOneNextAvailableForOrderByCompanyId($company->id, $order);
-
 
238
            if($habitContent) {
-
 
239
                $storage = \LeadersLinked\Library\Storage::getInstance($this->config);
-
 
240
                $path = $storage->getPathHabitContent();
-
 
241
                
-
 
242
                
-
 
243
                $link = $storage->getGenericFile($path, $habitContent->uuid, $habitContent->file);
-
 
244
                
-
 
245
                
-
 
246
            };
-
 
247
            
-
 
248
           
-
 
249
            
-
 
250
            return new JsonModel([
-
 
251
                'success' => true,
-
 
252
                'data' =>  $link
-
 
253
            ]);
-
 
254
            
-
 
255
            
-
 
256
        } else {
-
 
257
            return new JsonModel([
-
 
258
                'success' => false,
-
 
259
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
260
            ]);
-
 
261
        }
-
 
262
    }
Línea 159... Línea 263...
159
    
263