Example #1
0
 /**
  * Update Attributes Connections
  * @todo Test
  */
 protected function attachToAttributes($name, $form)
 {
     $new = $this->parseForm($form);
     if (!is_array($new['target'])) {
         return null;
     }
     foreach ($new['target'] as $a) {
         $a = trim($a);
         if (empty($a)) {
             continue;
         }
         if (starts_with($a, ":")) {
             // id
             $aDb = \Veer\Models\Attribute::find(substr($a, 1));
             if (!is_object($aDb)) {
                 continue;
             }
         } else {
             // string values
             $aDb = \Veer\Models\Attribute::firstOrNew(['name' => $name, 'val' => $a]);
             $aDb->type = empty($aDb->type) ? 'descr' : $aDb->type;
             $aDb->descr = empty($aDb->descr) ? '' : $aDb->descr;
             $aDb->save();
         }
         $attributes[] = $aDb->id;
     }
     if (isset($attributes)) {
         $this->attachFromForm($new['elements'], $attributes, 'attributes');
     }
 }