Example #1
0
 /**
  * Get the basic gallery info and supporting slices/tags
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function get($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $gallery = RokGallery_Model_GalleryTable::getSingle($params->id);
         foreach ($gallery->Slices as &$slice) {
             $slice->populateFilterInfo();
             $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
             $slice->clearRelated('File');
             $slice->Tags;
             $slice->FileTags;
         }
         $sortable_slices = $gallery->Slices->getData();
         usort($sortable_slices, array('RokGalleryAdminAjaxModelGallery', 'slice_ordering_sort'));
         $html = RokCommon_Composite::get('com_rokgallery.galleryorder')->load('default.php', array('slices' => $sortable_slices));
         $result->setPayload(array('gallery' => $gallery->toJsonableArray(), 'html' => $html));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Example #2
0
 /**
  * Removes an array of tags to a {@link RokGallery_Model_File} object
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1,
  *  'tags':['tag1','tag2']
  * }
  * </code>
  *
  * @param  $params
  * @return RokCommon_Ajax_Result
  */
 public function removeTags($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         RokGallery_Doctrine::getConnection()->beginTransaction();
         $file = RokGallery_Model_FileTable::getSingle($params->id);
         if ($file === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
         }
         RokGallery_Model_FileTable::removeTagsFromFile($file, $params->tags);
         RokGallery_Doctrine::getConnection()->commit();
         $file->imageurl;
         $file->Tags;
         foreach ($file->Slices as &$slice) {
             $slice->populateFilterInfo();
             $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
             $slice->clearRelated('File');
             $slice->Tags;
             $slice->FileTags;
             $slice->Gallery;
         }
         $result->setPayload(array('file' => $file->toJsonableArray()));
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         throw $e;
     }
     return $result;
 }
Example #3
0
 /**
  * Update the slice
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1
  *  'slice':{'title':'new title','description':'new description'}
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function create($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $file = RokGallery_Model_FileTable::getSingle($params->fileId);
         /** @var $slice RokGallery_Model_Slice */
         $slice =& RokGallery_Model_Slice::createNew($file);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_SLICE_N', $params->id));
         }
         foreach ($params->slice as $field => $value) {
             // change the manipulation format if passed
             if ($field == 'manipulations') {
                 $value = RokGallery_Manipulation_Helper::unserializeFromJson($value);
             }
             // Add any tags if they are passed
             if ($field == 'Tags') {
                 if (!empty($value) && is_array($value)) {
                     foreach ($value as $tag) {
                         $slice->addTag($tag);
                     }
                 }
                 continue;
             }
             $slice->{$field} = $value;
         }
         $slice->save();
         $slice->populateFilterInfo();
         $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
         $slice->Tags;
         $slice->FileTags;
         $slice->File;
         $result->setPayload(array('slice' => $slice->toJsonableArray()));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }