Nooku Server is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-server

Commit 3564

User picture
  • Author: arunasmazeika
  • 2012-04-05 09:11 (about 2 years ago)

Re-merged development branch.

re #186

Files Affected

 
35633564
32
        else parent::_beforeTableUpdate($context);
32
        else parent::_beforeTableUpdate($context);
33
    }
33
    }
34
 
34
 
35
    public function _buildQueryWhere(KDatabaseQuery $query)
35
    public function _buildQueryWhere(KDatabaseQuerySelect $query)
36
    {
36
    {
37
        if($this->getMixer()->getIdentifier()->name == 'article' && !isset($this->featured_order))
37
        if ($this->getMixer()->getIdentifier()->name == 'article' && !isset($this->featured_order)) 
38
        {
38
        {
39
            $query->where('catid', '=', $this->category_id)
39
            $query->where('catid = :category')
40
                  ->where('state', '>=', 0);
40
                  ->where('state >= :state')
 
 
41
                  ->bind(array('category' => $this->category_id, 'state' => 0));
41
        }
42
        }
42
    }
43
    }
43
}
44
}
35633564
27
     *
27
     *
28
     * @param  object   A database table object
28
     * @param  object   A database table object
29
     * @param  string   The row status
29
     * @param  string   The row status
30
     * @param  array    Array of row id's
30
     * @param  object   A KDatabaseQuerySelect object.
31
     * @return KDatabaseRowsetInterface
31
     * @return KDatabaseRowsetInterface
32
     */
32
     */
33
    protected function _selectRevisions($table, $status, $where)
33
    protected function _selectRevisions($table, $status, $query)
34
    {
34
    {
35
        $result = parent::_selectRevisions($table, $status, $where);
35
        $result = parent::_selectRevisions($table, $status, $query);
 
 
36
        $needle = array();
36
 
37
 
37
        $needle = array();
38
        // Filter by category id if set in the query.
38
        if(isset($where['tbl.catid'])) {
39
        foreach ($query->where as $where) {
39
            $needle['category_id'] = $where['tbl.catid'];
40
            if (is_string($where['condition']) && preg_match('/(?:^|AND\s+)tbl\.catid\s*=\s*(\d+|:[a-z_]+)/', $where['condition'], $matches)) {
 
 
41
                if (is_numeric($matches[1])) {
 
 
42
                    $needle['category_id'] = (int) $matches[1];
 
 
43
                    break;
 
 
44
                } elseif (isset($query->params[substr($matches[1], 1)])) {
 
 
45
                    $needle['category_id'] = (int) $query->params[substr($matches[1], 1)];
 
 
46
                    break;
 
 
47
                }
 
 
48
            }
40
        }
49
        }
41
 
50
 
42
        if(isset($where['tbl.sectionid'])) {
51
        // Filter by section id if set in the query.
43
            $needle['section_id'] = $where['tbl.sectionid'];
52
        foreach ($query->where as $where) {
 
 
53
            if (is_string($where['condition']) && preg_match('/(?:^|AND\s+)tbl\.sectionid\s*=\s*(\d+|:[a-z_]+)/', $where['condition'], $matches)) {
 
 
54
                if (is_numeric($matches[1])) {
 
 
55
                    $needle['section_id'] = (int) $matches[1];
 
 
56
                    break;
 
 
57
                } elseif (isset($query->params[substr($matches[1], 1)])) {
 
 
58
                    $needle['section_id'] = (int) $query->params[substr($matches[1], 1)];
 
 
59
                    break;
 
 
60
                }
 
 
61
            }
44
        }
62
        }
45
 
63
 
46
        if(!empty($needle)) {
64
        if($needle) {
47
            $result = $result->find($needle);
65
            $result = $result->find($needle);
48
        }
66
        }
49
 
67
 
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
            ->insert('section'   , 'int')
27
            ->insert('section'   , 'int')
28
            ->insert('category'  , 'int')
28
            ->insert('category'  , 'int')
29
            ->insert('state'     , 'int')
29
            ->insert('state'     , 'int')
...
 
...
 
32
            ->insert('featured'  , 'boolean')
32
            ->insert('featured'  , 'boolean')
33
            ->insert('trashed'   , 'int');
33
            ->insert('trashed'   , 'int');
34
 
34
 
35
        $this->_state->remove('sort')->insert('sort', 'cmd', 'section_title');
35
        $this->getState()->remove('sort')->insert('sort', 'cmd', 'section_title');
36
    }
36
    }
37
 
37
 
38
    protected function _buildQueryColumns(KDatabaseQuery $query)
38
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
39
    {
39
    {
40
        parent::_buildQueryColumns($query);
40
        parent::_buildQueryColumns($query);
41
 
41
 
42
        $query->select('section.title AS section_title')
42
        $query->columns(array(
43
            ->select('category.title AS category_title')
43
            'section_title'     => 'sections.title',
44
            ->select('user.name AS created_by_name')
44
            'category_title'    => 'categories.title',
45
            ->select('user.id   AS created_by_id')
45
            'created_by_name'   => 'users.name',
46
            ->select('IF(frontpage.content_id, 1, 0) AS featured')
46
            'created_by_id'     => 'users.id',
47
            ->select('frontpage.ordering AS featured_ordering')
47
            'featured_ordering' => 'frontpage.ordering',
48
            ->select('group.name AS group_name');
48
            'group_name'        => 'groups.name',
 
 
49
            'featured'          => 'IF(frontpage.content_id, 1, 0)'
 
 
50
        ));
49
    }
51
    }
50
 
52
 
51
    protected function _buildQueryJoins(KDatabaseQuery $query)
53
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
52
    {
54
    {
53
         parent::_buildQueryJoins($query);
55
        parent::_buildQueryJoins($query);
 
 
56
        
 
 
57
        $state = $this->getState();
54
 
58
 
55
        $state = $this->_state;
59
        $query->join(array('sections' => 'sections'), 'sections.id = tbl.sectionid')
 
 
60
              ->join(array('categories' => 'categories'), 'categories.id = tbl.catid')
 
 
61
              ->join(array('users' => 'users'), 'users.id = tbl.created_by')
 
 
62
              ->join(array('groups' => 'groups'), 'groups.id = tbl.access');
56
 
63
 
57
        $query->join('LEFT', 'sections AS section', 'section.id = tbl.sectionid')
64
        $query->join(array('frontpage' => 'content_frontpage'), 'frontpage.content_id = tbl.id', $state->featured ? 'RIGHT' : 'LEFT');
58
              ->join('LEFT', 'categories AS category', 'category.id = tbl.catid')
 
 
59
              ->join('LEFT', 'users AS user', 'user.id = tbl.created_by')
 
 
60
              ->join('LEFT', 'groups AS group', 'group.id = tbl.access');
 
 
61
 
 
 
62
        if(is_bool($state->featured) && $state->featured == true) {
 
 
63
            $query->join('RIGHT', 'content_frontpage AS frontpage', 'frontpage.content_id = tbl.id');
 
 
64
        } else {
 
 
65
            $query->join('LEFT', 'content_frontpage AS frontpage', 'frontpage.content_id = tbl.id');
 
 
66
        }
 
 
67
    }
65
    }
68
 
66
 
69
    protected function _buildQueryWhere(KDatabaseQuery $query)
67
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
70
    {
68
    {
71
        parent::_buildQueryWhere($query);
69
        parent::_buildQueryWhere($query);
 
 
70
 
 
 
71
        $state = $this->getState();
72
 
72
 
73
        $state = $this->_state;
73
        if(is_numeric($state->state)) 
74
 
74
        {
75
        if(is_numeric($state->state)) {
75
            $query->where('tbl.state = :state')
76
            $query->where('tbl.state', '=', $state->state);
76
                ->bind(array('state' => $state->state));
77
        } else {
77
        } 
78
            $query->where('tbl.state', '<>', -2);
78
        else 
 
 
79
        {
 
 
80
            $query->where('tbl.state <> :state')
 
 
81
                ->bind(array('state' => -2));
79
        }
82
        }
80
 
83
 
81
        if($state->search) {
84
        if($state->search) 
82
            $query->where('tbl.title', 'LIKE', '%'.$state->search.'%');
85
        {
 
 
86
            $query->where('tbl.title LIKE :search')
 
 
87
                ->bind(array('search' => '%'.$state->search.'%'));
83
        }
88
        }
84
 
89
 
85
        if(is_numeric($state->section)) {
90
        if(is_numeric($state->section)) 
86
            $query->where('tbl.sectionid', '=', $state->section );
91
        {
 
 
92
            $query->where('tbl.sectionid = :section')
 
 
93
                ->bind(array('section' => $state->section));
87
        }
94
        }
88
 
95
 
89
        if(is_numeric($state->category)) {
96
        if(is_numeric($state->category)) 
90
            $query->where('tbl.catid', '=',  $state->category);
97
        {
 
 
98
            $query->where('tbl.catid = :category')
 
 
99
                ->bind(array('category' => $state->category));
91
        }
100
        }
92
 
101
 
93
        if($state->created_by) {
102
        if($state->created_by) 
94
            $query->where('tbl.created_by', '=', $state->created_by);
103
        {
 
 
104
            $query->where('tbl.created_by = :created_by')
 
 
105
                ->bind(array('created_by' => $state->created_by));
95
        }
106
        }
96
 
107
 
97
        if(is_numeric($state->access)) {
108
        if(is_numeric($state->access)) 
98
            $query->where('tbl.access', '=', $state->access);
109
        {
 
 
110
            $query->where('tbl.access = :access')
 
 
111
                ->bind(array('access' => $state->access));
99
        }
112
        }
100
 
113
 
101
        if($this->getTable()->isRevisable() && $state->trashed) {
114
        if($this->getTable()->isRevisable() && $state->trashed) 
102
            $query->where('tbl.deleted', '=', 1);
115
        {
 
 
116
            $query->where('tbl.deleted = :trashed')
 
 
117
                ->bind(array('trashed' => 1));
103
        }
118
        }
104
    }
119
    }
105
 
120
 
106
    protected function _buildQueryOrder(KDatabaseQuery $query)
121
    protected function _buildQueryOrder(KDatabaseQuerySelect $query)
107
    {
122
    {
108
        $state = $this->_state;
123
        $state = $this->getState();
109
 
124
 
110
        $direction = strtoupper($state->direction);
125
        $direction = strtoupper($state->direction);
111
 
126
 
112
        if(is_bool($state->featured) && $state->featured == true)
127
        if (is_bool($state->featured) && $state->featured == true) 
113
        {
128
        {
114
            if($this->_state->sort == 'ordering')
129
            if ($state->sort != 'ordering') 
115
            {
130
            {
116
                $query->order('featured_ordering',  $direction);
131
                $query->order($this->getState()->sort, $direction)
117
            }
132
                    ->order('featured_ordering', 'ASC');
118
            else
133
            } 
119
            {
134
            else $query->order('featured_ordering',  $direction);
120
                $query->order($this->_state->sort, $direction)
135
        } 
121
                      ->order('featured_ordering', 'ASC');
136
        else 
122
            }
 
 
123
        }
 
 
124
        else
 
 
125
        {
137
        {
126
            if($this->_state->sort == 'ordering')
138
            if ($state->sort == 'ordering') 
127
            {
139
            {
128
                $query->order('section_title', 'ASC')
140
                $query->order('section_title', 'ASC')
129
                    ->order('category_title', 'ASC')
141
                    ->order('category_title', 'ASC')
130
                    ->order('ordering', $direction);
142
                    ->order('ordering', $direction);
131
            }
143
            } 
132
            else
144
            else 
133
            {
145
            {
134
                $query->order($this->_state->sort, $direction)
146
                $query->order($state->sort, $direction)
135
                    ->order('section_title', 'ASC')
147
                    ->order('section_title', 'ASC')
136
                    ->order('category_title', 'ASC')
148
                    ->order('category_title', 'ASC')
137
                    ->order('ordering', 'ASC');
149
                    ->order('ordering', 'ASC');
35633564
24
    {
24
    {
25
        parent::__construct($config);
25
        parent::__construct($config);
26
 
26
 
27
        $this->_state
27
        $this->getState()
28
            ->insert('published' ,'int')
28
            ->insert('published' ,'int')
29
            ->insert('limit'    , 'int')
29
            ->insert('limit'    , 'int')
30
            ->insert('offset'   , 'int')
30
            ->insert('offset'   , 'int')
...
 
...
 
36
    {
36
    {
37
        if(!isset($this->_list))
37
        if(!isset($this->_list))
38
        {
38
        {
 
 
39
            $state = $this->getState();
 
 
40
 
39
            $folders  = array(); 
41
            $folders  = array(); 
40
            $children = array();
42
            $children = array();
41
 
43
 
42
            $categories = $this->getService('com://admin/categories.model.categories')
44
            $categories = $this->getService('com://admin/categories.model.categories')
43
                ->published($this->_state->published)
45
                ->published($state->published)
44
                ->section('com_content')
46
                ->section('com_content')
45
                ->sort($this->_state->sort)
47
                ->sort($state->sort)
46
                ->direction($this->_state->direction)
48
                ->direction($state->direction)
47
                ->getList();
49
                ->getList();
48
 
50
 
49
            foreach($categories as $category)
51
            foreach($categories as $category)
...
 
...
 
64
            }
66
            }
65
 
67
 
66
            $sections = $this->getService('com://admin/articles.model.sections')
68
            $sections = $this->getService('com://admin/articles.model.sections')
67
                ->published($this->_state->published)
69
                ->published($state->published)
68
                ->sort($this->_state->sort)
70
                ->sort($state->sort)
69
                ->direction($this->_state->direction)
71
                ->direction($state->direction)
70
                ->getList();
72
                ->getList();
71
 
73
 
72
            $count = 0;
74
            $count = 0;
...
 
...
 
108
            $this->_total = count($folders);
110
            $this->_total = count($folders);
109
 
111
 
110
            //Apply limit and offset
112
            //Apply limit and offset
111
            if($this->_state->limit) {
113
            if($state->limit) {
112
                $folders = array_slice( $folders, $this->_state->offset, $this->_state->limit, true);
114
                $folders = array_slice( $folders, $state->offset, $state->limit, true);
113
            }
115
            }
114
 
116
 
115
            //Create the paths of each node
117
            //Create the paths of each node
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
             ->insert('search'     , 'string')
 
 
28
            ->insert('scope'     , 'string', '')
27
            ->insert('scope'     , 'string', '')
29
            ->insert('published' , 'boolean');
28
            ->insert('published' , 'boolean');
30
 
29
 
31
    }
30
    }
32
 
31
 
33
    protected function _buildQueryColumns(KDatabaseQuery $query)
32
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
34
    {
33
    {
35
        parent::_buildQueryColumns($query);
34
        parent::_buildQueryColumns($query);
36
        $query->select('categorycount')
35
 
37
            ->select('SUM( IF(active.state <> -2,1,0)) activecount');
36
        $query->columns(array(
 
 
37
            'categorycount',
 
 
38
            'activecount' => 'SUM(IF(active.state <> -2, 1, 0))'
 
 
39
        ));
38
    }
40
    }
39
 
41
 
40
    protected function _buildQueryJoins(KDatabaseQuery $query)
42
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
41
    {
43
    {
42
        //Exclude joins if counting records
44
        //Exclude joins if counting records
43
        if(!$query->count)
45
        if (!$query->count) {
44
        {
46
            $subquery = $this->getService('koowa:database.query.select')
45
            $query->join[]=array(
47
                ->columns(array('section', 'categorycount' => 'COUNT(section)'))
46
                'type' => 'LEFT',
48
                ->from('categories')
47
                'table' => '(SELECT section, COUNT(section) categorycount FROM #__categories 
49
                ->where('published <> - 2')
48
                    WHERE published <> -2 GROUP BY section) AS cat', 
50
                ->group('section');
49
                'condition' => array('cat.section = tbl.id'));
51
            
50
            
52
            $query->join(array('categories' => $subquery), 'categories.section = tbl.id')
51
            $query->join('LEFT','content AS active','active.sectionid = tbl.id');
53
                ->join(array('active' => 'content'), 'active.sectionid = tbl.id');
52
        }
54
        }
53
 
55
 
54
        parent::_buildQueryJoins($query);
56
        parent::_buildQueryJoins($query);
55
    }
57
    }
56
 
58
 
57
    protected function _buildQueryWhere(KDatabaseQuery $query)
59
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
58
    {
60
    {
59
        $state = $this->_state;
61
        parent::_buildQueryWhere($query);
 
 
62
        $state = $this->getState();
60
 
63
 
61
        if($state->search) {
64
        if($state->search) {
62
            $query->where('tbl.title', 'LIKE',  '%'.$state->search.'%');
65
            $query->where('tbl.title LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
63
        }
66
        }
64
 
67
 
65
        if($state->scope) {
68
        if($state->scope) {
66
            $query->where('tbl.scope', 'LIKE',  $state->scope);
69
            $query->where('tbl.scope LIKE :scope')->bind(array('scope' => $state->scope));
67
        }
70
        }
68
 
71
 
69
        if($state->published) {
72
        if($state->published) {
70
            $query->where('tbl.published', '=', (int) $state->published);
73
            $query->where('tbl.published = :published')->bind(array('published' => (int) $state->published));
71
        }
74
        }
72
          
 
 
73
        parent::_buildQueryWhere($query);
 
 
74
    }
75
    }
75
 
76
 
76
    protected function _buildQueryGroup(KDatabaseQuery $query)
77
    protected function _buildQueryGroup(KDatabaseQuerySelect $query)
77
    {
78
    {
78
        $query->group('tbl.id');
79
        $query->group('tbl.id');
79
    }
80
    }
35633564
36
            <input class="required" type="text" name="title" maxlength="255" value="<?= $article->title
?>" placeholder="<?= @text('Title') ?>" />
36
            <input class="required" type="text" name="title" maxlength="255" value="<?= $article->title
?>" placeholder="<?= @text('Title') ?>" />
37
        </div>
37
        </div>
38
 
38
 
39
        <?/*= @editor(array(
 
 
40
                'name' => 'text',
 
 
41
                'text' => $article->text,
 
 
42
                'width' => '100%',
 
 
43
                'height' => '300',
 
 
44
                'cols' => '60',
 
 
45
                'rows' => '20',
 
 
46
                'buttons' => true,
 
 
47
                'options' => array('theme' => 'simple', 'pagebreak', 'readmore')));
 
 
48
        //*/?>
 
 
49
        <?= @service('com://admin/editors.controller.editor')->name('text')->data($article->text)->display() ?>
39
        <?= @service('com://admin/editors.controller.editor')->name('text')->data($article->text)->display() ?>
50
    </div>
40
    </div>
51
    <div class="sidebar">        
41
    <div class="sidebar">        
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
            ->insert('published',   'boolean')
27
            ->insert('published',   'boolean')
28
            ->insert('category',    'int')
28
            ->insert('category',    'int')
29
            ->insert('sticky',        'int')
29
            ->insert('sticky',        'int')
...
 
...
 
30
            ->insert('tags',        'string');
30
            ->insert('tags',        'string');
31
    }
31
    }
32
 
32
 
33
    protected function _buildQueryColumns(KDatabaseQuery $query)
33
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
34
    {
34
    {
35
        parent::_buildQueryColumns($query);
35
        parent::_buildQueryColumns($query);
36
 
36
 
37
        $query
37
        $query->columns(array('category' => 'categories.title'));
38
            ->select('cc.title AS category');
 
 
39
    }
38
    }
40
 
39
 
41
    protected function _buildQueryJoins(KDatabaseQuery $query)
40
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
42
    {
41
    {
43
        //Exclude joins if counting records
42
        $query->join(array('categories' => 'categories'), 'categories.id = tbl.catid');
44
        if(!$query->count)
 
 
45
        {
 
 
46
            $query->join(
 
 
47
                '',
 
 
48
                'categories AS cc',
 
 
49
                array('cc.id = tbl.catid')
 
 
50
            );
 
 
51
                        
 
 
52
            $query->where('cc.section', 'LIKE', 'com_banner');
 
 
53
        }
 
 
54
    }
43
    }
55
 
44
 
56
    protected function _buildQueryWhere(KDatabaseQuery $query)
45
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
57
    {
46
    {
58
        parent::_buildQueryWhere($query);
47
        parent::_buildQueryWhere($query);
 
 
48
        $state = $this->getState();
59
 
49
 
60
        $state = $this->_state;
50
        $query->where('categories.section LIKE :section')->bind(array('section' => 'com_banner'));
61
 
51
 
62
        if (is_bool($state->published)) {
52
        if (is_bool($state->published)) {
63
            $query->where('tbl.showbanner', '=', (int) $state->published);
53
            $query->where('tbl.showbanner = :published')->bind(array('published' => (int) $state->published));
64
        }
54
        }
65
 
55
 
66
        if ($state->category) {
56
        if ($state->category) {
67
            $query->where('tbl.catid', '=', $state->category);
57
            $query->where('tbl.catid = :category')->bind(array('category' => $state->category));
68
        }
58
        }
69
 
59
 
70
        if (is_numeric($state->sticky)) {
60
        if (is_numeric($state->sticky)) {
71
            $query->where('tbl.sticky', '=', $state->sticky);
61
            $query->where('tbl.sticky = :sticky')->bind(array('sticky' => $state->sticky));
72
        }
62
        }
73
 
63
 
74
        if (!empty($state->search)) {
64
        if (!empty($state->search)) {
75
            $query->where('LOWER(tbl.name)', 'LIKE', '%'.strtolower($state->search).'%');
65
            $query->where('tbl.name LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
76
        }
66
        }
77
 
67
 
78
        if (!empty($state->tags)) 
68
        if (!empty($state->tags)) {
79
        {
69
            $query->where('UPPER(tags) REGEXP :tags')
80
            $where = array();
70
                ->bind(array('tags' => '[[:<:]]('.strtoupper(implode('|', $state->tags)).')[[:>:]]'));
81
            foreach ($state->tags as $tag) {
 
 
82
                $where[] = 'UPPER(tags) REGEXP \'[[:<:]]'.strtoupper(trim($tag)).'[[:>:]]\'';
 
 
83
            }
 
 
84
            
 
 
85
            $query->where('( '.implode(' OR ', $where).' )');
 
 
86
        }
71
        }
87
    }
72
    }
88
 
73
 
89
    protected function _buildQueryOrder(KDatabaseQuery $query)
74
    protected function _buildQueryOrder(KDatabaseQuerySelect $query)
90
    {
75
    {
91
        $sort       = $this->_state->sort ? $this->_state->sort : 'category';
76
        $state = $this->getState();
92
        $direction  = strtoupper($this->_state->direction);
 
 
93
 
77
 
 
 
78
        $sort      = $state->sort ? $state->sort : 'category';
 
 
79
        $direction = strtoupper($state->direction);
 
 
80
 
94
        switch ($sort)
81
        switch ($sort)
95
        {
82
        {
96
            case 'random':
83
            case 'random':
35633564
38
        parent::__construct($config);
38
        parent::__construct($config);
39
    }
39
    }
40
 
40
 
41
    public function _buildQueryWhere(KDatabaseQuery $query)
41
    public function _buildQueryWhere(KDatabaseQuerySelect $query)
42
    {
42
    {
43
        if ($this->_parent_column)
43
        if ($this->_parent_column)
44
        {
44
        {
45
            $parent = $this->_parent ? $this->_parent : $this->{$this->_parent_column};   
45
            $parent = $this->_parent ? $this->_parent : $this->{$this->_parent_column};   
46
            $query->where($this->_table->mapColumns($this->_parent_column), '=', $parent);
46
            $query->where($this->_table->mapColumns($this->_parent_column).' = :parent')->bind(array('parent' => $parent));
47
        }
47
        }
48
    }
48
    }
49
 
49
 
...
 
...
 
111
                $table = $context->caller;
111
                $table = $context->caller;
112
                $parent_column = $table->mapColumns($parent_column);
112
                $parent_column = $table->mapColumns($parent_column);
113
 
113
 
114
                $query->join[] = array('type' => 'LEFT',
114
                $subquery = $this->getService('koowa:database.query.select')
115
                    'table' => '(SELECT '.$parent_column.' , COUNT(ordering) order_total FROM #__'.$table->getBase().' ' 
115
                    ->columns(array($parent_column, 'order_total' => 'COUNT(ordering)'))
116
                            .'GROUP BY '.$parent_column.') AS orderable',
116
                    ->from($table->getBase())
117
                    'condition' => array('orderable.'.$parent_column.' = tbl.'.$parent_column ));
117
                    ->group($parent_column);
118
 
118
                
119
                $query->select('orderable.order_total');
119
                $query->columns('orderable.order_total')
 
 
120
                    ->join(array('orderable' => $subquery), 'orderable.'.$parent_column.' = tbl.'.$parent_column);
120
            }
121
            }
121
        }
122
        }
122
    }  
123
    }  
35633564
33
                'enabled'      => 'published',
33
                'enabled'      => 'published',
34
                'locked_on'    => 'checked_out_time',
34
                'locked_on'    => 'checked_out_time',
35
                'locked_by'    => 'checked_out',
35
                'locked_by'    => 'checked_out',
36
                'slug'         => 'alias',
36
                'section_id'   => 'section',
37
                'section_id'   => 'section'
37
                'slug'         => 'alias'
38
                ),
38
                ),
39
            ));
39
            ));
40
 
40
 
35633564
26
        parent::__construct($config);
26
        parent::__construct($config);
27
 
27
 
28
        // Set the state
28
        // Set the state
29
        $this->_state
29
        $this->getState()
30
            ->insert('section'   , 'string')
30
            ->insert('section'   , 'string')
31
            ->insert('parent'    , 'string')
31
            ->insert('parent'    , 'string')
32
            ->insert('published' , 'boolean')
32
            ->insert('published' , 'boolean')
...
 
...
 
34
 
34
 
35
    }
35
    }
36
 
36
 
37
    protected function _buildQueryColumns(KDatabaseQuery $query)
37
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
38
    {
38
    {
39
        parent::_buildQueryColumns($query);
39
        parent::_buildQueryColumns($query);
40
 
40
        $state = $this->getState();
41
        if ( $this->_state->section)
41
 
42
        {
42
        if ($state->section) {
43
            if ( $this->_state->section == 'com_content' || is_numeric($this->_state->section)){
43
            if ( $state->section == 'com_content' || is_numeric($state->section)){
44
                $query->select('sections.title AS section_title')
44
                $query->columns(array(
45
                      ->select('SUM( IF(content.state <> -2,1,0)) activecount');
45
                    'section_title' => 'section.title',
 
 
46
                    'activecount' => 'SUM(IF(content.state <> -2, 1, 0))',
 
 
47
                ));
46
            } else {
48
            } else {
47
                $query->select('SUM(IF(child.catid,1,0)) activecount');
49
                $query->columns(array('activecount' => 'SUM(IF(child.catid, 1, 0))'));
48
            }
50
            }
49
        }
51
        }
50
    }
52
    }
51
 
53
 
52
 
54
 
53
    protected function _buildQueryJoins(KDatabaseQuery $query)
55
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
54
    {
56
    {
 
 
57
        $state = $this->getState();
 
 
58
 
55
        //Exclude joins if counting records
59
        //Exclude joins if counting records
56
        if(!$query->count)
60
        if(!$query->count)
57
        {
61
        {
58
            if ( $this->_state->section)
62
            if ($state->section) {
59
            {
63
                if ($state->section == 'com_content' || is_numeric($state->section)){
60
                if ($this->_state->section == 'com_content' || is_numeric($this->_state->section)){
64
                    $query->join(array('content' => 'content'), 'content.catid = tbl.id');
61
                    $query->join('LEFT','content AS content','content.catid = tbl.id');
65
                    $query->join(array('section' => 'sections'), 'section.id = tbl.section');
62
                    $query->join('LEFT','sections AS sections','sections.id = tbl.section');
 
 
63
                } else {
66
                } else {
64
                    $query->join('LEFT',substr($this->_state->section,4).' AS child','child.catid = tbl.id');
67
                    $query->join(array('child' => substr($state->section, 4)), 'child.catid = tbl.id');
65
                }
68
                }
66
            }
69
            }
67
        }
70
        }
...
 
...
 
70
    }
73
    }
71
 
74
 
72
 
75
 
73
    protected function _buildQueryWhere(KDatabaseQuery $query)
76
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
74
    {
77
    {
75
        $state = $this->_state;
78
        $state = $this->getState();
76
 
79
 
77
        if($state->search) {
80
        if($state->search) {
78
            $query->where('tbl.title', 'LIKE',  '%'.$state->search.'%');
81
            $query->where('tbl.title LIKE %:search%')->bind(array('search' => $state->search));
79
        }
82
        }
80
 
83
 
81
        //select overall section
84
        //select overall section
...
 
...
 
82
        if ($state->section)
85
        if ($state->section)
83
        {
86
        {
84
            if( $state->section == 'com_content' ) {
87
            if( $state->section == 'com_content' ) {
85
                $query->where('tbl.section', 'NOT LIKE', 'com%');
88
                $query->where('tbl.section NOT LIKE :section')->bind(array('section' => 'com%'));
86
            } else {
89
            } else {
87
                $query->where('tbl.section', 'IN', $state->section);
90
                $query->where('tbl.section '.(is_array($state->section) ? 'IN' : '=').' :section')->bind(array('section' => $state->section));
88
            }
91
            }
89
        }
92
        }
90
 
93
 
91
        //select parent section within com_content
94
        //select parent section within com_content
92
        if ($state->parent) {
95
        if ($state->parent) {
93
            $query->where('tbl.section', 'IN', $state->parent);
96
            $query->where('tbl.section '.(is_array($state->section) ? 'IN' : '=').' :parent')->bind(array('parent' => $state->parent));
94
        }
97
        }
95
 
98
 
96
        if (is_bool($state->published)) {
99
        if (is_bool($state->published)) {
97
            $query->where('tbl.published', '=', (int) $state->published);
100
            $query->where('tbl.published = :published')->bind(array('published' => (int) $state->published));
98
        }
101
        }
99
 
102
 
100
        parent::_buildQueryWhere($query);
103
        parent::_buildQueryWhere($query);
101
    }
104
    }
102
 
105
 
103
    protected function _buildQueryGroup(KDatabaseQuery $query)
106
    protected function _buildQueryGroup(KDatabaseQuerySelect $query)
104
    {
107
    {
105
        $state = $this->_state;
108
        $state = $this->getState();
106
        if( $state->distinct ) 
109
        if( $state->distinct ) 
107
        {
110
        {
108
            $query->distinct();
111
            $query->distinct();
...
 
...
 
111
        else $query->group('tbl.id');
114
        else $query->group('tbl.id');
112
    }
115
    }
113
 
116
 
114
    protected function _buildQueryOrder(KDatabaseQuery $query)
117
    protected function _buildQueryOrder(KDatabaseQuerySelect $query)
115
    {
118
    {
116
        $sort = $this->_state->sort;
119
        $state = $this->getState();
117
        $direction  = strtoupper($this->_state->direction);
120
 
 
 
121
        $sort = $state->sort;
 
 
122
        $direction  = strtoupper($state->direction);
118
 
123
 
119
        if ( $sort) {
124
        if ( $sort) {
120
            $query->order($this->getTable()->mapColumns($sort), $direction);
125
            $query->order($this->getTable()->mapColumns($sort), $direction);
...
 
...
 
122
 
127
 
123
        if (empty($sort))
128
        if (empty($sort))
124
        {
129
        {
125
            if ($this->_state->section == 'com_content'){
130
            if ($state->section == 'com_content'){
126
                $query->order('sections.ordering','ASC');
131
                $query->order('section.ordering','ASC');
127
            }
132
            }
128
        }
133
        }
129
 
134
 
35633564
24
    {
24
    {
25
        parent::__construct($config);
25
        parent::__construct($config);
26
 
26
 
27
        $this->_state
27
        $this->getState()
28
            ->insert('published' , 'boolean')
28
            ->insert('published', 'boolean')
29
            ->insert('category'  , 'int');
29
            ->insert('category', 'int');
30
    }
30
    }
31
 
31
 
32
    protected function _buildQueryColumns(KDatabaseQuery $query)
32
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
33
    {
33
    {
34
        parent::_buildQueryColumns($query);
34
        parent::_buildQueryColumns($query);
35
 
35
 
36
        $query->select('categories.title AS category_title');
36
        $query->columns(array(
37
        $query->select('user.name AS username');
37
            'category_title' => 'categories.title',
 
 
38
            'username' => 'users.name'
 
 
39
        ));
38
    }
40
    }
39
 
41
 
40
    protected function _buildQueryJoins(KDatabaseQuery $query)
42
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
41
    {
43
    {
42
        parent::_buildQueryJoins($query);
44
        parent::_buildQueryJoins($query);
43
 
45
 
44
        $query->join('LEFT', 'categories AS categories', 'categories.id = tbl.catid');
46
        $query->join(array('categories' => 'categories'), 'categories.id = tbl.id')
45
        $query->join('LEFT', 'users AS user', 'user.id = tbl.user_id');
47
            ->join(array('users' => 'users'), 'users.id = tbl.user_id');
46
    }
48
    }
47
 
49
 
48
    protected function _buildQueryWhere(KDatabaseQuery $query)
50
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
49
    {
51
    {
50
        $state = $this->_state;
52
        parent::_buildQueryWhere($query);
 
 
53
        $state = $this->getState();
51
 
54
 
52
        if (is_bool($state->published)) {
55
        if (is_bool($state->published)) {
53
            $query->where('tbl.published', '=', (int) $state->published);
56
            $query->where('tbl.published = :published')->bind(array('published' => (int) $state->published));
54
        }
57
        }
55
 
58
 
56
        if (is_numeric($state->category) && !empty($state->category)) {
59
        if ($state->category) {
57
            $query->where('tbl.catid', '=', $state->category);
60
            $query->where('tbl.catid = :category')->bind(array('category' => $state->category));
58
        }
61
        }
59
 
62
 
60
        if ($state->search) {
63
        if ($state->search) {
61
            $query->where('tbl.name', 'LIKE', '%'.$state->search.'%');
64
            $query->where('tbl.name LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
62
        }
65
        }
63
        
 
 
64
        parent::_buildQueryWhere($query);
 
 
65
    }
66
    }
66
}
67
}
35633564
33
 
33
 
34
         parent::onAfterControllerBrowse($event);
34
         parent::onAfterControllerBrowse($event);
35
    }
35
    }
 
 
36
 
 
 
37
    protected function _commandDefault(KControllerToolbarCommand $command)
 
 
38
    {
 
 
39
        $command->label = JText::_('Make Default');
 
 
40
 
 
 
41
        $command->append(array(
 
 
42
                'attribs' => array(
 
 
43
                    'data-action' => 'edit',
 
 
44
                    'data-data'   => '{default:1}'
 
 
45
        )
 
 
46
        ));
 
 
47
    }
36
 
48
 
37
    protected function _commandPreview(KControllerToolbarCommand $command)
49
    protected function _commandPreview(KControllerToolbarCommand $command)
38
    {
50
    {
35633564
76
            $params = JComponentHelper::getParams('com_extensions');
76
            $params = JComponentHelper::getParams('com_extensions');
77
            $params->set('language_'.$this->application, $this->name);
77
            $params->set('language_'.$this->application, $this->name);
78
 
78
 
79
            //Save the params   
79
             //Save the params
80
            $result = $this->getService('com://admin/extensions.model.components', array('name' => 'components'))
80
            $result = $this->getService('com://admin/extensions.database.table.components')
81
                        ->select(array('option' => 'com_extensions'), KDatabase::FETCH_ROW) 
81
                           ->select(array('option' => 'com_extensions'), KDatabase::FETCH_ROW)
82
                        ->set('params', $params)       
82
                           ->set('params', $params)
83
                        ->save();
83
                           ->save();
84
 
84
            
85
            return $result;
85
            return $result;
86
        }
86
        }
87
 
87
 
35633564
90
            if(!$this->isNew()) 
90
            if(!$this->isNew()) 
91
            {
91
            {
92
                $table = $this->getService('com://admin/extensions.database.table.menus');
92
                $table = $this->getService('com://admin/extensions.database.table.menus');
93
                $query = $table->getDatabase()->getQuery()
93
                $query = $this->getService('koowa:database.query.select')
94
                                ->select('menuid')
94
                    ->columns('menuid')
95
                                ->where('moduleid', '=', $this->id);
95
                    ->where('moduleid = :id')
 
 
96
                    ->bind(array('id' => $this->id));
 
 
97
                
96
                $pages = $table->select($query, KDatabase::FETCH_FIELD_LIST);
98
                $pages = $table->select($query, KDatabase::FETCH_FIELD_LIST);
97
 
99
 
98
                if(count($pages) == 1 && $pages[0] == 0) {
100
                if(count($pages) == 1 && $pages[0] == 0) {
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
             ->insert('enabled', 'boolean')
27
             ->insert('enabled', 'boolean')
28
             ->insert('parent' , 'int')
28
             ->insert('parent' , 'int')
29
             ->insert('component' , 'cmd')
29
             ->insert('component' , 'cmd')
...
 
...
 
30
             ->insert('hidden' , 'boolean');    
30
             ->insert('hidden' , 'boolean');    
31
    }
31
    }
32
 
32
 
33
    protected function _buildQueryWhere(KDatabaseQuery $query)
33
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
34
    {
34
    {
35
        $state = $this->_state;
35
        parent::_buildQueryWhere($query);
 
 
36
        $state = $this->getState();
36
 
37
 
37
        if($state->search) {
38
        if($state->search) {
38
            $query->where('tbl.name', 'LIKE', '%'.$state->search.'%');
39
            $query->where('tbl.name LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
39
        }
40
        }
40
 
41
 
41
        if($state->component) {
42
        if($state->component) {
42
            $query->where('tbl.option', '=', $state->component);
43
            $query->where('tbl.option = :component')->bind(array('component' => $state->component));
43
        }
44
        }
44
 
45
 
45
        if(is_integer($state->parent)) {
46
        if(is_integer($state->parent)) {
46
            $query->where('tbl.parent', '=', $state->parent);
47
            $query->where('tbl.parent = :parent')->bind(array('parent' => $state->parent));
47
        }
48
        }
48
 
49
 
49
        if(is_bool($state->enabled)) {
50
        if(is_bool($state->enabled)) {
50
            $query->where('tbl.enabled', '=', (int) $state->enabled);
51
            $query->where('tbl.enabled :enabled')->bind(array('enabled' => (int) $state->enabled));
51
        }
52
        }
52
 
53
 
53
        if(is_bool($state->hidden)) {
54
        if(is_bool($state->hidden)) {
54
            $query->where('tbl.iscore', '=', (int) $state->hidden);
55
            $query->where('tbl.iscore = :hidden')->bind(array('hidden' => (int) $state->hidden));
55
        }
56
        }
56
    
 
 
57
        parent::_buildQueryWhere($query);
 
 
58
    }
57
    }
59
}
58
}
35633564
24
    {
24
    {
25
        parent::__construct($config);
25
        parent::__construct($config);
26
 
26
 
27
        $this->_state
27
        $this->getState()
28
            ->insert('limit'      , 'int', 0)
28
            ->insert('limit'      , 'int', 0)
29
            ->insert('offset'     , 'int', 0)
29
            ->insert('offset'     , 'int', 0)
30
            ->insert('direction'  , 'word', 'asc')
30
            ->insert('direction'  , 'word', 'asc')
...
 
...
 
37
    {
37
    {
38
        if (!isset($this->_item))
38
        if (!isset($this->_item))
39
        {
39
        {
40
            if($this->_state->isUnique())
40
            if($this->getState()->isUnique())
41
            {
41
            {
42
                $state = $this->_state;
42
                $state = $this->getState();
43
 
43
 
44
                //Get application information
44
                //Get application information
45
                $client    = JApplicationHelper::getClientInfo($state->application, true);
45
                $client    = JApplicationHelper::getClientInfo($state->application, true);
...
 
...
 
76
    {
76
    {
77
        if (!isset($this->_list))
77
        if (!isset($this->_list))
78
        {
78
        {
79
            $state     = $this->_state;
79
            $state     = $this->getState();
80
            $languages = array();
80
            $languages = array();
81
 
81
 
82
            foreach((array) KConfig::unbox($state->application) as $application)
82
            foreach((array) KConfig::unbox($state->application) as $application)
35633564
24
    {
24
    {
25
        parent::__construct($config);
25
        parent::__construct($config);
26
 
26
 
27
        $this->_state
27
        $this->getState()
28
             ->insert('application', 'cmd')
28
             ->insert('application', 'cmd')
29
             ->insert('sort'        , 'cmd', array('position', 'ordering'))
29
             ->insert('sort'        , 'cmd', array('position', 'ordering'))
30
             ->insert('enabled'      , 'boolean')
30
             ->insert('enabled'      , 'boolean')
...
 
...
 
34
             ->insert('hidden'     , 'boolean');
34
             ->insert('hidden'     , 'boolean');
35
    }
35
    }
36
 
36
 
37
    protected function _buildQueryJoin(KDatabaseQuery $query)
37
    protected function _buildQueryJoin(KDatabaseQuerySelect $query)
38
    {
38
    {
39
        $query
39
        $query
40
            ->join('left', 'users AS user', 'user.id = tbl.checked_out')
40
            ->join(array('user' => 'users'), 'user.id = tbl.checked_out')
41
            ->join('left', 'groups AS group', 'group.id = tbl.access')
41
            ->join(array('group' => 'groups'), 'group.id = tbl.access')
42
            ->join('left', 'modules_menu AS module_menu', 'module_menu.moduleid = tbl.id');
42
            ->join(array('module_menu' => 'modules_menu'), 'module_menu.moduleid = tbl.id');
43
 
43
 
44
        parent::_buildQueryJoin($query);
44
        parent::_buildQueryJoin($query);
45
    }
45
    }
46
 
46
 
47
    protected function _buildQueryWhere(KDatabaseQuery $query)
47
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
48
    {
48
    {
49
        $state = $this->_state;
49
        $state = $this->getState();
50
 
50
 
51
        if($state->search) {
51
        if($state->search) {
52
            $query->where('tbl.title', 'LIKE', '%'.$state->search.'%');
52
            $query->where('tbl.title LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
53
        }
53
        }
54
 
54
 
55
        if($state->position) {
55
        if($state->position) {
56
            $query->where('tbl.position', '=', $state->position);
56
            $query->where('tbl.position = :position')->bind(array('position' => $state->position));
57
        }
57
        }
58
 
58
 
59
        if($state->type) {
59
        if($state->type) {
60
            $query->where('tbl.module', '=', $state->type);
60
            $query->where('tbl.module = :type')->bind(array('type' => $state->type));
61
        }
61
        }
62
 
62
 
63
        if(is_bool($state->enabled)) {
63
        if(is_bool($state->enabled)) {
64
            $query->where('tbl.published', '=', (int) $state->enabled);
64
            $query->where('tbl.published = :enabled')->bind(array('enabled' => (int) $state->enabled));
65
        }
65
        }
66
 
66
 
67
        if(is_bool($state->hidden)) {
67
        if(is_bool($state->hidden)) {
68
            $query->where('tbl.iscore', '=', (int) $state->hidden);
68
            $query->where('tbl.iscore = :hidden')->bind(array('hidden' => (int) $state->hidden));
69
        }
69
        }
70
 
70
 
71
        if($state->application && is_scalar($state->application))
71
        if($state->application && is_scalar($state->application)) {
72
        {
 
 
73
            $client    = JApplicationHelper::getClientInfo($state->application, true);
72
            $client    = JApplicationHelper::getClientInfo($state->application, true);
74
            $query->where('tbl.client_id', '=', $client->id);
73
            $query->where('tbl.client_id = :client')->bind(array('client' => $client->id));
75
        }
74
        }
76
 
75
 
77
        parent::_buildQueryWhere($query);
76
        parent::_buildQueryWhere($query);
...
 
...
 
93
        {
92
        {
94
            $this->_item = parent::getItem();
93
            $this->_item = parent::getItem();
95
 
94
 
96
            if($this->_item->isNew() && $this->_state->type) 
95
            if($this->_item->isNew() && $this->getState()->type) 
97
            {
96
            {
98
                $client                    = JApplicationHelper::getClientInfo($this->_state->application, true);
97
                $client                    = JApplicationHelper::getClientInfo($this->getState()->application, true);
99
                $this->_item->client_id = $client->id;
98
                $this->_item->client_id = $client->id;
100
                $this->_item->type      = $this->_state->type;
99
                $this->_item->type      = $this->getState()->type;
101
            }
100
            }
102
        }
101
        }
103
 
102
 
...
 
...
 
116
    { 
115
    { 
117
        if(!isset($this->_list))
116
        if(!isset($this->_list))
118
        {
117
        {
119
            $state = $this->_state;
118
            $state = $this->getState();
120
 
119
 
121
            if($state->installed)
120
            if($state->installed)
122
            {
121
            {
...
 
...
 
152
                $this->_total = count($modules);
151
                $this->_total = count($modules);
153
 
152
 
154
                //Apply limit and offset
153
                //Apply limit and offset
155
                if($this->_state->limit) {
154
                if($this->getState()->limit) {
156
                    $modules = array_slice($modules, $state->offset, $state->limit ? $state->limit : $this->_total);
155
                    $modules = array_slice($modules, $state->offset, $state->limit ? $state->limit : $this->_total);
157
                }
156
                }
158
 
157
 
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
             ->insert('sort'   , 'cmd', 'folder')
27
             ->insert('sort'   , 'cmd', 'folder')
28
             ->insert('enabled', 'boolean')
28
             ->insert('enabled', 'boolean')
29
             ->insert('type'   , 'cmd')
29
             ->insert('type'   , 'cmd')
...
 
...
 
30
             ->insert('hidden' , 'boolean');    
30
             ->insert('hidden' , 'boolean');    
31
    }
31
    }
32
 
32
 
33
    protected function _buildQueryJoin(KDatabaseQuery $query)
33
    protected function _buildQueryJoin(KDatabaseQuerySelect $query)
34
    {
34
    {
35
        $query->join('left', 'groups AS group', 'group.id = tbl.access');
35
        $query->join(array('groups' => 'groups'), 'groups.id = tbl.access');
36
 
36
 
37
        parent::_buildQueryJoin($query);
37
        parent::_buildQueryJoin($query);
38
    }
38
    }
39
 
39
 
40
    protected function _buildQueryWhere(KDatabaseQuery $query)
40
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
41
    {
41
    {
42
        $state = $this->_state;
42
        parent::_buildQueryWhere($query);
 
 
43
        $state = $this->getState();
43
 
44
 
44
        if($state->search) {
45
        if($state->search) {
45
            $query->where('tbl.name', 'LIKE', '%'.$state->search.'%');
46
            $query->where('tbl.name LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
46
        }
47
        }
47
 
48
 
48
        if($state->type) {
49
        if($state->type) {
49
            $query->where('tbl.folder', '=', $state->type);
50
            $query->where('tbl.folder = :type')->bind(array('type' => $state->type));
50
        }
51
        }
51
 
52
 
52
        if(is_bool($state->enabled)) {
53
        if(is_bool($state->enabled)) {
53
            $query->where('tbl.published', '=', (int) $state->enabled);
54
            $query->where('tbl.published = :enabled')->bind(array('enabled' => (int) $state->enabled));
54
        }
55
        }
55
 
56
 
56
        if(is_bool($state->hidden)) {
57
        if(is_bool($state->hidden)) {
57
            $query->where('tbl.iscore', '=', (int) $state->hidden);
58
            $query->where('tbl.iscore = :hidden')->bind(array('hidden' => (int) $state->hidden));
58
        }
59
        }
59
 
 
 
60
        parent::_buildQueryWhere($query);
 
 
61
    }
60
    }
62
}
61
}
35633564
28
    {
28
    {
29
        parent::__construct($config);
29
        parent::__construct($config);
30
 
30
 
31
        $this->_state
31
        $this->getState()
32
            ->insert('limit'      , 'int')
32
            ->insert('limit'      , 'int')
33
            ->insert('offset'     , 'int')
33
            ->insert('offset'     , 'int')
34
            ->insert('sort'       , 'cmd')
34
            ->insert('sort'       , 'cmd')
...
 
...
 
47
    {
47
    {
48
        if(!isset($this->_item))
48
        if(!isset($this->_item))
49
        {
49
        {
50
            $state = $this->_state;
50
            $state = $this->getState();
51
 
51
 
52
            //Get application information
52
            //Get application information
53
            $client    = JApplicationHelper::getClientInfo($state->application, true);
53
            $client    = JApplicationHelper::getClientInfo($state->application, true);
...
 
...
 
87
    { 
87
    { 
88
        if(!isset($this->_list))
88
        if(!isset($this->_list))
89
        {
89
        {
90
            $state     = $this->_state;
90
            $state     = $this->getState();
91
            $templates = array();
91
            $templates = array();
92
 
92
 
93
            foreach((array) KConfig::unbox($state->application) as $application)
93
            foreach((array) KConfig::unbox($state->application) as $application)
...
 
...
 
121
            $this->_total = count($templates);
121
            $this->_total = count($templates);
122
 
122
 
123
            //Apply limit and offset
123
            //Apply limit and offset
124
            if($this->_state->limit) {
124
            if($this->getState()->limit) {
125
                $templates = array_slice($templates, $state->offset, $state->limit ? $state->limit : $this->_total);
125
                $templates = array_slice($templates, $state->offset, $state->limit ? $state->limit : $this->_total);
126
            }
126
            }
127
 
127
 
35633564
97
            <fieldset>
97
            <fieldset>
98
                <legend><?= @text('Custom Output') ?></legend>
98
                <legend><?= @text('Custom Output') ?></legend>
99
 
99
 
100
                <?= @editor(array(
100
                <?= @service('com://admin/editors.controller.editor')
101
                    'name'        => 'content',
 
 
102
                    //@TODO is escaping the module content really necessary?
101
                    //@TODO is escaping the module content really necessary?
103
                    'content'    => @escape($module->content),
102
                    ->name('content')
104
                    'height'    => 400,
103
                    ->data(@escape($module->content))
105
                    'cols'        => 60,
104
                    ->display() ?>
106
                    'buttons'    => array('pagebreak', 'readmore')
 
 
107
                )) ?>
 
 
108
            </fieldset>
105
            </fieldset>
109
            <? endif ?>
106
            <? endif ?>
110
        </div>
107
        </div>
35633564
39
                'modules/'                  => JPATH_SITE.'/modules',
39
                'modules/'                  => JPATH_SITE.'/modules',
40
                'plugins/'                  => JPATH_PLUGINS,
40
                'plugins/'                  => JPATH_PLUGINS,
41
                'plugins/content/'          => JPATH_PLUGINS.'/content',
41
                'plugins/content/'          => JPATH_PLUGINS.'/content',
42
                'plugins/editors/'          => JPATH_PLUGINS.'/editors',
 
 
43
                'plugins/editors-xtd/'      => JPATH_PLUGINS.'/editors-xtd',
 
 
44
                'plugins/search/'           => JPATH_PLUGINS.'/search',
42
                'plugins/search/'           => JPATH_PLUGINS.'/search',
45
                'plugins/system/'           => JPATH_PLUGINS.'/system',
43
                'plugins/system/'           => JPATH_PLUGINS.'/system',
46
                'plugins/user'              => JPATH_PLUGINS.'/user',
44
                'plugins/user'              => JPATH_PLUGINS.'/user',
35633564
12
/**
12
/**
13
 * Newsfeeds Model Class
13
 * Newsfeeds Model Class
14
 *
14
 *
15
 * @author      Babs Gšsgens <http://nooku.assembla.com/profile/babsgosgens>
15
 * @author      Babs Gösgens <http://nooku.assembla.com/profile/babsgosgens>
16
 * @category    Nooku
16
 * @category    Nooku
17
 * @package     Nooku_Server
17
 * @package     Nooku_Server
18
 * @subpackage  Newsfeeds
18
 * @subpackage  Newsfeeds
...
 
...
 
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        $this->_state
26
        $this->getState()
27
            ->insert('published', 'boolean')
27
            ->insert('published', 'boolean')
28
            ->insert('category' , 'int');
28
            ->insert('category' , 'slug');
29
    }
29
    }
30
 
30
 
31
    protected function _buildQueryColumns(KDatabaseQuery $query)
31
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
32
    {
32
    {
33
        parent::_buildQueryColumns($query);
33
        parent::_buildQueryColumns($query);
34
 
34
 
35
        $query->select('category.title AS category_title');
35
        $query->columns(array('category_title' => 'categories.title'));
36
    }
36
    }
37
 
37
 
38
    protected function _buildQueryJoins(KDatabaseQuery $query)
38
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
39
    {
39
    {
40
        // Exclude joins if counting records.
40
        // Exclude joins if counting records.
41
        if(!$query->count) {
41
        if(!$query->count) {
42
            $query->join('LEFT', 'categories AS category', 'category.id = tbl.catid');
42
            $query->join(array('categories' => 'categories'), 'categories.id = tbl.catid');
43
        }
43
        }
44
    }
44
    }
45
 
45
 
46
    protected function _buildQueryWhere(KDatabaseQuery $query)
46
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
47
    {
47
    {
48
        parent::_buildQueryWhere($query);
48
        parent::_buildQueryWhere($query);
 
 
49
        $state = $this->getState();
49
 
50
 
50
        $state = $this->_state;
 
 
51
 
 
 
52
        if (is_bool($state->published)) {
51
        if (is_bool($state->published)) {
53
            $query->where('tbl.published', '=', (int) $state->published);
52
            $query->where('tbl.published = :published')->bind(array('published' => (int) $state->published));
54
        }
53
        }
55
 
54
 
56
        if ($state->category) {
55
        if ($state->category) {
57
            $query->where('tbl.catid', '=', $state->category);
56
            $query->where('tbl.catid = :category')->bind(array('category' => (int) $state->category));
58
        }
57
        }
59
 
58
 
60
        if (!empty($state->search)) {
59
        if (!empty($state->search)) {
61
            $query->where('LOWER(tbl.name)', 'LIKE', '%'.strtolower($state->search).'%');
60
            $query->where('tbl.name LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
62
        }
61
        }
63
    }
62
    }
64
 
63
 
65
    protected function _buildQueryOrder(KDatabaseQuery $query)
64
    protected function _buildQueryOrder(KDatabaseQuerySelect $query)
66
    {
65
    {
67
        $sort       = $this->_state->sort;
66
        $state = $this->getState();
68
        $direction  = strtoupper($this->_state->direction);
67
 
 
 
68
        $sort       = $state->sort;
 
 
69
        $direction  = strtoupper($state->direction);
69
 
70
 
70
        if($sort) {
71
        if($sort) {
71
            $query->order($this->getTable()->mapColumns($sort), $direction);
72
            $query->order($this->getTable()->mapColumns($sort), $direction);
...
 
...
 
72
        }
73
        }
73
 
74
 
74
        if(array_key_exists('ordering', $this->getTable()->getColumns())) {
75
        if(array_key_exists('ordering', $this->getTable()->getColumns())) {
75
            $query->order('category.title, tbl.ordering', 'ASC');
76
            $query->order('categories.title, tbl.ordering', 'ASC');
76
        }
77
        }
77
    }
78
    }
78
}
79
}
35633564
24
    {
24
    {
25
        parent::__construct($config);
25
        parent::__construct($config);
26
 
26
 
27
        $this->_state
27
        $this->getState()
28
             ->insert('name', 'cmd', null, true);        
28
             ->insert('name', 'cmd', null, true);        
29
    }
29
    }
30
 
30
 
31
    public function getItem()
31
    public function getItem()
32
    {
32
    {
33
        if(isset($this->getList()->{$this->_state->name})) {
33
        if(isset($this->getList()->{$this->getState()->name})) {
34
            $row = $this->getList()->{$this->_state->name};
34
            $row = $this->getList()->{$this->getState()->name};
35
        } else {
35
        } else {
36
            $row = $this->getList()->getRow();
36
            $row = $this->getList()->getRow();
37
        }
37
        }
35633564
20
 
20
 
21
class ComSettingsTemplateHelperListbox extends ComDefaultTemplateHelperListbox
21
class ComSettingsTemplateHelperListbox extends ComDefaultTemplateHelperListbox
22
{
22
{
23
    public function editors($config = array())
 
 
24
    {
 
 
25
        $config = new KConfig($config);
 
 
26
        $config->append(array(
 
 
27
            'name'        => 'editor'
 
 
28
        ));
 
 
29
       
 
 
30
        $editors = $this->getService('com://admin/extensions.model.plugins')
 
 
31
                    ->type('editors')
 
 
32
                    ->enabled(1)
 
 
33
                    ->sort(array('ordering', 'name'))
 
 
34
                    ->getList();
 
 
35
    
 
 
36
        foreach($editors as $editor) {
 
 
37
            $options[]     = $this->option(array('text' => JText::_($editor->title), 'value' => $editor->name));
 
 
38
        }
 
 
39
 
 
 
40
        $list = $this->optionlist(array(
 
 
41
            'options'   => $options,
 
 
42
            'name'      => $config->name,
 
 
43
            'selected'  => $config->selected,
 
 
44
            'attribs'   => $config->attribs
 
 
45
        ));
 
 
46
 
 
 
47
        return $list;
 
 
48
    }
 
 
49
 
 
 
50
    public function list_limits($config = array())
23
    public function list_limits($config = array())
51
    {
24
    {
52
        $config = new KConfig($config);
25
        $config = new KConfig($config);
35633564
31
<fieldset class="form-horizontal">
31
<fieldset class="form-horizontal">
32
    <legend><?= @text( 'Defaults' ); ?></legend>
32
    <legend><?= @text( 'Defaults' ); ?></legend>
33
    <div class="control-group">
33
    <div class="control-group">
34
        <label class="control-label" for="settings[system][editor]"><?= @text( 'WYSIWYG Editor' ); ?></label>
 
 
35
        <div class="controls">
 
 
36
            <?= @helper('listbox.editors', array('name' => 'settings[system][editor]', 'selected' => $settings->editor)); ?>
 
 
37
            <p class="help-block"><?= @text( 'TIPDEFWYSIWYG' ); ?></p>
 
 
38
        </div>
 
 
39
    </div>
 
 
40
    <div class="control-group">
 
 
41
        <label class="control-label" for="settings[system][list_limit]"><?= @text( 'List Length' ); ?></label>
34
        <label class="control-label" for="settings[system][list_limit]"><?= @text( 'List Length' ); ?></label>
42
        <div class="controls">
35
        <div class="controls">
43
            <?= @helper('listbox.list_limits', array('name' => 'settings[system][list_limit]', 'selected' =>
$settings->list_limit)); ?>
36
            <?= @helper('listbox.list_limits', array('name' => 'settings[system][list_limit]', 'selected' =>
$settings->list_limit)); ?>
35633564
23
     {
23
     {
24
         parent::__construct($config);
24
         parent::__construct($config);
25
 
25
 
26
         $this->_state
26
         $this->getState()
27
             ->insert('name'      , 'cmd', null, true)
27
             ->insert('name'      , 'cmd', null, true)
28
             ->insert('limit'     , 'int')
28
             ->insert('limit'     , 'int')
29
             ->insert('offset'    , 'int')
29
             ->insert('offset'    , 'int')
...
 
...
 
50
    { 
50
    { 
51
        if(!isset($this->_list))
51
        if(!isset($this->_list))
52
        {
52
        {
 
 
53
            $state = $this->getState();
53
            $data = array();
54
            $data = array();
54
 
55
 
55
            //Get the sites
56
            //Get the sites
...
 
...
 
66
            //Apply state information
67
            //Apply state information
67
            foreach($data as $key => $value)
68
            foreach($data as $key => $value)
68
            {   
69
            {   
69
                if($this->_state->search)
70
                if($state->search)
70
                {
71
                {
71
                     if($value->name != $this->_state->search) {
72
                     if($value->name != $state->search) {
72
                         unset($data[$key]);
73
                         unset($data[$key]);
73
                      }
74
                      }
74
                }
75
                }
...
 
...
 
78
            $this->_total = count($data);
79
            $this->_total = count($data);
79
 
80
 
80
            //Apply limit and offset
81
            //Apply limit and offset
81
            if($this->_state->limit) {
82
            if($state->limit) {
82
                $data = array_slice($data, $this->_state->offset, $this->_state->limit);
83
                $data = array_slice($data, $state->offset, $state->limit);
83
            }
84
            }
84
 
85
 
85
            $this->_list = $this->getService('com://admin/sites.database.rowset.sites', array('data' => $data));
86
            $this->_list = $this->getService('com://admin/sites.database.rowset.sites', array('data' => $data));
35633564
60
 
60
 
61
    protected function _actionDelete(KCommandContext $context)
61
    protected function _actionDelete(KCommandContext $context)
62
    {
62
    {
63
        $rowset = parent::_actionDelete($context);
63
        $data = parent::_actionDelete($context);
64
 
64
        
65
        $this->getService('com://admin/users.model.sessions')
65
        $this->getService('com://admin/users.model.sessions')
66
            ->username($rowset->username)
66
            ->username($data->username)
67
            ->getList()
67
            ->getList()
68
            ->delete();
68
            ->delete();
69
 
69
 
70
        return $rowset;
70
        return $data;
71
    }
71
    }
72
 
72
 
73
    protected function _actionLogin(KCommandContext $context)
73
    protected function _actionLogin(KCommandContext $context)
35633564
3
    <name>Author User Type</name>
3
    <name>Author User Type</name>
4
    <params>
4
    <params>
5
        <param name="language" type="languages" client="site" default="" label="Front-end Language"
description="paramLanguage" />
5
        <param name="language" type="languages" client="site" default="" label="Front-end Language"
description="paramLanguage" />
6
        <param name="editor" type="editors" default="" label="User Editor" description="WYSIWYG Editor for this User" />
 
 
7
    </params>
6
    </params>
8
</form>
7
</form>
35633564
87
 
87
 
88
       if($this->isModified('username'))
88
       if($this->isModified('username'))
89
       {
89
       {
90
            $query = $this->getTable()->getDatabase()->getQuery()
90
            $query = $this->getService('koowa:database.query.select')
91
                        ->where('username', '=', $this->username)
91
                ->where('username', '=', $this->username)
92
                        ->where('id', '<>', (int) $this->id);
92
                ->where('id', '<>', (int) $this->id);
93
 
93
 
94
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
94
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
95
 
95
 
...
 
...
 
112
 
112
 
113
        if($this->isModified('email'))
113
        if($this->isModified('email'))
114
        {
114
        {
115
            $query = $this->getTable()->getDatabase()->getQuery()
115
            $query = $this->getService('koowa:database.query.select')
116
                        ->where('email', '=', $this->email)
116
                ->where('email', '=', $this->email)
117
                        ->where('id', '<>', (int) $this->id);
117
                ->where('id', '<>', (int) $this->id);
118
 
118
 
119
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
119
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
120
 
120
 
...
 
...
 
190
        // Don't allow users to change the user level of the last active super administrator.
190
        // Don't allow users to change the user level of the last active super administrator.
191
        if(isset($this->_modifid['users_group_id']) && $old_row->users_group_id != 25)
191
        if(isset($this->_modifid['users_group_id']) && $old_row->users_group_id != 25)
192
        {
192
        {
193
            $query = $this->getTable()->getDatabase()->getQuery()
193
            $query = $this->getService('koowa:database.query.select')
194
                        ->where('users_group_id', '=', 25)
194
                ->where('users_group_id', '=', 25)
195
                        ->where('enabled', '=', 1);
195
                ->where('enabled', '=', 1);
196
 
196
 
197
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
197
            $total = $this->getService('com://admin/users.database.table.users')->count($query);
198
 
198
 
...
 
...
 
239
            $this->registered_on = gmdate('Y-m-d H:i:s', time());
239
            $this->registered_on = gmdate('Y-m-d H:i:s', time());
240
        }
240
        }
241
 
241
 
242
        $query = $this->getTable()->getDatabase()->getQuery()
242
        // TODO: This shouldn't be executed on every save.
243
                    ->select('name')
243
        $query = $this->getService('koowa:database.query.select')
244
                    ->where('id', '=', $this->users_group_id);
244
            ->columns('name')
 
 
245
            ->where('id = :id')
 
 
246
            ->bind(array('id' => $this->users_group_id));
245
 
247
 
246
        $this->group_name = $this->getService('com://admin/users.database.table.groups')
248
        $this->group_name = $this->getService('com://admin/users.database.table.groups')
247
                                ->select($query, KDatabase::FETCH_FIELD);
249
            ->select($query, KDatabase::FETCH_FIELD);
248
 
250
 
249
        // Set parameters.
251
        // Set parameters.
250
        if($this->isModified('params'))
252
        if($this->isModified('params'))
35633564
3
    <params>
3
    <params>
4
        <param name="admin_language" type="languages" client="administrator" default="" label="Back-end
Language" description="paramAdminLanguage" />
4
        <param name="admin_language" type="languages" client="administrator" default="" label="Back-end
Language" description="paramAdminLanguage" />
5
        <param name="language" type="languages" client="site" default="" label="Front-end Language"
description="paramLanguage" />
5
        <param name="language" type="languages" client="site" default="" label="Front-end Language"
description="paramLanguage" />
6
        <param name="editor" type="editors" default="" label="User Editor" description="WYSIWYG Editor for this User" />
 
 
7
    </params>
6
    </params>
8
</form>
7
</form>
35633564
23
    {
23
    {
24
        parent::__construct($config);
24
        parent::__construct($config);
25
 
25
 
26
        //Make sure the email and username fields are unique
 
 
27
        $this->getColumn('email')->unique = true;
 
 
28
        $this->getColumn('username')->unique = true;
 
 
29
 
 
 
30
        $this->getColumn('users_group_id')->default = 0;
26
        $this->getColumn('users_group_id')->default = 0;
31
        $this->getColumn('enabled')->default = 1;
27
        $this->getColumn('enabled')->default = 1;
32
    }
28
    }
...
 
...
 
44
                'users_group_id'    => 'gid',
40
                'users_group_id'    => 'gid',
45
                'registered_on'        => 'registerDate',
41
                'registered_on'        => 'registerDate',
46
                'last_visited_on'    => 'lastvisitDate'
42
                'last_visited_on'    => 'lastvisitDate'
47
            )
43
            ),
 
 
44
            'behaviors' => array('identifiable')
48
        ));
45
        ));
49
 
46
        
50
        parent::_initialize($config);
47
        parent::_initialize($config);
51
    }
48
    }
52
}
49
}
35633564
39
     */
39
     */
40
    public function getRandom($length = 8)
40
    public function getRandom($length = 8)
41
    {
41
    {
42
        $salt        = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
42
        $bytes  = '';
43
        $password    = '';
43
        $return = '';
44
 
44
        
45
        for($i = 0; $i < $length; $i ++) {
45
        if (function_exists('openssl_random_pseudo_bytes') && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
46
            $password .= $salt[mt_rand(0, strlen($salt) -1)];
46
            $bytes = openssl_random_pseudo_bytes($length + 1);
47
        }
47
        }
48
 
48
        
49
        return $password;
49
        if ($bytes === '' && @is_readable('/dev/urandom') && ($handle = @fopen('/dev/urandom', 'rb')) !== false) {
 
 
50
            $bytes = fread($handle, $length + 1);
 
 
51
            fclose($handle);
 
 
52
        }
 
 
53
        
 
 
54
        if (strlen($bytes) < $length + 1) {
 
 
55
            $bytes = '';
 
 
56
            $random_state = microtime();
 
 
57
            
 
 
58
            if (function_exists('getmypid')) {
 
 
59
                $random_state .= getmypid();
 
 
60
            }
 
 
61
        
 
 
62
            for ($i = 0; $i < $length + 1; $i += 16) {
 
 
63
                $random_state = md5(microtime().$random_state);
 
 
64
                $bytes .= md5($random_state, true);
 
 
65
            }
 
 
66
            
 
 
67
            $bytes = substr($bytes, 0, $length + 1);
 
 
68
        }
 
 
69
        
 
 
70
        $salt  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 
 
71
        $shift = ord($bytes[0]);
 
 
72
        
 
 
73
        for ($i = 1; $i <= $length; ++$i) {
 
 
74
            $return .= $salt[($shift + ord($bytes[$i])) % strlen($salt)];
 
 
75
            $shift += ord($bytes[$i]);
 
 
76
        }
 
 
77
        
 
 
78
        return $return;
50
    }
79
    }
51
 
80
 
52
    /**
81
    /**
35633564
28
    {
28
    {
29
        parent::__construct($config);
29
        parent::__construct($config);
30
 
30
 
31
        $this->_state->insert('username', 'alnum');
31
        $this->getState()->insert('username', 'alnum');
32
    }
32
    }
33
 
33
 
34
    /**
34
    /**
...
 
...
 
37
     * @param   KDatabaseQuery  A query object.
37
     * @param   KDatabaseQuery  A query object.
38
     * @return  void
38
     * @return  void
39
     */
39
     */
40
    protected function _buildQueryWhere(KDatabaseQuery $query)
40
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
41
    {
41
    {
42
        parent::_buildQueryWhere($query);
42
        parent::_buildQueryWhere($query);
43
 
43
        $state = $this->getState();
44
        if($this->_state->username) {
44
 
45
            $query->where('username', 'IN', $this->_state->username);
45
        if ($state->username) {
 
 
46
            $query->where('username = :username')->bind(array('username' => $state->username));
46
        }
47
        }
47
    }
48
    }
48
}
49
}
35633564
28
    {
28
    {
29
        parent::__construct($config);
29
        parent::__construct($config);
30
 
30
 
31
        $this->_state
31
        $this->getState()
32
            ->insert('activation' , 'md5', null, true)
32
            ->insert('activation' , 'md5', null, true)
33
            ->insert('email'      , 'email', null, true)
33
            ->insert('email'      , 'email', null, true)
34
            ->insert('username'   , 'alnum', null, true)
34
            ->insert('username'   , 'alnum', null, true)
...
 
...
 
46
     * @param   KDatabaseQuery  A query object.
46
     * @param   KDatabaseQuery  A query object.
47
     * @return  void
47
     * @return  void
48
     */
48
     */
49
    protected function _buildQueryColumns(KDatabaseQuery $query)
49
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
50
    {
50
    {
51
        parent::_buildQueryColumns($query);
51
        parent::_buildQueryColumns($query);
52
        $state = $this->_state;
52
        $state = $this->getState();
53
 
53
 
54
        $query->select('IF(session.session_id IS NOT NULL, 1, 0) AS loggedin');
54
        $query->columns(array(
55
        $query->select('IF(tbl.block = 1, 0, 1) AS enabled');
55
            'loggedin' => 'IF(session.session_id IS NOT NULL, 1, 0)',
 
 
56
            'enabled'  => 'IF(tbl.block = 1, 0, 1)'
 
 
57
        ));
56
 
58
 
57
        if($state->loggedin) {
59
        if($state->loggedin) {
58
            $query->select(array('session.client_id AS loggedin_client_id', 'session.time AS loggedin_on', 'session.session_id AS loggedin_session_id'));
60
            $query->columns(array(
 
 
61
                'loggedin_client_id'  => 'session.client_id',
 
 
62
                'loggedin_on'         => 'session.time',
 
 
63
                'loggedin_session_id' => 'session.session_id',
 
 
64
            ));
59
        }
65
        }
60
    }
66
    }
61
 
67
 
...
 
...
 
65
     * @param   KDatabaseQuery  A query object.
71
     * @param   KDatabaseQuery  A query object.
66
     * @return  void
72
     * @return  void
67
     */
73
     */
68
    protected function _buildQueryJoins(KDatabaseQuery $query)
74
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
69
    {
75
    {
70
        $state = $this->_state;
76
        $state = $this->getState();
71
 
77
 
72
        $query->join($state->loggedin ? 'RIGHT' : 'LEFT', 'session AS session', 'tbl.id = session.userid');
78
        $query->join(array('session' => 'session'), 'tbl.id = session.userid', $state->loggedin ? 'RIGHT' : 'LEFT');
73
    }
79
    }
74
 
80
 
75
    /**
81
    /**
...
 
...
 
78
     * @param   KDatabaseQuery  A query object.
84
     * @param   KDatabaseQuery  A query object.
79
     * @return  void
85
     * @return  void
80
     */
86
     */
81
    protected function _buildQueryWhere(KDatabaseQuery $query)
87
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
82
    {
88
    {
83
        parent::_buildQueryWhere($query);
89
        parent::_buildQueryWhere($query);
84
        $state = $this->_state;
90
        $state = $this->getState();
85
 
91
 
86
        if($state->group)  {
92
        if ($state->group)  {
87
            $query->where('tbl.gid', $state->group_tree ? '>=' : '=', $state->group);
93
            $query->where('tbl.gid '.($state->group_tree ? '>=' : '=').' :group_id')->bind(array('group_id' => $state->group));
88
        }
94
        }
89
 
 
 
90
        if($state->group_name) {
 
 
91
            $query->where('LOWER(tbl.usertype)', '=', $state->group_name);
 
 
92
        }
 
 
93
 
95
 
94
        if(is_bool($state->enabled)) {
96
        if (is_bool($state->enabled)) {
95
            $query->where('tbl.block', '=', (int) $state->enabled);
97
            $query->where('tbl.block = :enabled')->bind(array('enabled' => $state->enabled ? 0 : 1));
96
        }
98
        }
97
 
99
 
98
        if($state->loggedin === false) {
100
        if ($state->loggedin === false) {
99
            $query->where('loggedin', 'IS NULL');
101
            $query->where('loggedin IS NULL');
100
        }
102
        }
101
 
103
 
102
        if(is_bool($state->visited)) {  
104
        if (is_bool($state->visited)) {  
103
            $query->where('lastvisitDate', $state->visited ? '!=' : '=', '0000-00-00 00:00:00');
105
            $query->where('lastvisitDate '.($state->visited ? '!=' : '=').' :last_visited_on')->bind(array('last_visited_on', '0000-00-00 00:00:00'));
104
        }
106
        }
105
 
107
 
106
        if($state->search) {
108
        if ($state->search) {
107
            $query->where('tbl.name', 'LIKE', '%'.$state->search.'%')
109
            $query->where('tbl.name LIKE :search')
108
                  ->where('tbl.email', 'LIKE', '%'.$state->search.'%', 'OR');
110
                ->where('tbl.name LIKE :search', 'OR')
 
 
111
                ->bind(array('search' => '%'.$state->search.'%'));
109
        }
112
        }
110
    }
113
    }
111
}
114
}
35633564
28
        parent::_initialize($config);
28
        parent::_initialize($config);
29
    }
29
    }
30
 
30
 
31
    protected function _buildQueryColumns(KDatabaseQuery $query)
31
    protected function _buildQueryColumns(KDatabaseQuerySelect $query)
32
    {
32
    {
33
        parent::_buildQueryColumns($query);
33
        parent::_buildQueryColumns($query);
34
 
34
 
35
        $query->select('COUNT(weblinks.id) AS numlinks');
35
        $query->columns(array('numlinks' => 'COUNT(weblinks.id)'));
36
    }
36
    }
37
 
37
 
38
    protected function _buildQueryGroup(KDatabaseQuery $query)
38
    protected function _buildQueryJoins(KDatabaseQuerySelect $query)
39
    {
39
    {
40
        parent::_buildQueryGroup($query);
40
        $query->join(array('weblinks' => 'weblinks'), 'weblinks.catid = tbl.id');
41
        
 
 
42
        $query->group('tbl.id');
 
 
43
    }
41
    }
44
 
42
 
45
    protected function _buildQueryJoins(KDatabaseQuery $query)
43
    protected function _buildQueryWhere(KDatabaseQuerySelect $query)
46
    {
44
    {
47
        parent::_buildQueryJoins($query);
45
        parent::_buildQueryWhere($query);
48
 
46
 
49
        $query->join('LEFT', 'weblinks AS weblinks', 'weblinks.catid = tbl.id');
47
        $query->where('tbl.section = :section')
 
 
48
            ->where('tbl.published = :published')
 
 
49
            ->where('weblinks.published :weblinks_published')
 
 
50
            ->where('tbl.access <= :access');
 
 
51
            
 
 
52
        $query->bind(array(
 
 
53
            'section' => 'com_weblinks',
 
 
54
            'published' => 1,
 
 
55
            'weblinks_publihsed' => 1,
 
 
56
            'access' => JFactory::getUser()->get('aid', '0')
 
 
57
        ));
50
    }
58
    }
51
 
59
    
52
    protected function _buildQueryOrder(KDatabaseQuery $query)
60
    protected function _buildQueryGroup(KDatabaseQuerySelect $query)
53
    {
61
    {
54
        parent::_buildQueryOrder($query);
62
        parent::_buildQueryGroup($query);
55
 
63
 
56
        $query->order('tbl.ordering', 'DESC');
64
        $query->group('tbl.id');
57
    }
65
    }
58
 
66
 
59
    protected function _buildQueryWhere(KDatabaseQuery $query)
67
    protected function _buildQueryOrder(KDatabaseQuerySelect $query)
60
    {
68
    {
61
        parent::_buildQueryWhere($query);
69
        parent::_buildQueryOrder($query);
62
 
70
 
63
        $query->where('tbl.section', '=', 'com_weblinks')
71
        $query->order('tbl.ordering', 'DESC');
64
              ->where('tbl.published', '=', '1')
 
 
65
              ->where('weblinks.published', '=', '1')
 
 
66
              ->where('tbl.access', '<=', JFactory::getUser()->get('aid', '0'));
 
 
67
    }
72
    }
68
}
73
}
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff
File was changed - ok, show the diff