本文整理汇总了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;
}
}
示例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();
}