Example #1
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;
 }