Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1.   /**
  2.    * Parse Typo3 Categories.
  3.    *
  4.    * Converts Typo3 categories to Specialties
  5.    *
  6.    * @param [array] $categories
  7.    *   Array of clean numeric Typo3 Category IDs.
  8.    *
  9.    * @return [array]
  10.    *   Array of arrays defining what data was parsed from where for what.
  11.    */
  12.   public function parseTaxonomyMapping($categories) {
  13.     // There will be other entries in this array, based on the type mapping...
  14.     // Examples: specialty, articletype.
  15.     $output = array(
  16.       'unmapped' => [],
  17.       'notfound' => [],
  18.     );
  19.  
  20.     // This array holds all target_term column names in the
  21.     // $this->target_topic_map mapping document.
  22.     $target_term_columns = $this->getTargetTermsMap();
  23.  
  24.     // Move through each category UID present.
  25.     foreach ($categories as $id) {
  26.  
  27.       // If the ID exists in our remapping list...
  28.       if (isset($this->target_topic_map[$id])) {
  29.         $map_row = $this->target_topic_map[$id];
  30.  
  31.         // Process all Specialty term mapping columns.
  32.         foreach ($target_term_columns as $target_term_column) {
  33.  
  34.           // Get the machine name. This will look like "specialty-01".
  35.           $machine_name = isset($map_row[$target_term_column]) && !empty($map_row[$target_term_column]) ? $map_row[$target_term_column] : FALSE;
  36.           $machine_name_process = $this->processMachineName($machine_name);
  37.  
  38.           // This mapping column is empty or not set.
  39.           if (!$machine_name) {
  40.             $output['unmapped'][] = 'Machine Name Not Set: ' . $machine_name;
  41.             continue;
  42.           }
  43.  
  44.           // This column is set to be ignored. Stop processing this column.
  45.           if ($machine_name == '[ignore]' || $machine_name == '[confirm-ignore]') {
  46.             continue;
  47.           }
  48.  
  49.           // Since the mapping works differently depending on the machine name
  50.           // type, call a method specific to this machine type.
  51.           // @See $this->getTermNameTypeSpecialties()
  52.           // @See $this->getTermNameTypeArticletype()
  53.           $machine_name_type = $machine_name_process['type'];
  54.           $type_class = 'getTermNameType' . ucfirst($machine_name_type);
  55.           if (method_exists($this, $type_class)) {
  56.             $term_name = $this->$type_class($machine_name, $machine_name_process);
  57.           }
  58.           else {
  59.             $output['unmapped'][] = "Type processing method doesn't exist: {$type_class}";
  60.             continue;
  61.           }
  62.  
  63.           // At this point we need to confirm that we can get to the term name.
  64.           if (!$term_name) {
  65.             $output['unmapped'][] = 'Taxonomy Not Defined (' . $machine_name_type . '): ' . $machine_name;
  66.             continue;
  67.           }
  68.  
  69.           // Add the taxonomy tern name to the correct array.
  70.           if (!isset($output[$machine_name_type])) {
  71.             $output[$machine_name_type] = array();
  72.           }
  73.  
  74.           $output[$machine_name_type][] = $term_name;
  75.         }
  76.  
  77.       }
  78.       else {
  79.         $output['notfound'][] = $id;
  80.       }
  81.     }
  82.  
  83.     // Ensure no duplicate data for output without key/value storage.
  84.     foreach ($output as $output_key => $output_value) {
  85.       $output[$output_key] = array_unique($output[$output_key]);
  86.     }
  87.  
  88.     return $output;
  89.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement