AnaestheticAgentMappingController::actionAdd PHP Method

actionAdd() public method

public actionAdd ( )
    public function actionAdd()
    {
        $subspecialtyId = $this->request->getParam('subspecialty_id');
        $siteId = $this->request->getParam('site_id');
        $anaestheticAgentId = $this->request->getParam('anaesthetic_agent_id');
        if (!Yii::app()->request->isAjaxRequest) {
            $this->render('errorpage', array('errormessage' => 'notajaxcall'));
        } else {
            if (!is_numeric($subspecialtyId) || !is_numeric($siteId) || !is_numeric($anaestheticAgentId)) {
                echo 'error';
            } else {
                $criteria = new CDbCriteria();
                $criteria->condition = 'anaesthetic_agent_id=:anaesthetic_agent_id AND site_id=:site_id AND subspecialty_id=:subspecialty_id';
                $criteria->params = array(':anaesthetic_agent_id' => $anaestheticAgentId, ':site_id' => $siteId, ':subspecialty_id' => $subspecialtyId);
                $currentSSAA = SiteSubspecialtyAnaestheticAgent::model()->findall($criteria);
                if (!$currentSSAA) {
                    $newSSAA = new SiteSubspecialtyAnaestheticAgent();
                    $newSSAA->subspecialty_id = $subspecialtyId;
                    $newSSAA->site_id = $siteId;
                    $newSSAA->anaesthetic_agent_id = $anaestheticAgentId;
                    if ($newSSAA->save()) {
                        echo 'success added to SSAA';
                    } else {
                        echo 'error';
                    }
                } else {
                    echo 'success';
                }
            }
        }
    }