/** * Creates or updates a character * @param array $data Array of fields. * @return null|integer Returns the character id on success or null. */ public static function CreateOrUpdate($data) { $char = ['name' => $data['name'], 'class' => $data['class'], 'diablo_id' => $data['id'], 'level' => $data['level'], 'hardcore' => $data['hardcore'] == "true", 'season' => $data['seasonal'] == "true", 'owner_id' => $data['owner_id']]; /* Check if character already exists */ try { $character = Character::where('diablo_id', $char['diablo_id'])->firstOrFail(); /* Character Exists - Update */ foreach ($char as $key => $val) { $character->{$key} = $val; } $character->save(); return $character->id; } catch (ModelNotFoundException $e) { /* Does not exist - Add */ Character::create($char); /* Return the created characters id */ try { $character = Character::where('diablo_id', $char['diablo_id'])->firstOrFail(); return $character->id; } catch (Exception $e) { return null; } } catch (Exception $e) { \Log::error($e->getMessage()); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $characters = Character::all(); foreach ($characters as $char) { $member = $char->member; $command = new CharacterUpdate($char, $member); $command->handle(); } }
public function deleteCharacter($id) { try { $character = Character::where('id', $id)->firstOrFail(); } catch (\Exception $e) { return response('Bad Request.', 400); } /* Is Admin? or Character Owner */ $user = Auth::user(); if ($user->isAdmin() || $user->id == $character->member->id) { $character->delete(); } }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $data = ['sitename' => \Config::get('diablo.sitename')]; $characters = Character::all(); if (count($characters) === 0) { return view('welcome', $data); } else { $data['characters'] = Character::with('member', 'stats')->get(); $data['ClassHelper'] = new CharacterClass(); return view('home', $data); //return view('index', $data); } }
/** * Execute the command. * * @return void */ public function handle() { $api = new Api(); $member = $this->member; $data = $api->getProfileInfo($member->battletag); /* Update member paragon levels */ $member->paragon = $data['paragonLevel']; $member->paragon_hc = $data['paragonLevelHardcore']; $member->paragon_curr_season = $data['paragonLevelSeason']; $member->paragon_curr_season_hc = $data['paragonLevelSeasonHardcore']; $member->save(); /* Update members characters */ $characters = $data['heroes']; $charClass = new CharacterClass(); foreach ($characters as $char) { $char['class'] = $charClass->getClassId($char['class']); $char['owner_id'] = $member->id; $char_id = Character::CreateOrUpdate($char); /* Also create a stats entry so that we can use eager loading (join) - without losing characters */ $data = ['character_id' => $char_id]; CharacterStats::CreateOrUpdate($data); } }
/** * Character Listing * @return \Illuminate\View\View */ public function characters() { $data = ['user' => Auth::user(), 'sitename' => \Config::get('diablo.sitename'), 'fields' => ['name' => ['type' => 'text', 'min' => 2, 'max' => 30], 'battletag' => ['type' => 'text', 'min' => 4, 'max' => 20]], 'endpoint' => \URL::route('member.post'), 'container' => 'memberForm', 'success' => "location.reload();", 'button' => 'addMember', 'title' => 'Add Member', 'characters' => Character::with('member')->get()]; return view('admin/characters/index', $data); }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { $data = ['sitename' => \Config::get('diablo.sitename'), 'characters' => Character::with('member', 'stats')->get(), 'user' => Auth::user(), 'ClassHelper' => new CharacterClass()]; return view('home', $data); }