MerciLocation.php in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2
File
modules/merci_migration/src/Plugin/migrate/source/d7/MerciLocation.php
View source
<?php
namespace Drupal\merci_migration\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Row;
class MerciLocation extends DrupalSqlBase {
public function query() {
$query = $this
->select('variable', 'v')
->fields('v');
$query
->condition('v.name', 'merci_hours_operation');
return $query;
}
public function prepareRow(Row $row) {
$hours = unserialize($row
->getSourceProperty('value'));
$open_hours = array();
foreach ($hours as $day => $open) {
if (is_numeric($day) and is_array($open)) {
list($starthour, $startmin) = explode(':', $open['open']);
list($endhour, $endmin) = explode(':', $open['close']);
$open_hours[] = array(
'day' => $day,
'starthours' => intval($starthour) . $startmin,
'endhours' => intval($endhour) . $endmin,
);
}
elseif ($day == 'closed_days') {
$holidays = array();
foreach ($open as $holiday) {
$holidays[] = array(
'value' => $holiday,
);
}
$row
->setSourceProperty('holidays', $holidays);
}
}
$row
->setSourceProperty('open_hours', $open_hours);
$row
->setSourceProperty('id', 1);
return parent::prepareRow($row);
}
public function fields() {
$fields = [
'id' => $this
->t('Row ID'),
'name' => $this
->t('Name of variable'),
'value' => $this
->t('Original value from database'),
'open_hours' => $this
->t('Open Hours'),
];
return $fields;
}
public function getIds() {
$ids['name']['type'] = 'text';
return $ids;
}
}