Exemplo n.º 1
0
 public static function saveTasksFilter($request, $filters, $sf_user, $filter_type = 'filter')
 {
     $report_type = Tasks::getReportType($request, $filter_type);
     if ($request->getParameter('update_user_filter') > 0) {
         $r = Doctrine_Core::getTable('UserReports')->createQuery()->addWhere('id=?', $request->getParameter('update_user_filter'))->addWhere('users_id=?', $sf_user->getAttribute('id'))->addWhere('report_type=?', $report_type)->fetchOne();
         if ($r) {
             $r->setName($request->getParameter('name'));
             $r->setIsDefault($request->getParameter('is_default'));
         } else {
             return false;
         }
     } else {
         $r = new UserReports();
         $r->setName($request->getParameter('name'));
         $r->setUsersId($sf_user->getAttribute('id'));
         $r->setReportType($report_type);
         $r->setIsDefault($request->getParameter('is_default'));
     }
     if (!$request->hasParameter('update_user_filter') or $request->hasParameter('update_user_filter') and $request->hasParameter('update_values')) {
         foreach ($filters as $table => $fstr) {
             switch ($table) {
                 case 'TasksPriority':
                     $r->setTasksPriorityId($fstr);
                     break;
                 case 'TasksStatus':
                     $r->setTasksStatusId($fstr);
                     break;
                 case 'TasksTypes':
                     $r->setTasksTypeId($fstr);
                     break;
                 case 'TasksLabels':
                     $r->setTasksLabelId($fstr);
                     break;
                 case 'TasksGroups':
                     $r->setTasksGroupsId($fstr);
                     break;
                 case 'Versions':
                     $r->setVersionsId($fstr);
                     break;
                 case 'ProjectsPhases':
                     $r->setProjectsPhasesId($fstr);
                     break;
                 case 'TasksAssignedTo':
                     $r->setAssignedTo($fstr);
                     break;
                 case 'TasksCreatedBy':
                     $r->setCreatedBy($fstr);
                     break;
                 case 'Projects':
                     $r->setProjectsId($fstr);
                     break;
                 case 'ProjectsPriority':
                     $r->setProjectsPriorityId($fstr);
                     break;
                 case 'ProjectsStatus':
                     $r->setProjectsStatusId($fstr);
                     break;
                 case 'ProjectsTypes':
                     $r->setProjectsTypeId($fstr);
                     break;
                 case 'ProjectsGroups':
                     $r->setProjectsGroupsId($fstr);
                     break;
             }
         }
     }
     $r->save();
     if ($r->getIsDefault() == 1) {
         Doctrine_Query::create()->update('UserReports')->set('is_default', 0)->addWhere('id != ?', $r->getId())->addWhere('report_type=?', $report_type)->execute();
     }
 }