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


PHP Propel::getReadConnection方法代码示例

本文整理汇总了PHP中Propel\Runtime\Propel::getReadConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::getReadConnection方法的具体用法?PHP Propel::getReadConnection怎么用?PHP Propel::getReadConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Runtime\Propel的用法示例。


在下文中一共展示了Propel::getReadConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRules

 /**
  *
  * Mode table:
  *
  *  0 all
  *  1 list
  *  2 view
  *  3 add
  *  4 update
  *  5 delete
  *
  * @static
  *
  * @param        $objectKey
  * @param  int $mode
  *
  * @param integer|null $targetType
  * @param integer|null $targetId
  *
  * @return mixed
  */
 public function getRules($objectKey, $mode = 1, $targetType = ACL::TARGET_TYPE_USER, $targetId = null)
 {
     $objectKey = Objects::normalizeObjectKey($objectKey);
     //normalize input. default is user
     $targetType = ACL::TARGET_TYPE_GROUP === $targetType ? ACL::TARGET_TYPE_GROUP : ACL::TARGET_TYPE_USER;
     $user = null;
     if ($targetType === ACL::TARGET_TYPE_USER) {
         if (!$targetId) {
             $user = $this->pageStack->getUser();
         } else {
             $user = UserQuery::create()->findPk($targetId);
         }
     }
     if (ACL::TARGET_TYPE_USER === $targetType) {
         if ($user) {
             $targetId = $user->getId();
             $inGroups = $user->getGroupIdsArray();
         } else {
             //no user found, so we check against guest
             $targetId = 0;
             $inGroups = [0];
         }
     } else {
         $inGroups = [(string) $targetId];
     }
     $cacheKey = '';
     if ($this->getCaching()) {
         $cacheKey = md5($targetType . '.' . $targetId . '.' . implode(',', $inGroups) . '.' . $objectKey . '.' . $mode);
         $cached = $this->cacher->getDistributedCache('core/acl/rules/' . $cacheKey);
         if (null !== $cached) {
             return $cached;
         }
     }
     $mode += 0;
     $data = array($objectKey, $mode);
     $targets = array();
     //group is always checked. If no user found, $inGroups is 0, which means it checks against Guest group.
     $targets[] = "( target_type = 1 AND target_id IN (?))";
     $data[] = implode(', ', $inGroups);
     if (ACL::TARGET_TYPE_USER === $targetType) {
         //if user type, we include additionally all user rules
         $targets[] = "( target_type = 0 AND target_id = ?)";
         if ($user) {
             $data[] = $user->getId();
         } else {
             //no user found, so we check against guest
             $data[] = 0;
         }
     }
     //now it gets dirty. A bit more complicated query, so we do it directly with PDO.
     $con = Propel::getReadConnection('default');
     $targets = implode(' OR ', $targets);
     $query = "\n                SELECT constraint_type, constraint_code, mode, access, sub, fields\n                FROM system_acl\n                WHERE\n                object = ? AND\n                (mode = ? OR mode = 0) AND\n                (\n                    {$targets}\n                )\n                ORDER BY prio DESC\n        ";
     $stmt = $con->prepare($query);
     $stmt->execute($data);
     $rules = array();
     while ($rule = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $rule['mode'] = (int) $rule['mode'];
         $rule['access'] = (int) $rule['access'];
         $rule['sub'] = (bool) $rule['sub'];
         $rule['constraint_type'] = (int) $rule['constraint_type'];
         if ($rule['fields'] && substr($rule['fields'], 0, 1) === '{') {
             $rule['fields'] = json_decode($rule['fields'], true);
         }
         if ($rule['constraint_type'] === ACL::CONSTRAINT_CONDITION && substr($rule['constraint_code'], 0, 1) === '[') {
             $rule['constraint_code'] = json_decode($rule['constraint_code'], true);
         }
         $rules[] = $rule;
     }
     if ($this->getCaching()) {
         $this->cacher->setDistributedCache('core/acl/rules/' . $cacheKey, $rules);
         return $rules;
     } else {
         return $rules;
     }
 }
开发者ID:jarves,项目名称:jarves,代码行数:97,代码来源:ACL.php

示例2: getTotalResultCountBySql

 private function getTotalResultCountBySql($sql)
 {
     $config = Helper::getConfig();
     $tableReference = $config['repository']['tableReference'];
     $search = array_keys($tableReference);
     $replace = array_values($tableReference);
     $sql = str_replace($search, $replace, $sql);
     $con = Propel::getReadConnection($config['database']['connectionName']);
     $stmt = $con->query($sql);
     return $stmt->count();
 }
开发者ID:arkanmgerges,项目名称:tasker,代码行数:11,代码来源:Task.php


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