| // +---------------------------------------------------------------------------+ // $Id$ require_once SGL_CORE_DIR . '/Category.php'; /** * Basic Permission object. * * @package SGL * @author Demian Turner * @version $Revision: 1.5 $ */ class SGL_CategoryPerms extends SGL_Category { var $sPerms = ''; var $aPerms = array(); var $catID = 0; function SGL_CategoryPerms($catID = -1) { SGL::logMessage(null, PEAR_LOG_DEBUG); if (isset($catID) && $catID >= 0) { $this->init($catID); } else { SGL::raiseError('No category ID passed', SGL_ERROR_INVALIDARGS); } parent::SGL_Category(); } function init($catID) { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->set('catID', $catID); } function update() { SGL::logMessage(null, PEAR_LOG_DEBUG); // only grab keys where perms = 0 // outputs an 1D array of GIDs where viewing is NOT permitted $aKeys = array_keys($this->aPerms, 0); // generate perms string from array $this->sPerms = implode(',', $aKeys); // notice null is a mysql null which is not the same as a PHP null $permsStr = count($aKeys) ? "perms = '$this->sPerms'" : 'perms = NULL'; $dbh = &SGL_DB::singleton(); $query = " UPDATE " . SGL_Config::get('table.category') . " SET $permsStr WHERE category_id = $this->catID "; $result = $dbh->query($query); // recurse to update children if ($this->isBranch($this->catID)) { $childNodeArray = $this->getChildren($this->catID); $this->_updateChildNodes($childNodeArray); } } function _updateChildNodes($childNodeArray) { SGL::logMessage(null, PEAR_LOG_DEBUG); $aKeys = array_keys($this->aPerms, 0); // generate perms string from array $this->sPerms = implode(',', $aKeys); // notice null is a mysql null which is not comparable with a PHP null $permsStr = count($aKeys) ? "perms = '$this->sPerms'" : 'perms = NULL'; $dbh = & SGL_DB::singleton(); for ($x=0; $x < count($childNodeArray); $x++) { $query = " UPDATE " . SGL_Config::get('table.category') . " SET $permsStr WHERE category_id = {$childNodeArray[$x]['category_id']} "; $result = $dbh->query($query); // recurse if child links detected if ($this->isBranch($childNodeArray[$x]['category_id'])) { $childNodeArrayInner = $this->getChildren($childNodeArray[$x]['category_id']); $this->_updateChildNodes($childNodeArrayInner); } } } function set($attributeName, $attributeValue) { $this->$attributeName = $attributeValue; } function get($attribute) { return $this->$attribute; } } ?>