本文整理汇总了PHP中Datasource::replaceParametersInString方法的典型用法代码示例。如果您正苦于以下问题:PHP Datasource::replaceParametersInString方法的具体用法?PHP Datasource::replaceParametersInString怎么用?PHP Datasource::replaceParametersInString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datasource
的用法示例。
在下文中一共展示了Datasource::replaceParametersInString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render(Register $ParameterOutput, $joins = NULL, array $where = array(), $filter_operation_type = self::FILTER_AND)
{
$execute = true;
$result = new XMLDocument();
$result->appendChild($result->createElement($this->parameters()->{'root-element'}));
$root = $result->documentElement;
// Conditions
// If any one condtion returns true (that is, do not execute), the DS will not execute at all
if (is_array($this->parameters()->conditions)) {
foreach ($this->parameters()->conditions as $condition) {
if (preg_match('/:/', $condition['parameter'])) {
$c = Datasource::replaceParametersInString($condition['parameter'], $ParameterOutput);
} else {
$c = Datasource::resolveParameter($condition['parameter'], $ParameterOutput);
}
// Is Empty
if ($condition['logic'] == 'empty' && (is_null($c) || strlen($c) == 0)) {
$execute = false;
} elseif ($condition['logic'] == 'set' && !is_null($c)) {
$execute = false;
}
if ($execute !== true) {
return NULL;
}
}
}
// Grab the section
try {
$section = Section::loadFromHandle($this->parameters()->section);
} catch (SectionException $e) {
} catch (Exception $e) {
}
$pagination = (object) array('total-entries' => NULL, 'entries-per-page' => max(1, (int) self::replaceParametersInString($this->parameters()->limit, $ParameterOutput)), 'total-pages' => NULL, 'current-page' => max(1, (int) self::replaceParametersInString($this->parameters()->page, $ParameterOutput)));
$pagination->{'record-start'} = max(0, ($pagination->{'current-page'} - 1) * $pagination->{'entries-per-page'});
$order = $sort = NULL;
// Apply the Sorting & Direction
if ($this->parameters()->{'sort-order'} == 'random') {
$order = 'RAND()';
} else {
$sort = strtolower($this->parameters()->{'sort-order'}) == 'asc' ? 'ASC' : 'DESC';
// System Field
if (preg_match('/^system:/i', $this->parameters()->{'sort-field'})) {
switch (preg_replace('/^system:/i', NULL, $this->parameters()->{'sort-field'})) {
case 'id':
$order = "e.id {$sort}";
break;
case 'creation-date':
$order = "e.creation_date {$sort}";
break;
case 'modification-date':
$order = "e.modification_date {$sort}";
break;
}
} else {
$join = NULL;
$sort_field = $section->fetchFieldByHandle($this->parameters()->{'sort-field'});
if ($sort_field instanceof Field && $sort_field->isSortable() && method_exists($sort_field, "buildSortingQuery")) {
$sort_field->buildSortingQuery($join, $order);
$joins .= sprintf($join, $sort_field->section, $sort_field->{'element-name'});
$order = sprintf($order, $sort);
}
}
}
// Process Datasource Filters for each of the Fields
if (is_array($this->parameters()->filters) && !empty($this->parameters()->filters)) {
foreach ($this->parameters()->filters as $k => $filter) {
if ($filter['element-name'] == 'system:id') {
$filter_value = $this->prepareFilterValue($filter['value'], $ParameterOutput);
if (!is_array($filter_value)) {
continue;
}
$filter_value = array_map('intval', $filter_value);
if (empty($filter_value)) {
continue;
}
$where[] = sprintf("(e.id %s IN (%s))", $filter['type'] == 'is-not' ? 'NOT' : NULL, implode(',', $filter_value));
} else {
$field = $section->fetchFieldByHandle($filter['element-name']);
if ($field instanceof Field) {
$field->buildFilterQuery($filter, $joins, $where, $ParameterOutput);
}
}
}
}
// Escape percent symbold:
$where = array_map(create_function('$string', 'return str_replace(\'%\', \'%%\', $string);'), $where);
$query = sprintf('SELECT DISTINCT SQL_CALC_FOUND_ROWS e.*
FROM `tbl_entries` AS `e`
%1$s
WHERE `section` = "%2$s"
%3$s
ORDER BY %4$s
LIMIT %5$d, %6$d', $joins, $section->handle, is_array($where) && !empty($where) ? 'AND (' . implode($filter_operation_type == self::FILTER_AND ? ' AND ' : ' OR ', $where) . ')' : NULL, $order, $pagination->{'record-start'}, $pagination->{'entries-per-page'});
try {
$entries = Symphony::Database()->query($query, array($section->handle, $section->{'publish-order-handle'}), 'EntryResult');
if (isset($this->parameters()->{'append-pagination'}) && $this->parameters()->{'append-pagination'} === true) {
$pagination->{'total-entries'} = (int) Symphony::Database()->query("SELECT FOUND_ROWS() AS `total`")->current()->total;
$pagination->{'total-pages'} = (int) ceil($pagination->{'total-entries'} * (1 / $pagination->{'entries-per-page'}));
// Pagination Element
$root->appendChild(General::buildPaginationElement($result, $pagination->{'total-entries'}, $pagination->{'total-pages'}, $pagination->{'entries-per-page'}, $pagination->{'current-page'}));
//.........这里部分代码省略.........