本文整理汇总了PHP中modX::newQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::newQuery方法的具体用法?PHP modX::newQuery怎么用?PHP modX::newQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::newQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* Abstract method for routing GET requests without a primary key passed. Must be defined in your derivative
* controller. Handles fetching of collections of objects.
*
* @abstract
* @return array
*/
public function getList()
{
$this->getProperties();
$c = $this->modx->newQuery($this->classKey);
$c = $this->addSearchQuery($c);
$c = $this->prepareListQueryBeforeCount($c);
$total = $this->modx->getCount($this->classKey, $c);
$alias = !empty($this->classAlias) ? $this->classAlias : $this->classKey;
$c->select($this->modx->getSelectColumns($this->classKey, $alias));
$c = $this->prepareListQueryAfterCount($c);
$c->sortby($this->getProperty($this->getOption('propertySort', 'sort'), $this->defaultSortField), $this->getProperty($this->getOption('propertySortDir', 'dir'), $this->defaultSortDirection));
$limit = $this->getProperty($this->getOption('propertyLimit', 'limit'), $this->defaultLimit);
if (empty($limit)) {
$limit = $this->defaultLimit;
}
$c->limit($limit, $this->getProperty($this->getOption('propertyOffset', 'start'), $this->defaultOffset));
$objects = $this->modx->getCollection($this->classKey, $c);
if (empty($objects)) {
$objects = array();
}
$list = array();
/** @var xPDOObject $object */
foreach ($objects as $object) {
$list[] = $this->prepareListObject($object);
}
return $this->collection($list, $total);
}
示例2: loadSettingsFromNamespace
/**
* Loads all system settings that start with the configured namespace.
*
* @return array
*/
public function loadSettingsFromNamespace()
{
$ns = $this->namespace;
$config = array();
$corePath = $this->modx->getOption($ns . '.core_path', null, MODX_CORE_PATH . 'components/' . $ns . '/');
$config['core_path'] = $corePath;
$config['templates_path'] = $corePath . 'templates/';
$config['controllers_path'] = $corePath . 'controllers/';
$config['model_path'] = $corePath . 'model/';
$config['processors_path'] = $corePath . 'processors/';
$config['elements_path'] = $corePath . 'elements/';
$assetsUrl = $this->modx->getOption($ns . '.assets_url', null, MODX_ASSETS_URL . 'components/' . $ns . '/');
$config['assets_url'] = $assetsUrl;
$config['connector_url'] = $assetsUrl . ' connector.php';
$c = $this->modx->newQuery('modSystemSetting');
$c->where(array('key:LIKE' => $ns . '.%'));
$c->limit(0);
/** @var \modSystemSetting[] $iterator */
$iterator = $this->modx->getIterator('modSystemSetting', $c);
foreach ($iterator as $setting) {
$key = $setting->get('key');
$key = substr($key, strlen($ns) + 1);
$config[$key] = $setting->get('value');
}
return $config;
}
示例3: getList
/**
* Get all names of template from provider
* @return array|\Iterator
*/
public function getList()
{
$c = $this->modx->newQuery('modTemplate');
$c->select('templatename');
if ($c->prepare() && $c->stmt->execute()) {
return $c->stmt->fetchAll(PDO::FETCH_COLUMN);
}
return array();
}
示例4: getProfitResourceGroups
/** @inheritdoc} */
public function getProfitResourceGroups($id = 0)
{
$groups = array();
$key = $this->MlmSystem->namespace;
$options = array('cache_key' => $key . '/profit/group/' . __CLASS__ . '/resource/' . $id, 'cacheTime' => 0);
if ($resource = $this->modx->getObject('modResource', array('id' => $id)) and !($groups = $this->MlmSystem->getCache($options))) {
$ids = $this->modx->getParentIds($id, 10, array('context' => $resource->get('context_key')));
$ids[] = $id;
$ids = array_unique($ids);
$q = $this->modx->newQuery('modResourceGroupResource', array('document:IN' => $ids));
$q->leftJoin('MlmSystemProfitGroup', 'MlmSystemProfitGroup', 'MlmSystemProfitGroup.group = modResourceGroupResource.document_group');
$q->where(array('MlmSystemProfitGroup.class' => 'modResourceGroup'));
$q->select('document_group,profit');
$q->sortby('profit');
$q->groupby('MlmSystemProfitGroup.group');
$tstart = microtime(true);
if ($q->prepare() && $q->stmt->execute()) {
$this->modx->queryTime += microtime(true) - $tstart;
$this->modx->executedQueries++;
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
$groups[$row['document_group']] = $row['profit'];
}
}
$this->MlmSystem->setCache($groups, $options);
}
return $groups;
}
示例5: getStats
function getStats()
{
$output = '';
$q_status = $this->modx->newQuery('msOrderStatus', array('active' => 1));
$q_status->select('id,name,color');
if ($q_status->prepare() && $q_status->stmt->execute()) {
while ($row = $q_status->stmt->fetch(PDO::FETCH_ASSOC)) {
//$output[$row['id']] = $row;
$output['total_counts'][$row['id']] = array('name' => $row['name'], 'color' => $row['color'], 'count_orders' => $this->modx->getCount('msOrder', array('status' => $row['id'])));
}
}
$q_stats_month = $this->modx->newQuery('msOrder');
$q_stats_month->select('status,`createdon`, month(`createdon`) AS `order_month`, count(*) AS `order_count`, SUM(cart_cost) AS order_cost');
$q_stats_month->groupby('month(`createdon`), status');
$q_stats_month->sortby('createdon', ASC);
if ($q_stats_month->prepare() && $q_stats_month->stmt->execute()) {
$output['cart_cost'] = 0;
$output['cart_count'] = 0;
while ($row = $q_stats_month->stmt->fetch(PDO::FETCH_ASSOC)) {
$date = date_parse($row['createdon']);
$output['stats_month'][$date['year'] . '-' . $date['month']][$row['status']] = array('total_cost' => $row['order_cost'], 'count_orders' => $row['order_count'], 'status' => $row['status']);
$output['cart_cost'] += $row['order_cost'];
$output['cart_count'] += $row['order_count'];
}
$output['cart_cost'] = number_format($output['cart_cost'], 2, ',', ' ');
$output['users_count'] = $this->modx->getCount('modUser', array('active' => 1, 'primary_group' => 0));
}
return $output;
}
示例6: conversationsMap
/**
* Create conversations map
*
* @return array|false False if cache is off
*/
public function conversationsMap()
{
/**
* If disabled caching return False
*/
if (!$this->modx->getCacheManager()) {
return false;
}
/**
* If a map is present in the cache, then just return it
*/
$map = $this->modx->cacheManager->get('conversations_map', array(xPDO::OPT_CACHE_KEY => 'modxtalks'));
if ($map) {
return $map;
}
/**
* If the map is not in the cache, we all topics from the database and build the map
*/
$map = array();
$c = $this->modx->newQuery('modxTalksConversation');
$c->select(array('id', 'rid', 'conversation'));
if ($c->prepare() && $c->stmt->execute()) {
$conversations = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($conversations as $c) {
$map[$c['rid']][$c['id']] = $c['conversation'];
}
$this->modx->cacheManager->set('conversations_map', $map, 0, array(xPDO::OPT_CACHE_KEY => 'modxtalks'));
}
return $map;
}
示例7: fetchPosts
/**
* Fetch all posts for this thread
*
* @param mixed $post A reference to a disPost or ID of disPost to start the posts from
* @param array $options An array of options for sorting, limiting and display
* @return array
*/
public function fetchPosts($post = false, array $options = array())
{
$response = array();
$c = $this->xpdo->newQuery('disPost');
$c->innerJoin('disThread', 'Thread');
$c->where(array('thread' => $this->get('id')));
$response['total'] = $this->xpdo->discuss->controller->getPostCount('disThread', $this->get('id'));
$flat = $this->xpdo->getOption('flat', $options, true);
$limit = $this->xpdo->getOption('limit', $options, (int) $this->xpdo->getOption('discuss.post_per_page', $options, 10));
$start = $this->xpdo->getOption('start', $options, 0);
if ($flat) {
$sortBy = $this->xpdo->getOption('sortBy', $options, 'createdon');
$sortDir = $this->xpdo->getOption('sortDir', $options, 'ASC');
$c->sortby($this->xpdo->getSelectColumns('disPost', 'disPost', '', array($sortBy)), $sortDir);
if (empty($_REQUEST['print'])) {
$c->limit($limit, $start);
}
} else {
$c->sortby($this->xpdo->getSelectColumns('disPost', 'disPost', '', array('rank')), 'ASC');
}
if (!empty($post)) {
if (!is_object($post)) {
$post = $this->xpdo->getObject('disPost', $post);
}
if ($post) {
$c->where(array('disPost.createdon:>=' => $post->get('createdon')));
}
}
$c->bindGraph('{"Author":{"PrimaryDiscussGroup":{},"PrimaryGroup":{}},"EditedBy":{}}');
//$c->prepare();
//$cacheKey = 'discuss/thread/'.$thread->get('id').'/'.md5($c->toSql());
$response['results'] = $this->xpdo->getCollectionGraph('disPost', '{"Author":{"PrimaryDiscussGroup":{},"PrimaryGroup":{}},"EditedBy":{}}', $c);
return $response;
}
示例8: addAliases
/**
* @param $string
*
* @return mixed
*/
public function addAliases($string)
{
$string = mb_strtoupper(str_ireplace('ё', 'е', $this->modx->stripTags($string)), 'UTF-8');
$string = preg_replace('#\\[.*\\]#isU', '', $string);
$pcre = $this->config['split_words'];
$words = preg_split($pcre, $string, -1, PREG_SPLIT_NO_EMPTY);
$words = array_unique($words);
$forms = $this->getBaseForms($words, false);
$q = $this->modx->newQuery('mseAlias', array('word:IN' => array_merge($words, array_keys($forms))));
$q->select('word,alias,replace');
$tstart = microtime(true);
if ($q->prepare() && $q->stmt->execute()) {
$this->modx->queryTime += microtime(true) - $tstart;
$this->modx->executedQueries++;
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['replace']) {
$all = current($this->getAllForms($row['word']));
$all[] = $row['word'];
foreach ($all as $word) {
$key = array_search(mb_strtolower($word), $words);
if ($key !== false) {
$words[$key] = $row['alias'];
}
}
} else {
$words[] = $row['alias'];
}
}
}
$words = array_unique($words);
return implode(' ', $words);
}
示例9: getPostCount
/**
* Get total post count
* @param string $class
* @param int $id
* return int
*/
public function getPostCount($className = 'disBoard', $id = 0)
{
$c = $this->modx->newQuery($className);
if ($className == 'disBoard') {
if (!$id) {
$c->select(array('post_count' => "SUM({$this->modx->escape('disBoard')}.{$this->modx->escape('total_posts')})"));
} else {
$c->select(array($this->modx->getSelectColumns('disBoard', 'disBoard', '', array('post_count'))));
$c->where(array('id' => $id));
}
} else {
if ($className == 'disThread') {
$c->select(array($this->modx->getSelectColumns('disThread', 'disThread', '', array('replies'))));
$c->where(array('id' => $id));
}
}
if ($stmt = $c->prepare()) {
if ($stmt->execute()) {
if ($results = $stmt->fetchAll(PDO::FETCH_COLUMN)) {
$count = reset($results);
$count = intval($count);
}
}
}
return !$results ? 0 : $className == 'disBoard' ? $count : $count + 1;
// +1 for original thread start post
}
示例10: checkResource
/**
* Verification of resource status
*
* @param int $id
*
* @return bool|int
*/
public function checkResource($id = 0)
{
$tmp = array();
if (empty($this->pdoTools->config['showHidden'])) {
$tmp['hidemenu'] = 0;
}
if (empty($this->pdoTools->config['showUnpublished'])) {
$tmp['published'] = 1;
}
if (!empty($this->pdoTools->config['hideUnsearchable'])) {
$tmp['searchable'] = 1;
}
if (!empty($tmp)) {
$tmp['id'] = $id;
$q = $this->modx->newQuery('modResource', $tmp);
$q->select('id');
$tstart = microtime(true);
if ($q->prepare() && $q->stmt->execute()) {
$this->modx->queryTime += microtime(true) - $tstart;
$this->modx->executedQueries++;
$res = $q->stmt->fetch(PDO::FETCH_COLUMN);
return (bool) $res;
}
}
return true;
}
示例11: refreshURIs
/**
* Refresh Resource URI fields for children of the specified parent.
*
* @static
* @param modX &$modx A reference to a valid modX instance.
* @param int $parent The id of a Resource parent to start from (default is 0, the root)
* @param array $options An array of various options for the method:
* - resetOverrides: if true, Resources with uri_override set to true will be included
* - contexts: an optional array of context keys to limit the refresh scope
* @return void
*/
public static function refreshURIs(modX &$modx, $parent = 0, array $options = array())
{
$resetOverrides = array_key_exists('resetOverrides', $options) ? (bool) $options['resetOverrides'] : false;
$contexts = array_key_exists('contexts', $options) ? explode(',', $options['contexts']) : null;
$criteria = $modx->newQuery('linguaSiteContent');
$criteria->where(array('lang_id' => $options['lang_id'], 'parent' => $parent));
if (!$resetOverrides) {
$criteria->where(array('uri_override' => false));
}
if (!empty($contexts)) {
$criteria->where(array('context_key:IN' => $contexts));
}
/** @var Resource $resource */
$resources = $modx->getIterator('linguaSiteContent', $criteria);
foreach ($resources as $resource) {
$resource->set('refreshURIs', true);
if ($resetOverrides) {
$resource->set('uri_override', false);
}
if (!$resource->get('uri_override')) {
$resource->set('uri', '');
}
$resource->save();
}
}
示例12: save
/**
* Overrides xPDOObject::save to handle closure table edits.
*
* @param boolean $cacheFlag
* @return boolean
*/
public function save($cacheFlag = null)
{
$new = $this->isNew();
if ($new) {
if (!$this->get('createdon')) {
$this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
}
$ip = $this->get('ip');
if (empty($ip) && !empty($_SERVER['REMOTE_ADDR'])) {
$this->set('ip', $_SERVER['REMOTE_ADDR']);
}
}
$saved = parent::save($cacheFlag);
if ($saved && $new) {
$id = $this->get('id');
$parent = $this->get('parent');
/* create self closure */
$cl = $this->xpdo->newObject('quipCommentClosure');
$cl->set('ancestor', $id);
$cl->set('descendant', $id);
if ($cl->save() === false) {
$this->remove();
return false;
}
/* create closures and calculate rank */
$c = $this->xpdo->newQuery('quipCommentClosure');
$c->where(array('descendant' => $parent, 'ancestor:!=' => 0));
$c->sortby('depth', 'DESC');
$gparents = $this->xpdo->getCollection('quipCommentClosure', $c);
$cgps = count($gparents);
$gps = array();
$i = $cgps;
/** @var quipCommentClosure $gparent */
foreach ($gparents as $gparent) {
$gps[] = str_pad($gparent->get('ancestor'), 10, '0', STR_PAD_LEFT);
/** @var quipCommentClosure $obj */
$obj = $this->xpdo->newObject('quipCommentClosure');
$obj->set('ancestor', $gparent->get('ancestor'));
$obj->set('descendant', $id);
$obj->set('depth', $i);
$obj->save();
$i--;
}
$gps[] = str_pad($id, 10, '0', STR_PAD_LEFT);
/* add self closure too */
/* add root closure */
/** @var quipCommentClosure $cl */
$cl = $this->xpdo->newObject('quipCommentClosure');
$cl->set('ancestor', 0);
$cl->set('descendant', $id);
$cl->set('depth', $cgps);
$cl->save();
/* set rank */
$rank = implode('-', $gps);
$this->set('rank', $rank);
$this->save();
}
return $saved;
}
示例13: 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;
}
示例14: getClientStatus
/** @inheritdoc} */
public function getClientStatus()
{
$statuses = array();
$q = $this->modx->newQuery('MlmSystemStatus', array('class' => 'MlmSystemClient', 'active' => 1));
$q->sortby('rank', 'ASC');
$q->select('id');
if ($q->prepare() && $q->stmt->execute()) {
$statuses = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
return $statuses;
}
示例15: simpleSearch
/**
* Search and return array with resources that matched for LIKE search
*
* @param $query
*
* @return array
*/
public function simpleSearch($query)
{
$string = preg_replace('/[^_-а-яёa-z0-9\\s\\.\\/]+/iu', ' ', $this->modx->stripTags($query));
$result = array();
$q = $this->modx->newQuery('mseIntro');
$q->select('`resource`');
$q->where(array('intro:LIKE' => '%' . $string . '%'));
if ($q->prepare() && $q->stmt->execute()) {
$result = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
return $result;
}