本文整理汇总了PHP中ModelBehavior::beforeFind方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelBehavior::beforeFind方法的具体用法?PHP ModelBehavior::beforeFind怎么用?PHP ModelBehavior::beforeFind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBehavior
的用法示例。
在下文中一共展示了ModelBehavior::beforeFind方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeFind
/**
* beforeFind callback
*
* @param object $Model
* @param array $query
*/
public function beforeFind(Model $Model, $query)
{
$Model->bindModel(array('hasOne' => array('Alias' => array('className' => 'Alias', 'foreignKey' => 'value', 'dependent' => true, 'conditions' => array('Alias.controller' => Inflector::tableize($Model->name)), 'fields' => '', 'order' => 'Alias.modified DESC'))), false);
$query['contain'][] = 'Alias';
$query['group'] = !empty($query['group']) ? $query['group'] : array($Model->alias => 'id');
return parent::beforeFind($Model, $query);
}
示例2: beforeFind
/**
* Before find we need to convert date fields to sqlformat
*
* @todo Optimize cycle, really poor implementation here
* @return Array
**/
public function beforeFind(Model $model, $query = array())
{
parent::beforeFind($model, $query);
if ($model->findQueryType == 'count') {
return $query;
}
//-- if conditions exists
if (isset($query['conditions']) && is_array($query['conditions'])) {
$columnTypes = $model->getColumnTypes();
$fields = array_filter($columnTypes, array($this, 'valueIsDate'));
//-- Get all conditions keys
$conditionsKeys = array_keys($query['conditions']);
$walked = array();
foreach ($conditionsKeys as $conKey) {
$cond = explode(' ', $conKey);
if (!in_array($cond[0], $fields)) {
continue;
}
$curObj = $this->dateObject($query['conditions'][$conKey]);
$walked[$conKey] = $this->ObjectToSQL($curObj);
}
$query['conditions'] = array_merge($query['conditions'], $walked);
}
return $query;
}
示例3: beforeFind
/**
* beforeFind method
*
* @param Model $model
* @param array $query
* @return void
*/
public function beforeFind(Model $model, $query) {
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeFind']) || $settings['beforeFind'] === 'off') {
return parent::beforeFind($model, $query);
}
switch ($settings['beforeFind']) {
case 'on':
return false;
case 'test':
return null;
case 'modify':
$query['fields'] = array($model->alias . '.id', $model->alias . '.name', $model->alias . '.mytime');
$query['recursive'] = -1;
return $query;
}
}
示例4: beforeFind
/**
* Before find callback
*
* @param object $model Model using this behavior
* @param array $query Data used to execute this query, i.e. conditions, order, etc.
* @return bool True if the operation should continue, false if it should abort
*/
public function beforeFind($model, $query)
{
$result = parent::beforeFind($model, $query);
if (empty($this->settings[$model->alias]['find']) || isset($query['defaultable']) && $query['defaultable'] === false || $result === false) {
return $result;
} else {
if (is_array($result)) {
$query = $result;
}
}
$Db = ConnectionManager::getDataSource($model->useDbConfig);
$defaultConditions = array();
foreach ($this->settings[$model->alias]['find'] as $field => $fieldValue) {
$fields = array($Db->name($model->alias) . '.' . $Db->name($field), $Db->name($field), $model->alias . '.' . $field, $field);
$include = true;
if (!empty($query['conditions'])) {
foreach (Set::flatten((array) $query['conditions']) as $key => $value) {
$condition = is_numeric($key) ? $value : $key;
foreach ($fields as $field) {
if (preg_match('/^((not|or)\\.)?' . preg_quote($field) . '/i', $condition) || preg_match('/^((not|or)\\.)?' . preg_quote($model->alias . '.' . $field) . '/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($field) . '[^A-Z0-9_]+/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($model->alias . '.' . $field) . '[^A-Z0-9_]+/i', $condition)) {
$include = false;
break;
}
}
if (!$include) {
break;
}
}
}
if ($include) {
$defaultConditions[$model->alias . '.' . $field] = $fieldValue;
}
}
if (!empty($defaultConditions)) {
if (empty($query['conditions'])) {
$query['conditions'] = array();
} else {
if (!is_array($query['conditions'])) {
$query['conditions'] = (array) $query['conditions'];
}
}
$query['conditions'] = array_merge($query['conditions'], $defaultConditions);
$result = $query;
}
return $result;
}
示例5: beforeFind
/**
* Before find we need to convert date fields to sqlformat
*
* @todo Optimize cycle, really poor implementation here
* @todo fix containable behavior
* @return Array
**/
public function beforeFind(Model $model, $query = array())
{
parent::beforeFind($model, $query);
if ($model->findQueryType == 'count') {
return $query;
}
//-- if conditions exists
if (isset($query['conditions']) && is_array($query['conditions'])) {
$columnTypes = $model->getColumnTypes();
$fields = array_filter($columnTypes, array($this, 'valueIsDate'));
//-- Get all conditions keys
$conditionsKeys = array_keys($query['conditions']);
$walked = array();
foreach ($conditionsKeys as $conKey) {
$cond = explode(' ', $conKey);
$cond[0] = str_replace($model->name . '.', null, $cond[0]);
if (!array_key_exists($cond[0], $fields)) {
continue;
}
$values = $query['conditions'][$conKey];
if (is_array($values)) {
foreach ($values as $key => $date) {
$tmpdate = $this->dateObject($date);
$query['conditions'][$conKey][$key] = $this->ObjectToSQL($tmpdate);
}
$walked[$conKey] = $query['conditions'][$conKey];
} elseif (is_string($values)) {
$curObj = $this->dateObject($values);
if (!$curObj) {
continue;
}
$walked[$conKey] = $this->ObjectToSQL($curObj);
}
}
$query['conditions'] = array_merge($query['conditions'], $walked);
}
return $query;
}
示例6: beforeFind
public function beforeFind(\Model $model, $query)
{
return parent::beforeFind($model, $query);
}
示例7: beforeFind
/**
* Adiciona condição de registros ativos nas buscas do modelo
* @param Model $Model
* @param array $queryData
* @see ModelBehavior::beforeFind()
*/
public function beforeFind(Model $Model, $queryData)
{
parent::beforeFind($Model, $queryData);
$this->_prepareFind($queryData, $Model);
return $queryData;
}
示例8: beforeFind
/**
*
* @see ModelBehavior::beforeFind()
*/
public function beforeFind(Model $model, $query)
{
parent::beforeFind($model, $query);
$this->_Model = $model;
$this->__checkConfig($model);
$this->localizeData($query['conditions']);
return $query;
}
示例9: beforeFind
/**
* Trim das informações no callback beforeFind
*
* @see ModelBehavior::beforeFind()
*/
public function beforeFind(Model $model, $query)
{
parent::beforeFind($model, $query);
$this->_Model = $model;
if (!isset($this->_disabledFor[$model->alias])) {
$this->_autoTrim($query['conditions']);
}
$this->_autoTrim();
return $query;
}