/** * @param \Onyx\Destiny\Objects\Hash $hash * @param string $index * @return bool */ public static function saveImageLocally($hash, $index = 'extra') { // BUG: Can't use variable object indexes implicitly // $hash->{$index} should work but doesn't // map the index explicitly with the attributes dumped into $bug $bug = $hash->getAttributes(); $url = "https://bungie.net" . $bug[$index]; $name = $index != 'extra' ? '_bg' : null; $name = $hash->hash . $name; // Make sure we aren't trying to save something that isn't an image // We only need this check because we cheat and store all hash related objects // in one table. This means we have crazy cheats to get things done. if (strlen($bug[$index]) < 5) { return false; } $location = public_path('uploads/thumbs/'); $filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION); if (File::isFile($location . $filename)) { return true; } if ($hash instanceof Hash) { $manager = new ImageManager(); try { $img = $manager->make($url); $img->save($location . $filename); } catch (NotReadableException $e) { Log::error('Could not download: ' . $url); } return true; } }
public function setEmblemAttribute($value) { $hash = Hash::where('extra', $value)->first(); if ($hash instanceof Hash) { $this->setAttributePullImage('emblem', $hash->hash); } }
/** * @param array $data Array of Definitions * @param string $index Index for this iteration * @param string $hash Index for hash of item * @param string $title Index for title of item * @param string $desc Index for description of item * @param null $extra Index for anything extra (optional) * @param null $secondary Index for anything secondary extra (optional) * @param null $third Index for a third extra field (optional) * @return bool */ private static function loadDefinitions(&$data, $index, $hash, $title, $desc, $extra = null, $secondary = null, $third = null) { if (isset($data[$index])) { foreach ($data[$index] as $item) { if (($mHash = Hash::where('hash', $item[$hash])->first()) == null) { $mHash = new Hash(); } // There are some records in the Hash response that have "FIELD_HIDDEN" // Probably from a future DLC, but we can't decode these. So skip em. if (!isset($item[$title])) { continue; } $mHash->hash = $item[$hash]; $mHash->title = $item[$title]; $mHash->description = isset($item[$desc]) ? $item[$desc] : null; $mHash->extra = $extra != null ? $item[$extra] : null; if ($secondary != null) { $mHash->extraSecondary = isset($item[$secondary]) ? $item[$secondary] : null; } if ($third != null) { $mHash->extraThird = isset($item[$third]) ? $item[$third] : null; } $mHash->save(); } } return false; }
/** * Reverse the migrations. * * @return void */ public function down() { Hash::where('hash', '9999999999')->delete(); }
private function getItems() { Hashes::$items = Hash::all(); return Hashes::$items; }