mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-16 03:48:24 +00:00
9560f78884
Revision: [1638] removing php short tags Revision: [1637] Remove renderElememnts loading of helpers also, forgot it in the last commit Revision: [1636] Refactoring after profiling code. Session was creating a new instance of Dispatcher removed the need for it. Added a check to the Component class to pass the base to the SessionComponent class, will refactor that at a later time. Changed View class so it would not load helpers when rending a layout, no need for that. A great performance boost after the change. Change the loadModels method call in app/webroot/index.php. Will only attempt the loadModels call if the AppModel class is not in memory, and the Database class is in memory. Removed all unnecessary calls to basics uses(). Again another big performance increase. Added fix to the Html::guiListTree() after discussing the output that is expected. A ticket was closed on this already. Revision: [1635] Removing calls to basic uses() Revision: [1634] Removing calls to basics uses() that are not needed. Revision: [1633] Removing calls to basics uses() that are not needed. Moved Object class further up in the loading order Revision: [1632] adding fix for Ticket #132 Revision: [1631] Added fix from Ticket #122 Revision: [1630] Scaffold views can now be placed in a view directory. These will override the core. Example (Must have the scaffold dot name): app/views/posts/scaffold.list.thtml app/views/posts/scaffold.new.thtml app/views/posts/scaffold.edit.thtml app/views/posts/scaffold.show.thtml Revision: [1629] Think I fixed the issue with scaffold showing proper dates prior to January 1 1970 00:00:00. Revision: [1628] Added a few more change to allow saving dates prior to January 1 1970 00:00:00. Still a few issues with this, but will get them figured out soon. Changed scaffold to use only one form view. Revision: [1627] Added fix for Ticket #189 Revision: [1626] Added fix for Ticket #120. Revision: [1625] left justified doc blocks Revision: [1624] remove files from uses() that are loaded by default in app/webroot/index.php no reason to attempt to load them again in the classes Revision: [1623] adding check to the loadModels and loadController that will only attempt to load files if the classes are not already in memory Revision: [1622] Adding fix to time helper that was lost in a previous merge Removing all tabs from code Revision: [1621] Addtional model validation fixes Revision: [1620] fixed parse error Revision: [1619] Fixing ticket #102 Revision: [1618] correcting mime types and keywords Revision: [1617] correcting mime types and keywords Revision: [1616] fixed link in footer Revision: [1615] Fixing ticket #207 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1639 3807eeeb-6ff5-0310-8944-8be069107fe0
337 lines
No EOL
8.7 KiB
PHP
337 lines
No EOL
8.7 KiB
PHP
<?php
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
* Short description for file.
|
|
*
|
|
* Long description for file
|
|
*
|
|
* PHP versions 4 and 5
|
|
*
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
* Copyright (c) 2005, 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 (c) 2005, Cake Software Foundation, Inc.
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.controller.components.dbacl.models
|
|
* @since CakePHP v 0.10.0.1232
|
|
* @version $Revision$
|
|
* @modifiedby $LastChangedBy$
|
|
* @lastmodified $Date$
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
*/
|
|
|
|
/**
|
|
* Short description.
|
|
*/
|
|
require_once(CAKE . 'app_model.php');
|
|
|
|
/**
|
|
* Short description for file.
|
|
*
|
|
* Long description for file
|
|
*
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.controller.components.dbacl.models
|
|
* @since CakePHP v 0.10.0.1232
|
|
*
|
|
*/
|
|
class AclNode extends AppModel
|
|
{
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
* @var unknown_type
|
|
*/
|
|
var $useTable = false;
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
*/
|
|
function __construct($object = null, $parent = null)
|
|
{
|
|
parent::__construct();
|
|
$this->__setTable();
|
|
if($object != null)
|
|
{
|
|
$this->create($object, $parent);
|
|
}
|
|
exit();
|
|
}
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
* @param unknown_type $object A new ACL object. This can be a string for alias-based ACL, or a Model for object-based ACL
|
|
* @param unknown_type $parent The parent object
|
|
* @return unknown
|
|
*/
|
|
function create($object = null, $parent = null)
|
|
{
|
|
if (strtolower(get_class($this)) == "aclnode")
|
|
{
|
|
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
|
return NULL;
|
|
}
|
|
parent::create();
|
|
|
|
pr($this->__dataVars());
|
|
exit();
|
|
|
|
extract($this->__dataVars());
|
|
|
|
if($parent_id == null || $parent_id === 0)
|
|
{
|
|
$parent = $this->find(null, "MAX(rght)");
|
|
$parent['lft'] = $parent[0]['MAX(rght)'];
|
|
|
|
if($parent[0]['MAX(rght)'] == null)
|
|
{
|
|
// The tree is empty
|
|
$parent['lft'] = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$parent = $this->find($this->_resolveID($parent_id, $secondary_id));
|
|
if($parent == null || count($parent) == 0)
|
|
{
|
|
trigger_error("Null parent in {$class}::create()", E_USER_ERROR);
|
|
}
|
|
|
|
$parent = $parent[$class];
|
|
$this->_syncTable($table_name, 1, $parent['lft'], $parent['lft']);
|
|
}
|
|
|
|
$return = $this->save(array($class => array(
|
|
$secondary_id => $link_id,
|
|
'alias' => $alias,
|
|
'lft' => $parent['lft'] + 1,
|
|
'rght' => $parent['lft'] + 2
|
|
)));
|
|
|
|
$this->setId($this->getLastInsertID());
|
|
return $return;
|
|
}
|
|
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
* @param unknown_type $parent_id
|
|
* @param unknown_type $id
|
|
* @return unknown
|
|
*/
|
|
function setParent($parent_id = null, $id = null)
|
|
{
|
|
if (strtolower(get_class($this)) == "aclnode")
|
|
{
|
|
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
|
return null;
|
|
}
|
|
extract($this->__dataVars());
|
|
|
|
if($id == null && $this->id == false)
|
|
{
|
|
return false;
|
|
}
|
|
else if($id == null)
|
|
{
|
|
$id = $this->id;
|
|
}
|
|
|
|
$object = $this->find($this->_resolveID($id, $secondary_id));
|
|
if($object == null || count($object) == 0)
|
|
{
|
|
// Couldn't find object
|
|
return false;
|
|
}
|
|
$parent = $this->getParent(intval($object[$class][$secondary_id]));
|
|
|
|
// Node is already at root, or new parent == old parent
|
|
if(($parent == null && $parent_id == null) || ($parent_id == $parent[$class][$secondary_id]) || ($parent_id == $parent[$class]['alias']))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if($parent_id != null && $parent[$class]['lft'] <= $object[$class]['lft'] && $parent[$class]['rght'] >= $object[$class]['rght'])
|
|
{
|
|
// Can't move object inside self or own child
|
|
return false;
|
|
}
|
|
$this->_syncTable($table_name, 0, $object[$class]['lft'], $object[$class]['lft']);
|
|
|
|
if($parent_id == null)
|
|
{
|
|
$parent = $this->find(null, "MAX(rght)");
|
|
$parent['lft'] = $parent[0]['MAX(rght)'];
|
|
}
|
|
else
|
|
{
|
|
$parent = $this->find($this->_resolveID($parent_id, $secondary_id));
|
|
$parent = $parent[$class];
|
|
$this->_syncTable($table_name, 1, $parent['lft'], $parent['lft']);
|
|
}
|
|
|
|
$object[$class]['lft'] = $parent['lft'] + 1;
|
|
$object[$class]['rght'] = $parent['lft'] + 2;
|
|
$this->save($object);
|
|
|
|
if($parent['lft'] == 0)
|
|
{
|
|
$this->_syncTable($table_name, 2, $parent['lft'], $parent['lft']);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
* @param unknown_type $id
|
|
* @return unknown
|
|
*/
|
|
function getParent($id)
|
|
{
|
|
$path = $this->getPath($id);
|
|
if($path == null || count($path) < 2)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return $path[count($path) - 2];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The path to a node as an array, where the first element of the array is at the root of the tree, and the last element is the requested node
|
|
*
|
|
* @param mixed $id
|
|
* @return array
|
|
*/
|
|
function getPath($id)
|
|
{
|
|
if (strtolower(get_class($this)) == "aclnode")
|
|
{
|
|
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
|
return NULL;
|
|
}
|
|
extract($this->__dataVars());
|
|
|
|
$item = $this->find($this->_resolveID($id, $secondary_id));
|
|
if($item == null || count($item) == 0)
|
|
{
|
|
return null;
|
|
}
|
|
return $this->findAll("lft <= {$item[$class]['lft']} and rght >= {$item[$class]['rght']}");
|
|
}
|
|
|
|
/**
|
|
* Gets the child nodes of a specified element
|
|
*
|
|
* @param mixed $id
|
|
* @return array
|
|
*/
|
|
function getChildren($id)
|
|
{
|
|
if (strtolower(get_class($this)) == "aclnode")
|
|
{
|
|
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
|
return NULL;
|
|
}
|
|
extract($this->__dataVars());
|
|
|
|
$item = $this->find($this->_resolveID($id, $secondary_id));
|
|
return $this->findAll("lft > {$item[$class]['lft']} and rght < {$item[$class]['rght']}");
|
|
}
|
|
|
|
/**
|
|
* Gets a reference to a node object
|
|
*
|
|
* @param unknown_type $obj
|
|
* @param unknown_type $fKey
|
|
* @return unknown
|
|
*/
|
|
function _resolveID($obj, $fKey)
|
|
{
|
|
extract($this->__dataVars());
|
|
if(is_object($obj))
|
|
{
|
|
if(isset($obj->id) && isset($obj->name))
|
|
{
|
|
return "model = '{$obj->name}' and {$secondary_id} = {$obj->id}";
|
|
}
|
|
return null;
|
|
}
|
|
else if(is_array($obj))
|
|
{
|
|
$keys = array_keys($obj);
|
|
$key1 = $keys[0];
|
|
if(is_string($key1) && is_array($obj[$key1]) && isset($obj[$key1]['id']))
|
|
{
|
|
return "model = '{$key1}' and {$secondary_id} = {$obj[$key1]['id']}";
|
|
}
|
|
return null;
|
|
}
|
|
else if(is_string($obj))
|
|
{
|
|
$path = explode('/', $obj);
|
|
|
|
}
|
|
$key = (is_string($id) ? 'alias' : $fKey);
|
|
$val = (is_string($id) ? '"' . addslashes($id) . '"' : $id);
|
|
return "{$key} = {$val}";
|
|
}
|
|
|
|
/**
|
|
* Private method: modifies the left and right values of affected nodes in a tree when a node is added or removed
|
|
*
|
|
* @param string $table aros or acos, depending on the tree to be modified
|
|
* @param int $dir The direction in which to shift the nodes
|
|
* @param int $lft The left position of the node being added or removed
|
|
* @param int $rght The right position of the node being added or removed
|
|
*/
|
|
function _syncTable($table, $dir, $lft, $rght)
|
|
{
|
|
$shift = ($dir == 2 ? 1 : 2);
|
|
$table = strtolower($table);
|
|
$this->db->query("UPDATE {$table} SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght);
|
|
$this->db->query("UPDATE {$table} SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft);
|
|
}
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
* @return unknown
|
|
*/
|
|
function __dataVars()
|
|
{
|
|
$vars = array();
|
|
$class = Inflector::camelize(strtolower(get_class($this)));
|
|
$vars['secondary_id'] = (strtolower($class) == 'aro' ? 'user_id' : 'object_id');
|
|
$vars['data_name'] = $class;
|
|
$vars['table_name'] = $class . 's';
|
|
$vars['class'] = Inflector::camelize($class);
|
|
return $vars;
|
|
}
|
|
|
|
/**
|
|
* Enter description here...
|
|
*
|
|
*/
|
|
function __setTable()
|
|
{
|
|
$this->table = strtolower(get_class($this)) . "s";
|
|
}
|
|
}
|
|
|
|
?>
|