예제 #1
0
 /**
  * Can be used to adjust the query prior to the COUNT statement
  *
  * @param xPDOQuery $c
  * @return xPDOQuery
  */
 public function prepareQueryBeforeCount(xPDOQuery $c)
 {
     $props = $this->getProperties();
     $c->distinct();
     // from combobox
     if (isset($props['valuesqry'])) {
         if ($props['valuesqry'] === 'true') {
             if (isset($props['query'])) {
                 if (!empty($props['query'])) {
                     $query = urldecode($props['query']);
                     $queries = @explode('||', $query);
                     $i = 0;
                     $where = '';
                     foreach ($queries as $query) {
                         $where .= ($i !== 0 ? ' OR ' : '') . "`smarttagTags`.`tag` = '{$query}'";
                         $i++;
                     }
                     $c->where("({$where})");
                 }
             }
         } else {
             if (isset($props['query']) && !empty($props['query'])) {
                 $c->where(array('tag:LIKE' => "{$props['query']}%", 'OR:tag:LIKE' => "% {$props['query']}%"));
             }
         }
     } else {
         if (isset($props['query']) && !empty($props['query'])) {
             $c->where(array('tag:LIKE' => "%{$props['query']}%"));
         }
     }
     $tvId = isset($props['tvId']) && is_numeric($props['tvId']) ? intval($props['tvId']) : '';
     // for tagcloud
     if (strtolower($props['sort']) === 'count') {
         $c->select(array('smarttagTags.id', 'smarttagTags.tag', 'count' => "(SELECT COUNT(*) FROM {$this->modx->getTableName('smarttagTagresources')} AS Tagresources " . 'WHERE (Tagresources.tag_id = smarttagTags.id ' . (!empty($tvId) ? 'AND Tagresources.tmplvar_id=' . $tvId : '') . '))'));
         $c->sortby('count', 'desc');
         $c->sortby('tag', 'asc');
     }
     if (!empty($tvId)) {
         $tv = $this->modx->getObject('modTemplateVar', $tvId);
         if ($tv) {
             $params = $tv->get('input_properties');
             if ($params['globaltags'] != 'true') {
                 $c->leftJoin('smarttagTagresources', 'Tagresources', 'Tagresources.tag_id = smarttagTags.id');
                 $c->where(array('Tagresources.tmplvar_id' => $tvId));
             }
         }
     }
     return $c;
 }
예제 #2
0
 public function prepareQueryBeforeCount(xPDOQuery $c)
 {
     $c->leftJoin('modUserProfile', 'Profile');
     $query = $this->getProperty('query', '');
     if (!empty($query)) {
         $c->where(array('modUser.username:LIKE' => '%' . $query . '%', 'OR:Profile.fullname:LIKE' => '%' . $query . '%', 'OR:Profile.email:LIKE' => '%' . $query . '%'));
     }
     $userGroup = $this->getProperty('usergroup', 0);
     if (!empty($userGroup)) {
         if ($userGroup === 'anonymous') {
             $c->join('modUserGroupMember', 'UserGroupMembers', 'LEFT OUTER JOIN');
             $c->where(array('UserGroupMembers.user_group' => NULL));
         } else {
             $c->distinct();
             $c->innerJoin('modUserGroupMember', 'UserGroupMembers');
             $c->where(array('UserGroupMembers.user_group' => $userGroup));
         }
     }
     return $c;
 }
예제 #3
0
 protected function prepareUniqObjectsQuery(xPDOQuery &$query)
 {
     $alias = $query->getAlias();
     $query->select(array("{$alias}.id"));
     $query->distinct();
     return $query;
 }
예제 #4
0
 protected function prepareUniqObjectsQuery(xPDOQuery &$query)
 {
     $query->select(array("{$this->classKey}.id"));
     $query->distinct();
     return $query;
 }