protected function getResults(xPDOQuery &$c) { $list = array(); $this->currentIndex = 0; if ($c->prepare()) { if ($c->stmt->execute()) { while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) { $object_id = $row['object_id']; if (empty($list[$object_id])) { $list[$object_id] = $row; $list[$object_id]['tvs'] = array(); $this->currentIndex++; } if (!empty($row['tv_name'])) { $list[$object_id]['tvs'][$row['tv_name']] = array('tv_id' => $row['tv_id'], 'caption' => $row['tv_caption'], 'category' => $row['tv_category'], 'value_id' => $row['tv_value_id'], 'value' => $row['tv_value']); } } } else { if ($c->stmt->errorCode() !== "00000") { $this->modx->log(xPDO::LOG_LEVEL_ERROR, __CLASS__); $this->modx->log(xPDO::LOG_LEVEL_ERROR, print_r($c->stmt->errorInfo(), true)); $this->modx->log(xPDO::LOG_LEVEL_ERROR, $c->toSQL()); } } } return $list; }
/** * @param xPDOQuery $c * * @return xPDOQuery */ public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('modMediaSource', 'Source'); $c->leftJoin($this->classKey, 'Thumb', "`{$this->classKey}`.`id` = `Thumb`.`parent`"); $c->groupby($this->classKey . '.id'); $c->select('`Source`.`name` as `source_name`'); $c->select('`Thumb`.`url` as `thumbnail`'); $c->where(array('resource_id' => $this->getProperty('resource_id'))); $parent = $this->getProperty('parent'); if ($parent !== false) { $c->where(array('parent' => $parent)); } $query = trim($this->getProperty('query')); if (!empty($query)) { $c->where(array('file:LIKE' => "%{$query}%", 'OR:name:LIKE' => "%{$query}%", 'OR:alt:LIKE' => "%{$query}%", 'OR:description:LIKE' => "%{$query}%", 'OR:add:LIKE' => "%{$query}%")); } $tags = array_map('trim', explode(',', $this->getProperty('tags'))); if (!empty($tags[0])) { $tags = implode("','", $tags); $c->innerJoin('msResourceFileTag', 'Tag', "`{$this->classKey}`.`id` = `Tag`.`file_id` AND `Tag`.`tag` IN ('" . $tags . "')"); $c->groupby($this->classKey . '.id'); $c->prepare(); $this->modx->log(1, $c->toSQL()); } return $c; }
/** * Set parameters and prepare query * * @return PDOStatement */ public function prepareQuery() { if (!empty($this->config['limit'])) { $time = microtime(true); $this->query->limit($this->config['limit'], $this->config['offset']); $this->addTime('Limited to <b>' . $this->config['limit'] . '</b>, offset <b>' . $this->config['offset'] . '</b>', microtime(true) - $time); } return $this->query->prepare(); }
/** * Set parameters and prepare query * * @return PDOStatement */ public function prepareQuery() { if ($limit = (int) $this->config['limit']) { $offset = (int) $this->config['offset']; $time = microtime(true); $this->query->limit($limit, $offset); $this->addTime('Limited to <b>' . $limit . '</b>, offset <b>' . $offset . '</b>', microtime(true) - $time); } return $this->query->prepare(); }
protected function countTotal($className, xPDOQuery &$query) { if (!$query->prepare()) { return false; } $sql = "SELECT count(*) as count FROM (" . $query->toSQL() . ") as t;"; if (!($stmt = $this->modx->prepare($sql)) or !$stmt->execute()) { return false; } return current((array) $stmt->fetch(PDO::FETCH_NUM)); }
protected function getResults(xPDOQuery &$c) { $list = array(); $this->currentIndex = 0; if ($c->prepare() && $c->stmt->execute()) { while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) { $object_id = $row['object_id']; if (empty($list[$object_id])) { $list[$object_id] = $row; $this->currentIndex++; } } } return $list; }
/** * */ public function rewindOriginal() { $this->index = 0; if (!empty($this->stmt)) { $this->stmt->closeCursor(); } $this->stmt = $this->criteria->prepare(); $tstart = microtime(true); if ($this->stmt && $this->stmt->execute()) { $this->xpdo->queryTime += microtime(true) - $tstart; $this->xpdo->executedQueries++; $this->fetch(); } elseif ($this->stmt) { $this->xpdo->queryTime += microtime(true) - $tstart; $this->xpdo->executedQueries++; } }
public function prepareQueryBeforeCount(xPDOQuery $c) { $form = $this->getProperty('form'); if (!empty($form)) { $c->andCondition(array('form' => $form)); } $context_key = $this->getProperty('context_key'); if (!empty($context_key)) { $c->andCondition(array('context_key' => $context_key)); } $startDate = $this->getProperty('startDate'); if ($startDate != '') { $c->andCondition(array('date:>' => strtotime($startDate . ' 00:00:00'))); } $endDate = $this->getProperty('endDate'); if ($endDate != '') { $c->andCondition(array('date:<' => strtotime($endDate . ' 23:59:59'))); } $c->prepare(); return $c; }
/** * Returns select statement for easy reading * * @access public * @param xPDOQuery $query The query to print * @return string The select statement * @author Coroico <*****@*****.**> */ public function niceQuery(xPDOQuery $query = null) { $searched = array("SELECT", "GROUP_CONCAT", "LEFT JOIN", "INNER JOIN", "EXISTS", "LIMIT", "FROM", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "OR", "AND", "IFNULL", "ON", "MATCH", "AGAINST", "COUNT"); $replace = array(" \r\nSELECT", " \r\nGROUP_CONCAT", " \r\nLEFT JOIN", " \r\nINNER JOIN", " \r\nEXISTS", " \r\nLIMIT", " \r\nFROM", " \r\nWHERE", " \r\nGROUP BY", " \r\nHAVING", " ORDER BY", " \r\nOR", " \r\nAND", " \r\nIFNULL", " \r\nON", " \r\nMATCH", " \r\nAGAINST", " \r\nCOUNT"); $output = ''; if (isset($query)) { $query->prepare(); $output = str_replace($searched, $replace, " " . $query->toSQL()); } return $output; }
public function prepareQueryAfterCount(xPDOQuery $c) { $c->prepare(); $this->modx->log(modX::LOG_LEVEL_ERROR, $c->toSql()); return $c; }
/** * Returns select statement for easy reading. * * @param xPDOQuery $query The query to print * * @return string The select statement * * @author Coroico <*****@*****.**> */ public function niceQuery(xPDOQuery $query = null) { $searched = array('SELECT', 'GROUP_CONCAT', 'LEFT JOIN', 'INNER JOIN', 'EXISTS', 'LIMIT', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'OR', 'AND', 'IFNULL', 'ON', 'MATCH', 'AGAINST', 'COUNT'); $replace = array(" \r\nSELECT", " \r\nGROUP_CONCAT", " \r\nLEFT JOIN", " \r\nINNER JOIN", " \r\nEXISTS", " \r\nLIMIT", " \r\nFROM", " \r\nWHERE", " \r\nGROUP BY", " \r\nHAVING", ' ORDER BY', " \r\nOR", " \r\nAND", " \r\nIFNULL", " \r\nON", " \r\nMATCH", " \r\nAGAINST", " \r\nCOUNT"); $output = ''; if (isset($query)) { $query->prepare(); $output = str_replace($searched, $replace, ' ' . $query->toSQL()); } return $output; }