Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active December 13, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matdave/5a4ac3d58ba5a7ad97398c0329da9cc9 to your computer and use it in GitHub Desktop.
Save matdave/5a4ac3d58ba5a7ad97398c0329da9cc9 to your computer and use it in GitHub Desktop.
Convert Maxi to MIGX
[
{"caption":"Image", "fields":[
{"field":"image","caption":"Image","inputTVtype":"image"}
]},
{"caption":"Info", "fields": [
{"field":"title","caption":"Title"},
{"field":"description","caption":"Description","inputTVtype":"richtext"}
]}
]
[
{"header": "Title", "width": "60", "sortable": "true", "dataIndex": "title"},
{"header": "Image", "width": "60", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"}
]
<?php
// [{"MIGX_id":"1","title":"Kitchen001","description":"","image":"assets/galleries/10/1kitchen_001.jpg"}]
if(!function_exists('csv2array')){
function csv2array($filename = '', $delimiter = ',', $asHash = true)
{
if (!(is_readable($filename) || (($status = get_headers($filename)) && strpos($status[0], '200')))) {
return FALSE;
}
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE) {
if ($asHash) {
while ($row = fgetcsv($handle, 0, $delimiter)) {
if (!$header) {
$header = $row;
} else {
$data[] = array_combine($header, $row);
}
}
} else {
while ($row = fgetcsv($handle, 0, $delimiter)) {
$data[] = $row;
}
}
fclose($handle);
}
return $data;
}
}
$path = $modx->getOption('base_path').'/import/';
$csv = 'modx-maxigallery.csv';
$array = csv2array($path.$csv);
$gallery = array();
if(!empty($array)){
foreach($array as $c){
$gallery[$c['gal_id']][$c['pos']] = array(
'MIGX_id' => $c['pos'],
'title' => $c['title'],
'description' => $c['descr'],
'image' => 'assets/galleries/'.$c['gal_id'].'/'.$c['filename']
);
}
foreach($gallery as $k=>$v){
$object = $modx->getObject(MODX\Revolution\modResource::class,$k);
if(!empty($object)){
//MIGXGalleryTV
$object->setTVValue('MIGXGalleryTV', $modx->toJSON(array_values($v)));
$object->save();
}
}
} else {
echo 'NO Items Found!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment