public function doExecute() { $strSubjectSelection = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); if (empty($strUsername)) { $strUsername = $this->request->getSession("username"); } // make sure they are logged in as the user they are trying to save as $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $existingSubject = $objData->getSubject($strSubjectSelection, null, Xerxes_DataMap::userCreatedMode, $strUsername); $subcats = $existingSubject->subcategories; if (count($subcats) <= 1) { if (count($subcats) == 1) { $subcat_id = $subcats[0]->id; } else { //create one $new_subcat = new Xerxes_Data_Subcategory(); $new_subcat->sequence = 1; $new_subcat->category_id = $existingSubject->id; $new_subcat->name = $this->registry->getConfig("default_collection_section_name", false, "Databases"); $new_subcat = $objData->addUserCreatedSubcategory($new_subcat); $subcat_id = $new_subcat->id; } $fixedUrl = $this->request->url_for(array("base" => "collections", "action" => "save_complete", "subject" => $existingSubject->normalized, "subcategory" => $subcat_id, "id" => $this->request->getProperty("id"), "username" => $strUsername, "return" => $this->request->getProperty("return")), true); // force full url for redirect $this->request->setRedirect($fixedUrl); } return 1; }
public function doExecute() { //Cancel? $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); if ($this->request->getProperty("cancel")) { $this->returnWithMessage($this->getLabel("text_collections_cancelled"), $arrDefaultReturn); return 1; } $strSubject = $this->request->getProperty("subject"); $strSubcatID = $this->request->getProperty("subcategory"); $strUsername = $this->request->getProperty("username"); $strNewName = $this->request->getProperty("new_name"); if (empty($strNewName)) { $this->returnWithMessage($this->getLabel("text_collections_blank_name"), $arrDefaultReturn); return 1; } // make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); if (!empty($strSubcatID)) { // rename a subcategory $subcat = $this->getSubcategory($category, $strSubcatID); $subcat->name = $strNewName; $objData->updateUserSubcategoryProperties($subcat); } else { // rename category $category->name = $strNewName; $objData->updateUserCategoryProperties($category); } // new name if it's been changed! $arrDefaultReturn["subject"] = $category->normalized; $this->returnWithMessage($this->getLabel("text_collections_renamed"), $arrDefaultReturn); return 1; }
public function doExecute() { $lang = $this->request->getProperty("lang"); // main list of subcategories and databases $objXml = new DOMDocument(); $objXml->loadXML("<category />"); // list of subcategories that should go in the sidebar $objSidebar = new DOMDocument(); $objSidebar->loadXML("<sidebar />"); $strOld = $this->request->getProperty("category"); $strSubject = $this->request->getProperty("subject"); $configSidebar = $this->registry->getConfig("SUBCATEGORIES_SIDEBAR", false, null, $lang); $arrSidebar = explode(",", $configSidebar); // look up home page default subject from config if no subject was specified, and we were // instructed to look it up with use_categories_quicksearch=true if ($strSubject == "" && $this->request->getProperty("use_categories_quicksearch") == "true") { $strSubject = $this->registry->getConfig("categories_quicksearch", false, "quick-search", $lang); } $objData = new Xerxes_DataMap(); $objCategoryData = $objData->getSubject($strSubject, $strOld, "metalib", null, $lang); $y = 1; if ($objCategoryData != null) { $objXml->documentElement->setAttribute("name", $objCategoryData->name); $objXml->documentElement->setAttribute("normalized", $objCategoryData->normalized); // standard url for the category $arrParams = array("base" => "databases", "action" => "subject", "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objXml->documentElement->appendChild($objElement); // the attributes of the subcategories $db_list_index = 1; foreach ($objCategoryData->subcategories as $objSubData) { $objSubCategory = $objXml->createElement("subcategory"); $objSubCategory->setAttribute("name", $objSubData->name); $objSubCategory->setAttribute("position", $y); $objSubCategory->setAttribute("id", $objSubData->id); $y++; // the database information foreach ($objSubData->databases as $objDatabaseData) { $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry, $db_list_index); $objDatabase = $objXml->importNode($objDatabase, true); $objSubCategory->appendChild($objDatabase); } // if marked for the sidebar, put it there if (in_array($objSubData->name, $arrSidebar)) { $objImport = $objSidebar->importNode($objSubCategory, true); $objSidebar->documentElement->appendChild($objImport); } else { $objXml->documentElement->appendChild($objSubCategory); } } } $this->request->addDocument($objXml); $this->request->addDocument($objSidebar); return 1; }
public function doExecute() { $strNormalizedSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); // Find the category $category = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $objData->deleteUserCreatedCategory($category); // Send them back where they came from, with a message. $this->returnWithMessage($this->getLabel("text_collections_deleted_category", $category->name), array("base" => "collections", "action" => "list", "username" => $strUsername)); return 1; }
public function doExecute() { // cancel? $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); if ($this->request->getProperty("cancel")) { $this->returnWithMessage($this->getLabel("text_collections_cancelled"), $arrDefaultReturn); return 1; } $strSubject = $this->request->getProperty("subject"); $strSubcatID = $this->request->getProperty("subcategory"); $strPublished = $this->request->getProperty("published"); $strUsername = $this->request->getProperty("username"); $strNewName = $this->request->getProperty("new_name"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $message = ""; if (!empty($strSubcatID)) { // edit a subcategory, rename $subcat = $this->getSubcategory($category, $strSubcatID); if (!empty($strNewName)) { $message .= "Section name changed. "; $subcat->name = $strNewName; $objData->updateUserSubcategoryProperties($subcat); } } else { // edit a category: rename/publish if (!empty($strNewName)) { $category->name = $strNewName; $message .= $this->getLabel("text_collections_name_changed"); } if (!empty($strPublished)) { $boolPublished = (int) ($strPublished == "true"); $category->published = $boolPublished; if ($boolPublished) { $message .= $this->getLabel("text_collections_made_published"); } else { $message .= $this->getLabel("text_collections_made_private"); } } $objData->updateUserCategoryProperties($category); } // new name if it's been changed! $arrDefaultReturn["subject"] = $category->normalized; $this->returnWithMessage($message, $arrDefaultReturn); return 1; }
public function doExecute() { $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); $strSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); // make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); // find any new assigned numbers, and reorder. $orderedSubcats = $category->subcategories; // we need to through the assignments in sorted order by sequence choice, // for this to work right. $sortedProperties = $this->request->getAllProperties(); asort($sortedProperties); foreach ($sortedProperties as $name => $new_sequence) { $matches = array(); if (!empty($new_sequence) && preg_match('/^subcat_seq_(\\d+)$/', $name, $matches)) { $subcatID = $matches[1]; $old_index = null; $subcategory = null; for ($i = 0; $i < count($orderedSubcats); $i++) { $candidate = $orderedSubcats[$i]; if ($candidate->id == $subcatID) { $old_index = $i; $subcategory = $candidate; } } // if we found it. if ($subcategory) { // remove it from the array, then add it back in array_splice($orderedSubcats, $old_index, 1); array_splice($orderedSubcats, $new_sequence - 1, 0, array($subcategory)); } } } // okay, we've re-ordered $orderedSubcats, now update the sequence #s for ($i = 0; $i < count($orderedSubcats); $i++) { $subcategory = $orderedSubcats[$i]; $subcategory->sequence = $i + 1; $objData->updateUserSubcategoryProperties($subcategory); } $this->returnWithMessage($this->getLabel("text_collections_section_order_changed"), $arrDefaultReturn); return 1; }
public function doExecute() { $strNormalizedSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); $strDatabaseID = $this->request->getProperty("id"); $strSubcatID = $this->request->getProperty("subcategory"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $subcategory = null; // Find the category $category = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $subcategory = $this->getSubcategory($category, $strSubcatID); $objData->removeDatabaseFromUserCreatedSubcategory($strDatabaseID, $subcategory); // Send them back where they came from, with a message. $this->returnWithMessage($this->getLabel("text_collections_removed_database")); return 1; }
public function doExecute() { $strNewSubject = $this->request->getProperty("new_subject_name"); if (empty($strNewSubject)) { $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases"); } $strUsername = $this->request->getProperty("username"); $strNewSubcategory = $this->request->getProperty("new_subcategory_name"); if ($this->request->getProperty("action") == "save_complete") { // Nevermind, don't do it. $strNewSubcategory = null; } // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $existingSubject = null; // Make sure it's truly new and has a unique normalized form, else // reuse existing. This takes care of browser-refresh, or typing in the identical // name of an already existing one. $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject); $existingSubject = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); // if we found a dupe, we'll use that, otherwise create one. if (!$existingSubject) { $objDataCategory = new Xerxes_Data_Category(); $objDataCategory->name = $strNewSubject; $objDataCategory->username = $strUsername; $objDataCategory->normalized = $strNormalizedSubject; $objDataCategory->published = 0; $existingSubject = $objData->addUserCreatedCategory($objDataCategory); } // and create an initial section, please. if ($strNewSubcategory && !$this->request->getProperty("format") == "json") { $subcategory = new Xerxes_Data_Subcategory(); $subcategory->name = $strNewSubcategory; $subcategory->category_id = $existingSubject->id; $subcategory->sequence = 1; $subcategory = $objData->addUserCreatedSubcategory($subcategory); } // send them off to the edit_mode of their new category. $newUrl = $this->request->url_for(array("base" => "collections", "action" => "subject", "username" => $this->request->getProperty("username"), "subject" => $existingSubject->normalized), true); // force full url for redirect $this->request->setRedirect($newUrl); return 1; }
public function doExecute() { $objXml = new DOMDOcument(); $objXml->loadXML("<category />"); $strSubject = $this->request->getProperty("subject"); $strUser = $this->request->getProperty("username"); $objData = new Xerxes_DataMap(); $objCategoryData = null; // only fetch if we actually have params, avoid the fetch-everything phenomena if ($strSubject && $strUser) { $objCategoryData = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUser); } // if there hasn't if (!$objCategoryData) { if ($this->request->getRedirect()) { // nevermind, we're in the creation process, already redirected, // just end now. return 1; } else { throw new Xerxes_Exception_NotFound("text_collections_error_personal_collection_not_found"); } } // make sure they have access if (!$objCategoryData->published) { Xerxes_Helper::ensureSpecifiedUser($objCategoryData->owned_by_user, $this->request, $this->registry, "text_collections_error_private_collection"); } $y = 1; if ($objCategoryData != null) { $objXml->documentElement->setAttribute("name", $objCategoryData->name); $objXml->documentElement->setAttribute("normalized", $objCategoryData->normalized); $objXml->documentElement->setAttribute("owned_by_user", $objCategoryData->owned_by_user); $objXml->documentElement->setAttribute("published", $objCategoryData->published); // we treat the 'default' collection (usually 'My Saved Records') special // giving it less flexibility for simplicity, in the XSL/javascript. if ($this->isDefaultCollection($objCategoryData)) { $objXml->documentElement->setAttribute("is_default_collection", "yes"); } // standard url for the category $arrParams = array("base" => "collections", "action" => "subject", "username" => $strUser, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objXml->documentElement->appendChild($objElement); //edit url for the user-created category $arrParams = array("base" => "collections", "action" => "edit_form", "username" => $strUser, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("edit_url", $url); $objXml->documentElement->appendChild($objElement); // the attributes of the subcategories $db_list_index = 1; foreach ($objCategoryData->subcategories as $objSubData) { $objSubCategory = $objXml->createElement("subcategory"); $objSubCategory->setAttribute("name", $objSubData->name); $objSubCategory->setAttribute("position", $y); $objSubCategory->setAttribute("id", $objSubData->id); $y++; // the database information foreach ($objSubData->databases as $objDatabaseData) { $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry, $db_list_index); $objDatabase = $objXml->importNode($objDatabase, true); $objSubCategory->appendChild($objDatabase); } $objXml->documentElement->appendChild($objSubCategory); } } $this->request->addDocument($objXml); return 1; }
public function doExecute() { // metalib search object $objSearch = $this->getSearchObject(); // params from the request $strQuery = $this->request->getProperty("query"); $strQuery2 = $this->request->getProperty("query2"); $strField = $this->request->getProperty("field"); $strField2 = $this->request->getProperty("field2"); $strFindOperator = $this->request->getProperty("find_operator1"); $arrDatabases = $this->request->getProperty("database", true); $strSubject = $this->request->getProperty("subject"); $strSpell = $this->request->getProperty("spell"); $strContext = $this->request->getProperty("context"); $strContextUrl = $this->request->getProperty("context_url"); // configuration options $configNormalize = $this->registry->getConfig("NORMALIZE_QUERY", false, false); $configBaseUrl = $this->registry->getConfig("BASE_URL", true); $configYahooID = $this->registry->getConfig("YAHOO_ID", false, "calstate"); $configSearchLimit = $this->registry->getConfig("SEARCH_LIMIT", true); $configContextUrl = $this->registry->getConfig("LIMIT_CONTEXT_URL", false); // if so configured, ensure that context_url is limited to certain domain(s) if ($configContextUrl != null) { $bolPassed = Xerxes_Framework_Parser::withinDomain($strContextUrl, $configContextUrl); if ($bolPassed == false) { throw new Exception("context_url only allowed for specified domains"); } } // database communications object $objData = new Xerxes_DataMap(); // if subject is given but not databases, automatically find // databases for subject, from first sub-category. if ($strSubject != null && count($arrDatabases) == 0) { $search_limit = $this->registry->getConfig("SEARCH_LIMIT", true); $arrDatabases = array(); $objSubject = $objData->getSubject(strtolower($strSubject), null, "metalib", null, $this->request->getProperty("lang")); // did we find a subject that has subcategories? if ($objSubject != null && $objSubject->subcategories != null && count($objSubject->subcategories) > 0) { $subs = $objSubject->subcategories; $objSubcategory = $subs[0]; $index = 0; // get databases up to search limit from first subcat, // add to $arrdatabases. foreach ($objSubcategory->databases as $objDatabaseData) { if ($objDatabaseData->searchable == 1) { array_push($arrDatabases, $objDatabaseData->metalib_id); $index++; } if ($index >= $search_limit) { break; } } } } // if we have a subject, but no context/contexturl, look // them up for the subject. Allows convenient defaults // for direct-linking into search results. if ($strContext == "" && $strSubject != "") { // look up the subject if we haven't already, to get the name. if (!isset($objSubject)) { $objSubject = $objData->getSubject($strSubject); } $strContext = $objSubject->name; } if ($strContextUrl == "" && $strSubject != "") { $strContextUrl = $this->request->url_for(array("base" => "databases", "action" => "subject", "subject" => $strSubject)); } // ensure a query and field if ($strQuery == "") { throw new Exception("text_metasearch_error_no_search_terms"); } if ($strField == "") { $strField = "WRD"; } if ($strField2 == "") { $strField2 = "WRD"; } if ($strFindOperator == "") { $strFindOperator = "AND"; } // get databases $arrDB = $objData->getDatabases($arrDatabases); // start out database information xml object. $objXml = new DOMDocument(); $objXml->loadXML("<search />"); // access control for databases $excludedDbs = array(); $excludedIDs = array(); foreach ($arrDB as $db) { if (!Xerxes_Helper::dbSearchableForUser($db, $this->request, $this->registry)) { $excludedDbs[] = $db; $excludedIDs[] = (string) $db->metalib_id; } } if (count($excludedDbs) > 0) { // remove excluded dbs from our db lists. what a pain in php, sorry. foreach ($arrDB as $key => $db) { if (in_array((string) $db->metalib_id, $excludedIDs)) { unset($arrDB[$key]); } } foreach ($arrDatabases as $key => $id) { if (in_array($id, $excludedIDs)) { unset($arrDatabases[$key]); } } // and make a note of the excluded dbs please. $excluded_xml = $objXml->createElement("excluded_dbs"); $objXml->documentElement->appendChild($excluded_xml); foreach ($excludedDbs as $db) { $element = Xerxes_Helper::databaseToNodeset($db, $this->request, $this->registry); $element = $objXml->importNode($element, true); $excluded_xml->appendChild($element); } } // ensure correct number of databases selected if (count($arrDatabases) < 1 && count($excludedDbs) > 0) { $e = new Xerxes_Exception_DatabasesDenied("text_metasearch_error_not_authorized"); $e->setDeniedDatabases($excludedDbs); throw $e; } elseif (count($arrDatabases) < 1) { throw new Exception("text_metasearch_error_no_databases"); } if (count($arrDatabases) > $configSearchLimit) { $labels = Xerxes_Framework_Labels::getInstance(); $error = $labels->getLabel("text_metasearch_error_too_many_databases"); $error = sprintf($error, $configSearchLimit); throw new Exception($error); } $strSpellCorrect = ""; // spelling correction $strSpellUrl = ""; // return url for spelling change $strGroup = ""; // group id number $strNormalizedQuery = ""; // normalized query // query parser provides normalization and spell check $objQueryParser = new Xerxes_QueryParser(); // normalize query option is still experimental (2009-04-16) $strFullQuery = $objQueryParser->normalizeMetalibQuery($strField, $strQuery, $strFindOperator, $strField2, $strQuery2, $configNormalize); // initiate search with Metalib $strGroup = $objSearch->search($strFullQuery, $arrDatabases); // something went wrong, yo! if ($strGroup == "") { throw new Exception("Could not initiate search with Metalib server"); } // check spelling unless this is a return submission from a previous spell correction $strSpellSuggestions = null; if ($strSpell == null) { // check spelling $strAltYahoo = $this->registry->getConfig("ALTERNATE_YAHOO_LOCATION", false); $strSpellCorrect = $objQueryParser->checkSpelling($strQuery, $configYahooID, $strAltYahoo); $strSpellCorrect2 = null; if ($strQuery2) { $strSpellCorrect2 = $objQueryParser->checkSpelling($strQuery2, $configYahooID); } if ($strSpellCorrect != "" || $strSpellCorrect2 != "") { // construct spell check return url with spelling suggestion // If both search fields were used (advanced search), spell corrections // may be in first, second, or both. $strNewQuery = $strQuery; $arrSuggestions = array(); if ($strSpellCorrect) { $strNewQuery = $strSpellCorrect; array_push($arrSuggestions, $strSpellCorrect); } $strNewQuery2 = $strQuery2; if ($strSpellCorrect2) { $strNewQuery2 = $strSpellCorrect2; array_push($arrSuggestions, $strSpellCorrect2); } $strSpellSuggestions = join(" ", $arrSuggestions); $strSpellUrl = "./?base=metasearch&action=search&spell=1&query=" . urlencode($strNewQuery) . "&field=" . $strField; if ($strNewQuery2) { $strSpellUrl .= "&query2=" . urlencode($strNewQuery2) . "&field2=" . $strField2; } $strSpellUrl .= "&context=" . urlencode($strContext); $strSpellUrl .= "&context_url=" . urlencode($strContextUrl); foreach ($arrDatabases as $strDatabase) { if ($strDatabase != null) { $strSpellUrl .= "&database=" . $strDatabase; } } } } // create search information xml $arrSearch = array(); $arrSearch["date"] = date("Y-m-d"); $arrSearch["spelling"] = $strSpellSuggestions; $arrSearch["spelling_url"] = $strSpellUrl; $arrSearch["context"] = $strContext; $arrSearch["context_url"] = $strContextUrl; foreach ($arrSearch as $key => $value) { $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value)); $objXml->documentElement->appendChild($objElement); } $objPair = $objXml->createElement("pair"); $objPair->setAttribute("position", 1); $objXml->documentElement->appendChild($objPair); $arrQuery = array(); $arrQuery["query"] = $strQuery; $arrQuery["field"] = $strField; $arrQuery["normalized"] = $strFullQuery; foreach ($arrQuery as $key => $value) { $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value)); $objPair->appendChild($objElement); } // add second pair if present. if ($strQuery2) { $objOperator = $objXml->createElement("operator", $strFindOperator); $objOperator->setAttribute("position", 1); $objXml->documentElement->appendChild($objOperator); $objPair = $objXml->createElement("pair"); $objPair->setAttribute("position", 2); $objXml->documentElement->appendChild($objPair); $arrQuery = array(); $arrQuery["query"] = $strQuery2; $arrQuery["field"] = $strField2; foreach ($arrQuery as $key => $value) { $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value)); $objPair->appendChild($objElement); } } // get links from ird records for those databases that have been included in the search and // store it here so we can get at this information easily on any subsequent page without having // to go back to the database $objDatabaseLinks = $objXml->createElement("database_links"); $objXml->documentElement->appendChild($objDatabaseLinks); foreach ($arrDB as $objDatabase) { // create a database node and append to database_links $objNodeDatabase = Xerxes_Helper::databaseToLinksNodeset($objDatabase, $this->request, $this->registry); $objNodeDatabase = $objXml->importNode($objNodeDatabase, true); $objDatabaseLinks->appendChild($objNodeDatabase); } // add any warnings from metalib $objWarnings = $objSearch->getWarnings(); if ($objWarnings != null) { $objImport = $objXml->importNode($objWarnings->documentElement, true); $objXml->documentElement->appendChild($objImport); } $strGroup = $this->getSearchDate() . "-" . $strGroup; // save this information in the cache $this->setCache($strGroup, "search", $objXml); // redirect to hits page $arrParams = array("base" => "metasearch", "action" => "hits", "group" => $strGroup); $this->saveCache(); $this->request->setRedirect($this->request->url_for($arrParams)); return 1; }
public function doExecute() { $strNormalizedSubject = $this->request->getProperty("subject"); // If that was set to "NEW" then, we have a newly created subject, // already created by a prior command in execution chain, but we // need to make sure to look it up properly. if ($strNormalizedSubject == "NEW") { $strNormalizedSubject = Xerxes_Data_Category::normalize($this->request->getProperty("new_subject_name")); } $strUsername = $this->request->getProperty("username"); $strDatabaseID = $this->request->getProperty("id"); $strSubcatSelection = $this->request->getProperty("subcategory"); $strNewSubcat = $this->request->getProperty("new_subcategory_name"); // make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $subcategory = null; // find the category $category = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); // to do. Create silently if not found? if (!$category) { throw new Exception("text_collections_error_no_such_category"); } // were we directed to create a new one? if ($strNewSubcat || $strSubcatSelection == "NEW") { if (empty($strNewSubcat)) { $strNewSubcat = "Databases"; } $subcategory = new Xerxes_Data_Subcategory(); $subcategory->name = $strNewSubcat; $subcategory->category_id = $category->id; // just put it at the end $last_one = $category->subcategories[count($category->subcategories) - 1]; $subcategory->sequence = $last_one->sequence + 1; $subcategory = $objData->addUserCreatedSubcategory($subcategory); } // if no db id was provided, all we needed to do was create a subcategory. if (!$strDatabaseID) { $this->returnWithMessage($this->getLabel("text_collections_section_new")); return 1; } // if we don't have a subcategory object from having just created one, find it from categories children. if (!$subcategory) { foreach ($category->subcategories as $s) { if ($s->id == $strSubcatSelection) { $subcategory = $s; } } } // now we better have one. if (!$subcategory) { throw new Exception("text_collections_error_no_such_section"); } // and add the db to it, unless it already is there. foreach ($subcategory->databases as $db) { if ($db->metalib_id == $strDatabaseID) { $this->returnWithMessage($this->getLabel("text_collections_database_already_saved", $subcategory->name, $category->name)); return 1; } } $objData->addDatabaseToUserCreatedSubcategory($strDatabaseID, $subcategory); // send them back where they came from, with a message. $this->returnWithMessage($this->getLabel("text_collections_database_saved", $category->name)); return 1; }