/** * Create a new milestone * * @param void * @return null */ function add() { $this->wireframe->print_button = false; if (!Milestone::canAdd($this->logged_user, $this->active_project)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $milestone_data = $this->request->post('milestone'); if (!$this->request->isSubmitted()) { $milestone_data['visibility'] = VISIBILITY_NORMAL; } $this->smarty->assign('milestone_data', $milestone_data); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_milestone = new Milestone(); $this->active_milestone->setAttributes($milestone_data); $this->active_milestone->setProjectId($this->active_project->getId()); if (trim($this->active_milestone->getCreatedByName()) == '' || trim($this->active_milestone->getCreatedByEmail()) == '') { $this->active_milestone->setCreatedBy($this->logged_user); } // if $this->active_milestone->setState(STATE_VISIBLE); //$this->active_milestone->setVisibility(VISIBILITY_NORMAL); $save = $this->active_milestone->save(); if ($save && !is_error($save)) { $subscribers = array($this->logged_user->getId()); if (is_foreachable(array_var($milestone_data['assignees'], 0))) { $subscribers = array_merge($subscribers, array_var($milestone_data['assignees'], 0)); } else { $subscribers[] = $this->active_project->getLeaderId(); } // if if (!in_array($this->active_project->getLeaderId(), $subscribers)) { $subscribers[] = $this->active_project->getLeaderId(); } // if Subscriptions::subscribeUsers($subscribers, $this->active_milestone); db_commit(); $this->active_milestone->ready(); //BOF: mod $this->active_milestone->register_departments(!empty($milestone_data['departments']) ? $milestone_data['departments'] : array()); //EOF: mod //BOF:mod 20110614 $assignees_flag_data = $this->request->post('assignee'); $this->active_milestone->register_assignees_flag($assignees_flag_data, true); //EOF:mod 20110614 if ($this->request->getFormat() == FORMAT_HTML) { //flash_success('Milestone ":name" has been created', array('name' => $this->active_milestone->getName()), false, true); flash_success('Project ":name" has been created', array('name' => $this->active_milestone->getName()), false, true); $this->redirectToUrl($this->active_milestone->getViewUrl()); } else { $this->serveData($this->active_milestone, 'milestone'); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $save); } else { $this->serveData($save); } // if } // if } // if }