/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { $currentuser = Auth::user(); $options = Option::where('module', 'main')->get(); $name = $options->where('option', 'name')->first()->value; $tagline = $options->where('option', 'tagline')->first()->value; $modules = Module::orderBy('status', 'desc')->get(); $navigation = Navigation::where('menu', 'admin')->get(); $view->with('currentuser', $currentuser)->with('name', $name)->with('tagline', $tagline)->with('modules', $modules)->with('navigation', $navigation); }
public static function setOption($name, $value) { if (is_array($value)) { $value = json_encode($value); } if (Option::where('name', $name)->update(['value' => $value, 'updated_at' => current_time()])) { return true; } else { return false; } }
public function saveFromNested($test) { // Clear already existing questions for this particular test. Question::where('test_id', $test['id'])->delete(); foreach ($test['questions'] as $question) { $savedQuestion = Question::create(['test_id' => $test['id'], 'title' => $question['title'], 'correct' => $question['correct']]); // Clear already existing options for this particular question. Option::where('question_id', $savedQuestion['id'])->delete(); foreach ($question['options'] as $i => $option) { Option::create(['question_id' => $savedQuestion->id, 'value' => $option]); } } }
public function set($module, $name, $value) { $option = Option::where('module', $module)->where('option', $name)->first(); if ($option != null) { $option->value = $value; $option->save(); } else { $option = new Option(); $option->module = $module; $option->option = $name; $option->value = $value; $option->save(); } }
public function setStatus($value) { $status = Option::where('option', 'status')->first(); $status->set('main', 'status', $value); $status->save(); }
/** * This very important method determines the compiled configuration for a board. * It does this by taking extant board Options and then laying on top Board Settings. * Anything null defaults, anything with a value takes that place. * * @param string $option_name If null, returns compiled config. * @param mixed $fallback If not null, returns itself if there is nothing defined. * @return mixed */ public function getConfig($option_name = null, $fallback = null) { $config =& static::$config[$this->board_uri]; if (!is_array($config)) { $config = []; // Available options + defaults $options = Option::where('option_type', "board")->get(); // Defined settings $settings = $this->settings; foreach ($options as $option) { $option->option_value = $option->default_value; $config[$option->option_name] = $option; foreach ($settings as $setting) { if ($setting->option_name === $option->option_name) { $setting->data_type = $option->data_type; $option->option_value = $setting->option_value; break; } } } } if (!is_null($option_name)) { foreach ($config as $setting) { if ($setting->option_name == $option_name) { $value = $setting->getDisplayValue(); if (is_null($value) || $value == "") { return $fallback; } return $value; } } } else { return $config; } return $fallback; }
/** * Make Combinations for specified resource. * * @param int $id * @return Response */ public function combine($id, Request $request) { $groups = $request->input('groups'); // Validate: $groups ahold not be empty, and values should match options table // http://laravel.io/forum/11-12-2014-how-to-validate-array-input // https://www.google.es/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8&client=ubuntu#q=laravel%20validate%20array%20input $product = $this->product->findOrFail($id); // Start Combinator machime! $data = array(); foreach ($groups as $group) { $data[] = \App\Option::where('option_group_id', '=', $group)->orderby('position', 'asc')->lists('id'); } $combos = combos($data); foreach ($combos as $combo) { $combination = \App\Combination::create(array()); $product->combinations()->save($combination); $combination->options()->attach($combo); } // ToDo: Combinations are created with stock = 0. So, set main product stock = 0 too! // El stock del producto principal es la suma de los stocks de las combinaciones! return redirect('products')->with('success', l('This record has been successfully combined :: (:id) ', ['id' => $id], 'layouts')); }
/** * @param $input * @param $FISArray * @param $USSAArray * * @return string * * Saves race, points, and racer when called. Returns string with status of save */ public function SaveRace($input, $FISArray, $USSAArray) { /* * Check to see if race already exists in the database. If it does set the saveStatus */ //Set Variables for the options $season = Option::where('option_name', '=', 'season')->first()->value; $USSA_list = Option::where('option_name', '=', 'USSA_list')->first()->value; $FIS_list = Option::where('option_name', '=', 'FIS_list')->first()->value; //Save location to database $saveLocation = new racelocation(); $latitude = round($input['hidden-lat'], 3); $longitude = round($input['hidden-long'], 3); //Check for location already existing $checkForLocation = $saveLocation->where('latitude', '=', $latitude)->where('longitude', '=', $longitude)->first(); if ($checkForLocation == null) { $saveLocation->location_name = $input['race-location']; $saveLocation->latitude = $latitude; $saveLocation->longitude = $longitude; $saveLocation->save(); $locationID = $saveLocation->location_id; } else { $locationID = $checkForLocation->location_id; } //Save race to datbase $saveRace = new savedrace(); $saveRace->status = 'not approved'; $saveRace->race_name = $input['race-name']; $saveRace->gender = $input['gender']; $saveRace->clicks = 0; $saveRace->USSA_list = $season . " " . $USSA_list; $saveRace->FIS_list = $season . " " . $FIS_list; $saveRace->distance = $input['distance']; $saveRace->format = $input['format']; $saveRace->winners_time = $input['winners-time']; $saveRace->technique = $input['technique']; $saveRace->distance_km = $input['distance-km']; $saveRace->savedLocation()->associate($locationID); $saveRace->save(); //Hold race that was just saved in a variable $savedRace = savedrace::where('savedrace_id', '=', $saveRace->savedrace_id)->first(); //Loop through racers and save them to the database $savedRacers = []; $iter = 1; foreach ($FISArray['Racers'] as $racer) { //Check to see if the racer already exists in our database $checkForSavedRacer = savedracer::where('last', 'LIKE', '%' . trim($racer['LastName']) . '%')->where('first', 'LIKE', '%' . trim($racer['FirstName']) . '%')->first(); if ($checkForSavedRacer != NULL) { $savedRacers[$iter] = $checkForSavedRacer; } else { $saveRacer = new savedracer(); $saveRacer->last = $racer['LastName']; $saveRacer->first = $racer['FirstName']; $saveRacer->save(); $savedRacers[$iter] = savedracer::where('savedracer_id', '=', $saveRacer->id)->first(); } $iter++; } //Loop through and save all the points from the race for ($i = 1; $i < 6; $i++) { $savePoints = new savedpoint(); $savePoints->place = $i; $savePoints->USSA_points = $USSAArray['Racers'][$i - 1]['Points']; $savePoints->FIS_points = $FISArray['Racers'][$i - 1]['Points']; if (array_key_exists('Note', $USSAArray['Racers'][$i - 1])) { $savePoints->USSA_note = $USSAArray['Racers'][$i - 1]['Note']; } else { $savePoints->USSA_note = null; } if (array_key_exists('Note', $FISArray['Racers'][$i - 1])) { $savePoints->FIS_note = $FISArray['Racers'][$i - 1]['Note']; } else { $savePoints->FIS_note = null; } //Associate race and racer with the points $savePoints->savedrace()->associate($savedRace); $savePoints->savedracer()->associate($savedRacers[$i]); $savePoints->save(); } $saveStatus = 'Race Successfully Saved, Waiting To Be Approved By Admin'; mail('*****@*****.**', 'Race Waiting to be approved', $input['race-name']); return $saveStatus; }
/** * Get an user option by 'id' or 'name', * Fallback to default if user does not have such option. * * @param string * * @return string * * @thows Illuminate\Database\Eloquent\ModelNotFoundException */ public function getOption($option) { if ($userOption = $this->options()->where('options.id', $option)->orWhere('options.name', $option)->first()) { return $userOption->pivot->value; } return Option::where('id', $option)->orWhere('name', $option)->firstOrFail()->value; }