| // +---------------------------------------------------------------------------+ // $Id: PlanetDAO.php,v 1.2 2005/04/17 02:15:02 demian Exp $ require_once 'DB/DataObject.php'; require_once SGL_LIB_DIR .'/SGL/Config.php'; /** * Manage planet links * * @package planet * @author Alexander J. Tarahchanowicz II */ class PlanetDAO { function PlanetDAO() { $c = &SGL_Config::singleton(); $this->conf = $c->getAll(); $this->dbh = $this->_getDb(); } function &_getDb() { $locator = &SGL_ServiceLocator::singleton(); $dbh = $locator->get('DB'); if (!$dbh) { $dbh = & SGL_DB::singleton(); $locator->register('DB', $dbh); } return $dbh; } /** * Returns a singleton PlanetDAO instance. * * example usage: * $da = & PlanetDAO::singleton(); * warning: in order to work correctly, the DA * singleton must be instantiated statically and * by reference * * @access public * @static * @return PlanetDAO reference to PlanetDAO object */ function &singleton() { static $instance; // If the instance is not there, create one if (!isset($instance)) { $class = __CLASS__; $instance = new $class(); } return $instance; } function hasBlogLink($usrId = null) { if (is_null($usrId)) { $usrId = SGL_Session::getUid(); } $planet = DB_DataObject::factory($this->conf['table']['planet_links']); $planet->usr_id = $usrId; $success = $planet->find(); if (PEAR::isError($success)) { return false; } return $success; } function addBlogLink($aData) { // detect if usr_id has been set if (!array_key_exists('usr_id', $aData) || empty($aData['usr_id'])) { $aData['usr_id'] = SGL_Session::getUid(); } $planet = &DB_DataObject::factory($this->conf['table']['planet_links']); $planet->setFrom($aData); $planet->planet_link_id = $this->dbh->nextId($this->conf['table']['planet_links']); $planet->created_by_id = SGL_Session::getUid(); $planet->updated_by_id = SGL_Session::getUid(); $planet->date_created = SGL_Date::getTime(); $planet->last_updated = SGL_Date::getTime(); $success = $planet->insert(); if (PEAR::isError($success)) { return false; } return $planet->planet_link_id; } function deleteBlogLink($planetLinkId) { $planet = & DB_DataObject::factory($this->conf['table']['planet_links']); $planet->planet_link_id = $planetLinkId; $success = $planet->delete(); if (PEAR::isError($success)) { return false; } return $success; } function getBlogLink($planetLinkId) { $planet = &DB_DataObject::factory($this->conf['table']['planet_links']); $planet->get($planetLinkId); if (PEAR::isError($planet)) { return false; } return $planet; } function getBlogLinkByUsrId($usrId) { $planet = &DB_DataObject::factory($this->conf['table']['planet_links']); $planet->get('usr_id', $usrId); if (PEAR::isError($planet)) { return false; } return $planet; } function updateBlogLink($aData) { // detect if usr_id has been set if (!array_key_exists('usr_id', $aData) || empty($aData['usr_id'])) { $aData['usr_id'] = SGL_Session::getUid(); } $planet = & DB_DataObject::factory($this->conf['table']['planet_links']); $planet->get($aData['planet_link_id']); $planet->setFrom($aData); $planet->updated_by_id = SGL_Session::getUid(); $planet->last_updated = SGL_Date::getTime(); $success = $planet->update(); if (PEAR::isError($success)) { return false; } return true; } } ?>