当前位置: 首页>>代码示例>>PHP>>正文


PHP ModelCriteria::addClause方法代码示例

本文整理汇总了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;
 }
开发者ID:Nessworthy,项目名称:buan,代码行数:11,代码来源:AclTypeManager.php

示例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])) {
开发者ID:Nessworthy,项目名称:buan,代码行数:67,代码来源:Model.php

示例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;
     }
 }
开发者ID:Nessworthy,项目名称:buan,代码行数:67,代码来源:AclRoleModel.php


注:本文中的ModelCriteria::addClause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。