CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • AclNode
  • Aco
  • AcoAction
  • Aro
  • BehaviorCollection
  • CakeSchema
  • ConnectionManager
  • I18nModel
  • Model
  • ModelBehavior
  • Permission
  1: <?php
  2: /**
  3:  *
  4:  * PHP 5
  5:  *
  6:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  7:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  8:  *
  9:  * Licensed under The MIT License
 10:  * Redistributions of files must retain the above copyright notice.
 11:  *
 12:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 13:  * @link          http://cakephp.org CakePHP(tm) Project
 14:  * @package       Cake.Model
 15:  * @since         CakePHP(tm) v 0.2.9
 16:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 17:  */
 18: 
 19: App::uses('Model', 'Model');
 20: 
 21: /**
 22:  * ACL Node
 23:  *
 24:  * @package       Cake.Model
 25:  */
 26: class AclNode extends Model {
 27: 
 28: /**
 29:  * Explicitly disable in-memory query caching for ACL models
 30:  *
 31:  * @var boolean
 32:  */
 33:     public $cacheQueries = false;
 34: 
 35: /**
 36:  * ACL models use the Tree behavior
 37:  *
 38:  * @var array
 39:  */
 40:     public $actsAs = array('Tree' => array('type' => 'nested'));
 41: 
 42: /**
 43:  * Constructor
 44:  *
 45:  */
 46:     public function __construct() {
 47:         $config = Configure::read('Acl.database');
 48:         if (isset($config)) {
 49:             $this->useDbConfig = $config;
 50:         }
 51:         parent::__construct();
 52:     }
 53: 
 54: /**
 55:  * Retrieves the Aro/Aco node for this model
 56:  *
 57:  * @param mixed $ref Array with 'model' and 'foreign_key', model object, or string value
 58:  * @return array Node found in database
 59:  * @throws CakeException when binding to a model that doesn't exist.
 60:  */
 61:     public function node($ref = null) {
 62:         $db = $this->getDataSource();
 63:         $type = $this->alias;
 64:         $result = null;
 65: 
 66:         if (!empty($this->useTable)) {
 67:             $table = $this->useTable;
 68:         } else {
 69:             $table = Inflector::pluralize(Inflector::underscore($type));
 70:         }
 71: 
 72:         if (empty($ref)) {
 73:             return null;
 74:         } elseif (is_string($ref)) {
 75:             $path = explode('/', $ref);
 76:             $start = $path[0];
 77:             unset($path[0]);
 78: 
 79:             $queryData = array(
 80:                 'conditions' => array(
 81:                     $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
 82:                     $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")),
 83:                 'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
 84:                 'joins' => array(array(
 85:                     'table' => $table,
 86:                     'alias' => "{$type}0",
 87:                     'type' => 'LEFT',
 88:                     'conditions' => array("{$type}0.alias" => $start)
 89:                 )),
 90:                 'order' => $db->name("{$type}.lft") . ' DESC'
 91:             );
 92: 
 93:             foreach ($path as $i => $alias) {
 94:                 $j = $i - 1;
 95: 
 96:                 $queryData['joins'][] = array(
 97:                     'table' => $table,
 98:                     'alias' => "{$type}{$i}",
 99:                     'type' => 'LEFT',
100:                     'conditions' => array(
101:                         $db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
102:                         $db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
103:                         $db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string'),
104:                         $db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id")
105:                     )
106:                 );
107: 
108:                 $queryData['conditions'] = array('or' => array(
109:                     $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
110:                     $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght"))
111:                 );
112:             }
113:             $result = $db->read($this, $queryData, -1);
114:             $path = array_values($path);
115: 
116:             if (
117:                 !isset($result[0][$type]) ||
118:                 (!empty($path) && $result[0][$type]['alias'] != $path[count($path) - 1]) ||
119:                 (empty($path) && $result[0][$type]['alias'] != $start)
120:             ) {
121:                 return false;
122:             }
123:         } elseif (is_object($ref) && is_a($ref, 'Model')) {
124:             $ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
125:         } elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
126:             $name = key($ref);
127:             list($plugin, $alias) = pluginSplit($name);
128: 
129:             $model = ClassRegistry::init(array('class' => $name, 'alias' => $alias));
130: 
131:             if (empty($model)) {
132:                 throw new CakeException('cake_dev', "Model class '%s' not found in AclNode::node() when trying to bind %s object", $type, $this->alias);
133:             }
134: 
135:             $tmpRef = null;
136:             if (method_exists($model, 'bindNode')) {
137:                 $tmpRef = $model->bindNode($ref);
138:             }
139:             if (empty($tmpRef)) {
140:                 $ref = array('model' => $alias, 'foreign_key' => $ref[$name][$model->primaryKey]);
141:             } else {
142:                 if (is_string($tmpRef)) {
143:                     return $this->node($tmpRef);
144:                 }
145:                 $ref = $tmpRef;
146:             }
147:         }
148:         if (is_array($ref)) {
149:             if (is_array(current($ref)) && is_string(key($ref))) {
150:                 $name = key($ref);
151:                 $ref = current($ref);
152:             }
153:             foreach ($ref as $key => $val) {
154:                 if (strpos($key, $type) !== 0 && strpos($key, '.') === false) {
155:                     unset($ref[$key]);
156:                     $ref["{$type}0.{$key}"] = $val;
157:                 }
158:             }
159:             $queryData = array(
160:                 'conditions' => $ref,
161:                 'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
162:                 'joins' => array(array(
163:                     'table' => $table,
164:                     'alias' => "{$type}0",
165:                     'type' => 'LEFT',
166:                     'conditions' => array(
167:                         $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
168:                         $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")
169:                     )
170:                 )),
171:                 'order' => $db->name("{$type}.lft") . ' DESC'
172:             );
173:             $result = $db->read($this, $queryData, -1);
174: 
175:             if (!$result) {
176:                 throw new CakeException(__d('cake_dev', "AclNode::node() - Couldn't find %s node identified by \"%s\"", $type, print_r($ref, true)));
177:             }
178:         }
179:         return $result;
180:     }
181: 
182: }
183: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs