Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublishedMonographDAO.inc.php
1 <?php
2 
17 import('classes.monograph.PublishedMonograph');
18 import('classes.monograph.MonographDAO');
19 
24  function PublishedMonographDAO() {
25  parent::MonographDAO();
26  }
27 
34  function getByPressId($pressId, $searchText = null, $rangeInfo = null) {
35  $primaryLocale = AppLocale::getPrimaryLocale();
36  $locale = AppLocale::getLocale();
37 
38  $params = array_merge(
39  array(REALLY_BIG_NUMBER),
40  $this->_getFetchParameters(),
41  array(
42  ASSOC_TYPE_PRESS,
43  (int) $pressId
44  )
45  );
46 
47  if ($searchText !== null) {
48  $params[] = $params[] = $params[] = "%$searchText%";
49  }
50 
51  $result = $this->retrieveRange(
52  'SELECT ' . ($searchText !== null?'DISTINCT ':'') . '
53  ps.*,
54  s.*,
55  COALESCE(f.seq, ?) AS order_by,
56  ' . $this->_getFetchColumns() . '
57  FROM published_submissions ps
58  JOIN submissions s ON ps.submission_id = s.submission_id
59  ' . $this->_getFetchJoins() . '
60  ' . ($searchText !== null?'
61  LEFT JOIN authors a ON s.submission_id = a.submission_id
62  LEFT JOIN submission_settings st ON (st.submission_id = s.submission_id AND st.setting_name = \'title\')
63  ':'') . '
64  LEFT JOIN features f ON (f.submission_id = s.submission_id AND f.assoc_type = ? AND f.assoc_id = s.context_id)
65  WHERE ps.date_published IS NOT NULL AND s.context_id = ?
66  ' . ($searchText !== null?' AND (st.setting_value LIKE ? OR a.first_name LIKE ? OR a.last_name LIKE ?)':'') . '
67  ORDER BY order_by, ps.date_published',
68  $params,
69  $rangeInfo
70  );
71 
72  return new DAOResultFactory($result, $this, '_fromRow');
73  }
74 
81  function getPressFeatures($pressId, $rangeInfo = null) {
82  $params = array_merge(
83  $this->_getFetchColumns(),
84  array(ASSOC_TYPE_PRESS, (int) $pressId)
85  );
86  $result = $this->retrieveRange(
87  'SELECT ps.*,
88  s.*,
89  ' . $this->_getFetchColumns() . '
90  FROM published_submissions ps
91  JOIN submissions s ON ps.submission_id = s.submission_id
92  ' . $this->_getFetchJoins() . '
93  JOIN features f ON (f.submission_id = s.submission_id AND f.assoc_type = ? AND f.assoc_id = s.context_id)
94  WHERE ps.date_published IS NOT NULL AND s.context_id = ?
95  ORDER BY f.seq, ps.date_published',
96  $params,
97  $rangeInfo
98  );
99 
100  return new DAOResultFactory($result, $this, '_fromRow');
101  }
102 
110  function getBySeriesId($seriesId, $pressId = null, $rangeInfo = null) {
111  $params = array_merge(
112  $this->_getFetchParameters(),
113  array(ASSOC_TYPE_SERIES, (int) $seriesId)
114  );
115 
116  if ($pressId) $params[] = (int) $pressId;
117 
118  $params[] = REALLY_BIG_NUMBER; // For feature sorting
119 
120  $result = $this->retrieveRange(
121  'SELECT ps.*,
122  s.*,
123  ' . $this->_getFetchColumns() . '
124  FROM published_submissions ps
125  JOIN submissions s ON ps.submission_id = s.submission_id
126  ' . $this->_getFetchJoins() . '
127  LEFT JOIN features f ON (f.submission_id = s.submission_id AND f.assoc_type = ? AND f.assoc_id = se.series_id)
128  WHERE ps.date_published IS NOT NULL AND se.series_id = ?
129  ' . ($pressId?' AND s.context_id = ?':'' ) . '
130  ORDER BY COALESCE(f.seq, ?) ASC, ps.date_published',
131  $params,
132  $rangeInfo
133  );
134 
135  return new DAOResultFactory($result, $this, '_fromRow');
136  }
137 
145  function getByCategoryId($categoryId, $pressId = null, $rangeInfo = null) {
146  $params = array_merge(
147  array(REALLY_BIG_NUMBER),
148  $this->_getFetchParameters(),
149  array(
150  (int) $categoryId, (int) $categoryId, (int) $categoryId,
151  ASSOC_TYPE_SERIES
152  )
153  );
154 
155  if ($pressId) $params[] = (int) $pressId;
156 
157  $result = $this->retrieveRange(
158  'SELECT DISTINCT ps.*,
159  s.*,
160  COALESCE(f.seq, ?) AS order_by,
161  ' . $this->_getFetchColumns() . '
162  FROM published_submissions ps
163  JOIN submissions s ON ps.submission_id = s.submission_id
164  ' . $this->_getFetchJoins() . '
165  LEFT JOIN submission_categories sc ON (sc.submission_id = s.submission_id AND sc.category_id = ?)
166  LEFT JOIN series_categories sca ON (sca.series_id = se.series_id)
167  LEFT JOIN categories c ON (c.category_id = sca.category_id AND c.category_id = ?)
168  LEFT JOIN features f ON (f.submission_id = s.submission_id AND f.assoc_type = ? AND f.assoc_id = ?)
169  WHERE ps.date_published IS NOT NULL AND (c.category_id IS NOT NULL OR sc.category_id IS NOT NULL)
170  ' . ($pressId?' AND s.context_id = ?':'' ) . '
171  ORDER BY order_by, ps.date_published',
172  $params,
173  $rangeInfo
174  );
175 
176  return new DAOResultFactory($result, $this, '_fromRow');
177  }
178 
185  function getById($monographId, $pressId = null, $metadataApprovedOnly = true) {
186  $params = $this->_getFetchParameters();
187  $params[] = (int) $monographId;
188  if ($pressId) $params[] = (int) $pressId;
189 
190  $result = $this->retrieve(
191  'SELECT s.*,
192  ps.*,
193  ' . $this->_getFetchColumns() . '
194  FROM submissions s
195  JOIN published_submissions ps ON (ps.submission_id = s.submission_id)
196  ' . $this->_getFetchJoins() . '
197  WHERE s.submission_id = ?
198  ' . ($pressId?' AND s.context_id = ?':'')
199  . ($metadataApprovedOnly?' AND ps.date_published IS NOT NULL':''),
200  $params
201  );
202 
203  $returner = null;
204  if ($result->RecordCount() != 0) {
205  $returner = $this->_fromRow($result->GetRowAssoc(false));
206  }
207 
208  $result->Close();
209  return $returner;
210  }
211 
216  function newDataObject() {
217  return new PublishedMonograph();
218  }
219 
225  function _fromRow($row) {
226  // Get the PublishedMonograph object, populated with Monograph data
227  $publishedMonograph = parent::_fromRow($row);
228 
229  // Add the additional PublishedMonograph data
230  $publishedMonograph->setDatePublished($this->datetimeFromDB($row['date_published']));
231  $publishedMonograph->setAudience($row['audience']);
232  $publishedMonograph->setAudienceRangeQualifier($row['audience_range_qualifier']);
233  $publishedMonograph->setAudienceRangeFrom($row['audience_range_from']);
234  $publishedMonograph->setAudienceRangeTo($row['audience_range_to']);
235  $publishedMonograph->setAudienceRangeExact($row['audience_range_exact']);
236  $publishedMonograph->setCoverImage(unserialize($row['cover_image']));
237 
238  HookRegistry::call('PublishedMonographDAO::_fromRow', array(&$publishedMonograph, &$row));
239  return $publishedMonograph;
240  }
241 
242 
247  function insertObject($publishedMonograph) {
248 
249  $this->update(
250  sprintf('INSERT INTO published_submissions
251  (submission_id, date_published, audience, audience_range_qualifier, audience_range_from, audience_range_to, audience_range_exact, cover_image)
252  VALUES
253  (?, %s, ?, ?, ?, ?, ?, ?)',
254  $this->datetimeToDB($publishedMonograph->getDatePublished())),
255  array(
256  (int) $publishedMonograph->getId(),
257  $publishedMonograph->getAudience(),
258  $publishedMonograph->getAudienceRangeQualifier(),
259  $publishedMonograph->getAudienceRangeFrom(),
260  $publishedMonograph->getAudienceRangeTo(),
261  $publishedMonograph->getAudienceRangeExact(),
262  serialize($publishedMonograph->getCoverImage() ? $publishedMonograph->getCoverImage() : array()),
263  )
264  );
265  }
266 
271  function deleteById($monographId) {
272  $this->update(
273  'DELETE FROM published_submissions WHERE submission_id = ?',
274  (int) $monographId
275  );
276  }
277 
282  function updateObject($publishedMonograph) {
283  $this->update(
284  sprintf('UPDATE published_submissions
285  SET date_published = %s,
286  audience = ?,
287  audience_range_qualifier = ?,
288  audience_range_from = ?,
289  audience_range_to = ?,
290  audience_range_exact = ?,
291  cover_image = ?
292  WHERE submission_id = ?',
293  $this->datetimeToDB($publishedMonograph->getDatePublished())),
294  array(
295  $publishedMonograph->getAudience(),
296  $publishedMonograph->getAudienceRangeQualifier(),
297  $publishedMonograph->getAudienceRangeFrom(),
298  $publishedMonograph->getAudienceRangeTo(),
299  $publishedMonograph->getAudienceRangeExact(),
300  serialize($publishedMonograph->getCoverImage() ? $publishedMonograph->getCoverImage() : array()),
301  (int) $publishedMonograph->getId()
302  )
303  );
304  }
305 }
306 
307 ?>
insertObject($publishedMonograph)
getById($monographId, $pressId=null, $metadataApprovedOnly=true)
static getPrimaryLocale()
getPressFeatures($pressId, $rangeInfo=null)
Operations for retrieving and modifying Monograph objects.
getByPressId($pressId, $searchText=null, $rangeInfo=null)
static getLocale()
getByCategoryId($categoryId, $pressId=null, $rangeInfo=null)
updateObject($publishedMonograph)
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Published monograph class.
Operations for retrieving and modifying PublishedMonograph objects.
getBySeriesId($seriesId, $pressId=null, $rangeInfo=null)