Completed
Pull Request — master (#29)
by Goffy
01:44
created

protocol.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ****************************************************************************
4
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
5
 * ****************************************************************************
6
 *  XNEWSLETTER - MODULE FOR XOOPS
7
 *  Copyright (c) 2007 - 2012
8
 *  Goffy ( wedega.com )
9
 *
10
 *  You may not change or alter any portion of this comment or credits
11
 *  of supporting developers from this source code or any supporting
12
 *  source code which is considered copyrighted (c) material of the
13
 *  original comment or credit authors.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *  ---------------------------------------------------------------------------
20
 * @copyright  Goffy ( wedega.com )
21
 * @license    GPL 2.0
22
 * @package    xnewsletter
23
 * @author     Goffy ( [email protected] )
24
 *
25
 * ****************************************************************************
26
 */
27
28
use Xmf\Request;
29
use XoopsModules\Xnewsletter;
30
31
$currentFile = basename(__FILE__);
32
require_once __DIR__ . '/header.php';
33
34
$GLOBALS['xoopsOption']['template_main'] = 'xnewsletter_protocol.tpl';
35
require_once XOOPS_ROOT_PATH . '/header.php';
36
37
$xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
38
$xoTheme->addMeta('meta', 'keywords', $helper->getConfig('keywords')); // keywords only for index page
39
$xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
40
// breadcrumb
41
$breadcrumb = new Xnewsletter\Breadcrumb();
42
$breadcrumb->addLink($helper->getModule()->getVar('name'), XNEWSLETTER_URL);
43
$breadcrumb->addLink(_MD_XNEWSLETTER_LIST, 'javascript:history.go(-1)');
44
$breadcrumb->addLink(_MD_XNEWSLETTER_PROTOCOL, '');
45
$xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
46
47
$op        = Request::getString('op', 'list_protocols');
48
$letter_id = Request::getInt('letter_id', 0);
49
50
$letterObj = $helper->getHandler('Letter')->get($letter_id);
51
$xoopsTpl->assign('letter', $letterObj->toArray());
52
53
$protocolCriteria = new \CriteriaCompo();
54
$protocolCriteria->add(new \Criteria('protocol_letter_id', $letter_id));
55
$start       = Request::getInt('start', 0);
56
$limit       = $helper->getConfig('adminperpage');
57
$protocolCriteria->setSort('protocol_id');
58
$protocolCriteria->setOrder('DESC');
59
$protocolCount = $helper->getHandler('Protocol')->getCount($protocolCriteria);
60
$protocolCriteria->setStart($start);
61
$protocolCriteria->setLimit($limit);
62
63
// pagenav
64 View Code Duplication
if ($protocolCount > $limit) {
0 ignored issues
show
This code seems to be duplicated across 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...
65
    $pagenav = new \XoopsPageNav($protocolCount, $limit, $start, 'start', "op={$op}&letter_id={$letter_id}");
66
    $xoopsTpl->assign('pagenav', $pagenav->renderNav());
67
}
68
69
// protocol table
70
if ($protocolCount > 0) {
71
    $protocolObjs = $helper->getHandler('Protocol')->getAll($protocolCriteria, null, true, true);
72
    foreach ($protocolObjs as $protocol_id => $protocolObj) {
73
        $protocol_array = $protocolObj->toArray();
74
        $subscrObj      = $helper->getHandler('Subscr')->get($protocolObj->getVar('protocol_subscriber_id'));
75
        if (is_object($subscrObj)) {
76
            $subscr_array                                = $subscrObj->toArray();
77
            $protocol_array['subscr']                    = $subscr_array;
78
            $protocol_array['subscr']['subscriber_name'] = (0 < $subscrObj->getVar('subscr_uid')) ? \XoopsUserUtility::getUnameFromId($subscrObj->getVar('subscr_uid')) : '';
79
        } else {
80
            $protocol_array['subscr'] = false;
81
        }
82
        $protocol_array['protocol_created_formatted'] = formatTimestamp($protocolObj->getVar('protocol_created'), $helper->getConfig('dateformat'));
83
        $xoopsTpl->append('protocols', $protocol_array);
84
    }
85
}
86
87
require_once __DIR__ . '/footer.php';
88