Created
December 5, 2011 23:16
-
-
Save iainurquhart/1435861 to your computer and use it in GitHub Desktop.
matrix hack for channel entries api
This file contains hidden or 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
<?php | |
// hacks to ft.matrix.php to allow import of matrix data via channel_entries api | |
// which doesn't call the validate() method in the fieldtype | |
// -------------------------------------------------------------------------------- | |
// CHANGE 1 | |
// update save method which is currently: | |
/** | |
* Save | |
*/ | |
function save() | |
{ | |
$field_id = $this->settings['field_id']; | |
// to call the validate method if the cache hasn't been set: | |
/** | |
* Save | |
*/ | |
function save($data) | |
{ | |
$field_id = $this->settings['field_id']; | |
if(!isset($this->cache['fields'][$field_id]['cols'])) | |
{ | |
$this->validate($data); | |
} | |
// -------------------------------------------------------------------------------- | |
// CHANGE 2 | |
// unset $this->cache for the next import otherwise all entries have same data. | |
// insert the following right at the end of the post_save() method | |
unset($this->cache["field_cols"][$field_id]); | |
unset($this->cache["fields"][$field_id]); | |
// -------------------------------------------------------------------------------- | |
// CHANGE 3 | |
// $this->settings['field_required'] isn't set when calling the validate method on save() | |
// update the following line (~1778) to prevent notices | |
if ($this->settings['field_required'] == 'y') | |
// to become | |
if (isset($this->settings['field_required']) && $this->settings['field_required'] == 'y') | |
// thats all. | |
// -------------------------------------------------------------------------------- | |
// EXAMPLE CODE FOR IMPORT | |
// basic EE field data | |
$data = array( | |
'title' => $operator['nameoflisting'], | |
'entry_date' => date("Y-m-d h:i A", $entry_date), | |
'channel_id' => $channel_id, | |
'status' => 'open', | |
'field_id_1' => $operator['unique_id'], | |
'field_id_2' => $operator['latitude'], | |
'field_id_3' => $operator['longitude'] | |
); | |
// matrix field_id_4 | |
if(count($operator['online_profiles'])) | |
{ | |
$i = 0; | |
foreach($operator['online_profiles'] as $profile) | |
{ | |
$data["field_id_4"]['row_order'][] = "row_new_$i"; | |
$data["field_id_4"]["row_new_$i"]["col_id_1"] = $profile['PROFILE_DATA']; | |
$data["field_id_4"]["row_new_$i"]["col_id_2"] = $profile['PROFILE_TYPE']; | |
$i++; | |
} | |
} | |
// matrix field_id_5 | |
if(count($operator['assets'])) | |
{ | |
$i = 0; | |
foreach($operator['assets'] as $type => $item) | |
{ | |
foreach($item as $asset) | |
{ | |
$data["field_id_6"]['row_order'][] = "row_new_$i"; | |
$data["field_id_6"]["row_new_$i"]["col_id_19"] = $type; | |
$data["field_id_6"]["row_new_$i"]["col_id_20"] = $asset['o_id']; | |
$data["field_id_6"]["row_new_$i"]["col_id_21"] = $asset['description']; | |
$data["field_id_6"]["row_new_$i"]["col_id_22"] = $asset['label']; | |
$data["field_id_6"]["row_new_$i"]["col_id_23"] = $asset['height']; | |
$data["field_id_6"]["row_new_$i"]["col_id_24"] = $asset['market']; | |
$data["field_id_6"]["row_new_$i"]["col_id_25"] = $asset['latitude']; | |
$data["field_id_6"]["row_new_$i"]["col_id_26"] = $asset['width']; | |
$data["field_id_6"]["row_new_$i"]["col_id_27"] = $asset['unique_id']; | |
$data["field_id_6"]["row_new_$i"]["col_id_28"] = $asset['asset_type']; | |
$data["field_id_6"]["row_new_$i"]["col_id_29"] = $asset['credit']; | |
$data["field_id_6"]["row_new_$i"]["col_id_30"] = $asset['exists']; | |
$data["field_id_6"]["row_new_$i"]["col_id_31"] = $asset['caption']; | |
$data["field_id_6"]["row_new_$i"]["col_id_32"] = $asset['longitude']; | |
$data["field_id_6"]["row_new_$i"]["col_id_33"] = $asset['url']; | |
$data["field_id_6"]["row_new_$i"]["col_id_34"] = $asset['type_o_id']; | |
$i++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment