コード例 #1
0
ファイル: GoalController.php プロジェクト: naneri/goalkeeper
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $data['user_id'] = Auth::id();
     Goal::create($data);
     return redirect('goal/create');
 }
コード例 #2
0
ファイル: GoalSeeder.php プロジェクト: Cheddam/health
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $categories = [['name' => 'The Basics', 'weight' => 1], ['name' => 'Bonus Points', 'weight' => 2]];
     $goals = [['name' => 'Slept 6-8 hours last night', 'points' => 10, 'weight' => 1, 'category_id' => 1], ['name' => 'Exercised for at least 30 mins', 'points' => 10, 'weight' => 2, 'category_id' => 1], ['name' => 'Drank at least 4 glasses of water', 'points' => 10, 'weight' => 3, 'category_id' => 1], ['name' => 'Ate a healthy lunch', 'points' => 10, 'weight' => 4, 'category_id' => 1], ['name' => 'Purposeful exercise (run, gym, etc.)', 'points' => 15, 'weight' => 1, 'category_id' => 2], ['name' => 'Ate home-cooked dinner', 'points' => 15, 'weight' => 2, 'category_id' => 2], ['name' => 'Avoided caffeine', 'points' => 15, 'weight' => 3, 'category_id' => 2], ['name' => 'Avoided refined sugar (treats)', 'points' => 15, 'weight' => 4, 'category_id' => 2], ['name' => 'Took 2 or more breaks from screen', 'points' => 15, 'weight' => 5, 'category_id' => 2]];
     foreach ($categories as $cat) {
         Category::create($cat);
     }
     foreach ($goals as $goal) {
         Goal::create($goal);
     }
 }
コード例 #3
0
 public function addGoal(Request $request, Plan $plan)
 {
     if (isset($request->add)) {
         $newgoal = Goal::create($request->all());
         $newgoal->plan_id = $plan->id;
         $newgoal->save();
         return view('plans.addgoals')->with('plan', $plan);
     } else {
         return view('plans.addobjectives')->with('plan', $plan);
     }
 }
コード例 #4
0
 public function store()
 {
     $redirectID;
     $input = Request::all();
     if (Request::has('created')) {
         $redirectID = $input['id'];
         BusinessPlan::create($input);
     }
     if (Request::has('bpid')) {
         if ($input['bp'] == 'False') {
             $input['bp'] = True;
         } else {
             $input['bp'] = False;
         }
         $input['group'] += 1;
         Goal::create($input);
         $redirectID = $input['bpid'];
     }
     if (Request::has('goal_id')) {
         // return  $input['goal_id'];
         $goals = DB::select("select * from goals where bpid = '" . $input['idbp'] . "'");
         $input['goal_id'] = $goals[$input['goal_id']]->id;
         $objectiveIdent = count(DB::table('objectives')->where('goal_id', $input['goal_id'])->get()) + 1;
         $goalIdent = $input['goal_id'];
         $input['ident'] = "{$goalIdent}.{$objectiveIdent}";
         $redirectIDArray = DB::table('goals')->where('id', $input['goal_id'])->pluck('bpid');
         $redirectID = $redirectIDArray[0];
         Objective::create($input);
     }
     if (Request::has('objective_id')) {
         $input['group'] += 1;
         $objectives = DB::select("select distinct * from goals, objectives where bpid = '" . $input['idbp'] . "' and objectives.goal_id = goals.id");
         $input['objective_id'] = $objectives[$input['objective_id']]->id;
         $input['userId'] += 1;
         $objectiveIdent = DB::table('objectives')->where('id', $input['objective_id'])->pluck('ident');
         $actionIdent = count(DB::table('actions')->where('objective_id', $input['objective_id'])->get()) + 1;
         $input['ident'] = "{$objectiveIdent['0']}.{$actionIdent}";
         $var2 = $input['idbp'];
         $redirectIDArray = DB::table('goals as g')->join('objectives as o', function ($join) use($var2) {
             $join->on('o.goal_id', '=', 'g.id')->where('g.bpid', '=', $var2);
         })->distinct()->pluck('g.bpid');
         $redirectID = $redirectIDArray[0];
         $collabs = "";
         if (array_key_exists('collaborators-groups', $input)) {
             foreach ($input['collaborators-groups'] as $x) {
                 $group = Group::find($x);
                 if ($group != null) {
                     $collabs .= Group::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         if (array_key_exists('collaborators-users', $input)) {
             foreach ($input['collaborators-users'] as $x) {
                 $user = User::find($x);
                 if ($user != null) {
                     $collabs .= User::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         $collabs = rtrim($collabs, ", ");
         $input['collaborators'] = $collabs;
         Action::create($input);
     }
     if (Request::has('action_id')) {
         $input['group'] += 1;
         $actions = DB::select("select distinct * from goals, objectives,actions where bpid = '" . $input['idbp'] . "' and objectives.goal_id = goals.id and actions.objective_id = objectives.id");
         $input['action_id'] = $actions[$input['action_id']]->id;
         $input['userId'] += 1;
         $actionIdent = DB::table('actions')->where('id', $input['action_id'])->pluck('ident');
         $taskIdent = count(DB::table('tasks')->where('action_id', $input['action_id'])->get()) + 1;
         $input['ident'] = "{$actionIdent['0']}.{$taskIdent}";
         $var2 = $input['idbp'];
         $redirectIDArray = DB::table('goals as g')->join('objectives as o', function ($join2) use($var2) {
             $join2->on('o.goal_id', '=', 'g.id')->where('g.bpid', '=', $var2);
         })->join('actions as a', function ($join) {
             $join->on('a.objective_id', '=', 'o.id');
         })->distinct()->pluck('g.bpid');
         $redirectID = $redirectIDArray[0];
         $collabs = "";
         if (array_key_exists('collaborators-groups', $input)) {
             foreach ($input['collaborators-groups'] as $x) {
                 $group = Group::find($x);
                 if ($group != null) {
                     $collabs .= Group::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         if (array_key_exists('collaborators-users', $input)) {
             foreach ($input['collaborators-users'] as $x) {
                 $user = User::find($x);
                 if ($user != null) {
                     $collabs .= User::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         $collabs = rtrim($collabs, ", ");
         $input['collaborators'] = $collabs;
         Task::create($input);
     }
     return redirect("businessplan/" . $redirectID . "");
 }