本文整理汇总了PHP中modX::getCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::getCollection方法的具体用法?PHP modX::getCollection怎么用?PHP modX::getCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::getCollection方法的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: buildBreadcrumbs
/**
* Build the breadcrumb trail for this thread
*
* @param array $defaultTrail
* @param boolean $showTitle
* @return array
*/
public function buildBreadcrumbs($defaultTrail = array(), $showTitle = false)
{
$c = $this->xpdo->newQuery('disBoard');
$c->innerJoin('disBoardClosure', 'Ancestors');
$c->where(array('Ancestors.descendant' => $this->get('board')));
$c->sortby('Ancestors.depth', 'DESC');
$ancestors = $this->xpdo->getCollection('disBoard', $c);
$idx = 0;
$total = count($ancestors);
$trail = empty($defaultTrail) ? array(array('url' => $this->xpdo->discuss->request->makeUrl(), 'text' => $this->xpdo->getOption('discuss.forum_title'), 'last' => $total == 0)) : $defaultTrail;
$category = false;
/** @var disBoardClosure $ancestor */
foreach ($ancestors as $ancestor) {
if (empty($category)) {
$category = $ancestor->getOne('Category');
if ($category) {
$trail[] = array('url' => $this->xpdo->discuss->request->makeUrl('', array('type' => 'category', 'category' => $category->get('id'))), 'text' => $category->get('name'), 'last' => false);
}
}
$trail[] = array('url' => $this->xpdo->discuss->request->makeUrl('board', array('board' => $ancestor->get('id'))), 'text' => $ancestor->get('name'), 'last' => empty($showTitle) && $idx >= $total - 1 ? true : false);
$idx++;
}
if ($showTitle) {
$title = str_replace(array('[', ']'), array('[', ']'), $this->get('title'));
$trail[] = array('text' => $title, 'active' => true, 'last' => true);
}
$trail = $this->xpdo->discuss->hooks->load('breadcrumbs', array('items' => &$trail));
$this->set('trail', $trail);
return $trail;
}
示例3: 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;
}
示例4: getSettings
/**
* Grab settings (from cache if possible) as key => value pairs.
* @return array|mixed
*/
public function getSettings()
{
/* Attempt to get from cache */
$cacheOptions = array(xPDO::OPT_CACHE_KEY => 'system_settings');
$settings = $this->modx->getCacheManager()->get('clientconfig', $cacheOptions);
if (empty($settings) && $this->modx->getCount('cgSetting') > 0) {
$collection = $this->modx->getCollection('cgSetting');
$settings = array();
/* @var cgSetting $setting */
foreach ($collection as $setting) {
$settings[$setting->get('key')] = $setting->get('value');
}
/* Write to cache again */
$this->modx->cacheManager->set('clientconfig', $settings, 0, $cacheOptions);
}
return is_array($settings) ? $settings : array();
}
示例5: translateSite
/**
* Translate the site into Revolution-style tags
*
* @param boolean $save Whether or not to actually save the content changed
* @param null $classes An array of classes and fields to translate
* @param array $files An array of files to attempt to translate
* @param boolean|string $toFile If true, will write the file to the specified log
* @return void
*/
public function translateSite($save = false, $classes = null, $files = array(), $toFile = false)
{
$parser = $this->getParser();
$parser->tagTranslation = $this->tagTranslation;
if ($classes === null) {
$classes = array('modResource' => array('content', 'pagetitle', 'longtitle', 'description', 'menutitle', 'introtext'), 'modTemplate' => array('content'), 'modChunk' => array('snippet'), 'modSnippet' => array('snippet'), 'modPlugin' => array('plugincode'), 'modTemplateVar' => array('default_text'), 'modTemplateVarResource' => array('value'), 'modSystemSetting' => array('value'));
}
ob_start();
echo "Processing classes: " . print_r($classes, true) . "\n\n\n";
foreach ($classes as $className => $fields) {
$resources = $this->modx->getCollection($className);
if ($resources) {
foreach ($resources as $resource) {
foreach ($fields as $field) {
$content = $resource->get($field);
if ($content) {
echo "[BEGIN TRANSLATING FIELD] {$field}\n";
$content = str_replace($this->preTranslationSearch, $this->preTranslationReplace, $content);
while ($parser->translate($content, array(), true)) {
$resource->set($field, $content);
}
echo "[END TRANSLATING FIELD] {$field}\n\n";
}
}
if ($save) {
$resource->save();
}
}
}
}
if (!empty($files)) {
echo $this->translateFiles($save, $files);
}
$log = ob_get_contents();
ob_end_clean();
if ($toFile) {
$cacheManager = $this->modx->getCacheManager();
$cacheManager->writeFile($toFile, $log);
} else {
echo $log;
}
}
示例6: loadSourceMap
/**
* Get a map of MediaSource id => baseUrl
*
* @return array
*/
private function loadSourceMap()
{
$sources = $this->modx->getCollection('sources.modMediaSource');
$sourceMap = array();
foreach ($sources as $source) {
/** @var modMediaSource $source */
$source->initialize();
$sourceMap[$source->get('id')] = new stdClass();
$sourceMap[$source->get('id')]->url = $source->getBaseUrl();
}
return $sourceMap;
}
示例7: getAllActionIDs
/**
* Get a list of all modAction IDs
* @param string $namespace
* @return array
*/
public function getAllActionIDs($namespace = '')
{
$c = array();
if (!empty($namespace)) {
$c['namespace'] = $namespace;
}
$actions = $this->modx->getCollection('modAction', $c);
$actionList = array();
/** @var modAction $action */
foreach ($actions as $action) {
$key = ($action->get('namespace') == 'core' ? '' : $action->get('namespace') . ':') . $action->get('controller');
$actionList[$key] = $action->get('id');
}
return $actionList;
}
示例8: loadCache
/**
* Loads a lexicon topic from the cache. If not found, tries to generate a
* cache file from the database.
*
* @access public
* @param string $namespace The namespace to load from. Defaults to 'core'.
* @param string $topic The topic to load. Defaults to 'default'.
* @param string $language The language to load. Defaults to 'en'.
* @return array The loaded lexicon array.
*/
public function loadCache($namespace = 'core', $topic = 'default', $language = '') {
if (empty($language)) $language = $this->modx->getOption('cultureKey',null,'en');
$key = $this->getCacheKey($namespace, $topic, $language);
$enableCache = ($namespace != 'core' && !$this->modx->getOption('cache_noncore_lexicon_topics',null,true)) ? false : true;
$cached = $this->modx->cacheManager->get($key, array(
xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_lexicon_topics_key', null, 'lexicon_topics'),
xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_lexicon_topics_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_lexicon_topics_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
));
if (!$enableCache || $cached == null) {
$results= false;
/* load file-based lexicon */
$results = $this->getFileTopic($language,$namespace,$topic);
if ($results === false) { /* default back to en */
$results = $this->getFileTopic('en',$namespace,$topic);
if ($results === false) {
$results = array();
}
}
/* get DB overrides */
$c= $this->modx->newQuery('modLexiconEntry');
$c->innerJoin('modNamespace','Namespace');
$c->where(array(
'modLexiconEntry.topic' => $topic,
'modLexiconEntry.language' => $language,
'Namespace.name' => $namespace,
));
$c->sortby($this->modx->getSelectColumns('modLexiconEntry','modLexiconEntry','',array('name')),'ASC');
$entries= $this->modx->getCollection('modLexiconEntry',$c);
if (!empty($entries)) {
foreach ($entries as $entry) {
$results[$entry->get('name')]= $entry->get('value');
}
}
if ($enableCache) {
$cached = $this->modx->cacheManager->generateLexiconTopic($key,$results);
} else {
$cached = $results;
}
}
if (empty($cached)) {
$this->modx->log(xPDO::LOG_LEVEL_DEBUG, "An error occurred while trying to cache {$key} (lexicon/language/namespace/topic)");
}
return $cached;
}
示例9: duplicateLevel
function duplicateLevel(modX &$modx, $oldKey, $newKey, $parent = 0, $newParent = 0)
{
$resources = $modx->getCollection('modResource', array('context_key' => $oldKey, 'parent' => $parent));
if (count($resources) <= 0) {
return array();
}
foreach ($resources as $oldResource) {
$oldResourceArray = $oldResource->toArray();
$newResource = $modx->newObject('modResource');
$newResource->fromArray($oldResourceArray);
$newResource->set('parent', $newParent);
$newResource->set('context_key', $newKey);
$newResource->save();
duplicateLevel($modx, $oldKey, $newKey, $oldResourceArray['id'], $newResource->get('id'));
}
}
示例10: checkResourceGroupAccess
/**
* Check to see if the
* @param modUser|null $user
* @param string $context
* @return bool
*/
public function checkResourceGroupAccess($user = null, $context = '')
{
$context = !empty($context) ? $context : '';
$c = $this->xpdo->newQuery('modResourceGroup');
$c->innerJoin('modTemplateVarResourceGroup', 'TemplateVarResourceGroups', array('TemplateVarResourceGroups.documentgroup = modResourceGroup.id', 'TemplateVarResourceGroups.tmplvarid' => $this->get('id')));
$resourceGroups = $this->xpdo->getCollection('modResourceGroup', $c);
$hasAccess = true;
if (!empty($resourceGroups)) {
$hasAccess = false;
/** @var modResourceGroup $resourceGroup */
foreach ($resourceGroups as $resourceGroup) {
if ($resourceGroup->hasAccess($user, $context)) {
$hasAccess = true;
break;
}
}
}
return $hasAccess;
}
示例11: listPackageVersions
public static function listPackageVersions(modX &$modx, $criteria, $limit = 0, $offset = 0) {
$result = array('collection' => array(), 'total' => 0);
$c = $modx->newQuery('transport.modTransportPackage');
$c->select($modx->getSelectColumns('transport.modTransportPackage','modTransportPackage'));
$c->select(array('Provider.name AS provider_name'));
$c->leftJoin('transport.modTransportProvider','Provider');
$c->where($criteria);
$result['total'] = $modx->getCount('modTransportPackage',$c);
$c->sortby('modTransportPackage.version_major', 'DESC');
$c->sortby('modTransportPackage.version_minor', 'DESC');
$c->sortby('modTransportPackage.version_patch', 'DESC');
$c->sortby('IF(modTransportPackage.release = "" OR modTransportPackage.release = "ga" OR modTransportPackage.release = "pl","z",modTransportPackage.release) DESC','');
$c->sortby('modTransportPackage.release_index', 'DESC');
if((int)$limit > 0) {
$c->limit((int)$limit, (int)$offset);
}
$result['collection'] = $modx->getCollection('transport.modTransportPackage',$c);
return $result;
}
示例12: truncate
/**
* Truncates a thread.
* @return boolean
*/
public function truncate()
{
if (!$this->checkPolicy('truncate')) {
return false;
}
$c = $this->xpdo->newQuery('quipComment');
$c->where(array('thread' => $this->get('name')));
$comments = $this->xpdo->getCollection('quipComment', $c);
$truncated = true;
/** @var quipComment $comment */
foreach ($comments as $comment) {
$comment->set('deleted', true);
$comment->set('deletedon', strftime('%Y-%m-%d %H:%M:%S'));
if ($this->xpdo instanceof modX) {
$comment->set('deletedby', $this->xpdo->user->get('id'));
}
$truncated = $comment->save();
}
return $truncated;
}
示例13: getUserGroupSettings
/**
* Get all group settings for the user in array format.
*
* Preference is set by group rank + member rank, with primary_group having
* highest priority.
*
* @return array An associative array of group settings.
*/
public function getUserGroupSettings()
{
$settings = array();
$primary = array();
$query = $this->xpdo->newQuery('modUserGroupSetting');
$query->innerJoin('modUserGroup', 'UserGroup', array('UserGroup.id = modUserGroupSetting.group'));
$query->innerJoin('modUserGroupMember', 'Member', array('Member.member' => $this->get('id'), 'UserGroup.id = Member.user_group'));
$query->sortby('UserGroup.rank', 'DESC');
$query->sortby('Member.rank', 'DESC');
$ugss = $this->xpdo->getCollection('modUserGroupSetting', $query);
/** @var modUserGroupSetting $ugs */
foreach ($ugss as $ugs) {
if ($ugs->get('group') === $this->get('primary_group')) {
$primary[$ugs->get('key')] = $ugs->get('value');
} else {
$settings[$ugs->get('key')] = $ugs->get('value');
}
}
return array_merge($settings, $primary);
}
示例14: initialize
/**
* Load all config files and prepare the values.
*
* @access public
* @return void
*/
public function initialize()
{
$configs = $this->modx->getCollection('CustomrequestConfigs');
// TODO: Caching of the calculated values.
// import config files
foreach ($configs as $config) {
// fill urlParams if defined
$urlParams = ($tmp = json_decode($config->get('urlparams'))) ? $tmp : array();
$regEx = $config->get('regex');
if ($alias = $config->get('alias')) {
// if alias is defined, calculate the other values
if ($config->get('resourceid')) {
$resourceId = $config->get('resourceid');
} elseif ($res = $this->modx->getObject('modResource', array('uri' => $config->get('alias')))) {
$resourceId = $res->get('id');
} else {
// if resourceId could not be calculated or is not set, don't use that setting
if ($this->getOption('debug')) {
$this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the resourceId for the given alias "' . $alias . '"');
}
break;
}
} elseif ($resourceId = $config->get('resourceid')) {
// else if resourceId is defined, calculate the other values
if ($config->get('alias')) {
$alias = $config->get('alias');
} elseif ($resourceId && ($alias = $this->modx->makeUrl($resourceId))) {
// cutoff trailing .html or /
$alias = trim(str_replace('.html', '', $alias), '/');
} else {
// if alias could not be calculated, don't use that setting
if ($this->getOption('debug')) {
$this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the alias for the given resourceId "' . $resourceId . '"');
}
break;
}
}
$this->requests[$alias] = array('resourceId' => $resourceId, 'alias' => $alias, 'urlParams' => $urlParams, 'regEx' => $regEx);
}
return;
}
示例15: __construct
public function __construct(modX &$modx, array $config = array())
{
$this->modx =& $modx;
if (!($corePath = $this->modx->getOption('modhybridauth.core_path', $config))) {
$corePath = $this->modx->getOption('core_path') . 'components/modhybridauth/';
}
if (!($assetsPath = $this->modx->getOption('modhybridauth.assets_path', $config))) {
$assetsPath = $this->modx->getOption('assets_path') . 'components/modhybridauth/';
}
if (!($assetsUrl = $this->modx->getOption('modhybridauth.assets_url', $config))) {
$assetsUrl = $this->modx->getOption('assets_url') . 'components/modhybridauth/';
}
// Удаляем слеш в начале УРЛа, так как Яша не понимает двойной слош в УРЛе (не протоколе)
$assetsUrl = preg_replace('/^\\/+/', '', $assetsUrl);
$connectorUrl = $assetsUrl . 'connector.php';
$this->config = array_merge(array('assetsUrl' => $assetsUrl, 'cssUrl' => $assetsUrl . 'css/', 'jsUrl' => $assetsUrl . 'js/', 'imagesUrl' => $assetsUrl . 'images/', 'connectorUrl' => $connectorUrl, 'corePath' => $corePath, 'modelPath' => $corePath . 'model/', 'chunksPath' => $corePath . 'elements/chunks/', 'snippetsPath' => $corePath . 'elements/snippets/', 'processorsPath' => $corePath . 'processors/'), $config);
/*$this->modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
$this->modx->setLogTarget('HTML');
*/
$providers = array();
$key = "hybridauth_providers";
if (!($providersCache = $modx->cacheManager->get($key))) {
if ($providersCollection = $modx->getCollection('modHybridAuthProvider')) {
foreach ($providersCollection as $provider) {
$data = $provider->toArray();
$providers[$data['name']] = $data;
}
$modx->cacheManager->set($key, $providers);
}
} else {
$providers = $providersCache;
}
if (!($base_url = $modx->getOption('modhybridauth.base_url'))) {
$base_url = $modx->getOption('site_url') . $assetsUrl . 'connectors/profile/auth.php';
# exit;
}
$this->providers_config = array("base_url" => $base_url, "providers" => $providers);
$this->modx->loadClass('Hybrid_Auth', null, false, true);
}