Exemplo n.º 1
0
 public static function searchByKeywords($keywords, $filter = null)
 {
     $items = Item::with(array('company', 'tags', 'categories', 'territory'));
     if (!empty($keywords)) {
         $items->where(function ($q) use($keywords) {
             $q->where('name', 'LIKE', '%' . $keywords . "%");
             $q->orWhere('description', 'LIKE', '%' . $keywords . "%");
         });
     }
     if (!empty($filter) && is_array($filter)) {
         if (count($filter['categories'])) {
             $items->whereHas('categories', function ($q) use($filter) {
                 $q->whereIn('item_categories.category_id', $filter['categories']);
             });
         }
         if (!empty($filter['min']) && !empty($filter['max'])) {
             $items->where('min_investment', '>=', $filter['min'] * 10000);
             $items->where('min_investment', '<=', $filter['max'] * 10000);
         } elseif (!empty($filter['min']) && empty($filter['max'])) {
             $items->where('min_investment', '>=', $filter['min'] * 10000);
         } elseif (empty($filter['min']) && !empty($filter['max'])) {
             $items->where('min_investment', '<=', $filter['max'] * 10000);
         }
     }
     return $items->get();
 }
Exemplo n.º 2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $access_token = Util::getAccessToken();
     $user = User::findUserByToken($access_token);
     if ($user->hasRole('admin')) {
         $bookmarks = BookmarkObject::all();
         foreach ($bookmarks as $bookmark) {
             if ($bookmark->type == 'item') {
                 $bookmark->object = Item::with(array('company', 'tags', 'categories'))->find($bookmark->object_id);
             } elseif ($bookmark->type == 'company') {
                 $bookmark->object = Company::with(array('tags'))->find($bookmark->object_id);
             }
         }
     } else {
         $bookmarks = BookmarkObject::where('user_id', $user->id)->get();
         foreach ($bookmarks as $bookmark) {
             if ($bookmark->type == 'item') {
                 $bookmark->object = Item::with(array('company', 'tags'))->find($bookmark->object_id);
             } elseif ($bookmark->type == 'company') {
                 $bookmark->object = Company::with(array('tags'))->find($bookmark->object_id);
             }
         }
     }
     return Response::json(array('success_code' => 'OK', 'data' => $bookmarks->toArray()));
 }
 /**
  * Show the profile for the given user.
  */
 public function trending()
 {
     $pinned = array('pins' => function ($query) {
         $query->where('user_id', '=', Auth::id());
     }, 'user');
     $items = Item::with($pinned)->get()->take(25);
     return View::make('trending', array('items' => $items));
 }
 public function testWithBelongsTo()
 {
     $user = User::create(array('name' => 'John Doe'));
     Item::create(array('type' => 'knife', 'user_id' => $user->_id));
     Item::create(array('type' => 'shield', 'user_id' => $user->_id));
     Item::create(array('type' => 'sword', 'user_id' => $user->_id));
     Item::create(array('type' => 'bag', 'user_id' => null));
     $items = Item::with('user')->orderBy('user_id', 'desc')->get();
     $user = $items[0]->getRelation('user');
     $this->assertInstanceOf('User', $user);
     $this->assertEquals('John Doe', $user->name);
     $this->assertEquals(1, count($items[0]->getRelations()));
     $this->assertEquals(null, $items[3]->getRelation('user'));
 }
 public function getView($id = 0)
 {
     $item = Item::with('name', 'vendors', 'vendors.npc', 'vendors.npc.name', 'vendors.npc.location', 'vendors.npc.location.name')->where('id', $id)->remember(Config::get('site.cache_length'))->first();
     $vendors = array();
     foreach ($item->vendors as $vendor) {
         $npc = array('id' => $vendor->npc->id, 'name' => $vendor->npc->name->term, 'color' => $vendor->pivot->color);
         foreach ($vendor->npc->location as $loc) {
             if (!isset($vendors[$loc->id])) {
                 $vendors[$loc->id] = array('name' => $loc->name->term, 'npcs' => array());
             }
             $vendors[$loc->id]['npcs'][] = array_merge($npc, $loc->pivot->x ? array('coords' => array('x' => $loc->pivot->x, 'y' => $loc->pivot->y)) : array());
         }
     }
     ksort($vendors);
     exit(json_encode(array('html' => View::make('vendors.modal', array('item' => $item, 'vendors' => $vendors))->render())));
 }
 public function getBeasts($id = 0)
 {
     $item = Item::with('name', 'beasts', 'beasts.name', 'beasts.location', 'beasts.location.name')->where('id', $id)->remember(Config::get('site.cache_length'))->first();
     $beasts = array();
     foreach ($item->beasts as $beast) {
         foreach ($beast->location as $loc) {
             @($beasts[$loc->name->term][ltrim($beast->name->term, '\\x20') . ($loc->pivot->triggered ? '*' : '')][] = $loc->pivot->levels);
         }
     }
     // echo View::make('beasts.modal', array(
     // 		'item' => $item,
     // 		'beasts' => $beasts
     // 	))->render();
     // exit;
     exit(json_encode(array('html' => View::make('beasts.modal', array('item' => $item, 'beasts' => $beasts))->render())));
 }
 public function getIndex()
 {
     // Items that are Materia
     $results = Item::with('name', 'en_name', 'baseparam', 'baseparam.name', 'baseparam.en_name')->where('itemcategory_id', 13)->orderBy('id')->get();
     // Flatten materia list
     $materia = array();
     foreach ($results as $row) {
         preg_match('/^(.*)\\sMateria\\s(.*)$/', $row->en_name->term, $matches);
         list($ignore, $name, $power) = $matches;
         if (!isset($materia[$name])) {
             $materia[$name] = array('icon' => $row->baseparam[0]->en_name->term, 'stat' => $row->baseparam[0]->name->term, 'power' => array());
         }
         $materia[$name]['power'][$power] = array('id' => $row->id, 'amount' => $row->baseparam[0]->pivot->nq_amount);
     }
     // Let's move a few up front
     // First, Crafters, then Gatherers, then the rest (Battling)
     return View::make('pages.materia')->with('materia_list', $materia);
 }
Exemplo n.º 8
0
 public function show($id)
 {
     $user = UserService::getLoggedInUser();
     $item = DB::transaction(function () use($id, $user) {
         if ($user) {
             Item::updateStatus($id, $user, 'read');
         }
         $item = Item::with('tags', 'userStatuses')->find($id);
         return $item;
     });
     if (!$item) {
         return Response::json(array('error_code' => Config::get('constants.ERROR.ITEM_NOT_FOUND'), 'error_message' => 'Item not found'), 500);
     }
     if ($user) {
         return Response::json(array('success_code' => 'OK', 'data' => $item->toArray($user)));
     } else {
         return Response::json(array('success_code' => 'OK', 'data' => $item->toArray()));
     }
 }
 public function getIndex()
 {
     // Get the list
     $list = Session::get('list', array());
     foreach ($list as $k => &$l) {
         // $l starts as the amount integer and we're transforming it to an array
         $l = array('amount' => $l, 'item' => Item::with(array('recipe' => function ($query) {
             $query->limit(1);
         }, 'name'))->find($k));
         if (count($l['item']->recipe) == 0) {
             unset($list[$k]);
         }
     }
     unset($l);
     $saved = array();
     if ($list) {
         foreach ($list as $id => $info) {
             $saved[] = $id . ',' . $info['amount'];
         }
     }
     $saved = implode(':', $saved);
     return View::make('pages.list')->with('active', 'list')->with('list', $list)->with('saved_link', $saved)->with('job_list', ClassJob::get_name_abbr_list());
 }
Exemplo n.º 10
0
 public function postIndex()
 {
     $title = preg_replace('/\\s+/m', ' ', preg_replace("/\n/", '', trim(Input::get('title'))));
     View::share('map_title', $title);
     $posted_list = explode('||', Input::get('items'));
     $item_list = array();
     foreach ($posted_list as $row) {
         list($id, $amount) = explode('|', $row);
         $item_list[$id] = $amount;
     }
     if (!empty($item_list)) {
         $items = Item::with('name', 'vendors', 'vendors.npc', 'vendors.npc.name', 'vendors.npc.location', 'vendors.npc.location.name', 'clusters', 'clusters.classjob', 'clusters.classjob.name', 'clusters.classjob.abbr', 'clusters.location', 'clusters.location.name', 'clusters.nodes', 'beasts', 'beasts.name', 'beasts.location')->whereIn('id', array_keys($item_list))->remember(Config::get('site.cache_length'))->get();
         $map_data = array();
         foreach ($items as $item) {
             foreach ($item->vendors as $v) {
                 foreach ($v->npc->location as $l) {
                     if (!isset($map_data[$l->id])) {
                         $map_data[$l->id] = array('name' => $l->name->term);
                     }
                     if (!isset($map_data[$l->id]['vendors'])) {
                         $map_data[$l->id]['vendors'] = array();
                     }
                     //						// Map ID 			// NPC ID
                     if (!isset($map_data[$l->id]['vendors'][$v->npc->id])) {
                         $map_data[$l->id]['vendors'][$v->npc->id] = array('name' => $v->npc->name->term, 'x' => $l->pivot->x, 'y' => $l->pivot->y, 'items' => array());
                     }
                     $map_data[$l->id]['vendors'][$v->npc->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term, 'min_price' => $item->min_price, 'max_price' => $item->max_price);
                 }
             }
             foreach ($item->clusters as $c) {
                 if (!isset($map_data[$c->placename_id])) {
                     $map_data[$c->placename_id] = array('name' => is_null($c->location) ? 'unknown' : $c->location->name->term);
                 }
                 if (!isset($map_data[$c->placename_id]['clusters'])) {
                     $map_data[$c->placename_id]['clusters'] = array();
                 }
                 if (!isset($map_data[$c->placename_id]['clusters'][$c->id])) {
                     $map_data[$c->placename_id]['clusters'][$c->id] = array('icon' => $c->icon, 'level' => $c->level, 'classjob' => $c->classjob_id, 'classjob_name' => $c->classjob->name->term, 'classjob_abbr' => $c->classjob->abbr->term, 'x' => $c->x, 'y' => $c->y, 'items' => array());
                 }
                 $map_data[$c->placename_id]['clusters'][$c->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term, 'min_price' => $item->min_price, 'max_price' => $item->max_price);
             }
             foreach ($item->beasts as $b) {
                 foreach ($b->location as $l) {
                     if (!isset($map_data[$l->id])) {
                         $map_data[$l->id] = array('name' => $b->name->term);
                     }
                     if (!isset($map_data[$l->id]['beasts'])) {
                         $map_data[$l->id]['beasts'] = array();
                     }
                     //						// Map ID 			// NPC ID
                     if (!isset($map_data[$l->id]['beasts'][$b->id])) {
                         $map_data[$l->id]['beasts'][$b->id] = array('name' => $b->name->term, 'levels' => $b->pivot->levels, 'triggered' => $b->pivot->triggered, 'items' => array());
                     }
                     $map_data[$l->id]['beasts'][$b->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term);
                 }
             }
         }
         View::share('map_data', $map_data);
         View::share('items', $items);
     }
     return $this->getIndex();
 }
 public function getIndex()
 {
     list($sections, $translations) = Cache::get('food_sections_' . Config::get('language'), function () {
         // Items that are Food
         $results = Item::with('name', 'baseparam', 'baseparam.name', 'baseparam.en_name', 'vendors')->where('itemcategory_id', 5)->orderBy('id')->get();
         // Group the food up
         $food_groups = $translations = array();
         foreach ($results as $item) {
             $stats = $names = $key_name = array();
             foreach ($item->baseparam as $baseparam) {
                 $nq_limit = $baseparam->pivot->nq_limit ?: (int) $baseparam->pivot->nq_amount;
                 $hq_limit = $baseparam->pivot->hq_limit ?: (int) $baseparam->pivot->hq_amount;
                 $translations[$baseparam->en_name->term] = $baseparam->name->term;
                 $stats[$baseparam->en_name->term] = array('name' => $baseparam->name->term, 'nq' => array('amount' => (int) $baseparam->pivot->nq_amount, 'limit' => $nq_limit, 'threshold' => round($nq_limit / ($baseparam->pivot->nq_amount / 100))), 'hq' => array('amount' => (int) $baseparam->pivot->hq_amount, 'limit' => $hq_limit, 'threshold' => $baseparam->pivot->hq_amount == 0 ? 0 : round($hq_limit / ($baseparam->pivot->hq_amount / 100))));
             }
             $names = array_keys($stats);
             sort($names);
             if (empty($names)) {
                 continue;
             }
             $food_groups[implode('|', $names)][] = array('id' => $item->id, 'has_hq' => $item->has_hq, 'name' => $item->name->term, 'min_price' => $item->min_price, 'vendor_count' => count($item->vendors), 'stats' => $stats);
         }
         ksort($food_groups);
         // Break these up into groups
         $sections_base = array('data' => array(), 'headers' => array(), 'intersections' => array());
         // This order determines how they show up on the page, so it's kind of important to keep it this way
         $sections = array('Crafting' => $sections_base, 'Gathering' => $sections_base, 'Battle' => $sections_base, 'Resistances' => $sections_base);
         foreach ($food_groups as $key => $value) {
             $keys = explode('|', $key);
             $belongs_to = 'Battle';
             if (count(array_intersect(array('CP', 'Control', 'Craftsmanship'), $keys)) > 0) {
                 $belongs_to = 'Crafting';
             } elseif (count(array_intersect(array('GP', 'Gathering', 'Perception'), $keys)) > 0) {
                 $belongs_to = 'Gathering';
             } elseif (preg_match('/Resistance/', $key)) {
                 $belongs_to = 'Resistances';
             }
             $sections[$belongs_to]['data'][$key] = $value;
         }
         foreach ($sections as $section_key => $section_array) {
             $single_keys = array();
             foreach (array_keys($section_array['data']) as $keys) {
                 $single_keys = array_merge($single_keys, explode('|', $keys));
             }
             $single_keys = array_unique($single_keys);
             sort($single_keys);
             $sections[$section_key]['headers'] = $single_keys;
             // Also get the Intersections
             $intersections = array();
             foreach ($single_keys as $i) {
                 if (!isset($intersections[$i])) {
                     $intersections[$i] = array();
                 }
                 foreach ($single_keys as $j) {
                     if (!isset($intersections[$i][$j])) {
                         $intersections[$i][$j] = 0;
                     }
                     $looking_for = $i == $j ? 1 : 2;
                     foreach ($section_array['data'] as $key => $value) {
                         $keys = explode('|', $key);
                         $matched = 0;
                         $bonus = 0;
                         if (in_array($i, $keys)) {
                             $matched++;
                         }
                         if ($i != $j && in_array($j, $keys)) {
                             $matched++;
                         }
                         if (preg_match('/Vitality/', $key)) {
                             $bonus = 1;
                             $matched++;
                         }
                         if ($matched == $looking_for + $bonus && count($keys) == $looking_for + $bonus) {
                             // Count base items
                             $intersections[$i][$j] += count($value);
                             // Count HQ items
                             foreach ($value as $x) {
                                 if ($x['has_hq']) {
                                     $intersections[$i][$j]++;
                                 }
                             }
                         }
                     }
                 }
             }
             $sections[$section_key]['intersections'] = $intersections;
         }
         unset($food_groups);
         return array($sections, $translations);
     });
     return View::make('pages.food')->with('sections', $sections)->with('translations', $translations);
 }
Exemplo n.º 12
0
 public static function calculate($job_id = 0, $level = 1, $range = 0, $craftable_only = TRUE, $rewardable_too = TRUE)
 {
     $cache_key = __METHOD__ . '|' . Config::get('language') . '|' . $job_id . ',' . $level . ',' . $range . ($craftable_only ? 'T' . ($rewardable_too ? 'T' : 'F') : 'F');
     // Does cache exist?  Return that instead
     if (Cache::has($cache_key)) {
         return Cache::get($cache_key);
     }
     // Get the job IDs
     $job = ClassJob::with('en_abbr')->find($job_id);
     $equipment_list = array_flip(Config::get('site.equipment_roles'));
     array_walk($equipment_list, function (&$i) {
         $i = array();
     });
     // Slot data
     $slots = Config::get('site.defined_slots');
     $slot_alias = Config::get('site.slot_alias');
     $slot_cannot_equip = Config::get('site.slot_cannot_equip');
     foreach ($slot_cannot_equip as &$sce) {
         foreach ($sce as &$ce) {
             $ce = $slots[$ce];
         }
     }
     unset($sce, $ce);
     // Make sure the slot avoids pieces with certain stats
     $stat_ids_to_avoid = Stat::get_ids(Stat::avoid($job->en_abbr->term));
     $stat_ids_to_focus = Stat::get_ids(Stat::focus($job->en_abbr->term));
     $boring_stat_ids = Stat::get_ids(Stat::boring());
     $advanced_stat_avoidance = Stat::advanced_avoidance($job->en_abbr->term);
     foreach ($advanced_stat_avoidance as &$ava) {
         // These are in a very specific order.
         // Keep that order in tact.
         list($a, $b) = explode(' w/o ', $ava);
         $ava[0] = Stat::get_ids(array($a))[0];
         $ava[1] = Stat::get_ids(array($b))[0];
     }
     unset($ava);
     // Get all items where:
     // Slot isn't zero
     // It's between the level & level - 10
     // The class can use it
     // craftable only?
     // rewardable?
     foreach ($slots as $slot_identifier => $slot_name) {
         $query = Item::with('name', 'baseparam', 'baseparam.name', 'vendors', 'recipe', 'recipe.classjob', 'recipe.classjob.name')->where('slot', $slot_identifier)->whereBetween('equip_level', array($level - 10, $level + $range))->whereHas('classjob', function ($query) use($job_id) {
             $query->where('classjob.id', $job_id);
         })->whereHas('baseparam', function ($query) use($stat_ids_to_focus) {
             $query->whereIn('baseparam.id', $stat_ids_to_focus);
         })->orderBy('items.equip_level', 'DESC')->orderBy('items.level', 'DESC')->limit(20);
         if ($craftable_only && $rewardable_too) {
             $query->where(function ($query) {
                 $query->whereHas('recipe', function ($query) {
                     $query->where('recipes.item_id', DB::raw('items.id'));
                 })->orWhere('items.achievable', '1')->orWhere('items.rewarded', '1');
             });
         } elseif ($craftable_only) {
             $query->whereHas('recipe', function ($query) {
                 $query->where('recipes.item_id', DB::raw('items.id'));
             });
         }
         $items = $query->remember(Config::get('site.cache_length'))->get();
         $slot = isset($slot_alias[$slot_identifier]) ? $slot_alias[$slot_identifier] : $slot_identifier;
         $role = $slots[$slot];
         foreach ($items as $item) {
             // Kick it to the curb because of attributes?
             // Compare the focused vs the avoids
             $focus = $avoid = 0;
             $param_count = array_fill(1, 100, 0);
             // 73 total stats, 100's pretty safe, not to mention we only really focus on the first dozen
             foreach ($item->baseparam as $param) {
                 $param_count[$param->id]++;
                 if (in_array($param->id, $stat_ids_to_avoid)) {
                     $avoid++;
                 } elseif (in_array($param->id, $stat_ids_to_focus)) {
                     $focus++;
                 }
             }
             if ($advanced_stat_avoidance) {
                 foreach ($advanced_stat_avoidance as $ava) {
                     // If the [0] stat exists, but the [1] stat doesn't, drop the piece completely
                     if ($param_count[$ava[0]] > 0 && $param_count[$ava[1]] == 0) {
                         $avoid += 10;
                     }
                 }
             }
             // Really sell that this should be avoided
             # echo '<strong>' . $item->name->term . ' [' . $item->id . ']</strong> for ' . $role . ' (' . $focus . ',' . $avoid . ')<br>';
             if ($avoid >= $focus || $focus == 0) {
                 continue;
             }
             // if ($item->name->term == 'Linen Cowl')
             // 	dd($item->name->term, $item->slot, $slot, $slot_cannot_equip, $slot_cannot_equip[$item->slot]);
             // Cannot equip attribute?
             if (isset($slot_cannot_equip[$item->slot])) {
                 $item->cannot_equip = implode(',', $slot_cannot_equip[$item->slot]);
             }
             $equipment_list[$role][] = $item;
             # echo '<strong>+ ' . $item->name->term . ' [' . $item->id . ']</strong> for ' . $role . '<br>';
         }
         unset($items);
     }
     $two_handed_weapon_ids = ItemUICategory::two_handed_weapon_ids();
     $leveled_equipment = array();
     // We now have a proper list, but now we need to widdle down further by ilvl
     foreach (range($level, $level + $range) as $l) {
         $leveled_equipment[$l] = array();
         foreach ($equipment_list as $role => $items) {
             $leveled_equipment[$l][$role] = array();
             $max_equip_level = 0;
             // Find max
             foreach ($items as $item) {
                 if ($item->equip_level <= $l && $item->equip_level > $max_equip_level) {
                     $max_equip_level = $item->equip_level;
                 }
             }
             // Drop lesser items
             // OR figure out cannot equip stuff for weapons
             foreach ($items as $key => $item) {
                 if ($item->equip_level == $max_equip_level) {
                     if (empty($item->cannot_equip) && in_array($item->itemuicategory_id, $two_handed_weapon_ids)) {
                         $item->cannot_equip = 'Off Hand';
                     }
                     //$item->cannot_equip = array_flip(Config::get('site.defined_slots'))['Off Hand'];
                     if (!isset($leveled_equipment[$l][$role][$item->level])) {
                         $leveled_equipment[$l][$role][$item->level] = array();
                     }
                     $leveled_equipment[$l][$role][$item->level][] = $item;
                 }
             }
             // Place highest ilvl first
             krsort($leveled_equipment[$l][$role]);
             // Re-key the list for good measure
             //$items = array_values($items);
             //$leveled_equipment[$l][$role] = $items;
         }
     }
     // We should mostly have a list of just single items now
     // Cache the results
     Cache::put($cache_key, $leveled_equipment, Config::get('site.cache_length'));
     return $leveled_equipment;
 }