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

actionTakeTicket() public method

Method to take ownership of a ticket for the current user.
public actionTakeTicket ( $id )
$id
    public function actionTakeTicket($id)
    {
        if (!($ticket = models\Ticket::model()->with('current_queue')->findByPk($_REQUEST['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;
            if ($ticket->assignee_user_id != Yii::app()->user->id) {
                $resp['message'] = 'Ticket has already been taken by ' . $ticket->assignee->getFullName();
            } else {
                $resp['message'] = 'Ticket was already taken by you.';
            }
        } else {
            $ticket->assignee_user_id = Yii::app()->user->id;
            $ticket->assignee_date = date('Y-m-d H:i:s');
            if ($ticket->save()) {
                $resp['status'] = 1;
                $ticket->audit('ticket', 'take-ownership', $ticket->id);
            } else {
                $resp['status'] = 0;
                $resp['message'] = 'Unable to take ticket at this time.';
                Yii::log("Couldn't save ticket to take it: " . print_r($ticket->getErrors(), true), \CLogger::LEVEL_ERROR);
            }
        }
        echo \CJSON::encode($resp);
    }