/**
 * Handle on_project_object_moved event
 *
 * @param ProjectObject $object
 * @param Project $source
 * @param Project $destination
 * @return null
 */
function tickets_handle_on_project_object_moved(&$object, &$source, &$destination)
{
    if (instance_of($object, 'Ticket')) {
        $object->setTicketId(Tickets::findNextTicketIdByProject($destination));
        $object->save();
    }
    // if
}
 /**
  * Edit specific milestone
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     //$this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this milestone', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this project', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $milestone_data = $this->request->post('milestone');
     if (!is_array($milestone_data)) {
         $milestone_data = array('name' => $this->active_milestone->getName(), 'body' => $this->active_milestone->getBody(), 'start_on' => $this->active_milestone->getStartOn(), 'due_on' => $this->active_milestone->getDueOn(), 'priority' => $this->active_milestone->getPriority(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_milestone), 'tags' => $this->active_milestone->getTags(), 'project_id' => $this->active_milestone->getProjectId(), 'visibility' => $this->active_milestone->getVisibility());
     }
     // if
     //BOF:mod 20121116
     $options = array();
     $options[] = array('url' => 'javascript:convert_object_to_ticket(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Ticket');
     $options[] = array('url' => 'javascript:convert_object_to_page(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Page');
     $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
     //EOF:mod 20121116
     $this->smarty->assign('milestone_data', $milestone_data);
     //BOF: task 07 | AD
     $this->smarty->assign('is_edit_mode', '1');
     //EOF: task 07 | AD
     if ($this->request->isSubmitted()) {
         if (!isset($milestone_data['assignees'])) {
             $milestone_data['assignees'] = array(array(), 0);
         }
         // if
         db_begin_work();
         $old_name = $this->active_milestone->getName();
         //BOF: task 07 | AD
         $old_project_id = $this->active_milestone->getProjectId();
         //EOF: task 07 | AD
         $this->active_milestone->setAttributes($milestone_data);
         $save = $this->active_milestone->save();
         if ($save && !is_error($save)) {
             db_commit();
             //BOF: task 07 | AD
             //BOF: mod
             $this->active_milestone->register_departments(!empty($milestone_data['departments']) ? $milestone_data['departments'] : array(), implode(',', $milestone_data['departments']));
             //EOF: mod
             //BOF:mod 20110614
             $assignees_flag_data = $this->request->post('assignee');
             $this->active_milestone->register_assignees_flag($assignees_flag_data);
             //EOF:mod 20110614
             if ($old_project_id != $this->active_milestone->getProjectId()) {
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME, $link);
                 $query = "select id, integer_field_1 \n\t\t\t\t\t\t\tfrom healingcrystals_project_objects where \n\t\t\t\t\t\t\tmilestone_id ='" . $this->active_milestone->getId() . "' and \n\t\t\t\t\t\t\tproject_id='" . $old_project_id . "' and type='Ticket' and integer_field_1 is not null";
                 $result = mysql_query($query);
                 $next_id = Tickets::findNextTicketIdByProject($this->active_milestone->getProjectId());
                 while ($ticket = mysql_fetch_assoc($result)) {
                     mysql_query("update healingcrystals_project_objects \n\t\t\t\t\t\t\t\t\tset integer_field_1='" . $next_id . "'  \n\t\t\t\t\t\t\t\t\twhere id='" . $ticket['id'] . "'");
                     $next_id++;
                 }
                 $query = "select updated_on, updated_by_id, updated_by_name, integer_field_1 from healingcrystals_project_objects where id='" . $this->active_milestone->getId() . "'";
                 $result = mysql_query($query, $link);
                 $info = mysql_fetch_assoc($result);
                 $query = "update healingcrystals_project_objects set \n\t\t\t\t\t\t\tproject_id ='" . $this->active_milestone->getProjectId() . "', \n\t\t\t\t\t\t\tupdated_on =" . (empty($info['updated_on']) ? "null" : "'" . $info['updated_on'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_id =" . (empty($info['updated_by_id']) ? "null" : "'" . $info['updated_by_id'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_name =" . (empty($info['updated_by_name']) ? "null" : "'" . mysql_real_escape_string($info['updated_by_name']) . "'") . ", \n\t\t\t\t\t\t\tupdated_by_email =" . (empty($info['updated_by_email']) ? "null" : "'" . $info['updated_by_email'] . "'") . " \n\t\t\t\t\t\t\twhere milestone_id ='" . $this->active_milestone->getId() . "' and project_id='" . $old_project_id . "'";
                 mysql_query($query);
                 $query = "update healingcrystals_project_objects set category_id=null where id='" . $this->active_milestone->getId() . "'";
                 mysql_query($query);
                 mysql_close($link);
             }
             //EOF: task 07 | AD
             if ($this->request->getFormat() == FORMAT_HTML) {
                 //flash_success('Milestone ":name" has been updated', array('name' => $old_name), false, true);
                 flash_success('Project ":name" has been updated', array('name' => $old_name), 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
 }
예제 #3
0
 /**
  * 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;
 }