Ejemplo n.º 1
0
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Milestone;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Milestone']))
{
$model->attributes=$_POST['Milestone'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}
Ejemplo n.º 2
0
 /**
  * Save milestone record to the database
  *
  * @return boolean
  */
 function save()
 {
     // hack
     DB::beginWork('Saving Milestone @ ' . __CLASS__);
     // 		if($this->isNew()){
     DB::execute('UPDATE ' . TABLE_PREFIX . 'object_contexts SET parent_type = ? WHERE parent_id = ?', 'RemediaMilestone', $this->getId());
     // 		}
     $result = parent::save();
     // hack
     DB::execute('UPDATE ' . TABLE_PREFIX . 'object_contexts SET parent_type = ? WHERE parent_id = ?', 'Milestone', $this->getId());
     DB::execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET type = ? WHERE type = ?', 'Milestone', 'RemediaMilestone');
     DB::execute('UPDATE ' . TABLE_PREFIX . 'modification_logs SET parent_type = ? WHERE parent_type = ?', 'Milestone', 'RemediaMilestone');
     DB::execute('UPDATE ' . TABLE_PREFIX . 'activity_logs SET subject_type = ? WHERE subject_type = ?', 'Milestone', 'RemediaMilestone');
     DB::execute('UPDATE ' . TABLE_PREFIX . 'activity_logs SET action = ? WHERE action = ?', 'milestone/created', 'remedia_milestone/created');
     // DB::execute('DELETE FROM ' . TABLE_PREFIX . 'subscriptions WHERE parent_type = \'RemediaMilestone\' AND parent_id IN (SELECT parent_id FROM ' . TABLE_PREFIX . 'subscriptions WHERE parent_type = \'Milestone\')');
     // DB::execute('UPDATE ' . TABLE_PREFIX . 'subscriptions SET parent_type = ? WHERE parent_type = ?', 'Milestone', 'RemediaMilestone');
     DB::commit('Milestone saved @ ' . __CLASS__);
     return $result;
 }
 function convertToMilestone(&$logged_user, &$error)
 {
     db_begin_work();
     $milestone = new Milestone();
     $milestone->setProjectId($this->getProjectId());
     $milestone->setName($this->getName());
     $milestone->setBody($this->getBody());
     $milestone->setState($this->getState());
     $milestone->setVisibility($this->getVisibility());
     $milestone->setPriority($this->getPriority());
     $milestone->setCommentsCount($this->getCommentsCount());
     $milestone->setIsLocked($this->getIsLocked());
     $milestone->setCreatedById($logged_user->getId());
     $milestone->setCreatedByName($logged_user->getName());
     $milestone->setCreatedByEmail($logged_user->getEmail());
     $save = $milestone->save();
     if ($save && !is_error($save)) {
         db_commit();
         $milestone->ready();
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "update healingcrystals_project_objects set parent_id='" . $milestone->getId() . "', parent_type='Milestone' where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type in ('Comment', 'Task')";
         mysql_query($query);
         $query = "update healingcrystals_project_objects set parent_id=null, parent_type=null where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type not in ('Comment', 'Task')";
         mysql_query($query);
         $query = "select * from healingcrystals_assignments where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert into healingcrystals_assignments (user_id, object_id, is_owner) values ('" . $entry['user_id'] . "', '" . $milestone->getId() . "', '" . $entry['is_owner'] . "')";
             mysql_query($query);
         }
         $query = "select * from healingcrystals_project_object_categories where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert ignore into healingcrystals_project_object_categories (object_id, category_id) values ('" . $milestone->getId() . "', '" . $entry['category_id'] . "')";
             mysql_query($query);
         }
         mysql_close($link);
         $this->moveToTrash();
         return $milestone->getId();
     } else {
         db_rollback();
         $error = $save;
         return '';
     }
 }
 /**
  * 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
 }
 public function createMilestone()
 {
     $project_id = Input::get('project_select_in_milestone');
     $subject = Input::get('subject_in_milestone');
     $summary = Input::get('summary_in_milestone');
     $validation = Validator::make(['project_id' => Input::get('project_select_in_milestone'), 'subject' => Input::get('subject_in_milestone'), 'summary' => Input::get('summary_in_milestone'), 'milestone_date' => Input::get('milestone_date')], ['project_id' => 'required', 'subject' => 'required|max:20|min:4', 'summary' => 'max:40|min:10', 'milestone_date' => 'required']);
     if ($validation->fails()) {
         return 'Error Happend';
     } else {
         $create_time = new DateTime();
         $milestone_date = Input::get('milestone_date');
         $milestone_date_updated = date("Y-m-d", strtotime($milestone_date));
         try {
             $milestone = new Milestone();
             $milestone->project_id = $project_id;
             $milestone->subject = $subject;
             $milestone->summary = $summary;
             $milestone->date = $milestone_date_updated;
             $milestone->created_at = $create_time;
             $milestone->save();
             return Redirect::route('home');
         } catch (Exception $e) {
             echo $e;
         }
     }
 }