/** * 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); }