本文整理汇总了PHP中UserList::find方法的典型用法代码示例。如果您正苦于以下问题:PHP UserList::find方法的具体用法?PHP UserList::find怎么用?PHP UserList::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserList
的用法示例。
在下文中一共展示了UserList::find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
public function getList($id)
{
if (is_numeric($id)) {
$list = UserList::find($id);
if (!empty($list)) {
return View::make('user_lists.list', array('list' => $list));
}
}
return App::abort(404);
}
示例2: launch
function launch($msg = null)
{
global $interface;
global $configArray;
if (!($user = UserAccount::isLoggedIn())) {
require_once ROOT_DIR . '/services/MyAccount/Login.php';
MyAccount_Login::launch();
exit;
}
// Save Data
if (isset($_POST['submit'])) {
$this->saveChanges($user);
// After changes are saved, send the user back to an appropriate page;
// either the list they were viewing when they started editing, or the
// overall favorites list.
if (isset($_REQUEST['list_id'])) {
$nextAction = 'MyList/' . $_REQUEST['list_id'];
} else {
$nextAction = 'Home';
}
header('Location: ' . $configArray['Site']['path'] . '/MyAccount/' . $nextAction);
exit;
}
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$userList = new UserList();
$userList->id = $_REQUEST['list_id'];
$userList->find(true);
$interface->assign('list', $userList);
require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
$id = $_GET['id'];
$groupedWorkDriver = new GroupedWorkDriver($id);
if ($groupedWorkDriver->isValid) {
$interface->assign('recordDriver', $groupedWorkDriver);
}
// Record ID
$interface->assign('recordId', $id);
// Retrieve saved information about record
require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
$userListEntry = new UserListEntry();
$userListEntry->groupedWorkPermanentId = $id;
$userListEntry->listId = $_REQUEST['list_id'];
$userListEntry->find(true);
$interface->assign('listEntry', $userListEntry);
$interface->assign('listFilter', $_GET['list_id']);
$interface->setTemplate('editListTitle.tpl');
$interface->display('layout.tpl');
}
示例3: addTitlesToList
/**
* Add titles to a user list.
*
* Parameters:
* <ul>
* <li>username - The barcode of the user. Can be truncated to the last 7 or 9 digits.</li>
* <li>password - The pin number for the user. </li>
* <li>listId - The id of the list to add items to.</li>
* <li>recordIds - The id of the record(s) to add to the list.</li>
* <li>tags - A comma separated string of tags to apply to the titles within the list. (optional)</li>
* <li>notes - descriptive text to apply to the titles. Can be viewed while on the list. (optional)</li>
* </ul>
*
* Note: You may also provide the parameters to addTitlesToList and titles will be added to the list
* after the list is created.
*
* Returns:
* <ul>
* <li>success - true if the account is valid and the titles could be added to the list, false if the username or password were incorrect or the list could not be created.</li>
* <li>listId - the id of the list that titles were added to.</li>
* <li>numAdded - the number of titles that were added to the list.</li>
* </ul>
*
* Sample Call:
* <code>
* http://catalog.douglascountylibraries.org/API/ListAPI?method=createList&username=23025003575917&password=1234&title=Test+List&description=Test&public=0
* </code>
*
* Sample Response:
* <code>
* {"result":{"success":true,"listId":"1688"}}
* </code>
*/
function addTitlesToList()
{
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if (!isset($_REQUEST['listId'])) {
return array('success' => false, 'message' => 'You must provide the listId to add titles to.');
}
$recordIds = array();
if (!isset($_REQUEST['recordIds'])) {
return array('success' => false, 'message' => 'You must provide one or more records to add tot he list.');
} else {
if (!is_array($_REQUEST['recordIds'])) {
$recordIds[] = $_REQUEST['recordIds'];
} else {
$recordIds = $_REQUEST['recordIds'];
}
}
global $user;
$user = UserAccount::validateAccount($username, $password);
if ($user && !PEAR_Singleton::isError($user)) {
$list = new UserList();
$list->id = $_REQUEST['listId'];
$list->user_id = $user->id;
if (!$list->find(true)) {
return array('success' => false, 'message' => 'Unable to find the list to add titles to.');
} else {
$numAdded = 0;
foreach ($recordIds as $id) {
$userListEntry = new UserListEntry();
$userListEntry->listId = $list->id;
$userListEntry->groupedWorkPermanentId = $id;
$existingEntry = false;
if ($userListEntry->find(true)) {
$existingEntry = true;
}
if (isset($_REQUEST['notes'])) {
$notes = $_REQUEST['notes'];
} else {
$notes = '';
}
$userListEntry->notes = $notes;
$userListEntry->dateAdded = time();
if ($existingEntry) {
$userListEntry->update();
} else {
$userListEntry->insert();
}
$numAdded++;
}
return array('success' => true, 'listId' => $list->id, 'numAdded' => $numAdded);
}
} else {
return array('success' => false, 'message' => 'Login unsuccessful');
}
}
示例4: __construct
public function __construct($names) {
if ($names != null) {
foreach ($names as $name) {
$this->_list [] = $name;
}
}
}
public function add($name) {
$this->_list [] = $name;
}
public function find($filter) {
$recs = array();
foreach ($this->_list as $user) {
if ($filter->filter($user))
$recs [] = $user;
}
return $recs;
}
}
$ul = new UserList(array("Andy", "Jack", "Lori", "Megan"));
$f1 = $ul->find(new FindAfterStrategy("J"));
print_r($f1);
$f2 = $ul->find(new RandomStrategy());
print_r($f2);
?>
示例5: addList
function addList()
{
if ($this->user) {
if (strlen(trim($_REQUEST['title'])) == 0) {
return new PEAR_Error('list_edit_name_required');
}
$list = new UserList();
$list->title = $_REQUEST['title'];
$list->description = $_REQUEST['desc'];
$list->public = $_REQUEST['public'];
$list->user_id = $this->user->id;
$list->insert();
$list->find();
return $list->id;
} else {
return false;
}
}
示例6: loadUserData
function loadUserData()
{
global $user;
global $interface;
//Load profile information
$catalog = CatalogFactory::getCatalogConnectionInstance();
$profile = $catalog->getMyProfile($user);
if (!PEAR_Singleton::isError($profile)) {
$interface->assign('profile', $profile);
}
//Load a list of lists
$lists = array();
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$tmpList = new UserList();
$tmpList->user_id = $user->id;
$tmpList->deleted = 0;
$tmpList->orderBy("title ASC");
$tmpList->find();
if ($tmpList->N > 0) {
while ($tmpList->fetch()) {
$lists[$tmpList->id] = array('name' => $tmpList->title, 'url' => '/MyAccount/MyList/' . $tmpList->id, 'id' => $tmpList->id, 'numTitles' => $tmpList->num_titles());
}
}
$interface->assign('lists', $lists);
// Get My Tags
$tagList = $user->getTags();
$interface->assign('tagList', $tagList);
if ($user->hasRole('opacAdmin') || $user->hasRole('libraryAdmin') || $user->hasRole('cataloging')) {
$variable = new Variable();
$variable->name = 'lastFullReindexFinish';
if ($variable->find(true)) {
$interface->assign('lastFullReindexFinish', date('m-d-Y H:i:s', $variable->value));
} else {
$interface->assign('lastFullReindexFinish', 'Unknown');
}
$variable = new Variable();
$variable->name = 'lastPartialReindexFinish';
if ($variable->find(true)) {
$interface->assign('lastPartialReindexFinish', date('m-d-Y H:i:s', $variable->value));
} else {
$interface->assign('lastPartialReindexFinish', 'Unknown');
}
}
}
示例7: getObjectStructure
static function getObjectStructure()
{
global $user;
// Get All User Lists
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$userLists = new UserList();
$userLists->public = 1;
$userLists->orderBy('title asc');
$userLists->find();
$sourceLists = array();
$sourceLists[-1] = 'Generate from search term and filters';
while ($userLists->fetch()) {
if ($userLists->num_titles() > 0) {
$sourceLists[$userLists->id] = "({$userLists->id}) {$userLists->title} - {$userLists->num_titles()} titles";
}
}
// Get Structure for Sub-categories
$browseSubCategoryStructure = SubBrowseCategories::getObjectStructure();
unset($browseSubCategoryStructure['weight']);
unset($browseSubCategoryStructure['browseCategoryId']);
$structure = array('id' => array('property' => 'id', 'type' => 'label', 'label' => 'Id', 'description' => 'The unique id of this association'), 'label' => array('property' => 'label', 'type' => 'text', 'label' => 'Label', 'description' => 'The label to show to the user', 'maxLength' => 50, 'required' => true), 'textId' => array('property' => 'textId', 'type' => 'text', 'label' => 'textId', 'description' => 'A textual id to identify the category', 'serverValidation' => 'validateTextId', 'maxLength' => 50), 'userId' => array('property' => 'userId', 'type' => 'label', 'label' => 'userId', 'description' => 'The User Id who created this category', 'default' => $user->id), 'sharing' => array('property' => 'sharing', 'type' => 'enum', 'values' => array('private' => 'Just Me', 'location' => 'My Home Branch', 'library' => 'My Home Library', 'everyone' => 'Everyone'), 'label' => 'Share With', 'description' => 'Who the category should be shared with', 'default' => 'everyone'), 'description' => array('property' => 'description', 'type' => 'html', 'label' => 'Description', 'description' => 'A description of the category.', 'hideInLists' => true), 'subBrowseCategories' => array('property' => 'subBrowseCategories', 'type' => 'oneToMany', 'label' => 'Browse Sub-Categories', 'description' => 'Browse Categories that will be displayed as sub-categories of this Browse Category', 'keyThis' => 'id', 'keyOther' => 'browseCategoryId', 'subObjectType' => 'SubBrowseCategories', 'structure' => $browseSubCategoryStructure, 'sortable' => true, 'storeDb' => true, 'allowEdit' => false, 'canEdit' => false), 'catalogScoping' => array('property' => 'catalogScoping', 'type' => 'enum', 'label' => 'Catalog Scoping', 'values' => array('unscoped' => 'Unscoped', 'library' => 'Current Library', 'location' => 'Current Location'), 'description' => 'What scoping should be used for this search scope?.', 'default' => 'unscoped'), 'searchTerm' => array('property' => 'searchTerm', 'type' => 'text', 'label' => 'Search Term', 'description' => 'A default search term to apply to the category', 'default' => '', 'hideInLists' => true), 'defaultFilter' => array('property' => 'defaultFilter', 'type' => 'textarea', 'label' => 'Default Filter(s)', 'description' => 'Filters to apply to the search by default.', 'hideInLists' => true, 'rows' => 3, 'cols' => 80), 'sourceListId' => array('property' => 'sourceListId', 'type' => 'enum', 'values' => $sourceLists, 'label' => 'Source List', 'description' => 'A public list to display titles from'), 'defaultSort' => array('property' => 'defaultSort', 'type' => 'enum', 'label' => 'Default Sort', 'values' => array('relevance' => 'Best Match', 'popularity' => 'Popularity', 'newest_to_oldest' => 'Newest First', 'oldest_to_newest' => 'Oldest First', 'author' => 'Author', 'title' => 'Title', 'user_rating' => 'Rating'), 'description' => 'The default sort for the search if none is specified', 'default' => 'relevance', 'hideInLists' => true), 'numTimesShown' => array('property' => 'numTimesShown', 'type' => 'label', 'label' => 'Times Shown', 'description' => 'The number of times this category has been shown to users'), 'numTitlesClickedOn' => array('property' => 'numTitlesClickedOn', 'type' => 'label', 'label' => 'Titles Clicked', 'description' => 'The number of times users have clicked on titles within this category'));
// used by Object Editor to make a list of Browse Categories for Admin interface
foreach ($structure as $fieldName => $field) {
if (isset($field['property'])) {
$field['propertyOld'] = $field['property'] . 'Old';
$structure[$fieldName] = $field;
}
}
return $structure;
}
示例8: launch
function launch()
{
global $configArray;
global $interface;
global $user;
// Fetch List object
$listId = $_REQUEST['id'];
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$list = new UserList();
$list->id = $listId;
if (!$list->find(true)) {
//TODO: Use the first list?
$list = new UserList();
$list->user_id = $user->id;
$list->public = false;
$list->title = "My Favorites";
}
// Ensure user has privileges to view the list
if (!isset($list) || !$list->public && !UserAccount::isLoggedIn()) {
require_once ROOT_DIR . '/services/MyAccount/Login.php';
MyAccount_Login::launch();
exit;
}
if (!$list->public && $list->user_id != $user->id) {
//Allow the user to view if they are admin
if ($user && $user->hasRole('opacAdmin')) {
//Allow the user to view
} else {
$interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
$interface->setTemplate('invalidList.tpl');
$interface->display('layout.tpl');
return;
}
}
if (isset($_SESSION['listNotes'])) {
$interface->assign('notes', $_SESSION['listNotes']);
unset($_SESSION['listNotes']);
}
//Perform an action on the list, but verify that the user has permission to do so.
$userCanEdit = false;
if ($user != false) {
$userCanEdit = $user->canEditList($list);
// if ($user->id == $list->user_id){
// $userCanEdit = true;
// }elseif ($user->hasRole('opacAdmin')){
// $userCanEdit = true;
// }elseif ($user->hasRole('libraryAdmin') || $user->hasRole('contentEditor')){
// $listUser = new User();
// $listUser->id = $list->user_id;
// $listUser->find(true);
// $listLibrary = Library::getLibraryForLocation($listUser->homeLocationId);
// $userLibrary = Library::getLibraryForLocation($user->homeLocationId);
// if ($userLibrary->libraryId == $listLibrary->libraryId){
// $userCanEdit = true;
// }
// }
}
if ($userCanEdit && (isset($_REQUEST['myListActionHead']) || isset($_REQUEST['myListActionItem']) || isset($_GET['delete']))) {
if (isset($_REQUEST['myListActionHead']) && strlen($_REQUEST['myListActionHead']) > 0) {
$actionToPerform = $_REQUEST['myListActionHead'];
if ($actionToPerform == 'makePublic') {
$list->public = 1;
$list->update();
} elseif ($actionToPerform == 'makePrivate') {
$list->public = 0;
$list->update();
} elseif ($actionToPerform == 'saveList') {
$list->title = $_REQUEST['newTitle'];
$list->description = $_REQUEST['newDescription'];
$list->defaultSort = $_REQUEST['defaultSort'];
$list->update();
} elseif ($actionToPerform == 'deleteList') {
$list->delete();
header("Location: {$configArray['Site']['path']}/MyAccount/Home");
die;
} elseif ($actionToPerform == 'bulkAddTitles') {
$notes = $this->bulkAddTitles($list);
$_SESSION['listNotes'] = $notes;
}
} elseif (isset($_REQUEST['myListActionItem']) && strlen($_REQUEST['myListActionItem']) > 0) {
$actionToPerform = $_REQUEST['myListActionItem'];
if ($actionToPerform == 'deleteMarked') {
//get a list of all titles that were selected
$itemsToRemove = $_REQUEST['selected'];
foreach ($itemsToRemove as $id => $selected) {
//add back the leading . to get the full bib record
$list->removeListEntry($id);
}
} elseif ($actionToPerform == 'deleteAll') {
$list->removeAllListEntries(isset($_GET['tag']) ? $_GET['tag'] : null);
}
$list->update();
} elseif (isset($_REQUEST['delete'])) {
$recordToDelete = $_REQUEST['delete'];
$list->removeListEntry($recordToDelete);
$list->update();
}
//Redirect back to avoid having the parameters stay in the URL.
header("Location: {$configArray['Site']['path']}/MyAccount/MyList/{$list->id}");
die;
//.........这里部分代码省略.........
示例9: importListsFromIls
/**
* Import Lists from the ILS
*
* @return array - an array of results including the names of the lists that were imported as well as number of titles.
*/
function importListsFromIls()
{
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
global $user;
$results = array('totalTitles' => 0, 'totalLists' => 0);
$patronDump = $this->_getPatronDump($this->_getBarcode());
//Get the page which contains a table with all lists in them.
$listsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists');
//Get the actual table
if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listsPage, $listsPageMatches)) {
$allListTable = $listsPageMatches[1];
//Now that we have the table, get the actual list names and ids
preg_match_all('/<tr[^>]*?class="patFuncEntry"[^>]*?>.*?<input type="checkbox" id ="(\\d+)".*?<a.*?>(.*?)<\\/a>.*?<td[^>]*class="patFuncDetails">(.*?)<\\/td>.*?<\\/tr>/si', $allListTable, $listDetails, PREG_SET_ORDER);
for ($listIndex = 0; $listIndex < count($listDetails); $listIndex++) {
$listId = $listDetails[$listIndex][1];
$title = $listDetails[$listIndex][2];
$description = str_replace(' ', '', $listDetails[$listIndex][3]);
//Create the list (or find one that already exists)
$newList = new UserList();
$newList->user_id = $user->id;
$newList->title = $title;
if (!$newList->find(true)) {
$newList->description = $description;
$newList->insert();
}
$currentListTitles = $newList->getListTitles();
//Get a list of all titles within the list to be imported
$listDetailsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists?listNum=' . $listId);
//Get the table for the details
if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listDetailsPage, $listsDetailsMatches)) {
$listTitlesTable = $listsDetailsMatches[1];
//Get the bib numbers for the title
preg_match_all('/<input type="checkbox" name="(b\\d{1,7})".*?<span[^>]*class="patFuncTitle(?:Main)?">(.*?)<\\/span>/si', $listTitlesTable, $bibNumberMatches, PREG_SET_ORDER);
for ($bibCtr = 0; $bibCtr < count($bibNumberMatches); $bibCtr++) {
$bibNumber = $bibNumberMatches[$bibCtr][1];
$bibTitle = strip_tags($bibNumberMatches[$bibCtr][2]);
//Get the grouped work for the resource
require_once ROOT_DIR . '/sys/Grouping/GroupedWorkPrimaryIdentifier.php';
require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php';
$primaryIdentifier = new GroupedWorkPrimaryIdentifier();
$groupedWork = new GroupedWork();
$primaryIdentifier->identifier = '.' . $bibNumber . $this->getCheckDigit($bibNumber);
$primaryIdentifier->type = 'ils';
$primaryIdentifier->joinAdd($groupedWork);
if ($primaryIdentifier->find(true)) {
//Check to see if this title is already on the list.
$resourceOnList = false;
foreach ($currentListTitles as $currentTitle) {
if ($currentTitle->groupedWorkPermanentId == $primaryIdentifier->permanent_id) {
$resourceOnList = true;
break;
}
}
if (!$resourceOnList) {
$listEntry = new UserListEntry();
$listEntry->groupedWorkPermanentId = $primaryIdentifier->permanent_id;
$listEntry->listId = $newList->id;
$listEntry->notes = '';
$listEntry->dateAdded = time();
$listEntry->insert();
}
} else {
//The title is not in the resources, add an error to the results
if (!isset($results['errors'])) {
$results['errors'] = array();
}
$results['errors'][] = "\"{$bibTitle}\" on list {$title} could not be found in the catalog and was not imported.";
}
$results['totalTitles']++;
}
}
$results['totalLists'] += 1;
}
}
return $results;
}
示例10: getSaveToListForm
function getSaveToListForm()
{
global $interface;
global $user;
$id = $_REQUEST['id'];
$interface->assign('id', $id);
require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
//Get a list of all lists for the user
$containingLists = array();
$nonContainingLists = array();
$userLists = new UserList();
$userLists->user_id = $user->id;
$userLists->deleted = 0;
$userLists->find();
while ($userLists->fetch()) {
//Check to see if the user has already added the title to the list.
$userListEntry = new UserListEntry();
$userListEntry->listId = $userLists->id;
$userListEntry->groupedWorkPermanentId = $id;
if ($userListEntry->find(true)) {
$containingLists[] = array('id' => $userLists->id, 'title' => $userLists->title);
} else {
$nonContainingLists[] = array('id' => $userLists->id, 'title' => $userLists->title);
}
}
$interface->assign('containingLists', $containingLists);
$interface->assign('nonContainingLists', $nonContainingLists);
$results = array('title' => 'Add To List', 'modalBody' => $interface->fetch("GroupedWork/save.tpl"), 'modalButtons' => "<span class='tool btn btn-primary' onclick='VuFind.GroupedWork.saveToList(\"{$id}\"); return false;'>Save To List</span>");
return json_encode($results);
}
示例11: getBrowseCategoryResults
private function getBrowseCategoryResults($pageToLoad = 1)
{
$browseMode = $this->setBrowseMode();
if ($pageToLoad == 1 && !isset($_REQUEST['reload'])) {
// only first page is cached
global $memCache, $solrScope;
$key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode;
$browseCategoryInfo = $memCache->get($key);
if ($browseCategoryInfo != false) {
return $browseCategoryInfo;
}
}
$result = array('result' => false);
$browseCategory = $this->getBrowseCategory();
if ($browseCategory) {
global $interface;
$interface->assign('browseCategoryId', $this->textId);
$result['result'] = true;
$result['textId'] = $browseCategory->textId;
$result['label'] = $browseCategory->label;
//$result['description'] = $browseCategory->description; // the description is not used anywhere on front end. plb 1-2-2015
// User List Browse Category //
if ($browseCategory->sourceListId != null && $browseCategory->sourceListId > 0) {
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$sourceList = new UserList();
$sourceList->id = $browseCategory->sourceListId;
if ($sourceList->find(true)) {
$records = $sourceList->getBrowseRecords(($pageToLoad - 1) * self::ITEMS_PER_PAGE, self::ITEMS_PER_PAGE);
} else {
$records = array();
}
$result['searchUrl'] = '/MyAccount/MyList/' . $browseCategory->sourceListId;
// Search Browse Category //
} else {
$this->searchObject = SearchObjectFactory::initSearchObject();
$defaultFilterInfo = $browseCategory->defaultFilter;
$defaultFilters = preg_split('/[\\r\\n,;]+/', $defaultFilterInfo);
foreach ($defaultFilters as $filter) {
$this->searchObject->addFilter(trim($filter));
}
//Set Sorting, this is actually slightly mangled from the category to Solr
$this->searchObject->setSort($browseCategory->getSolrSort());
if ($browseCategory->searchTerm != '') {
$this->searchObject->setSearchTerm($browseCategory->searchTerm);
}
//Get titles for the list
$this->searchObject->clearFacets();
$this->searchObject->disableSpelling();
$this->searchObject->disableLogging();
$this->searchObject->setLimit(self::ITEMS_PER_PAGE);
$this->searchObject->setPage($pageToLoad);
$this->searchObject->processSearch();
$records = $this->searchObject->getBrowseRecordHTML();
$result['searchUrl'] = $this->searchObject->renderSearchUrl();
//TODO: Check if last page
// Shutdown the search object
$this->searchObject->close();
}
if (count($records) == 0) {
$records[] = $interface->fetch('Browse/noResults.tpl');
}
$result['records'] = implode('', $records);
$result['numRecords'] = count($records);
}
// Store first page of browse category in the MemCache
if ($pageToLoad == 1) {
global $memCache, $configArray, $solrScope;
$key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode;
$memCache->add($key, $result, 0, $configArray['Caching']['browse_category_info']);
}
return $result;
}
示例12: setListEntryPositions
function setListEntryPositions()
{
$success = false;
// assume failure
$listId = $_REQUEST['listID'];
$updates = $_REQUEST['updates'];
if (ctype_digit($listId) && !empty($updates)) {
global $user;
require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
$list = new UserList();
$list->id = $listId;
if ($list->find(true) && $user->canEditList($list)) {
// list exists & user can edit
require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
$success = true;
// assume success now
foreach ($updates as $update) {
$userListEntry = new UserListEntry();
$userListEntry->listId = $listId;
$userListEntry->groupedWorkPermanentId = $update['id'];
if ($userListEntry->find(true) && ctype_digit($update['newOrder'])) {
// check entry exists already and the new weight is a number
$userListEntry->weight = $update['newOrder'];
if (!$userListEntry->update()) {
$success = false;
}
} else {
$success = false;
}
}
}
}
return array('success' => $success);
}