public function clearBrowseCategories() { $browseCategories = new LibraryBrowseCategory(); $browseCategories->libraryId = $this->libraryId; $browseCategories->delete(); $this->browseCategories = array(); }
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); } }