本文整理汇总了PHP中Varien_File_Csv::getDataPairs方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Csv::getDataPairs方法的具体用法?PHP Varien_File_Csv::getDataPairs怎么用?PHP Varien_File_Csv::getDataPairs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Csv
的用法示例。
在下文中一共展示了Varien_File_Csv::getDataPairs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getFileData
/**
* Retrieve data from file
*
* @param string $file
* @return array
*/
protected function _getFileData($file)
{
$data = array();
if (file_exists($file)) {
$parser = new Varien_File_Csv();
$parser->setDelimiter(self::CSV_SEPARATOR);
$data = $parser->getDataPairs($file);
}
return $data;
}
示例2: csvAction
public function csvAction()
{
$dump = Mage::helper('pdfinvoiceplus/localization')->translate('Shipping & Handling');
zend_debug::dump($dump);
die;
$p = 'magestore\\pdfinvoiceplus\\localization\\localization_england.csv';
$path = str_replace(array('\\', '/'), DS, $p);
$file = Mage::getBaseDir('media') . DS . $path;
$csv = new Varien_File_Csv();
$data = $csv->getDataPairs($file);
zend_debug::dump($data);
die;
// die($file);
$csv = scandir($file);
$data = array();
foreach ($csv as $file) {
if (preg_match('/^localization/', $file)) {
$data[] = $file;
}
}
zend_debug::dump($data);
die;
for ($i = 1; $i < count($data); $i++) {
var_dump($data[$i]);
}
}
示例3: getFileData
/**
* Get data from csv file
*
* @param string $file
* @return array
*/
protected function getFileData($file)
{
$parser = new Varien_File_Csv();
return $parser->getDataPairs($file);
}
示例4: exportAction
/**
* Do the export.
*/
public function exportAction()
{
Mage::log("TranslationExporter: Export started");
$translate = Mage::getSingleton('core/translate');
$locale = $translate->getLocale();
$baseFolder = $locale . '_base';
$targetDir = Mage::getBaseDir('var') . DS . 'translations' . DS . $locale;
$localeDir = Mage::getBaseDir('locale');
Mage::log("TranslationExporter - target directory: {$targetDir}");
$dbtrans = $translate->getResource()->getTranslationArray(null, $locale);
Mage::log("TranslationExporter: " . count($dbtrans) . " translation rows from DB");
// for each module:
// - for each CSV file in that module:
// 1. read it to memory
// 2. modify it according to DB translation for that module
// 3. write it back to dest dir
$parser = new Varien_File_Csv();
$parser->setDelimiter(Mage_Core_Model_Translate::CSV_SEPARATOR);
foreach ($translate->getModulesConfig() as $moduleName => $info) {
$info = $info->asArray();
Mage::log("TranslationExporter: Exporting module {$moduleName}");
foreach ($info['files'] as $file) {
$enData = array();
$enFilePath = $localeDir . DS . 'en_US' . DS . $file;
if (file_exists($enFilePath)) {
$enData = $parser->getDataPairs($enFilePath);
}
$baseData = array();
$baseFilePath = $localeDir . DS . $baseFolder . DS . $file;
if (file_exists($baseFilePath)) {
$baseData = $parser->getDataPairs($baseFilePath);
}
foreach ($baseData as $key => $val) {
if (isset($enData[$key]) && $enData[$key] !== $val) {
$enData[$key] = $val;
}
}
$data = array();
$filePath = $localeDir . DS . $locale . DS . $file;
Mage::log("TranslationExporter: Reading {$filePath}");
if (file_exists($filePath)) {
$data = $parser->getDataPairs($filePath);
}
foreach ($data as $key => $val) {
if (isset($enData[$key]) && $enData[$key] !== $val) {
$enData[$key] = $val;
}
}
// 2. MODIFY
foreach ($enData as $key => $val) {
$fullKey = $moduleName . '::' . $key;
if (isset($dbtrans[$fullKey])) {
$stack[] = $fullKey;
Mage::log("TranslationExporter: Rewrite '{$fullKey}' from '{$val}' to '{$dbtrans[$fullKey]}'");
$enData[$key] = $dbtrans[$fullKey];
}
}
// 3. WRITE
if (!file_exists($targetDir)) {
if (!mkdir($targetDir, 0777, true)) {
throw new Exception("Cannot create {$targetDir}");
}
}
$targetFile = $targetDir . '/' . $file;
$parser = new Varien_File_Csv();
$csvdata = array();
foreach ($enData as $key => $val) {
$csvdata[] = array($key, $val);
}
$parser->saveData($targetFile, $csvdata);
Mage::log("TranslationExporter: wrote {$targetFile}");
}
Mage::log("TranslationExporter: Done.");
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('compiler')->__("Translations has been exported to '%s'.", $targetDir));
$this->_redirect('*/*/');
}