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')); } }