Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
StaticPagesDAO.inc.php
1 <?php
15 import('lib.pkp.classes.db.DAO');
16 
17 class StaticPagesDAO extends DAO {
20 
25  $this->parentPluginName = $parentPluginName;
26  parent::DAO();
27  }
28 
29  function getStaticPage($staticPageId) {
30  $result = $this->retrieve(
31  'SELECT * FROM static_pages WHERE static_page_id = ?', $staticPageId
32  );
33 
34  $returner = null;
35  if ($result->RecordCount() != 0) {
36  $returner =& $this->_returnStaticPageFromRow($result->GetRowAssoc(false));
37  }
38  $result->Close();
39  return $returner;
40  }
41 
42  function &getStaticPagesByJournalId($journalId, $rangeInfo = null) {
43  $result = $this->retrieveRange(
44  'SELECT * FROM static_pages WHERE journal_id = ?', $journalId, $rangeInfo
45  );
46 
47  $returner = new DAOResultFactory($result, $this, '_returnStaticPageFromRow');
48  return $returner;
49  }
50 
51  function getStaticPageByPath($journalId, $path) {
52  $result = $this->retrieve(
53  'SELECT * FROM static_pages WHERE journal_id = ? AND path = ?', array($journalId, $path)
54  );
55 
56  $returner = null;
57  if ($result->RecordCount() != 0) {
58  $returner =& $this->_returnStaticPageFromRow($result->GetRowAssoc(false));
59  }
60  $result->Close();
61  return $returner;
62  }
63 
64  function insertStaticPage(&$staticPage) {
65  $this->update(
66  'INSERT INTO static_pages
67  (journal_id, path)
68  VALUES
69  (?, ?)',
70  array(
71  $staticPage->getJournalId(),
72  $staticPage->getPath()
73  )
74  );
75 
76  $staticPage->setId($this->getInsertId());
77  $this->updateLocaleFields($staticPage);
78 
79  return $staticPage->getId();
80  }
81 
82  function updateStaticPage(&$staticPage) {
83  $returner = $this->update(
84  'UPDATE static_pages
85  SET
86  journal_id = ?,
87  path = ?
88  WHERE static_page_id = ?',
89  array(
90  $staticPage->getJournalId(),
91  $staticPage->getPath(),
92  $staticPage->getId()
93  )
94  );
95  $this->updateLocaleFields($staticPage);
96  return $returner;
97  }
98 
99  function deleteStaticPageById($staticPageId) {
100  $returner = $this->update(
101  'DELETE FROM static_pages WHERE static_page_id = ?', $staticPageId
102  );
103  return $this->update(
104  'DELETE FROM static_page_settings WHERE static_page_id = ?', $staticPageId
105  );
106  }
107 
108  function &_returnStaticPageFromRow($row) {
109  $staticPagesPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
110  $staticPagesPlugin->import('StaticPage');
111 
112  $staticPage = new StaticPage();
113  $staticPage->setId($row['static_page_id']);
114  $staticPage->setPath($row['path']);
115  $staticPage->setJournalId($row['journal_id']);
116 
117  $this->getDataObjectSettings('static_page_settings', 'static_page_id', $row['static_page_id'], $staticPage);
118  return $staticPage;
119  }
120 
121  function getInsertId() {
122  return $this->_getInsertId('static_pages', 'static_page_id');
123  }
124 
129  function getLocaleFieldNames() {
130  return array('title', 'content');
131  }
137  function updateLocaleFields(&$staticPage) {
138  $this->updateDataObjectSettings('static_page_settings', $staticPage, array(
139  'static_page_id' => $staticPage->getId()
140  ));
141  }
142 
150  function duplicatePathExists ($path, $journalId, $staticPageId = null) {
151  $params = array(
152  $journalId,
153  $path
154  );
155  if (isset($staticPageId)) $params[] = $staticPageId;
156 
157  $result = $this->retrieve(
158  'SELECT *
159  FROM static_pages
160  WHERE journal_id = ?
161  AND path = ?' .
162  (isset($staticPageId)?' AND NOT (static_page_id = ?)':''),
163  $params
164  );
165 
166  if($result->RecordCount() == 0) {
167  // no duplicate exists
168  $returner = false;
169  } else {
170  $returner = true;
171  }
172  return $returner;
173  }
174 }
175 ?>
updateLocaleFields(&$staticPage)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
StaticPagesDAO($parentPluginName)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
duplicatePathExists($path, $journalId, $staticPageId=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
static & getPlugin($category, $name)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208