Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ExternalFeedDAO.inc.php
1 <?php
2 
16 import('lib.pkp.classes.db.DAO');
17 
18 class ExternalFeedDAO extends DAO {
21 
26  $this->parentPluginName = $parentPluginName;
27  parent::DAO();
28  }
29 
35  function &getExternalFeed($feedId) {
36  $result = $this->retrieve(
37  'SELECT * FROM external_feeds WHERE feed_id = ?', $feedId
38  );
39 
40  $returner = null;
41  if ($result->RecordCount() != 0) {
42  $returner =& $this->_returnExternalFeedFromRow($result->GetRowAssoc(false));
43  }
44  $result->Close();
45  return $returner;
46  }
47 
53  function getExternalFeedJournalId($feedId) {
54  $result = $this->retrieve(
55  'SELECT journal_id FROM external_feeds WHERE feed_id = ?', $feedId
56  );
57 
58  return isset($result->fields[0]) ? $result->fields[0] : 0;
59  }
60 
66  function &_returnExternalFeedFromRow($row) {
67  $externalFeedPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
68  $externalFeedPlugin->import('ExternalFeed');
69 
70  $externalFeed = new ExternalFeed();
71  $externalFeed->setId($row['feed_id']);
72  $externalFeed->setJournalId($row['journal_id']);
73  $externalFeed->setUrl($row['url']);
74  $externalFeed->setSeq($row['seq']);
75  $externalFeed->setDisplayHomepage($row['display_homepage']);
76  $externalFeed->setDisplayBlock($row['display_block']);
77  $externalFeed->setLimitItems($row['limit_items']);
78  $externalFeed->setRecentItems($row['recent_items']);
79 
80  $this->getDataObjectSettings(
81  'external_feed_settings',
82  'feed_id',
83  $row['feed_id'],
84  $externalFeed
85  );
86 
87  return $externalFeed;
88  }
89 
95  function insertExternalFeed(&$externalFeed) {
96  $ret = $this->update(
97  'INSERT INTO external_feeds
98  (journal_id,
99  url,
100  seq,
101  display_homepage,
102  display_block,
103  limit_items,
104  recent_items)
105  VALUES
106  (?, ?, ?, ?, ?, ?, ?)',
107  array(
108  $externalFeed->getJournalId(),
109  $externalFeed->getUrl(),
110  $externalFeed->getSeq(),
111  $externalFeed->getDisplayHomepage(),
112  $externalFeed->getDisplayBlock(),
113  $externalFeed->getLimitItems(),
114  $externalFeed->getRecentItems()
115  )
116  );
117  $externalFeed->setId($this->getInsertId());
118 
119  $this->updateLocaleFields($externalFeed);
120 
121  return $externalFeed->getId();
122  }
123 
128  function getLocaleFieldNames() {
129  return array('title');
130  }
136  function updateLocaleFields(&$externalFeed) {
137  $this->updateDataObjectSettings('external_feed_settings', $externalFeed, array(
138  'feed_id' => $externalFeed->getId()
139  ));
140  }
141 
147  function updateExternalFeed(&$externalFeed) {
148  $this->update(
149  'UPDATE external_feeds
150  SET
151  journal_id = ?,
152  url = ?,
153  seq = ?,
154  display_homepage = ?,
155  display_block = ?,
156  limit_items = ?,
157  recent_items = ?
158  WHERE feed_id = ?',
159  array(
160  $externalFeed->getJournalId(),
161  $externalFeed->getUrl(),
162  $externalFeed->getSeq(),
163  $externalFeed->getDisplayHomepage(),
164  $externalFeed->getDisplayBlock(),
165  $externalFeed->getLimitItems(),
166  $externalFeed->getRecentItems(),
167  $externalFeed->getId()
168  )
169  );
170 
171  $this->updateLocaleFields($externalFeed);
172  }
173 
179  function deleteExternalFeed($externalFeed) {
180  return $this->deleteExternalFeedById($externalFeed->getId());
181  }
188  function deleteExternalFeedById($feedId) {
189  $this->update(
190  'DELETE FROM external_feeds WHERE feed_id = ?', $feedId
191  );
192 
193  $this->update(
194  'DELETE FROM external_feed_settings WHERE feed_id = ?', $feedId
195  );
196  }
197 
202  function deleteExternalFeedsByJournalId($journalId) {
203  $feeds = $this->getExternalFeedsByJournalId($journalId);
204 
205  while ($feed = $feeds->next()) {
206  $this->deleteExternalFeedById($feed->getId());
207  }
208  }
209 
216  function getExternalFeedsByJournalId($journalId, $rangeInfo = null) {
217  $result = $this->retrieveRange(
218  'SELECT * FROM external_feeds WHERE journal_id = ? ORDER BY seq ASC',
219  $journalId,
220  $rangeInfo
221  );
222 
223  return new DAOResultFactory($result, $this, '_returnExternalFeedFromRow');
224  }
225 
229  function resequenceExternalFeeds($journalId) {
230  $result = $this->retrieve(
231  'SELECT feed_id FROM external_feeds WHERE journal_id = ? ORDER BY seq',
232  $journalId
233  );
234 
235  for ($i=1; !$result->EOF; $i++) {
236  list($feedId) = $result->fields;
237  $this->update(
238  'UPDATE external_feeds SET seq = ? WHERE feed_id = ?',
239  array(
240  $i,
241  $feedId
242  )
243  );
244 
245  $result->MoveNext();
246  }
247  $result->Close();
248  }
249 
254  function getInsertId() {
255  return $this->_getInsertId('external_feeds', 'feed_id');
256  }
257 }
258 
259 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
ExternalFeedDAO($parentPluginName)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getExternalFeedJournalId($feedId)
updateLocaleFields(&$externalFeed)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
& _returnExternalFeedFromRow($row)
getExternalFeedsByJournalId($journalId, $rangeInfo=null)
resequenceExternalFeeds($journalId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Basic class describing an external feed.
static & getPlugin($category, $name)
& getExternalFeed($feedId)
insertExternalFeed(&$externalFeed)
Operations for retrieving and modifying ExternalFeed objects.
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
deleteExternalFeedsByJournalId($journalId)
updateExternalFeed(&$externalFeed)
deleteExternalFeed($externalFeed)