Exemple #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'));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  *
  * @return void
  */
 public function beforeSave()
 {
     // title validator
     $this->addValidator('title', v::required(), v::length(2, 128));
     //description validator
     $this->addValidator('description', v::required(), v::length(2, 250), v::string());
     //category validator
     $this->addValidator('categoryId', v::required(), v::integer());
     //cost validator
     $this->addValidator('cost', v::required(), v::float(), v::min(0.01, true));
 }
Exemple #3
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'));
 }