当前位置: 首页>>代码示例>>PHP>>正文


PHP Admin::determineCsvDialect方法代码示例

本文整理汇总了PHP中Pimcore\Tool\Admin::determineCsvDialect方法的典型用法代码示例。如果您正苦于以下问题:PHP Admin::determineCsvDialect方法的具体用法?PHP Admin::determineCsvDialect怎么用?PHP Admin::determineCsvDialect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimcore\Tool\Admin的用法示例。


在下文中一共展示了Admin::determineCsvDialect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importProcessAction

 public function importProcessAction()
 {
     $success = true;
     $parentId = $this->getParam("parentId");
     $job = $this->getParam("job");
     $id = $this->getParam("id");
     $mappingRaw = \Zend_Json::decode($this->getParam("mapping"));
     $class = Object\ClassDefinition::getById($this->getParam("classId"));
     $skipFirstRow = $this->getParam("skipHeadRow") == "true";
     $fields = $class->getFieldDefinitions();
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id;
     // currently only csv supported
     // determine type
     $dialect = Tool\Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id . "_original");
     $count = 0;
     if (($handle = fopen($file, "r")) !== false) {
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     if ($skipFirstRow && $job == 1) {
         //read the next row, we need to skip the head row
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     $tmpFile = $file . "_tmp";
     $tmpHandle = fopen($tmpFile, "w+");
     while (!feof($handle)) {
         $buffer = fgets($handle);
         fwrite($tmpHandle, $buffer);
     }
     fclose($handle);
     fclose($tmpHandle);
     unlink($file);
     rename($tmpFile, $file);
     // prepare mapping
     foreach ($mappingRaw as $map) {
         if ($map[0] !== "" && $map[1] && !empty($map[2])) {
             $mapping[$map[2]] = $map[0];
         } else {
             if ($map[1] == "published (system)") {
                 $mapping["published"] = $map[0];
             } else {
                 if ($map[1] == "type (system)") {
                     $mapping["type"] = $map[0];
                 }
             }
         }
     }
     // create new object
     $className = "\\Pimcore\\Model\\Object\\" . ucfirst($this->getParam("className"));
     $className = Tool::getModelClassMapping($className);
     $parent = Object::getById($this->getParam("parentId"));
     $objectKey = "object_" . $job;
     if ($this->getParam("filename") == "id") {
         $objectKey = null;
     } else {
         if ($this->getParam("filename") != "default") {
             $objectKey = File::getValidFilename($data[$this->getParam("filename")]);
         }
     }
     $overwrite = false;
     if ($this->getParam("overwrite") == "true") {
         $overwrite = true;
     }
     if ($parent->isAllowed("create")) {
         $intendedPath = $parent->getFullPath() . "/" . $objectKey;
         if ($overwrite) {
             $object = Object::getByPath($intendedPath);
             if (!$object instanceof Object\Concrete) {
                 //create new object
                 $object = new $className();
             } else {
                 if ($object instanceof Object\Concrete and !$object instanceof $className) {
                     //delete the old object it is of a different class
                     $object->delete();
                     $object = new $className();
                 } else {
                     if ($object instanceof Object\Folder) {
                         //delete the folder
                         $object->delete();
                         $object = new $className();
                     } else {
                         //use the existing object
                     }
                 }
             }
         } else {
             $counter = 1;
             while (Object::getByPath($intendedPath) != null) {
                 $objectKey .= "_" . $counter;
                 $intendedPath = $parent->getFullPath() . "/" . $objectKey;
                 $counter++;
             }
             $object = new $className();
         }
         $object->setClassId($this->getParam("classId"));
         $object->setClassName($this->getParam("className"));
         $object->setParentId($this->getParam("parentId"));
         $object->setKey($objectKey);
         $object->setCreationDate(time());
         $object->setUserOwner($this->getUser()->getId());
         $object->setUserModification($this->getUser()->getId());
//.........这里部分代码省略.........
开发者ID:cannonerd,项目名称:pimcore,代码行数:101,代码来源:ObjectHelperController.php

示例2: importTranslationsFromFile

 /**
  * Imports translations from a csv file
  * The CSV file has to have the same format as an Pimcore translation-export-file
  *
  * @static
  * @param $file - path to the csv file
  * @param bool $replaceExistingTranslations
  * @throws \Exception
  */
 public static function importTranslationsFromFile($file, $replaceExistingTranslations = true, $languages = null)
 {
     $delta = [];
     if (is_readable($file)) {
         if (!$languages || empty($languages) || !is_array($languages)) {
             $languages = Tool::getValidLanguages();
         }
         //read import data
         $tmpData = file_get_contents($file);
         //replace magic excel bytes
         $tmpData = str_replace("", "", $tmpData);
         //convert to utf-8 if needed
         $tmpData = Tool\Text::convertToUTF8($tmpData);
         //store data for further usage
         $importFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_translations";
         File::put($importFile, $tmpData);
         $importFileOriginal = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_translations_original";
         File::put($importFileOriginal, $tmpData);
         // determine csv type
         $dialect = Tool\Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_translations_original");
         //read data
         if (($handle = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_translations", "r")) !== false) {
             while (($rowData = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar)) !== false) {
                 $data[] = $rowData;
             }
             fclose($handle);
         }
         //process translations
         if (is_array($data) and count($data) > 1) {
             $keys = $data[0];
             // remove wrong quotes in some export/import constellations
             $keys = array_map(function ($value) {
                 return trim($value, '""');
             }, $keys);
             $data = array_slice($data, 1);
             foreach ($data as $row) {
                 $keyValueArray = [];
                 for ($counter = 0; $counter < count($row); $counter++) {
                     $rd = str_replace("&quot;", '"', $row[$counter]);
                     $keyValueArray[$keys[$counter]] = $rd;
                 }
                 $textKey = $keyValueArray["key"];
                 if ($textKey) {
                     $t = static::getByKey($textKey, true);
                     $dirty = false;
                     foreach ($keyValueArray as $key => $value) {
                         if (in_array($key, $languages)) {
                             $currentTranslation = $t->getTranslation($key);
                             if ($replaceExistingTranslations) {
                                 $t->addTranslation($key, $value);
                                 if ($currentTranslation != $value) {
                                     $dirty = true;
                                 }
                             } else {
                                 if (!$t->getTranslation($key)) {
                                     $t->addTranslation($key, $value);
                                     if ($currentTranslation != $value) {
                                         $dirty = true;
                                     }
                                 } elseif ($t->getTranslation($key) != $value && $value) {
                                     $delta[] = ["lg" => $key, "key" => $textKey, "text" => $t->getTranslation($key), "csv" => $value];
                                 }
                             }
                         }
                     }
                     if ($dirty) {
                         if ($keyValueArray['creationDate']) {
                             $t->setCreationDate($keyValueArray['creationDate']);
                         }
                         $t->setModificationDate(time());
                         //ignore modificationDate from file
                         $t->save();
                     }
                 }
             }
             Model\Translation\AbstractTranslation::clearDependentCache();
         } else {
             throw new \Exception("less than 2 rows of data - nothing to import");
         }
     } else {
         throw new \Exception("{$file} is not readable");
     }
     return $delta;
 }
开发者ID:solverat,项目名称:pimcore,代码行数:93,代码来源:AbstractTranslation.php


注:本文中的Pimcore\Tool\Admin::determineCsvDialect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。