OEModule\PatientTicketing\controllers\AdminController::saveQueue PHP Method

saveQueue() protected method

Performs the update/create process on a Queue.
protected saveQueue ( $queue, null $parent = null )
$queue
$parent null
    protected function saveQueue($queue, $parent = null)
    {
        // try and process form
        $queue->attributes = $_POST;
        if (!$parent && $queue->isNewRecord) {
            $queue->is_initial = true;
        }
        if (!$queue->validate()) {
            $resp = array('success' => false, 'form' => $this->renderPartial('form_queue', array('parent' => $parent, 'queue' => $queue, 'errors' => $queue->getErrors()), true));
            echo \CJSON::encode($resp);
        } else {
            $transaction = Yii::app()->db->beginTransaction();
            try {
                $action = $queue->isNewRecord ? 'create' : 'update';
                $queue->save();
                if ($parent) {
                    $outcome = new models\QueueOutcome();
                    $outcome->queue_id = $parent->id;
                    $outcome->outcome_queue_id = $queue->id;
                    $outcome->save();
                }
                \Audit::add('admin', $action, $queue->id, null, array('module' => 'PatientTicketing', 'model' => $queue->getShortModelName()));
                $transaction->commit();
                $resp = array('success' => true, 'queueId' => $queue->id);
                echo \CJSON::encode($resp);
            } catch (Exception $e) {
                $transaction->rollback();
                throw new \CHttpException(500, 'Unable to create queue');
            }
        }
    }