| Conditions | 22 |
| Paths | 16 |
| Total Lines | 257 |
| Code Lines | 130 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 | $context = Administration::instance()->getPageCallback(); |
||
| 110 | |||
| 111 | $this->setPageType('table'); |
||
| 112 | |||
| 113 | Sortable::initialize($this, $resources, $sort, $order, array( |
||
| 114 | 'type' => $resource_type, |
||
| 115 | )); |
||
| 116 | |||
| 117 | $columns = array( |
||
| 118 | array( |
||
| 119 | 'label' => __('Name'), |
||
| 120 | 'sortable' => true, |
||
| 121 | 'handle' => 'name' |
||
| 122 | ), |
||
| 123 | array( |
||
| 124 | 'label' => __('Source'), |
||
| 125 | 'sortable' => true, |
||
| 126 | 'handle' => 'source' |
||
| 127 | ), |
||
| 128 | array( |
||
| 129 | 'label' => __('Pages'), |
||
| 130 | 'sortable' => false, |
||
| 131 | ), |
||
| 132 | array( |
||
| 133 | 'label' => __('Author'), |
||
| 134 | 'sortable' => true, |
||
| 135 | 'handle' => 'author' |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Allows the creation of custom table columns for each resource. Called |
||
| 141 | * after all the table headers columns have been added. |
||
| 142 | * |
||
| 143 | * @delegate AddCustomResourceColumn |
||
| 144 | * @since Symphony 3.0.0 |
||
| 145 | * @param string $context |
||
| 146 | * '/blueprints/datasources/' or '/blueprints/events/' |
||
| 147 | * @param array $columns |
||
| 148 | * An array of the current columns, passed by reference |
||
| 149 | * @param string $sort |
||
| 150 | * The sort field |
||
| 151 | * @param string $order |
||
| 152 | * The sort order |
||
| 153 | * @param int $resource_type |
||
| 154 | * The resource type, i.e. `ResourceManager::RESOURCE_TYPE_EVENT` or |
||
| 155 | * `ResourceManager::RESOURCE_TYPE_DATASOURCE`. |
||
| 156 | * @param array $resources |
||
| 157 | * The resources array |
||
| 158 | * @param object $manager |
||
| 159 | * The resources manager |
||
| 160 | */ |
||
| 161 | Symphony::ExtensionManager()->notifyMembers('AddCustomResourceColumn', $context['pageroot'], [ |
||
| 162 | 'columns' => &$columns, |
||
| 163 | 'sort' => $sort, |
||
| 164 | 'order' => $order, |
||
| 165 | 'resource_type' => $resource_type, |
||
| 166 | 'resources' => $resources, |
||
| 167 | 'manager' => $manager, |
||
| 168 | ]); |
||
| 169 | |||
| 170 | $aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, (isset($_REQUEST['filter']) ? '&filter=' . $_REQUEST['filter'] : '')); |
||
| 171 | |||
| 172 | $aTableBody = array(); |
||
| 173 | |||
| 174 | if (!is_array($resources) || empty($resources)) { |
||
| 175 | $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd')); |
||
| 176 | } else { |
||
| 177 | foreach ($resources as $r) { |
||
| 178 | $action = 'edit'; |
||
| 179 | $status = null; |
||
| 180 | $locked = null; |
||
| 181 | |||
| 182 | // Locked resources |
||
| 183 | if (isset($r['can_parse']) && $r['can_parse'] !== true) { |
||
| 184 | $action = 'info'; |
||
| 185 | $status = 'status-notice'; |
||
| 186 | $locked = array( |
||
| 187 | 'data-status' => ' — ' . __('read only') |
||
| 188 | ); |
||
| 189 | } |
||
| 190 | |||
| 191 | $name = Widget::TableData( |
||
| 192 | Widget::Anchor( |
||
| 193 | stripslashes($r['name']), |
||
| 194 | SYMPHONY_URL . $context['pageroot'] . $action . '/' . $r['handle'] . '/', |
||
| 195 | $r['handle'], |
||
| 196 | 'resource-' . $action, |
||
| 197 | null, |
||
| 198 | $locked |
||
| 199 | ) |
||
| 200 | ); |
||
| 201 | |||
| 202 | $name->appendChild(Widget::Label(__('Select ' . $friendly_resource . ' %s', array($r['name'])), null, 'accessible', null, array( |
||
| 203 | 'for' => 'resource-' . $r['handle'] |
||
| 204 | ))); |
||
| 205 | $name->appendChild(Widget::Input('items['.$r['handle'].']', 'on', 'checkbox', array( |
||
| 206 | 'id' => 'resource-' . $r['handle'] |
||
| 207 | ))); |
||
| 208 | |||
| 209 | // Resource type/source |
||
| 210 | if (isset($r['source'], $r['source']['id'])) { |
||
| 211 | $section = Widget::TableData( |
||
| 212 | Widget::Anchor( |
||
| 213 | $r['source']['name'], |
||
| 214 | SYMPHONY_URL . '/blueprints/sections/edit/' . $r['source']['id'] . '/', |
||
| 215 | $r['source']['handle'] |
||
| 216 | ) |
||
| 217 | ); |
||
| 218 | } elseif (isset($r['source']) && class_exists($r['source']['name']) && method_exists($r['source']['name'], 'getSourceColumn')) { |
||
| 219 | $class = call_user_func(array($manager, '__getClassName'), $r['handle']); |
||
| 220 | $section = Widget::TableData(call_user_func(array($class, 'getSourceColumn'), $r['handle'])); |
||
| 221 | } elseif (isset($r['source'], $r['source']['name'])) { |
||
| 222 | $section = Widget::TableData(stripslashes($r['source']['name'])); |
||
| 223 | } else { |
||
| 224 | $section = Widget::TableData(__('Unknown'), 'inactive'); |
||
| 225 | } |
||
| 226 | |||
| 227 | // Attached pages |
||
| 228 | $pages = ResourceManager::getAttachedPages($resource_type, $r['handle']); |
||
| 229 | |||
| 230 | $pagelinks = array(); |
||
| 231 | $i = 0; |
||
| 232 | |||
| 233 | foreach ($pages as $p) { |
||
| 234 | ++$i; |
||
| 235 | $pagelinks[] = Widget::Anchor( |
||
| 236 | $p['title'], |
||
| 237 | SYMPHONY_URL . '/blueprints/pages/edit/' . $p['id'] . '/' |
||
| 238 | )->generate() . (count($pages) > $i ? (($i % 10) == 0 ? '<br />' : ', ') : ''); |
||
| 239 | } |
||
| 240 | |||
| 241 | $pages = implode('', $pagelinks); |
||
| 242 | |||
| 243 | if ($pages == '') { |
||
| 244 | $pagelinks = Widget::TableData(__('None'), 'inactive'); |
||
| 245 | } else { |
||
| 246 | $pagelinks = Widget::TableData($pages, 'pages'); |
||
| 247 | } |
||
| 248 | |||
| 249 | // Authors |
||
| 250 | $author = $r['author']['name']; |
||
| 251 | |||
| 252 | if ($author) { |
||
| 253 | if (isset($r['author']['website'])) { |
||
| 254 | $author = Widget::Anchor($r['author']['name'], General::validateURL($r['author']['website'])); |
||
| 255 | } elseif (isset($r['author']['email'])) { |
||
| 256 | $author = Widget::Anchor($r['author']['name'], 'mailto:' . $r['author']['email']); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | $author = Widget::TableData($author); |
||
| 261 | $tableData = [$name, $section, $pagelinks, $author]; |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Allows Extensions to inject custom table data for each Resource |
||
| 265 | * into the Resource Index |
||
| 266 | * |
||
| 267 | * @delegate AddCustomResourceColumnData |
||
| 268 | * @since Symphony 3.0.0 |
||
| 269 | * @param string $context |
||
| 270 | * '/blueprints/datasources/' or '/blueprints/events/' |
||
| 271 | * @param array $tableData |
||
| 272 | * An array of `Widget::TableData`, passed by reference |
||
| 273 | * @param array $columns |
||
| 274 | * An array of the current columns |
||
| 275 | * @param int $resource_type |
||
| 276 | * The resource type, i.e. `ResourceManager::RESOURCE_TYPE_EVENT` or |
||
| 277 | * `ResourceManager::RESOURCE_TYPE_DATASOURCE`. |
||
| 278 | * @param array $resource |
||
| 279 | * The resource array |
||
| 280 | * @param string $action |
||
| 281 | * The name of the action |
||
| 282 | * @param string $status |
||
| 283 | * The status of the row |
||
| 284 | * @param bool $locked |
||
| 285 | * If the resource is locked, i.e., read-only |
||
| 286 | */ |
||
| 287 | Symphony::ExtensionManager()->notifyMembers('AddCustomResourceColumnData', '/system/authors/', [ |
||
| 288 | 'tableData' => &$tableData, |
||
| 289 | 'columns' => $columns, |
||
| 290 | 'resource_type' => $resource_type, |
||
| 291 | 'resource' => $r, |
||
| 292 | 'action' => $action, |
||
| 293 | 'status' => $status, |
||
| 294 | 'locked' => $locked, |
||
| 295 | ]); |
||
| 296 | |||
| 297 | $aTableBody[] = Widget::TableRow($tableData, $status); |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | $table = Widget::Table( |
||
| 302 | Widget::TableHead($aTableHead), |
||
| 303 | null, |
||
| 304 | Widget::TableBody($aTableBody), |
||
| 305 | 'selectable', |
||
| 306 | null, |
||
| 307 | array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
||
| 308 | ); |
||
| 309 | |||
| 310 | $this->Form->appendChild($table); |
||
| 311 | |||
| 312 | $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
||
| 313 | 'id' => 'version' |
||
| 314 | )); |
||
| 315 | $this->Form->appendChild($version); |
||
| 316 | |||
| 317 | $tableActions = new XMLElement('div'); |
||
| 318 | $tableActions->setAttribute('class', 'actions'); |
||
| 319 | |||
| 320 | $options = array( |
||
| 321 | array(null, false, __('With Selected...')), |
||
| 322 | array('delete', false, __('Delete'), 'confirm'), |
||
| 323 | ); |
||
| 324 | |||
| 325 | $pages = $this->pagesFlatView(); |
||
| 326 | |||
| 327 | $group_attach = array('label' => __('Attach to Page'), 'options' => array()); |
||
| 328 | $group_detach = array('label' => __('Detach from Page'), 'options' => array()); |
||
| 329 | |||
| 330 | $group_attach['options'][] = array('attach-all-pages', false, __('All')); |
||
| 331 | $group_detach['options'][] = array('detach-all-pages', false, __('All')); |
||
| 332 | |||
| 333 | foreach ($pages as $p) { |
||
| 334 | $group_attach['options'][] = array('attach-to-page-' . $p['id'], false, $p['title']); |
||
| 335 | $group_detach['options'][] = array('detach-from-page-' . $p['id'], false, $p['title']); |
||
| 336 | } |
||
| 337 | |||
| 338 | $options[] = $group_attach; |
||
| 339 | $options[] = $group_detach; |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Allows an extension to modify the existing options for this page's |
||
| 343 | * With Selected menu. If the `$options` parameter is an empty array, |
||
| 344 | * the 'With Selected' menu will not be rendered. |
||
| 345 | * |
||
| 346 | * @delegate AddCustomActions |
||
| 347 | * @since Symphony 2.3.2 |
||
| 348 | * @param string $context |
||
| 349 | * '/blueprints/datasources/' or '/blueprints/events/' |
||
| 350 | * @param array $options |
||
| 351 | * An array of arrays, where each child array represents an option |
||
| 352 | * in the With Selected menu. Options should follow the same format |
||
| 353 | * expected by `Widget::__SelectBuildOption`. Passed by reference. |
||
| 354 | */ |
||
| 355 | Symphony::ExtensionManager()->notifyMembers('AddCustomActions', $context['pageroot'], array( |
||
| 356 | 'options' => &$options |
||
| 357 | )); |
||
| 358 | |||
| 359 | if (!empty($options)) { |
||
| 360 | $tableActions->appendChild(Widget::Apply($options)); |
||
| 361 | $this->Form->appendChild($tableActions); |
||
| 362 | } |
||
| 544 |