/** * Construct a JSON string to use for AJAX communication * @return string */ function getString() { // Construct an associative array that contains all information we require. $jsonObject = array('status' => $this->getStatus(), 'content' => $this->getContent(), 'elementId' => $this->getElementId()); if (is_array($this->getAdditionalAttributes())) { foreach ($this->getAdditionalAttributes() as $key => $value) { $jsonObject[$key] = $value; } } if (is_array($this->getEvent())) { $jsonObject['event'] = $this->getEvent(); } // Encode the object. import('lib.pkp.classes.core.JSONManager'); $jsonManager = new JSONManager(); return $jsonManager->encode($jsonObject); }
/** * Build the required article information for the * metrics visualization. * @param $article PublishedArticle * @return string JSON response */ function _buildRequiredArticleInfoJson($article) { if ($article->getDatePublished()) { $datePublished = $article->getDatePublished(); } else { // Sometimes there is no article getDatePublished, so fallback on the issue's $issueDao =& DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ $issue =& $issueDao->getIssueByArticleId($article->getId(), $article->getJournalId()); $datePublished = $issue->getDatePublished(); } $response = array(array('publication_date' => date('c', strtotime($datePublished)), 'doi' => $article->getPubId('doi'), 'title' => $article->getLocalizedTitle(), 'sources' => array())); $jsonManager = new JSONManager(); return $jsonManager->encode($response); }