Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 function createBrowseCategory()
 {
     global $library;
     global $locationSingleton;
     global $user;
     $searchLocation = $locationSingleton->getSearchLocation();
     $categoryName = isset($_REQUEST['categoryName']) ? $_REQUEST['categoryName'] : '';
     $addAsSubCategoryOf = isset($_REQUEST['addAsSubCategoryOf']) && !empty($_REQUEST['addAsSubCategoryOf']) ? $_REQUEST['addAsSubCategoryOf'] : null;
     // value of zero means nothing was selected.
     //Get the text id for the category
     $textId = str_replace(' ', '_', strtolower(trim($categoryName)));
     $textId = preg_replace('/[^\\w\\d_]/', '', $textId);
     if (strlen($textId) == 0) {
         return array('result' => false, 'message' => 'Please enter a category name');
     }
     if ($searchLocation) {
         $textId = $searchLocation->code . '_' . $textId;
     } elseif ($library) {
         $textId = $library->subdomain . '_' . $textId;
     }
     //Check to see if we have an existing browse category
     require_once ROOT_DIR . '/sys/Browse/BrowseCategory.php';
     $browseCategory = new BrowseCategory();
     $browseCategory->textId = $textId;
     if ($browseCategory->find(true)) {
         return array('result' => false, 'message' => "Sorry the title of the category was not unique.  Please enter a new name.");
     } else {
         $searchId = $_REQUEST['searchId'];
         /** @var SearchObject_Solr|SearchObject_Base $searchObj */
         $searchObj = SearchObjectFactory::initSearchObject();
         $searchObj->init();
         $searchObj = $searchObj->restoreSavedSearch($searchId, false, true);
         if (!$browseCategory->updateFromSearch($searchObj)) {
             return array('result' => false, 'message' => "Sorry, this search is too complex to create a category from.");
         }
         $browseCategory->label = $categoryName;
         $browseCategory->userId = $user->id;
         $browseCategory->sharing = 'everyone';
         $browseCategory->catalogScoping = 'unscoped';
         $browseCategory->description = '';
         //setup and add the category
         if (!$browseCategory->insert()) {
             return array('result' => false, 'message' => "There was an error saving the category.  Please contact Marmot.");
         } elseif ($addAsSubCategoryOf) {
             $id = $browseCategory->id;
             // get from above insertion operation
             $subCategory = new SubBrowseCategories();
             $subCategory->browseCategoryId = $addAsSubCategoryOf;
             $subCategory->subCategoryId = $id;
             if (!$subCategory->insert()) {
                 return array('result' => false, 'message' => "There was an error saving the category as a sub-category.  Please contact Marmot.");
             }
         }
         //Now add to the library/location
         /*if ($searchLocation){
         			require_once ROOT_DIR . '/sys/Browse/LocationBrowseCategory.php';
         			$locationBrowseCategory = new LocationBrowseCategory();
         			$locationBrowseCategory->locationId = $searchLocation->locationId;
         			$locationBrowseCategory->browseCategoryTextId = $textId;
         			$locationBrowseCategory->insert();
         		}else*/
         if ($library && !$addAsSubCategoryOf) {
             // Only add main browse categories to the library carousel
             require_once ROOT_DIR . '/sys/Browse/LibraryBrowseCategory.php';
             $libraryBrowseCategory = new LibraryBrowseCategory();
             $libraryBrowseCategory->libraryId = $library->libraryId;
             $libraryBrowseCategory->browseCategoryTextId = $textId;
             $libraryBrowseCategory->insert();
         }
         return array('result' => true);
     }
 }