public function actionReject($id) { /*Retrieve ticket Details */ $model = Ticket::model()->findByPk($id); $old_mentor = $model->assign_user_id; $current_user = User::model()->getCurrentUserId(); if ($old_mentor == $current_user) { $this->render("reject"); //begin collecting all the data $tier = 1; if ($model->isEscalated != null) { $tier = 2; } $rule = ReassignRules::model()->findBySql("Select * from reassign_rules where rule_id =1"); $count = TicketEvents::model()->findBySql("Select COUNT(id) as 'id' from ticket_events where event_type_id = 3 and ticket_id =:tid", array(":tid" => $id)); if ($count->id >= $rule->setting) { //reassign to system admin to many reassigns. $model->assign_user_id = 5; } else { $boolean = true; /* Identify is the subdomain was specified by the user */ if ($model->subdomain_id == null) { $boolean = false; $model->assign_user_id = User::reassignTicket($model->domain_id, $boolean, $old_mentor, $tier, $id); } else { $model->assign_user_id = User::reassignTicket($model->subdomain_id, $boolean, $old_mentor, $tier, $id); } } $recordStatusChangeFromRejectToPending = false; /*Change the status of the ticket to Pending from Reject */ if ($model->status == Ticket::Status_Reject) { $model->status = Ticket::Status_Pending; $recordStatusChangeFromRejectToPending = true; } $model->assigned_date = new CDbExpression('NOW()'); /* Get the current date and time */ //Save all the ticket with it's transactions $saved = true; $trans = Yii::app()->db->beginTransaction(); try { //save the ticket $model->save(); //save the Reassign event TicketEvents::recordEvent(EventType::Event_AssignedOrReasignedToUser, $model->id, $old_mentor, $model->assign_user_id, NULL); if ($recordStatusChangeFromRejectToPending) { TicketEvents::recordEvent(EventType::Event_Status_Changed, $model->id, Ticket::Status_Reject, Ticket::Status_Pending, 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; } //prepare the response $response = array(); if ($saved) { /*If save if true send Notification the the Domain Mentor who was assigned the ticket */ User::sendStatusReassignedEmailNotificationToOldMentor($model->id, $old_mentor, User::model()->getCurrentUserId()); if (User::isCurrentUserAdmin()) { $response['url'] = "/coplat/index.php/home/adminHome"; } else { $response['url'] = "/coplat/index.php/home/userHome"; } } else { $response['url'] = "/coplat/index.php/home/userHome"; } User::sendTicketAssignedEmailNotification($model->creator_user_id, $model->assign_user_id, $model->domain_id, $model->id); // //Yii::app()->request->redirect(Yii::app()->homeURL); } else { Yii::app()->request->redirect(Yii::app()->homeURL); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ReassignRules the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ReassignRules::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }