예제 #1
0
 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;
 }
예제 #2
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;
 }
 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;
 }