OEModule\PatientTicketing\controllers\DefaultController::actionReleaseTicket PHP Method

actionReleaseTicket() public method

Release a ticket from assignment.
public actionReleaseTicket ( $id )
$id
    public function actionReleaseTicket($id)
    {
        if (!($ticket = models\Ticket::model()->with('current_queue')->findByPk($id))) {
            throw new \CHttpException(404, 'Invalid ticket id.');
        }
        $qs_svc = Yii::app()->service->getService(self::$QUEUESET_SERVICE);
        $queueset = $qs_svc->getQueueSetForTicket($ticket->id);
        if (!$this->checkQueueSetProcessAccess($queueset)) {
            throw new \CHttpException(403, 'Not authorised to take ticket');
        }
        $resp = array('status' => null);
        if (!$ticket->assignee_user_id) {
            $resp['status'] = 0;
            $resp['message'] = 'A ticket that is not owned cannot be released.';
        } elseif ($ticket->assignee_user_id != Yii::app()->user->id) {
            $resp['status'] = 0;
            $resp['message'] = "You cannot release a ticket you don't own.";
        } else {
            $ticket->assignee_user_id = null;
            $ticket->assignee_date = null;
            if ($ticket->save()) {
                $resp['status'] = 1;
                $ticket->audit('ticket', 'release', $ticket->id);
            } else {
                $resp['status'] = 0;
                $resp['message'] = 'Unable to release ticket at this time.';
                Yii::log("Couldn't save ticket to release it: " . print_r($ticket->getErrors(), true), \CLogger::LEVEL_ERROR);
            }
        }
        echo \CJSON::encode($resp);
    }