/** * Sets order of bookmarks in the currently loaded folder to the order of bookmark_ids as set in $pa_bookmark_ids * * @param array $pa_bookmark_ids A list of bookmark_ids in the folder, in the order in which they should be displayed in the ui * @param int $pn_folder_id Optional folder_id to set * @param int $pn_user_id Optional user_id to enforce for folder selection * @param array $pa_options An optional array of options. Supported options include: * * @return array An array of errors. If the array is empty then no errors occurred */ public function reorderBookmarks($pa_bookmark_ids, $pn_folder_id = null, $pn_user_id = null, $pa_options = null) { if (!($vn_folder_id = $this->_getFolderID($pn_folder_id, $pn_user_id))) { return false; } $va_bookmark_ranks = $this->getBookmarkIDRanks($pn_folder_id, $pn_user_id, $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_bookmark = new ca_bookmarks(); $t_bookmark->setTransaction($o_trans); $t_bookmark->setMode(ACCESS_WRITE); $va_errors = array(); // delete rows not present in $pa_stop_ids $va_to_delete = array(); foreach ($va_bookmark_ranks as $vn_bookmark_id => $va_rank) { if (!in_array($vn_bookmark_id, $pa_bookmark_ids)) { if ($t_bookmark->load(array('folder_id' => $vn_folder_id, 'bookmark' => $vn_bookmark_id))) { $t_bookmark->delete(true); } } } // rewrite ranks foreach ($pa_bookmark_ids as $vn_rank => $vn_bookmark_id) { if (isset($va_bookmark_ranks[$vn_bookmark_id]) && $t_bookmark->load(array('folder_id' => $vn_folder_id, 'bookmark_id' => $vn_bookmark_id))) { if ($va_bookmark_ranks[$vn_bookmark_id] != $vn_rank) { $t_bookmark->set('rank', $vn_rank); $t_bookmark->update(); if ($t_bookmark->numErrors()) { $va_errors[$vn_bookmark_id] = _t('Could not reorder bookmark %1: %2', $vn_bookmark_id, join('; ', $t_bookmark->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; }
/** * */ public function removeBookmark($pn_bookmark_id, $pn_folder_id = null, $pn_user_id = null) { if (!($vn_folder_id = $this->_getFolderID($pn_folder_id, $pn_user_id))) { return false; } $t_bookmark = new ca_bookmarks($pn_bookmark_id); if ($t_bookmark->get('folder_id') != $vn_folder_id) { return false; } $t_bookmark->setMode(ACCESS_WRITE); $t_bookmark->delete(); if ($t_bookmark->numErrors()) { $this->errors = $t_bookmark->errors; return false; } return true; }