00001 <?php
00002
00017 import ('classes.press.FooterLink');
00018
00019 class FooterLinkDAO extends DAO {
00023 function FooterLinkDAO() {
00024 parent::DAO();
00025 }
00026
00033 function &getById($footerLinkId, $pressId = null) {
00034 $params = array((int) $footerLinkId);
00035 if ($pressId) $params[] = (int) $pressId;
00036
00037 $result =& $this->retrieve(
00038 'SELECT *
00039 FROM footerlinks
00040 WHERE footerlink_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 FooterLink();
00062 }
00063
00069 function _fromRow(&$row) {
00070 $footerLink = $this->newDataObject();
00071
00072 $footerLink->setId($row['footerlink_id']);
00073 $footerLink->setPressId($row['press_id']);
00074 $footerLink->setUrl($row['url']);
00075 $footerLink->setCategoryId($row['footer_category_id']);
00076
00077 $this->getDataObjectSettings('footerlink_settings', 'footerlink_id', $row['footerlink_id'], $footerLink);
00078
00079 HookRegistry::call('FooterLinkDAO::_fromRow', array(&$footerLink, &$row));
00080
00081 return $footerLink;
00082 }
00083
00088 function getLocaleFieldNames() {
00089 return array('title');
00090 }
00091
00096 function updateLocaleFields(&$footerLink) {
00097 $this->updateDataObjectSettings(
00098 'footerlink_settings', $footerLink,
00099 array(
00100 'footerlink_id' => $footerLink->getId()
00101 )
00102 );
00103 }
00104
00110 function insertObject(&$footerLink) {
00111 $this->update(
00112 'INSERT INTO footerlinks
00113 (press_id, footer_category_id, url)
00114 VALUES
00115 (?, ?, ?)',
00116 array(
00117 (int) $footerLink->getPressId(),
00118 (int) $footerLink->getCategoryId(),
00119 $footerLink->getUrl()
00120 )
00121 );
00122
00123 $footerLink->setId($this->getInsertFooterLinkId());
00124 $this->updateLocaleFields($footerLink);
00125 return $footerLink->getId();
00126 }
00127
00132 function updateObject($footerLink) {
00133 $returner = $this->update(
00134 'UPDATE footerlinks
00135 SET press_id = ?,
00136 footer_category_id = ?,
00137 url = ?
00138 WHERE footerlink_id = ?',
00139 array(
00140 (int) $footerLink->getPressId(),
00141 (int) $footerLink->getCategoryId(),
00142 $footerLink->getUrl(),
00143 (int) $footerLink->getId()
00144 )
00145 );
00146 $this->updateLocaleFields($footerLink);
00147 return $returner;
00148 }
00149
00154 function deleteObject(&$footerLink) {
00155 return $this->deleteById(
00156 $footerLink->getId(),
00157 $footerLink->getPressId()
00158 );
00159 }
00160
00166 function deleteById($footerLinkId, $pressId = null) {
00167 $params = array((int) $footerLinkId);
00168 if ($pressId) $params[] = (int) $pressId;
00169
00170 $this->update(
00171 'DELETE FROM footerlinks
00172 WHERE footerlink_id = ?
00173 ' . ($pressId?' AND press_id = ?':''),
00174 $params
00175 );
00176
00177
00178
00179 if ($this->getAffectedRows()) {
00180 return $this->update(
00181 'DELETE FROM footerlink_settings WHERE footerlink_id = ?',
00182 array((int) $footerLinkId)
00183 );
00184 }
00185 }
00186
00193 function deleteByPressId($pressId) {
00194 $footerlinks =& $this->getByPressId($pressId);
00195 while ($footerLink =& $footerlinks->next()) {
00196 $this->deleteObject($footerLink, $pressId);
00197 unset($footerLink);
00198 }
00199 }
00200
00205 function &getByCategoryId($categoryId, $pressId = null, $rangeInfo = null) {
00206 $params = array((int) $categoryId);
00207 if ($pressId) $params[] = (int) $pressId;
00208
00209 $result =& $this->retrieveRange(
00210 'SELECT *
00211 FROM footerlinks
00212 WHERE footer_category_id = ?
00213 ' . ($pressId?' AND press_id = ?':''),
00214 $params
00215 );
00216
00217 $returner = new DAOResultFactory($result, $this, '_fromRow');
00218 return $returner;
00219 }
00220
00225 function getInsertFooterLinkId() {
00226 return $this->getInsertId('footerlinks', 'footerlink_id');
00227 }
00228
00234 function getLargestCategoryTotalByPressId($pressId) {
00235 $result =& $this->retrieve(
00236 'SELECT count(*) AS total
00237 FROM footerlinks
00238 WHERE press_id = ? GROUP BY footer_category_id
00239 ORDER BY total DESC LIMIT 1', array((int)$pressId));
00240
00241 $returner = null;
00242 if ($result->RecordCount() != 0) {
00243 $row =& $result->GetRowAssoc(false);
00244 $returner = $row['total'];
00245 }
00246
00247 $result->Close();
00248 unset($result);
00249
00250 return $returner;
00251
00252 }
00253 }
00254 ?>