• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/press/FooterCategoryDAO.inc.php

00001 <?php
00002 
00017 import ('classes.press.FooterCategory');
00018 
00019 class FooterCategoryDAO extends DAO {
00023    function FooterCategoryDAO() {
00024       parent::DAO();
00025    }
00026 
00033    function &getById($categoryId, $pressId = null) {
00034       $params = array((int) $categoryId);
00035       if ($pressId) $params[] = (int) $pressId;
00036 
00037       $result =& $this->retrieve(
00038          'SELECT *
00039          FROM footer_categories
00040          WHERE footer_category_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 
00062    function &getByPath($path, $pressId) {
00063       $returner = null;
00064       $result =& $this->retrieve(
00065          'SELECT * FROM footer_categories WHERE path = ? AND press_id = ?',
00066          array((string) $path, (int) $pressId)
00067       );
00068 
00069       if ($result->RecordCount() != 0) {
00070          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00071       }
00072 
00073       $result->Close();
00074       unset($result);
00075 
00076       return $returner;
00077    }
00078 
00085    function categoryExistsByPath($path, $pressId = null) {
00086       $params = array($path);
00087       if ($pressId) $params[] = (int) $pressId;
00088 
00089       $result =& $this->retrieve(
00090          'SELECT COUNT(*) FROM footer_categories WHERE path = ?
00091          ' . ($pressId?' AND press_id = ?':''),
00092          $params
00093       );
00094       $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00095 
00096       $result->Close();
00097       unset($result);
00098 
00099       return $returner;
00100    }
00101 
00106    function newDataObject() {
00107       return new FooterCategory();
00108    }
00109 
00115    function _fromRow(&$row) {
00116       $category = $this->newDataObject();
00117 
00118       $category->setId($row['footer_category_id']);
00119       $category->setPressId($row['press_id']);
00120       $category->setPath($row['path']);
00121 
00122       $this->getDataObjectSettings('footer_category_settings', 'footer_category_id', $row['footer_category_id'], $category);
00123 
00124       HookRegistry::call('FooterCategoryDAO::_fromRow', array(&$category, &$row));
00125 
00126       return $category;
00127    }
00128 
00133    function getLocaleFieldNames() {
00134       return array('title', 'description');
00135    }
00136 
00141    function updateLocaleFields(&$category) {
00142       $this->updateDataObjectSettings(
00143          'footer_category_settings', $category,
00144          array(
00145             'footer_category_id' => $category->getId()
00146          )
00147       );
00148    }
00149 
00155    function insertObject(&$category) {
00156       $this->update(
00157          'INSERT INTO footer_categories
00158             (press_id, path)
00159             VALUES
00160             (?, ?)',
00161          array(
00162             (int) $category->getPressId(),
00163             $category->getPath()
00164          )
00165       );
00166 
00167       $category->setId($this->getInsertFooterCategoryId());
00168       $this->updateLocaleFields($category);
00169       return $category->getId();
00170    }
00171 
00176    function updateObject($category) {
00177       $returner = $this->update(
00178          'UPDATE footer_categories
00179          SET   press_id = ?,
00180             path = ?
00181          WHERE footer_category_id = ?',
00182          array(
00183             (int) $category->getPressId(),
00184             $category->getPath(),
00185             (int) $category->getId()
00186          )
00187       );
00188       $this->updateLocaleFields($category);
00189       return $returner;
00190    }
00191 
00196    function deleteObject(&$category) {
00197       return $this->deleteById(
00198          $category->getId(),
00199          $category->getPressId()
00200       );
00201    }
00202 
00208    function deleteById($categoryId, $pressId = null) {
00209       $params = array((int) $categoryId);
00210       if ($pressId) $params[] = (int) $pressId;
00211 
00212       $this->update(
00213          'DELETE FROM footer_categories
00214          WHERE footer_category_id = ?
00215             ' . ($pressId?' AND press_id = ?':''),
00216          $params
00217       );
00218 
00219       // If the category was deleted (this validates press_id,
00220       // if specified), delete any associated settings as well.
00221       if ($this->getAffectedRows()) {
00222          $this->update(
00223             'DELETE FROM footer_category_settings WHERE footer_category_id = ?',
00224             array((int) $categoryId)
00225          );
00226 
00227          return true;
00228       }
00229    }
00230 
00237    function deleteByPressId($pressId) {
00238       $categories =& $this->getByPressId($pressId);
00239       while ($category =& $categories->next()) {
00240          $this->deleteObject($category, $pressId);
00241          unset($category);
00242       }
00243    }
00244 
00249    function &getByPressId($pressId, $rangeInfo = null) {
00250       $result =& $this->retrieveRange(
00251          'SELECT *
00252          FROM footer_categories
00253          WHERE press_id = ?',
00254          array((int) $pressId)
00255       );
00256 
00257       $returner = new DAOResultFactory($result, $this, '_fromRow');
00258       return $returner;
00259    }
00260 
00265    function &getNotEmptyByPressId($pressId, $rangeInfo = null) {
00266       $result =& $this->retrieveRange(
00267          'SELECT DISTINCT f.footer_category_id, f.*
00268          FROM  footer_categories f, footerlinks fl
00269          WHERE f.footer_category_id = fl.footer_category_id AND f.press_id = ?',
00270          array((int) $pressId)
00271       );
00272 
00273       $returner = new DAOResultFactory($result, $this, '_fromRow');
00274       return $returner;
00275    }
00276 
00281    function &getCountByPressId($pressId) {
00282       $result =& $this->retrieve(
00283          'SELECT COUNT(*)
00284          FROM footer_categories
00285          WHERE press_id = ?',
00286          (int) $pressId
00287       );
00288 
00289       $returner = $result->fields[0];
00290 
00291       $result->Close();
00292       unset($result);
00293       return $returner;
00294    }
00295 
00300    function getInsertFooterCategoryId() {
00301       return $this->getInsertId('footer_categories', 'footer_category_id');
00302    }
00303 }
00304 
00305 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1