Example #1
0
 public function setColors($selected)
 {
     $all_colors = $this->getColors();
     $array = $this->getColorsData($all_colors);
     foreach ($all_colors as $key => $value) {
         if (in_array($key, $selected) && !in_array($key, $array)) {
             $this->setModelAttribute($this->id, $key);
         } elseif (in_array($key, $array) && !in_array($key, $selected)) {
             $item = R::findAll('rel_model_attr', 'model_id = ? AND attr_id = ?', [$this->id, $key]);
             R::trashAll($item);
         }
     }
 }