public function doExecute() { // get properties from request $strUsername = $this->request->getSession("username"); $strGroup = $this->request->getProperty("group"); $strResultSet = $this->request->getProperty("resultSet"); $iStartRecord = $this->request->getProperty("startRecord"); // get the search start date $objSearchXml = $this->getCache($strGroup, "search", "SimpleXML"); $strDate = (string) $objSearchXml->date; // construct a fully unique id for metalib record based on // date, resultset, and startrecord numbers $strID = ""; $strID = $strDate . ":"; $strID .= $strResultSet . ":"; $strID .= str_pad($iStartRecord, 6, "0", STR_PAD_LEFT); // the save and delete action come in on the same onClick event from the search results page, // so we have to check here to see if it is a delete or save based on the session. This is a // bit dangerous, since maybe the session got out of sync? Oh well, it'll do for now, since // that's what was done with the previous cookie implementation. $objData = new Xerxes_DataMap(); $bolAdd = !$this->isMarkedSaved($strResultSet, $iStartRecord); $strInsertedId = null; if ($bolAdd == true) { // add command // get record from metalib result set $objXerxesRecord = new Xerxes_MetalibRecord(); $objXerxesRecord->loadXML($this->getRecord()); // add to database $objData->addRecord($strUsername, "metalib", $strID, $objXerxesRecord); $strInsertedId = $objXerxesRecord->id; // mark saved for feedback on search results $this->markSaved($objXerxesRecord); } else { // delete command $objData->deleteRecordBySource($strUsername, "metalib", $strID); $this->unmarkSaved($strResultSet, $iStartRecord); } // build a response $objXml = new DOMDocument(); $objXml->loadXML("<results />"); if ($bolAdd == false) { // flag this as being a delete comand in the view, in the event // user has javascript turned off and we need to show them an actual page $objDelete = $objXml->createElement("delete", "1"); $objXml->documentElement->appendChild($objDelete); } else { // add inserted id for ajax response $objInsertedId = $objXml->createElement("savedRecordID", $strInsertedId); $objXml->documentElement->appendChild($objInsertedId); } $this->request->addDocument($objXml); return 1; }
public function doExecute() { // ensure this is the same user $strRedirect = $this->enforceUsername(); if ($strRedirect != null) { $this->request->setRedirect($strRedirect); return 1; } // get request parameters and configuration settings $strUsername = $this->request->getSession("username"); $strSource = $this->request->getProperty("source"); $strID = $this->request->getProperty("id"); // params for deciding where to send the user back $strType = $this->request->getProperty("type"); $strLabel = $this->request->getProperty("label"); $iStart = $this->request->getProperty("startRecord"); $iTotal = $this->request->getProperty("total"); $iCount = $this->request->getProperty("recordsPerPage"); $strSort = $this->request->getProperty("sortKeys"); // ensure we send user back to a page with actual results! if ($iTotal == 1 && ($strLabel != "" || $strType != "")) { // if this is the last result in a tag or format grouping, then // simply redirect back to the folder home page $arrParams = array("base" => "folder", "action" => "home", "sortKeys" => $strSort, "username" => $this->request->getSession("username")); } else { // if the last record in the results is also the last one on // the page (of 10 or whatever), send the user back to an // earlier page with results on it if ($iStart > $iCount && $iStart == $iTotal) { $iStart = $iStart - $iCount; } $arrParams = array("base" => "folder", "action" => "home", "username" => $this->request->getSession("username"), "type" => $strType, "label" => $strLabel, "sortKeys" => $strSort, "startRecord" => $iStart); } $strReturn = $this->request->url_for($arrParams); // delete the record from the database $objData = new Xerxes_DataMap(); $objData->deleteRecordBySource($strUsername, $strSource, $strID); // update the session // Sorry this gets a bit confusing, the api hasn't stayed entirely consistent. $resultSet = ""; $recordNumber = $strID; $id = explode(':', $strID); // metalib if (count($id) > 1) { $resultSet = $id[1]; $recordNumber = $id[2]; } Xerxes_Helper::unmarkSaved($resultSet, $recordNumber); // send the user back out, so they don't step on this again $this->request->setRedirect($strReturn); return 1; }