本文整理汇总了PHP中ModelCriteria::addClause方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::addClause方法的具体用法?PHP ModelCriteria::addClause怎么用?PHP ModelCriteria::addClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::addClause方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadByType
public function loadByType(&$model)
{
$C = new ModelCriteria();
$C->addClause(ModelCriteria::EQUALS, 'type', $model->type);
$models = self::select($model->modelName, $C);
if (count($models) > 0) {
$model = $models[0];
return TRUE;
}
return FALSE;
}
示例2: findRelatives
//.........这里部分代码省略.........
// Such relations are held as 1:M,1 relations internally so it'll be
// handled by the 1:M case below.
break;
/* 1:M */
/* 1:M */
case ModelRelation::ONE_TO_MANY:
// First, gather all the in-memory relatives attached to $this model.
// If $criteria has been specified then we also check that these models
// satisfy those criteria.
$cd = ModelRelation::ONE_TO_MANY;
$tm = $relation->getTargetModel();
$rr = $relation->getReference();
if (isset($this->relatives[$cd][$tm][$rr])) {
$collection = new ModelCollection($this->relatives[$cd][$tm][$rr]);
if ($criteria !== null) {
// TODO: ::applyTo() isn't implemented yet! so this will create an empty collection every time
$collection = $criteria->applyTo($collection);
}
} else {
$collection = new ModelCollection();
}
// If $this model is in the db then query the db to find all matching
// relatives and append them to the collection.
// TODO: Need to handle composite or NULL PKs
if ($this->isInDatabase()) {
// With no specific criteria to follow we'll load ALL relatives from
// persistent storage
$targetModelName = $relation->getTargetModel();
$targetModel = Model::create($targetModelName);
if ($criteria === null) {
$pkv = $this->{$relation->getNativeKey()};
//$this->getPrimaryKeyValue();
$c = new ModelCriteria();
$c->addClause(ModelCriteria::EQUALS, "`{$targetModel->getDbTableName()}`." . $targetModel->getForeignKey($this, $relation->getReference()), $pkv);
try {
$collection->append(ModelManager::select($targetModelName, $c));
} catch (Exception $e) {
}
} else {
$pkv = $this->{$relation->getNativeKey()};
//$this->getPrimaryKeyValue();
$criteria->addClause(ModelCriteria::EQUALS, "`{$targetModel->getDbTableName()}`." . $targetModel->getForeignKey($this, $relation->getReference()), $pkv);
$collection->append(ModelManager::select($targetModelName, $criteria));
}
}
// For recursive 1:M relationships we now need to load Models on the
// M:1 side of the relationship in order to establish a link between
// the loaded instance on the 1 and M sides, so don't break and instead
// pass through to the next switch case ...
if ($relation->isRecursive()) {
$relation = $relation->getInverseRelation();
$loadingTheInverse = true;
} else {
return $collection;
break;
}
/* M:1 */
/* M:1 */
case ModelRelation::MANY_TO_ONE:
// First, check if an in-memory model exists on the 1-side of this
// relationship
$cd = ModelRelation::MANY_TO_ONE;
$tm = $relation->getTargetModel();
$rr = $relation->getReference();
$col = new ModelCollection();
if (isset($this->relatives[$cd][$tm][$rr])) {
示例3: isDenied
public function isDenied($permissions, $resource, $ignoreInheritance = FALSE)
{
// Load resource from a given alias
$alias = $resource;
if (is_string($resource) && !($resource = $this->loadResourceByAlias($resource))) {
throw new BuanException("Could not find AclResource with an alias of '{$alias}'");
return FALSE;
}
// Convert $permissions to an array
if (!is_array($permissions)) {
$permissions = explode(",", preg_replace("/[^a-z0-9_\\-\\*,]/i", "", strtolower($permissions)));
}
$permissions = array_unique($permissions);
// Travel up through $resource and it's parent AclResources to find a
// usable AclEntry
$tmpEntry = Model::create('AclEntry');
$pAclResource = $resource;
while ($pAclResource !== NULL) {
// Load all AclEntry Models related to $pAclResource
$C = new ModelCriteria();
$C->addClause(ModelCriteria::EQUALS, $tmpEntry->getForeignKey($this->modelName), $this->id);
$pAclResource->loadRelatedModels('AclEntry', $C);
$entry = $pAclResource->getLinkingModel($this);
if ($entry !== NULL) {
// Wildcard permissions
if ($entry->pdeny == '*') {
return TRUE;
}
if ($entry->pallow == '*') {
return FALSE;
}
// All specified permissions are denied
$unknownDenyPerms = array_diff($permissions, explode(",", $entry->pdeny));
if (count($unknownDenyPerms) == 0) {
return TRUE;
} else {
// If any of the permissions are listed in the "pallow" column,
// then we need to return FALSE
$permissions = $unknownDenyPerms;
$unknownAllowPerms = array_diff($permissions, explode(",", $entry->pallow));
if (count($unknownAllowPerms) != count($permissions)) {
return FALSE;
}
}
}
// No AclEntry was found, so try $pAclResource's parent AclResource
if (!$ignoreInheritance) {
$pAclResource->loadRelatedModels('AclResource', NULL, ModelRelation::REF_CHILD);
$pAclResource = $pAclResource->getRelatedModels('AclResource', ModelRelation::REF_CHILD);
} else {
$pAclResource = NULL;
}
}
// If ALL the permissions are not yet satisfied, then start testing
// permissions on the parents $role
if (count($permissions) > 0 && !$ignoreInheritance) {
$rModel = $this->loadAndGetAclRole(NULL, ModelRelation::REF_CHILD);
foreach ($rModel as $rm) {
if ($rm->isDenied($permissions, $resource)) {
return TRUE;
}
}
return FALSE;
} else {
return FALSE;
}
}