Example #1
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aElement !== null) {
             if (!$this->aElement->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aElement->getValidationFailures());
             }
         }
         if ($this->aOrderStatus !== null) {
             if (!$this->aOrderStatus->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aOrderStatus->getValidationFailures());
             }
         }
         if ($this->aClient !== null) {
             if (!$this->aClient->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aClient->getValidationFailures());
             }
         }
         if (($retval = OrderPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAddCustomer()
 {
     $model = new Client();
     if (Yii::app()->user->checkAccess('client.create')) {
         if (isset($_POST['Client'])) {
             $model->attributes = $_POST['Client'];
             if ($model->validate()) {
                 if ($model->save()) {
                     if (!empty($_POST['Client']['debter_id'])) {
                         $debter_id = $_POST['Client']['debter_id'];
                         $mod_debter_ref = new DebterClientRef();
                         $mod_debter_ref->client_id = $model->id;
                         $mod_debter_ref->debter_id = (int) $debter_id;
                         $mod_debter_ref->save();
                     }
                     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                     Yii::app()->shoppingCart->setCustomer($model->id);
                     $this->redirect(array('saleItem/index'));
                 }
             }
         }
     } else {
         throw new CHttpException(403, 'You are not authorized to perform this action');
     }
     if (Yii::app()->request->isAjaxRequest) {
         Yii::app()->clientScript->scriptMap['*.js'] = false;
         //Yii::app()->clientScript->scriptMap['*.cs'] = false;
         if (Yii::app()->settings->get('system', 'touchScreen') == '1') {
             echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form_touchscreen', array('model' => $model), true, false)));
         } else {
             echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, false)));
         }
         Yii::app()->end();
     } else {
         $this->render('_form', array('model' => $model));
     }
 }