Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
PKPSocialMediaDAO.inc.php
1 <?php
2 
17 import ('lib.pkp.classes.context.PKPSocialMedia');
18 
19 class PKPSocialMediaDAO extends DAO {
23  function PKPSocialMediaDAO() {
24  parent::DAO();
25  }
26 
33  function getById($socialMediaId, $contextId = null) {
34  $params = array((int) $socialMediaId);
35  if ($contextId) $params[] = (int) $contextId;
36 
37  $result = $this->retrieve(
38  'SELECT *
39  FROM social_media
40  WHERE social_media_id = ?
41  ' . ($contextId?' AND context_id = ?':''),
42  $params
43  );
44 
45  $returner = null;
46  if ($result->RecordCount() != 0) {
47  $returner = $this->_fromRow($result->GetRowAssoc(false));
48  }
49 
50  $result->Close();
51  return $returner;
52  }
53 
58  function newDataObject() {
59  return new PKPSocialMedia();
60  }
61 
67  function _fromRow($row) {
68  $socialMedia = $this->newDataObject();
69 
70  $socialMedia->setId($row['social_media_id']);
71  $socialMedia->setContextId($row['context_id']);
72  $socialMedia->setCode($row['code']);
73  $socialMedia->setIncludeInCatalog($row['include_in_catalog']);
74 
75  $this->getDataObjectSettings('social_media_settings', 'social_media_id', $row['social_media_id'], $socialMedia);
76 
77  HookRegistry::call('SocialMediaDAO::_fromRow', array(&$socialMedia, &$row));
78 
79  return $socialMedia;
80  }
81 
86  function getLocaleFieldNames() {
87  return array('platform');
88  }
89 
94  function updateLocaleFields($socialMedia) {
96  'social_media_settings', $socialMedia,
97  array(
98  'social_media_id' => $socialMedia->getId(),
99  )
100  );
101  }
102 
108  function insertObject($socialMedia) {
109  $this->update(
110  'INSERT INTO social_media
111  (context_id, code, include_in_catalog)
112  VALUES
113  (?, ?, ?)',
114  array(
115  (int) $socialMedia->getContextId(),
116  $socialMedia->getCode(),
117  $socialMedia->getIncludeInCatalog(),
118  )
119  );
120 
121  $socialMedia->setId($this->getInsertId());
122  $this->updateLocaleFields($socialMedia);
123  return $socialMedia->getId();
124  }
125 
130  function updateObject($socialMedia) {
131  $returner = $this->update(
132  'UPDATE social_media
133  SET context_id = ?,
134  code = ?,
135  include_in_catalog = ?
136  WHERE social_media_id = ?',
137  array(
138  (int) $socialMedia->getContextId(),
139  $socialMedia->getCode(),
140  (int) $socialMedia->getIncludeInCatalog(),
141  (int) $socialMedia->getId(),
142  )
143  );
144  $this->updateLocaleFields($socialMedia);
145  return $returner;
146  }
147 
152  function deleteObject($socialMedia) {
153  return $this->deleteById(
154  $socialMedia->getId(),
155  $socialMedia->getContextId()
156  );
157  }
158 
164  function deleteById($socialMediaId, $contextId = null) {
165  $params = array((int) $socialMediaId);
166  if ($contextId) $params[] = (int) $contextId;
167 
168  $this->update(
169  'DELETE FROM social_media
170  WHERE social_media_id = ?
171  ' . ($contextId?' AND context_id = ?':''),
172  $params
173  );
174 
175  if ($this->getAffectedRows()) {
176  return $this->update(
177  'DELETE FROM social_media_settings WHERE social_media_id = ?',
178  array((int) $socialMediaId)
179  );
180  }
181  }
182 
189  function deleteByContextId($contextId) {
190  $socialMediaObjects = $this->getByContextId($contextId);
191  while ($socialMedia = $socialMediaObjects->next()) {
192  $this->deleteObject($socialMedia, $contextId);
193  }
194  }
195 
201  function getByContextId($contextId, $rangeInfo = null) {
202  $params = array((int) $contextId);
203 
204  $result = $this->retrieveRange(
205  'SELECT *
206  FROM social_media
207  WHERE context_id = ?',
208  $params,
209  $rangeInfo
210  );
211 
212  $returner = new DAOResultFactory($result, $this, '_fromRow');
213  return $returner;
214  }
215 
221  function getEnabledForCatalogByContextId($contextId, $rangeInfo = null) {
222  $params = array((int) $contextId);
223 
224  $result = $this->retrieveRange(
225  'SELECT *
226  FROM social_media
227  WHERE include_in_catalog = 1 AND context_id = ?',
228  $params,
229  $rangeInfo
230  );
231 
232  $returner = new DAOResultFactory($result, $this, '_fromRow');
233  return $returner;
234  }
235 
241  function getEnabledForContextByContextId($contextId, $rangeInfo = null) {
242  $params = array((int) $contextId);
243 
244  $result = $this->retrieveRange(
245  'SELECT *
246  FROM social_media
247  WHERE include_in_catalog = 0 AND context_id = ?',
248  $params,
249  $rangeInfo
250  );
251 
252  $returner = new DAOResultFactory($result, $this, '_fromRow');
253  return $returner;
254  }
255 
260  function getInsertId() {
261  return $this->_getInsertId('social_media', 'social_media_id');
262  }
263 }
264 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Operations for retrieving and modifying PKPSocialMedia objects.
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
deleteById($socialMediaId, $contextId=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getAffectedRows()
Definition: DAO.inc.php:258
getById($socialMediaId, $contextId=null)
static call($hookName, $args=null)
updateLocaleFields($socialMedia)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getEnabledForContextByContextId($contextId, $rangeInfo=null)
getByContextId($contextId, $rangeInfo=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
getEnabledForCatalogByContextId($contextId, $rangeInfo=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Describes basic PKPSocialMedia properties.