Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
MetricsDAO.inc.php
1 <?php
2 
16 import('lib.pkp.classes.statistics.PKPMetricsDAO');
17 
18 class MetricsDAO extends PKPMetricsDAO {
19 
23  function &getMetrics($metricType, $columns = array(), $filters = array(), $orderBy = array(), $range = null, $nonAdditive = true) {
24  // Translate the issue dimension to a generic one used in pkp library.
25  foreach (array(&$columns, &$filters, &$orderBy) as &$parameter) { // Reference needed.
26  if ($parameter === $filters && array_key_exists(STATISTICS_DIMENSION_ISSUE_ID, $parameter)) {
27  $parameter[STATISTICS_DIMENSION_ASSOC_OBJECT_TYPE] = ASSOC_TYPE_ISSUE;
28  }
29 
30  $key = array_search(STATISTICS_DIMENSION_ISSUE_ID, $parameter);
31  if ($key !== false) {
32  $parameter[] = STATISTICS_DIMENSION_ASSOC_OBJECT_TYPE;
33  }
34  unset($parameter);
35  }
36 
37  return parent::getMetrics($metricType, $columns, $filters, $orderBy, $range, $nonAdditive);
38  }
39 
43  protected function foreignKeyLookup($assocType, $assocId) {
44  list($contextId, $sectionId, $assocObjType,
45  $assocObjId, $submissionId, $representationId) = parent::foreignKeyLookup($assocType, $assocId);
46 
47  $isFile = false;
48 
49  if (!$contextId) {
50  switch ($assocType) {
51  case ASSOC_TYPE_ISSUE_GALLEY:
52  $issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO');
53  $issueGalley = $issueGalleyDao->getById($assocId);
54  if (!$issueGalley) {
55  throw new Exception('Cannot load record: invalid issue galley id.');
56  }
57 
58  $assocObjType = ASSOC_TYPE_ISSUE;
59  $assocObjId = $issueGalley->getIssueId();
60  $isFile = true;
61  // Don't break but go on to retrieve the issue.
62  case ASSOC_TYPE_ISSUE:
63  if (!$isFile) {
64  $assocObjType = $assocObjId = null;
65  $issueId = $assocId;
66  } else {
67  $issueId = $assocObjId;
68  }
69 
70  $issueDao = DAORegistry::getDAO('IssueDAO');
71  $issue = $issueDao->getById($issueId);
72 
73  if (!$issue) {
74  throw new Exception('Cannot load record: invalid issue id.');
75  }
76 
77  $contextId = $issue->getJournalId();
78  break;
79  }
80  }
81 
82  return array($contextId, $sectionId, $assocObjType, $assocObjId, $submissionId, $representationId);
83  }
84 
88  protected function getAssocObjectInfo($submissionId, $contextId) {
89  $returnArray = parent::getAssocObjectInfo($submissionId, $contextId);
90 
91  // Submissions in OJS are associated with an Issue.
92  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
93  $publishedArticle = $publishedArticleDao->getPublishedArticleByArticleId($submissionId, $contextId, true);
94  if ($publishedArticle) {
95  $returnArray = array(ASSOC_TYPE_ISSUE, $publishedArticle->getIssueId());
96  }
97  return $returnArray;
98  }
99 }
100 ?>
static & getDAO($name, $dbconn=null)
Class with basic operations for retrieving and adding statistics data.
& getMetrics($metricType, $columns=array(), $filters=array(), $orderBy=array(), $range=null, $nonAdditive=true)
foreignKeyLookup($assocType, $assocId)
Operations for retrieving and adding statistics data.
getAssocObjectInfo($submissionId, $contextId)