/**
  * Lists all billboards for a given collection
  *
  * @apiMethod GET
  * @apiUri    /billboards/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Collection identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @return  void
  */
 public function readTask()
 {
     // Get the collection id
     $collection = Request::getInt('id', 0);
     // Load up the collection
     $collection = Collection::oneOrNew($collection);
     // Make sure we found a collection
     if ($collection->isNew()) {
         throw new Exception(Lang::txt('Collection not found'), 404);
     }
     $billboards = $collection->billboards()->select('name')->select('learn_more_target')->select('background_img')->whereEquals('published', 1)->rows();
     foreach ($billboards as $billboard) {
         $image = $billboard->get('background_img');
         $billboard->set('retina_background_img', $image);
         if (is_file(PATH_APP . DS . $image)) {
             $image_info = pathinfo($image);
             $retina_image = $image_info['dirname'] . DS . $image_info['filename'] . "@2x." . $image_info['extension'];
             if (file_exists(PATH_APP . DS . $retina_image)) {
                 $billboard->set('retina_background_img', $retina_image);
             }
         }
     }
     // Get the collection and its billboards
     $collection = array('id' => $collection->id, 'name' => $collection->name, 'billboards' => $billboards->toArray());
     $this->send(array('collection' => $collection));
 }
Example #2
0
 /**
  * Save a collection
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Create object
     $collection = Collection::oneOrNew(Request::getInt('id'))->set(array('name' => Request::getVar('name')));
     if (!$collection->save()) {
         // Something went wrong...return errors
         foreach ($collection->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('edit');
         $this->view->task = 'edit';
         $this->editTask($collection);
         return;
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BILLBOARDS_COLLECTION_SUCCESSFULLY_SAVED'));
 }
Example #3
0
 /**
  * Save a billboard
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming, make sure to allow HTML to pass through
     $data = Request::getVar('billboard', array(), 'post', 'array', JREQUEST_ALLOWHTML);
     // Create object
     $billboard = Billboard::oneOrNew($data['id'])->set($data);
     // Check to make sure collection exists
     $collection = Collection::oneOrNew($billboard->collection_id);
     if ($collection->isNew()) {
         $collection->set('name', 'Default Collection')->save();
         $billboard->set('collection_id', $collection->id);
     }
     if (!$billboard->save()) {
         // Something went wrong...return errors
         foreach ($billboard->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('edit');
         $this->view->task = 'edit';
         $this->editTask($billboard);
         return;
     }
     // See if we have an image coming in as well
     $billboard_image = Request::getVar('billboard-image', false, 'files', 'array');
     // If so, proceed with saving the image
     if (isset($billboard_image['name']) && $billboard_image['name']) {
         // Build the upload path if it doesn't exist
         $image_location = $this->config->get('image_location', 'app' . DS . 'site' . DS . 'media' . DS . 'images' . DS . 'billboards');
         $uploadDirectory = PATH_ROOT . DS . trim($image_location, DS) . DS;
         // Make sure upload directory exists and is writable
         if (!is_dir($uploadDirectory)) {
             if (!\Filesystem::makeDirectory($uploadDirectory)) {
                 $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 $this->view->setLayout('edit');
                 $this->view->task = 'edit';
                 $this->editTask($billboard);
                 return;
             }
         }
         // Scan for viruses
         if (!\Filesystem::isSafe($billboard_image['tmp_name'])) {
             $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_FAILED_VIRUS_SCAN'));
             $this->view->setLayout('edit');
             $this->view->task = 'edit';
             $this->editTask($billboard);
             return;
         }
         if (!move_uploaded_file($billboard_image['tmp_name'], $uploadDirectory . $billboard_image['name'])) {
             $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_FILE_MOVE_FAILED'));
             $this->view->setLayout('edit');
             $this->view->task = 'edit';
             $this->editTask($billboard);
             return;
         } else {
             // Move successful, save the image url to the billboard entry
             $billboard->set('background_img', $billboard_image['name'])->save();
         }
     }
     // Check in the billboard now that we've saved it
     $billboard->checkin();
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BILLBOARDS_BILLBOARD_SUCCESSFULLY_SAVED'));
 }
Example #4
0
 /**
  * Save a collection
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Create object
     $collection = Collection::oneOrNew(Request::getInt('id'))->set(array('name' => Request::getVar('name')));
     if (!$collection->save()) {
         // Something went wrong...return errors
         foreach ($collection->getErrors() as $error) {
             Notify::error($error);
         }
         return $this->editTask($collection);
     }
     // Output messsage and redirect
     Notify::success(Lang::txt('COM_BILLBOARDS_COLLECTION_SUCCESSFULLY_SAVED'));
     $this->cancelTask();
 }