Skip to content

Instantly share code, notes, and snippets.

@leftclickben
Last active August 29, 2015 14:24
Show Gist options
  • Save leftclickben/2d79979de6c2b735cf0c to your computer and use it in GitHub Desktop.
Save leftclickben/2d79979de6c2b735cf0c to your computer and use it in GitHub Desktop.
(CollectiveAccess) Retrieve CSV of placements for a given screen, with labels
#!/usr/bin/env php
<?php
$screen = 35; // modify as required
$locale = 'en_AU';
$pdo = new PDO('mysql:host=wamcmisdb01-staging;dbname=cmis', 'cmis', 'uhkdv5Uwhkk7pmv');
$placements = $pdo->query('select * from ca_editor_ui_bundle_placements where screen_id = ' . $screen . ' order by rank asc')->fetchAll();
foreach ($placements as $placement) {
$settings = unserialize(base64_decode($placement['settings']));
$label = isset($settings['label']) && isset($settings['label'][$locale]) ? $settings['label'][$locale] : null;
if (!$label && preg_match('/ca_attribute_/', $placement['bundle_name'])) {
$code = preg_replace('/ca_attribute_/', '', $placement['bundle_name']);
$elements = $pdo->query('select * from ca_metadata_elements where element_code = \'' . $code . '\'')->fetchAll(); // Yes yes, SQL injection, whatever
if (sizeof($elements) > 0) {
$elementLabels = $pdo->query('select * from ca_metadata_element_labels where element_id = ' . $elements[0]['element_id'])->fetchAll();
if (sizeof($elementLabels) > 0) {
$label = $elementLabels[0]['name'];
}
}
}
echo $placement['placement_id'] . ',' . $placement['placement_code'] . ',' . $placement['bundle_name'] . ',' . $label . ',' . $placement['rank'] . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment