00001 <?php
00002
00017 import ('classes.press.SocialMedia');
00018
00019 class SocialMediaDAO extends DAO {
00023 function SocialMediaDAO() {
00024 parent::DAO();
00025 }
00026
00033 function &getById($socialMediaId, $pressId = null) {
00034 $params = array((int) $socialMediaId);
00035 if ($pressId) $params[] = (int) $pressId;
00036
00037 $result =& $this->retrieve(
00038 'SELECT *
00039 FROM social_media
00040 WHERE social_media_id = ?
00041 ' . ($pressId?' AND press_id = ?':''),
00042 $params
00043 );
00044
00045 $returner = null;
00046 if ($result->RecordCount() != 0) {
00047 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00048 }
00049
00050 $result->Close();
00051 unset($result);
00052
00053 return $returner;
00054 }
00055
00060 function newDataObject() {
00061 return new SocialMedia();
00062 }
00063
00069 function _fromRow(&$row) {
00070 $socialMedia = $this->newDataObject();
00071
00072 $socialMedia->setId($row['social_media_id']);
00073 $socialMedia->setPressId($row['press_id']);
00074 $socialMedia->setCode($row['code']);
00075 $socialMedia->setIncludeInCatalog($row['include_in_catalog']);
00076
00077 $this->getDataObjectSettings('social_media_settings', 'social_media_id', $row['social_media_id'], $socialMedia);
00078
00079 HookRegistry::call('SocialMediaDAO::_fromRow', array(&$socialMedia, &$row));
00080
00081 return $socialMedia;
00082 }
00083
00088 function getLocaleFieldNames() {
00089 return array('platform');
00090 }
00091
00096 function updateLocaleFields(&$socialMedia) {
00097 $this->updateDataObjectSettings(
00098 'social_media_settings', $socialMedia,
00099 array(
00100 'social_media_id' => $socialMedia->getId(),
00101 )
00102 );
00103 }
00104
00110 function insertObject(&$socialMedia) {
00111 $this->update(
00112 'INSERT INTO social_media
00113 (press_id, code, include_in_catalog)
00114 VALUES
00115 (?, ?, ?)',
00116 array(
00117 (int) $socialMedia->getPressId(),
00118 $socialMedia->getCode(),
00119 $socialMedia->getIncludeInCatalog(),
00120 )
00121 );
00122
00123 $socialMedia->setId($this->getInsertSocialMediaId());
00124 $this->updateLocaleFields($socialMedia);
00125 return $socialMedia->getId();
00126 }
00127
00132 function updateObject($socialMedia) {
00133 $returner = $this->update(
00134 'UPDATE social_media
00135 SET press_id = ?,
00136 code = ?,
00137 include_in_catalog = ?
00138 WHERE social_media_id = ?',
00139 array(
00140 (int) $socialMedia->getPressId(),
00141 $socialMedia->getCode(),
00142 (int) $socialMedia->getIncludeInCatalog(),
00143 (int) $socialMedia->getId(),
00144 )
00145 );
00146 $this->updateLocaleFields($socialMedia);
00147 return $returner;
00148 }
00149
00154 function deleteObject(&$socialMedia) {
00155 return $this->deleteById(
00156 $socialMedia->getId(),
00157 $socialMedia->getPressId()
00158 );
00159 }
00160
00166 function deleteById($socialMediaId, $pressId = null) {
00167 $params = array((int) $socialMediaId);
00168 if ($pressId) $params[] = (int) $pressId;
00169
00170 $this->update(
00171 'DELETE FROM social_media
00172 WHERE social_media_id = ?
00173 ' . ($pressId?' AND press_id = ?':''),
00174 $params
00175 );
00176
00177 if ($this->getAffectedRows()) {
00178 return $this->update(
00179 'DELETE FROM social_media_settings WHERE social_media_id = ?',
00180 array((int) $socialMediaId)
00181 );
00182 }
00183 }
00184
00191 function deleteByPressId($pressId) {
00192 $socialMediaObjects =& $this->getByPressId($pressId);
00193 while ($socialMedia =& $socialMediaObjects->next()) {
00194 $this->deleteObject($socialMedia, $pressId);
00195 unset($socialMedia);
00196 }
00197 }
00198
00204 function &getByPressId($pressId, $rangeInfo = null) {
00205 $params = array((int) $pressId);
00206
00207 $result =& $this->retrieveRange(
00208 'SELECT *
00209 FROM social_media
00210 WHERE press_id = ?',
00211 $params,
00212 $rangeInfo
00213 );
00214
00215 $returner = new DAOResultFactory($result, $this, '_fromRow');
00216 return $returner;
00217 }
00218
00224 function &getEnabledForCatalogByPressId($pressId, $rangeInfo = null) {
00225 $params = array((int) $pressId);
00226
00227 $result =& $this->retrieveRange(
00228 'SELECT *
00229 FROM social_media
00230 WHERE include_in_catalog = 1 AND press_id = ?',
00231 $params,
00232 $rangeInfo
00233 );
00234
00235 $returner = new DAOResultFactory($result, $this, '_fromRow');
00236 return $returner;
00237 }
00238
00244 function &getEnabledForPressByPressId($pressId, $rangeInfo = null) {
00245 $params = array((int) $pressId);
00246
00247 $result =& $this->retrieveRange(
00248 'SELECT *
00249 FROM social_media
00250 WHERE include_in_catalog = 0 AND press_id = ?',
00251 $params,
00252 $rangeInfo
00253 );
00254
00255 $returner = new DAOResultFactory($result, $this, '_fromRow');
00256 return $returner;
00257 }
00258
00263 function getInsertSocialMediaId() {
00264 return $this->getInsertId('social_media', 'social_media_id');
00265 }
00266 }
00267 ?>