2005-11-05 04:08:14 +00:00
|
|
|
<?php
|
2005-12-22 01:07:28 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.controller.components.dbacl.models
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.10.0.1232
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-12-22 01:07:28 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* Long description for file
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.controller.components.dbacl.models
|
2005-12-22 01:07:28 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-11-24 17:27:11 +00:00
|
|
|
loadModel();
|
2007-02-09 08:13:13 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
class AclNode extends AppModel {
|
2006-10-09 15:47:50 +00:00
|
|
|
|
|
|
|
var $useDbConfig = ACL_DATABASE;
|
2005-12-22 01:07:28 +00:00
|
|
|
/**
|
2007-02-09 08:13:13 +00:00
|
|
|
* Explicitly disable in-memory query caching for ACL models
|
2005-12-22 01:07:28 +00:00
|
|
|
*
|
2007-02-09 08:13:13 +00:00
|
|
|
* @var boolean
|
2005-12-22 01:07:28 +00:00
|
|
|
*/
|
2007-02-09 08:13:13 +00:00
|
|
|
var $cacheQueries = false;
|
2005-12-22 01:07:28 +00:00
|
|
|
/**
|
2007-02-09 08:13:13 +00:00
|
|
|
* ACL models use the Tree behavior
|
2005-12-22 01:07:28 +00:00
|
|
|
*
|
2007-02-09 08:13:13 +00:00
|
|
|
* @var mixed
|
2005-12-22 01:07:28 +00:00
|
|
|
*/
|
2007-02-09 08:13:13 +00:00
|
|
|
var $actsAs = array('Tree' => 'nested');
|
2007-02-09 21:26:09 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the Aro/Aco node for this model
|
|
|
|
*
|
|
|
|
* @param mixed $ref
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function node($ref = null) {
|
|
|
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
|
|
|
$type = $this->name;
|
|
|
|
$table = low($type) . 's';
|
|
|
|
$prefix = $this->tablePrefix;
|
|
|
|
|
|
|
|
if (empty($ref)) {
|
2007-02-10 20:28:22 +00:00
|
|
|
return null;
|
2007-02-09 21:26:09 +00:00
|
|
|
} elseif (is_string($ref)) {
|
|
|
|
$path = explode('/', $ref);
|
|
|
|
$start = $path[count($path) - 1];
|
|
|
|
unset($path[count($path) - 1]);
|
|
|
|
|
|
|
|
$query = "SELECT {$type}0.* From {$prefix}{$table} AS {$type}0 ";
|
|
|
|
foreach ($path as $i => $alias) {
|
|
|
|
$j = $i - 1;
|
|
|
|
$k = $i + 1;
|
|
|
|
$query .= "LEFT JOIN {$prefix}{$table} AS {$type}{$k} ";
|
|
|
|
$query .= "ON {$type}{$k}.lft > {$type}{$i}.lft && {$type}{$k}.rght < {$type}{$i}.rght ";
|
|
|
|
$query .= "AND {$type}{$k}.alias = " . $db->value($alias) . " ";
|
|
|
|
}
|
|
|
|
$result = $this->query("{$query} WHERE {$type}0.alias = " . $db->value($start));
|
|
|
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
$result = $result[0]["{$type}0"];
|
|
|
|
}
|
|
|
|
} elseif (is_object($ref) && is_a($ref, 'Model')) {
|
|
|
|
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
|
2007-02-10 22:59:08 +00:00
|
|
|
} elseif (is_array($ref) && !isset($ref['model'])) {
|
|
|
|
$name = key($ref);
|
|
|
|
if (!ClassRegistry::isKeySet($name)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$model =& ClassRegistry::getObject($name);
|
|
|
|
$ref = array('model' => $name, 'foreign_key' => $ref[$name][$model->primaryKey]);
|
2007-02-09 21:26:09 +00:00
|
|
|
}
|
|
|
|
if (is_array($ref)) {
|
2007-02-10 22:59:08 +00:00
|
|
|
$result = $this->find($ref, null, null, -1);
|
|
|
|
if ($result) {
|
|
|
|
list($result) = array_values($result);
|
|
|
|
}
|
2007-02-09 21:26:09 +00:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2005-11-05 04:08:14 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
2005-11-05 04:08:14 +00:00
|
|
|
?>
|