| Conditions | 24 |
| Paths | 16 |
| Total Lines | 195 |
| Code Lines | 116 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 105 | public function __viewIndex($resource_type) |
||
| 106 | { |
||
| 107 | $manager = ResourceManager::getManagerFromType($resource_type); |
||
| 108 | $friendly_resource = ($resource_type === ResourceManager::RESOURCE_TYPE_EVENT) ? __('Event') : __('DataSource'); |
||
| 109 | |||
| 110 | $this->setPageType('table'); |
||
| 111 | |||
| 112 | Sortable::initialize($this, $resources, $sort, $order, array( |
||
| 113 | 'type' => $resource_type, |
||
| 114 | )); |
||
| 115 | |||
| 116 | $columns = array( |
||
| 117 | array( |
||
| 118 | 'label' => __('Name'), |
||
| 119 | 'sortable' => true, |
||
| 120 | 'handle' => 'name' |
||
| 121 | ), |
||
| 122 | array( |
||
| 123 | 'label' => __('Source'), |
||
| 124 | 'sortable' => true, |
||
| 125 | 'handle' => 'source' |
||
| 126 | ), |
||
| 127 | array( |
||
| 128 | 'label' => __('Pages'), |
||
| 129 | 'sortable' => false, |
||
| 130 | ), |
||
| 131 | array( |
||
| 132 | 'label' => __('Author'), |
||
| 133 | 'sortable' => true, |
||
| 134 | 'handle' => 'author' |
||
| 135 | ) |
||
| 136 | ); |
||
| 137 | |||
| 138 | $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, (isset($_REQUEST['filter']) ? '&filter=' . $_REQUEST['filter'] : '')); |
||
| 139 | |||
| 140 | $aTableBody = array(); |
||
| 141 | |||
| 142 | if (!is_array($resources) || empty($resources)) { |
||
| 143 | $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd')); |
||
| 144 | } else { |
||
| 145 | $context = Administration::instance()->getPageCallback(); |
||
| 146 | |||
| 147 | foreach ($resources as $r) { |
||
| 148 | $action = 'edit'; |
||
| 149 | $status = null; |
||
| 150 | $locked = null; |
||
| 151 | |||
| 152 | // Locked resources |
||
| 153 | if ( |
||
| 154 | isset($r['can_parse']) && $r['can_parse'] !== true || |
||
| 155 | ($resource_type === ResourceManager::RESOURCE_TYPE_DS && $r['source']['name'] === 'Dynamic_xml') |
||
| 156 | ) { |
||
| 157 | $action = 'info'; |
||
| 158 | $status = 'status-notice'; |
||
| 159 | $locked = array( |
||
| 160 | 'data-status' => ' — ' . __('read only') |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | |||
| 164 | $name = Widget::TableData( |
||
| 165 | Widget::Anchor( |
||
| 166 | stripslashes($r['name']), |
||
| 167 | SYMPHONY_URL . $context['pageroot'] . $action . '/' . $r['handle'] . '/', |
||
| 168 | $r['handle'], |
||
| 169 | 'resource-' . $action, |
||
| 170 | null, |
||
| 171 | $locked |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | |||
| 175 | $name->appendChild(Widget::Label(__('Select ' . $friendly_resource . ' %s', array($r['name'])), null, 'accessible', null, array( |
||
| 176 | 'for' => 'resource-' . $r['handle'] |
||
| 177 | ))); |
||
| 178 | $name->appendChild(Widget::Input('items['.$r['handle'].']', 'on', 'checkbox', array( |
||
| 179 | 'id' => 'resource-' . $r['handle'] |
||
| 180 | ))); |
||
| 181 | |||
| 182 | // Resource type/source |
||
| 183 | if (isset($r['source'], $r['source']['id'])) { |
||
| 184 | $section = Widget::TableData( |
||
| 185 | Widget::Anchor( |
||
| 186 | $r['source']['name'], |
||
| 187 | SYMPHONY_URL . '/blueprints/sections/edit/' . $r['source']['id'] . '/', |
||
| 188 | $r['source']['handle'] |
||
| 189 | ) |
||
| 190 | ); |
||
| 191 | } elseif (isset($r['source']) && class_exists($r['source']['name']) && method_exists($r['source']['name'], 'getSourceColumn')) { |
||
| 192 | $class = call_user_func(array($manager, '__getClassName'), $r['handle']); |
||
| 193 | $section = Widget::TableData(call_user_func(array($class, 'getSourceColumn'), $r['handle'])); |
||
| 194 | } elseif (isset($r['source'], $r['source']['name'])) { |
||
| 195 | $section = Widget::TableData(stripslashes($r['source']['name'])); |
||
| 196 | } else { |
||
| 197 | $section = Widget::TableData(__('Unknown'), 'inactive'); |
||
| 198 | } |
||
| 199 | |||
| 200 | // Attached pages |
||
| 201 | $pages = ResourceManager::getAttachedPages($resource_type, $r['handle']); |
||
| 202 | |||
| 203 | $pagelinks = array(); |
||
| 204 | $i = 0; |
||
| 205 | |||
| 206 | foreach ($pages as $p) { |
||
| 207 | ++$i; |
||
| 208 | $pagelinks[] = Widget::Anchor( |
||
| 209 | General::sanitize($p['title']), |
||
| 210 | SYMPHONY_URL . '/blueprints/pages/edit/' . $p['id'] . '/' |
||
| 211 | )->generate() . (count($pages) > $i ? (($i % 10) == 0 ? '<br />' : ', ') : ''); |
||
| 212 | } |
||
| 213 | |||
| 214 | $pages = implode('', $pagelinks); |
||
| 215 | |||
| 216 | if ($pages == '') { |
||
| 217 | $pagelinks = Widget::TableData(__('None'), 'inactive'); |
||
| 218 | } else { |
||
| 219 | $pagelinks = Widget::TableData($pages, 'pages'); |
||
| 220 | } |
||
| 221 | |||
| 222 | // Authors |
||
| 223 | $author = $r['author']['name']; |
||
| 224 | |||
| 225 | if ($author) { |
||
| 226 | if (isset($r['author']['website'])) { |
||
| 227 | $author = Widget::Anchor($r['author']['name'], General::validateURL($r['author']['website'])); |
||
| 228 | } elseif (isset($r['author']['email'])) { |
||
| 229 | $author = Widget::Anchor($r['author']['name'], 'mailto:' . $r['author']['email']); |
||
| 230 | } |
||
| 231 | } |
||
| 232 | |||
| 233 | $author = Widget::TableData($author); |
||
| 234 | |||
| 235 | $aTableBody[] = Widget::TableRow(array($name, $section, $pagelinks, $author), $status); |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | $table = Widget::Table( |
||
| 240 | Widget::TableHead($aTableHead), |
||
| 241 | null, |
||
| 242 | Widget::TableBody($aTableBody), |
||
| 243 | 'selectable', |
||
| 244 | null, |
||
| 245 | array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
||
| 246 | ); |
||
| 247 | |||
| 248 | $this->Form->appendChild($table); |
||
| 249 | |||
| 250 | $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
||
| 251 | 'id' => 'version' |
||
| 252 | )); |
||
| 253 | $this->Form->appendChild($version); |
||
| 254 | |||
| 255 | $tableActions = new XMLElement('div'); |
||
| 256 | $tableActions->setAttribute('class', 'actions'); |
||
| 257 | |||
| 258 | $options = array( |
||
| 259 | array(null, false, __('With Selected...')), |
||
| 260 | array('delete', false, __('Delete'), 'confirm'), |
||
| 261 | ); |
||
| 262 | |||
| 263 | $pages = $this->pagesFlatView(); |
||
| 264 | |||
| 265 | $group_attach = array('label' => __('Attach to Page'), 'options' => array()); |
||
| 266 | $group_detach = array('label' => __('Detach from Page'), 'options' => array()); |
||
| 267 | |||
| 268 | $group_attach['options'][] = array('attach-all-pages', false, __('All')); |
||
| 269 | $group_detach['options'][] = array('detach-all-pages', false, __('All')); |
||
| 270 | |||
| 271 | foreach ($pages as $p) { |
||
| 272 | $group_attach['options'][] = array('attach-to-page-' . $p['id'], false, General::sanitize($p['title'])); |
||
| 273 | $group_detach['options'][] = array('detach-from-page-' . $p['id'], false, General::sanitize($p['title'])); |
||
| 274 | } |
||
| 275 | |||
| 276 | $options[] = $group_attach; |
||
| 277 | $options[] = $group_detach; |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Allows an extension to modify the existing options for this page's |
||
| 281 | * With Selected menu. If the `$options` parameter is an empty array, |
||
| 282 | * the 'With Selected' menu will not be rendered. |
||
| 283 | * |
||
| 284 | * @delegate AddCustomActions |
||
| 285 | * @since Symphony 2.3.2 |
||
| 286 | * @param string $context |
||
| 287 | * '/blueprints/datasources/' or '/blueprints/events/' |
||
| 288 | * @param array $options |
||
| 289 | * An array of arrays, where each child array represents an option |
||
| 290 | * in the With Selected menu. Options should follow the same format |
||
| 291 | * expected by `Widget::__SelectBuildOption`. Passed by reference. |
||
| 292 | */ |
||
| 293 | Symphony::ExtensionManager()->notifyMembers('AddCustomActions', $context['pageroot'], array( |
||
| 294 | 'options' => &$options |
||
| 295 | )); |
||
| 296 | |||
| 297 | if (!empty($options)) { |
||
| 298 | $tableActions->appendChild(Widget::Apply($options)); |
||
| 299 | $this->Form->appendChild($tableActions); |
||
| 300 | } |
||
| 438 |