/**
  * @param RequestInterface  $request  A PSR-7 compatible Request instance.
  * @param ResponseInterface $response A PSR-7 compatible Response instance.
  * @return ResponseInterface
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     $params = $request->getParams();
     $this->setData($params);
     $obj = $this->obj();
     $revNum = $params['rev_num'];
     $ret = $obj->revertToRevision($revNum);
     if ($ret) {
         $this->setSuccess(true);
         $this->addFeedback('success', 'Object was succesfully reverted to revision.');
         return $response;
     } else {
         $this->setSuccess(false);
         $this->addFeedback('error', 'Could not revert to revision');
         return $response->withStatus(404);
     }
 }
 /**
  * @param RequestInterface  $request  A PSR-7 compatible Request instance.
  * @param ResponseInterface $response A PSR-7 compatible Response instance.
  * @return ResponseInterface
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     try {
         $this->setData($request->getParams());
         // Create or load object (From `ObjectContainerTrait`)
         $obj = $this->obj();
         $saveData = $this->saveData();
         $obj->setFlatData($this->saveData());
         $valid = $obj->validate();
         if (!$valid) {
             $this->setSuccess(false);
             $this->addFeedbackFromValidation($obj);
             if (!$this->hasFeedbacks()) {
                 $this->addFeedback('error', 'Failed to create object: validation error(s).');
             }
             return $response->withStatus(404);
         }
         $authorIdent = $this->authorIdent();
         if (!$obj->lastModifiedBy()) {
             $obj->setLastModifiedBy($authorIdent);
         }
         if (!$obj->createdBy()) {
             $obj->setCreatedBy($authorIdent);
         }
         $ret = $obj->save();
         if ($ret) {
             $this->setObj($obj);
             $this->setSuccess(true);
             $this->addFeedback('success', 'Object was successfully created');
             $this->addFeedbackFromValidation($obj, ModelValidator::NOTICE);
             return $response;
         } else {
             $this->setObj(null);
             $this->setSuccess(false);
             $this->addFeedback('error', 'Could not create objet. Unknown error');
             $this->addFeedbackFromValidation($obj);
             return $response->withStatus(404);
         }
     } catch (Exception $e) {
         $this->setObj(null);
         $this->setSuccess(false);
         $this->addFeedback('error', $e->getMessage());
         return $response->withStatus(404);
     }
 }
 /**
  * @param RequestInterface  $request  A PSR-7 compatible Request instance.
  * @param ResponseInterface $response A PSR-7 compatible Response instance.
  * @return ResponseInterface
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     $params = $request->getParams();
     if (!isset($params['obj_type'])) {
         $this->setSuccess(false);
         return $response->withStatus(404);
     }
     // Does this do anything?
     $this->setMode('csv');
     $exporter = new Exporter(['logger' => $this->logger, 'factory' => $this->modelFactory(), 'obj_type' => $params['obj_type'], 'propertyFactory' => $this->propertyFactory]);
     if (isset($params['ident'])) {
         $exporter->setExportIdent($params['ident']);
     }
     $exporter->process();
     // Kind of always true unless there are no keywords defined.
     $this->setSuccess(true);
     return $response;
 }
 /**
  * Retrieve options from Request's parameters (GET).
  *
  * @param RequestInterface $request The PSR7 request.
  * @return boolean
  */
 public function init(RequestInterface $request)
 {
     $params = $request->getParams();
     if (isset($params['obj_type'])) {
         $this->objType = filter_var($params['obj_type'], FILTER_SANITIZE_STRING);
     }
     if (isset($params['obj_id'])) {
         $this->objId = filter_var($params['obj_id'], FILTER_SANITIZE_STRING);
     }
     if (isset($params['property'])) {
         $this->propertyIdent = filter_var($params['property'], FILTER_SANITIZE_STRING);
     }
     if (isset($params['assets'])) {
         $this->showAssets = !!$params['assets'];
     }
     if (isset($params['callback'])) {
         $this->callbackIdent = filter_var($params['callback'], FILTER_SANITIZE_STRING);
     }
     if (isset($this->elfinderConfig['translations'])) {
         $this->setLocalizations(array_replace_recursive($this->defaultLocalizations(), $this->elfinderConfig['translations']));
     }
     return true;
 }
 /**
  * Template's init method is called automatically from `charcoal-app`'s Template Route.
  *
  * For admin templates, initializations is:
  *
  * - to start a session, if necessary
  * - to authenticate
  * - to initialize the template data with `$_GET`
  *
  * @param RequestInterface $request The request to initialize.
  * @return boolean
  * @see \Charcoal\App\Route\TemplateRoute::__invoke()
  */
 public function init(RequestInterface $request)
 {
     if (!session_id()) {
         session_cache_limiter(false);
         session_start();
     }
     if ($this->authRequired() !== false) {
         // This can reset headers / die if unauthorized.
         if (!$this->authenticator()->authenticate()) {
             header('HTTP/1.0 403 Forbidden');
             exit;
         }
         // Initialize data with GET / POST parameters.
         $this->setData($request->getParams());
         // Test template vs. ACL roles
         $authUser = $this->authenticator()->authenticate();
         if (!$this->authorizer()->userAllowed($authUser, $this->requiredAclPermissions())) {
             header('HTTP/1.0 403 Forbidden');
             exit;
         }
     } else {
         // Initialize data with GET / POST parameters.
         $this->setData($request->getParams());
     }
     return parent::init($request);
 }