Ejemplo n.º 1
0
 public function edit(Request $request, $id)
 {
     if ($request->has('type')) {
         $type = $request->input('type');
         switch ($type) {
             case 'selectalarm':
                 if ($id == 'no') {
                     $available = AlarmType::where('entity_type', '=', 0)->get();
                     $existing = Alarm::where('entity_id', '=', 0)->get();
                 } else {
                     $e = Entity::findOrFail($id);
                     $available = $e->type->alarms;
                     $existing = $e->alarms;
                 }
                 $structured = array();
                 foreach ($available as $a) {
                     $unit = (object) array('alarm' => $a, 'pendings' => array());
                     foreach ($existing as $exist) {
                         if ($exist->type->id == $a->id) {
                             $unit->pendings[] = $exist;
                         }
                     }
                     $structured[] = $unit;
                 }
                 return view('alarms.choosealarmtype', ['structured' => $structured]);
                 break;
         }
     } else {
         $e = Entity::findOrFail($id);
         return view('entities.edit', ['entity' => $e]);
     }
 }
 /**
  * Register any other events for your application.
  *
  * @param  \Illuminate\Contracts\Events\Dispatcher  $events
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     AttributeType::deleting(function ($attr) {
         $sub_attrs = Attribute::where('type_id', '=', $attr->id)->get();
         foreach ($sub_attrs as $sa) {
             $sa->delete();
         }
     });
     EntityType::deleting(function ($entity) {
         $entities = $entity->entities;
         foreach ($entities as $e) {
             $e->delete();
         }
     });
     Entity::deleting(function ($entity) {
         $alarms = $entity->alarms;
         foreach ($alarms as $a) {
             $a->delete();
         }
     });
     Alarm::deleting(function ($alarm) {
         $reminders = $alarm->history;
         foreach ($reminders as $r) {
             $r->delete();
         }
     });
 }
Ejemplo n.º 3
0
 public function getIcs()
 {
     $alarms = Alarm::where('closed', '=', false)->orderBy('date1', 'asc')->get();
     $reminders = Reminder::where('active', '=', true)->orderBy('expiry', 'asc')->get();
     return view('export.ics', ['alarms' => $alarms, 'reminders' => $reminders]);
 }
Ejemplo n.º 4
0
 public function reIterate()
 {
     if ($this->type->recurrence == 'once') {
         return;
     }
     $a = new Alarm();
     $a->type_id = $this->type_id;
     $a->entity_id = $this->entity_id;
     $a->author_id = Auth::user()->id;
     $a->owner_id = $this->owner_id;
     $a->notes = '';
     $a->closed = false;
     $a->closer_id = -1;
     $a->prev_id = $this->id;
     switch ($this->type->recurrence) {
         case 'daily':
             $future = '+1 day';
             break;
         case 'weekly':
             $future = '+1 week';
             break;
         case 'monthly':
             $future = '+1 month';
             break;
         case 'yearly':
             $future = '+1 year';
             break;
         case 'custom':
             $future = sprintf('+%s', $this->type->recurrence_details);
             break;
     }
     $a->date1 = date('Y-m-d', strtotime($this->date1 . $future));
     if ($this->type->type == 'interval') {
         $a->date2 = date('Y-m-d', strtotime($this->date2 . $future));
     }
     $a->save();
 }
Ejemplo n.º 5
0
 public function fetch($id, $filename)
 {
     $a = Alarm::findOrFail($id);
     $filepath = $a->filesPath() . '/' . $filename;
     return response()->download($filepath);
 }