public function performIntuitiveAssignment() { //Grab all the activities $activities = Activity::all(); //pr0duce a tally 0f h0w many succesful applicati0ns each activity has received, //in the f0rm 0f an ass0ciative array f0r th0se activities which have received //m0re than 0 applicati0ns $activityApplicationTally = array(); foreach ($activities as $activity) { //get a c0unt 0f the number 0f succesful applicants f0r this activity $numSuccesfulApplicants = $activity->getSuccessfulApplications->count(); if ($numSuccesfulApplicants > 0) { $activityApplicationTally[$activity->id] = $numSuccesfulApplicants; } } //fr0m http://www.w3schools.com/php/func_array_asort.asp asort($activityApplicationTally, SORT_NUMERIC); foreach ($activityApplicationTally as $activityID => $numSuccesfulApplicants) { $numTutorsRequired = Activity::find($activityID)->quant_ppl_needed; echo $numTutorsRequired; //var_dump($activity); } //return $activityApplicationTally; //return Activity::with('activityRequests'); }
public function update($id, Request $request) { if ($this->inputIsValid($request)) { $agenda = Agenda::findOrFail($id); $agenda->update($request->except('attendees', 'activities')); // Remove all old attendees. $agenda->users()->detach(); // Add attendees to agenda_user table as many-to-many relationship. foreach ($request->input('attendees') as $attendeeId) { $agenda->users()->attach(1, ['agenda_id' => $agenda->id, 'user_id' => $attendeeId]); } // Remove this agenda_id from all its activities. foreach ($agenda->activities() as $activity) { $activity = Activity::find($activityId); $activity->agenda_id = 0; $activity->save(); } // Add agenda_id to a_activities table. foreach ($request->input('activities') as $activityId) { $activity = Activity::find($activityId); $activity->agenda_id = $agenda->id; $activity->save(); } return response()->json(['header' => 'Your agenda was successfully updated!', 'info' => 'Both your agenda here on Meeter and you Google Calendar event were updated with your changes.'], 200); } else { return response()->json('', 400); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $item = Activity::find($id); $item->status = 'deleted'; $item->save(); Log::create(array("user_id" => Auth::user()->id, "action" => "Delete Activities named " . $item->name)); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Requests\SpacificationEditRequesyt $request, $id) { $especificacion = Spacification::find($id); $especificacion->fill($request->all()); $especificacion->save(); $actividad = Activity::find($especificacion->activity_id); return response()->json(['valid', $especificacion, $actividad]); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\Prospect $request) { $activity = Activity::find($request->get('activity_id')); $prospect = new Prospect($request->all()); $activity->prospects()->save($prospect); if ($request->has('links')) { foreach ($request->get('links') as $link) { $type = LinkType::findOrFail($link['type_id']); $link = new Link(['url' => $link['url']]); $link->prospect()->associate($prospect); $link->type()->associate($type); $link->save(); } } return response()->json($prospect); }
public function performIntuitiveAssignment() { $activities = Activity::all(); //create an ass0ciative array representing the am0unt 0f succesful applicatins //there has been f0r each supp0rt activity, where the key is the activity's primary key //in the database, and the value is the number 0f succesful applicati0ns. $activityApplicationTally = array(); foreach ($activities as $activity) { //c0unt the number 0f succesful applicati0ns f0r the activity $numSuccesfulApplicants = $activity->getSuccessfulApplications->count(); //it is imp0ssible t0 intuitively assign phd students t0 the activity //if the activity has had n0 succesful applicants, theref0re 0nly activities //which have at least 1 succesful applicati0n will be added t0 the ass0ciative array if ($numSuccesfulApplicants > 0) { $activityApplicationTally[$activity->id] = $numSuccesfulApplicants; } } //fr0m http://www.w3schools.com/php/func_array_asort.asp //s0rt the ass0ciative array s0 that the activities with the fewest number 0f sucessful //applicants will be pr0cessed first. asort($activityApplicationTally, SORT_NUMERIC); //pr0cess the activties in the assci0ative array 1 by 1. $assignmentsMade = array(); //Ass0ciative array where key is the PHD student's ID in the database and //the value is the id 0f the activity t0 which they were assigned foreach ($activityApplicationTally as $activityID => $numSuccesfulApplicants) { $numTutorsRequired = Activity::find($activityID)->quant_ppl_needed; if ($numSuccesfulApplicants == $numTutorsRequired) { $activity = Activity::find($activityID); $successfulApplications = $activity->getSuccessfulApplications; //assign the succesful applicants t0 all sessi0ns f0r the activity foreach ($successfulApplications as $successfulApplication) { $phdStudent = User::find($successfulApplication->user_id); //line bel0w fr0m here https://laravel.com/docs/master/collections#method-pluck, why d0es this w0rk? $phdStudentSessions = $phdStudent->sessions()->attach($activity->sessions->pluck('id')->all()); $assignmentsMade[$phdStudent->name] = $activity->title; } } } //foreach($assignments as $assignment) { //var_dump($assignment); //} return view('intuitiveAssignmentResults')->with('assignmentsMade', $assignmentsMade); //var_dump( $assignments); //var_dump($phdStudentSessions); //return $phdStudentSessions; }
public function showActivityEventPlannerView() { $activitiesIds = session('activities'); $activities = []; foreach ($activitiesIds as $id) { array_push($activities, Activity::find($id)); } $eventPatternIds = session('eventPatterns'); $eventPatterns = []; foreach ($eventPatternIds as $id) { array_push($eventPatterns, EventPattern::find($id)); } $groupId = session('group'); $group = Group::find($groupId); $groups = Group::all(); $events2 = EventOccurrence::with('activities')->get(); $events = $events2->filter(function ($item) use($groupId) { return $item->group->id === $groupId; }); return view('ActivityPlanning/activityEventPlanner', compact('activities', 'eventPatterns', 'groups', 'group', 'events', 'groupId')); }
public function testManyActivitiesCanBeAddedToUsers() { factory(App\Group::class, 4)->create()->each(function ($g) { for ($i = 0; $i < 5; $i++) { $g->users()->save(factory(App\User::class)->make(), ['role' => 'member']); } $g->users()->save(factory(App\User::class)->make(), ['role' => 'leader']); }); factory(App\Activity::class, 5)->create(); $group = Group::find(1); $activity = Activity::find(1); $stuff = array('activityId' => $activity->id, 'group' => $group->id); foreach ($group->users as $user) { $stuff[$user->id] = 'true'; } $request = Request::create('/', 'POST', $stuff); $this->controller->addMany($request); foreach ($group->users as $user) { $this->seeInDatabase('activity_user', ['activity_id' => $activity->id, 'user_id' => $user->id]); } }
/** * Display the Guest attendance of the Activity. * * @param int $id * @return \Illuminate\Http\Response */ public function showGuestAttendance($id) { if (Gate::denies('show', Activity::class)) { abort(403); } $record = Activity::find($id); $data = array('title' => 'Activities', 'id' => $id, 'date_of_activity' => $record->date_of_activity, 'barangay' => $record->barangay, 'title_id' => $record->subtitle->title->title, 'subtitle_id' => $record->subtitle->subtitle, 'day_of_activity' => $record->day_of_activity, 'venue_of_activity' => $record->venue_of_activity, 'conducted_by' => $record->conducted_by, 'remarks' => $record->remarks); return view('activity.guestattendance')->with($data); }
public function recordActivity($event) { $model = strtolower(class_basename($this)); if ($event == "created") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; if ($model == "category") { $activity->old_value = $this->name; } elseif ($model == "information") { $activity->old_value = $this->value; } elseif ($model == "field") { $activity->old_value = $this->category_label; } elseif ($model == "devicelog") { $activity->old_value = $this->action; } elseif ($model == "owner") { $activity->old_value = $this->fullName(); } else { $activity->old_value = $this->name; } $activity->save(); } elseif ($event == "updates") { if ($model == "category") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->old_value = $this->name; $activity->new_value = Input::get('name'); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $this->name = Input::get('name'); $this->save(); } elseif ($model == "device") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->old_value = $this->name; $activity->new_value = Input::get('phone_number'); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $this->phone_number = Input::get('name'); $this->save(); } elseif ($model == "information") { foreach (Input::all() as $key => $value) { if (strpos($key, 'info') !== false) { $key = explode('-', $key); $info_id = $key[1]; $activity = new Activity(); $information = Information::find($info_id); $activity->subject_id = $information->id; $activity->subject_type = get_class($information); $activity->name = $information->getActivityName($information, $event); $activity->old_value = $information->value; $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $information->value = $value; $information->save(); $act = Activity::find($activity->id); $act->new_value = $information->value; $act->save(); } } } } elseif ($event == "deleted") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; if ($model == "field") { $activity->old_value = $this->category_label; } elseif ($model == "information") { $activity->old_value = $this->value; } else { $activity->old_value = $this->name; } $activity->save(); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { if ($id == null) { return null; } $activity = Activity::find($id); $activity->activityType()->detach(); $activity->user()->detach(); $activity->delete(); return response("success", 200); }
public function getA2Attribute($value) { return Activity::find($value); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $activity = Activity::find($id); $activity->delete(); return Redirect::to('activity'); }
/** * Handles the checking to prevent user from applying from activities from the same time period of another activity. * * @param \Illuminate\Http\Request $request * @return JSON array with Status */ public function checkActivityApplication(Request $request) { if ($request->get('volunteer_id') == null || $request->get('activity_id') == null) { $status = ["Missing parameter"]; return response()->json(compact('status')); } else { $userID = $request->get('volunteer_id'); $actID = $request->get('activity_id'); $withdrawnTask = Task::where('volunteer_id', $userID)->where('activity_id', $actID)->where('approval', '=', 'withdrawn')->lists('activity_id'); $applyingActivity = Activity::findOrFail($actID); if ($applyingActivity == null) { $status = ["do not exist"]; return response()->json(compact('status')); } else { $activityStartTime = $applyingActivity->datetime_start; $activityDuration = $applyingActivity->expected_duration_minutes; $activityEndTime = $applyingActivity->datetime_start->addMinutes($activityDuration); $activityFullDayStart = $applyingActivity->datetime_start->startOfDay()->toDateTimeString(); $activityFullDayEnd = $applyingActivity->datetime_start->endOfDay()->toDateTimeString(); $activitiesOnSameDay = Activity::whereBetween('datetime_start', [$activityFullDayStart, $activityFullDayEnd])->where('activity_id', '<>', $actID)->lists('activity_id'); $status = ['rejected']; $taskofUserOnSameDay = Task::where('volunteer_id', $userID)->whereIn('activity_id', $activitiesOnSameDay)->whereNotIn('approval', $status)->lists('activity_id'); $check = false; foreach ($taskofUserOnSameDay as $activityID) { $activity = Activity::find($activityID); $bStartTime = $activity->datetime_start; $bDuration = $activity->expected_duration_minutes; $bEndTime = $activity->datetime_start->addMinutes($bDuration); if ($activityStartTime->lte($bStartTime) && $bStartTime->lte($activityEndTime) && $activityEndTime->lte($bEndTime)) { $check = true; } if ($bStartTime->lte($activityStartTime) && $activityStartTime->lte($bEndTime) && $bEndTime->lte($activityEndTime)) { $check = true; } if ($activityStartTime->lte($bStartTime) && $bStartTime->lte($activityEndTime) && $bEndTime->lte($activityEndTime)) { $check = true; } if ($bStartTime->lte($activityStartTime) && $activityStartTime->lte($bEndTime) && $activityEndTime->lte($bEndTime)) { $check = true; } if ($activityStartTime->eq($bStartTime) && $activityEndTime->eq($bEndTime)) { $check = true; } } if (!$check) { $status = ["do not exist"]; return response()->json(compact('status')); } else { $status = ["exist"]; return response()->json(compact('status')); } } } }
public function postDel(Request $request, $activity_id) { $res = ['response' => 'YES', 'status' => 0]; $activity = Activity::findOrFail($activity_id); $img = $activity->Img_icon()->first(); if ($img) { $img->update(['img_active' => $img->img_active - 1 >= 0 ? $img->img_active - 1 : 0]); } $img = $activity->Img_bg()->first(); if ($img) { $img->update(['img_active' => $img->img_active - 1 >= 0 ? $img->img_active - 1 : 0]); } $activity->delete(); if (!Activity::find($activity_id)) { $res['status'] = 1; } else { $res['msgError'] = '出错了...'; } return response()->json($res); }
public function getDoDelete($activity_id) { # Get the activity to be deleted $activity = \App\Activity::find($activity_id); if (is_null($activity)) { \Session::flash('flash_message', 'Activity not found.'); return redirect('/activities/show'); } # Delete the row in activity-schedule pivot if ($activity->schedules()) { $activity->schedules()->detach(); } # Then delete the activity after the days of week $activity->activities_dow()->delete(); $activity->delete(); # Done \Session::flash('flash_message', $activity->name . ' was deleted.'); return redirect('/activities/show'); }
public function destroy($id) { $activity = Activity::find($id); $activity->delete(); $nil = Nil::where('activity_id', '=', $id)->get(); if ($nil->count() > 0) { $nil->pop()->delete(); } $maintenance = Maintenance::where('activity_id', '=', $id)->get(); if ($maintenance->count() > 0) { $maintenance->pop()->delete(); } $onday = Onday::where('activity_id', '=', $id)->get(); if ($onday->count() > 0) { $onday->pop()->delete(); } return redirect()->back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $actividad = Activity::find($id); $actividad->delete(); return response()->json($actividad); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // $v = Validator::make(Request::all(), ['activity' => 'required|max:50', 'desc' => 'required|max:100']); if ($v->fails()) { return redirect()->back()->withErrors($v->errors())->withInput(); } else { $id = Request::get('id'); $activity = Activity::find($id); $activity->activity = Request::get('activity'); $activity->desc = Request::get('desc'); $activity->save(); return redirect('activities'); } }