Conditions | 16 |
Paths | 40 |
Total Lines | 106 |
Code Lines | 82 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
38 | function b_wgevents_event_show($options) |
||
39 | { |
||
40 | $helper = Helper::getInstance(); |
||
41 | $eventHandler = $helper->getHandler('Event'); |
||
42 | $permissionsHandler = $helper->getHandler('Permission'); |
||
43 | $registrationHandler = $helper->getHandler('Registration'); |
||
44 | |||
45 | $GLOBALS['xoopsTpl']->assign('user_maxchar', $helper->getConfig('user_maxchar')); |
||
46 | $eventRegprocessbar = (string)$helper->getConfig('event_regprocessbar'); |
||
47 | $GLOBALS['xoopsTpl']->assign('event_regprocessbar', $eventRegprocessbar); |
||
48 | $uidCurrent = 0; |
||
49 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
50 | $uidCurrent = $GLOBALS['xoopsUser']->uid(); |
||
51 | } |
||
52 | |||
53 | $block = []; |
||
54 | $typeBlock = $options[0]; |
||
55 | $limit = (int)$options[1]; |
||
56 | $lengthTitle = (int)$options[2]; |
||
|
|||
57 | $blockType = '0' === (string)$options[3] ? 'simple' : (string)$options[3] ; |
||
58 | \array_shift($options); |
||
59 | \array_shift($options); |
||
60 | \array_shift($options); |
||
61 | \array_shift($options); |
||
62 | |||
63 | $GLOBALS['xoTheme']->addStylesheet(\WGEVENTS_URL . '/assets/css/style.css', null); |
||
64 | |||
65 | $dateCreated = 0; |
||
66 | switch ($typeBlock) { |
||
67 | case 'last': |
||
68 | default: |
||
69 | // For the block: events last |
||
70 | $dateFrom = 0; |
||
71 | $sortBy = 'datecreated'; |
||
72 | $orderBy = 'DESC'; |
||
73 | break; |
||
74 | case 'new': |
||
75 | // For the block: events new |
||
76 | // new since last week: 7 * 24 * 60 * 60 = 604800 |
||
77 | $dateCreated = \time() - 604800; |
||
78 | $dateFrom = 0; |
||
79 | $sortBy = 'datecreated'; |
||
80 | $orderBy = 'ASC'; |
||
81 | break; |
||
82 | case 'random': |
||
83 | // For the block: events random |
||
84 | $dateFrom = 0; |
||
85 | $sortBy = 'RAND()'; |
||
86 | $orderBy = ''; |
||
87 | break; |
||
88 | case 'coming': |
||
89 | // For the block: next events |
||
90 | $dateFrom = \time(); |
||
91 | $sortBy = 'datefrom'; |
||
92 | $orderBy = 'ASC'; |
||
93 | break; |
||
94 | } |
||
95 | |||
96 | $eventsArr = $eventHandler->getEvents(0, $limit, $dateFrom, 0, $sortBy, $orderBy, '', 0, '', [], $dateCreated); |
||
97 | $eventsCount = $eventsArr['count']; |
||
98 | |||
99 | if ($eventsCount > 0) { |
||
100 | $eventsAll = $eventsArr['eventsAll']; |
||
101 | foreach (\array_keys($eventsAll) as $i) { |
||
102 | $block[$i] = $eventsAll[$i]->getValuesEvents(); |
||
103 | //get progress of registrations |
||
104 | //currently only for wgevents_block_events_panel |
||
105 | if ('panel' === $blockType) { |
||
106 | $crRegistration = new \CriteriaCompo(); |
||
107 | $crRegistration->add(new \Criteria('evid', $i)); |
||
108 | $numberRegCurr = $registrationHandler->getCount($crRegistration); |
||
109 | $block[$i]['nb_registrations'] = $numberRegCurr; |
||
110 | $registerMax = (int)$block[$i]['register_max']; |
||
111 | if ($registerMax > 0) { |
||
112 | $block[$i]['regmax'] = $registerMax; |
||
113 | $proportion = $numberRegCurr / $registerMax; |
||
114 | if ($proportion >= 1) { |
||
115 | $block[$i]['regcurrent'] = \_MA_WGEVENTS_REGISTRATIONS_FULL; |
||
116 | } else { |
||
117 | $block[$i]['regcurrent'] = \sprintf(\_MA_WGEVENTS_REGISTRATIONS_NBCURR_INDEX, $numberRegCurr, $registerMax); |
||
118 | } |
||
119 | $block[$i]['regcurrent_text'] = $block[$i]['regcurrent']; |
||
120 | $block[$i]['regcurrent_tip'] = true; |
||
121 | if ($proportion < 0.75) { |
||
122 | $block[$i]['regcurrentstate'] = 'success'; |
||
123 | } elseif ($proportion < 1) { |
||
124 | $block[$i]['regcurrentstate'] = 'warning'; |
||
125 | } else { |
||
126 | $block[$i]['regcurrentstate'] = 'danger'; |
||
127 | $block[$i]['regcurrent_tip'] = false; |
||
128 | } |
||
129 | $block[$i]['regpercentage'] = (int)($proportion * 100); |
||
130 | } |
||
131 | } |
||
132 | $block[$i]['datefromto_text'] = $eventHandler->getDateFromToText($eventsAll[$i]->getVar('datefrom'), $eventsAll[$i]->getVar('dateto'), $eventsAll[$i]->getVar('allday')); |
||
133 | $block[$i]['permEdit'] = ($permissionsHandler->getPermEventsEdit($eventsAll[$i]->getVar('submitter'), $eventsAll[$i]->getVar('status')) || $uidCurrent == $eventsAll[$i]->getVar('submitter')); |
||
134 | } |
||
135 | } |
||
136 | $GLOBALS['xoopsTpl']->assign('wgevents_permAdd', ($uidCurrent > 0 && $permissionsHandler->getPermEventsSubmit())); |
||
137 | $GLOBALS['xoopsTpl']->assign('permRegister', $permissionsHandler->getPermRegistrationsSubmit()); |
||
138 | $GLOBALS['xoopsTpl']->assign('wgevents_blocktype', $blockType); |
||
139 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_catlogos_url', \WGEVENTS_UPLOAD_CATLOGOS_URL); |
||
140 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_eventlogos_url', \WGEVENTS_UPLOAD_EVENTLOGOS_URL); |
||
141 | $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL); |
||
142 | |||
143 | return $block; |
||
144 | |||
199 |