Example #1
0
 public function interact()
 {
     // Fetch and hydrate the entity...
     $entity = $this->getEntity();
     // ... verify that the entity can be created by the current user
     $this->verifyCreateAuth($entity);
     // ... verify that the entity is in a valid state
     $this->verifyValid($entity);
     // ... persist the new entity
     $id = $this->repo->create($entity);
     // ... get the newly created entity
     $entity = $this->getCreatedEntity($id);
     // ... verify that the entity can be read by the current user
     $this->verifyReadAuth($entity);
     // ... and return the formatted entity
     return $this->formatter->__invoke($entity);
 }
Example #2
0
 public function interact()
 {
     // Fetch a default entity and apply the payload...
     $entity = $this->getEntity();
     // ... verify that the entity can be created by the current user
     $this->verifyCreateAuth($entity);
     // ... verify that the entity is in a valid state
     $this->verifyValid($entity);
     // ... persist the new entity
     $id = $this->repo->create($entity);
     // ... get the newly created entity
     $entity = $this->getCreatedEntity($id);
     // ... check that the entity can be read by the current user
     if ($this->auth->isAllowed($entity, 'read')) {
         // ... and either return the formatted entity
         return $this->formatter->__invoke($entity);
     } else {
         // ... or just return nothing
         return;
     }
 }
 /**
  * Create post for message
  * @param  Entity $message
  * @return Int
  */
 protected function createPost(Entity $message)
 {
     $values = [];
     // Pull locations from extra metadata
     if ($message->additional_data) {
         $values['message_location'] = [];
         foreach ($message->additional_data['location'] as $location) {
             if (!empty($location['type']) && !empty($location['coordinates']) && ucfirst($location['type']) == 'Point') {
                 $values['message_location'][] = ['lon' => $location['coordinates'][0], 'lat' => $location['coordinates'][1]];
             }
         }
     }
     // First create a post
     $post = $this->postRepo->getEntity()->setState(['title' => $message->title, 'content' => $message->message, 'values' => $values]);
     return $this->postRepo->create($post);
 }
Example #4
0
 /**
  * Create post for message
  * @param  Entity $message
  * @return Int
  */
 protected function createPost(Entity $message)
 {
     // First create a post
     $post = $this->postRepo->getEntity()->setState(['title' => $message->title, 'content' => $message->message]);
     return $this->postRepo->create($post);
 }