public function concept()
 {
     $page = 'medicamentos-genericos';
     $websiteSettings = \App\Exceptions\Handler::readFile("websiteSettings.json");
     $pages = Pages::where('slug', '=', $page)->first();
     $texts = Concept::orderBy('sortorder', 'ASC')->get();
     return view('website.genericsMedications.concept')->with(compact('page', 'pages', 'websiteSettings', 'texts'));
 }
 public function delete(Request $request)
 {
     if (!ACL::hasPermission('concept', 'delete')) {
         return redirect(route('concept'))->withErrors(['Você não tem permissão para deletar.']);
     }
     Concept::find($request->get('conceptId'))->delete();
     $success = "Texto excluído com sucesso.";
     return redirect(route('concept'))->with(compact('success'));
 }
예제 #3
0
 public function getAssociationsForUser($concept_id, $player)
 {
     $concept = Concept::find($concept_id);
     $concept->load(['associations' => function ($query) use($player) {
         $query->where('user_id', $player->id);
     }]);
     $concept->load(['appreciations' => function ($query) use($player) {
         $query->where('user_id', $player->id);
     }]);
     foreach ($concept->associations as $association) {
         $association->load(['associated_concept.appreciations' => function ($query) use($player) {
             $query->where('user_id', $player->id);
         }]);
     }
     $concept->associations = $concept->associations->sortBy('weight');
     return $concept;
 }
예제 #4
0
 public function saveAssociations(Request $request)
 {
     $user = Auth::user();
     $domain_id = $request->input('domain_id');
     $inputs = $request->input('associations');
     $main_concept = Concept::find($inputs[0]['concept_id']);
     // Remove all existing associations for the concept and user
     Association::where('user_id', $user->id)->where('concept_id', $main_concept->id)->delete();
     $associations = array();
     foreach ($inputs as $association) {
         // Adding the entred concepts
         $concept = Concept::create($association['associated_concept']);
         // Adding the associations
         $associations[] = Association::create(['user_id' => $user->id, 'concept_id' => $association['concept_id'], 'weight' => $association['weight'], 'associated_concept_id' => $concept->id]);
         // Adding the appreciations if exists
         if (isset($association['associated_concept']['appreciations']) && isset($association['associated_concept']['appreciations'][0])) {
             Appreciation::create(['user_id' => $user->id, 'concept_id' => $concept->id, 'appreciation' => $association['associated_concept']['appreciations'][0]['appreciation']]);
         }
     }
     // Look if there is an open match
     $match = Match::where('concept_id', $main_concept->id)->where('user_id', '<>', $user->id)->whereNull('opponent_user_id')->get()->first();
     if ($match) {
         // if there is an open match then close it
         $match->opponent_user_id = $user->id;
         $match->save();
     } else {
         // if there is no open match then sorry :(
         // create a match
         if (!Match::where('concept_id', $main_concept->id)->where('user_id', $user->id)->whereNull('opponent_user_id')->get()->first()) {
             // if there is no open match by the same user for the same concept
             Match::create(['user_id' => $user->id, 'concept_id' => $main_concept->id]);
         }
         return Response::json(['flash' => 'No opponent found. your answers will be saved, and you will be notifed when an other player challenges them ;) .', 'nomatch' => true]);
     }
     // there is an open match!
     return Response::json(['match_id' => $match->id]);
 }