Exemple #1
0
/**
 * Check for duplicates and non-integer sequence number 
 * in the list of default items for a specific event type
 * @param int $type_id
 */
function checkDefaultItemsSequencing($type_id)
{
    $items = DefaultItem::where('type_id', $type_id)->orderBy('seq_no')->get();
    foreach ($items as $key => $item) {
        # use the key as the new sequence number
        $item->seq_no = $key + 1;
        $item->save();
    }
}
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     // find a single resource by ID
     $output = DefaultItem::find($id);
     if ($output) {
         $output->delete();
         $message = 'DefaultItem with id "' . $id . '" deleted.';
         return \Redirect::route($this->view_idx, ['filterby' => 'type', 'filtervalue' => $output->type_id])->with(['status' => $message]);
     }
     //
     $message = 'Error! DefaultItem with ID "' . $id . '" not found';
     return \Redirect::route($this->view_idx)->with(['status' => $message]);
 }
Exemple #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);
 }