Open Journal Systems  3.3.0
PubObjectCache.inc.php
1 <?php
2 
18  /* @var array */
19  var $_objectCache = array();
20 
21 
22  //
23  // Public API
24  //
30  function add($object, $parent) {
31  if (is_a($object, 'Issue')) {
32  $this->_insertInternally($object, 'issues', $object->getId());
33  }
34  if (is_a($object, 'Submission')) {
35  $this->_insertInternally($object, 'articles', $object->getId());
36  $this->_insertInternally($object, 'articlesByIssue', $object->getcurrentPublication()->getData('issueId'), $object->getId());
37  }
38  if (is_a($object, 'ArticleGalley')) {
39  assert(is_a($parent, 'Submission'));
40  $this->_insertInternally($object, 'galleys', $object->getId());
41  $this->_insertInternally($object, 'galleysByArticle', $object->getSubmissionId(), $object->getId());
42  $this->_insertInternally($object, 'galleysByIssue', $parent->getIssueId(), $object->getId());
43  }
44  }
45 
54  function markComplete($cacheId, $objectId) {
55  assert(is_array($this->_objectCache[$cacheId][$objectId]));
56  $this->_objectCache[$cacheId][$objectId]['complete'] = true;
57 
58  // Order objects in the completed cache by ID.
59  ksort($this->_objectCache[$cacheId][$objectId]);
60  }
61 
74  function get($cacheId, $id1, $id2 = null) {
75  assert($this->isCached($cacheId, $id1, $id2));
76  if (is_null($id2)) {
77  $returner = $this->_objectCache[$cacheId][$id1];
78  if (is_array($returner)) unset($returner['complete']);
79  return $returner;
80  } else {
81  return $this->_objectCache[$cacheId][$id1][$id2];
82  }
83  }
84 
94  function isCached($cacheId, $id1, $id2 = null) {
95  if (!isset($this->_objectCache[$cacheId])) return false;
96 
97  $id1 = (int)$id1;
98  if (is_null($id2)) {
99  if (!isset($this->_objectCache[$cacheId][$id1])) return false;
100  if (is_array($this->_objectCache[$cacheId][$id1])) {
101  return isset($this->_objectCache[$cacheId][$id1]['complete']);
102  } else {
103  return true;
104  }
105  } else {
106  $id2 = (int)$id2;
107  return isset($this->_objectCache[$cacheId][$id1][$id2]);
108  }
109  }
110 
111 
112  //
113  // Private helper methods
114  //
123  function _insertInternally($object, $cacheId, $id1, $id2 = null) {
124  if ($this->isCached($cacheId, $id1, $id2)) return;
125 
126  if (!isset($this->_objectCache[$cacheId])) {
127  $this->_objectCache[$cacheId] = array();
128  }
129 
130  $id1 = (int)$id1;
131  if (is_null($id2)) {
132  $this->_objectCache[$cacheId][$id1] = $object;
133  } else {
134  $id2 = (int)$id2;
135  if (!isset($this->_objectCache[$cacheId][$id1])) {
136  $this->_objectCache[$cacheId][$id1] = array();
137  }
138  $this->_objectCache[$cacheId][$id1][$id2] = $object;
139  }
140  }
141 }
142 
143 
PubObjectCache\$_objectCache
$_objectCache
Definition: PubObjectCache.inc.php:22
PubObjectCache\isCached
isCached($cacheId, $id1, $id2=null)
Definition: PubObjectCache.inc.php:97
PubObjectCache
A cache for publication objects required during export.
Definition: PubObjectCache.inc.php:17
PubObjectCache\add
add($object, $parent)
Definition: PubObjectCache.inc.php:33
PubObjectCache\markComplete
markComplete($cacheId, $objectId)
Definition: PubObjectCache.inc.php:57
PubObjectCache\_insertInternally
_insertInternally($object, $cacheId, $id1, $id2=null)
Definition: PubObjectCache.inc.php:126