Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FieldEntry_relationship often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FieldEntry_relationship, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class FieldEntry_relationship extends Field |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * |
||
| 24 | * Name of the field table |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | const FIELD_TBL_NAME = 'tbl_fields_entry_relationship'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * |
||
| 31 | * Separator char for values |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | const SEPARATOR = ','; |
||
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * |
||
| 39 | * Current recursive level of output |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $recursiveLevel = 1; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * |
||
| 46 | * Parent's maximum recursive level of output |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | protected $recursiveDeepness = null; |
||
| 50 | |||
| 51 | /* Cacheable Managers */ |
||
| 52 | private $sectionManager; |
||
| 53 | private $entryManager; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * |
||
| 57 | * Constructor for the oEmbed Field object |
||
| 58 | */ |
||
| 59 | public function __construct() |
||
| 60 | { |
||
| 61 | // call the parent constructor |
||
| 62 | parent::__construct(); |
||
| 63 | // set the name of the field |
||
| 64 | $this->_name = __('Entry Relationship'); |
||
| 65 | // permits to make it required |
||
| 66 | $this->_required = true; |
||
| 67 | // permits the make it show in the table columns |
||
| 68 | $this->_showcolumn = true; |
||
| 69 | // permits association |
||
| 70 | $this->_showassociation = true; |
||
| 71 | // current recursive level |
||
| 72 | $this->recursiveLevel = 1; |
||
| 73 | // parent's maximum recursive level of output |
||
| 74 | $this->recursiveDeepness = null; |
||
| 75 | // set as not required by default |
||
| 76 | $this->set('required', 'no'); |
||
| 77 | // show association by default |
||
| 78 | $this->set('show_association', 'yes'); |
||
| 79 | // no sections |
||
| 80 | $this->set('sections', null); |
||
| 81 | // no max deepness |
||
| 82 | $this->set('deepness', null); |
||
| 83 | // no included elements |
||
| 84 | $this->set('elements', null); |
||
| 85 | // no modes |
||
| 86 | $this->set('mode', null); |
||
| 87 | $this->set('mode_table', null); |
||
| 88 | $this->set('mode_header', null); |
||
| 89 | $this->set('mode_footer', null); |
||
| 90 | // no limit |
||
| 91 | $this->set('min_entries', null); |
||
| 92 | $this->set('max_entries', null); |
||
| 93 | // all permissions |
||
| 94 | $this->set('allow_new', 'yes'); |
||
| 95 | $this->set('allow_edit', 'yes'); |
||
| 96 | $this->set('allow_link', 'yes'); |
||
| 97 | $this->set('allow_delete', 'no'); |
||
| 98 | // display options |
||
| 99 | $this->set('allow_collapse', 'yes'); |
||
| 100 | $this->set('show_header', 'yes'); |
||
| 101 | $this->sectionManager = new CacheableFetch('SectionManager'); |
||
| 102 | $this->entryManager = new CacheableFetch('EntryManager'); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function isSortable() |
||
| 106 | { |
||
| 107 | return false; |
||
| 108 | } |
||
| 109 | |||
| 110 | public function canFilter() |
||
| 111 | { |
||
| 112 | return true; |
||
| 113 | } |
||
| 114 | |||
| 115 | public function canPublishFilter() |
||
| 116 | { |
||
| 117 | return false; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function canImport() |
||
| 121 | { |
||
| 122 | return false; |
||
| 123 | } |
||
| 124 | |||
| 125 | public function canPrePopulate() |
||
| 126 | { |
||
| 127 | return false; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function mustBeUnique() |
||
| 131 | { |
||
| 132 | return false; |
||
| 133 | } |
||
| 134 | |||
| 135 | public function allowDatasourceOutputGrouping() |
||
| 136 | { |
||
| 137 | return false; |
||
| 138 | } |
||
| 139 | |||
| 140 | public function requiresSQLGrouping() |
||
| 141 | { |
||
| 142 | return false; |
||
| 143 | } |
||
| 144 | |||
| 145 | public function allowDatasourceParamOutput() |
||
| 146 | { |
||
| 147 | return true; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param string $name |
||
| 152 | */ |
||
| 153 | public function getInt($name) |
||
| 154 | { |
||
| 155 | return General::intval($this->get($name)); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Check if a given property is == 'yes' |
||
| 160 | * @param string $name |
||
| 161 | * @return bool |
||
| 162 | * True if the current field's value is 'yes' |
||
| 163 | */ |
||
| 164 | public function is($name) |
||
| 165 | { |
||
| 166 | return $this->get($name) == 'yes'; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return bool |
||
| 171 | * True if the current field is required |
||
| 172 | */ |
||
| 173 | public function isRequired() |
||
| 174 | { |
||
| 175 | return $this->is('required'); |
||
| 176 | } |
||
| 177 | |||
| 178 | public static function getEntries(array $data) |
||
| 179 | { |
||
| 180 | return array_map(array('General', 'intval'), array_filter(array_map(trim, explode(self::SEPARATOR, $data['entries'])))); |
||
| 181 | } |
||
| 182 | |||
| 183 | /* ********** INPUT AND FIELD *********** */ |
||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * |
||
| 188 | * Validates input |
||
| 189 | * Called before <code>processRawFieldData</code> |
||
| 190 | * @param $data |
||
| 191 | * @param $message |
||
| 192 | * @param $entry_id |
||
| 193 | */ |
||
| 194 | public function checkPostFieldData($data, &$message, $entry_id=NULL) |
||
| 195 | { |
||
| 196 | $message = NULL; |
||
| 197 | $required = $this->isRequired(); |
||
| 198 | |||
| 199 | if ($required && (!is_array($data) || count($data) == 0 || strlen($data['entries']) < 1)) { |
||
| 200 | $message = __("'%s' is a required field.", array($this->get('label'))); |
||
| 201 | return self::__MISSING_FIELDS__; |
||
| 202 | } |
||
| 203 | |||
| 204 | $entries = $data['entries']; |
||
| 205 | |||
| 206 | if (!is_array($entries)) { |
||
| 207 | $entries = static::getEntries($data); |
||
| 208 | } |
||
| 209 | |||
| 210 | // enforce limits only if required or it contains data |
||
| 211 | if ($required || count($entries) > 0) { |
||
| 212 | if ($this->getInt('min_entries') > 0 && $this->getInt('min_entries') > count($entries)) { |
||
| 213 | $message = __("'%s' requires a minimum of %s entries.", array($this->get('label'), $this->getInt('min_entries'))); |
||
| 214 | return self::__INVALID_FIELDS__; |
||
| 215 | } else if ($this->getInt('max_entries') > 0 && $this->getInt('max_entries') < count($entries)) { |
||
| 216 | $message = __("'%s' can not contains more than %s entries.", array($this->get('label'), $this->getInt('max_entries'))); |
||
| 217 | return self::__INVALID_FIELDS__; |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 221 | return self::__OK__; |
||
| 222 | } |
||
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * |
||
| 227 | * Process data before saving into database. |
||
| 228 | * |
||
| 229 | * @param array $data |
||
| 230 | * @param int $status |
||
| 231 | * @param boolean $simulate |
||
| 232 | * @param int $entry_id |
||
| 233 | * |
||
| 234 | * @return Array - data to be inserted into DB |
||
| 235 | */ |
||
| 236 | public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) |
||
| 237 | { |
||
| 238 | $status = self::__OK__; |
||
| 239 | $entries = null; |
||
| 240 | |||
| 241 | if (!is_array($data) && !is_string($data)) { |
||
| 242 | return null; |
||
| 243 | } |
||
| 244 | |||
| 245 | if (isset($data['entries'])) { |
||
| 246 | $entries = $data['entries']; |
||
| 247 | } |
||
| 248 | else if (is_string($data)) { |
||
| 249 | $entries = $data; |
||
| 250 | } |
||
| 251 | |||
| 252 | $row = array( |
||
| 253 | 'entries' => $entries |
||
| 254 | ); |
||
| 255 | |||
| 256 | // return row |
||
| 257 | return $row; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * This function permits parsing different field settings values |
||
| 262 | * |
||
| 263 | * @param array $settings |
||
| 264 | * the data array to initialize if necessary. |
||
| 265 | */ |
||
| 266 | public function setFromPOST(Array &$settings = array()) |
||
| 267 | { |
||
| 268 | // call the default behavior |
||
| 269 | parent::setFromPOST($settings); |
||
| 270 | |||
| 271 | // declare a new setting array |
||
| 272 | $new_settings = array(); |
||
| 273 | |||
| 274 | // set new settings |
||
| 275 | $new_settings['sections'] = is_array($settings['sections']) ? |
||
| 276 | implode(self::SEPARATOR, $settings['sections']) : |
||
| 277 | (is_string($settings['sections']) ? $settings['sections'] : null); |
||
| 278 | |||
| 279 | $new_settings['show_association'] = $settings['show_association'] == 'yes' ? 'yes' : 'no'; |
||
| 280 | $new_settings['deepness'] = General::intval($settings['deepness']); |
||
| 281 | $new_settings['deepness'] = $new_settings['deepness'] < 1 ? null : $new_settings['deepness']; |
||
| 282 | $new_settings['elements'] = empty($settings['elements']) ? null : $settings['elements']; |
||
| 283 | $new_settings['mode'] = empty($settings['mode']) ? null : $settings['mode']; |
||
| 284 | $new_settings['mode_table'] = empty($settings['mode_table']) ? null : $settings['mode_table']; |
||
| 285 | $new_settings['mode_header'] = empty($settings['mode_header']) ? null : $settings['mode_header']; |
||
| 286 | $new_settings['mode_footer'] = empty($settings['mode_footer']) ? null : $settings['mode_footer']; |
||
| 287 | $new_settings['allow_new'] = $settings['allow_new'] == 'yes' ? 'yes' : 'no'; |
||
| 288 | $new_settings['allow_edit'] = $settings['allow_edit'] == 'yes' ? 'yes' : 'no'; |
||
| 289 | $new_settings['allow_link'] = $settings['allow_link'] == 'yes' ? 'yes' : 'no'; |
||
| 290 | $new_settings['allow_delete'] = $settings['allow_delete'] == 'yes' ? 'yes' : 'no'; |
||
| 291 | $new_settings['allow_collapse'] = $settings['allow_collapse'] == 'yes' ? 'yes' : 'no'; |
||
| 292 | $new_settings['show_header'] = $settings['show_header'] == 'yes' ? 'yes' : 'no'; |
||
| 293 | |||
| 294 | // save it into the array |
||
| 295 | $this->setArray($new_settings); |
||
| 296 | } |
||
| 297 | |||
| 298 | |||
| 299 | /** |
||
| 300 | * |
||
| 301 | * Validates the field settings before saving it into the field's table |
||
| 302 | */ |
||
| 303 | public function checkFields(Array &$errors, $checkForDuplicates) |
||
| 304 | { |
||
| 305 | $parent = parent::checkFields($errors, $checkForDuplicates); |
||
| 306 | if ($parent != self::__OK__) { |
||
| 307 | return $parent; |
||
| 308 | } |
||
| 309 | |||
| 310 | $sections = $this->get('sections'); |
||
| 311 | |||
| 312 | if (empty($sections)) { |
||
| 313 | $errors['sections'] = __('At least one section must be chosen'); |
||
| 314 | } |
||
| 315 | |||
| 316 | return (!empty($errors) ? self::__ERROR__ : self::__OK__); |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * |
||
| 321 | * Save field settings into the field's table |
||
| 322 | */ |
||
| 323 | public function commit() |
||
| 324 | { |
||
| 325 | // if the default implementation works... |
||
| 326 | if(!parent::commit()) return false; |
||
| 327 | |||
| 328 | $id = $this->get('id'); |
||
| 329 | |||
| 330 | // exit if there is no id |
||
| 331 | if($id == false) return false; |
||
| 332 | |||
| 333 | // we are the child, with multiple parents |
||
| 334 | $child_field_id = $id; |
||
| 335 | |||
| 336 | // delete associations, only where we are the child |
||
| 337 | self::removeSectionAssociation($child_field_id); |
||
| 338 | |||
| 339 | $sections = $this->getSelectedSectionsArray(); |
||
| 340 | |||
| 341 | foreach ($sections as $key => $sectionId) { |
||
| 342 | if (empty($sectionId)) { |
||
| 343 | continue; |
||
| 344 | } |
||
| 345 | $parent_section_id = General::intval($sectionId); |
||
| 346 | $parent_section = SectionManager::fetch($sectionId); |
||
| 347 | $fields = $parent_section->fetchVisibleColumns(); |
||
| 348 | if (empty($fields)) { |
||
| 349 | // no visible field, revert to all |
||
| 350 | $fields = $parent_section->fetchFields(); |
||
| 351 | } |
||
| 352 | $parent_field_id = current(array_keys($fields)); |
||
| 353 | // create association |
||
| 354 | SectionManager::createSectionAssociation( |
||
| 355 | $parent_section_id, |
||
| 356 | $child_field_id, |
||
| 357 | $parent_field_id, |
||
| 358 | $this->get('show_association') == 'yes' |
||
| 359 | ); |
||
| 360 | } |
||
| 361 | |||
| 362 | // declare an array contains the field's settings |
||
| 363 | $settings = array( |
||
| 364 | 'sections' => $this->get('sections'), |
||
| 365 | 'show_association' => $this->get('show_association'), |
||
| 366 | 'deepness' => $this->get('deepness'), |
||
| 367 | 'elements' => $this->get('elements'), |
||
| 368 | 'mode' => $this->get('mode'), |
||
| 369 | 'mode_table' => $this->get('mode_table'), |
||
| 370 | 'mode_header' => $this->get('mode_header'), |
||
| 371 | 'mode_footer' => $this->get('mode_footer'), |
||
| 372 | 'min_entries' => $this->get('min_entries'), |
||
| 373 | 'max_entries' => $this->get('max_entries'), |
||
| 374 | 'allow_new' => $this->get('allow_new'), |
||
| 375 | 'allow_edit' => $this->get('allow_edit'), |
||
| 376 | 'allow_link' => $this->get('allow_link'), |
||
| 377 | 'allow_delete' => $this->get('allow_delete'), |
||
| 378 | 'allow_collapse' => $this->get('allow_collapse'), |
||
| 379 | 'show_header' => $this->get('show_header'), |
||
| 380 | ); |
||
| 381 | |||
| 382 | return FieldManager::saveSettings($id, $settings); |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * |
||
| 387 | * This function allows Fields to cleanup any additional things before it is removed |
||
| 388 | * from the section. |
||
| 389 | * @return boolean |
||
| 390 | */ |
||
| 391 | public function tearDown() |
||
| 392 | { |
||
| 393 | self::removeSectionAssociation($this->get('id')); |
||
| 394 | return parent::tearDown(); |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Generates the where filter for searching by entry id |
||
| 399 | * |
||
| 400 | * @param string $value |
||
| 401 | * @param @optional string $col |
||
| 402 | * @param @optional boolean $andOperation |
||
| 403 | */ |
||
| 404 | public function generateWhereFilter($value, $col = 'd', $andOperation = true) |
||
| 405 | { |
||
| 406 | $junction = $andOperation ? 'AND' : 'OR'; |
||
| 407 | if (!$value) { |
||
| 408 | return "{$junction} (`{$col}`.`entries` IS NULL)"; |
||
| 409 | } |
||
| 410 | return " {$junction} (`{$col}`.`entries` = '{$value}' OR |
||
| 411 | `{$col}`.`entries` LIKE '{$value},%' OR |
||
| 412 | `{$col}`.`entries` LIKE '%,{$value}' OR |
||
| 413 | `{$col}`.`entries` LIKE '%,{$value},%')"; |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Fetch the number of associated entries for a particular entry id |
||
| 418 | * |
||
| 419 | * @param string $value |
||
| 420 | */ |
||
| 421 | public function fetchAssociatedEntryCount($value) |
||
| 422 | { |
||
| 423 | if (!$value) { |
||
| 424 | return 0; |
||
| 425 | } |
||
| 426 | $join = sprintf(" INNER JOIN `tbl_entries_data_%s` AS `d` ON `e`.id = `d`.`entry_id`", $this->get('id')); |
||
| 427 | $where = $this->generateWhereFilter($value); |
||
| 428 | |||
| 429 | $entries = EntryManager::fetch(null, $this->get('parent_section'), null, 0, $where, $join, false, false, array()); |
||
| 430 | |||
| 431 | return count($entries); |
||
| 432 | } |
||
| 433 | |||
| 434 | public function fetchAssociatedEntrySearchValue($data, $field_id = null, $parent_entry_id = null) |
||
| 435 | { |
||
| 436 | return $parent_entry_id; |
||
| 437 | } |
||
| 438 | |||
| 439 | public function findRelatedEntries($entry_id) |
||
| 440 | { |
||
| 441 | $joins = ''; |
||
| 442 | $where = ''; |
||
| 443 | $this->buildDSRetrievalSQL(array($entry_id), $joins, $where, true); |
||
| 444 | |||
| 445 | $entries = EntryManager::fetch(null, $this->get('parent_section'), null, 0, $where, $joins, false, false, array()); |
||
| 446 | |||
| 447 | $ids = array(); |
||
| 448 | foreach ($entries as $key => $e) { |
||
| 449 | $ids[] = $e['id']; |
||
| 450 | } |
||
| 451 | return $ids; |
||
| 452 | } |
||
| 453 | |||
| 454 | public function prepareAssociationsDrawerXMLElement(Entry $e, array $parent_association, $prepolutate = '') |
||
| 455 | { |
||
| 456 | $currentSection = SectionManager::fetch($parent_association['child_section_id']); |
||
| 457 | $visibleCols = $currentSection->fetchVisibleColumns(); |
||
| 458 | $outputFieldId = current(array_keys($visibleCols)); |
||
| 459 | $outputField = FieldManager::fetch($outputFieldId); |
||
| 460 | |||
| 461 | $value = $outputField->prepareReadableValue($e->getData($outputFieldId), $e->get('id'), true, __('None')); |
||
| 462 | |||
| 463 | $li = new XMLElement('li'); |
||
| 464 | $li->setAttribute('class', 'field-' . $this->get('type')); |
||
| 465 | $a = new XMLElement('a', strip_tags($value)); |
||
| 466 | $a->setAttribute('href', SYMPHONY_URL . '/publish/' . $parent_association['handle'] . '/edit/' . $e->get('id') . '/'); |
||
| 467 | $li->appendChild($a); |
||
| 468 | |||
| 469 | return $li; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @param string $joins |
||
| 474 | * @param string $where |
||
| 475 | */ |
||
| 476 | public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) |
||
| 477 | { |
||
| 478 | $field_id = $this->get('id'); |
||
| 479 | |||
| 480 | // REGEX filtering is a special case, and will only work on the first item |
||
| 481 | // in the array. You cannot specify multiple filters when REGEX is involved. |
||
| 482 | if (self::isFilterRegex($data[0])) { |
||
| 483 | return $this->buildRegexSQL($data[0], array('entries'), $joins, $where); |
||
| 484 | } |
||
| 485 | |||
| 486 | $this->_key++; |
||
| 487 | |||
| 488 | $where .= ' AND (1=' . ($andOperation ? '1' : '0') . ' '; |
||
| 489 | |||
| 490 | $joins .= " |
||
| 491 | INNER JOIN |
||
| 492 | `tbl_entries_data_{$field_id}` AS `t{$field_id}_{$this->_key}` |
||
| 493 | ON (`e`.`id` = `t{$field_id}_{$this->_key}`.`entry_id`) |
||
| 494 | "; |
||
| 495 | |||
| 496 | foreach ($data as $value) { |
||
| 497 | $where .= $this->generateWhereFilter($this->cleanValue($value), "t{$field_id}_{$this->_key}", $andOperation); |
||
| 498 | } |
||
| 499 | |||
| 500 | $where .= ')'; |
||
| 501 | |||
| 502 | return true; // this tells the DS Manager that filters are OK!! |
||
| 503 | } |
||
| 504 | |||
| 505 | /* ******* EVENTS ******* */ |
||
| 506 | |||
| 507 | public function getExampleFormMarkup() |
||
| 508 | { |
||
| 509 | $label = Widget::Label($this->get('label')); |
||
| 510 | $label->appendChild(Widget::Input('fields['.$this->get('element_name').'][entries]', null, 'hidden')); |
||
| 511 | |||
| 512 | return $label; |
||
| 513 | } |
||
| 514 | |||
| 515 | |||
| 516 | /* ******* DATA SOURCE ******* */ |
||
| 517 | |||
| 518 | private function fetchEntry($eId, $elements = array()) |
||
| 526 | |||
| 527 | public function fetchIncludableElements() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Appends data into the XML tree of a Data Source |
||
| 543 | * @param $wrapper |
||
| 544 | * @param $data |
||
| 545 | */ |
||
| 546 | public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null, $entry_id = null) |
||
| 547 | { |
||
| 548 | if(!is_array($data) || empty($data)) return; |
||
| 549 | |||
| 550 | // root for all values |
||
| 551 | $root = new XMLElement($this->get('element_name')); |
||
| 552 | |||
| 553 | // selected items |
||
| 554 | $entries = static::getEntries($data); |
||
| 555 | |||
| 556 | // current linked entries |
||
| 557 | $root->setAttribute('entries', $data['entries']); |
||
| 558 | |||
| 559 | // available sections |
||
| 560 | $root->setAttribute('sections', $this->get('sections')); |
||
| 561 | |||
| 562 | // included elements |
||
| 563 | $elements = static::parseElements($this); |
||
| 564 | |||
| 565 | // DS mode |
||
| 566 | if (!$mode) { |
||
| 567 | $mode = '*'; |
||
| 772 | |||
| 773 | public function getParameterPoolValue(array $data, $entry_id = null) |
||
| 778 | |||
| 779 | /* ********* Utils *********** */ |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Return true if $fieldName is allowed in $sectionElements |
||
| 783 | * @param string $fieldName |
||
| 784 | * @param string $sectionElements |
||
| 785 | * @return bool |
||
| 786 | */ |
||
| 787 | public static function isFieldIncluded($fieldName, $sectionElements) |
||
| 791 | |||
| 792 | public static function getSectionElementName($fieldName, $sectionElements) |
||
| 806 | |||
| 807 | public static function parseElements($field) |
||
| 843 | |||
| 844 | public static function extractMode($fieldName, $mode) |
||
| 856 | |||
| 857 | /** |
||
| 858 | * @param string $prefix |
||
| 859 | * @param string $name |
||
| 860 | * @param @optional bool $multiple |
||
| 861 | */ |
||
| 862 | private function createFieldName($prefix, $name, $multiple = false) |
||
| 870 | |||
| 871 | /** |
||
| 872 | * @param string $name |
||
| 873 | */ |
||
| 874 | private function createSettingsFieldName($name, $multiple = false) |
||
| 878 | |||
| 879 | /** |
||
| 880 | * @param string $name |
||
| 881 | */ |
||
| 882 | private function createPublishFieldName($name, $multiple = false) |
||
| 886 | |||
| 887 | private function getSelectedSectionsArray() |
||
| 900 | |||
| 901 | private function buildSectionSelect($name) |
||
| 915 | |||
| 916 | private function appendSelectionSelect(&$wrapper) |
||
| 930 | |||
| 931 | private function createEntriesList($entries) |
||
| 953 | |||
| 954 | private function createEntriesHiddenInput($data) |
||
| 964 | |||
| 965 | private function createActionBarMenu($sections) |
||
| 1010 | |||
| 1011 | /* ********* UI *********** */ |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * |
||
| 1015 | * Builds the UI for the field's settings when creating/editing a section |
||
| 1016 | * @param XMLElement $wrapper |
||
| 1017 | * @param array $errors |
||
| 1018 | */ |
||
| 1019 | public function displaySettingsPanel(&$wrapper, $errors=NULL) |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * @param string $fieldName |
||
| 1154 | * @param string $text |
||
| 1155 | */ |
||
| 1156 | private function createCheckbox($fieldName, $text) { |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * |
||
| 1170 | * Builds the UI for the publish page |
||
| 1171 | * @param XMLElement $wrapper |
||
| 1172 | * @param mixed $data |
||
| 1173 | * @param mixed $flagWithError |
||
| 1174 | * @param string $fieldnamePrefix |
||
| 1175 | * @param string $fieldnamePostfix |
||
| 1176 | */ |
||
| 1177 | public function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL, $entry_id = null) |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * @param integer $count |
||
| 1231 | */ |
||
| 1232 | private static function formatCount($count) |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * |
||
| 1244 | * Return a plain text representation of the field's data |
||
| 1245 | * @param array $data |
||
| 1246 | * @param int $entry_id |
||
| 1247 | */ |
||
| 1248 | public function prepareTextValue($data, $entry_id = null) |
||
| 1255 | |||
| 1256 | /** |
||
| 1257 | * Format this field value for display as readable text value. |
||
| 1258 | * |
||
| 1259 | * @param array $data |
||
| 1260 | * an associative array of data for this string. At minimum this requires a |
||
| 1261 | * key of 'value'. |
||
| 1262 | * @param integer $entry_id (optional) |
||
| 1263 | * An option entry ID for more intelligent processing. Defaults to null. |
||
| 1264 | * @param string $defaultValue (optional) |
||
| 1265 | * The value to use when no plain text representation of the field's data |
||
| 1266 | * can be made. Defaults to null. |
||
| 1267 | * @return string |
||
| 1268 | * the readable text summary of the values of this field instance. |
||
| 1269 | */ |
||
| 1270 | public function prepareReadableValue($data, $entry_id = null, $truncate = false, $defaultValue = 'None') |
||
| 1290 | |||
| 1291 | /** |
||
| 1292 | * Format this field value for display in the publish index tables. |
||
| 1293 | * |
||
| 1294 | * @param array $data |
||
| 1295 | * an associative array of data for this string. At minimum this requires a |
||
| 1296 | * key of 'value'. |
||
| 1297 | * @param XMLElement $link (optional) |
||
| 1298 | * an XML link structure to append the content of this to provided it is not |
||
| 1299 | * null. it defaults to null. |
||
| 1300 | * @param integer $entry_id (optional) |
||
| 1301 | * An option entry ID for more intelligent processing. defaults to null |
||
| 1302 | * @return string |
||
| 1303 | * the formatted string summary of the values of this field instance. |
||
| 1304 | */ |
||
| 1305 | public function prepareTableValue($data, XMLElement $link = null, $entry_id = null) |
||
| 1332 | |||
| 1333 | /* ********* SQL Data Definition ************* */ |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * |
||
| 1337 | * Creates table needed for entries of individual fields |
||
| 1338 | */ |
||
| 1339 | public function createTable() |
||
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Creates the table needed for the settings of the field |
||
| 1356 | */ |
||
| 1357 | public static function createFieldTable() |
||
| 1386 | |||
| 1387 | public static function update_102() |
||
| 1413 | |||
| 1414 | public static function update_103() |
||
| 1424 | |||
| 1425 | public static function update_200() |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * |
||
| 1446 | * Drops the table needed for the settings of the field |
||
| 1447 | */ |
||
| 1448 | public static function deleteFieldTable() |
||
| 1456 | |||
| 1457 | private static function removeSectionAssociation($child_field_id) |
||
| 1461 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.