Open Monograph Press  3.3.0
FeatureDAO.inc.php
1 <?php
2 
17 class FeatureDAO extends DAO {
21  function __construct() {
22  parent::__construct();
23  }
24 
31  function getMonographIdsByAssoc($assocType, $assocId) {
32  $returner = array();
33  $result = $this->retrieve(
34  'SELECT submission_id, seq FROM features WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
35  array((int) $assocType, (int) $assocId)
36  );
37 
38  while (!$result->EOF) {
39  list($monographId, $seq) = $result->fields;
40  $returner[$seq] = $monographId;
41  $result->MoveNext();
42  }
43 
44  $result->Close();
45  return $returner;
46  }
47 
54  function getSequencesByAssoc($assocType, $assocId) {
55  return array_flip($this->getMonographIdsByAssoc($assocType, $assocId));
56  }
57 
65  function insertFeature($monographId, $assocType, $assocId, $seq) {
66  $this->update(
67  'INSERT INTO features
68  (submission_id, assoc_type, assoc_id, seq)
69  VALUES
70  (?, ?, ?, ?)',
71  array(
72  (int) $monographId,
73  (int) $assocType,
74  (int) $assocId,
75  (int) $seq
76  )
77  );
78  }
79 
85  function deleteByMonographId($monographId) {
86  $this->update(
87  'DELETE FROM features WHERE submission_id = ?',
88  (int) $monographId
89  );
90  }
91 
97  function deleteByAssoc($assocType, $assocId) {
98  $this->update(
99  'DELETE FROM features WHERE assoc_type = ? AND assoc_id = ?',
100  array((int) $assocType, (int) $assocId)
101  );
102  }
103 
110  function deleteFeature($monographId, $assocType, $assocId) {
111  $this->update(
112  'DELETE FROM features
113  WHERE submission_id = ? AND
114  assoc_type = ? AND
115  assoc_id = ?',
116  array(
117  (int) $monographId,
118  (int) $assocType,
119  (int) $assocId
120  )
121  );
122  }
123 
134  function isFeatured($monographId, $assocType, $assocId) {
135  $result = $this->retrieve(
136  'SELECT submission_id FROM features WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
137  array((int) $monographId, (int) $assocType, (int) $assocId)
138  );
139  if ($result->RecordCount() > 0) {
140  return true;
141  }
142 
143  return false;
144  }
145 
151  function getFeaturedAll($monographId) {
152  $result = $this->retrieve(
153  'SELECT assoc_type, assoc_id, seq FROM features WHERE submission_id = ?',
154  array((int) $monographId)
155  );
156 
157  $featured = array();
158  while (!$result->EOF) {
159  $featured[] = array(
160  'assoc_type' => (int) $result->fields['assoc_type'],
161  'assoc_id' => (int) $result->fields['assoc_id'],
162  'seq' => (int) $result->fields['seq'],
163  );
164  $result->MoveNext();
165  }
166 
167  return $featured;
168  }
169 
178  function getSequencePosition($monographId, $assocType, $assocId) {
179  $result = $this->retrieve(
180  'SELECT seq FROM features WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
181  array((int) $monographId, (int) $assocType, (int) $assocId)
182  );
183  if ($result->RecordCount() > 0) {
184  return current($result->fields);
185  }
186 
187  return false;
188  }
189 
190  function setSequencePosition($monographId, $assocType, $assocId, $sequencePosition) {
191  $this->update(
192  'UPDATE features SET seq = ? WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
193  array((int) $sequencePosition, (int) $monographId, (int) $assocType, (int) $assocId)
194  );
195  }
196 
204  function resequenceByAssoc($assocType, $assocId) {
205  $returner = array();
206  $result = $this->retrieve(
207  'SELECT submission_id FROM features WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
208  array((int) $assocType, (int) $assocId)
209  );
210 
211  for ($i=2; !$result->EOF; $i+=2) {
212  list($monographId) = $result->fields;
213  $this->update(
214  'UPDATE features SET seq = ? WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
215  array(
216  $i,
217  $monographId,
218  (int) $assocType,
219  (int) $assocId
220  )
221  );
222  $returner[$monographId] = $i;
223 
224  $result->MoveNext();
225  }
226 
227  $result->Close();
228  return $returner;
229  }
230 }
231 
232 
FeatureDAO\isFeatured
isFeatured($monographId, $assocType, $assocId)
Definition: FeatureDAO.inc.php:134
FeatureDAO\setSequencePosition
setSequencePosition($monographId, $assocType, $assocId, $sequencePosition)
Definition: FeatureDAO.inc.php:190
FeatureDAO\resequenceByAssoc
resequenceByAssoc($assocType, $assocId)
Definition: FeatureDAO.inc.php:204
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
FeatureDAO\getFeaturedAll
getFeaturedAll($monographId)
Definition: FeatureDAO.inc.php:151
FeatureDAO\deleteByMonographId
deleteByMonographId($monographId)
Definition: FeatureDAO.inc.php:85
FeatureDAO\__construct
__construct()
Definition: FeatureDAO.inc.php:21
FeatureDAO\deleteByAssoc
deleteByAssoc($assocType, $assocId)
Definition: FeatureDAO.inc.php:97
FeatureDAO\getSequencesByAssoc
getSequencesByAssoc($assocType, $assocId)
Definition: FeatureDAO.inc.php:54
FeatureDAO\getMonographIdsByAssoc
getMonographIdsByAssoc($assocType, $assocId)
Definition: FeatureDAO.inc.php:31
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
FeatureDAO
Operations for setting Featured status on various items.
Definition: FeatureDAO.inc.php:17
FeatureDAO\insertFeature
insertFeature($monographId, $assocType, $assocId, $seq)
Definition: FeatureDAO.inc.php:65
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
FeatureDAO\deleteFeature
deleteFeature($monographId, $assocType, $assocId)
Definition: FeatureDAO.inc.php:110
FeatureDAO\getSequencePosition
getSequencePosition($monographId, $assocType, $assocId)
Definition: FeatureDAO.inc.php:178