【php开源代码栏目提醒】:网学会员php开源代码为您提供aclnode.php参考,解决您在aclnode.php学习中工作中的难题,参考学习。
<?php
/* SVN FILE: $Id: aclnode.php 4450 2007-02-05 05:18:05Z phpnut $ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp Cake
PHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.controller.components.dbacl.models
* @since CakePHP(tm) v 0.10.0.1232
* @version $Revision: 4450 $
* @modifiedby $LastChangedBy: phpnut $
* @lastmodified $Date: 2007-02-04 23:18:05 -0600 (Sun, 04 Feb 2007) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Load AppModel class
*/
loadModel();
/**
* Short description for file.
*
* Long description for file
*
* @package cake
* @subpackage cake.cake.libs.controller.components.dbacl.models
*
*/
class AclNode extends AppModel {
/**
* Database configuration to use
*
* @var string
*/
var $useDbConfig = ACL_DATABASE;
/**
* Cache Queries
*
* @var boolean
*/
var $cacheQueries = false;
/**
* Creates a new ARO/ACO node
*
* @param int $linkId
* @param mixed $parentId
* @param string $alias
* @return boolean True on success, false on fail
* @access public
*/
function create($linkId = 0, $parentId = null, $alias = '') {
parent::create();
if (strtolower(get_class($this)) == "aclnode") {
trigger_error("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.", E_USER_ERROR);
return null;
}
extract ($this->__dataVars());
if ($parentId == null || $parentId === 0) {
$parent = $this->find(null, 'MAX(rght) as rght', null, -1);
$parent['lft'] = $parent[0]['rght'];
if ($parent[0]['rght'] == null || !$parent[0]['rght']) {
$parent['lft'] = 0;
}
} else {
$parent = $this->find($this->_resolveID($parentId), null, null, 0);
if ($parent == null || count($parent) == 0) {
trigger_error("Null parent in {$class}::create()", E_USER_WARNING);
return null;
}
$parent = $parent[$class];
$this->_syncTable(1, $parent['lft'], $parent['lft']);
}
$return = $this->save(array($class => array($secondary_id => $linkId,
'alias' => $alias,
'lft' => $parent['lft'] + 1,
'rght' => $parent['lft'] + 2)));
$this->id = $this->getLastInsertID();
return $return;
}
/**
* Deletes the ARO/ACO node with the given ID
*
* @param mixed $id The id or alias of an ARO/ACO node
* @return boolean True on success, false on fail
* @access public
*/
function delete($id) {
extract ($this->__dataVars());
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$result = $this->find($this->_resolveID($id));
$object = $result[$class];
if ($object == null || count($object) == 0) {
return false;
}
$children = $this->findAll(array("{$class}.rght" => "< {$result[$class]['rght']}", "{$class}.lft" => "> {$result[$class]['lft']}"), 'id', null, null, null, -1);
$idList = DataSource::getFieldValue($children, '{n}.' . $class . '.id');
$idList[] = $result[$class]['id'];
$this->ArosAco->query('DELETE FROM ' . $db->fullTableName($this->ArosAco) . " WHERE {$class}_id in (" . implode(', ', $idList) . ')');
$table = $db->fullTableName($this);
$this->query("DELETE FROM {$table} WHERE {$table}.lft >= {$result[$class]['lft']} AND {$table}.rght <= {$result[$class]['rght']}");
$shift = 1 + $result[$class]['rght'] - $result[$class]['lft'];
$this->query('UPDATE ' . $table . ' SET ' . $db->name('rght') . ' = ' . $db->name('rght') . ' - ' . $shift . ' WHERE ' . $db->name('rght') . ' > ' . $result[$class]['rght']);
$this->query('UPDATE ' . $table . ' SET ' . $db->name('lft') . ' = ' . $db->name('lft') . ' - ' . $shift . ' WHERE ' . $db->name('lft') . ' > ' . $result[$class]['lft']);
return true;
}
/**
* Sets the parent of the given node
*
* @param mixed $parentId
* @param mixed $id
* @return boolean True on success, false on failure
* @access public
*/
function setParent($parentId = null, $id = null) {
if (strtolower(get_class($this)) == "aclnode") {
trigger_error("[acl_base] The AclBase class constructor has been called,