Completed
Push — master ( 16270d...f28230 )
by Michael
03:23
created

latest_files.php ➔ publisher_latest_files_edit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 23
Ratio 95.83 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 1
dl 23
loc 24
rs 8.9713
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Publisher
16
 * @subpackage      Blocks
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
24
include_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * @param $options
28
 *
29
 * @return array
30
 */
31
function publisher_latest_files_show($options)
32
{
33
    $publisher = PublisherPublisher::getInstance();
34
    /**
35
     * $options[0] : Category
36
     * $options[1] : Sort order - datesub | counter
37
     * $options[2] : Number of files to display
38
     * $oprions[3] : bool TRUE to link to the file download, FALSE to link to the article
39
     */
40
41
    $block = array();
42
43
    $sort           = $options[1];
44
    $order          = publisherGetOrderBy($sort);
45
    $limit          = $options[2];
46
    $directDownload = $options[3];
47
48
    // creating the files objects
49
    $filesObj = $publisher->getHandler('file')->getAllFiles(0, PublisherConstants::PUBLISHER_STATUS_FILE_ACTIVE, $limit, 0, $sort, $order, explode(',', $options[0]));
50
    foreach ($filesObj as $fileObj) {
51
        $aFile         = array();
52
        $aFile['link'] = $directDownload ? $fileObj->getFileLink() : $fileObj->getItemLink();
53
        if ($sort === 'datesub') {
54
            $aFile['new'] = $fileObj->getDatesub();
55
        } elseif ($sort === 'counter') {
56
            $aFile['new'] = $fileObj->counter();
57
        } elseif ($sort === 'weight') {
58
            $aFile['new'] = $fileObj->weight();
59
        }
60
        $block['files'][] = $aFile;
61
    }
62
63
    return $block;
64
}
65
66
/**
67
 * @param $options
68
 *
69
 * @return string
70
 */
71 View Code Duplication
function publisher_latest_files_edit($options)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
{
73
    include_once PUBLISHER_ROOT_PATH . '/class/blockform.php';
74
    xoops_load('XoopsFormLoader');
75
76
    $form = new PublisherBlockForm();
77
78
    $catEle   = new XoopsFormLabel(_MB_PUBLISHER_SELECTCAT, publisherCreateCategorySelect($options[0], 0, true, 'options[0]'));
79
    $orderEle = new XoopsFormSelect(_MB_PUBLISHER_ORDER, 'options[1]', $options[1]);
80
    $orderEle->addOptionArray(array(
81
                                  'datesub' => _MB_PUBLISHER_DATE,
82
                                  'counter' => _MB_PUBLISHER_HITS,
83
                                  'weight'  => _MB_PUBLISHER_WEIGHT
84
                              ));
85
    $dispEle   = new XoopsFormText(_MB_PUBLISHER_DISP, 'options[2]', 10, 255, $options[2]);
86
    $directEle = new XoopsFormRadioYN(_MB_PUBLISHER_DIRECTDOWNLOAD, 'options[3]', $options[3]);
87
88
    $form->addElement($catEle);
89
    $form->addElement($orderEle);
90
    $form->addElement($dispEle);
91
    $form->addElement($directEle);
92
93
    return $form->render();
94
}
95