コード例 #1
0
ファイル: editpub.php プロジェクト: Raffprta/Open-Access
 public function handle($context)
 {
     # Ensure that the user is staff at least
     $context->mustbestaff();
     # Load the publication RESTfully
     $pub = R::load('publication', $context->rest()[0]);
     # Check if the staff is allowed to edit it.
     if ($context->user()->id != $pub->uploaderId) {
         $context->local()->addval('error', 'You must be the staff who uploaded this to edit it.');
         return 'editpub.twig';
     }
     # Check if it's a post
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         # Set up a new publication handler.
         $pubcreator = new Manipulatepub($pub, 'editpub.twig');
         $returnerr = $pubcreator->manipulatepublication($context);
         # If it's a non-empty string a error occured.
         if (!empty($returnerr)) {
             $context->local()->addval('error', $returnerr);
             return 'editpub.twig';
         }
         $pub = $pubcreator->getpub();
         # Otherwise it is a publication, so store it.
         R::store($pub);
         # The publication has been sucessfully edited, let's divert the user to the view page using REST.
         $context->divert("/viewpub/" . $pub->id);
     }
     $context->local()->addval(['pub' => $pub, 'auths' => $pub->sharedAuthor]);
     return 'editpub.twig';
 }
コード例 #2
0
ファイル: upload.php プロジェクト: Raffprta/Open-Access
 /**
  * Handle setting up the ORM handling, form handling and delegating 
  * upload information to a separate handler.
  *
  * @param object    $context    The context object for the site
  *
  * @return string    A template name
  */
 public function handle($context)
 {
     # Ensure user is valid.
     $context->mustbestaff();
     # Check if it's a post
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         # Dispense a publication, author and file bean.
         $this->pub = R::dispense('publication');
         # Set up a new publication handler.
         $pubcreator = new Manipulatepub($this->pub, 'upload.twig');
         $returnerr = $pubcreator->manipulatepublication($context);
         # If it's a non-empty string a error occured.
         if (!empty($returnerr)) {
             $context->local()->message('error', $returnerr);
             return 'upload.twig';
         }
         $this->pub = $pubcreator->getpub();
         # Set up a category.
         $cat = R::findOne('type', 'id=?', array($this->pub->category));
         # Call method to handle uploads -- this method returns a twig
         $errorpresent = $this->handleuploads($context, $cat->name, $this->pub);
         if (!empty($errorpresent)) {
             return $errorpresent;
         }
         # Finally associate the staff member uploading to the publication
         $this->pub->uploader = $context->user();
         # Persist the file data
         foreach ($this->files as $f) {
             $this->pub->xownFiles[] = $f;
         }
         R::store($this->pub);
         # The publication has been sucessfully created, let's divert the user to the view page using REST.
         $context->divert("/viewpub/" . $this->pub->id);
     }
     # Will not be returned in a successful POST.
     return 'upload.twig';
 }