예제 #1
0
 public static function add($id, $meta)
 {
     $desc = Description::create(['id' => $id, 'name' => $meta->name, 'market_name' => $meta->market_name ?: $meta->name, 'icon_url' => $meta->icon_url, 'icon_url_large' => isset($meta->icon_url_large) ? $meta->icon_url_large : '', 'name_color' => $meta->name_color ?: '000000']);
     if (!empty($meta->actions)) {
         foreach ($meta->actions as $idx => $action) {
             if ($action->name == 'Inspect in Game...') {
                 $desc->inspect_url_template = $action->link;
                 $desc->save();
                 break;
             }
         }
     }
     foreach ($meta->tags as $idx => $tag_data) {
         $tag = Tag::find('all', array('conditions' => array('category = ? AND category_name = ? AND internal_name = ? AND name = ?', $tag_data->category, $tag_data->category_name, $tag_data->internal_name, $tag_data->name)));
         if (empty($tag)) {
             $tag = new Tag(['category' => $tag_data->category, 'category_name' => $tag_data->category_name, 'internal_name' => $tag_data->internal_name, 'name' => $tag_data->name]);
             if (!$tag->is_valid()) {
                 $desc->delete();
                 return null;
             } else {
                 $tag->save();
             }
         } else {
             $tag = $tag[0];
         }
         if ($tag_data->category == 'Rarity') {
             $desc->name_color = $tag_data->color;
             $desc->save();
         }
         Descriptiontag::create(['description_id' => $desc->id, 'tag_id' => $tag->id]);
     }
     return $desc;
 }