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


PHP modX::prepare方法代码示例

本文整理汇总了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;
 }
开发者ID:bendasvadim,项目名称:miniShop2,代码行数:68,代码来源:minishop2.class.php

示例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');
                 }
             }
         }
     }
 }
开发者ID:vgrish,项目名称:mlmsystem,代码行数:47,代码来源:systempaths.class.php


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