本文整理汇总了PHP中xPDO::newQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::newQuery方法的具体用法?PHP xPDO::newQuery怎么用?PHP xPDO::newQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::newQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listProfiles
public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
$objCollection= array ();
/* query for profiles */
$c = $xpdo->newQuery('modFormCustomizationProfile');
$c->select(array(
$xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile'),
));
$c->where($criteria,null,2);// also log issue in remine to look at this usage of where()
$count = $xpdo->getCount('modFormCustomizationProfile',$c);
foreach($sort as $field=> $dir) {
$c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir);
}
if ((int) $limit > 0) {
$c->limit((int) $limit, (int) $offset);
}
$rows= xPDOObject :: _loadRows($xpdo, 'modFormCustomizationProfile', $c);
$rowsArray = $rows->fetchAll(PDO::FETCH_ASSOC);
$rows->closeCursor();
foreach($rowsArray as $row) {
$objCollection[] = $xpdo->call('modFormCustomizationProfile', '_loadInstance', array(&$xpdo, 'modFormCustomizationProfile', $c, $row));
}
unset($row, $rowsArray);
return array(
'count'=> $count,
'collection'=> $objCollection
);
}
示例2: listEvents
public static function listEvents(xPDO &$xpdo, $plugin, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
$c = $xpdo->newQuery('modEvent');
$count = $xpdo->getCount('modEvent',$c);
$c->select(array(
'modEvent.*',
'IF(ISNULL(modPluginEvent.pluginid),0,1) AS enabled',
'modPluginEvent.priority AS priority',
'modPluginEvent.propertyset AS propertyset',
));
$c->leftJoin('modPluginEvent','modPluginEvent','
modPluginEvent.event = modEvent.name
AND modPluginEvent.pluginid = '.$plugin.'
');
$c->where($criteria);
foreach($sort as $field=> $dir) {
$c->sortby($xpdo->getSelectColumns('modEvent','modEvent','',array($field)),$dir);
}
if ((int) $limit > 0) {
$c->limit((int) $limit, (int) $offset);
}
return array(
'count'=> $count,
'collection'=> $xpdo->getCollection('modEvent',$c)
);
}
示例3: listSettings
public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
/* build query */
$c = $xpdo->newQuery('modSystemSetting');
$c->select(array(
$xpdo->getSelectColumns('modSystemSetting','modSystemSetting'),
));
$c->select(array(
'name_trans' => 'Entry.value',
'description_trans' => 'Description.value',
));
$c->leftJoin('modLexiconEntry','Entry',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')}) = Entry.name");
$c->leftJoin('modLexiconEntry','Description',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')},'_desc') = Description.name");
$c->where($criteria);
$count = $xpdo->getCount('modSystemSetting',$c);
$c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array('area')),'ASC');
foreach($sort as $field=> $dir) {
$c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array($field)),$dir);
}
if ((int) $limit > 0) {
$c->limit((int) $limit, (int) $offset);
}
$c->prepare();
return array(
'count'=> $count,
'collection'=> $xpdo->getCollection('modSystemSetting',$c)
);
}
示例4: loadOptions
public static function loadOptions(xPDO &$xpdo, $product)
{
$c = $xpdo->newQuery('msProductOption');
$c->rightJoin('msOption', 'msOption', 'msProductOption.key=msOption.key');
$c->leftJoin('modCategory', 'Category', 'Category.id=msOption.category');
$c->where(array('msProductOption.product_id' => $product));
$c->select($xpdo->getSelectColumns('msOption', 'msOption'));
$c->select($xpdo->getSelectColumns('msProductOption', 'msProductOption', '', array('key'), true));
$c->select('`Category`.`category` AS `category_name`');
$data = array();
$tstart = microtime(true);
if ($c->prepare() && $c->stmt->execute()) {
$xpdo->queryTime += microtime(true) - $tstart;
$xpdo->executedQueries++;
while ($option = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
if (isset($data[$option['key']])) {
// если опция повторяется, ее значение будет массивом
if (!is_array($data[$option['key']])) {
$data[$option['key']] = array($data[$option['key']]);
}
$data[$option['key']][] = $option['value'];
} else {
// одиночная опция останется строкой
$data[$option['key']] = $option['value'];
}
foreach ($option as $key => $value) {
$data[$option['key'] . '.' . $key] = $value;
}
}
}
return $data;
}
示例5: 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;
}
示例6: _loadFieldData
/**
* Load persistent data from the source for the field(s) indicated.
*
* @access protected
* @param string|array $fields A field name or array of field names to load
* from the data source.
*/
protected function _loadFieldData($fields) {
if (!is_array($fields)) $fields= array($fields);
else $fields= array_values($fields);
$criteria= $this->xpdo->newQuery($this->_class, $this->getPrimaryKey());
$criteria->select($fields);
if ($rows= xPDOObject :: _loadRows($this->xpdo, $this->_class, $criteria)) {
$row= reset($rows);
$this->fromArray($row, '', false, true);
$this->_lazy= array_diff($this->_lazy, $fields);
}
}
示例7: _loadFieldData
/**
* Load persistent data from the source for the field(s) indicated.
*
* @access protected
* @param string|array $fields A field name or array of field names to load
* from the data source.
*/
protected function _loadFieldData($fields)
{
if (!is_array($fields)) {
$fields = array($fields);
} else {
$fields = array_values($fields);
}
$criteria = $this->xpdo->newQuery($this->_class, $this->getPrimaryKey());
$criteria->select($fields);
if ($rows = xPDOObject::_loadRows($this->xpdo, $this->_class, $criteria)) {
$row = $rows->fetch(PDO::FETCH_ASSOC);
$rows->closeCursor();
$this->fromArray($row, '', false, true);
$this->_lazy = array_diff($this->_lazy, $fields);
}
}
示例8: listSettings
public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0)
{
$c = $xpdo->newQuery('modUserGroupSetting');
$c->select(array($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting'), 'Entry.value AS name_trans', 'Description.value AS description_trans'));
$c->leftJoin('modLexiconEntry', 'Entry', "'setting_' + modUserGroupSetting.[key] = Entry.name");
$c->leftJoin('modLexiconEntry', 'Description', "'setting_' + modUserGroupSetting.[key] + '_desc' = Description.name");
$c->where($criteria);
$count = $xpdo->getCount('modUserGroupSetting', $c);
$c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array('area')), 'ASC');
foreach ($sort as $field => $dir) {
$c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array($field)), $dir);
}
if ((int) $limit > 0) {
$c->limit((int) $limit, (int) $offset);
}
return array('count' => $count, 'collection' => $xpdo->getCollection('modUserGroupSetting', $c));
}
示例9: findResolution
/**
* Search for package to satisfy a dependency.
*
* @param string $package The name of the dependent package.
* @param string $constraint The version constraint the package must satisfy.
* @param modTransportProvider|null $provider A reference which is set to the
* modTransportProvider which satisfies the dependency.
*
* @return array|bool The metadata for the package version which satisfies the dependency, or FALSE.
*/
public function findResolution($package, $constraint, &$provider = null)
{
$resolution = false;
$conditions = array('active' => true);
switch (strtolower($package)) {
case 'php':
/* you must resolve php dependencies manually */
$this->xpdo->log(xPDO::LOG_LEVEL_WARN, "PHP version dependencies must be resolved manually", '', __METHOD__, __FILE__, __LINE__);
break;
case 'modx':
case 'revo':
case 'revolution':
/* resolve core dependencies manually for now */
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "MODX core version dependencies must be resolved manually", '', __METHOD__, __FILE__, __LINE__);
break;
default:
/* TODO: scan for local packages to satisfy dependency */
/* see if current provider can satisfy dependency */
/** @var modTransportProvider $provider */
$provider = $this->Provider;
if ($provider) {
$resolution = $provider->latest($package, $constraint);
}
/* loop through active providers if all else fails */
if ($resolution === false) {
$query = $this->xpdo->newQuery('transport.modTransportProvider', $conditions);
$query->sortby('priority', 'ASC');
/** @var modTransportProvider $p */
foreach ($this->xpdo->getIterator('transport.modTransportProvider', $query) as $p) {
$resolution = $p->latest($package, $constraint);
if ($resolution) {
$provider = $p;
break;
}
}
}
if ($resolution === false) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package to satisfy dependency {$package} @ {$constraint} from your currently active providers", '', __METHOD__, __FILE__, __LINE__);
}
break;
}
return $resolution;
}
示例10: leaveGroup
/**
* Removes the User from the specified User Group.
*
* @access public
* @param mixed $groupId Either the name or ID of the User Group to join.
* @return boolean True if successful.
*/
public function leaveGroup($groupId)
{
$left = false;
$c = $this->xpdo->newQuery('modUserGroupMember');
$c->innerJoin('modUserGroup', 'UserGroup');
$c->where(array('member' => $this->get('id')));
$fk = is_string($groupId) ? 'name' : 'id';
$c->where(array('member' => $this->get('id'), 'UserGroup.' . $fk => $groupId));
/** @var modUserGroupMember $member */
$member = $this->xpdo->getObject('modUserGroupMember', $c);
if (empty($member)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'User could not leave group with key "' . $groupId . '" because the User was not a part of that group.');
} else {
$left = $member->remove();
if (!$left) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'An unknown error occurred preventing removing the User from the User Group.');
} else {
unset($_SESSION["modx.user.{$this->get('id')}.userGroupNames"], $_SESSION["modx.user.{$this->get('id')}.userGroups"]);
}
}
return $left;
}
示例11: fetchList
/**
* Fetch a full list of boards for the forum with restrictions based on current user
*
* @static
* @param xPDO $modx
* @param bool $ignoreBoards
* @return array
*/
public static function fetchList(xPDO &$modx, $ignoreBoards = true)
{
$c = array('ignore_boards' => $ignoreBoards);
$cacheKey = 'discuss/board/user/' . $modx->discuss->user->get('id') . '/select-options-' . md5(serialize($c));
$boards = $modx->cacheManager->get($cacheKey);
if (empty($boards)) {
$c = $modx->newQuery('disBoard');
$c->innerJoin('disBoardClosure', 'Descendants');
$c->leftJoin('disBoardUserGroup', 'UserGroups');
$c->innerJoin('disCategory', 'Category');
$groups = $modx->discuss->user->getUserGroups();
if (!$modx->discuss->user->isAdmin()) {
if (!empty($groups)) {
/* restrict boards by user group if applicable */
$g = array('UserGroups.usergroup:IN' => $groups);
$g['OR:UserGroups.usergroup:IS'] = null;
$where[] = $g;
$c->andCondition($where, null, 2);
} else {
$c->where(array('UserGroups.usergroup:IS' => null));
}
}
if ($modx->discuss->user->isLoggedIn && $ignoreBoards) {
$ignoreBoards = $modx->discuss->user->get('ignore_boards');
if (!empty($ignoreBoards)) {
$c->where(array('id:NOT IN' => explode(',', $ignoreBoards)));
}
}
$c->select($modx->getSelectColumns('disBoard', 'disBoard'));
$c->select(array('Descendants.depth AS depth', 'Category.name AS category_name'));
$c->where(array('Descendants.ancestor' => 0));
$c->sortby('Category.rank', 'ASC');
$c->sortby('disBoard.map', 'ASC');
$c->groupby('disBoard.id');
$boardObjects = $modx->getCollection('disBoard', $c);
/** @var disBoard $board */
foreach ($boardObjects as $board) {
$boards[] = $board->toArray('', false, true);
}
if (!empty($boards)) {
$modx->cacheManager->set($cacheKey, $boards, $modx->getOption('discuss.cache_time', null, 3600));
}
}
return $boards;
}
示例12: clearCache
/**
* Clear the caches of all sources
* @param array $options
* @return void
*/
public function clearCache(array $options = array())
{
/** @var modCacheManager $cacheManager */
$cacheManager = $this->xpdo->getCacheManager();
if (empty($cacheManager)) {
return;
}
$c = $this->xpdo->newQuery('modContext');
$c->select($this->xpdo->escape('key'));
$options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources');
$options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options));
$options[xPDO::OPT_CACHE_FORMAT] = (int) $this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));
$options[xPDO::OPT_CACHE_ATTEMPTS] = (int) $this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));
$options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (int) $this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));
if ($c->prepare() && $c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row && !empty($row['key'])) {
$cacheManager->delete($row['key'] . '/source', $options);
}
}
}
}
示例13: fetchActive
/**
* Fetch a list of active users in the forum
*
* @static
* @param xPDO $modx A reference to the modX object
* @param int $timeAgo If set, will grab within X seconds
* @param int $limit Limit results to this number
* @param int $start Start at this index
* @return array A response array of active users
*/
public static function fetchActive(xPDO &$modx, $timeAgo = 0, $limit = 0, $start = 0)
{
$response = array();
$c = $modx->newQuery('disUser');
$c->innerJoin('disSession', 'Session', $modx->getSelectColumns('disSession', 'Session', '', array('user')) . ' = ' . $modx->getSelectColumns('disUser', 'disUser', '', array('id')));
$c->innerJoin('modUser', 'User');
$c->leftJoin('disUserGroupProfile', 'PrimaryDiscussGroup');
if (!empty($timeAgo)) {
$c->where(array('Session.access:>=' => $timeAgo));
}
if (!empty($limit)) {
$c->limit($limit, $start);
}
$response['total'] = $modx->getCount('disUser', $c);
$c->select(array('disUser.id', 'disUser.username', 'PrimaryDiscussGroup.color'));
$c->groupby('disUser.id');
$c->sortby('Session.access', 'ASC');
$response['results'] = $modx->getCollection('disUser', $c);
return $response;
}
示例14: fetchNewReplies
/**
* Fetch all new replies in threads that the active user is a participant in
*
* @static
*
* @param xPDO $modx A reference to the modX instance
* @param string $sortBy The column to sort by
* @param string $sortDir The direction to sort
* @param int $limit The # of threads to limit
* @param int $start The index to start by
* @param boolean $sinceLastLogin
* @param bool $countOnly Set to true to only return count, not run the actual query
*
* @return array An array in results/total format
*/
public static function fetchNewReplies(xPDO &$modx, $sortBy = 'post_last_on', $sortDir = 'DESC', $limit = 20, $start = 0, $sinceLastLogin = false, $countOnly = false)
{
$response = array();
$c = $modx->newQuery('disThread');
$c->innerJoin('disBoard', 'Board');
$c->innerJoin('disUser', 'LastAuthor');
$c->innerJoin('disThreadParticipant', 'Participants', array("{$modx->escape('Participants')}.{$modx->escape('user')} = {$modx->discuss->user->get('id')}", "{$modx->escape('Participants')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
$groups = $modx->discuss->user->getUserGroups();
/* usergroup protection */
if ($modx->discuss->user->isLoggedIn) {
if ($sinceLastLogin) {
$lastLogin = $modx->discuss->user->get('last_login');
if (!empty($lastLogin)) {
$c->where(array('disThread.post_last_on:>=' => is_int($lastLogin) ? $lastLogin : strtotime($lastLogin)));
}
}
$ignoreBoards = $modx->discuss->user->get('ignore_boards');
if (!empty($ignoreBoards)) {
$c->where(array('Board.id:NOT IN' => explode(',', $ignoreBoards)));
}
}
$cRead = $modx->newQuery('disThreadRead');
$cRead->select(array($modx->getSelectColumns('disThreadRead', 'disThreadRead', '', array('thread'))));
$cRead->where(array('user' => $modx->discuss->user->get('id'), "{$modx->escape('disThreadRead')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
$cRead->prepare();
$c->WHERE(array("{$modx->escape('disThread')}.{$modx->escape('id')} NOT IN ({$cRead->toSQL()})"));
if (!$modx->discuss->user->isAdmin()) {
$c->leftJoin('disBoardUserGroup', 'UserGroups', 'Board.id = UserGroups.board');
if (!empty($groups)) {
/* restrict boards by user group if applicable */
$g = array('UserGroups.usergroup:IN' => $groups);
$g['OR:UserGroups.usergroup:IS'] = null;
$where[] = $g;
$c->andCondition($where, null, 2);
} else {
$c->where(array('UserGroups.usergroup:IS' => null));
}
}
$daysAgo = time() - $modx->getOption('discuss.new_replies_threshold', null, 14) * 24 * 60 * 60;
$c->where(array('Board.status:>' => disBoard::STATUS_INACTIVE, 'author_last:!=' => $modx->discuss->user->get('id')));
/* ignore spam/recycle bin boards */
$spamBoard = $modx->getOption('discuss.spam_bucket_board', null, false);
if (!empty($spamBoard)) {
$c->where(array('Board.id:!=' => $spamBoard));
}
$trashBoard = $modx->getOption('discuss.recycle_bin_board', null, false);
if (!empty($trashBoard)) {
$c->where(array('Board.id:!=' => $trashBoard));
}
$response['total'] = $modx->getCount('disThread', $c);
$c->select($modx->getSelectColumns('disThread', 'disThread'));
$c->select(array('board_name' => "{$modx->escape('Board')}.{$modx->escape('name')}", 'thread' => "{$modx->escape('disThread')}.{$modx->escape('id')}", 'author_username' => 'LastAuthor.username', 'post_id' => "{$modx->escape('disThread')}.{$modx->escape('post_last')}", "FROM_UNIXTIME({$modx->escape('disThread')}.{$modx->escape('post_last_on')}) AS {$modx->escape('createdon')}", 'author' => "{$modx->escape('disThread')}.{$modx->escape('author_last')}", 'last_post_replies' => "{$modx->escape('disThread')}.{$modx->escape('replies')}"));
$c->sortby($sortBy, $sortDir);
$c->limit($limit, $start);
if (!$countOnly) {
$response['results'] = $modx->getCollection('disThread', $c);
}
return $response;
}
示例15: foreach
$category_tv->fromArray($data);
$category_tv->save();
}
$category_tv_id = $category_tv->get('id');
foreach ($templates as $template_name => $template_id) {
if ($template_id) {
$tv_link = $modx->newObject('modTemplateVarTemplate');
$tv_link->set('templateid', $template_id);
$tv_link->set('tmplvarid', $category_tv_id);
$tv_link->set('rank', 1);
$tv_link->save();
}
}
}
// set up all wp postmeta options up as template variables
$criteria = $wp->newQuery('Postmeta');
$criteria->groupby('meta_key');
$criteria->sortby('meta_key', 'ASC');
$postmetas = $wp->getCollection('Postmeta', $criteria);
foreach ($postmetas as $meta) {
// create each meta tv
$meta_tv = $modx->newObject('modTemplateVar');
$data = array('name' => $meta->get('meta_key'), 'caption' => $meta->get('meta_key'), 'type' => 'textarea');
$meta_tv->fromArray($data);
$meta_tv->save();
$meta_tv_id = $meta_tv->get('id');
$meta_tv_ids[$meta->get('meta_key')] = $meta_tv->get('id');
// link the postmeta tvs to the templates
foreach ($templates as $template_name => $template_id) {
if ($template_id) {
$tv_link = $modx->newObject('modTemplateVarTemplate');