Skip to content
Snippets Groups Projects
Commit a037e06f authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'dev#41679_generer_horaires_a_partir_des_horaires_d_ouverture' into 'master'

Dev#41679 generer horaires a partir des horaires d ouverture

See merge request !1616
parents c036f171 adbb7d19
Branches
Tags
4 merge requests!1659Master,!1620Master,!1618Master,!1610Dev#35088 oai import in cosmogramme
- ticket #41679 : Ajout d'un script de génération du contenu du champs horaire des bibliothèques à partir des données d'ouverture saisies
\ No newline at end of file
<?php
require_once './console.php';
class Openings_Migrator {
public function run() {
echo "\nStarted at " . date('c') . "\n";
$total = Class_Bib::count();
$count = 0;
foreach(Class_Bib::findAllBy(['order' => 'id_site']) as $model) {
$this->runOne($model);
$count++;
}
echo "\nFinished at " . date('c') . "\n";
}
protected function runOne($model) {
echo ' ' . $model->getLibelle() . ' : ' . $model->numberOfOuvertures() . ' ouverture(s) définie(s)' . "\n";
$openings = [];
foreach(Class_Ouverture::findAllBy(['id_site' => $model->getId(),
'jour_semaine not' => null,
'order' => 'jour_semaine']) as $opening)
if ($translated = $this->translate($opening))
$openings[] = $translated;
echo $translated = implode("\n", $openings);
$model->setHoraire($translated)
->save();
echo "\n\n";
}
protected function translate($opening) {
$am = $this->translatePeriod($opening->getDebutMatin(), $opening->getFinMatin());
$pm = $this->translatePeriod($opening->getDebutApresMidi(), $opening->getFinApresMidi());
$hours = $this->translateHours($am, $pm);
if ($hours)
return $opening->getFormattedJour() . ' : ' . str_replace('h00', 'h', $hours);
}
protected function translatePeriod($from, $to) {
if ($from == $to)
return $this->translateHour($from);
$from = $this->translateHour($from);
$to = $this->translateHour($to);
return $from && $to
? $from . ' - ' . $to
: '';
}
protected function translateHour($hour) {
return '00:00' == $hour ? '' : str_replace(':', 'h', $hour);
}
protected function translateHours($am, $pm) {
if ('' != $am && '' != $pm) {
if (substr($am, -5, 5) == substr($pm, 0, 5))
return substr($am, 0, 5) . substr($pm, 5);
return $am . ' / ' . $pm;
}
if ($am)
return $am;
return $pm;
}
}
(new Openings_Migrator())->run();
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment