本文整理汇总了PHP中Finder::optionMerge方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::optionMerge方法的具体用法?PHP Finder::optionMerge怎么用?PHP Finder::optionMerge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Finder
的用法示例。
在下文中一共展示了Finder::optionMerge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Will get the desired objects as long as they're configured correctly
*
* i.e. var $hasMany = array('Class Name' => 'fieldName in that table');
* e.g. var $hasMany = array('Expense' => 'categoryID'); // would go in the ExpenseCategory object
*
* Has And Belongs To Many - $habtm - objects we're joined to via record_record or a join table
*
* Special option keys for $additionalFinderOpts:
* 'associations' - BOOL default false - if you only want the association objects and not the actual objects themselves pass this in
* *NOTE* applies only to record_record
*/
public function get($getKey, $additionalFinderOpts = NULL)
{
$className = ucfirst($getKey);
$internalVarName = self::INTERNAL_VAR_PREFIX . $className;
if (!$this->{$internalVarName} || !is_null($additionalFinderOpts)) {
// has many
if (array_key_exists($className, $this->hasMany)) {
if (!$this->id) {
return array();
}
$classNameToFind = $this->hasMany[$className]['className'] ? $this->hasMany[$className]['className'] : $className;
$opts = array('where' => $this->hasMany[$className]['field'] . " = '" . $this->id . "'");
if ($this->hasMany[$className]['condition']) {
$opts['where'] .= ' AND ' . $this->hasMany[$className]['condition'];
}
if (is_null($additionalFinderOpts)) {
$opts['order'] = $this->hasMany[$className]['order'];
if ($this->hasMany[$className]['finderOpts']) {
$opts = Finder::optionMerge($opts, $this->hasMany[$className]['finderOpts']);
}
$this->{$internalVarName} = Finder::factory($classNameToFind)->findAll($opts);
// cache this object in the found object
foreach ($this->{$internalVarName} as $foundObj) {
if (array_key_exists($this->getClass(), $foundObj->belongsTo)) {
$foundObj->set($this->getClass(), $this);
}
}
} else {
$opts = Finder::optionMerge($opts, $additionalFinderOpts);
return Finder::factory($classNameToFind)->findAll($opts);
}
// belongs to
} elseif (array_key_exists($className, $this->belongsTo)) {
// this is a special keyword for tables with: className and recordID
if ($className == 'Object') {
$this->{$internalVarName} = Finder::factory($this->className)->find($this->recordID);
} else {
$foreignKey = $this->belongsTo[$className]['field'];
$classNameToFind = $this->belongsTo[$className]['className'] ? $this->belongsTo[$className]['className'] : $className;
$this->{$internalVarName} = Finder::factory($classNameToFind)->find($this->{$foreignKey});
}
// has and belongs to many
} elseif (array_key_exists($className, $this->habtm)) {
if (!$this->id()) {
return array();
}
// via the Associator
if ($this->habtm[$className]['table'] == 'record_record') {
$classNameToFind = $this->habtm[$className]['className'] ? $this->habtm[$className]['className'] : $className;
$associator = new Associator();
$objectFinderOpts = array();
if ($this->habtm[$className]['condition']) {
$opts['where'] = $this->habtm[$className]['condition'];
}
if ($this->habtm[$className]['objectFinderOpts']) {
$objectFinderOpts = Finder::optionMerge($opts, $this->habtm[$className]['objectFinderOpts']);
}
// return only the associations, not the objects themselves
if ($additionalFinderOpts['associations']) {
$refObj = new ReflectionClass(ucfirst($className));
return $associator->findAssociations($refObj->getStaticPropertyValue('tableName'), $this->getTableName(), $this->id());
}
if ($additionalFinderOpts) {
$objectFinderOpts = Finder::optionMerge($additionalFinderOpts, $objectFinderOpts);
}
$this->{$internalVarName} = $associator->findAllObjectsForClassWithTableAndRecord($classNameToFind, $this->getTableName(), $this->id(), $opts, $objectFinderOpts);
// TODO: any join table
} else {
$joinTable = $this->habtm[$className]['table'];
$associationForeignKey = $this->habtm[$className]['associationForeignKey'];
$foreignKey = $this->habtm[$className]['foreignKey'];
$ro = new ReflectionClass($className);
$instance = $ro->newInstance();
$tableName = $instance->getTableName();
$finder = new Finder($instance);
// more generic join tables
if (isset($this->habtm[$className]['typeKey']) && isset($this->habtm[$className]['typeValue'])) {
$typeKey = $this->habtm[$className]['typeKey'];
$typeValue = $this->habtm[$className]['typeValue'];
$additionalAnd = " AND jt." . $typeKey . "='{$typeValue}' ";
}
$sql = "SELECT activeRecord.* FROM {$joinTable} AS jt, {$tableName} as activeRecord\n\t\t\t\t\t\t\t\tWHERE jt." . $associationForeignKey . "=activeRecord.id\n\t\t\t\t\t\t\t\tAND activeRecord.siteID='" . $this->siteID . "'\n\t\t\t\t\t\t\t\tAND jt." . $foreignKey . "='" . $this->id . "'\n\t\t\t\t\t\t\t\t{$additionalAnd}";
$this->{$internalVarName} = $finder->findAllWithSql($sql, $additionalFinderOpts);
}
// try extras for ease
} elseif ($this->hasExtra($getKey)) {
return $this->getExtras($getKey);
// error
//.........这里部分代码省略.........