本文整理汇总了PHP中modX::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::prepare方法的具体用法?PHP modX::prepare怎么用?PHP modX::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::prepare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTagged
/**
* Gets matching resources by tags. This is adapted function from miniShop1 for backward compatibility
* @deprecated
*
* @param array $tags Tags for search
* @param int $only_ids Return only ids of matched resources
* @param int $strict 0 - goods must have at least one specified tag
* 1 - goods must have all specified tags, but can have more
* 2 - goods must have exactly the same tags.
* @return array $ids Or array with resources with data and tags
*/
function getTagged($tags = array(), $strict = 0, $only_ids = 0)
{
if (!is_array($tags)) {
$tags = explode(',', $tags);
}
$q = $this->modx->newQuery('msProductOption', array('key' => 'tags', 'value:IN' => $tags));
$q->select('product_id');
$ids = array();
if ($q->prepare() && $q->stmt->execute()) {
$ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
$ids = array_unique($ids);
// If needed only ids of not strictly mathed items - return.
if (!$strict && $only_ids) {
return $ids;
}
// Filtering ids
$count = count($tags);
/* @var PDOStatement $stmt*/
if ($strict) {
foreach ($ids as $key => $product_id) {
if ($strict > 1) {
$sql = "SELECT COUNT(*) FROM {$this->modx->getTableName('msProductOption')} WHERE `product_id` = {$product_id} AND `key` = 'tags';";
$stmt = $this->modx->prepare($sql);
$stmt->execute();
if ($stmt->fetch(PDO::FETCH_COLUMN) != $count) {
unset($ids[$key]);
continue;
}
}
foreach ($tags as $tag) {
$sql = "SELECT COUNT(`product_id`) FROM {$this->modx->getTableName('msProductOption')} WHERE `product_id` = {$product_id} AND `key` = 'tags' AND `value` = '{$tag}';";
$stmt = $this->modx->prepare($sql);
$stmt->execute();
if (!$stmt->fetch(PDO::FETCH_COLUMN)) {
unset($ids[$key]);
break;
}
}
}
}
// Return strictly ids, if needed
$ids = array_unique($ids);
if ($only_ids) {
return $ids;
}
// Process results
$data = array();
foreach ($ids as $id) {
if (!$only_ids) {
if ($res = $this->modx->getObject('msProduct', $id)) {
$data[$id] = $res->toArray();
}
}
}
return $data;
}
示例2: createTree
/** Create tree */
public static function createTree($total, $lvls = 3)
{
self::$modx->query("DELETE FROM " . self::$ClientTable);
self::$modx->query("ALTER TABLE " . self::$ClientTable . " AUTO_INCREMENT=1");
// distribution of elements on the levels of nesting
$num = $total;
$lvlsArr = array();
for ($i = $lvls; $i > 0; $i--) {
if ($i == 1) {
$limit = $num;
} else {
$limit = ceil($num * 0.6);
$num -= $limit;
}
$lvlsArr[$i] = $limit;
}
$sql = "INSERT INTO " . self::$ClientTable . " (`id`, `parent`) VALUES (:id, :parent)";
$stmt = self::$modx->prepare($sql);
$pArr = array();
$k = 0;
for ($i = 1; $i <= $lvls; $i++) {
$limit = $lvlsArr[$i];
echo $i . ' level: ' . $limit . ' pcs.<br>';
while ($limit--) {
$k = $k + 1;
$prev = NULL;
if ($i > 1) {
$c = count($pArr[$i - 1]) - 1;
$prev = $pArr[$i - 1][mt_rand(0, $c)];
} else {
$c = 0;
$prev = 0;
}
if ($stmt instanceof PDOStatement) {
$stmt->bindValue(':id', $k);
$stmt->bindValue(':parent', $prev);
if ($stmt->execute()) {
$pArr[$i][] = $k;
//$this->modx->lastInsertId();
} else {
throw new Exception('Error add');
}
}
}
}
}