Code Duplication    Length = 67-70 lines in 2 locations

main/wiki/wiki.inc.php 2 locations

@@ 4674-4740 (lines=67) @@
4671
    /**
4672
     * @param string $action
4673
     */
4674
    public function getMostChangedPages($action)
4675
    {
4676
        $_course = $this->courseInfo;
4677
        $tbl_wiki = $this->tbl_wiki;
4678
        $course_id = $this->course_id;
4679
        $condition_session = $this->condition_session;
4680
        $groupfilter = $this->groupfilter;
4681
4682
        echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
4683
4684
        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
4685
            $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
4686
                    WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
4687
                    GROUP BY reflink';//TODO:check MAX and group by return last version
4688
        } else {
4689
            $sql = 'SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.'
4690
                    WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1
4691
                    GROUP BY reflink'; //TODO:check MAX and group by return last version
4692
        }
4693
4694
        $allpages = Database::query($sql);
4695
4696
        //show table
4697
        if (Database::num_rows($allpages) > 0) {
4698
            $rows = array();
4699
            while ($obj = Database::fetch_object($allpages)) {
4700
                //get type assignment icon
4701
                $ShowAssignment = '';
4702
                if ($obj->assignment == 1) {
4703
                    $ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
4704
                } elseif ($obj->assignment == 2) {
4705
                    $ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
4706
                } elseif ($obj->assignment == 0) {
4707
                    $ShowAssignment = Display::return_icon('px_transparent.gif');
4708
                }
4709
4710
                $row = array();
4711
                $row[] = $ShowAssignment;
4712
                $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
4713
                    api_htmlentities($obj->title).'</a>';
4714
                $row[] = $obj->MAX;
4715
                $rows[] = $row;
4716
            }
4717
4718
            $table = new SortableTableFromArrayConfig(
4719
                $rows,
4720
                2,
4721
                10,
4722
                'MostChangedPages_table',
4723
                '',
4724
                '',
4725
                'DESC'
4726
            );
4727
            $table->set_additional_parameters(
4728
                array(
4729
                    'cidReq' => Security::remove_XSS($_GET['cidReq']),
4730
                    'action' => Security::remove_XSS($action),
4731
                    'session_id' => intval($_GET['session_id']),
4732
                    'group_id' => intval($_GET['group_id']),
4733
                )
4734
            );
4735
            $table->set_header(
4736
                0,
4737
                get_lang('Type'),
4738
                true,
4739
                array('style' => 'width:30px;')
4740
            );
4741
            $table->set_header(1, get_lang('Title'), true);
4742
            $table->set_header(2, get_lang('Changes'), true);
4743
            $table->display();
@@ 5273-5342 (lines=70) @@
5270
    /**
5271
     * Most visited
5272
     */
5273
    public function getMostVisited()
5274
    {
5275
        $tbl_wiki = $this->tbl_wiki;
5276
        $course_id = $this->course_id;
5277
        $groupfilter = $this->groupfilter;
5278
        $condition_session = $this->condition_session;
5279
        $_course = $this->courseInfo;
5280
5281
        echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
5282
5283
        if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { //only by professors if page is hidden
5284
            $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
5285
                    WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'
5286
                    GROUP BY reflink';
5287
        } else {
5288
            $sql = 'SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.'
5289
                    WHERE
5290
                        c_id = '.$course_id.' AND
5291
                        '.$groupfilter.$condition_session.' AND
5292
                        visibility=1
5293
                    GROUP BY reflink';
5294
        }
5295
5296
        $allpages = Database::query($sql);
5297
5298
        //show table
5299
        if (Database::num_rows($allpages) > 0) {
5300
            $rows = array();
5301
            while ($obj = Database::fetch_object($allpages)) {
5302
                //get type assignment icon
5303
                $ShowAssignment = '';
5304
                if ($obj->assignment == 1) {
5305
                    $ShowAssignment = Display::return_icon(
5306
                        'wiki_assignment.png',
5307
                        get_lang('AssignmentDesc'),
5308
                        '',
5309
                        ICON_SIZE_SMALL
5310
                    );
5311
                } elseif ($obj->assignment == 2) {
5312
                    $ShowAssignment = $ShowAssignment = Display::return_icon(
5313
                        'wiki_work.png',
5314
                        get_lang('AssignmentWork'),
5315
                        '',
5316
                        ICON_SIZE_SMALL
5317
                    );
5318
                } elseif ($obj->assignment == 0) {
5319
                    $ShowAssignment = Display::return_icon(
5320
                        'px_transparent.gif'
5321
                    );
5322
                }
5323
5324
                $row = array();
5325
                $row[] = $ShowAssignment;
5326
                $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
5327
                    api_htmlentities($obj->title).'</a>';
5328
                $row[] = $obj->tsum;
5329
                $rows[] = $row;
5330
            }
5331
5332
            $table = new SortableTableFromArrayConfig(
5333
                $rows,
5334
                2,
5335
                10,
5336
                'MostVisitedPages_table',
5337
                '',
5338
                '',
5339
                'DESC'
5340
            );
5341
            $table->set_additional_parameters(
5342
                array(
5343
                    'cidReq' => Security::remove_XSS($_GET['cidReq']),
5344
                    'action' => Security::remove_XSS($this->action),
5345
                    'session_id' => intval($_GET['session_id']),