/** * Upate discussion * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // ifs if ($this->active_discussion->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_discussion->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if //BOF:mod 20110615 $subscribers = $this->active_discussion->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 $discussion_data = $this->request->post('discussion'); if (!is_array($discussion_data)) { $discussion_data = array('name' => $this->active_discussion->getName(), 'body' => $this->active_discussion->getBody(), 'parent_id' => $this->active_discussion->getParentId(), 'milestone_id' => $this->active_discussion->getMilestoneId(), 'visibility' => $this->active_discussion->getVisibility(), 'tags' => $this->active_discussion->getTags()); } // if $this->smarty->assign('discussion_data', $discussion_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_discussion->getName(); $this->active_discussion->setAttributes($discussion_data); $save = $this->active_discussion->save(); if ($save && !is_error($save)) { db_commit(); //BOF: mod $this->active_discussion->register_departments(!empty($discussion_data['departments']) ? $discussion_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_discussion); $assignees_flag_data = $this->request->post('assignee'); $this->active_discussion->register_assignees_flag($assignees_flag_data); //EOF:mod 20110614 if ($this->request->getFormat() == FORMAT_HTML) { flash_success('Discussion ":name" has been updated', array('name' => $old_name)); $this->redirectToUrl($this->active_discussion->getViewUrl()); } else { $this->serveData($this->active_discussion, 'discussion'); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $save); } else { $this->serveData($save); } // if } // if } // if }