/**
  * Create and return a representation node. Extend the parent class
  * with publication format specific data.
  * @param $doc DOMDocument
  * @param $representation Representation
  * @return DOMElement
  */
 function createRepresentationNode($doc, $representation)
 {
     $representationNode = parent::createRepresentationNode($doc, $representation);
     $representationNode->setAttribute('approved', $representation->getIsApproved() ? 'true' : 'false');
     $representationNode->setAttribute('available', $representation->getIsAvailable() ? 'true' : 'false');
     $representationNode->setAttribute('physical_format', $representation->getPhysicalFormat() ? 'true' : 'false');
     // If all nexessary press settings exist, export ONIX metadata
     $context = $this->getDeployment()->getContext();
     if ($context->getSetting('publisher') && $context->getSetting('location') && $context->getSetting('codeType') && $context->getSetting('codeValue')) {
         $submission = $this->getDeployment()->getSubmission();
         $filterDao = DAORegistry::getDAO('FilterDAO');
         $nativeExportFilters = $filterDao->getObjectsByGroup('monograph=>onix30-xml');
         assert(count($nativeExportFilters) == 1);
         // Assert only a single serialization filter
         $exportFilter = array_shift($nativeExportFilters);
         $exportFilter->setDeployment(new Onix30ExportDeployment(Request::getContext(), Request::getUser()));
         $onixDoc = $exportFilter->execute($submission);
         if ($onixDoc) {
             // we do this to ensure validation.
             // assemble just the Product node we want.
             $publicationFormatDOMElement = $exportFilter->createProductNode($doc, $submission, $representation);
             if ($publicationFormatDOMElement instanceof DOMElement) {
                 import('lib.pkp.classes.xslt.XSLTransformer');
                 $xslTransformer = new XSLTransformer();
                 $xslFile = 'plugins/importexport/native/onixProduct2NativeXml.xsl';
                 $productXml = $publicationFormatDOMElement->ownerDocument->saveXML($publicationFormatDOMElement);
                 $filteredXml = $xslTransformer->transform($productXml, XSL_TRANSFORMER_DOCTYPE_STRING, $xslFile, XSL_TRANSFORMER_DOCTYPE_FILE, XSL_TRANSFORMER_DOCTYPE_STRING);
                 $representationFragment = $doc->createDocumentFragment();
                 $representationFragment->appendXML($filteredXml);
                 $representationNode->appendChild($representationFragment);
             }
         }
     }
     return $representationNode;
 }
Example #2
0
 /**
  * Create a new notification with the specified arguments and insert into DB
  * This is a static method
  * @param $userId int
  * @param $contents string
  * @param $param string
  * @param $location string
  * @param $isLocalized bool
  * @param $assocType int
  * @param $assocId int
  * @return Notification object
  */
 function createNotification($userId, $contents, $param, $location, $isLocalized, $assocType)
 {
     $notification = new Notification();
     $context =& Request::getContext();
     $contextId = $context->getId();
     $notification->setUserId($userId);
     $notification->setContents($contents);
     $notification->setParam($param);
     $notification->setLocation($location);
     $notification->setIsLocalized($isLocalized);
     $notification->setAssocType($assocType);
     $notification->setContext($contextId);
     $notificationDao =& DAORegistry::getDAO('NotificationDAO');
     $notificationDao->insertNotification($notification);
     return $notification;
 }
Example #3
0
 public static function assetController()
 {
     $p = Request::getPath();
     if (Request::getContext() == 'css') {
         $file = 'css/' . $p[count($p) - 1] . '.css.twig';
         if (file_exists(Asset . $file)) {
             return self::$twig->render($file);
         }
     } else {
         if (Request::getContext() == 'js') {
             $file = Asset . 'js/' . $p[count($p) - 1] . '.js';
             if (file_exists($file)) {
                 return file_get_contents($file);
             }
         }
     }
     return '';
 }
 /**
  * Retrieve Notes by assoc id/type
  * @param $assocId int
  * @param $assocType int
  * @param $userId int
  * @return object DAOResultFactory containing matching Note objects
  */
 function &getByAssoc($assocType, $assocId, $userId = null)
 {
     $application =& PKPApplication::getApplication();
     $productName = $application->getName();
     $context =& Request::getContext();
     $contextId = $context ? $context->getId() : 0;
     $params = array((int) $assocId, (int) $assocType, (int) $contextId);
     if (isset($userId)) {
         $params[] = (int) $userId;
     }
     $sql = 'SELECT * FROM notes WHERE assoc_id = ? AND assoc_type = ? AND context_id = ?';
     if (isset($userId)) {
         $sql .= ' AND user_id = ?';
     }
     $sql .= ' ORDER BY date_created DESC';
     $result =& $this->retrieveRange($sql, $params);
     $returner = new DAOResultFactory($result, $this, '_returnNoteFromRow');
     return $returner;
 }
 /**
  * Send an update to all users on the mailing list
  * @param $notification object Notification
  */
 function sendToMailingList($notification)
 {
     $notificationSettingsDao =& DAORegistry::getDAO('NotificationSettingsDAO');
     $mailList = $notificationSettingsDao->getMailList();
     Locale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON));
     foreach ($mailList as $email) {
         if ($notification->getIsLocalized()) {
             $params = array('param' => $notification->getParam());
             $notificationContents = Locale::translate($notification->getContents(), $params);
         } else {
             $notificationContents = $notification->getContents();
         }
         import('mail.MailTemplate');
         $context =& Request::getContext();
         $site =& Request::getSite();
         $mail = new MailTemplate('NOTIFICATION_MAILLIST');
         $mail->setFrom($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
         $mail->assignParams(array('notificationContents' => $notificationContents, 'url' => $notification->getLocation(), 'siteTitle' => $context->getLocalizedTitle(), 'unsubscribeLink' => Request::url(null, 'notification', 'unsubscribeMailList')));
         $mail->addRecipient($email);
         $mail->send();
     }
 }
Example #6
0
 /**
  * Sanitize and save a theme option
  *
  * @param $name string A unique id for the option to save
  * @param $value mixed The new value to save
  * @param $contextId int Optional context id. Defaults to the current
  *  context
  */
 public function saveOption($name, $value, $contextId = null)
 {
     $option = !empty($this->options[$name]) ? $this->options[$name] : null;
     if (is_null($option)) {
         return $this->parent ? $this->parent->saveOption($name, $value, $contextId) : false;
     }
     $type = '';
     switch ($option['type']) {
         case 'text':
         case 'select':
         case 'colour':
             $type = 'text';
             break;
     }
     if (is_null($contextId)) {
         $context = Request::getContext();
         $contextId = $context->getId();
     }
     $this->updateSetting($contextId, $name, $value, $type);
     // Clear the template cache so that new settings can take effect
     $templateMgr = TemplateManager::getManager($this->getRequest());
     $templateMgr->clearTemplateCache();
     $templateMgr->clearCssCache();
 }
 /**
  * Generates and inserts a new password for a mailing list user
  * @param $email string
  * @return string
  */
 function resetPassword($email)
 {
     $application =& PKPApplication::getApplication();
     $productName = $application->getName();
     $context =& Request::getContext();
     $contextId = $context->getId();
     $result =& $this->retrieve('SELECT setting_id FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?', array('mailList', $email, $productName, (int) $contextId));
     $row = $result->GetRowAssoc(false);
     $settingId = $row['setting_id'];
     $result->Close();
     unset($result);
     $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
     $accessKey = $accessKeyDao->getAccessKeyByUserId('MailListContext', $settingId);
     if ($accessKey) {
         $key = Validation::generatePassword();
         $accessKey->setKeyHash(md5($key));
         $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
         $accessKeyDao->updateObject($accessKey);
         return $key;
     } else {
         return false;
     }
 }
 /**
  * Get the number of read messages for a user
  * @param $userId int
  * @return int
  */
 function getReadNotificationCount($userId, $level = NOTIFICATION_LEVEL_NORMAL)
 {
     $application =& PKPApplication::getApplication();
     $productName = $application->getName();
     $context =& Request::getContext();
     $contextId = $context ? $context->getId() : 0;
     $result =& $this->retrieve('SELECT count(*) FROM notifications WHERE user_id = ? AND date_read IS NOT NULL AND product = ? AND context = ? AND level = ?', array((int) $userId, $productName, (int) $contextId, (int) $level));
     $returner = $result->fields[0];
     $result->Close();
     unset($result);
     return $returner;
 }
 /**
  * Process the Product node found inside the publication_format node.  There may be many of these.
  * @param $node DOMElement
  * @param $representation PublicationFormat
  */
 function _processProductNode($node, $deployment, &$representation)
 {
     $onixDeployment = new Onix30ExportDeployment(Request::getContext(), Request::getUser());
     $representation->setProductCompositionCode($this->_extractTextFromNode($node, $onixDeployment, 'ProductComposition'));
     $representation->setEntryKey($this->_extractTextFromNode($node, $onixDeployment, 'ProductForm'));
     $representation->setProductFormDetailCode($this->_extractTextFromNode($node, $onixDeployment, 'ProductFormDetail'));
     $representation->setImprint($this->_extractTextFromNode($node, $onixDeployment, 'ImprintName'));
     $representation->setTechnicalProtectionCode($this->_extractTextFromNode($node, $onixDeployment, 'EpubTechnicalProtection'));
     $representation->setCountryManufactureCode($this->_extractTextFromNode($node, $onixDeployment, 'CountryOfManufacture'));
     $this->_extractMeasureContent($node, $onixDeployment, $representation);
     $this->_extractExtentContent($node, $onixDeployment, $representation);
     // if this is a published monograph, extract the Audience elements and store them.
     $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
     $publishedMonograph = $publishedMonographDao->getById($representation->getSubmissionId());
     if ($publishedMonograph) {
         $publishedMonograph->setAudience($this->_extractTextFromNode($node, $onixDeployment, 'AudienceCodeType'));
         $publishedMonograph->setAudienceRangeQualifier($this->_extractTextFromNode($node, $onixDeployment, 'AudienceRangeQualifier'));
         $this->_extractAudienceRangeContent($node, $onixDeployment, $representation);
         $publishedMonographDao->updateObject($publishedMonograph);
     }
     // Things below here require a publication format id since they are dependent on the PublicationFormat.
     // Extract ProductIdentifier elements.
     $nodeList = $node->getElementsByTagNameNS($onixDeployment->getNamespace(), 'ProductIdentifier');
     if ($nodeList->length > 0) {
         $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
         for ($i = 0; $i < $nodeList->length; $i++) {
             $n = $nodeList->item($i);
             $identificationCode = $identificationCodeDao->newDataObject();
             $identificationCode->setPublicationFormatId($representation->getId());
             for ($o = $n->firstChild; $o !== null; $o = $o->nextSibling) {
                 if (is_a($o, 'DOMElement')) {
                     switch ($o->tagName) {
                         case 'onix:ProductIDType':
                             $identificationCode->setCode($o->textContent);
                             break;
                         case 'onix:IDValue':
                             $identificationCode->setValue($o->textContent);
                             break;
                     }
                 }
             }
             // if this is a DOI, use the DOI-plugin structure instead.
             if ($identificationCode->getCode() == '06') {
                 // DOI code
                 $representation->setStoredPubId('doi', $identificationCode->getValue());
             } else {
                 $identificationCodeDao->insertObject($identificationCode);
             }
             unset($identificationCode);
         }
     }
     // Extract PublishingDate elements.
     $nodeList = $node->getElementsByTagNameNS($onixDeployment->getNamespace(), 'PublishingDate');
     if ($nodeList->length > 0) {
         $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
         for ($i = 0; $i < $nodeList->length; $i++) {
             $n = $nodeList->item($i);
             $date = $publicationDateDao->newDataObject();
             $date->setPublicationFormatId($representation->getId());
             for ($o = $n->firstChild; $o !== null; $o = $o->nextSibling) {
                 if (is_a($o, 'DOMElement')) {
                     switch ($o->tagName) {
                         case 'onix:PublishingDateRole':
                             $date->setRole($o->textContent);
                             break;
                         case 'onix:Date':
                             $date->setDate($o->textContent);
                             $date->setDateFormat($o->getAttribute('dateformat'));
                             break;
                     }
                 }
             }
             $publicationDateDao->insertObject($date);
             unset($date);
         }
     }
     // Extract SalesRights elements.
     $nodeList = $node->getElementsByTagNameNS($onixDeployment->getNamespace(), 'SalesRights');
     if ($nodeList->length > 0) {
         $salesRightsDao = DAORegistry::getDAO('SalesRightsDAO');
         for ($i = 0; $i < $nodeList->length; $i++) {
             $salesRights = $salesRightsDao->newDataObject();
             $salesRights->setPublicationFormatId($representation->getId());
             $salesRightsNode = $nodeList->item($i);
             $salesRightsROW = $this->_extractTextFromNode($salesRightsNode, $onixDeployment, 'ROWSalesRightsType');
             if ($salesRightsROW) {
                 $salesRights->setROWSetting(true);
                 $salesRights->setType($salesRightsROW);
             } else {
                 // Not a 'rest of world' sales rights entry.  Parse the Territory elements as well.
                 $salesRights->setType($this->_extractTextFromNode($salesRightsNode, $onixDeployment, 'SalesRightsType'));
                 $salesRights->setROWSetting(false);
                 $territoryNodeList = $salesRightsNode->getElementsByTagNameNS($onixDeployment->getNamespace(), 'Territory');
                 assert($territoryNodeList->length == 1);
                 $territoryNode = $territoryNodeList->item(0);
                 for ($o = $territoryNode->firstChild; $o !== null; $o = $o->nextSibling) {
                     if (is_a($o, 'DOMElement')) {
                         switch ($o->tagName) {
                             case 'onix:RegionsIncluded':
                                 $salesRights->setRegionsIncluded(preg_split('/\\s+/', $o->textContent));
                                 break;
                             case 'onix:CountriesIncluded':
                                 $salesRights->setCountriesIncluded(preg_split('/\\s+/', $o->textContent));
                                 break;
                             case 'onix:RegionsExcluded':
                                 $salesRights->setRegionsExcluded(preg_split('/\\s+/', $o->textContent));
                                 break;
                             case 'onix:CountriesExcluded':
                                 $salesRights->setCountriesExcluded(preg_split('/\\s+/', $o->textContent));
                                 break;
                         }
                     }
                 }
             }
             $salesRightsDao->insertObject($salesRights);
             unset($salesRights);
         }
     }
     // Extract ProductSupply elements.  Contains Markets, Pricing, Suppliers, and Sales Agents.
     $nodeList = $node->getElementsByTagNameNS($onixDeployment->getNamespace(), 'ProductSupply');
     if ($nodeList->length > 0) {
         $marketDao = DAORegistry::getDAO('MarketDAO');
         $representativeDao = DAORegistry::getDAO('RepresentativeDAO');
         for ($i = 0; $i < $nodeList->length; $i++) {
             $productSupplyNode = $nodeList->item($i);
             $market = $marketDao->newDataObject();
             $market->setPublicationFormatId($representation->getId());
             // parse out the Territory for this market.
             $territoryNodeList = $productSupplyNode->getElementsByTagNameNS($onixDeployment->getNamespace(), 'Territory');
             assert($territoryNodeList->length == 1);
             $territoryNode = $territoryNodeList->item(0);
             for ($o = $territoryNode->firstChild; $o !== null; $o = $o->nextSibling) {
                 if (is_a($o, 'DOMElement')) {
                     switch ($o->tagName) {
                         case 'onix:RegionsIncluded':
                             $market->setRegionsIncluded(preg_split('/\\s+/', $o->textContent));
                             break;
                         case 'onix:CountriesIncluded':
                             $market->setCountriesIncluded(preg_split('/\\s+/', $o->textContent));
                             break;
                         case 'onix:RegionsExcluded':
                             $market->setRegionsExcluded(preg_split('/\\s+/', $o->textContent));
                             break;
                         case 'onix:CountriesExcluded':
                             $market->setCountriesExcluded(preg_split('/\\s+/', $o->textContent));
                             break;
                     }
                 }
             }
             // Market date information.
             $market->setDate($this->_extractTextFromNode($productSupplyNode, $onixDeployment, 'Date'));
             $market->setDateRole($this->_extractTextFromNode($productSupplyNode, $onixDeployment, 'MarketDateRole'));
             $market->setDateFormat($this->_extractTextFromNode($productSupplyNode, $onixDeployment, 'DateFormat'));
             // A product supply may have an Agent.  Look for the PublisherRepresentative element and parse if found.
             $publisherRepNodeList = $productSupplyNode->getElementsByTagNameNS($onixDeployment->getNamespace(), 'PublisherRepresentative');
             if ($publisherRepNodeList->length == 1) {
                 $publisherRepNode = $publisherRepNodeList->item(0);
                 $representative = $representativeDao->newDataObject();
                 $representative->setMonographId($deployment->getSubmission()->getId());
                 $representative->setRole($this->_extractTextFromNode($publisherRepNode, $onixDeployment, 'AgentRole'));
                 $representative->setName($this->_extractTextFromNode($publisherRepNode, $onixDeployment, 'AgentName'));
                 $representative->setUrl($this->_extractTextFromNode($publisherRepNode, $onixDeployment, 'WebsiteLink'));
                 // to prevent duplicate Agent creation, check to see if this agent already exists.  If it does, use it instead of creating a new one.
                 $existingAgents = $representativeDao->getAgentsByMonographId($deployment->getSubmission()->getId());
                 $foundAgent = false;
                 while ($agent = $existingAgents->next()) {
                     if ($agent->getRole() == $representative->getRole() && $agent->getName() == $representative->getName() && $agent->getUrl() == $representative->getUrl()) {
                         $market->setAgentId($agent->getId());
                         $foundAgent = true;
                         break;
                     }
                 }
                 if (!$foundAgent) {
                     $market->setAgentId($representativeDao->insertObject($representative));
                 }
             }
             // Now look for a SupplyDetail element, for the Supplier information.
             $supplierNodeList = $productSupplyNode->getElementsByTagNameNS($onixDeployment->getNamespace(), 'Supplier');
             if ($supplierNodeList->length == 1) {
                 $supplierNode = $supplierNodeList->item(0);
                 $representative = $representativeDao->newDataObject();
                 $representative->setMonographId($deployment->getSubmission()->getId());
                 $representative->setRole($this->_extractTextFromNode($supplierNode, $onixDeployment, 'SupplierRole'));
                 $representative->setName($this->_extractTextFromNode($supplierNode, $onixDeployment, 'SupplierName'));
                 $representative->setPhone($this->_extractTextFromNode($supplierNode, $onixDeployment, 'TelephoneNumber'));
                 $representative->setEmail($this->_extractTextFromNode($supplierNode, $onixDeployment, 'EmailAddress'));
                 $representative->setUrl($this->_extractTextFromNode($supplierNode, $onixDeployment, 'WebsiteLink'));
                 $representative->setIsSupplier(true);
                 // Again, to prevent duplicate Supplier creation, check to see if this rep already exists.  If it does, use it instead of creating a new one.
                 $existingSuppliers = $representativeDao->getSuppliersByMonographId($deployment->getSubmission()->getId());
                 $foundSupplier = false;
                 while ($supplier = $existingSuppliers->next()) {
                     if ($supplier->getRole() == $representative->getRole() && $supplier->getName() == $representative->getName() && $supplier->getUrl() == $representative->getUrl() && $supplier->getPhone() == $representative->getPhone() && $supplier->getEmail() == $representative->getEmail()) {
                         $market->setSupplierId($supplier->getId());
                         $foundSupplier = true;
                         break;
                     }
                 }
                 if (!$foundSupplier) {
                     $market->setSupplierId($representativeDao->insertObject($representative));
                 }
                 $priceNodeList = $productSupplyNode->getElementsByTagNameNS($onixDeployment->getNamespace(), 'Price');
                 if ($priceNodeList->length == 1) {
                     $priceNode = $priceNodeList->item(0);
                     $market->setPriceTypeCode($this->_extractTextFromNode($priceNode, $onixDeployment, 'PriceType'));
                     $market->setDiscount($this->_extractTextFromNode($priceNode, $onixDeployment, 'DiscountPercent'));
                     $market->setPrice($this->_extractTextFromNode($priceNode, $onixDeployment, 'PriceAmount'));
                     $market->setTaxTypeCode($this->_extractTextFromNode($priceNode, $onixDeployment, 'TaxType'));
                     $market->setTaxRateCode($this->_extractTextFromNode($priceNode, $onixDeployment, 'TaxRateCode'));
                     $market->setCurrencyCode($this->_extractTextFromNode($priceNode, $onixDeployment, 'CurrencyCode'));
                 }
             }
             // Extract Pricing information for this format.
             $representation->setReturnableIndicatorCode($this->_extractTextFromNode($supplierNode, $onixDeployment, 'ReturnsCode'));
             $representation->getProductAvailabilityCode($this->_extractTextFromNode($supplierNode, $onixDeployment, 'ProductAvailability'));
             $marketDao->insertObject($market);
         }
     }
 }
Example #10
0
 /**
  * Return the DBResultRange structure and misc. variables describing the current page of a set of pages.
  * @param $rangeName string Symbolic name of range of pages; must match the Smarty {page_list ...} name.
  * @param $contextData array If set, this should contain a set of data that are required to
  * 	define the context of this request (for maintaining page numbers across requests).
  *	To disable persistent page contexts, set this variable to null.
  * @return array ($pageNum, $dbResultRange)
  */
 function &getRangeInfo($rangeName, $contextData = null)
 {
     //FIXME: is there any way to get around calling a Request (instead of a PKPRequest) here?
     $context =& Request::getContext();
     $pageNum = PKPRequest::getUserVar($rangeName . 'Page');
     if (empty($pageNum)) {
         $session =& PKPRequest::getSession();
         $pageNum = 1;
         // Default to page 1
         if ($session && $contextData !== null) {
             // See if we can get a page number from a prior request
             $contextHash = PKPHandler::hashPageContext($contextData);
             if (PKPRequest::getUserVar('clearPageContext')) {
                 // Explicitly clear the old page context
                 $session->unsetSessionVar("page-{$contextHash}");
             } else {
                 $oldPage = $session->getSessionVar("page-{$contextHash}");
                 if (is_numeric($oldPage)) {
                     $pageNum = $oldPage;
                 }
             }
         }
     } else {
         $session =& PKPRequest::getSession();
         if ($session && $contextData !== null) {
             // Store the page number
             $contextHash = PKPHandler::hashPageContext($contextData);
             $session->setSessionVar("page-{$contextHash}", $pageNum);
         }
     }
     if ($context) {
         $count = $context->getSetting('itemsPerPage');
     }
     if (!isset($count)) {
         $count = Config::getVar('interface', 'items_per_page');
     }
     import('db.DBResultRange');
     if (isset($count)) {
         $returner = new DBResultRange($count, $pageNum);
     } else {
         $returner = new DBResultRange(-1, -1);
     }
     return $returner;
 }
 /**
  * Parse a publication format and add it to the submission.
  * @param $n DOMElement
  * @param $submission Submission
  */
 function parsePublicationFormat($n, $submission)
 {
     $importFilter = $this->getImportFilter($n->tagName);
     assert($importFilter);
     // There should be a filter
     $existingDeployment = $this->getDeployment();
     $onixDeployment = new Onix30ExportDeployment(Request::getContext(), Request::getUser());
     $onixDeployment->setSubmission($existingDeployment->getSubmission());
     $onixDeployment->setFileDBIds($existingDeployment->getFileDBIds());
     $importFilter->setDeployment($onixDeployment);
     $formatDoc = new DOMDocument();
     $formatDoc->appendChild($formatDoc->importNode($n, true));
     return $importFilter->execute($formatDoc);
 }