-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giel Berkers
committed
Jan 22, 2013
1 parent
8e7eeb9
commit df99a2a
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* Import Driver | ||
* | ||
* Each field should have a specific class for import-export functions. | ||
* When none is found, the default fallback is this class. | ||
*/ | ||
|
||
class ImportDriver_multilingual extends ImportDriver_default { | ||
|
||
/** | ||
* Constructor | ||
* @return void | ||
*/ | ||
public function ImportDriver_default() | ||
{ | ||
$this->type = 'multilingual'; | ||
} | ||
|
||
/** | ||
* Process the data so it can be imported into the entry. | ||
* @param $value The value to import | ||
* @param $entry_id If a duplicate is found, an entry ID will be provided. | ||
* @return The data returned by the field object | ||
*/ | ||
public function import($value, $entry_id = null) | ||
{ | ||
$languageCodes = $this->field->getSupportedLanguageCodes(); | ||
$dataArr = unserialize($value); | ||
$newValue = array(); | ||
foreach($languageCodes as $code) | ||
{ | ||
if(isset($dataArr[$code])) | ||
{ | ||
$newValue['value-'.$code] = $dataArr[$code]; | ||
} | ||
} | ||
$data = $this->field->processRawFieldData($newValue, $this->field->__OK__, false, $entry_id); | ||
return $data; | ||
} | ||
|
||
/** | ||
* Process the data so it can be exported to a CSV | ||
* @param $data The data as provided by the entry | ||
* @param $entry_id The ID of the entry that is exported | ||
* @return string A string representation of the data to import into the CSV file | ||
*/ | ||
public function export($data, $entry_id = null) | ||
{ | ||
$storeData = array(); | ||
foreach($data as $key => $value) | ||
{ | ||
if(substr($key, 0, 13) == 'value_format-') | ||
{ | ||
$a = explode('-', $key); | ||
$storeData[$a[1]] = $value; | ||
} | ||
} | ||
return serialize($storeData); | ||
} | ||
|
||
} |