Example #1
0
 public function executeMultipleEdit(sfWebRequest $request)
 {
     if ($request->getParameter('projects_id') > 0) {
         $this->forward404Unless($this->projects = Doctrine_Core::getTable('Projects')->createQuery()->addWhere('id=?', $request->getParameter('projects_id'))->fetchOne(), sprintf('Object projects does not exist (%s).', $request->getParameter('projects_id')));
         $this->checkProjectsAccess($this->projects);
         $this->checkTicketsAccess('edit', false, $this->projects);
     } else {
         $this->checkTicketsAccess('edit');
     }
     $this->fields = array();
     if ($request->getParameter('projects_id') > 0) {
         $this->fields['departments_id'] = array('title' => t::__('Department'), 'choices' => app::getItemsChoicesByTable('Departments', true));
     }
     $choices = app::getItemsChoicesByTable('TicketsStatus', true);
     if (count($choices) > 1) {
         $this->fields['tickets_status_id'] = array('title' => t::__('Status'), 'choices' => $choices);
     }
     $choices = app::getItemsChoicesByTable('TicketsTypes', true);
     if (count($choices) > 1) {
         $this->fields['tickets_types_id'] = array('title' => t::__('Type'), 'choices' => $choices);
     }
     if ($request->getParameter('fields')) {
         if (strlen($request->getParameter('selected_items') == 0)) {
             exit;
         }
         foreach ($request->getParameter('fields') as $key => $value) {
             if (strlen($value) == 0 and !is_array($value)) {
                 continue;
             }
             if ($key == 'tickets_status_id') {
                 foreach (explode(',', $request->getParameter('selected_items')) as $pid) {
                     if ($p = Doctrine_Core::getTable('Tickets')->find($pid)) {
                         if ($p->getTicketsStatusId() != $value) {
                             $p->setTicketsStatusId($value);
                             $p->save();
                             if ($p->getDepartmentsId() > 0) {
                                 Tickets::sendNotification($this, $p, array('status' => explode(',', $p->getDepartments()->getUsersId())), $this->getUser());
                             }
                             $c = new TicketsComments();
                             $c->setTicketsStatusId($value);
                             $c->setTicketsId($pid);
                             $c->setCreatedAt(date('Y-m-d H:i:s'));
                             $c->setUsersId($this->getUser()->getAttribute('id'));
                             $c->save();
                         }
                     }
                 }
             } elseif ($key == 'departments_id') {
                 foreach (explode(',', $request->getParameter('selected_items')) as $pid) {
                     if ($p = Doctrine_Core::getTable('Tickets')->find($pid)) {
                         if ($p->getDepartmentsId() != $value) {
                             $p->setDepartmentsId($value);
                             $p->save();
                             if ($p->getDepartmentsId() > 0) {
                                 Tickets::sendNotification($this, $p, array('new' => explode(',', $p->getDepartments()->getUsersId())), $this->getUser());
                             }
                         }
                     }
                 }
             } else {
                 Doctrine_Query::create()->update('Tickets')->set($key, $value)->whereIn('id', explode(',', $request->getParameter('selected_items')))->execute();
             }
         }
         $this->redirect_to($request->getParameter('redirect_to'), $request->getParameter('projects_id'), $request->getParameter('tickets_id'));
     }
 }
Example #2
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         if ($form->getObject()->isNew()) {
             $tickets = Doctrine_Core::getTable('Tickets')->find($request->getParameter('tickets_id'));
             if ($form->getValue('tickets_status_id') > 0) {
                 $tickets->setTicketsStatusId($form->getValue('tickets_status_id'));
             } else {
                 unset($form['tickets_status_id']);
             }
             if ($request->getParameter('tickets_types_id') > 0) {
                 $tickets->setTicketsTypesId($request->getParameter('tickets_types_id'));
             }
             if ($request->getParameter('departments_id') > 0) {
                 $tickets->setDepartmentsId($request->getParameter('departments_id'));
             }
             $tickets->save();
         }
         if ($form->getObject()->isNew()) {
             $form->setFieldValue('created_at', date('Y-m-d H:i:s'));
         }
         $tickets_comments = $form->save();
         Attachments::insertAttachments($request->getFiles(), 'ticketsComments', $tickets_comments->getId(), $request->getParameter('attachments_info'), $this->getUser());
         TicketsComments::sendNotification($this, $tickets_comments, $this->getUser());
         $this->redirect('ticketsComments/index?tickets_id=' . $request->getParameter('tickets_id') . ($request->getParameter('projects_id') > 0 ? '&projects_id=' . $request->getParameter('projects_id') : ''));
     }
 }