Пример #1
0
/**
 * 
 *
 * @param RequestHTTP $po_request
 * @param array $pa_options
 * @param array $pa_additional_display_options
 * @return string HTML output
 */
function caRepresentationViewerHTMLBundleForSearchResult($po_data, $po_request, $pa_options = null, $pa_additional_display_options = null)
{
    $ps_version = $po_request->getParameter('version', pString);
    $va_access_values = isset($pa_options['access']) && is_array($pa_options['access']) ? $pa_options['access'] : array();
    $vs_display_type = isset($pa_options['display']) && $pa_options['display'] ? $pa_options['display'] : 'media_overlay';
    $vs_container_dom_id = isset($pa_options['containerID']) && $pa_options['containerID'] ? $pa_options['containerID'] : null;
    $vn_object_id = isset($pa_options['object_id']) && $pa_options['object_id'] ? $pa_options['object_id'] : null;
    $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null;
    $vn_order_item_id = isset($pa_options['order_item_id']) && $pa_options['order_item_id'] ? $pa_options['order_item_id'] : null;
    $vb_media_editor = isset($pa_options['mediaEditor']) && $pa_options['mediaEditor'] ? true : false;
    $vb_no_controls = isset($pa_options['noControls']) && $pa_options['noControls'] ? true : false;
    $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null;
    $t_object = new ca_objects($vn_object_id);
    //if (!$t_object->getPrimaryKey()) { return false; }
    if (!$po_data->getPrimaryKey() && $t_object->getPrimaryKey() && method_exists($po_data, 'load')) {
        $po_data->load($t_object->getPrimaryRepresentationID(array('checkAccess' => $va_access_values)));
    }
    $t_set_item = new ca_set_items();
    if ($vn_item_id) {
        $t_set_item->load($vn_item_id);
    }
    $t_order_item = new ca_commerce_order_items();
    if ($vn_order_item_id) {
        $t_order_item->load($vn_order_item_id);
    }
    $o_view = new View($po_request, $po_request->getViewsDirectoryPath() . '/bundles/');
    $o_view->setVar('t_object', $t_object);
    $o_view->setVar('t_set_item', $t_set_item);
    $o_view->setVar('t_order_item', $t_order_item);
    $o_view->setVar('use_media_editor', $vb_media_editor);
    $o_view->setVar('noControls', $vb_no_controls);
    $va_rep_display_info = array();
    if (isset($pa_options['use_book_viewer'])) {
        $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer'];
    }
    if ($t_object->getPrimaryKey()) {
        $o_view->setVar('reps', $va_reps = $t_object->getRepresentations(array('icon'), null, array("return_with_access" => $va_access_values)));
    }
    $t_media = new Media();
    $va_buf = array();
    while ($po_data->nextHit()) {
        if (method_exists($po_data, 'numFiles')) {
            $o_view->setVar('num_multifiles', $po_data->numFiles());
        }
        $o_view->setVar('t_object_representation', $po_data);
        if (($vn_representation_id = $po_data->getPrimaryKey()) && (!sizeof($va_access_values) || in_array($po_data->get('access'), $va_access_values))) {
            // check rep access
            $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $vs_mimetype = $po_data->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
            $va_rep_display_info['poster_frame_url'] = $po_data->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
            $va_additional_display_options = array();
            if (is_array($pa_additional_display_options) && isset($pa_additional_display_options[$vs_mimetype]) && is_array($pa_additional_display_options[$vs_mimetype])) {
                $va_additional_display_options = $pa_additional_display_options[$vs_mimetype];
            }
            $o_view->setVar('display_options', caGetMediaDisplayInfo('detail', $vs_mimetype));
            $o_view->setVar('display_type', $vs_display_type);
            $o_view->setVar('representation_id', $vn_representation_id);
            $o_view->setVar('t_object_representation', $po_data);
            $o_view->setVar('versions', $va_versions = $po_data->getMediaVersions('media'));
            $o_view->setVar('containerID', $vs_container_dom_id . $vn_representation_id);
            $o_view->setVar('version_type', $t_media->getMimetypeTypename($po_data->getMediaInfo('media', 'original', 'MIMETYPE')));
            if ($t_object->getPrimaryKey()) {
                $vn_next_rep = $vn_prev_rep = null;
                $va_rep_list = array_values($va_reps);
                foreach ($va_rep_list as $vn_i => $va_rep) {
                    if ($va_rep['representation_id'] == $vn_representation_id) {
                        if (isset($va_rep_list[$vn_i - 1])) {
                            $vn_prev_rep = $va_rep_list[$vn_i - 1]['representation_id'];
                        }
                        if (isset($va_rep_list[$vn_i + 1])) {
                            $vn_next_rep = $va_rep_list[$vn_i + 1]['representation_id'];
                        }
                        $o_view->setVar('representation_index', $vn_i + 1);
                    }
                }
                $o_view->setVar('previous_representation_id', $vn_prev_rep);
                $o_view->setVar('next_representation_id', $vn_next_rep);
            }
            if (!in_array($ps_version, $va_versions)) {
                if (!($ps_version = $va_rep_display_info['display_version'])) {
                    $ps_version = null;
                }
            }
            $o_view->setVar('version_info', $po_data->getMediaInfo('media', $ps_version));
            $o_view->setVar('version', $ps_version);
        }
        $va_buf[$vn_representation_id] = $o_view->render('representation_viewer_html.php');
    }
    return $va_buf;
}
Пример #2
0
/**
 * Return rendered HTML for media viewer for both re
 *
 * @param RequestHTTP $po_request
 * @param array $pa_options
 * @param array $pa_additional_display_options
 * @return string HTML output
 */
function caGetMediaViewerHTMLBundle($po_request, $pa_options = null, $pa_additional_display_options = null)
{
    $va_access_values = isset($pa_options['access']) && is_array($pa_options['access']) ? $pa_options['access'] : array();
    $vs_display_type = isset($pa_options['display']) && $pa_options['display'] ? $pa_options['display'] : 'media_overlay';
    $vs_container_dom_id = isset($pa_options['containerID']) && $pa_options['containerID'] ? $pa_options['containerID'] : null;
    $t_subject = isset($pa_options['t_subject']) && $pa_options['t_subject'] ? $pa_options['t_subject'] : null;
    $t_rep = isset($pa_options['t_representation']) && $pa_options['t_representation'] ? $pa_options['t_representation'] : null;
    $vn_representation_id = $t_rep ? $t_rep->getPrimaryKey() : null;
    $t_attr_val = isset($pa_options['t_attribute_value']) && $pa_options['t_attribute_value'] ? $pa_options['t_attribute_value'] : null;
    $vn_value_id = $t_attr_val ? $t_attr_val->getPrimaryKey() : null;
    $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null;
    $vn_order_item_id = isset($pa_options['order_item_id']) && $pa_options['order_item_id'] ? $pa_options['order_item_id'] : null;
    $vb_media_editor = isset($pa_options['mediaEditor']) && $pa_options['mediaEditor'] ? true : false;
    $vb_no_controls = isset($pa_options['noControls']) && $pa_options['noControls'] ? true : false;
    $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null;
    $vn_subject_id = $t_subject ? $t_subject->getPrimaryKey() : null;
    if (!$vn_value_id && !$vn_representation_id) {
        $t_rep->load($t_subject->getPrimaryRepresentationID(array('checkAccess' => $va_access_values)));
    }
    $o_view = new View($po_request, $po_request->getViewsDirectoryPath() . '/bundles/');
    $t_set_item = new ca_set_items();
    if ($vn_item_id) {
        $t_set_item->load($vn_item_id);
    }
    $t_order_item = new ca_commerce_order_items();
    if ($vn_order_item_id) {
        $t_order_item->load($vn_order_item_id);
    }
    $o_view->setVar('containerID', $vs_container_dom_id);
    $o_view->setVar('t_subject', $t_subject);
    $o_view->setVar('t_representation', $t_rep);
    if ($vn_representation_id && (!sizeof($va_access_values) || in_array($t_rep->get('access'), $va_access_values))) {
        // check rep access
        $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
        $va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
        $o_view->setVar('num_multifiles', $t_rep->numFiles());
        if (isset($pa_options['use_book_viewer'])) {
            $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer'];
        }
        $o_view->setVar('display_type', $vs_display_type);
        if (is_array($pa_additional_display_options)) {
            $va_rep_display_info = array_merge($va_rep_display_info, $pa_additional_display_options);
        }
        $o_view->setVar('display_options', $va_rep_display_info);
        $o_view->setVar('representation_id', $vn_representation_id);
        $o_view->setVar('versions', $va_versions = $t_rep->getMediaVersions('media'));
        $t_media = new Media();
        $o_view->setVar('version_type', $t_media->getMimetypeTypename($t_rep->getMediaInfo('media', 'original', 'MIMETYPE')));
        if ($vn_subject_id) {
            $o_view->setVar('reps', $va_reps = $t_subject->getRepresentations(array('icon'), null, array("return_with_access" => $va_access_values)));
            $vn_next_rep = $vn_prev_rep = null;
            $va_rep_list = array_values($va_reps);
            foreach ($va_rep_list as $vn_i => $va_rep) {
                if ($va_rep['representation_id'] == $vn_representation_id) {
                    if (isset($va_rep_list[$vn_i - 1])) {
                        $vn_prev_rep = $va_rep_list[$vn_i - 1]['representation_id'];
                    }
                    if (isset($va_rep_list[$vn_i + 1])) {
                        $vn_next_rep = $va_rep_list[$vn_i + 1]['representation_id'];
                    }
                    $o_view->setVar('representation_index', $vn_i + 1);
                }
            }
            $o_view->setVar('previous_representation_id', $vn_prev_rep);
            $o_view->setVar('next_representation_id', $vn_next_rep);
        }
        $ps_version = $po_request->getParameter('version', pString);
        if (!in_array($ps_version, $va_versions)) {
            if (!($ps_version = $va_rep_display_info['display_version'])) {
                $ps_version = null;
            }
        }
        $o_view->setVar('version', $ps_version);
        $o_view->setVar('version_info', $t_rep->getMediaInfo('media', $ps_version));
        $o_view->setVar('t_set_item', $t_set_item);
        $o_view->setVar('t_order_item', $t_order_item);
        $o_view->setVar('use_media_editor', $vb_media_editor);
        $o_view->setVar('noControls', $vb_no_controls);
    } else {
        //$t_attr = new ca_attributes($t_attr_val->get('attribute_id'));
        $t_attr_val->useBlobAsMediaField(true);
        $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $t_attr_val->getMediaInfo('value_blob', 'INPUT', 'MIMETYPE'));
        $va_rep_display_info['poster_frame_url'] = $t_attr_val->getMediaUrl('value_blob', $va_rep_display_info['poster_frame_version']);
        $o_view->setVar('num_multifiles', $t_attr_val->numFiles());
        if (isset($pa_options['use_book_viewer'])) {
            $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer'];
        }
        $o_view->setVar('display_type', $vs_display_type);
        if (is_array($pa_additional_display_options)) {
            $va_rep_display_info = array_merge($va_rep_display_info, $pa_additional_display_options);
        }
        $o_view->setVar('display_options', $va_rep_display_info);
        $o_view->setVar('representation_id', $vn_representation_id);
        $o_view->setVar('t_attribute_value', $t_attr_val);
        $o_view->setVar('versions', $va_versions = $t_attr_val->getMediaVersions('value_blob'));
        $t_media = new Media();
        $o_view->setVar('version_type', $t_media->getMimetypeTypename($t_attr_val->getMediaInfo('value_blob', 'original', 'MIMETYPE')));
        $o_view->setVar('reps', array());
        $ps_version = $po_request->getParameter('version', pString);
        if (!in_array($ps_version, $va_versions)) {
            if (!($ps_version = $va_rep_display_info['display_version'])) {
                $ps_version = null;
            }
        }
        $o_view->setVar('version', $ps_version);
        $o_view->setVar('version_info', $t_attr_val->getMediaInfo('value_blob', $ps_version));
        $o_view->setVar('t_subject', $t_subject);
        $o_view->setVar('t_set_item', $t_set_item);
        $o_view->setVar('t_order_item', $t_order_item);
        $o_view->setVar('use_media_editor', $vb_media_editor);
        $o_view->setVar('noControls', $vb_no_controls);
    }
    return $o_view->render('representation_viewer_html.php');
}
Пример #3
0
 /**
  * Sets order of items in the currently loaded set to the order of row_ids as set in $pa_row_ids
  *
  * @param array $pa_row_ids A list of row_ids in the set, in the order in which they should be displayed in the set
  * @param array $pa_options An optional array of options. Supported options include:
  *			user_id = the user_id of the current user; used to determine which sets the user has access to
  *			treatRowIDsAsRIDs = assume combination row_id/item_id indices in $pa_row_ids array instead of solely row_ids. Since a set can potentially contain multiple instances of the same row_id, only "rIDs" – a combination of the row_id and the set item_id (row_id + "_" + item_id) – are guaranteed to be unique. [Default=false]
  * 			deleteExcludedItems = should the set items not passed in pa_row_ids be deleted?  default is false
  * @return array An array of errors. If the array is empty then no errors occurred
  */
 public function reorderItems($pa_row_ids, $pa_options = null)
 {
     if (!($vn_set_id = $this->getPrimaryKey())) {
         return null;
     }
     $vn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $vb_treat_row_ids_as_rids = caGetOption('treatRowIDsAsRIDs', $pa_options, false);
     $vb_delete_excluded_items = caGetOption('deleteExcludedItems', $pa_options, false);
     // does user have edit access to set?
     if ($vn_user_id && !$this->haveAccessToSet($vn_user_id, __CA_SET_EDIT_ACCESS__)) {
         return false;
     }
     $va_row_ranks = $this->getRowIDRanks($pa_options);
     // get current ranks
     $vn_i = 0;
     $vb_web_set_transaction = false;
     if (!$this->inTransaction()) {
         $o_trans = new Transaction($this->getDb());
         $vb_web_set_transaction = true;
     } else {
         $o_trans = $this->getTransaction();
     }
     $t_set_item = new ca_set_items();
     $t_set_item->setTransaction($o_trans);
     $t_set_item->setMode(ACCESS_WRITE);
     $va_errors = array();
     // delete rows not present in $pa_row_ids
     $va_excluded_item_ids = array();
     foreach ($va_row_ranks as $vn_row_id => $va_rank) {
         if (!in_array($vn_row_id, $pa_row_ids)) {
             if ($vb_treat_row_ids_as_rids) {
                 $va_tmp = explode("_", $vn_row_id);
                 if ($t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $va_tmp[0], 'item_id' => $va_tmp[1]))) {
                     $va_excluded_item_ids[$t_set_item->get("rank")] = $t_set_item->get("item_id");
                     if ($vb_delete_excluded_items) {
                         $t_set_item->delete(true);
                     }
                 }
             } else {
                 if ($t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $vn_row_id))) {
                     $va_excluded_item_ids[$t_set_item->get("rank")] = $t_set_item->get("item_id");
                     if ($vb_delete_excluded_items) {
                         $t_set_item->delete(true);
                     }
                 }
             }
             if (($vn_k = array_search($pa_row_ids, $pa_row_ids)) !== false) {
                 unset($pa_row_ids[$vn_k]);
             }
             unset($va_row_ranks[$vn_row_id]);
         }
     }
     // rewrite ranks
     $va_existing_ranks = array_values($va_row_ranks);
     $vn_rank_acc = end(array_values($va_row_ranks));
     $va_rank_updates = array();
     foreach ($pa_row_ids as $vn_rank => $vn_row_id) {
         if (isset($va_existing_ranks[$vn_rank])) {
             $vn_rank_inc = $va_existing_ranks[$vn_rank];
         } else {
             $vn_rank_acc++;
             $vn_rank_inc = $vn_rank_acc;
         }
         if ($vb_treat_row_ids_as_rids) {
             $va_tmp = explode("_", $vn_row_id);
         }
         if (isset($va_row_ranks[$vn_row_id]) && $va_row_ranks[$vn_row_id] != $vn_rank_inc) {
             $va_rank_updates[$vn_row_id] = $vn_rank_inc;
         } elseif (!isset($va_row_ranks[$vn_row_id])) {
             // add item to set
             $this->addItem($vb_treat_row_ids_as_rids ? $va_tmp[0] : $vn_row_id, null, $vn_user_id, $vn_rank_inc);
         }
     }
     foreach ($va_rank_updates as $vn_row_id => $vn_new_rank) {
         if ($vb_treat_row_ids_as_rids) {
             $va_tmp = explode("_", $vn_row_id);
             $this->getDb()->query("UPDATE ca_set_items SET rank = ? WHERE set_id = ? AND row_id = ? AND item_id = ?", $x = array($vn_new_rank, $vn_set_id, $va_tmp[0], $va_tmp[1]));
         } else {
             $this->getDb()->query("UPDATE ca_set_items SET rank = ? WHERE set_id = ? AND row_id = ?", array($vn_set_id, $vn_new_rank));
         }
     }
     if (sizeof($va_errors)) {
         if ($vb_web_set_transaction) {
             $o_trans->rollback();
         }
     } else {
         if ($vb_web_set_transaction) {
             $o_trans->commit();
         }
     }
     return $va_errors;
 }
Пример #4
0
 /**
  * Sets order of items in the currently loaded set to the order of row_ids as set in $pa_row_ids
  *
  * @param array $pa_row_ids A list of row_ids in the set, in the order in which they should be displayed in the set
  * @param array $pa_options An optional array of options. Supported options include:
  *			user_id = the user_id of the current user; used to determine which sets the user has access to
  * @return array An array of errors. If the array is empty then no errors occurred
  */
 public function reorderItems($pa_row_ids, $pa_options = null)
 {
     if (!($vn_set_id = $this->getPrimaryKey())) {
         return null;
     }
     $vn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     // does user have edit access to set?
     if ($vn_user_id && !$this->haveAccessToSet($vn_user_id, __CA_SET_EDIT_ACCESS__)) {
         return false;
     }
     $va_row_ranks = $this->getRowIDRanks($pa_options);
     // get current ranks
     $vn_i = 0;
     $o_trans = new Transaction();
     $t_set_item = new ca_set_items();
     $t_set_item->setTransaction($o_trans);
     $t_set_item->setMode(ACCESS_WRITE);
     $va_errors = array();
     // delete rows not present in $pa_row_ids
     $va_to_delete = array();
     foreach ($va_row_ranks as $vn_row_id => $va_rank) {
         if (!in_array($vn_row_id, $pa_row_ids)) {
             if ($t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $vn_row_id))) {
                 $t_set_item->delete(true);
             }
         }
     }
     // rewrite ranks
     foreach ($pa_row_ids as $vn_rank => $vn_row_id) {
         if (isset($va_row_ranks[$vn_row_id]) && $t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $vn_row_id))) {
             if ($va_row_ranks[$vn_row_id] != $vn_rank) {
                 $t_set_item->set('rank', $vn_rank);
                 $t_set_item->update();
                 if ($t_set_item->numErrors()) {
                     $va_errors[$vn_row_id] = _t('Could not reorder item %1: %2', $vn_row_id, join('; ', $t_set_item->getErrors()));
                 }
             }
         } else {
             // add item to set
             $this->addItem($vn_row_id, null, $vn_user_id, $vn_rank);
         }
     }
     if (sizeof($va_errors)) {
         $o_trans->rollback();
     } else {
         $o_trans->commit();
     }
     return $va_errors;
 }
Пример #5
0
 public function ReorderItems()
 {
     if ($this->request->isLoggedIn()) {
         $t_set = $this->_getSet();
         if (!$t_set->getPrimaryKey()) {
             $this->notification->addNotification(_t("The collection does not exist"), __NOTIFICATION_TYPE_ERROR__);
             return;
         }
         // does user have edit access to set?
         if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) {
             $this->notification->addNotification(_t("You cannot edit this collection"), __NOTIFICATION_TYPE_ERROR__);
             $this->Edit();
             return;
         }
         $va_item_ids = explode(';', $this->request->getParameter('sort', pString));
         for ($vn_i = 0; $vn_i < sizeof($va_item_ids); $vn_i++) {
             $va_item_ids[$vn_i] = str_replace('setItem', '', $va_item_ids[$vn_i]);
         }
         // get ranks
         $va_item_ranks = $t_set->getItemRanks(array('user_id' => $this->request->getUserID()));
         // rewrite ranks
         $vn_i = 0;
         $o_trans = new Transaction();
         $t_set_item = new ca_set_items();
         $t_set_item->setTransaction($o_trans);
         $t_set_item->setMode(ACCESS_WRITE);
         $va_errors = array();
         foreach ($va_item_ranks as $vn_item_id => $vn_rank) {
             if ($vn_item_id != $va_item_ids[$vn_i]) {
                 if ($t_set_item->load($va_item_ids[$vn_i])) {
                     $t_set_item->set('rank', $vn_rank);
                     $t_set_item->update();
                     if ($t_set_item->numErrors()) {
                         $va_errors[$va_item_ids[$vn_i]] = _t('Could not reorder item %1: %2', $va_item_ids[$vn_i], join('; ', $t_set_item->getErrors()));
                     }
                 }
             }
             $vn_i++;
         }
         if (sizeof($va_errors)) {
             $o_trans->rollback();
         } else {
             $o_trans->commit();
         }
     } else {
         $va_errors['general'] = 'Must be logged in';
     }
     $this->view->setVar('errors', $va_errors);
     $this->render('Sets/ajax_reorder_items_json.php');
 }
Пример #6
0
 /**
  * Sets order of items in the currently loaded set to the order of row_ids as set in $pa_row_ids
  *
  * @param array $pa_row_ids A list of row_ids in the set, in the order in which they should be displayed in the set
  * @param array $pa_options An optional array of options. Supported options include:
  *			user_id = the user_id of the current user; used to determine which sets the user has access to
  *			treatRowIDsAsRIDs = assume combination row_id/item_id indices in $pa_row_ids array instead of solely row_ids. Since a set can potentially contain multiple instances of the same row_id, only "rIDs" – a combination of the row_id and the set item_id (row_id + "_" + item_id) – are guaranteed to be unique. [Default=false]
  * 			deleteExludedItems = should the set items not passed in pa_row_ids be deleted?  default is false
  * @return array An array of errors. If the array is empty then no errors occurred
  */
 public function reorderItems($pa_row_ids, $pa_options = null)
 {
     if (!($vn_set_id = $this->getPrimaryKey())) {
         return null;
     }
     $vn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $vb_treat_row_ids_as_rids = caGetOption('treatRowIDsAsRIDs', $pa_options, false);
     $vb_delete_excluded_items = caGetOption('deleteExludedItems', $pa_options, false);
     // does user have edit access to set?
     if ($vn_user_id && !$this->haveAccessToSet($vn_user_id, __CA_SET_EDIT_ACCESS__)) {
         return false;
     }
     $va_row_ranks = $this->getRowIDRanks($pa_options);
     // get current ranks
     $vn_i = 0;
     $vb_web_set_transaction = false;
     if (!$this->inTransaction()) {
         $o_trans = new Transaction($this->getDb());
         $vb_web_set_transaction = true;
     } else {
         $o_trans = $this->getTransaction();
     }
     $t_set_item = new ca_set_items();
     $t_set_item->setTransaction($o_trans);
     $t_set_item->setMode(ACCESS_WRITE);
     $va_errors = array();
     // delete rows not present in $pa_row_ids
     $va_excluded_item_ids = array();
     foreach ($va_row_ranks as $vn_row_id => $va_rank) {
         if (!in_array($vn_row_id, $pa_row_ids)) {
             if ($vb_treat_row_ids_as_rids) {
                 $va_tmp = explode("_", $vn_row_id);
                 if ($t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $va_tmp[0], 'item_id' => $va_tmp[1]))) {
                     $va_excluded_item_ids[$t_set_item->get("rank")] = $t_set_item->get("item_id");
                     if ($vb_delete_excluded_items) {
                         $t_set_item->delete(true);
                     }
                 }
             } else {
                 if ($t_set_item->load(array('set_id' => $vn_set_id, 'row_id' => $vn_row_id))) {
                     $va_excluded_item_ids[$t_set_item->get("rank")] = $t_set_item->get("item_id");
                     if ($vb_delete_excluded_items) {
                         $t_set_item->delete(true);
                     }
                 }
             }
         }
     }
     // rewrite ranks
     foreach ($pa_row_ids as $vn_rank => $vn_row_id) {
         $vn_rank_inc = $vn_rank + 1;
         if ($vb_treat_row_ids_as_rids) {
             $va_tmp = explode("_", $vn_row_id);
         }
         if (isset($va_row_ranks[$vn_row_id]) && $t_set_item->load($vb_treat_row_ids_as_rids ? array('set_id' => $vn_set_id, 'row_id' => $va_tmp[0], 'item_id' => $va_tmp[1]) : array('set_id' => $vn_set_id, 'row_id' => $vn_row_id))) {
             if ($va_row_ranks[$vn_row_id] != $vn_rank_inc) {
                 $t_set_item->set('rank', $vn_rank_inc);
                 $t_set_item->update();
                 if ($t_set_item->numErrors()) {
                     $va_errors[$vn_row_id] = _t('Could not reorder item %1: %2', $vn_row_id, join('; ', $t_set_item->getErrors()));
                 }
             }
         } else {
             // add item to set
             $this->addItem($vb_treat_row_ids_as_rids ? $va_tmp[0] : $vn_row_id, null, $vn_user_id, $vn_rank_inc);
         }
     }
     if (!$vb_delete_excluded_items) {
         # --- don't delete items whose id's where not passed to this function,
         foreach ($va_excluded_item_ids as $vn_item_id) {
             $vn_rank_inc++;
             $t_set_item->load($vn_item_id);
             $t_set_item->set('rank', $vn_rank_inc);
             $t_set_item->update();
             if ($t_set_item->numErrors()) {
                 $va_errors[$vn_row_id] = _t('Could not reorder item %1: %2', $vn_row_id, join('; ', $t_set_item->getErrors()));
             }
         }
     }
     if (sizeof($va_errors)) {
         if ($vb_web_set_transaction) {
             $o_trans->rollback();
         }
     } else {
         if ($vb_web_set_transaction) {
             $o_trans->commit();
         }
     }
     return $va_errors;
 }
 /**
  * Removes item from set
  *
  * @param int $set_id
  * @param int $set_item_id
  * @return boolean
  * @throws SoapFault
  */
 public function removeItemFromSet($set_id, $set_item_id)
 {
     $t_set_item = new ca_set_items();
     if (!$t_set_item->load($set_item_id)) {
         throw new SoapFault("Server", "Invalid set_item id");
     }
     $t_set_item->setMode(ACCESS_WRITE);
     $t_set_item->delete();
     if ($t_set_item->numErrors() == 0) {
         return true;
     } else {
         throw new SoapFault("Server", "There were errors while updating the item: " . join(";", $t_set_item->getErrors()));
     }
 }