/**
  * @param $info
  * @param $loc Location
  **/
 protected function createEvent($info, $loc)
 {
     // TODO: validate input types
     $event = Event::create(['title' => $info['title'], 'description' => $info['description'], 'hash' => $info['hash'], 'starting_time' => Carbon::parse($info['starting_time']), 'url' => $info['url']]);
     if (isset($info['ending_time'])) {
         $event->ending_time = Carbon::parse($info['ending_time']);
     }
     if (isset($info['notes'])) {
         $event->notes = $info['notes'];
     }
     $event->location()->associate($loc);
     if (isset($info['tags'])) {
         foreach ($info['tags'] as $tagName) {
             try {
                 $tag = Tag::whereName($tagName)->firstOrFail();
                 $event->tags()->save($tag);
             } catch (ModelNotFoundException $e) {
                 $this->raiseIssue("[{$this->name}]: Unknown tag name '{$tagName}'", "The tag '{$tagName}' is not registered.\n\n" . "Full entity info was:\n\n" . var_export($info, true));
                 continue;
             }
         }
     }
     $event->save();
 }
 public function add()
 {
     if ($this->shouldLockIfNoPermission('data.edit')) {
         return;
     }
     if ($this->request->is('post')) {
         $valuesToBind = [];
         $postItem = array_map('trim', $_POST);
         foreach (self::$tableColumns as $column) {
             if (isset($postItem[$column])) {
                 if ($column === 'created' || strpos($column, 'date_') === 0) {
                     $postItem[$column] = strtotime($postItem[$column]);
                 }
                 $valuesToBind[$column] = $postItem[$column];
             } else {
                 $valuesToBind[$column] = null;
             }
         }
         $postName = isset($postItem['name']) ? $postItem['name'] : '';
         if (strlen($postName) < 1) {
             $this->flash->warning('You must type in a name!');
             return $this->redirect($this->request->here);
         }
         $user = $this->session->get('user');
         $valuesToBind['created_by'] = $user['username'];
         $eventService = new Event($this->db);
         if ($eventService->create($valuesToBind) !== false) {
             $this->flash->success('Added this event successfully!');
             return $this->redirect('/events/view/' . $eventService->lastInsertId());
         } else {
             $this->flash->error('Unable to add event!');
         }
         return $this->redirect($this->request->here);
     }
     $this->set('now', date('n/j/Y', time()));
 }