Ejemplo n.º 1
0
 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)
     );
 }
    public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
        /* query for profiles */
        $c = $xpdo->newQuery('modFormCustomizationProfile');
        $c->select(array(
            'modFormCustomizationProfile.*',
        ));
        $c->select('
            (SELECT GROUP_CONCAT(UserGroup.name) FROM '.$xpdo->getTableName('modUserGroup').' AS UserGroup
                INNER JOIN '.$xpdo->getTableName('modFormCustomizationProfileUserGroup').' AS fcpug
                ON fcpug.usergroup = UserGroup.id
             WHERE fcpug.profile = modFormCustomizationProfile.id
            ) AS usergroups
        ');
        $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);
        }
        return array(
            'count'=> $count,
            'collection'=> $xpdo->getCollection('modFormCustomizationProfile',$c)
        );
    }
Ejemplo n.º 3
0
    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)
        );
    }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 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));
 }
Ejemplo n.º 6
0
 /**
  * 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);
 }
Ejemplo n.º 7
0
 /**
  * Gets related objects by a foreign key and specified criteria.
  *
  * @access protected
  * @param string $alias The alias representing the relationship.
  * @param mixed An optional xPDO criteria expression.
  * @param boolean|integer Indicates if the saved object(s) should
  * be cached and optionally, by specifying an integer value, for how many
  * seconds before expiring.  Overrides the cacheFlag for the object.
  * @return array A collection of objects matching the criteria.
  */
 protected function &_getRelatedObjectsByFK($alias, $criteria = null, $cacheFlag = true)
 {
     $collection = array();
     if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || is_array($this->_relatedObjects[$alias]) && !empty($this->_relatedObjects[$alias]))) {
         $collection =& $this->_relatedObjects[$alias];
     } else {
         $fkMeta = $this->getFKDefinition($alias);
         if ($fkMeta) {
             $fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
             if ($criteria === null) {
                 $criteria = array($fkMeta['foreign'] => $this->get($fkMeta['local']));
                 if ($fkCriteria !== null) {
                     $criteria = array($fkCriteria, $criteria);
                 }
             } else {
                 $criteria = $this->xpdo->newQuery($fkMeta['class'], $criteria);
                 $addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
                 if ($fkCriteria !== null) {
                     $fkAddCriteria = array();
                     foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
                         if (is_numeric($fkCritKey)) {
                             continue;
                         }
                         $fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal;
                     }
                     if (!empty($fkAddCriteria)) {
                         $addCriteria = array($fkAddCriteria, $addCriteria);
                     }
                 }
                 $criteria->andCondition($addCriteria);
             }
             if ($collection = $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
                 $this->_relatedObjects[$alias] = array_diff_key($this->_relatedObjects[$alias], $collection) + $collection;
             }
         }
     }
     if ($this->xpdo->getDebug() === true) {
         $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true) . "\n" . print_r($criteria->bindings, true) : 'no criteria'));
     }
     return $collection;
 }
Ejemplo n.º 8
0
 /**
  * Gets related objects by a foreign key and specified criteria.
  *
  * @access protected
  * @param string $alias The alias representing the relationship.
  * @param mixed An optional xPDO criteria expression.
  * @param boolean|integer Indicates if the saved object(s) should
  * be cached and optionally, by specifying an integer value, for how many
  * seconds before expiring.  Overrides the cacheFlag for the object.
  * @return array A collection of objects matching the criteria.
  */
 protected function &_getRelatedObjectsByFK($alias, $criteria = null, $cacheFlag = true)
 {
     $collection = array();
     if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || is_array($this->_relatedObjects[$alias]) && !empty($this->_relatedObjects[$alias]))) {
         $collection =& $this->_relatedObjects[$alias];
     } else {
         $fkMeta = $this->getFKDefinition($alias);
         if ($fkMeta) {
             if ($criteria === null) {
                 $criteria = array($fkMeta['foreign'] => $this->get($fkMeta['local']));
             }
             if ($collection = $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
                 $this->_relatedObjects[$alias] = array_merge($this->_relatedObjects[$alias], $collection);
             }
         }
     }
     if ($this->xpdo->getDebug() === true) {
         $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true) . "\n" . print_r($criteria->bindings, true) : 'no criteria'));
     }
     return $collection;
 }
Ejemplo n.º 9
0
 /**
  * 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;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
    $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');
            $tv_link->set('templateid', $template_id);
            $tv_link->set('tmplvarid', $meta_tv_id);
            $tv_link->set('rank', 1);