code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function __validateWithModels($options) { $valid = true; foreach ($this->hasAndBelongsToMany as $assoc => $association) { if (empty($association['with']) || !isset($this->data[$assoc])) { continue; } list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']); $data = $this->data[$assoc]; $newData = array(); foreach ((array)$data as $row) { if (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) { $newData[] = $row; } elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) { $newData[] = $row[$join]; } } if (empty($newData)) { continue; } foreach ($newData as $data) { $data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $this->id; $this->{$join}->create($data); $valid = ($valid && $this->{$join}->validates($options)); } } return $valid; }
Runs validation for hasAndBelongsToMany associations that have 'with' keys set. And data in the set() data set. @param array $options Array of options to use on Valdation of with models @return boolean Failure of validation on with models. @access private @see Model::validates()
__validateWithModels
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function invalidate($field, $value = true) { if (!is_array($this->validationErrors)) { $this->validationErrors = array(); } $this->validationErrors[$field] = $value; }
Marks a field as invalid, optionally setting the name of validation rule (in case of multiple validation for field) that was broken. @param string $field The name of the field to invalidate @param mixed $value Name of validation rule that was not failed, or validation message to be returned. If no validation key is provided, defaults to true. @access public
invalidate
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function isForeignKey($field) { $foreignKeys = array(); if (!empty($this->belongsTo)) { foreach ($this->belongsTo as $assoc => $data) { $foreignKeys[] = $data['foreignKey']; } } return in_array($field, $foreignKeys); }
Returns true if given field name is a foreign key in this model. @param string $field Returns true if the input string ends in "_id" @return boolean True if the field is a foreign key listed in the belongsTo array. @access public
isForeignKey
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function escapeField($field = null, $alias = null) { if (empty($alias)) { $alias = $this->alias; } if (empty($field)) { $field = $this->primaryKey; } $db =& ConnectionManager::getDataSource($this->useDbConfig); if (strpos($field, $db->name($alias) . '.') === 0) { return $field; } return $db->name($alias . '.' . $field); }
Escapes the field name and prepends the model name. Escaping is done according to the current database driver's rules. @param string $field Field to escape (e.g: id) @param string $alias Alias for the model (e.g: Post) @return string The name of the escaped field for this Model (i.e. id becomes `Post`.`id`). @access public
escapeField
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getID($list = 0) { if (empty($this->id) || (is_array($this->id) && isset($this->id[0]) && empty($this->id[0]))) { return false; } if (!is_array($this->id)) { return $this->id; } if (empty($this->id)) { return false; } if (isset($this->id[$list]) && !empty($this->id[$list])) { return $this->id[$list]; } elseif (isset($this->id[$list])) { return false; } foreach ($this->id as $id) { return $id; } return false; }
Returns the current record's ID @param integer $list Index on which the composed ID is located @return mixed The ID of the current record, false if no ID @access public
getID
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getLastInsertID() { return $this->getInsertID(); }
Returns the ID of the last record this model inserted. @return mixed Last inserted ID @access public
getLastInsertID
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getInsertID() { return $this->__insertID; }
Returns the ID of the last record this model inserted. @return mixed Last inserted ID @access public
getInsertID
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function setInsertID($id) { $this->__insertID = $id; }
Sets the ID of the last record this model inserted @param mixed Last inserted ID @access public
setInsertID
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getNumRows() { $db =& ConnectionManager::getDataSource($this->useDbConfig); return $db->lastNumRows(); }
Returns the number of rows returned from the last query. @return int Number of rows @access public
getNumRows
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getAffectedRows() { $db =& ConnectionManager::getDataSource($this->useDbConfig); return $db->lastAffected(); }
Returns the number of rows affected by the last query. @return int Number of rows @access public
getAffectedRows
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function setDataSource($dataSource = null) { $oldConfig = $this->useDbConfig; if ($dataSource != null) { $this->useDbConfig = $dataSource; } $db =& ConnectionManager::getDataSource($this->useDbConfig); if (!empty($oldConfig) && isset($db->config['prefix'])) { $oldDb =& ConnectionManager::getDataSource($oldConfig); if (!isset($this->tablePrefix) || (!isset($oldDb->config['prefix']) || $this->tablePrefix == $oldDb->config['prefix'])) { $this->tablePrefix = $db->config['prefix']; } } elseif (isset($db->config['prefix'])) { $this->tablePrefix = $db->config['prefix']; } if (empty($db) || !is_object($db)) { return $this->cakeError('missingConnection', array(array('code' => 500, 'className' => $this->alias))); } }
Sets the DataSource to which this model is bound. @param string $dataSource The name of the DataSource, as defined in app/config/database.php @return boolean True on success @access public
setDataSource
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function &getDataSource() { $db =& ConnectionManager::getDataSource($this->useDbConfig); return $db; }
Gets the DataSource to which this model is bound. Not safe for use with some versions of PHP4, because this class is overloaded. @return object A DataSource object @access public
getDataSource
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function getAssociated($type = null) { if ($type == null) { $associated = array(); foreach ($this->__associations as $assoc) { if (!empty($this->{$assoc})) { $models = array_keys($this->{$assoc}); foreach ($models as $m) { $associated[$m] = $assoc; } } } return $associated; } elseif (in_array($type, $this->__associations)) { if (empty($this->{$type})) { return array(); } return array_keys($this->{$type}); } else { $assoc = array_merge( $this->hasOne, $this->hasMany, $this->belongsTo, $this->hasAndBelongsToMany ); if (array_key_exists($type, $assoc)) { foreach ($this->__associations as $a) { if (isset($this->{$a}[$type])) { $assoc[$type]['association'] = $a; break; } } return $assoc[$type]; } return null; } }
Gets all the models with which this model is associated. @param string $type Only result associations of this type @return array Associations @access public
getAssociated
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function joinModel($assoc, $keys = array()) { if (is_string($assoc)) { return array($assoc, array_keys($this->{$assoc}->schema())); } elseif (is_array($assoc)) { $with = key($assoc); return array($with, array_unique(array_merge($assoc[$with], $keys))); } trigger_error( sprintf(__('Invalid join model settings in %s', true), $model->alias), E_USER_WARNING ); }
Gets the name and fields to be used by a join model. This allows specifying join fields in the association definition. @param object $model The model to be joined @param mixed $with The 'with' key of the model association @param array $keys Any join keys which must be merged with the keys queried @return array @access public
joinModel
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function beforeFind($queryData) { return true; }
Called before each find operation. Return false if you want to halt the find call, otherwise return the (modified) query data. @param array $queryData Data used to execute this query, i.e. conditions, order, etc. @return mixed true if the operation should continue, false if it should abort; or, modified $queryData to continue with new $queryData @access public @link http://book.cakephp.org/view/1048/Callback-Methods#beforeFind-1049
beforeFind
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function afterFind($results, $primary = false) { return $results; }
Called after each find operation. Can be used to modify any results returned by find(). Return value should be the (modified) results. @param mixed $results The results of the find operation @param boolean $primary Whether this model is being queried directly (vs. being queried as an association) @return mixed Result of the find operation @access public @link http://book.cakephp.org/view/1048/Callback-Methods#afterFind-1050
afterFind
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function beforeSave($options = array()) { return true; }
Called before each save operation, after validation. Return a non-true result to halt the save. @return boolean True if the operation should continue, false if it should abort @access public @link http://book.cakephp.org/view/1048/Callback-Methods#beforeSave-1052
beforeSave
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function beforeDelete($cascade = true) { return true; }
Called before every deletion operation. @param boolean $cascade If true records that depend on this record will also be deleted @return boolean True if the operation should continue, false if it should abort @access public @link http://book.cakephp.org/view/1048/Callback-Methods#beforeDelete-1054
beforeDelete
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function beforeValidate($options = array()) { return true; }
Called during validation operations, before validation. Please note that custom validation rules can be defined in $validate. @return boolean True if validate operation should continue, false to abort @param $options array Options passed from model::save(), see $options of model::save(). @access public @link http://book.cakephp.org/view/1048/Callback-Methods#beforeValidate-1051
beforeValidate
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function _clearCache($type = null) { if ($type === null) { if (Configure::read('Cache.check') === true) { $assoc[] = strtolower(Inflector::pluralize($this->alias)); $assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($this->alias))); foreach ($this->__associations as $key => $association) { foreach ($this->$association as $key => $className) { $check = strtolower(Inflector::pluralize($className['className'])); if (!in_array($check, $assoc)) { $assoc[] = strtolower(Inflector::pluralize($className['className'])); $assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($className['className']))); } } } clearCache($assoc); return true; } } else { //Will use for query cache deleting } }
Private method. Clears cache for this model. @param string $type If null this deletes cached views if Cache.check is true Will be used to allow deleting query cache also @return boolean true on delete @access protected @todo
_clearCache
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function __sleep() { $return = array_keys(get_object_vars($this)); return $return; }
Called when serializing a model. @return array Set of object variable names this model has @access private
__sleep
php
Datawalke/Coordino
cake/libs/model/model.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model.php
MIT
function cleanup(&$model) { if (isset($this->settings[$model->alias])) { unset($this->settings[$model->alias]); } }
Clean up any initialization this behavior has done on a model. Called when a behavior is dynamically detached from a model using Model::detach(). @param object $model Model using this behavior @access public @see BehaviorCollection::detach()
cleanup
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function dispatchMethod(&$model, $method, $params = array()) { if (empty($params)) { return $this->{$method}($model); } $params = array_values($params); switch (count($params)) { case 1: return $this->{$method}($model, $params[0]); case 2: return $this->{$method}($model, $params[0], $params[1]); case 3: return $this->{$method}($model, $params[0], $params[1], $params[2]); case 4: return $this->{$method}($model, $params[0], $params[1], $params[2], $params[3]); case 5: return $this->{$method}($model, $params[0], $params[1], $params[2], $params[3], $params[4]); default: $params = array_merge(array(&$model), $params); return call_user_func_array(array(&$this, $method), $params); break; } }
Overrides Object::dispatchMethod to account for PHP4's broken reference support @see Object::dispatchMethod @access public @return mixed
dispatchMethod
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function _addToWhitelist(&$model, $field) { if (is_array($field)) { foreach ($field as $f) { $this->_addToWhitelist($model, $f); } return; } if (!empty($model->whitelist) && !in_array($field, $model->whitelist)) { $model->whitelist[] = $field; } }
If $model's whitelist property is non-empty, $field will be added to it. Note: this method should *only* be used in beforeValidate or beforeSave to ensure that it only modifies the whitelist for the current save operation. Also make sure you explicitly set the value of the field which you are allowing. @param object $model Model using this behavior @param string $field Field to be added to $model's whitelist @access protected @return void
_addToWhitelist
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function init($modelName, $behaviors = array()) { $this->modelName = $modelName; if (!empty($behaviors)) { foreach (Set::normalize($behaviors) as $behavior => $config) { $this->attach($behavior, $config); } } }
Attaches a model object and loads a list of behaviors @access public @return void
init
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function attach($behavior, $config = array()) { list($plugin, $name) = pluginSplit($behavior); $class = $name . 'Behavior'; if (!App::import('Behavior', $behavior)) { $this->cakeError('missingBehaviorFile', array(array( 'behavior' => $behavior, 'file' => Inflector::underscore($behavior) . '.php', 'code' => 500, 'base' => '/' ))); return false; } if (!class_exists($class)) { $this->cakeError('missingBehaviorClass', array(array( 'behavior' => $class, 'file' => Inflector::underscore($class) . '.php', 'code' => 500, 'base' => '/' ))); return false; } if (!isset($this->{$name})) { if (ClassRegistry::isKeySet($class)) { if (PHP5) { $this->{$name} = ClassRegistry::getObject($class); } else { $this->{$name} =& ClassRegistry::getObject($class); } } else { if (PHP5) { $this->{$name} = new $class; } else { $this->{$name} =& new $class; } ClassRegistry::addObject($class, $this->{$name}); if (!empty($plugin)) { ClassRegistry::addObject($plugin.'.'.$class, $this->{$name}); } } } elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) { if ($config !== null && $config !== false) { $config = array_merge($this->{$name}->settings[$this->modelName], $config); } else { $config = array(); } } if (empty($config)) { $config = array(); } $this->{$name}->setup(ClassRegistry::getObject($this->modelName), $config); foreach ($this->{$name}->mapMethods as $method => $alias) { $this->__mappedMethods[$method] = array($alias, $name); } $methods = get_class_methods($this->{$name}); $parentMethods = array_flip(get_class_methods('ModelBehavior')); $callbacks = array( 'setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete', 'afterError' ); foreach ($methods as $m) { if (!isset($parentMethods[$m])) { $methodAllowed = ( $m[0] != '_' && !array_key_exists($m, $this->__methods) && !in_array($m, $callbacks) ); if ($methodAllowed) { $this->__methods[$m] = array($m, $name); } } } if (!in_array($name, $this->_attached)) { $this->_attached[] = $name; } if (in_array($name, $this->_disabled) && !(isset($config['enabled']) && $config['enabled'] === false)) { $this->enable($name); } elseif (isset($config['enabled']) && $config['enabled'] === false) { $this->disable($name); } return true; }
Attaches a behavior to a model @param string $behavior CamelCased name of the behavior to load @param array $config Behavior configuration parameters @return boolean True on success, false on failure @access public
attach
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function detach($name) { list($plugin, $name) = pluginSplit($name); if (isset($this->{$name})) { $this->{$name}->cleanup(ClassRegistry::getObject($this->modelName)); unset($this->{$name}); } foreach ($this->__methods as $m => $callback) { if (is_array($callback) && $callback[1] == $name) { unset($this->__methods[$m]); } } $this->_attached = array_values(array_diff($this->_attached, (array)$name)); }
Detaches a behavior from a model @param string $name CamelCased name of the behavior to unload @return void @access public
detach
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function enable($name) { $this->_disabled = array_diff($this->_disabled, (array)$name); }
Enables callbacks on a behavior or array of behaviors @param mixed $name CamelCased name of the behavior(s) to enable (string or array) @return void @access public
enable
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function disable($name) { foreach ((array)$name as $behavior) { if (in_array($behavior, $this->_attached) && !in_array($behavior, $this->_disabled)) { $this->_disabled[] = $behavior; } } }
Disables callbacks on a behavior or array of behaviors. Public behavior methods are still callable as normal. @param mixed $name CamelCased name of the behavior(s) to disable (string or array) @return void @access public
disable
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function dispatchMethod(&$model, $method, $params = array(), $strict = false) { $methods = array_keys($this->__methods); foreach ($methods as $key => $value) { $methods[$key] = strtolower($value); } $method = strtolower($method); $check = array_flip($methods); $found = isset($check[$method]); $call = null; if ($strict && !$found) { trigger_error(sprintf(__("BehaviorCollection::dispatchMethod() - Method %s not found in any attached behavior", true), $method), E_USER_WARNING); return null; } elseif ($found) { $methods = array_combine($methods, array_values($this->__methods)); $call = $methods[$method]; } else { $count = count($this->__mappedMethods); $mapped = array_keys($this->__mappedMethods); for ($i = 0; $i < $count; $i++) { if (preg_match($mapped[$i] . 'i', $method)) { $call = $this->__mappedMethods[$mapped[$i]]; array_unshift($params, $method); break; } } } if (!empty($call)) { return $this->{$call[1]}->dispatchMethod($model, $call[0], $params); } return array('unhandled'); }
Dispatches a behavior method @return array All methods for all behaviors attached to this object @access public
dispatchMethod
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function trigger(&$model, $callback, $params = array(), $options = array()) { if (empty($this->_attached)) { return true; } $options = array_merge(array('break' => false, 'breakOn' => array(null, false), 'modParams' => false), $options); $count = count($this->_attached); for ($i = 0; $i < $count; $i++) { $name = $this->_attached[$i]; if (in_array($name, $this->_disabled)) { continue; } $result = $this->{$name}->dispatchMethod($model, $callback, $params); if ($options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))) { return $result; } elseif ($options['modParams'] && is_array($result)) { $params[0] = $result; } } if ($options['modParams'] && isset($params[0])) { return $params[0]; } return true; }
Dispatches a behavior callback on all attached behavior objects @param model $model @param string $callback @param array $params @param array $options @return mixed @access public
trigger
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function methods() { return $this->__methods; }
Gets the method list for attached behaviors, i.e. all public, non-callback methods @return array All public methods for all behaviors attached to this collection @access public
methods
php
Datawalke/Coordino
cake/libs/model/model_behavior.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/model_behavior.php
MIT
function setup(&$model, $config = array()) { if (is_string($config)) { $config = array('type' => $config); } $this->settings[$model->name] = array_merge(array('type' => 'requester'), (array)$config); $this->settings[$model->name]['type'] = strtolower($this->settings[$model->name]['type']); $type = $this->__typeMaps[$this->settings[$model->name]['type']]; if (!class_exists('AclNode')) { require LIBS . 'model' . DS . 'db_acl.php'; } if (PHP5) { $model->{$type} = ClassRegistry::init($type); } else { $model->{$type} =& ClassRegistry::init($type); } if (!method_exists($model, 'parentNode')) { trigger_error(sprintf(__('Callback parentNode() not defined in %s', true), $model->alias), E_USER_WARNING); } }
Sets up the configuation for the model, and loads ACL models if they haven't been already @param mixed $config @return void @access public
setup
php
Datawalke/Coordino
cake/libs/model/behaviors/acl.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/acl.php
MIT
function node(&$model, $ref = null) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; if (empty($ref)) { $ref = array('model' => $model->name, 'foreign_key' => $model->id); } return $model->{$type}->node($ref); }
Retrieves the Aro/Aco node for this model @param mixed $ref @return array @access public @link http://book.cakephp.org/view/1322/node
node
php
Datawalke/Coordino
cake/libs/model/behaviors/acl.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/acl.php
MIT
function afterSave(&$model, $created) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; $parent = $model->parentNode(); if (!empty($parent)) { $parent = $this->node($model, $parent); } $data = array( 'parent_id' => isset($parent[0][$type]['id']) ? $parent[0][$type]['id'] : null, 'model' => $model->name, 'foreign_key' => $model->id ); if (!$created) { $node = $this->node($model); $data['id'] = isset($node[0][$type]['id']) ? $node[0][$type]['id'] : null; } $model->{$type}->create(); $model->{$type}->save($data); }
Creates a new ARO/ACO node bound to this record @param boolean $created True if this is a new record @return void @access public
afterSave
php
Datawalke/Coordino
cake/libs/model/behaviors/acl.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/acl.php
MIT
function afterDelete(&$model) { $type = $this->__typeMaps[$this->settings[$model->name]['type']]; $node = Set::extract($this->node($model), "0.{$type}.id"); if (!empty($node)) { $model->{$type}->delete($node); } }
Destroys the ARO/ACO node bound to the deleted record @return void @access public
afterDelete
php
Datawalke/Coordino
cake/libs/model/behaviors/acl.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/acl.php
MIT
function setup(&$Model, $settings = array()) { if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true); } if (!is_array($settings)) { $settings = array(); } $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings); }
Initiate behavior for the model using specified settings. Available settings: - recursive: (boolean, optional) set to true to allow containable to automatically determine the recursiveness level needed to fetch specified models, and set the model recursiveness to this level. setting it to false disables this feature. DEFAULTS TO: true - notices: (boolean, optional) issues E_NOTICES for bindings referenced in a containable call that are not valid. DEFAULTS TO: true - autoFields: (boolean, optional) auto-add needed fields to fetch requested bindings. DEFAULTS TO: true @param object $Model Model using the behavior @param array $settings Settings to override for model. @access public
setup
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function beforeFind(&$Model, $query) { $reset = (isset($query['reset']) ? $query['reset'] : true); $noContain = false; $contain = array(); if (isset($this->runtime[$Model->alias]['contain'])) { $noContain = empty($this->runtime[$Model->alias]['contain']); $contain = $this->runtime[$Model->alias]['contain']; unset($this->runtime[$Model->alias]['contain']); } if (isset($query['contain'])) { $noContain = $noContain || empty($query['contain']); if ($query['contain'] !== false) { $contain = array_merge($contain, (array)$query['contain']); } } $noContain = $noContain && empty($contain); if ( $noContain || empty($contain) || (isset($contain[0]) && $contain[0] === null) ) { if ($noContain) { $query['recursive'] = -1; } return $query; } if ((isset($contain[0]) && is_bool($contain[0])) || is_bool(end($contain))) { $reset = is_bool(end($contain)) ? array_pop($contain) : array_shift($contain); } $containments = $this->containments($Model, $contain); $map = $this->containmentsMap($containments); $mandatory = array(); foreach ($containments['models'] as $name => $model) { $instance =& $model['instance']; $needed = $this->fieldDependencies($instance, $map, false); if (!empty($needed)) { $mandatory = array_merge($mandatory, $needed); } if ($contain) { $backupBindings = array(); foreach ($this->types as $relation) { if (!empty($instance->__backAssociation[$relation])) { $backupBindings[$relation] = $instance->__backAssociation[$relation]; } else { $backupBindings[$relation] = $instance->{$relation}; } } foreach ($this->types as $type) { $unbind = array(); foreach ($instance->{$type} as $assoc => $options) { if (!isset($model['keep'][$assoc])) { $unbind[] = $assoc; } } if (!empty($unbind)) { if (!$reset && empty($instance->__backOriginalAssociation)) { $instance->__backOriginalAssociation = $backupBindings; } $instance->unbindModel(array($type => $unbind), $reset); } foreach ($instance->{$type} as $assoc => $options) { if (isset($model['keep'][$assoc]) && !empty($model['keep'][$assoc])) { if (isset($model['keep'][$assoc]['fields'])) { $model['keep'][$assoc]['fields'] = $this->fieldDependencies($containments['models'][$assoc]['instance'], $map, $model['keep'][$assoc]['fields']); } if (!$reset && empty($instance->__backOriginalAssociation)) { $instance->__backOriginalAssociation = $backupBindings; } else if ($reset) { $instance->__backAssociation[$type] = $backupBindings[$type]; } $instance->{$type}[$assoc] = array_merge($instance->{$type}[$assoc], $model['keep'][$assoc]); } if (!$reset) { $instance->__backInnerAssociation[] = $assoc; } } } } } if ($this->settings[$Model->alias]['recursive']) { $query['recursive'] = (isset($query['recursive'])) ? $query['recursive'] : $containments['depth']; } $autoFields = ($this->settings[$Model->alias]['autoFields'] && !in_array($Model->findQueryType, array('list', 'count')) && !empty($query['fields'])); if (!$autoFields) { return $query; } $query['fields'] = (array)$query['fields']; foreach (array('hasOne', 'belongsTo') as $type) { if (!empty($Model->{$type})) { foreach ($Model->{$type} as $assoc => $data) { if ($Model->useDbConfig == $Model->{$assoc}->useDbConfig && !empty($data['fields'])) { foreach ((array) $data['fields'] as $field) { $query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field; } } } } } if (!empty($mandatory[$Model->alias])) { foreach ($mandatory[$Model->alias] as $field) { if ($field == '--primaryKey--') { $field = $Model->primaryKey; } else if (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) { list($modelName, $field) = explode('.', $field); if ($Model->useDbConfig == $Model->{$modelName}->useDbConfig) { $field = $modelName . '.' . ( ($field === '--primaryKey--') ? $Model->$modelName->primaryKey : $field ); } else { $field = null; } } if ($field !== null) { $query['fields'][] = $field; } } } $query['fields'] = array_unique($query['fields']); return $query; }
Runs before a find() operation. Used to allow 'contain' setting as part of the find call, like this: `Model->find('all', array('contain' => array('Model1', 'Model2')));` {{{ Model->find('all', array('contain' => array( 'Model1' => array('Model11', 'Model12'), 'Model2', 'Model3' => array( 'Model31' => 'Model311', 'Model32', 'Model33' => array('Model331', 'Model332') ))); }}} @param object $Model Model using the behavior @param array $query Query parameters as set by cake @return array @access public
beforeFind
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function contain(&$Model) { $args = func_get_args(); $contain = call_user_func_array('am', array_slice($args, 1)); $this->runtime[$Model->alias]['contain'] = $contain; }
Unbinds all relations from a model except the specified ones. Calling this function without parameters unbinds all related models. @param object $Model Model on which binding restriction is being applied @return void @access public @link http://book.cakephp.org/view/1323/Containable#Using-Containable-1324
contain
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function resetBindings(&$Model) { if (!empty($Model->__backOriginalAssociation)) { $Model->__backAssociation = $Model->__backOriginalAssociation; unset($Model->__backOriginalAssociation); } $Model->resetAssociations(); if (!empty($Model->__backInnerAssociation)) { $assocs = $Model->__backInnerAssociation; unset($Model->__backInnerAssociation); foreach ($assocs as $currentModel) { $this->resetBindings($Model->$currentModel); } } }
Permanently restore the original binding settings of given model, useful for restoring the bindings after using 'reset' => false as part of the contain call. @param object $Model Model on which to reset bindings @return void @access public
resetBindings
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function containments(&$Model, $contain, $containments = array(), $throwErrors = null) { $options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery'); $keep = array(); $depth = array(); if ($throwErrors === null) { $throwErrors = (empty($this->settings[$Model->alias]) ? true : $this->settings[$Model->alias]['notices']); } foreach ((array)$contain as $name => $children) { if (is_numeric($name)) { $name = $children; $children = array(); } if (preg_match('/(?<!\.)\(/', $name)) { $name = str_replace('(', '.(', $name); } if (strpos($name, '.') !== false) { $chain = explode('.', $name); $name = array_shift($chain); $children = array(implode('.', $chain) => $children); } $children = (array)$children; foreach ($children as $key => $val) { if (is_string($key) && is_string($val) && !in_array($key, $options, true)) { $children[$key] = (array) $val; } } $keys = array_keys($children); if ($keys && isset($children[0])) { $keys = array_merge(array_values($children), $keys); } foreach ($keys as $i => $key) { if (is_array($key)) { continue; } $optionKey = in_array($key, $options, true); if (!$optionKey && is_string($key) && preg_match('/^[a-z(]/', $key) && (!isset($Model->{$key}) || !is_object($Model->{$key}))) { $option = 'fields'; $val = array($key); if ($key{0} == '(') { $val = preg_split('/\s*,\s*/', substr(substr($key, 1), 0, -1)); } elseif (preg_match('/ASC|DESC$/', $key)) { $option = 'order'; $val = $Model->{$name}->alias.'.'.$key; } elseif (preg_match('/[ =!]/', $key)) { $option = 'conditions'; $val = $Model->{$name}->alias.'.'.$key; } $children[$option] = is_array($val) ? $val : array($val); $newChildren = null; if (!empty($name) && !empty($children[$key])) { $newChildren = $children[$key]; } unset($children[$key], $children[$i]); $key = $option; $optionKey = true; if (!empty($newChildren)) { $children = Set::merge($children, $newChildren); } } if ($optionKey && isset($children[$key])) { if (!empty($keep[$name][$key]) && is_array($keep[$name][$key])) { $keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array) $children[$key]); } else { $keep[$name][$key] = $children[$key]; } unset($children[$key]); } } if (!isset($Model->{$name}) || !is_object($Model->{$name})) { if ($throwErrors) { trigger_error(sprintf(__('Model "%s" is not associated with model "%s"', true), $Model->alias, $name), E_USER_WARNING); } continue; } $containments = $this->containments($Model->{$name}, $children, $containments); $depths[] = $containments['depth'] + 1; if (!isset($keep[$name])) { $keep[$name] = array(); } } if (!isset($containments['models'][$Model->alias])) { $containments['models'][$Model->alias] = array('keep' => array(),'instance' => &$Model); } $containments['models'][$Model->alias]['keep'] = array_merge($containments['models'][$Model->alias]['keep'], $keep); $containments['depth'] = empty($depths) ? 0 : max($depths); return $containments; }
Process containments for model. @param object $Model Model on which binding restriction is being applied @param array $contain Parameters to use for restricting this model @param array $containments Current set of containments @param bool $throwErrors Wether unexisting bindings show throw errors @return array Containments @access public
containments
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function fieldDependencies(&$Model, $map, $fields = array()) { if ($fields === false) { foreach ($map as $parent => $children) { foreach ($children as $type => $bindings) { foreach ($bindings as $dependency) { if ($type == 'hasAndBelongsToMany') { $fields[$parent][] = '--primaryKey--'; } else if ($type == 'belongsTo') { $fields[$parent][] = $dependency . '.--primaryKey--'; } } } } return $fields; } if (empty($map[$Model->alias])) { return $fields; } foreach ($map[$Model->alias] as $type => $bindings) { foreach ($bindings as $dependency) { $innerFields = array(); switch ($type) { case 'belongsTo': $fields[] = $Model->{$type}[$dependency]['foreignKey']; break; case 'hasOne': case 'hasMany': $innerFields[] = $Model->$dependency->primaryKey; $fields[] = $Model->primaryKey; break; } if (!empty($innerFields) && !empty($Model->{$type}[$dependency]['fields'])) { $Model->{$type}[$dependency]['fields'] = array_unique(array_merge($Model->{$type}[$dependency]['fields'], $innerFields)); } } } return array_unique($fields); }
Calculate needed fields to fetch the required bindings for the given model. @param object $Model Model @param array $map Map of relations for given model @param mixed $fields If array, fields to initially load, if false use $Model as primary model @return array Fields @access public
fieldDependencies
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function containmentsMap($containments) { $map = array(); foreach ($containments['models'] as $name => $model) { $instance =& $model['instance']; foreach ($this->types as $type) { foreach ($instance->{$type} as $assoc => $options) { if (isset($model['keep'][$assoc])) { $map[$name][$type] = isset($map[$name][$type]) ? array_merge($map[$name][$type], (array)$assoc) : (array)$assoc; } } } } return $map; }
Build the map of containments @param array $containments Containments @return array Built containments @access public
containmentsMap
php
Datawalke/Coordino
cake/libs/model/behaviors/containable.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/containable.php
MIT
function setup(&$model, $config = array()) { $db =& ConnectionManager::getDataSource($model->useDbConfig); if (!$db->connected) { trigger_error( sprintf(__('Datasource %s for TranslateBehavior of model %s is not connected', true), $model->useDbConfig, $model->alias), E_USER_ERROR ); return false; } $this->settings[$model->alias] = array(); $this->runtime[$model->alias] = array('fields' => array()); $this->translateModel($model); return $this->bindTranslation($model, $config, false); }
Callback $config for TranslateBehavior should be array( 'fields' => array('field_one', 'field_two' => 'FieldAssoc', 'field_three')) With above example only one permanent hasMany will be joined (for field_two as FieldAssoc) $config could be empty - and translations configured dynamically by bindTranslation() method @param Model $model Model the behavior is being attached to. @param array $config Array of configuration information. @return mixed @access public
setup
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function cleanup(&$model) { $this->unbindTranslation($model); unset($this->settings[$model->alias]); unset($this->runtime[$model->alias]); }
Cleanup Callback unbinds bound translations and deletes setting information. @param Model $model Model being detached. @return void @access public
cleanup
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function beforeFind(&$model, $query) { $locale = $this->_getLocale($model); if (empty($locale)) { return $query; } $db =& ConnectionManager::getDataSource($model->useDbConfig); $RuntimeModel =& $this->translateModel($model); if (!empty($RuntimeModel->tablePrefix)) { $tablePrefix = $RuntimeModel->tablePrefix; } else { $tablePrefix = $db->config['prefix']; } $joinTable = new StdClass(); $joinTable->tablePrefix = $tablePrefix; $joinTable->table = $RuntimeModel->table; $this->_joinTable = $joinTable; $this->_runtimeModel = $RuntimeModel; if (is_string($query['fields']) && 'COUNT(*) AS ' . $db->name('count') == $query['fields']) { $query['fields'] = 'COUNT(DISTINCT('.$db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count'; $query['joins'][] = array( 'type' => 'INNER', 'alias' => $RuntimeModel->alias, 'table' => $joinTable, 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier($RuntimeModel->alias.'.foreign_key'), $RuntimeModel->alias.'.model' => $model->name, $RuntimeModel->alias.'.locale' => $locale ) ); $conditionFields = $this->_checkConditions($model, $query); foreach ($conditionFields as $field) { $query = $this->_addJoin($model, $query, $field, $locale, false); } unset($this->_joinTable, $this->_runtimeModel); return $query; } $autoFields = false; if (empty($query['fields'])) { $query['fields'] = array($model->alias.'.*'); $recursive = $model->recursive; if (isset($query['recursive'])) { $recursive = $query['recursive']; } if ($recursive >= 0) { foreach (array('hasOne', 'belongsTo') as $type) { foreach ($model->{$type} as $key => $value) { if (empty($value['fields'])) { $query['fields'][] = $key.'.*'; } else { foreach ($value['fields'] as $field) { $query['fields'][] = $key.'.'.$field; } } } } } $autoFields = true; } $fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']); $addFields = array(); if (is_array($query['fields'])) { foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; if (in_array($model->alias.'.*', $query['fields']) || $autoFields || in_array($model->alias.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { $addFields[] = $field; } } } if ($addFields) { foreach ($addFields as $field) { foreach (array($field, $model->alias.'.'.$field) as $_field) { $key = array_search($_field, $query['fields']); if ($key !== false) { unset($query['fields'][$key]); } } $query = $this->_addJoin($model, $query, $field, $locale, true); } } $this->runtime[$model->alias]['beforeFind'] = $addFields; unset($this->_joinTable, $this->_runtimeModel); return $query; }
beforeFind Callback @param Model $model Model find is being run on. @param array $query Array of Query parameters. @return array Modified query @access public
beforeFind
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function _checkConditions(&$model, $query) { $conditionFields = array(); if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions'])) ) { return $conditionFields; } foreach ($query['conditions'] as $col => $val) { foreach ($this->settings[$model->alias] as $field => $assoc) { if (is_numeric($field)) { $field = $assoc; } if (strpos($col, $field) !== false) { $conditionFields[] = $field; } } } return $conditionFields; }
Check a query's conditions for translated fields. Return an array of translated fields found in the conditions. @param Model $model The model being read. @param array $query The query array. @return array The list of translated fields that are in the conditions.
_checkConditions
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function _addJoin(&$model, $query, $field, $locale, $addField = false) { $db =& ConnectionManager::getDataSource($model->useDbConfig); $RuntimeModel = $this->_runtimeModel; $joinTable = $this->_joinTable; if (is_array($locale)) { foreach ($locale as $_locale) { if ($addField) { $query['fields'][] = 'I18n__'.$field.'__'.$_locale.'.content'; } $query['joins'][] = array( 'type' => 'LEFT', 'alias' => 'I18n__'.$field.'__'.$_locale, 'table' => $joinTable, 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"), 'I18n__'.$field.'__'.$_locale.'.model' => $model->name, 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $field, 'I18n__'.$field.'__'.$_locale.'.locale' => $_locale ) ); } } else { if ($addField) { $query['fields'][] = 'I18n__'.$field.'.content'; } $query['joins'][] = array( 'type' => 'INNER', 'alias' => 'I18n__'.$field, 'table' => $joinTable, 'conditions' => array( $model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"), 'I18n__'.$field.'.model' => $model->name, 'I18n__'.$field.'.'.$RuntimeModel->displayField => $field, 'I18n__'.$field.'.locale' => $locale ) ); } return $query; }
Appends a join for translated fields and possibly a field. @param Model $model The model being worked on. @param object $joinTable The jointable object. @param array $query The query array to append a join to. @param string $field The field name being joined. @param mixed $locale The locale(s) having joins added. @param boolean $addField Whether or not to add a field. @return array The modfied query
_addJoin
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function afterFind(&$model, $results, $primary) { $this->runtime[$model->alias]['fields'] = array(); $locale = $this->_getLocale($model); if (empty($locale) || empty($results) || empty($this->runtime[$model->alias]['beforeFind'])) { return $results; } $beforeFind = $this->runtime[$model->alias]['beforeFind']; foreach ($results as $key => $row) { $results[$key][$model->alias]['locale'] = (is_array($locale)) ? @$locale[0] : $locale; foreach ($beforeFind as $field) { if (is_array($locale)) { foreach ($locale as $_locale) { if (!isset($results[$key][$model->alias][$field]) && !empty($results[$key]['I18n__'.$field.'__'.$_locale]['content'])) { $results[$key][$model->alias][$field] = $results[$key]['I18n__'.$field.'__'.$_locale]['content']; } unset($results[$key]['I18n__'.$field.'__'.$_locale]); } if (!isset($results[$key][$model->alias][$field])) { $results[$key][$model->alias][$field] = ''; } } else { $value = ''; if (!empty($results[$key]['I18n__'.$field]['content'])) { $value = $results[$key]['I18n__'.$field]['content']; } $results[$key][$model->alias][$field] = $value; unset($results[$key]['I18n__'.$field]); } } } return $results; }
afterFind Callback @param Model $model Model find was run on @param array $results Array of model results. @param boolean $primary Did the find originate on $model. @return array Modified results @access public
afterFind
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function beforeValidate(&$model) { unset($this->runtime[$model->alias]['beforeSave']); $this->_setRuntimeData($model); return true; }
beforeValidate Callback @param Model $model Model invalidFields was called on. @return boolean @access public
beforeValidate
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function beforeSave($model, $options = array()) { if (isset($options['validate']) && $options['validate'] == false) { unset($this->runtime[$model->alias]['beforeSave']); } if (isset($this->runtime[$model->alias]['beforeSave'])) { return true; } $this->_setRuntimeData($model); return true; }
beforeSave callback. Copies data into the runtime property when `$options['validate']` is disabled. Or the runtime data hasn't been set yet. @param Model $model Model save was called on. @return boolean true.
beforeSave
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function _setRuntimeData(Model $model) { $locale = $this->_getLocale($model); if (empty($locale)) { return true; } $fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']); $tempData = array(); foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; if (isset($model->data[$model->alias][$field])) { $tempData[$field] = $model->data[$model->alias][$field]; if (is_array($model->data[$model->alias][$field])) { if (is_string($locale) && !empty($model->data[$model->alias][$field][$locale])) { $model->data[$model->alias][$field] = $model->data[$model->alias][$field][$locale]; } else { $values = array_values($model->data[$model->alias][$field]); $model->data[$model->alias][$field] = $values[0]; } } } } $this->runtime[$model->alias]['beforeSave'] = $tempData; }
Sets the runtime data. Used from beforeValidate() and beforeSave() for compatibility issues, and to allow translations to be persisted even when validation is disabled. @param Model $model @return void
_setRuntimeData
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function afterSave(&$model, $created) { if (!isset($this->runtime[$model->alias]['beforeValidate']) && !isset($this->runtime[$model->alias]['beforeSave'])) { return true; } $locale = $this->_getLocale($model); if (isset($this->runtime[$model->alias]['beforeValidate'])) { $tempData = $this->runtime[$model->alias]['beforeValidate']; } else { $tempData = $this->runtime[$model->alias]['beforeSave']; } unset($this->runtime[$model->alias]['beforeValidate'], $this->runtime[$model->alias]['beforeSave']); $conditions = array('model' => $model->alias, 'foreign_key' => $model->id); $RuntimeModel =& $this->translateModel($model); foreach ($tempData as $field => $value) { unset($conditions['content']); $conditions['field'] = $field; if (is_array($value)) { $conditions['locale'] = array_keys($value); } else { $conditions['locale'] = $locale; if (is_array($locale)) { $value = array($locale[0] => $value); } else { $value = array($locale => $value); } } $translations = $RuntimeModel->find('list', array('conditions' => $conditions, 'fields' => array($RuntimeModel->alias . '.locale', $RuntimeModel->alias . '.id'))); foreach ($value as $_locale => $_value) { $RuntimeModel->create(); $conditions['locale'] = $_locale; $conditions['content'] = $_value; if (array_key_exists($_locale, $translations)) { $RuntimeModel->save(array($RuntimeModel->alias => array_merge($conditions, array('id' => $translations[$_locale])))); } else { $RuntimeModel->save(array($RuntimeModel->alias => $conditions)); } } } }
afterSave Callback @param Model $model Model the callback is called on @param boolean $created Whether or not the save created a record. @return void @access public
afterSave
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function afterDelete(&$model) { $RuntimeModel =& $this->translateModel($model); $conditions = array('model' => $model->alias, 'foreign_key' => $model->id); $RuntimeModel->deleteAll($conditions); }
afterDelete Callback @param Model $model Model the callback was run on. @return void @access public
afterDelete
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function _getLocale(&$model) { if (!isset($model->locale) || is_null($model->locale)) { if (!class_exists('I18n')) { App::import('Core', 'i18n'); } $I18n =& I18n::getInstance(); $I18n->l10n->get(Configure::read('Config.language')); $model->locale = $I18n->l10n->locale; } return $model->locale; }
Get selected locale for model @param Model $model Model the locale needs to be set/get on. @return mixed string or false @access protected
_getLocale
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function &translateModel(&$model) { if (!isset($this->runtime[$model->alias]['model'])) { if (!isset($model->translateModel) || empty($model->translateModel)) { $className = 'I18nModel'; } else { $className = $model->translateModel; } if (PHP5) { $this->runtime[$model->alias]['model'] = ClassRegistry::init($className, 'Model'); } else { $this->runtime[$model->alias]['model'] =& ClassRegistry::init($className, 'Model'); } } if (!empty($model->translateTable) && $model->translateTable !== $this->runtime[$model->alias]['model']->useTable) { $this->runtime[$model->alias]['model']->setSource($model->translateTable); } elseif (empty($model->translateTable) && empty($model->translateModel)) { $this->runtime[$model->alias]['model']->setSource('i18n'); } $model =& $this->runtime[$model->alias]['model']; return $model; }
Get instance of model for translations. If the model has a translateModel property set, this will be used as the class name to find/use. If no translateModel property is found 'I18nModel' will be used. @param Model $model Model to get a translatemodel for. @return object @access public
translateModel
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function bindTranslation(&$model, $fields, $reset = true) { if (is_string($fields)) { $fields = array($fields); } $associations = array(); $RuntimeModel =& $this->translateModel($model); $default = array('className' => $RuntimeModel->alias, 'foreignKey' => 'foreign_key'); foreach ($fields as $key => $value) { if (is_numeric($key)) { $field = $value; $association = null; } else { $field = $key; $association = $value; } if (array_key_exists($field, $this->settings[$model->alias])) { unset($this->settings[$model->alias][$field]); } elseif (in_array($field, $this->settings[$model->alias])) { $this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field))); } if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) { unset($this->runtime[$model->alias]['fields'][$field]); } elseif (in_array($field, $this->runtime[$model->alias]['fields'])) { $this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field))); } if (is_null($association)) { if ($reset) { $this->runtime[$model->alias]['fields'][] = $field; } else { $this->settings[$model->alias][] = $field; } } else { if ($reset) { $this->runtime[$model->alias]['fields'][$field] = $association; } else { $this->settings[$model->alias][$field] = $association; } foreach (array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) { if (isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) { trigger_error( sprintf(__('Association %s is already binded to model %s', true), $association, $model->alias), E_USER_ERROR ); return false; } } $associations[$association] = array_merge($default, array('conditions' => array( 'model' => $model->alias, $RuntimeModel->displayField => $field ))); } } if (!empty($associations)) { $model->bindModel(array('hasMany' => $associations), $reset); } return true; }
Bind translation for fields, optionally with hasMany association for fake field @param object instance of model @param mixed string with field or array(field1, field2=>AssocName, field3) @param boolean $reset @return bool
bindTranslation
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function unbindTranslation(&$model, $fields = null) { if (empty($fields) && empty($this->settings[$model->alias])) { return false; } if (empty($fields)) { return $this->unbindTranslation($model, $this->settings[$model->alias]); } if (is_string($fields)) { $fields = array($fields); } $RuntimeModel =& $this->translateModel($model); $associations = array(); foreach ($fields as $key => $value) { if (is_numeric($key)) { $field = $value; $association = null; } else { $field = $key; $association = $value; } if (array_key_exists($field, $this->settings[$model->alias])) { unset($this->settings[$model->alias][$field]); } elseif (in_array($field, $this->settings[$model->alias])) { $this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field))); } if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) { unset($this->runtime[$model->alias]['fields'][$field]); } elseif (in_array($field, $this->runtime[$model->alias]['fields'])) { $this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field))); } if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) { $associations[] = $association; } } if (!empty($associations)) { $model->unbindModel(array('hasMany' => $associations), false); } return true; }
Unbind translation for fields, optionally unbinds hasMany association for fake field @param object $model instance of model @param mixed $fields string with field, or array(field1, field2=>AssocName, field3), or null for unbind all original translations @return bool
unbindTranslation
php
Datawalke/Coordino
cake/libs/model/behaviors/translate.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/translate.php
MIT
function setup(&$Model, $config = array()) { if (!is_array($config)) { $config = array('type' => $config); } $settings = array_merge($this->_defaults, $config); if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) { $data = $Model->getAssociated($settings['scope']); $parent =& $Model->{$settings['scope']}; $settings['scope'] = $Model->alias . '.' . $data['foreignKey'] . ' = ' . $parent->alias . '.' . $parent->primaryKey; $settings['recursive'] = 0; } $this->settings[$Model->alias] = $settings; }
Initiate Tree behavior @param object $Model instance of model @param array $config array of configuration settings. @return void @access public
setup
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function afterSave(&$Model, $created) { extract($this->settings[$Model->alias]); if ($created) { if ((isset($Model->data[$Model->alias][$parent])) && $Model->data[$Model->alias][$parent]) { return $this->_setParent($Model, $Model->data[$Model->alias][$parent], $created); } } elseif ($__parentChange) { $this->settings[$Model->alias]['__parentChange'] = false; return $this->_setParent($Model, $Model->data[$Model->alias][$parent]); } }
After save method. Called after all saves Overriden to transparently manage setting the lft and rght fields if and only if the parent field is included in the parameters to be saved. @param AppModel $Model Model instance. @param boolean $created indicates whether the node just saved was created or updated @return boolean true on success, false on failure @access public
afterSave
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function beforeDelete(&$Model) { extract($this->settings[$Model->alias]); list($name, $data) = array($Model->alias, $Model->read()); $data = $data[$name]; if (!$data[$right] || !$data[$left]) { return true; } $diff = $data[$right] - $data[$left] + 1; if ($diff > 2) { if (is_string($scope)) { $scope = array($scope); } $scope[]["{$Model->alias}.{$left} BETWEEN ? AND ?"] = array($data[$left] + 1, $data[$right] - 1); $Model->deleteAll($scope); } $this->__sync($Model, $diff, '-', '> ' . $data[$right]); return true; }
Before delete method. Called before all deletes Will delete the current node and all children using the deleteAll method and sync the table @param AppModel $Model Model instance @return boolean true to continue, false to abort the delete @access public
beforeDelete
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function beforeSave(&$Model) { extract($this->settings[$Model->alias]); $this->_addToWhitelist($Model, array($left, $right)); if (!$Model->id) { if (array_key_exists($parent, $Model->data[$Model->alias]) && $Model->data[$Model->alias][$parent]) { $parentNode = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $Model->data[$Model->alias][$parent]), 'fields' => array($Model->primaryKey, $right), 'recursive' => $recursive )); if (!$parentNode) { return false; } list($parentNode) = array_values($parentNode); $Model->data[$Model->alias][$left] = 0; //$parentNode[$right]; $Model->data[$Model->alias][$right] = 0; //$parentNode[$right] + 1; } else { $edge = $this->__getMax($Model, $scope, $right, $recursive); $Model->data[$Model->alias][$left] = $edge + 1; $Model->data[$Model->alias][$right] = $edge + 2; } } elseif (array_key_exists($parent, $Model->data[$Model->alias])) { if ($Model->data[$Model->alias][$parent] != $Model->field($parent)) { $this->settings[$Model->alias]['__parentChange'] = true; } if (!$Model->data[$Model->alias][$parent]) { $Model->data[$Model->alias][$parent] = null; $this->_addToWhitelist($Model, $parent); } else { $values = $Model->find('first', array( 'conditions' => array($scope,$Model->escapeField() => $Model->id), 'fields' => array($Model->primaryKey, $parent, $left, $right ), 'recursive' => $recursive) ); if ($values === false) { return false; } list($node) = array_values($values); $parentNode = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $Model->data[$Model->alias][$parent]), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive )); if (!$parentNode) { return false; } list($parentNode) = array_values($parentNode); if (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) { return false; } elseif ($node[$Model->primaryKey] == $parentNode[$Model->primaryKey]) { return false; } } } return true; }
Before save method. Called before all saves Overriden to transparently manage setting the lft and rght fields if and only if the parent field is included in the parameters to be saved. For newly created nodes with NO parent the left and right field values are set directly by this method bypassing the setParent logic. @since 1.2 @param AppModel $Model Model instance @return boolean true to continue, false to abort the save @access public
beforeSave
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function childcount(&$Model, $id = null, $direct = false) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } if ($id === null && $Model->id) { $id = $Model->id; } elseif (!$id) { $id = null; } extract($this->settings[$Model->alias]); if ($direct) { return $Model->find('count', array('conditions' => array($scope, $Model->escapeField($parent) => $id))); } if ($id === null) { return $Model->find('count', array('conditions' => $scope)); } elseif ($Model->id === $id && isset($Model->data[$Model->alias][$left]) && isset($Model->data[$Model->alias][$right])) { $data = $Model->data[$Model->alias]; } else { $data = $Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive)); if (!$data) { return 0; } $data = $data[$Model->alias]; } return ($data[$right] - $data[$left] - 1) / 2; }
Get the number of child nodes If the direct parameter is set to true, only the direct children are counted (based upon the parent_id field) If false is passed for the id parameter, all top level nodes are counted, or all nodes are counted. @param AppModel $Model Model instance @param mixed $id The ID of the record to read or false to read all top level nodes @param boolean $direct whether to count direct, or all, children @return integer number of child nodes @access public @link http://book.cakephp.org/view/1347/Counting-children
childcount
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function generatetreelist(&$Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) { $overrideRecursive = $recursive; extract($this->settings[$Model->alias]); if (!is_null($overrideRecursive)) { $recursive = $overrideRecursive; } if ($keyPath == null && $valuePath == null && $Model->hasField($Model->displayField)) { $fields = array($Model->primaryKey, $Model->displayField, $left, $right); } else { $fields = null; } if ($keyPath == null) { $keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey; } if ($valuePath == null) { $valuePath = array('{0}{1}', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField); } elseif (is_string($valuePath)) { $valuePath = array('{0}{1}', '{n}.tree_prefix', $valuePath); } else { $valuePath[0] = '{' . (count($valuePath) - 1) . '}' . $valuePath[0]; $valuePath[] = '{n}.tree_prefix'; } $order = $Model->alias . '.' . $left . ' asc'; $results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive')); $stack = array(); foreach ($results as $i => $result) { while ($stack && ($stack[count($stack) - 1] < $result[$Model->alias][$right])) { array_pop($stack); } $results[$i]['tree_prefix'] = str_repeat($spacer,count($stack)); $stack[] = $result[$Model->alias][$right]; } if (empty($results)) { return array(); } return Set::combine($results, $keyPath, $valuePath); }
A convenience method for returning a hierarchical array used for HTML select boxes @param AppModel $Model Model instance @param mixed $conditions SQL conditions as a string or as an array('field' =>'value',...) @param string $keyPath A string path to the key, i.e. "{n}.Post.id" @param string $valuePath A string path to the value, i.e. "{n}.Post.title" @param string $spacer The character or characters which will be repeated @param integer $recursive The number of levels deep to fetch associated records @return array An associative array of records, where the id is the key, and the display field is the value @access public @link http://book.cakephp.org/view/1348/generatetreelist
generatetreelist
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function getparentnode(&$Model, $id = null, $fields = null, $recursive = null) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } $overrideRecursive = $recursive; if (empty ($id)) { $id = $Model->id; } extract($this->settings[$Model->alias]); if (!is_null($overrideRecursive)) { $recursive = $overrideRecursive; } $parentId = $Model->find('first', array('conditions' => array($Model->primaryKey => $id), 'fields' => array($parent), 'recursive' => -1)); if ($parentId) { $parentId = $parentId[$Model->alias][$parent]; $parent = $Model->find('first', array('conditions' => array($Model->escapeField() => $parentId), 'fields' => $fields, 'recursive' => $recursive)); return $parent; } return false; }
Get the parent node reads the parent id and returns this node @param AppModel $Model Model instance @param mixed $id The ID of the record to read @param integer $recursive The number of levels deep to fetch associated records @return array Array of data for the parent node @access public @link http://book.cakephp.org/view/1349/getparentnode
getparentnode
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function getpath(&$Model, $id = null, $fields = null, $recursive = null) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } $overrideRecursive = $recursive; if (empty ($id)) { $id = $Model->id; } extract($this->settings[$Model->alias]); if (!is_null($overrideRecursive)) { $recursive = $overrideRecursive; } $result = $Model->find('first', array('conditions' => array($Model->escapeField() => $id), 'fields' => array($left, $right), 'recursive' => $recursive)); if ($result) { $result = array_values($result); } else { return null; } $item = $result[0]; $results = $Model->find('all', array( 'conditions' => array($scope, $Model->escapeField($left) . ' <=' => $item[$left], $Model->escapeField($right) . ' >=' => $item[$right]), 'fields' => $fields, 'order' => array($Model->escapeField($left) => 'asc'), 'recursive' => $recursive )); return $results; }
Get the path to the given node @param AppModel $Model Model instance @param mixed $id The ID of the record to read @param mixed $fields Either a single string of a field name, or an array of field names @param integer $recursive The number of levels deep to fetch associated records @return array Array of nodes from top most parent to current node @access public @link http://book.cakephp.org/view/1350/getpath
getpath
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function movedown(&$Model, $id = null, $number = 1) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } if (!$number) { return false; } if (empty ($id)) { $id = $Model->id; } extract($this->settings[$Model->alias]); list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $id), 'fields' => array($Model->primaryKey, $left, $right, $parent), 'recursive' => $recursive ))); if ($node[$parent]) { list($parentNode) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $node[$parent]), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive ))); if (($node[$right] + 1) == $parentNode[$right]) { return false; } } $nextNode = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField($left) => ($node[$right] + 1)), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive) ); if ($nextNode) { list($nextNode) = array_values($nextNode); } else { return false; } $edge = $this->__getMax($Model, $scope, $right, $recursive); $this->__sync($Model, $edge - $node[$left] + 1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right]); $this->__sync($Model, $nextNode[$left] - $node[$left], '-', 'BETWEEN ' . $nextNode[$left] . ' AND ' . $nextNode[$right]); $this->__sync($Model, $edge - $node[$left] - ($nextNode[$right] - $nextNode[$left]), '-', '> ' . $edge); if (is_int($number)) { $number--; } if ($number) { $this->moveDown($Model, $id, $number); } return true; }
Reorder the node without changing the parent. If the node is the last child, or is a top level node with no subsequent node this method will return false @param AppModel $Model Model instance @param mixed $id The ID of the record to move @param int|bool $number how many places to move the node or true to move to last position @return boolean true on success, false on failure @access public @link http://book.cakephp.org/view/1352/moveDown
movedown
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function moveup(&$Model, $id = null, $number = 1) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } if (!$number) { return false; } if (empty ($id)) { $id = $Model->id; } extract($this->settings[$Model->alias]); list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $id), 'fields' => array($Model->primaryKey, $left, $right, $parent ), 'recursive' => $recursive ))); if ($node[$parent]) { list($parentNode) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $node[$parent]), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive ))); if (($node[$left] - 1) == $parentNode[$left]) { return false; } } $previousNode = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField($right) => ($node[$left] - 1)), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive )); if ($previousNode) { list($previousNode) = array_values($previousNode); } else { return false; } $edge = $this->__getMax($Model, $scope, $right, $recursive); $this->__sync($Model, $edge - $previousNode[$left] +1, '+', 'BETWEEN ' . $previousNode[$left] . ' AND ' . $previousNode[$right]); $this->__sync($Model, $node[$left] - $previousNode[$left], '-', 'BETWEEN ' .$node[$left] . ' AND ' . $node[$right]); $this->__sync($Model, $edge - $previousNode[$left] - ($node[$right] - $node[$left]), '-', '> ' . $edge); if (is_int($number)) { $number--; } if ($number) { $this->moveUp($Model, $id, $number); } return true; }
Reorder the node without changing the parent. If the node is the first child, or is a top level node with no previous node this method will return false @param AppModel $Model Model instance @param mixed $id The ID of the record to move @param int|bool $number how many places to move the node, or true to move to first position @return boolean true on success, false on failure @access public @link http://book.cakephp.org/view/1353/moveUp
moveup
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function recover(&$Model, $mode = 'parent', $missingParentAction = null) { if (is_array($mode)) { extract (array_merge(array('mode' => 'parent'), $mode)); } extract($this->settings[$Model->alias]); $Model->recursive = $recursive; if ($mode == 'parent') { $Model->bindModel(array('belongsTo' => array('VerifyParent' => array( 'className' => $Model->name, 'foreignKey' => $parent, 'fields' => array($Model->primaryKey, $left, $right, $parent), )))); $missingParents = $Model->find('list', array( 'recursive' => 0, 'conditions' => array($scope, array( 'NOT' => array($Model->escapeField($parent) => null), $Model->VerifyParent->escapeField() => null )) )); $Model->unbindModel(array('belongsTo' => array('VerifyParent'))); if ($missingParents) { if ($missingParentAction == 'return') { foreach ($missingParents as $id => $display) { $this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')'; } return false; } elseif ($missingParentAction == 'delete') { $Model->deleteAll(array($Model->primaryKey => array_flip($missingParents))); } else { $Model->updateAll(array($parent => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents))); } } $count = 1; foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) { $lft = $count++; $rght = $count++; $Model->create(false); $Model->id = $array[$Model->alias][$Model->primaryKey]; $Model->save(array($left => $lft, $right => $rght), array('callbacks' => false)); } foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $Model->create(false); $Model->id = $array[$Model->alias][$Model->primaryKey]; $this->_setParent($Model, $array[$Model->alias][$parent]); } } else { $db =& ConnectionManager::getDataSource($Model->useDbConfig); foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $path = $this->getpath($Model, $array[$Model->alias][$Model->primaryKey]); if ($path == null || count($path) < 2) { $parentId = null; } else { $parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey]; } $Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey])); } } return true; }
Recover a corrupted tree The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode 'parent' the values of the parent_id field will be used to populate the left and right fields. The missingParentAction parameter only applies to "parent" mode and determines what to do if the parent field contains an id that is not present. @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. @param AppModel $Model Model instance @param string $mode parent or tree @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to delete, or the id of the parent to set as the parent_id @return boolean true on success, false on failure @access public @link http://book.cakephp.org/view/1628/Recover
recover
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function reorder(&$Model, $options = array()) { $options = array_merge(array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true), $options); extract($options); if ($verify && !$this->verify($Model)) { return false; } $verify = false; extract($this->settings[$Model->alias]); $fields = array($Model->primaryKey, $field, $left, $right); $sort = $field . ' ' . $order; $nodes = $this->children($Model, $id, true, $fields, $sort, null, null, $recursive); $cacheQueries = $Model->cacheQueries; $Model->cacheQueries = false; if ($nodes) { foreach ($nodes as $node) { $id = $node[$Model->alias][$Model->primaryKey]; $this->moveDown($Model, $id, true); if ($node[$Model->alias][$left] != $node[$Model->alias][$right] - 1) { $this->reorder($Model, compact('id', 'field', 'order', 'verify')); } } } $Model->cacheQueries = $cacheQueries; return true; }
Reorder method. Reorders the nodes (and child nodes) of the tree according to the field and direction specified in the parameters. This method does not change the parent of any node. Requires a valid tree, by default it verifies the tree before beginning. Options: - 'id' id of record to use as top node for reordering - 'field' Which field to use in reordeing defaults to displayField - 'order' Direction to order either DESC or ASC (defaults to ASC) - 'verify' Whether or not to verify the tree before reorder. defaults to true. @param AppModel $Model Model instance @param array $options array of options to use in reordering. @return boolean true on success, false on failure @link http://book.cakephp.org/view/1355/reorder @link http://book.cakephp.org/view/1629/Reorder
reorder
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function removefromtree(&$Model, $id = null, $delete = false) { if (is_array($id)) { extract (array_merge(array('id' => null), $id)); } extract($this->settings[$Model->alias]); list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $id), 'fields' => array($Model->primaryKey, $left, $right, $parent), 'recursive' => $recursive ))); if ($node[$right] == $node[$left] + 1) { if ($delete) { return $Model->delete($id); } else { $Model->id = $id; return $Model->saveField($parent, null); } } elseif ($node[$parent]) { list($parentNode) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $node[$parent]), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive ))); } else { $parentNode[$right] = $node[$right] + 1; } $db =& ConnectionManager::getDataSource($Model->useDbConfig); $Model->updateAll( array($parent => $db->value($node[$parent], $parent)), array($Model->escapeField($parent) => $node[$Model->primaryKey]) ); $this->__sync($Model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1)); $this->__sync($Model, 2, '-', '> ' . ($node[$right])); $Model->id = $id; if ($delete) { $Model->updateAll( array( $Model->escapeField($left) => 0, $Model->escapeField($right) => 0, $Model->escapeField($parent) => null ), array($Model->escapeField() => $id) ); return $Model->delete($id); } else { $edge = $this->__getMax($Model, $scope, $right, $recursive); if ($node[$right] == $edge) { $edge = $edge - 2; } $Model->id = $id; return $Model->save( array($left => $edge + 1, $right => $edge + 2, $parent => null), array('callbacks' => false) ); } }
Remove the current node from the tree, and reparent all children up one level. If the parameter delete is false, the node will become a new top level node. Otherwise the node will be deleted after the children are reparented. @param AppModel $Model Model instance @param mixed $id The ID of the record to remove @param boolean $delete whether to delete the node after reparenting children (if any) @return boolean true on success, false on failure @access public @link http://book.cakephp.org/view/1354/removeFromTree
removefromtree
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function verify(&$Model) { extract($this->settings[$Model->alias]); if (!$Model->find('count', array('conditions' => $scope))) { return true; } $min = $this->__getMin($Model, $scope, $left, $recursive); $edge = $this->__getMax($Model, $scope, $right, $recursive); $errors = array(); for ($i = $min; $i <= $edge; $i++) { $count = $Model->find('count', array('conditions' => array( $scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i) ))); if ($count != 1) { if ($count == 0) { $errors[] = array('index', $i, 'missing'); } else { $errors[] = array('index', $i, 'duplicate'); } } } $node = $Model->find('first', array('conditions' => array($scope, $Model->escapeField($right) . '< ' . $Model->escapeField($left)), 'recursive' => 0)); if ($node) { $errors[] = array('node', $node[$Model->alias][$Model->primaryKey], 'left greater than right.'); } $Model->bindModel(array('belongsTo' => array('VerifyParent' => array( 'className' => $Model->name, 'foreignKey' => $parent, 'fields' => array($Model->primaryKey, $left, $right, $parent) )))); foreach ($Model->find('all', array('conditions' => $scope, 'recursive' => 0)) as $instance) { if (is_null($instance[$Model->alias][$left]) || is_null($instance[$Model->alias][$right])) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'has invalid left or right values'); } elseif ($instance[$Model->alias][$left] == $instance[$Model->alias][$right]) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'left and right values identical'); } elseif ($instance[$Model->alias][$parent]) { if (!$instance['VerifyParent'][$Model->primaryKey]) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'The parent node ' . $instance[$Model->alias][$parent] . ' doesn\'t exist'); } elseif ($instance[$Model->alias][$left] < $instance['VerifyParent'][$left]) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'left less than parent (node ' . $instance['VerifyParent'][$Model->primaryKey] . ').'); } elseif ($instance[$Model->alias][$right] > $instance['VerifyParent'][$right]) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'right greater than parent (node ' . $instance['VerifyParent'][$Model->primaryKey] . ').'); } } elseif ($Model->find('count', array('conditions' => array($scope, $Model->escapeField($left) . ' <' => $instance[$Model->alias][$left], $Model->escapeField($right) . ' >' => $instance[$Model->alias][$right]), 'recursive' => 0))) { $errors[] = array('node', $instance[$Model->alias][$Model->primaryKey], 'The parent field is blank, but has a parent'); } } if ($errors) { return $errors; } return true; }
Check if the current tree is valid. Returns true if the tree is valid otherwise an array of (type, incorrect left/right index, message) @param AppModel $Model Model instance @return mixed true if the tree is valid or empty, otherwise an array of (error type [index, node], [incorrect left/right index,node id], message) @access public @link http://book.cakephp.org/view/1630/Verify
verify
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function _setParent(&$Model, $parentId = null, $created = false) { extract($this->settings[$Model->alias]); list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $Model->id), 'fields' => array($Model->primaryKey, $parent, $left, $right), 'recursive' => $recursive ))); $edge = $this->__getMax($Model, $scope, $right, $recursive, $created); if (empty ($parentId)) { $this->__sync($Model, $edge - $node[$left] + 1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right], $created); $this->__sync($Model, $node[$right] - $node[$left] + 1, '-', '> ' . $node[$left], $created); } else { $values = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $parentId), 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive )); if ($values === false) { return false; } $parentNode = array_values($values); if (empty($parentNode) || empty($parentNode[0])) { return false; } $parentNode = $parentNode[0]; if (($Model->id == $parentId)) { return false; } elseif (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) { return false; } if (empty($node[$left]) && empty ($node[$right])) { $this->__sync($Model, 2, '+', '>= ' . $parentNode[$right], $created); $result = $Model->save( array($left => $parentNode[$right], $right => $parentNode[$right] + 1, $parent => $parentId), array('validate' => false, 'callbacks' => false) ); $Model->data = $result; } else { $this->__sync($Model, $edge - $node[$left] +1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right], $created); $diff = $node[$right] - $node[$left] + 1; if ($node[$left] > $parentNode[$left]) { if ($node[$right] < $parentNode[$right]) { $this->__sync($Model, $diff, '-', 'BETWEEN ' . $node[$right] . ' AND ' . ($parentNode[$right] - 1), $created); $this->__sync($Model, $edge - $parentNode[$right] + $diff + 1, '-', '> ' . $edge, $created); } else { $this->__sync($Model, $diff, '+', 'BETWEEN ' . $parentNode[$right] . ' AND ' . $node[$right], $created); $this->__sync($Model, $edge - $parentNode[$right] + 1, '-', '> ' . $edge, $created); } } else { $this->__sync($Model, $diff, '-', 'BETWEEN ' . $node[$right] . ' AND ' . ($parentNode[$right] - 1), $created); $this->__sync($Model, $edge - $parentNode[$right] + $diff + 1, '-', '> ' . $edge, $created); } } } return true; }
Sets the parent of the given node The force parameter is used to override the "don't change the parent to the current parent" logic in the event of recovering a corrupted table, or creating new nodes. Otherwise it should always be false. In reality this method could be private, since calling save with parent_id set also calls setParent @param AppModel $Model Model instance @param mixed $parentId @param boolean $created @return boolean true on success, false on failure @access protected
_setParent
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function __getMax($Model, $scope, $right, $recursive = -1, $created = false) { $db =& ConnectionManager::getDataSource($Model->useDbConfig); if ($created) { if (is_string($scope)) { $scope .= " AND {$Model->alias}.{$Model->primaryKey} <> "; $scope .= $db->value($Model->id, $Model->getColumnType($Model->primaryKey)); } else { $scope['NOT'][$Model->alias . '.' . $Model->primaryKey] = $Model->id; } } $name = $Model->alias . '.' . $right; list($edge) = array_values($Model->find('first', array( 'conditions' => $scope, 'fields' => $db->calculate($Model, 'max', array($name, $right)), 'recursive' => $recursive ))); return (empty($edge[$right])) ? 0 : $edge[$right]; }
get the maximum index value in the table. @param AppModel $Model @param string $scope @param string $right @param int $recursive @param boolean $created @return int @access private
__getMax
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function __getMin($Model, $scope, $left, $recursive = -1) { $db =& ConnectionManager::getDataSource($Model->useDbConfig); $name = $Model->alias . '.' . $left; list($edge) = array_values($Model->find('first', array( 'conditions' => $scope, 'fields' => $db->calculate($Model, 'min', array($name, $left)), 'recursive' => $recursive ))); return (empty($edge[$left])) ? 0 : $edge[$left]; }
get the minimum index value in the table. @param AppModel $Model @param string $scope @param string $right @return int @access private
__getMin
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function __sync(&$Model, $shift, $dir = '+', $conditions = array(), $created = false, $field = 'both') { $ModelRecursive = $Model->recursive; extract($this->settings[$Model->alias]); $Model->recursive = $recursive; if ($field == 'both') { $this->__sync($Model, $shift, $dir, $conditions, $created, $left); $field = $right; } if (is_string($conditions)) { $conditions = array("{$Model->alias}.{$field} {$conditions}"); } if (($scope != '1 = 1' && $scope !== true) && $scope) { $conditions[] = $scope; } if ($created) { $conditions['NOT'][$Model->alias . '.' . $Model->primaryKey] = $Model->id; } $Model->updateAll(array($Model->alias . '.' . $field => $Model->escapeField($field) . ' ' . $dir . ' ' . $shift), $conditions); $Model->recursive = $ModelRecursive; }
Table sync method. Handles table sync operations, Taking account of the behavior scope. @param AppModel $Model @param integer $shift @param string $direction @param array $conditions @param boolean $created @param string $field @access private
__sync
php
Datawalke/Coordino
cake/libs/model/behaviors/tree.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/behaviors/tree.php
MIT
function __construct($config = array()) { parent::__construct(); $this->setConfig($config); }
Constructor. @param array $config Array of configuration information for the datasource. @return void.
__construct
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function listSources($data = null) { if ($this->cacheSources === false) { return null; } if ($this->_sources !== null) { return $this->_sources; } $key = ConnectionManager::getSourceName($this) . '_' . $this->config['database'] . '_list'; $key = preg_replace('/[^A-Za-z0-9_\-.+]/', '_', $key); $sources = Cache::read($key, '_cake_model_'); if (empty($sources)) { $sources = $data; Cache::write($key, $data, '_cake_model_'); } $this->_sources = $sources; return $sources; }
Caches/returns cached results for child instances @param mixed $data @return array Array of sources available in this datasource. @access public
listSources
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function sources($reset = false) { if ($reset === true) { $this->_sources = null; } return array_map('strtolower', $this->listSources()); }
Convenience method for DboSource::listSources(). Returns source names in lowercase. @param boolean $reset Whether or not the source list should be reset. @return array Array of sources available in this datasource @access public
sources
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function describe(&$model) { if ($this->cacheSources === false) { return null; } $table = $model->tablePrefix . $model->table; if (isset($this->__descriptions[$table])) { return $this->__descriptions[$table]; } $cache = $this->__cacheDescription($table); if ($cache !== null) { $this->__descriptions[$table] =& $cache; return $cache; } return null; }
Returns a Model description (metadata) or null if none found. @param Model $model @return array Array of Metadata for the $model @access public
describe
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function begin(&$model) { return !$this->_transactionStarted; }
Begin a transaction @return boolean Returns true if a transaction is not in progress @access public
begin
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function rollback(&$model) { return $this->_transactionStarted; }
Rollback a transaction @return boolean Returns true if a transaction is in progress @access public
rollback
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function column($real) { return false; }
Converts column types to basic types @param string $real Real column type (i.e. "varchar(255)") @return string Abstract column type (i.e. "string") @access public
column
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function create(&$model, $fields = null, $values = null) { return false; }
Used to create new records. The "C" CRUD. To-be-overridden in subclasses. @param Model $model The Model to be created. @param array $fields An Array of fields to be saved. @param array $values An Array of values to save. @return boolean success @access public
create
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function read(&$model, $queryData = array()) { return false; }
Used to read records from the Datasource. The "R" in CRUD To-be-overridden in subclasses. @param Model $model The model being read. @param array $queryData An array of query data used to find the data you want @return mixed @access public
read
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function update(&$model, $fields = null, $values = null) { return false; }
Update a record(s) in the datasource. To-be-overridden in subclasses. @param Model $model Instance of the model class being updated @param array $fields Array of fields to be updated @param array $values Array of values to be update $fields to. @return boolean Success @access public
update
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function delete(&$model, $conditions = null) { return false; }
Delete a record(s) in the datasource. To-be-overridden in subclasses. @param Model $model The model class having record(s) deleted @param mixed $conditions The conditions to use for deleting. @access public
delete
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function lastInsertId($source = null) { return false; }
Returns the ID generated from the previous INSERT operation. @param unknown_type $source @return mixed Last ID key generated in previous INSERT @access public
lastInsertId
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function lastNumRows($source = null) { return false; }
Returns the number of rows returned by last operation. @param unknown_type $source @return integer Number of rows returned by last operation @access public
lastNumRows
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function lastAffected($source = null) { return false; }
Returns the number of rows affected by last query. @param unknown_type $source @return integer Number of rows affected by last query. @access public
lastAffected
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function enabled() { return true; }
Check whether the conditions for the Datasource being available are satisfied. Often used from connect() to check for support before establishing a connection. @return boolean Whether or not the Datasources conditions for use are met. @access public
enabled
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function isInterfaceSupported($interface) { static $methods = false; if ($methods === false) { $methods = array_map('strtolower', get_class_methods($this)); } return in_array(strtolower($interface), $methods); }
Returns true if the DataSource supports the given interface (method) @param string $interface The name of the interface (method) @return boolean True on success @access public
isInterfaceSupported
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function setConfig($config = array()) { $this->config = array_merge($this->_baseConfig, $this->config, $config); }
Sets the configuration for the DataSource. Merges the $config information with the _baseConfig and the existing $config property. @param array $config The configuration array @return void @access public
setConfig
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function __cacheDescription($object, $data = null) { if ($this->cacheSources === false) { return null; } if ($data !== null) { $this->__descriptions[$object] =& $data; } $key = ConnectionManager::getSourceName($this) . '_' . $object; $cache = Cache::read($key, '_cake_model_'); if (empty($cache)) { $cache = $data; Cache::write($key, $cache, '_cake_model_'); } return $cache; }
Cache the DataSource description @param string $object The name of the object (model) to cache @param mixed $data The description of the model, usually a string or array @return mixed @access private
__cacheDescription
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) { $keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}'); foreach ($keys as $key) { $val = null; $type = null; if (strpos($query, $key) !== false) { switch ($key) { case '{$__cakeID__$}': if (isset($data[$model->alias]) || isset($data[$association])) { if (isset($data[$model->alias][$model->primaryKey])) { $val = $data[$model->alias][$model->primaryKey]; } elseif (isset($data[$association][$model->primaryKey])) { $val = $data[$association][$model->primaryKey]; } } else { $found = false; foreach (array_reverse($stack) as $assoc) { if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) { $val = $data[$assoc][$model->primaryKey]; $found = true; break; } } if (!$found) { $val = ''; } } $type = $model->getColumnType($model->primaryKey); break; case '{$__cakeForeignKey__$}': foreach ($model->__associations as $id => $name) { foreach ($model->$name as $assocName => $assoc) { if ($assocName === $association) { if (isset($assoc['foreignKey'])) { $foreignKey = $assoc['foreignKey']; $assocModel = $model->$assocName; $type = $assocModel->getColumnType($assocModel->primaryKey); if (isset($data[$model->alias][$foreignKey])) { $val = $data[$model->alias][$foreignKey]; } elseif (isset($data[$association][$foreignKey])) { $val = $data[$association][$foreignKey]; } else { $found = false; foreach (array_reverse($stack) as $assoc) { if (isset($data[$assoc]) && isset($data[$assoc][$foreignKey])) { $val = $data[$assoc][$foreignKey]; $found = true; break; } } if (!$found) { $val = ''; } } } break 3; } } } break; } if (empty($val) && $val !== '0') { return false; } $query = str_replace($key, $this->value($val, $type), $query); } } return $query; }
Replaces `{$__cakeID__$}` and `{$__cakeForeignKey__$}` placeholders in query data. @param string $query Query string needing replacements done. @param array $data Array of data with values that will be inserted in placeholders. @param string $association Name of association model being replaced @param unknown_type $assocData @param Model $model Instance of the model to replace $__cakeID__$ @param Model $linkModel Instance of model to replace $__cakeForeignKey__$ @param array $stack @return string String of query data with placeholders replaced. @access public @todo Remove and refactor $assocData, ensure uses of the method have the param removed too.
insertQueryData
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function resolveKey(&$model, $key) { return $model->alias . $key; }
To-be-overridden in subclasses. @param Model $model Model instance @param string $key Key name to make @return string Key name for model. @access public
resolveKey
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function __destruct() { if ($this->_transactionStarted) { $null = null; $this->rollback($null); } if ($this->connected) { $this->close(); } }
Closes the current datasource. @return void @access public
__destruct
php
Datawalke/Coordino
cake/libs/model/datasources/datasource.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/datasource.php
MIT
function __construct($config = null, $autoConnect = true) { if (!isset($config['prefix'])) { $config['prefix'] = ''; } parent::__construct($config); $this->fullDebug = Configure::read() > 1; if (!$this->enabled()) { return false; } if ($autoConnect) { return $this->connect(); } else { return true; } }
Constructor @param array $config Array of configuration information for the Datasource. @param boolean $autoConnect Whether or not the datasource should automatically connect. @access public
__construct
php
Datawalke/Coordino
cake/libs/model/datasources/dbo_source.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo_source.php
MIT
function reconnect($config = array()) { $this->disconnect(); $this->setConfig($config); $this->_sources = null; return $this->connect(); }
Reconnects to database server with optional new settings @param array $config An array defining the new configuration settings @return boolean True on success, false on failure @access public
reconnect
php
Datawalke/Coordino
cake/libs/model/datasources/dbo_source.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo_source.php
MIT
function value($data, $column = null, $read = true) { if (is_array($data) && !empty($data)) { return array_map( array(&$this, 'value'), $data, array_fill(0, count($data), $column), array_fill(0, count($data), $read) ); } elseif (is_object($data) && isset($data->type)) { if ($data->type == 'identifier') { return $this->name($data->value); } elseif ($data->type == 'expression') { return $data->value; } } elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { return $data; } else { return null; } }
Prepares a value, or an array of values for database queries by quoting and escaping them. @param mixed $data A value or an array of values to prepare. @param string $column The column into which this data will be inserted @param boolean $read Value to be used in READ or WRITE context @return mixed Prepared value or array of values. @access public
value
php
Datawalke/Coordino
cake/libs/model/datasources/dbo_source.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo_source.php
MIT