Esempio 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'));
 }