public function doExecute()
 {
     // if supplied in url, use that (for future API use)
     $username = $this->request->getProperty("username");
     if (!$username) {
         // default to logged in user
         $username = $this->request->getSession("username");
     }
     // default names for if we have to create a new category.
     // can be sent with HTTP request, otherwise we have hard coded defaults.
     $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases");
     $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject);
     // we can only do this if we have a real user (not temp user)
     if ($username == null || !Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) {
         throw new Xerxes_Exception_AccessDenied("text_collections_error_not_logged_in");
     }
     $objData = new Xerxes_DataMap();
     //$arrResults = $objData->getUserCreatedCategories($username, "id");
     $arrResults = $objData->getUserCreatedCategories($username);
     // find the default one, if present.
     $redirectCategory = null;
     for ($i = 0; $i < count($arrResults); $i++) {
         $iCat = $arrResults[$i];
         if ($iCat->normalized == $strNormalizedSubject) {
             $redirectCategory = $iCat;
             break;
         }
     }
     // Couldn't find it? Have to make one.
     if (empty($redirectCategory)) {
         //Create one
         $redirectCategory = $this->addDefaultCollection($objData, $username);
     }
     /*  This doesn't work right yet, although it's a nice idea. 
         else {
           // Okay, let's make sure our default category has at least one
           // section, which it always ought to, but data corruption sometimes,
           // and we can fix it up. Got to refetch it to get it's subcategories.
           
           $redirectCategory = $objData->getSubject( $redirectCategory->normalized, null, Xerxes_DataMap::userCreatedMode, $redirectCategory->username);
           
           if ( count($redirectCategory->subcategories) == 0) {
             // add the default one 
             $this->addDefaultSubcategory($objData, $redirectCategory);
           }
         }*/
     // and redirect
     $url = $this->request->url_for(array('base' => 'collections', 'action' => 'subject', 'username' => $username, 'subject' => $redirectCategory->normalized));
     $this->request->setRedirect($url);
     return 1;
 }
 public function doExecute()
 {
     // If supplied in URL, use that (for future API use).
     // Nevermind, this is a privacy problem until we right access
     // controls for that future API use.
     //$username = $this->request->getProperty("username");
     //if ( ! $username ) {
     // default to logged in user
     $username = $this->request->getSession("username");
     //}
     // we can only do this if we have a real user (not temp user), otherwise
     // just add no XML.
     if ($username == null || !Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) {
         return 0;
     }
     $objXml = new DOMDOcument();
     $objData = new Xerxes_DataMap();
     $arrResults = $objData->getUserCreatedCategories($username);
     $x = 1;
     if (count($arrResults) > 0) {
         $objXml->loadXML("<userCategories />");
         foreach ($arrResults as $objCategoryData) {
             $objCategory = $objXml->createElement("category");
             $objCategory->setAttribute("position", $x);
             foreach ($objCategoryData->properties() as $key => $value) {
                 if ($value != null) {
                     $objElement = $objXml->createElement("{$key}", Xerxes_Framework_Parser::escapeXml($value));
                     $objCategory->appendChild($objElement);
                 }
             }
             // add the url for the category
             $arrParams = array("base" => "collections", "action" => "subject", "username" => $username, "subject" => $objCategoryData->normalized);
             $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams));
             $objElement = $objXml->createElement("url", $url);
             $objCategory->appendChild($objElement);
             $objXml->documentElement->appendChild($objCategory);
             $x++;
         }
     }
     $this->request->addDocument($objXml);
     return 1;
 }