public function addTask() { if ($_POST) { if (Request::has('id')) { $outcome = Outcome::find(Request::get('outcomeid')); if (Request::has('add')) { $outcome->addTask(Request::get('id')); } if (Request::has('remove')) { $outcome->removeTask(Request::get('id')); } if (Request::has('up')) { $outcome->moveTaskUp(Request::get('id')); } if (Request::has('down')) { $outcome->moveTaskDown(Request::get('id')); } if (Request::has('markfinal')) { $outcome->addFinalTask(Request::get('id')); } if (Request::has('removefinal')) { $outcome->finalTask()->delete(array('task_id' => Request::get('id'))); } return Redirect::to('outcome/addtask')->with('addtask_outcome', serialize($outcome)); } } // This is where we will add task/s to outcome $outcome = unserialize(Session::get('addtask_outcome')); if (is_null($outcome) || !isset($outcome->id)) { return Redirect::to('/outcomes'); } $this->layout->content = View::make('outcome.addtask')->with('outcome', $outcome); }
public function fetchPostByID() { $user = Auth::user(); $input = Input::all(); // search for post by ID //$searchForPost = DB::table('posts')->where('id', $input['postid'])->get(); $post = Post::where('id', $input['postid'])->take(1)->get(); //$jsonOut = json_decode($searchForPost[0]->status); $post->status = $post[0]->filterStatus(); $post->image = ($post[0]->statustype = 'image') ? $post[0]->displayMediaApi() : ''; ////////// if ($post->image != '') { $doc = new DOMDocument(); $doc->loadHTML($post->image); $xpath = new DOMXPath($doc); $src = $xpath->evaluate("string(//img/@src)"); $post->image = $src; } ///////// //$post->mission_completed = true; //print_r(); // set display mission if ($post[0]->display_mission == 1) { $post->display_mission = true; } // get the groupid $groupid = GroupUser::where('user_id', '=', $user['id'])->pluck('group_id'); // get the taskid $taskid = $post[0]->task_id; // get the outcome id $group = Group::find($groupid); $outcomeid = Outcome::find($group->outcome)->id; // execute query $userTaskArray = DB::table('user_tasks')->where('outcome_id', $outcomeid)->where('user_id', $user['id'])->where('group_id', $groupid)->where('task_id', $taskid)->where('complete', 1)->get(); //print_r(count($userTaskArray)); if (count($userTaskArray) > 0) { $post->mission_completed = true; $post->general = false; } else { $post->mission_completed = false; $post->general = true; } return json_encode($post); }
/** * This function will be called from the dice page. It will accept the * task that the user has agreed to and will send that to the database */ public function acceptTask() { if (!$_POST) { App::abort(404); } $user = User::find(Input::get('userid')); $group = Group::find(Input::get('groupid')); $outcome = Outcome::find($group->outcome); $task = Task::find(Input::get('taskid')); // TODO: Check if the record already exists in the DB DB::table('user_tasks')->insert(array('user_id' => $user->id, 'group_id' => $group->id, 'outcome_id' => $outcome->id, 'task_id' => $task->id, 'created_at' => new DateTime(), 'updated_at' => new DateTime())); return Redirect::action('PlayController@showStatusPage', array('id' => $group->id)); }
<?php /* * Let's just first assume that a user will onely have one group * with one and only one outcome */ /** * These are the variables that have been supplied in the request */ $groupid = Request::get('groupid') ?: 1; $userid = Request::get('userid') ?: 1; $group = Group::find($groupid); $outcome = Outcome::find($group->outcome); $availArray = array_fetch($outcome->tasks->toArray(), 'id'); $currentDay = round((time() - $group->timestart) / 86400, 0); $doneArray = array(); $doneArray = DB::table('user_tasks')->where('group_id', $groupid)->where('user_id', $userid)->where('complete', 1)->lists('task_id'); $doneArray[] = $outcome->getFinalTask(); $array = array_diff($availArray, $doneArray); if (empty($array)) { if ($currentDay >= 21) { $array[20] = $outcome->getFinalTask(); } else { $array = $availArray; } } elseif ($currentDay >= 21) { $array = array(); $array[20] = $outcome->getFinalTask(); } echo '<pre>'; print_r($array);
public function getNextTask() { // Get the current user $user = Auth::user(); // Get the group that the user belongs to $group = $user->getGroup(); // Get the outcome from group $outcome = Outcome::find($group->outcome); // Now get the remaining task/s for this user in the specified group $tasks = $user->getRemainingTasks(); }