本文整理汇总了PHP中modX::query方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::query方法的具体用法?PHP modX::query怎么用?PHP modX::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collectUserCaches
/**
* Get the cache of Users and User Groups from the Discuss database
* @return boolean
*/
protected function collectUserCaches()
{
$this->log('Collecting User cache...');
$userTable = $this->modx->getTableName('disUser');
$stmt = $this->modx->query('SELECT id,username,integrated_id FROM ' . $userTable . ' ORDER BY username ASC');
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$this->memberCache[$row['integrated_id']] = $row['id'];
$this->memberNameCache[$row['integrated_id']] = $row['username'];
}
$stmt->closeCursor();
}
$this->log('Collecting User Group cache...');
$userGroupTable = $this->modx->getTableName('disUserGroupProfile');
$stmt = $this->modx->query('SELECT id,name,integrated_id FROM ' . $userGroupTable . ' ORDER BY name ASC');
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$this->memberGroupCache[$row['integrated_id']] = $row['id'];
}
$stmt->closeCursor();
}
return true;
}
示例2: getnum
/**
* Return current number of order
*
* @return string
*/
public function getnum()
{
$table = $this->modx->getTableName('msOrder');
$cur = date('ym');
$sql = $this->modx->query("SELECT `num` FROM {$table} WHERE `num` LIKE '{$cur}%' ORDER BY `id` DESC LIMIT 1");
$num = $sql->fetch(PDO::FETCH_COLUMN);
if (empty($num)) {
$num = date('ym') . '/0';
}
$num = explode('/', $num);
$num = $cur . '/' . ($num[1] + 1);
return $num;
}
示例3: 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');
}
}
}
}
}
示例4: getResourceBypass
function getResourceBypass(modX &$modx, $criteria)
{
$resource = null;
$c = $modx->newQuery('modResource');
$c->select(array('id', 'published'));
$c->where($criteria);
$c->prepare();
$sql = $c->toSql();
$stmt = $modx->query($sql);
if ($stmt && $stmt instanceof PDOStatement) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
$resource = $row;
}
$stmt->closeCursor();
}
return $resource;
}
示例5: processBindings
/**
* Process bindings assigned to a template variable.
*
* @access public
* @param string $value The value specified from the binding.
* @param integer $resourceId The resource in which the TV is assigned.
* @param boolean $preProcess Whether or not to process certain bindings.
* @return string The processed value.
*/
public function processBindings($value = '', $resourceId = 0, $preProcess = true)
{
$bdata = $this->getBindingDataFromValue($value);
if (empty($bdata['cmd'])) {
return $value;
}
$modx =& $this->xpdo;
if (empty($modx->resource)) {
if (!empty($resourceId)) {
$modx->resource = $modx->getObject('modResource', $resourceId);
}
if (empty($modx->resource) || empty($resourceId)) {
$modx->resource = $modx->newObject('modResource');
$modx->resource->set('id', 0);
}
}
$cmd = $bdata['cmd'];
$param = !empty($bdata['param']) ? $bdata['param'] : null;
switch ($cmd) {
case 'FILE':
if ($preProcess) {
$output = $this->processFileBinding($param);
}
break;
case 'CHUNK':
/* retrieve a chunk and process it's content */
if ($preProcess) {
$output = $this->xpdo->getChunk($param);
}
break;
case 'RESOURCE':
case 'DOCUMENT':
/* retrieve a document and process it's content */
if ($preProcess) {
$query = $this->xpdo->newQuery('modResource', array('id' => (int) $param, 'deleted' => false));
$query->select('content');
if ($query->prepare() && $query->stmt->execute()) {
$output = $query->stmt->fetch(PDO::FETCH_COLUMN);
} else {
$output = 'Unable to locate resource ' . $param;
}
}
break;
case 'SELECT':
/* selects a record from the cms database */
if ($preProcess) {
$dbtags = array();
if ($modx->resource && $modx->resource instanceof modResource) {
$dbtags = $modx->resource->toArray();
}
$dbtags['DBASE'] = $this->xpdo->getOption('dbname');
$dbtags['PREFIX'] = $this->xpdo->getOption('table_prefix');
foreach ($dbtags as $key => $pValue) {
$param = str_replace('[[+' . $key . ']]', $pValue, $param);
}
$stmt = $this->xpdo->query('SELECT ' . $param);
if ($stmt && $stmt instanceof PDOStatement) {
$data = '';
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$col = '';
if (isset($row[1])) {
$col = $row[0] . '==' . $row[1];
} else {
$col = $row[0];
}
$data .= (!empty($data) ? '||' : '') . $col;
}
$stmt->closeCursor();
}
$output = $data;
}
break;
case 'EVAL':
/* evaluates text as php codes return the results */
if ($preProcess) {
$output = eval($param);
}
break;
case 'INHERIT':
if ($preProcess) {
$output = $this->processInheritBinding($param, $resourceId);
} else {
$output = $value;
}
break;
case 'DIRECTORY':
$path = $this->xpdo->getOption('base_path') . $param;
if (substr($path, -1, 1) != '/') {
$path .= '/';
}
if (!is_dir($path)) {
//.........这里部分代码省略.........
示例6: foreach
/** @var xPDOObject $object */
foreach ($modx->getIterator($class, $classCriteria) as $object) {
if ($package->put($object, $classAttributes)) {
$instances++;
} else {
$modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey()));
}
}
$modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
}
/* collect table names from classes and grab any additional tables/data not listed */
$coreTables = array();
foreach ($classes as $class) {
$coreTables[$class] = $modx->quote($modx->literal($modx->getTableName($class)));
}
$stmt = $modx->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '{$modxDatabase}' AND TABLE_NAME NOT IN (" . implode(',', $coreTables) . ")");
$extraTables = $stmt->fetchAll(PDO::FETCH_COLUMN);
if (is_array($extraTables) && !empty($extraTables)) {
$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR . 'model/', true, true);
$excludeExtraTablePrefix = isset($vaporOptions['excludeExtraTablePrefix']) && is_array($vaporOptions['excludeExtraTablePrefix']) ? $vaporOptions['excludeExtraTablePrefix'] : array();
$excludeExtraTables = isset($vaporOptions['excludeExtraTables']) && is_array($vaporOptions['excludeExtraTables']) ? $vaporOptions['excludeExtraTables'] : array();
foreach ($extraTables as $extraTable) {
if (in_array($extraTable, $excludeExtraTables)) {
continue;
}
if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
set_time_limit(0);
}
$instances = 0;
$object = array();
$attributes = array('vehicle_package' => 'vapor', 'vehicle_class' => 'vaporVehicle');
示例7: merge
/**
* Merge another user into this account
*
* @param disUser $oldUser
* @return boolean
*/
public function merge(disUser &$oldUser)
{
$success = true;
$user = $this->getOne('User');
if (empty($user)) {
return false;
}
$oldModxUser = $oldUser->getOne('User');
if (empty($oldModxUser)) {
return false;
}
$this->xpdo->beginTransaction();
/* merge post count */
$posts = $user->get('posts');
$posts = $posts + $oldUser->get('posts');
$this->set('posts', $posts);
/* merge ignore boards */
$ibs = $this->get('ignore_boards');
$ibs = explode(',', $ibs);
$oldIbs = $oldUser->get('ignore_boards');
$oldIbs = explode(',', $oldIbs);
$ibs = array_merge($oldIbs, $ibs);
$this->set('ignore_boards', implode(',', $ibs));
/* merge signature if needed */
$signature = $this->get('signature');
$oldSignature = $oldUser->get('signature');
if (empty($signature) && !empty($oldSignature)) {
$this->set('signature', $oldSignature);
}
/* merge title if needed */
$title = $this->get('title');
$oldTitle = $oldUser->get('title');
if (empty($title) && !empty($oldTitle)) {
$this->set('title', $oldTitle);
}
/* merge primary_group if needed */
$pg = $this->get('primary_group');
$oldPg = $oldUser->get('primary_group');
if (empty($pg) && !empty($oldPg)) {
$this->set('primary_group', $oldPg);
}
$this->set('integrated_id', $oldUser->get('integrated_id'));
$this->set('synced', true);
$this->set('syncedat', $this->xpdo->discuss->now());
$this->save();
/* grant old usergroups to this user */
$oldUserGroups = $this->xpdo->getCollection('modUserGroupMember', array('member' => $oldModxUser->get('id')));
$ugs = array();
foreach ($oldUserGroups as $oldUserGroup) {
$ugs[] = $oldUserGroup->get('user_group');
}
$ugs = array_unique($ugs);
foreach ($ugs as $ug) {
$user->joinGroup($ug);
}
/* merge in posts, change authors */
$sql = 'UPDATE ' . $this->xpdo->getTableName('disPost') . '
SET `author` = ' . $this->get('id') . '
WHERE `author` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
$sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . '
SET `author_first` = ' . $this->get('id') . '
WHERE `author_first` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
$sql = 'UPDATE ' . $this->xpdo->getTableName('disThread') . '
SET `author_last` = ' . $this->get('id') . '
WHERE `author_last` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
/* merge in disThreadRead */
$sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadRead') . '
SET `user` = ' . $this->get('id') . '
WHERE `user` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
/* merge in disThreadUser */
$sql = 'UPDATE ' . $this->xpdo->getTableName('disThreadUser') . '
SET `user` = ' . $this->get('id') . '
WHERE `user` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
/* merge in disUserFriend */
$sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . '
SET `user` = ' . $this->get('id') . '
WHERE `user` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
$sql = 'UPDATE ' . $this->xpdo->getTableName('disUserFriend') . '
SET `friend` = ' . $this->get('id') . '
WHERE `friend` = ' . $oldUser->get('id') . '
';
$this->xpdo->query($sql);
//.........这里部分代码省略.........
示例8: prepare_modx_upgrade
/**
* Logout all users, clear the cache, make sure config file is writable
*
*/
function prepare_modx_upgrade($data)
{
$core_path = $data['core_path'];
chmod($core_path . 'config/config.inc.php', DIR_PERMS);
// This might brick if the install isn't working.
require_once $data['base_path'] . 'index.php';
$modx = new modX();
$modx->initialize('mgr');
// See http://tracker.modx.com/issues/9916
$sessionTable = $modx->getTableName('modSession');
$modx->query("TRUNCATE TABLE {$sessionTable}");
@$modx->cacheManager->refresh();
}
示例9: foreach
{
$cc = 0;
foreach ($_SESSION as $key => $value) {
if (substr($key, 0, 3) == 'pro') {
$cc = $cc + $value;
}
//echo $key." ".$value." ".substr($key,0,3);
}
return $cc;
}
if (isset($_GET['action'])) {
if ($_GET['action'] == 'product_photo') {
?>
<img src="<?php
$sql_img = "select * from s_prices pr\n\njoin s_images i\n on i.price_id=pr.id\n\nwhere (pr.id=" . mysql_escape_string($_GET['id']) . ")and(i.mainimg=1);\n\n";
foreach ($modx->query($sql_img) as $rowIMain) {
echo upload_dir . $rowIMain['filename'];
}
?>
">
<div class="product_photo_small">
<?php
$sql_img = "select * from s_prices pr\n\njoin s_images i\n on i.price_id=pr.id\n\nwhere (pr.id=" . mysql_escape_string($_GET['id']) . ")and(i.mainimg=0);\n\n";
foreach ($modx->query($sql_img) as $rowIMain) {
?>
<div>
<img src="<?php
echo upload_dir . $rowIMain['filename'];
?>
示例10: COUNT
ini_set('memory_limit', '1024M');
set_time_limit(0);
@ob_end_clean();
echo '<pre>';
/* fix num_topics */
$sql = 'SELECT
disBoard.id,
disBoard.name,
disBoard.num_topics,
(
SELECT COUNT(`Threads`.`id`) FROM ' . $modx->getTableName('disThread') . ' AS `Threads`
WHERE `Threads`.`board` = `disBoard`.`id`
) AS `real_count`
FROM ' . $modx->getTableName('disBoard') . ' `disBoard`
ORDER BY `disBoard`.`map` ASC';
$stmt = $modx->query($sql);
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if (!empty($row['real_count']) && $row['real_count'] != $row['num_topics']) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Setting "' . $row['name'] . '" to ' . $row['real_count'] . ' from ' . $row['num_topics']);
$modx->exec('UPDATE ' . $modx->getTableName('disBoard') . '
SET `num_topics` = ' . $row['real_count'] . '
WHERE `id` = ' . $row['id']);
}
}
$stmt->closeCursor();
}
/* fix num_replies */
/* fix total_posts */
$mtime = microtime();
$mtime = explode(" ", $mtime);
示例11:
$user->set('active', 1);
$user->set('password', $password);
$profile->set('email', $email);
$profile->set('internalKey', 0);
$user->addOne($profile, 'Profile');
// save user
if (!$user->save()) {
print 'ERROR: Could not save user.';
}
}
// Add User to a User Group
$Member = $modx->newObject('modUserGroupMember');
$Member->set('user_group', $usergroup->get('id'));
$Member->set('member', $user->get('id'));
// Grant the user a role within that group
$Member->set('role', 1);
$Member->set('rank', 0);
if (!$Member->save()) {
print 'ERROR: Could not add User to User Group';
exit;
}
}
}
// Flush Permissions ??
// Clear Cache
$modx->query("TRUNCATE TABLE " . $modx->getTableName("modSession"));
$modx->cacheManager->refresh();
$login_id = $page1->get('id');
$url = $modx->makeUrl($login_id, '', '', 'full');
print 'SUCCESS. You can log in at <a href="' . $url . '">Login Page</a>';
/*EOF*/
示例12: process
//.........这里部分代码省略.........
$classAttributes['resolve'][] = array('type' => 'file', 'source' => $source, 'target' => "return {$target};");
$classAttributes['resolve'][] = array('type' => 'php', 'source' => VAPOR_DIR . 'scripts/resolve.media_source.php', 'target' => $sourceBasePath, 'targetRelative' => false, 'targetPrepend' => "return dirname(MODX_BASE_PATH) . '/sources/';");
}
}
}
if ($package->put($object, $classAttributes)) {
$instances++;
} else {
$modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
}
}
$modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
continue 2;
default:
break;
}
/** @var xPDOObject $object */
foreach ($modx->getIterator($class, $classCriteria) as $object) {
if ($package->put($object, $classAttributes)) {
$instances++;
} else {
$modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
}
}
$modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
}
/* collect table names from classes and grab any additional tables/data not listed */
$coreTables = array();
$extraTables = array();
foreach ($classes as $class) {
$coreTables[$class] = $modx->quote($modx->literal($modx->getTableName($class)));
}
if ($coreTables) {
$stmt = $modx->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '{$modxDatabase}' AND TABLE_NAME NOT IN (" . implode(',', $coreTables) . ")");
$extraTables = $stmt->fetchAll(PDO::FETCH_COLUMN);
}
if (is_array($extraTables) && !empty($extraTables)) {
//$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR . 'model/', true, true);
$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR, true, true);
$excludeExtraTablePrefix = isset($vaporOptions['excludeExtraTablePrefix']) && is_array($vaporOptions['excludeExtraTablePrefix']) ? $vaporOptions['excludeExtraTablePrefix'] : array();
$excludeExtraTables = isset($vaporOptions['excludeExtraTables']) && is_array($vaporOptions['excludeExtraTables']) ? $vaporOptions['excludeExtraTables'] : array();
foreach ($extraTables as $extraTable) {
if (in_array($extraTable, $excludeExtraTables)) {
continue;
}
if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
set_time_limit(0);
}
$instances = 0;
$object = array();
$attributes = array('vehicle_package' => 'vapor', 'vehicle_class' => 'vaporVehicle');
/* remove modx table_prefix if table starts with it */
$extraTableName = $extraTable;
if (!empty($modxTablePrefix) && strpos($extraTableName, $modxTablePrefix) === 0) {
$extraTableName = substr($extraTableName, strlen($modxTablePrefix));
$addTablePrefix = true;
} elseif (!empty($modxTablePrefix) || in_array($extraTableName, $excludeExtraTablePrefix)) {
$addTablePrefix = false;
} else {
$addTablePrefix = true;
}
$object['tableName'] = $extraTableName;
$modx->log(modX::LOG_LEVEL_INFO, "Extracting non-core table {$extraTableName}");
/* generate the CREATE TABLE statement */
$stmt = $modx->query("SHOW CREATE TABLE {$modx->escape($extraTable)}");
$resultSet = $stmt->fetch(PDO::FETCH_NUM);