Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(PlansRequest $request, $id)
 {
     foreach ($request->all() as $key => $val) {
         if (substr($key, 0, 2) == "p_") {
             $tagname = "t_" . substr($key, 2);
             $tag = $request->input($tagname);
             if (!$tag) {
                 $tag = null;
             }
             if ($val) {
                 $pid = substr($val, 2);
                 if (substr($val, 0, 1) == "M") {
                     $ptyp = "App\\Models\\Minister";
                 } elseif (substr($val, 0, 1) == "P") {
                     $ptyp = "App\\Models\\Preacher";
                 } else {
                     $ptyp = "App\\Models\\Guest";
                 }
             } else {
                 $pid = null;
                 $ptyp = null;
             }
             $kk = array(explode('_', $key));
             $plan = Plan::where('society_id', '=', $kk[0][1])->where('service_id', '=', $kk[0][2])->where('planyear', '=', $kk[0][3])->where('planmonth', '=', $kk[0][4])->where('planday', '=', $kk[0][5])->first();
             if (count($plan)) {
                 $plan->tag_id = $tag;
                 $plan->preachable_id = $pid;
                 $plan->preachable_type = $ptyp;
                 if ($tag == null and $pid == null) {
                     $plan->delete();
                 } else {
                     $plan->save();
                 }
             } else {
                 if ($tag or $pid) {
                     $newplan = Plan::create(array('society_id' => $kk[0][1], 'service_id' => $kk[0][2], 'planyear' => $kk[0][3], 'planmonth' => $kk[0][4], 'planday' => $kk[0][5], 'preachable_id' => $pid, 'preachable_type' => $ptyp, 'tag_id' => $tag));
                 }
             }
         }
     }
     return Redirect::back()->with('okmessage', 'Plan details have been updated');
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PlanCreateRequest $request)
 {
     Plan::create($request->all());
     Session::flash('mensaje', 'Plan creado correctamente');
     return redirect('planes');
 }
Example #3
0
 /**
  * Store a newly created plan in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(StorePlanRequest $request)
 {
     // create new record
     $plan = Plan::create($request->except(['start', 'end']));
     // set some defaults
     $plan->changer = Auth::user()->first_name;
     $plan->state = 1;
     $planDate = Carbon::instance($plan->date);
     // insert default service TIMES if requested
     if ($request->input('defaultValues') == 'Y') {
         $type = Type::find($plan->type_id);
         if (count($type)) {
             // default end time is only the time of day. We need to combine this with the plan date
             $startTme = Carbon::parse($type->start);
             $endTime = Carbon::parse($type->end);
             $plan->date = $planDate->copy()->addHour($startTme->hour)->addMinute($startTme->minute);
             $plan->date_end = $planDate->addHour($endTime->hour)->addMinute($endTime->minute);
         }
     } else {
         // request contains custom start and end times
         $startTme = Carbon::parse($request->start);
         $endTime = Carbon::parse($request->end);
         $plan->date = $planDate->copy()->addHour($startTme->hour)->addMinute($startTme->minute);
         $plan->date_end = $planDate->addHour($endTime->hour)->addMinute($endTime->minute);
     }
     $plan->save();
     addDefaultRolesAndResourcesToPlan($plan);
     // insert default items if requested
     if ($request->input('defaultItems') == 'Y') {
         $dItems = DefaultItem::where('type_id', $plan->type_id)->get();
         // $newItems = [];
         foreach ($dItems as $dItem) {
             // get single default item to create a nwe Item object
             $iNew = new Item(['seq_no' => $dItem->seq_no, 'comment' => $dItem->text, 'forLeadersEyesOnly' => $dItem->forLeadersEyesOnly]);
             // save the new item to the new plan
             $plan->items()->save($iNew);
             // if default item contains a default image, link the new Plan item to the image
             if ($dItem->file_id) {
                 $file = File::find($dItem->file_id);
                 $iNew->files()->save($file);
             }
             // array_push( $newItems, $iNew );
         }
     }
     flash('New Plan added with id ' . $plan->id);
     // redirect back to the plan editor to create another plan
     if ($request->input('addAnother') == 'Y') {
         // use heper function to calculate next date for this plan
         $newDate = getNextPlanDate($plan);
         // send the default values to the View
         $request->session()->flash('defaultValues', ['type_id' => $plan->type_id, 'date' => $newDate, 'start' => $startTme->toTimeString(), 'end' => $endTime->toTimeString(), 'leader_id' => $plan->leader_id]);
         // get list of service types
         $types = Type::get();
         // get list of users
         $users = User::orderBy('first_name')->get();
         return view($this->view_one, array('types' => $types, 'users' => $users));
     }
     return \Redirect::route('plans.edit', $plan->id);
 }