Last active
December 13, 2022 19:22
-
-
Save matdave/5a4ac3d58ba5a7ad97398c0329da9cc9 to your computer and use it in GitHub Desktop.
Convert Maxi to MIGX
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
[ | |
{"caption":"Image", "fields":[ | |
{"field":"image","caption":"Image","inputTVtype":"image"} | |
]}, | |
{"caption":"Info", "fields": [ | |
{"field":"title","caption":"Title"}, | |
{"field":"description","caption":"Description","inputTVtype":"richtext"} | |
]} | |
] |
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
[ | |
{"header": "Title", "width": "60", "sortable": "true", "dataIndex": "title"}, | |
{"header": "Image", "width": "60", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"} | |
] |
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 | |
// [{"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