Exemplo n.º 1
0
 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;
 }
 protected function addDefaultCollection($objData, $username)
 {
     $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases");
     $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject);
     $redirectCategory = new Xerxes_Data_Category();
     $redirectCategory->name = $strNewSubject;
     $redirectCategory->username = $username;
     $redirectCategory->normalized = $strNormalizedSubject;
     $redirectCategory->published = 0;
     $newCollection = $objData->addUserCreatedCategory($redirectCategory);
     //And give it a section
     $this->addDefaultSubcategory($objData, $newCollection);
     return $newCollection;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 /**
  * Is the collection the default one? We tell by seeing if it's name matches
  * the default name. 
  *
  * @param unknown_type $objCategoryData
  * @return unknown
  */
 public function isDefaultCollection($objCategoryData)
 {
     return $objCategoryData->normalized == Xerxes_Data_Category::normalize($this->registry->getConfig("default_collection_name", false, "My Saved Databases"));
 }
Exemplo n.º 5
0
 /**
  * Get user-created categories for specified user. 
  * @param string $username
  * @return array		array of Xerxes_Data_Category objects
  */
 public function getUserCreatedCategories($username)
 {
     if (!$username) {
         throw new Exception("Must supply a username argument");
     }
     $arrCategories = array();
     $strSQL = "SELECT * from xerxes_user_categories WHERE username = :username ORDER BY UPPER(name) ASC";
     $arrResults = $this->select($strSQL, array(":username" => $username));
     foreach ($arrResults as $arrResult) {
         $objCategory = new Xerxes_Data_Category();
         $objCategory->load($arrResult);
         array_push($arrCategories, $objCategory);
     }
     return $arrCategories;
 }
Exemplo n.º 6
0
 private function normalizeOld($strSubject)
 {
     return Xerxes_Data_Category::normalize($strSubject);
 }
 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;
 }