Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Parse Typo3 Categories.
- *
- * Converts Typo3 categories to Specialties
- *
- * @param [array] $categories
- * Array of clean numeric Typo3 Category IDs.
- *
- * @return [array]
- * Array of arrays defining what data was parsed from where for what.
- */
- public function parseTaxonomyMapping($categories) {
- // There will be other entries in this array, based on the type mapping...
- // Examples: specialty, articletype.
- $output = array(
- 'unmapped' => [],
- 'notfound' => [],
- );
- // This array holds all target_term column names in the
- // $this->target_topic_map mapping document.
- $target_term_columns = $this->getTargetTermsMap();
- // Move through each category UID present.
- foreach ($categories as $id) {
- // If the ID exists in our remapping list...
- if (isset($this->target_topic_map[$id])) {
- $map_row = $this->target_topic_map[$id];
- // Process all Specialty term mapping columns.
- foreach ($target_term_columns as $target_term_column) {
- // Get the machine name. This will look like "specialty-01".
- $machine_name = isset($map_row[$target_term_column]) && !empty($map_row[$target_term_column]) ? $map_row[$target_term_column] : FALSE;
- $machine_name_process = $this->processMachineName($machine_name);
- // This mapping column is empty or not set.
- if (!$machine_name) {
- $output['unmapped'][] = 'Machine Name Not Set: ' . $machine_name;
- continue;
- }
- // This column is set to be ignored. Stop processing this column.
- if ($machine_name == '[ignore]' || $machine_name == '[confirm-ignore]') {
- continue;
- }
- // Since the mapping works differently depending on the machine name
- // type, call a method specific to this machine type.
- // @See $this->getTermNameTypeSpecialties()
- // @See $this->getTermNameTypeArticletype()
- $machine_name_type = $machine_name_process['type'];
- $type_class = 'getTermNameType' . ucfirst($machine_name_type);
- if (method_exists($this, $type_class)) {
- $term_name = $this->$type_class($machine_name, $machine_name_process);
- }
- else {
- $output['unmapped'][] = "Type processing method doesn't exist: {$type_class}";
- continue;
- }
- // At this point we need to confirm that we can get to the term name.
- if (!$term_name) {
- $output['unmapped'][] = 'Taxonomy Not Defined (' . $machine_name_type . '): ' . $machine_name;
- continue;
- }
- // Add the taxonomy tern name to the correct array.
- if (!isset($output[$machine_name_type])) {
- $output[$machine_name_type] = array();
- }
- $output[$machine_name_type][] = $term_name;
- }
- }
- else {
- $output['notfound'][] = $id;
- }
- }
- // Ensure no duplicate data for output without key/value storage.
- foreach ($output as $output_key => $output_value) {
- $output[$output_key] = array_unique($output[$output_key]);
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement