Example #1
0
 public static function createTypes($types, $existed = false)
 {
     // read existed
     if ($existed === false) {
         $existed = static::getExistedTypes();
     }
     // here we try to add type names for ALL languages
     $langs = Location\Admin\NameHelper::getLanguageList();
     foreach ($types as $line) {
         // for sure
         unset($line['SELECTORLEVEL']);
         unset($line['DEFAULTSELECT']);
         $names = array();
         if (!is_array($line['NAME'])) {
             $line['NAME'] = array();
         }
         if (is_array($langs)) {
             foreach ($langs as $lid => $f) {
                 $names[ToUpper($lid)] = static::getTranslatedName($line['NAME'], $lid);
             }
         }
         if (!isset($existed[$line['CODE']])) {
             $existed[$line['CODE']] = static::createType($line);
         } else {
             // ensure it has all appropriate translations
             // we can not use ::updateMultipleForOwner() here, because user may rename his types manually
             Location\Name\TypeTable::addAbsentForOwner($existed[$line['CODE']], $names);
         }
     }
     return $existed;
 }