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.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.3
      • 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
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

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