Example #1
0
 /**
  * afterSave callback
  *
  * Checks for authors, publishers and narrators and creates them on the fly if 
  * they dont exist, if they exist by the entered name the id will be looked up
  * and stored in the record.
  *
  * @return boolean True on success
  */
 public function afterSave(Model $Model, $created)
 {
     extract($this->settings[$Model->alias]);
     $resave = false;
     foreach ($types as $submodel) {
         $viewField = Inflector::underscore($submodel . '_' . $Model->{Inflector::classify($submodel)}->displayField);
         if (isset($Model->data[$Model->alias][$viewField]) && !empty($Model->data[$Model->alias][$viewField])) {
             if ($Model->lookup($submodel, $Model->data[$Model->alias][$viewField])) {
                 $resave = true;
             }
         }
     }
     if ($resave) {
         $result = $Model->save($Model->data, array('validate' => false, 'callbacks' => false));
         $Model->data = $result;
     }
 }