public function doExecute() { $strUsername = $this->request->getProperty("username"); if (empty($strUsername)) { //default to logged in user $strUsername = $this->request->getSession("username"); } $objData = new Xerxes_DataMap(); $existingCategoryNames = $this->request->getData('/*/userCategories/category/normalized', null, 'ARRAY'); if (count($existingCategoryNames) <= 1) { if (count($existingCategoryNames) == 1) { $normalized_name = $existingCategoryNames[0]; } else { // create a new one $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases"); $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject); $newCategory = new Xerxes_Data_Category(); $newCategory->name = $strNewSubject; $newCategory->username = $strUsername; $newCategory->normalized = $strNormalizedSubject; $newCategory->published = 0; $newCategory = $objData->addUserCreatedCategory($newCategory); $normalized_name = $newCategory->normalized; } // redirect past the category selection page $fixedUrl = $this->request->url_for(array("base" => "collections", "action" => "save_choose_subheading", "subject" => $normalized_name, "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() { $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; }