Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public final function init()
 {
     $this->getResponse()->setHeader('Access-Control-Allow-Origin', '*', true)->setHeader('Access-Control-Allow-Credentials', 'true', true)->setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE', true)->setHeader('Access-Control-Allow-Headers', 'Content-Type, X-Preferred-Locale, X-Context, Authorization', true)->setHeader('Access-Control-Max-Age', '1728000', true)->setHeader('X-Preferred-Locale', $this->getPreferredLocale(), true)->setHeader('X-Context', $this->getContext(), true)->setHeader('Vary', 'Accept-Encoding', true)->setHeader('Content-Type', 'application/json; charset=utf-8', true);
     $this->setAuth($this->getRequest()->getHeader('Authorization'))->setContext($this->getContext());
     Table::setAuthUser($this->getCurrentUser());
     Table::setContext($this->getContext());
     Table::setPreferredLocale($this->getPreferredLocale());
     $this->_helper->viewRenderer->setNoRender(true);
     $this->input = new \StdClass();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public final function isSiteAdmin()
 {
     $context = Db\Table::getContext();
     if ($this->admin) {
         return true;
     } elseif (!array_key_exists($context, $this->permissions)) {
         return false;
     } else {
         foreach ($this->permissions[$context] as $group) {
             if ($group[1]) {
                 return true;
             }
         }
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     /// A read-only row cannot be saved.
     if ($this->_readOnly === true) {
         throw new Exception('ERR.READ_ONLY');
     }
     /// Allows pre-save logic to be applied to any row.
     /// Zend_Db_Table_Row only uses to do it on _insert OR _update,
     /// why Zend, why?
     ///
     /// Computers are bullshit!
     $this->_save();
     foreach ($this->_data as $column => &$value) {
         if ($value instanceof \DateTime) {
             $value->setFormat('Y:m:d H:i:s');
         }
     }
     if (false !== $this->getErrors()) {
         throw new Exception('ERR.VALIDATION_INVALID');
     }
     $user = Table::getAuthUser();
     if ($user) {
         $created_by = $user->id;
     } else {
         $created_by = 1;
     }
     if ($this->isNewRecord()) {
         if ($this->offsetExists('created_by')) {
             $this->created_by = $created_by;
         }
         if ($this->offsetExists('updated_by')) {
             $this->updated_by = $created_by;
         }
     } else {
         if ($this->offsetExists('updated_by')) {
             $this->updated_by = $created_by;
         }
     }
     ///
     parent::save();
     ///
     $this->_postSave();
 }