/** * Edit selected checklist * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if if ($this->active_checklist->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_checklist->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if //BOF:mod 20110615 $subscribers = $this->active_checklist->getSubscribers(); $notify_users = array(array(), null); foreach ($subscribers as $subscriber) { $notify_users[0][] = $subscriber->getId(); } $this->smarty->assign('notify_users', $notify_users); //EOF:mod 20110615 $checklist_data = $this->request->post('checklist'); if (!is_array($checklist_data)) { $checklist_data = array('name' => $this->active_checklist->getName(), 'body' => $this->active_checklist->getBody(), 'visibility' => $this->active_checklist->getVisibility(), 'milestone_id' => $this->active_checklist->getMilestoneId(), 'tags' => $this->active_checklist->getTags()); } // if $this->smarty->assign('checklist_data', $checklist_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_checklist->getName(); $this->active_checklist->setAttributes($checklist_data); $save = $this->active_checklist->save(); if ($save && !is_error($save)) { db_commit(); //BOF: mod $this->active_checklist->register_departments(!empty($checklist_data['departments']) ? $checklist_data['departments'] : array()); //EOF: mod //BOF:mod 20110614 $subscribers = $this->request->post('notify_users'); if (!in_array($this->active_project->getLeaderId(), $subscribers)) { $subscribers[] = $this->active_project->getLeaderId(); } // if Subscriptions::subscribeUsers($subscribers, $this->active_checklist); $assignees_flag_data = $this->request->post('assignee'); $this->active_checklist->register_assignees_flag($assignees_flag_data); //EOF:mod 20110614 if ($this->request->getFormat() == FORMAT_HTML) { flash_success('Checklist :name has been updated', array('name' => $old_name)); $this->redirectToUrl($this->active_checklist->getViewUrl()); } else { $this->serveData($this->active_checklist, 'checklist'); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $save); } else { $this->serveData($save); } // if } // if } // if }