Ejemplo n.º 1
0
 public function getLatestActivityDate()
 {
     $latestTicketEvent = TicketEvents::model()->findBySql("select max(event_recorded_date) as event_recorded_date, description as id  from (select event_type_id, event_recorded_date from ticket_events where ticket_id = " . $this->id . " and (event_type_id != 9 and event_type_id !=8) order by event_recorded_date desc)x left join event_type on event_type.id = event_type_id; ");
     return "" . $latestTicketEvent->id . " " . date("M d, Y", strtotime($latestTicketEvent->event_recorded_date));
 }
 public static function recordEvent($event_type_id, $ticket_id, $old_value, $new_value, $comment)
 {
     $resEvent = NULL;
     $newEvent = new TicketEvents();
     //Some validation first
     if (!isset($event_type_id)) {
         throw new CException("Event Type required when loggin ticket events.");
     }
     if (!isset($ticket_id)) {
         throw new CException("Ticket ID required when loggin ticket events.");
     }
     //Collect and prepare the data
     $newEvent->event_type_id = $event_type_id;
     $newEvent->ticket_id = $ticket_id;
     $newEvent->event_recorded_date = new CDbExpression('NOW()');
     $newEvent->old_value = $old_value;
     $newEvent->new_value = $new_value;
     $newEvent->comment = $comment;
     $newEvent->event_performed_by_user_id = User::getCurrentUserId();
     //if save susscessfully, just return the new event
     if ($newEvent->save()) {
         $resEvent = $newEvent;
     }
     return $resEvent;
 }
 public function actionEscalate($id)
 {
     $model = $this->loadModel($id);
     $modelNew = new Ticket();
     $modelNew->creator_user_id = User::getCurrentUserId();
     $modelNew->status = 'Pending';
     $modelNew->created_date = new CDbExpression('NOW()');
     $modelNew->subject = $model->subject;
     $modelNew->description = $model->description;
     $modelNew->domain_id = $model->domain_id;
     $modelNew->subdomain_id = $model->subdomain_id;
     $modelNew->file = $model->file;
     $modelNew->priority_id = $model->priority_id;
     $modelNew->isEscalated = 1;
     $modelNew->assigned_date = new CDbExpression('NOW()');
     /* Get the current date and time */
     /*Assign the ticket to the most appropiate Domain mentor in tier2*/
     $sub = true;
     if ($model->subdomain_id == null) {
         $sub = false;
     }
     if (!$sub) {
         $modelNew->assign_user_id = User::escalateTicket($model->domain_id, $sub);
     } else {
         $modelNew->assign_user_id = User::escalateTicket($model->subdomain_id, $sub);
     }
     $saved = true;
     $trans = Yii::app()->db->beginTransaction();
     try {
         $saved = $modelNew->save();
         $sql = 'INSERT INTO comment(description, added_date, ticket_id, user_added) SELECT description, added_date,' . $modelNew->id . ', user_added FROM comment WHERE ticket_id =' . $model->id;
         $command = Yii::app()->db->createCommand($sql);
         $command->execute();
         //generate the escalated events
         TicketEvents::recordEvent(EventType::Event_Escalated_To, $model->id, NULL, $modelNew->id, NULL);
         //generate the new event
         TicketEvents::recordEvent(EventType::Event_New, $modelNew->id, NULL, NULL, NULL);
         //generate the escalated events
         TicketEvents::recordEvent(EventType::Event_Escalated_From, $modelNew->id, $model->id, NULL, NULL);
         $trans->commit();
     } catch (Exception $e) {
         $trans->rollback();
         Yii::log("Error occurred while saving the ticket or its events. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
         $saved = false;
     }
     //$send = $modelNew->isNewRecord;
     if ($saved) {
         /*If save if true send Notification the the Domain Mentor who was assigned the ticket */
         // if($send)
         User::sendTicketAssignedEmailNotification($modelNew->creator_user_id, $modelNew->assign_user_id, $modelNew->domain_id, $modelNew->id);
         // $this->redirect(array('view', 'id' => $modelNew->id));
         //copy all the comments from the old ticket to the new ticket
         //this has been substituted here for a change of status
         /*  $sql2 = 'INSERT INTO comment(description, added_date, ticket_id, user_added) VALUES ("Ticket ' . $model->id . ' was escalated to ticket '. $modelNew->id . '" , ' . $modelNew->created_date. ',' . $model->id . ', "System")';
                     $command2 = Yii::app()->db->createCommand($sql2);
                     $command2->execute();
         
                     $sql3 = 'INSERT INTO comment(description, added_date, ticket_id, user_added) VALUES ("Ticket ' . $model->id . ' was escalated to ticket '. $modelNew->id . '" , ' . $modelNew->created_date. ',' . $modelNew->id . ', "System")';
                     $command3 = Yii::app()->db->createCommand($sql3);
                     $command3->execute();*/
         $response = array();
         $response['url'] = "/coplat/index.php/home/userHome";
         echo json_encode($response);
         exit;
     }
 }