Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @return void
  */
 public function beforeSave()
 {
     // nickname validator
     $this->addValidator('nickname', v::required());
     // group validator
     $this->addValidator('group', v::required());
     // types validator
     $this->types = explode(',', $this->types);
     $this->addValidator('types', v::callback(function ($input) {
         foreach ($input as &$type) {
             $type = trim($type);
         }
         $length = sizeof($input);
         $types = \Application\MusicTypes\Table::select()->select('type')->where('type IN (?)', $input)->execute();
         if (sizeof($types) == $length) {
             return true;
         }
     })->setError('Types does not exist'));
     // concert_date validator
     $this->addValidator('concertDate', v::required(), v::date('Y-m-d'));
     $this->addValidator('alias', v::required(), v::length(2, 64), v::slug(), v::callback(function ($input) {
         $select = $this->getTable()->select()->where('alias = ?', $input);
         if ($this->id) {
             $select->andWhere('id != ?', $this->id);
         }
         return !sizeof($select->execute());
     })->setError('Musician with alias "{{input}}" already exists'));
 }
Ejemplo n.º 2
0
 /**
  * @return void
  */
 public function beforeSave()
 {
     $this->addValidator('name', v::required(), v::length(2, 128));
     $this->addValidator('alias', v::required(), v::length(2, 64), v::slug(), v::callback(function ($input) {
         $select = $this->getTable()->select()->where('alias = ?', $input);
         if ($this->id) {
             $select->andWhere('id != ?', $this->id);
         }
         if ($this->parentId) {
             $select->andWhere('parentId = ?', $this->parentId);
         } else {
             $select->andWhere('parentId IS NULL');
         }
         return !sizeof($select->execute());
     })->setError('Category with alias "{{input}}" already exists'));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * @return void
  */
 public function beforeSave()
 {
     // title validator
     $this->addValidator('title', v::required());
     // alias validator
     $this->addValidator('alias', v::required(), v::slug(), v::callback(function ($input) {
         if ($row = $this->getTable()->findRowWhere(['alias' => $input])) {
             if ($row->id != $this->id) {
                 return false;
             }
         }
         return true;
     })->setError('Alias "{{input}}" already exists'));
     // content validator
     $this->addValidator('content', v::callback(function ($input) {
         if (empty($input) or trim(strip_tags($input, '<img>')) == '') {
             return false;
         }
         return true;
     })->setError('Content can\'t be empty'));
 }