/** * @return string|null */ public function page() { switch ($this->page_type) { case 'area': $area = Area::find($this->page_id); return $area ? $area->name : null; case 'category': $category = Category::find($this->page_id); return $category ? $category->area->name . ' (' . $category->name . ') ' : null; } }
public function run() { DB::table('areas')->truncate(); DB::table('area_sponsor')->truncate(); $areas = [['county_id' => 26, 'publish' => 1, 'name' => 'Web backend', 'slug' => 'web-backend', 'cover' => 'cover.png', 'thumbnail' => 'back-end.png'], ['county_id' => 26, 'publish' => 1, 'name' => 'Web frontend', 'slug' => 'web-frontend', 'cover' => 'cover.png', 'thumbnail' => 'front-end.png'], ['county_id' => 26, 'publish' => 1, 'name' => 'Android', 'slug' => 'android', 'cover' => 'cover.png', 'thumbnail' => 'android.png'], ['county_id' => 26, 'publish' => 1, 'name' => 'iOS', 'slug' => 'ios', 'cover' => 'cover.png', 'thumbnail' => 'ios.png']]; $faker = Faker::create(); foreach ($areas as $area) { $area['content'] = $faker->text(1000); $area = Area::create($area); $area->sponsors()->attach([1, 2, 3]); } }
/** * Store a newly created resource in storage. * * @param int $areaId * @return Response */ public function store($areaId) { $area = Area::findOrFail($areaId); $input = Input::only('name', 'content', 'category_id', 'display_order', 'slug', 'available'); try { $this->createGroupForm->validate($input); } catch (FormValidationException $e) { return Redirect::back()->withInput()->withErrors($e->getErrors()); } $group = new Group(['name' => e($input['name']), 'content' => $input['content'], 'category_id' => $input['category_id'], 'display_order' => $input['display_order'] ?: 0, 'slug' => str_slug($input['slug'] ?: $input['name']), 'available' => $input['available'] ?: 0]); $area->groups()->save($group); flash("Grupa <b>{$group->name}</b> a fost adăugată cu success."); return Redirect::route('admin.areas.edit', $area->id); }
public function create($areaId, $groupId) { $area = Area::findOrFail($areaId); $group = Group::findOrFail($groupId); $query = Response::join('users', 'users.id', '=', 'response.user_id')->join('quiz', 'quiz.id', '=', 'response.quiz_id')->where('area_id', $areaId); if ($group->category_id) { $query->where('category_id', $group->category_id); } $users = $query->get(['full_name', 'users.id', 'email', 'phone', 'school', 'response.id as response_id']); $from = $group->category ? $group->category : $area; $groups = $from->groups()->lists('id'); foreach ($users as $key => $user) { if (DB::table('area_group_user')->whereIn('area_group_id', array_values($groups))->where('user_id', $user->id)->exists()) { $users->forget($key); } } return view('admin.groups.user', ['group' => Group::findOrFail($groupId), 'users' => $users]); }
/** * @return Response */ public function api() { $data = []; $groups = User::find($this->userId, ['id'])->trainerGroups()->get(['area_id', 'category_id', 'name']); foreach ($groups as $group) { $key = $group->area_id . ($group->category_id ? '_' . $group->category_id : ''); if (isset($data[$key])) { continue; } $area = Area::findOrFail($group->area_id, ['id', 'name']); $category = null; $query = Response::join('quiz', 'response.quiz_id', '=', 'quiz.id')->join('users', 'response.user_id', '=', 'users.id'); if ($group->category_id) { $category = Category::findOrFail($group->category_id, ['id', 'name']); $query->where('category_id', $category->id); } else { $query->where('area_id', $area->id); } $applicants = $query->get(['response.id', 'response.created_at', 'full_name', 'email', 'school']); foreach ($applicants as $key => $applicant) { $applicants[$key]->id = (int) $applicant->id; $response = Response::findOrFail($applicant->id); $choices = $applicant->trainerchoices()->lists('choice', 'trainer_id'); $choice = isset($choices[$this->userId]) ? (int) $choices[$this->userId] : null; if ($choice !== 1 && !is_null($choice)) { $applicants->forget($key); continue; } $responses = []; foreach ($response->questions as $rquestion) { if (!$rquestion->question) { continue; } $answers = []; $roptions = $rquestion->options->lists('response', 'quiz_question_option_id'); foreach ($rquestion->question->options as $option) { if (array_key_exists($option->id, $roptions)) { if ($rquestion->question->type == 'text' || $rquestion->question->type == 'textbox') { $answer = html_entity_decode($roptions[$option->id]); } else { $answer = true; } } else { $answer = false; } $answers[] = ['option' => $option->option ? html_entity_decode($option->option) : null, 'answer' => $answer]; } $responses[] = ['question' => $rquestion->question->question, 'question_type' => $rquestion->question->type, 'answers' => $answers]; } $applicant->responses = $responses; } $applicants->values(); $data[$key] = ['applicants' => $applicants, 'area' => $area, 'category' => $category]; } return json(array_values($data), 200); }
public function categories($areaId) { $area = Area::findOrFail($areaId); return json($area->categories); }
protected static function boot() { parent::boot(); Area::observe(new AreaObserver()); }
public function categoryList() { $areaTable = Area::getTableName(); $categoryTable = Category::getTableName(); return $this->entity->categories()->join($areaTable, "{$categoryTable}.area_id", '=', $areaTable . '.' . $this->entity->getKeyName())->get(["{$areaTable}.slug as area_slug", "{$categoryTable}.slug as slug", "{$categoryTable}.name as name"]); }
/** * List all areas on the homepage. * * @return \Response */ public function home() { $countyId = config('app.county'); $areas = Area::where('county_id', $countyId)->where('publish', 1)->orderBy('display_order')->get(['id', 'name', 'excerpt', 'slug', 'thumbnail', 'image']); return view('pages.home')->with('areas', $areas); }