Ejemplo n.º 1
0
 /**
  * Assert thet the model can be saved without error and, if errors are present, print
  * out the corresponding error messages.
  * @param CActiveRecord $model
  */
 public function assertSaves(CActiveRecord $model)
 {
     $saved = $model->save();
     if ($model->hasErrors()) {
         VERBOSE_MODE && print_r($model->getErrors());
     }
     $this->assertTrue($saved);
 }
Ejemplo n.º 2
0
 /**
  *### .checkErros()
  *
  * errors as CHttpException
  * @internal param $msg
  */
 public function checkErrors()
 {
     if ($this->model->hasErrors()) {
         $msg = array();
         foreach ($this->model->getErrors() as $attribute => $errors) {
             $msg = array_merge($msg, $errors);
         }
         //todo: show several messages. should be checked in x-editable js
         //$this->error(join("\n", $msg));
         $this->error($msg[0]);
     }
 }
Ejemplo n.º 3
0
 /**
  *### .checkErros()
  *
  * errors as CHttpException
  * @internal param $msg
  * @throws CHttpException
  */
 public function checkErrors()
 {
     if (!$this->model->hasErrors()) {
         return;
     }
     $msg = array();
     foreach ($this->model->getErrors() as $attribute => $errors) {
         // TODO: make use of $attribute elements
         $msg = array_merge($msg, $errors);
     }
     $this->error($msg[0]);
 }
Ejemplo n.º 4
0
 /**
  * beforeUpdate
  *
  */
 protected function beforeUpdate()
 {
     $this->onBeforeUpdate(new CEvent($this));
     return !$this->model->hasErrors();
 }
Ejemplo n.º 5
0
 /**
  * Assert thet the model can be saved without error and, if errors are present, print
  * out the corresponding error messages.
  * @param CActiveRecord $model
  */
 public function assertSaves(CActiveRecord $model)
 {
     $saved = $model->save();
     if ($model->hasErrors()) {
         X2_TEST_DEBUG_LEVEL > 1 && print_r($model->getErrors());
     }
     $this->assertTrue($saved);
 }
Ejemplo n.º 6
0
 public static function textInputFull(CActiveRecord $model, $fieldName, $options = array())
 {
     $containerCss = '';
     $options['class'] = 'form-control';
     if (array_key_exists('inputClass', $options)) {
         $options['class'] .= " {$options['inputClass']}";
         unset($options['inputClass']);
     }
     if (array_key_exists('fieldColumn', $options)) {
         $columns = $options['fieldColumn'];
         unset($options['fieldColumn']);
     } else {
         $columns = self::$fullColumn;
     }
     $errorHelp = '';
     if ($model->hasErrors($fieldName)) {
         $containerCss .= ' has-error';
         $errorHelp = '<span class="help-block">' . $model->getError($fieldName) . '</span>';
     }
     $str = "<div class=\"form-group{$containerCss}\">";
     if (array_key_exists('hasLabel', $options)) {
         $str .= '<div class="input-caption col-md-' . $columns . '">' . CHtml::activeLabelEx($model, $fieldName, array('class' => 'control-label')) . '</div>';
         unset($options['hasLabel']);
     }
     $str .= "<div class=\"col-md-{$columns}\">" . CHtml::activeTextField($model, $fieldName, $options) . "{$errorHelp}</div></div>";
     return $str;
 }