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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.10
      • 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
  • None

Classes

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