Exemple #1
0
 /**
  * Post error callback
  *
  * @param \Crud\Event\Subject $subject Event subject
  * @return void
  */
 protected function _error(Subject $subject)
 {
     $subject->set(['success' => false, 'created' => true]);
     $this->_trigger('afterRegister', $subject);
     $this->setFlash('error', $subject);
     $this->_trigger('beforeRender', $subject);
 }
 /**
  * Post error callback
  *
  * @param \Crud\Event\Subject $subject Event subject
  * @return void
  */
 protected function _error(Subject $subject)
 {
     $subject->set(['success' => false]);
     $this->_trigger('afterLogin', $subject);
     $this->setFlash('error', $subject);
     $this->_trigger('beforeRender', $subject);
 }
 /**
  * Throw exception if a record is not found
  *
  * @param string $id Record id
  * @param \Crud\Event\Subject $subject Event subject
  * @return void
  * @throws \Exception
  */
 protected function _notFound($id, Subject $subject)
 {
     $subject->set(['success' => false]);
     $this->_trigger('recordNotFound', $subject);
     $message = $this->message('recordNotFound', compact('id'));
     $exceptionClass = $message['class'];
     throw new $exceptionClass($message['text'], $message['code']);
 }
 /**
  * Find a audit log by id
  *
  * @param string $id Record id
  * @param \Crud\Event\Subject $subject Event subject
  * @return \AuditStash\Model\Document\AuditLog
  */
 protected function _findRecord($id, Subject $subject)
 {
     $repository = $this->_table();
     $this->_configIndex($repository, $this->_request());
     if ($this->_request()->query('type')) {
         $repository->name($this->_request()->query('type'));
     }
     $query = $repository->find($this->findMethod());
     $query->where(['_id' => $id]);
     $subject->set(['repository' => $repository, 'query' => $query]);
     $this->_trigger('beforeFind', $subject);
     $entity = $query->first();
     if (!$entity) {
         return $this->_notFound($id, $subject);
     }
     $subject->set(['entity' => $entity, 'success' => true]);
     $this->_trigger('afterFind', $subject);
     return $entity;
 }
 /**
  * Wrapper for FlashComponent::set()
  *
  * @param string $type Message type
  * @param \Crud\Event\Subject $subject Event subject
  * @return void
  */
 public function setFlash($type, Subject $subject)
 {
     $subject->set($this->message($type));
     $event = $this->_trigger('setFlash', $subject);
     if ($event->isStopped()) {
         return;
     }
     $this->_controller()->Flash->set($subject->text, ['element' => $subject->element, 'params' => $subject->params, 'key' => $subject->key]);
 }
Exemple #6
0
 /**
  * Stopped callback
  *
  * @param \Crud\Event\Subject $subject Event subject
  * @return \Cake\Network\Response
  */
 protected function _stopped(Subject $subject)
 {
     $subject->set(['success' => false]);
     $this->setFlash('error', $subject);
     return $this->_redirect($subject, ['action' => 'index']);
 }
Exemple #7
0
 /**
  * Create a CakeEvent subject with the required properties.
  *
  * @param array $additional Additional properties for the subject.
  * @return \Crud\Event\Subject
  */
 public function getSubject($additional = [])
 {
     $subject = new Subject();
     $subject->set($additional);
     return $subject;
 }