/** * Get the current term. * * This method returns the instance that represents the current term by * calculating the season based on the current date. It then uses that * calculation to find the stored instance. * * @Get("/current_term") * @Response(200, body={"id": 1, "name": "Fall", "year": "2015"}) */ public function current_term() { $timezone = new \DateTimeZone('America/New_York'); $date = (new \DateTime('now', $timezone))->format('Y-m-d'); $term = Term::where('start_date', '<=', $date)->where('end_date', '>=', $date)->first(); return response()->json($term); }
<option value="{{ $city->city_name }}">{{ $city->city_name }}</option> @endforeach </select> </div> </div> <div class="clearfix"></div> <div class="form-group"> <div class="col-sm-6"> <label class="control-label" for="owner_name">Category</label> <select name="category" class="form-control" placeholder=""> <?php $categories = \App\Term::where('type', 'property_category')->get(); ?> @foreach($categories as $category) <option value="{{ $category->id }}">{{ $category->name }}</option> @endforeach </select> </div> </div> <div class="form-group map"> <div class="col-sm-12"> <label class="control-label" for="sell_note">Comment</label> <textarea name="sell_note" class="form-control" rows="5" placeholder="" style="margin-bottom: 30px;"></textarea> </div> </div>
public function drop_term($id, Request $request) { if (!Auth::user()) { return redirect('/'); } try { Term::where('id', '=', $id)->delete(); } catch (\exception $e) { $rules = ['delete' => 'required']; $messages = ['delete.required' => 'წაშლა შეუძლებელია']; $this->validate($request, $rules, $messages); } return redirect('/admin'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(InterestRequest $request, $username) { $interests = $request->except('_method'); $user = MecanexUser::where('username', $username)->get()->first(); if (empty($user)) { $response = ["error" => "User doesn`t exist"]; $statusCode = 404; } elseif (count($user->interest) == 0) { $response = ["message" => "User has not set any interests, To create interests, try store"]; $statusCode = 404; } else { //check if what sends is correct or else it crushes //updates interests and user scores $key_values = array(); foreach ($interests as $key => $value) { $interest = Interest::where('short_name', $key)->get(array('id'))->first(); $key_values[$interest->id] = $value; $user->interest()->sync([$interest->id => ['interest_score' => $value]], false); $term = Term::where('term', $key)->firstOrFail(); $value = $value / 5; $user->term()->sync([$term->id => ['user_score' => $value]], false); } //there must be a more clever way to do this (foreach maybe) //created 2 arrays one with the term ids ($term_ids) and the other with the scores ($term_scores) $terms = Term::get(array('id')); $all_terms = []; foreach ($terms as $term) { array_push($all_terms, $term->id); } $all_terms_length = count($all_terms); ksort($key_values); $term_ids = array_keys($key_values); $term_ids_length = count($term_ids); //update adjacency matrix for ($i = 0; $i <= $term_ids_length - 1; $i++) { for ($j = 0; $j <= $all_terms_length - 1; $j++) { if ($term_ids[$i] == $all_terms[$j]) { continue; } elseif ($term_ids[$i] > $all_terms[$j]) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $all_terms[$j])->where('term_neighbor_id', $term_ids[$i])->get()->first(); $temp_user = $user->term->find($all_terms[$j]); $user_term_score_a = $temp_user->pivot->user_score; $temp_user = $user->term->find($term_ids[$i]); $user_term_score_b = $temp_user->pivot->user_score; $new_score = $user_term_score_b * $user_term_score_a; // } } else { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $term_ids[$i])->where('term_neighbor_id', $all_terms[$j])->get()->first(); $temp_user = $user->term->find($all_terms[$j]); $user_term_score_a = $temp_user->pivot->user_score; $temp_user = $user->term->find($term_ids[$i]); $user_term_score_b = $temp_user->pivot->user_score; $new_score = $user_term_score_b * $user_term_score_a; } $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } //update profile for ($j = 1; $j <= $all_terms_length; $j++) { $profile_score = 0; for ($i = 1; $i <= $all_terms_length; $i++) { $temp_user = $user->term->find($i); $user_term_score = $temp_user->pivot->user_score; //get score of user if ($i == $j) { $link_score = 0; } elseif ($i > $j) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first(); $link_score = $temp_user_matrix->link_score; } else { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first(); $link_score = $temp_user_matrix->link_score; } $profile_score = $profile_score + $user_term_score * $link_score; } $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false); } $response = ["message" => "User Interests were saved"]; $statusCode = 201; } return response($response, $statusCode)->header('Content-Type', 'application/json'); }
<m-input select class="m-input-wrapper w50-6"> <select name="status"> <option value="1" {{ $property->status == 1 ? 'selected' : '' }}>available</option> <option value="0" {{ $property->status == 0 ? 'selected' : '' }}>unavailable</option> <option value="-1" {{ $property->status == -1 ? 'selected' : '' }}>hidden</option> </select> <label for="title">status</label> </m-input> </div> <div class="m-input-group fwidth flexbox flexbox-wrap"> <?php $exist_tags = $property->tags->lists('id')->toArray(); ?> <?php $tags = \App\Term::where('type', 'property_tag')->get(); ?> @foreach($tags as $tag) <m-checkbox data-label="{{ $tag->name }}" w25-9> <input type="checkbox" value="{{ $tag->id }}" name="tag[]" {{ in_array($tag->id, $exist_tags) ? 'checked' : '' }}> <lever></lever> </m-checkbox> @endforeach </div> <div class="m-input-group textarea fwidth flexbox flexbox-wrap"> <h3 class="input-group-title">Property Description</h3> <div class="input-wrapper fwidth"> <textarea name="content" id="property-input-description" rows="10" style="padding-top: 0">{{ $property->localeEN()->content or '' }}</textarea> </div> </div>
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request) { // //get the input $arts = $request->arts; $disasters = $request->disasters; $education = $request->education; $environment = $request->environment; $health = $request->health; $lifestyle = $request->lifestyle; $media = $request->media; $holidays = $request->holidays; $politics = $request->politics; $religion = $request->religion; $society = $request->society; $transportation = $request->transportation; $wars = $request->wars; $work = $request->work; //delete all records of that user in pivot table $mecanex_user = Auth::user()->mecanex_user; $mecanex_user->interest()->detach(); //store input in pivot table $mecanex_user->interest()->sync([1 => ['interest_score' => $arts], 2 => ['interest_score' => $disasters], 3 => ['interest_score' => $education], 4 => ['interest_score' => $environment], 5 => ['interest_score' => $health], 6 => ['interest_score' => $lifestyle], 7 => ['interest_score' => $media], 8 => ['interest_score' => $holidays], 9 => ['interest_score' => $politics], 10 => ['interest_score' => $religion], 11 => ['interest_score' => $society], 12 => ['interest_score' => $transportation], 13 => ['interest_score' => $wars], 14 => ['interest_score' => $work]]); //$interests=Interest::all(array('short_name')); $user_interests = $mecanex_user->interest; $term_ids = []; foreach ($user_interests as $user_interest) { $short_name = $user_interest->short_name; array_push($term_ids, $user_interest->id); $term = Term::where('term', $short_name)->firstOrFail(); $mecanex_user->term()->sync([$term->id => ['user_score' => $user_interest->pivot->interest_score / 5]], false); //normalization } $terms = Term::all()->count(); for ($i = 0; $i <= $terms - 1; $i++) { for ($j = $i + 1; $j <= $terms - 1; $j++) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $mecanex_user->id)->where('term_home_id', $term_ids[$i])->where('term_neighbor_id', $term_ids[$j])->get()->first(); $temp_user = $mecanex_user->term->find($term_ids[$i]); $user_term_score_a = $temp_user->pivot->user_score; $temp_user = $mecanex_user->term->find($term_ids[$j]); $user_term_score_b = $temp_user->pivot->user_score; $new_score = $user_term_score_a * $user_term_score_b; $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } for ($j = 1; $j <= $terms; $j++) { $profile_score = 0; for ($i = 1; $i <= $terms; $i++) { $temp_user = $mecanex_user->term->find($i); $user_term_score = $temp_user->pivot->user_score; //get score of user if ($i == $j) { $link_score = 0; } elseif ($i > $j) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $mecanex_user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first(); $link_score = $temp_user_matrix->link_score; } else { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $mecanex_user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first(); $link_score = $temp_user_matrix->link_score; } $profile_score = $profile_score + $user_term_score * $link_score; } $mecanex_user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false); } return Redirect::route('home')->with('message', 'Your interests were updated'); }
public function post_categories(Request $request) { $categories = \App\Term::where('type', 'post_category')->get(); if ($request->action == 'create') { return view('admin.pages.post.category-create', compact('categories')); } if ($request->action == 'edit' && isset($request->id)) { $term = \App\Term::find($request->id); return view('admin.pages.post.category-edit', compact('term', 'categories')); } return view('admin.pages.post.category-listing'); }
public function search(Request $request, $page, $term = null) { $limit = 24; $properties = new Property(); $properties = $properties->select('properties.*'); // filter category if ($term != null) { $segment = explode('/', $term); $category = end($segment); $term = \App\Term::where('slug', $category); // not category abort if ($term->count() == 0) { return abort('404'); } // $segment = $properties = $properties->join('property_terms', 'property_terms.property_id', '=', 'properties.id')->join('terms', 'terms.id', '=', 'property_terms.term_id'); $term = $term->first(); // filter category $properties = $properties->where('terms.slug', $term->slug); // check child category if ($term->childs) { $properties = $properties->categoryChild($term->childs); } } $properties = $properties->paginate($limit); return view('pages.search-property', compact('properties', 'term')); }