/** * Save into database * * @return boolean */ function save() { if ($this->isNew()) { $this->setTicketId(Tickets::findNextTicketIdByProject($this->getProjectId())); } // if $changes = null; if ($this->isLoaded()) { $log_fields = array('project_id', 'milestone_id', 'parent_id', 'name', 'body', 'priority', 'due_on', 'completed_on'); $changes = new TicketChange(); $changes->setTicketId($this->getId()); $changes->setVersion($this->getVersion()); $changes->setCreatedOn(DateTimeValue::now()); $changes->setCreatedBy(get_logged_user()); if ($this->new_assignees !== false) { list($old_assignees, $old_owner_id) = $this->getAssignmentData(); if (is_array($this->new_assignees) && isset($this->new_assignees[0]) && isset($this->new_assignees[1])) { $new_assignees = $this->new_assignees[0]; $new_owner_id = $this->new_assignees[1]; } else { $new_assignees = array(); $new_owner_id = 0; } // if if ($new_owner_id != $old_owner_id) { $changes->addChange('owner', $old_owner_id, $new_owner_id); } // if sort($new_assignees); sort($old_assignees); if ($new_assignees != $old_assignees) { $changes->addChange('assignees', $old_assignees, $new_assignees); } // if } // if foreach ($this->modified_fields as $field) { if (!in_array($field, $log_fields)) { continue; } // if $old_value = array_var($this->old_values, $field); $new_value = array_var($this->values, $field); if ($old_value != $new_value) { $changes->addChange($field, $old_value, $new_value); } // if } // foreach } // if $save = parent::save(); if ($save && !is_error($save)) { if (instance_of($changes, 'TicketChange') && count($changes->changes)) { $this->changes = false; $changes->save(); } // if } // if return $save; }
/** * Show and process add page form * * @param void * @return null */ function add() { $this->wireframe->print_button = false; if (!Page::canAdd($this->logged_user, $this->active_project)) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall()); } // if $parent_id = (int) $this->request->get('parent_id'); $page_data = $this->request->post('page'); if (!is_array($page_data)) { $page_data = array('parent_id' => $this->request->get('parent_id'), 'milestone_id' => $this->request->get('milestone_id'), 'visibility' => $this->active_project->getDefaultVisibility()); } // if $this->smarty->assign('page_data', $page_data); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_page = new Page(); attach_from_files($this->active_page, $this->logged_user); $this->active_page->setAttributes($page_data); $this->active_page->setProjectId($this->active_project->getId()); if (trim($this->active_page->getCreatedByName()) == '' || trim($this->active_page->getCreatedByEmail()) == '') { $this->active_page->setCreatedBy($this->logged_user); } // if $this->active_page->setUpdatedOn(DateTimeValue::now()); $this->active_page->setUpdatedBy($this->logged_user); $this->active_page->setState(STATE_VISIBLE); $save = $this->active_page->save(); if ($save && !is_error($save)) { $subscribers = array($this->logged_user->getId()); if (is_foreachable($this->request->post('notify_users'))) { $subscribers = array_merge($subscribers, $this->request->post('notify_users')); } 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_page); db_commit(); $this->active_page->ready(); //BOF: mod $this->active_page->register_departments(!empty($page_data['departments']) ? $page_data['departments'] : array()); //EOF: mod //BOF:mod 20110614 $assignees_flag_data = $this->request->post('assignee'); $this->active_page->register_assignees_flag($assignees_flag_data, true); //EOF:20110614 if ($this->request->isApiCall()) { $this->serveData($this->active_page, 'page'); } else { flash_success('Page ":name" has been created', array('name' => $this->active_page->getName())); $this->redirectToUrl($this->active_page->getViewUrl()); } // if } else { db_rollback(); if ($this->request->isApiCall()) { $this->serveData($save); } else { $this->smarty->assign('errors', $save); } // if } // if } // if }
/** * Prende le stime dei figli, le somma e ne genera una singola */ function getEstimateFromChilds() { // Prendo tutti i figli della milestone corrente $tasks = Tasks::findByMilestone($this->object, STATE_VISIBLE); // Scorro tutti i figli e ne salvo le stime $estimates = array(); $estimates_sum = 0; if (is_foreachable($tasks)) { foreach ($tasks as $task) { $estimate = Estimates::findLatestByParent($task); // Se non รจ stata impostata la stima ritorna nullo, quindi bisogna controllare che effettivamente l'oggetto esista if ($estimate && $estimate instanceof Estimate) { $estimates[] = $estimate; $estimates_sum += $estimate->getValue(); } } } // FIXME: seconda parte dell'if inutile if ($this->object instanceof Milestone || $this->object instanceof RemediaMilestone) { $estimate = new Estimate(); $estimate->setParent($this->object); $estimate->setValue($estimates_sum); $estimate->setJobType(JobTypes::findById(1)); // TODO: ho preso un job a caso, chissene $estimate->setComment('Stima generata automaticamente'); $estimate->setCreatedBy($this->object->assignees()->getAssignee()); // Assegno come creatore un tizio tra gli assegnatari $estimate->setCreatedOn(DateTimeValue::now()); } return $estimate; }
/** * Returns true if this object is due in future * * @param void * @return boolean */ function isUpcoming() { $now = DateTimeValue::now(); $due_on = $this->getDueOn(); if (instance_of($due_on, 'DateTimeValue')) { return $due_on->getTimestamp() > $now->getTimestamp() && !$this->isToday(); } // if return false; }
/** * Mark all items as read (update users last visit timestamp) * * @param void * @return null */ function mark_all_read() { if ($this->request->isSubmitted()) { $this->logged_user->setLastVisitOn(DateTimeValue::now()); $save = $this->logged_user->save(); if ($save && !is_error($save)) { if ($this->request->isAsyncCall()) { $this->httpOk(); } else { flash_success('All new items are marked as read'); } // if } else { $message = lang('Failed to mark new items as read'); if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED, $message); die; } else { flash_success($message); } // if } // if $this->redirectToReferer(assemble_url('dashboard')); } else { $this->httpError(HTTP_BAD_REQUEST); } // if }