Skip to content

Instantly share code, notes, and snippets.

@stefankeidel
Created March 7, 2016 13:38
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 stefankeidel/cc5cd86b9618fc7beae4 to your computer and use it in GitHub Desktop.
Save stefankeidel/cc5cd86b9618fc7beae4 to your computer and use it in GitHub Desktop.
CollectiveAccess data mangling example
<?php
require_once('./setup.php');
require_once(__CA_MODELS_DIR__.'/ca_occurrences.php');
$o_db = new Db();
$qr_prods = $o_db->query('SELECT occurrence_id FROM ca_occurrences WHERE type_id = 116');
while($qr_prods->nextRow()) {
$t_occ = new ca_occurrences($qr_prods->get('occurrence_id'));
if($va_dates = $t_occ->get('ca_occurrences.perfSchedule', array('returnAsArray' => true, 'returnBlankValues' => false))) {
$t_occ->setMode(ACCESS_WRITE);
$vb_update = false;
foreach($va_dates as $vs_date) {
if($vs_date) {
$t_occ->addAttribute(array(
'productionDate' => trim($vs_date)
), 'productionDate');
$vb_update = true;
}
}
if($vb_update) {
$t_occ->removeAttributes('perfSchedule');
$t_occ->update();
if ($t_occ->numErrors() > 0) {
var_dump($t_occ->getErrors());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment