Peut être qu'une petite recherche Google t'aurais apporté la réponse
http://www.php.net/manual/fr/language.o ... ng.members
Justement connais-tu une institution qui ne gère qu'un seul cour a une meme heure ?Le script a été fait pour une gestion de cours.
Or on a rarement deux cours à deux endroits différents se déroulant au même moment.
Donc je doute que cela soit géré.
Code : Tout sélectionner
<?php
include('Planning.php');
include('PlanningCellule.php');
include('PlanningMapper.php');
$contenusCellules[] = new PlanningCellule(1,'17:15:00','19:00:00','#008000','<b>Zeus</b><br />B1/1');
$contenusCellules[] = new PlanningCellule(1,'19:00:00','21:00:00','#7CCAF4','<b>Ryle</b><br />A2');
$planning = new Planning(1, 6, 540, 1320, 15, $contenusCellules);
$planning->afficherHtmlTable();
?>
<?php
namespace Virgule\Bundle\MainBundle\Entity\Planning;
use Virgule\Bundle\MainBundle\Entity\Planning\HeaderCell;
use Virgule\Bundle\MainBundle\Entity\Planning\PlanningCell;
use Virgule\Bundle\MainBundle\Entity\CourseHydrated;
class Planning {
// cells[jour][heure_debut]
private $dayStart;
private $dayEnd;
private $startTime;
private $endTime;
public static $cellSize = 30;
private $header = Array();
private $rows = Array();
private $classRooms = Array();
public function __construct($courses) {
$this->dayStart = 1;
$this->dayEnd = 6;
$this->startTime = new \DateTime('08:00');
$this->endTime = new \DateTime('21:30');
$this->initPlanning($courses);
$this->initHeader();
$this->addCourses($courses);
}
public function getRows() {
return $this->rows;
}
public function getHeader() {
return $this->header;
}
private function initHeader() {
for ($day = $this->dayStart; $day <= $this->dayEnd; $day++) {
$this->header[$day] = new HeaderCell($day);
foreach ($this->classRooms as $classRoomId => $classRoomName) {
$this->header[$day]->addClassRoom($classRoomId, $classRoomName);
}
}
}
private function initPlanning($courses) {
$startTimeCell = clone $this->startTime;
$endTimeCell = clone $this->startTime;
$endTimeCell->modify("+" . self::$cellSize . " minutes");
foreach ($courses as $course) {
$this->storeClassRoom($course->getClassRoomId(), $course->getClassRoomName());
}
if (count($this->classRooms) == 0) {
$this->storeClassRoom(0, "");
}
while ($startTimeCell <= $this->endTime) {
$timeIndex = $startTimeCell->format('H:i');
$this->rows[$timeIndex] = new PlanningRow($startTimeCell->format('H:i'), $endTimeCell->format('H:i'));
for ($day = $this->dayStart; $day <= $this->dayEnd; $day++) {
foreach ($this->classRooms as $classRoomId => $classRoomName) {
$this->rows[$timeIndex]->initCell($day, $classRoomId);
}
}
$startTimeCell->modify("+" . self::$cellSize . " minutes");
$endTimeCell->modify("+" . self::$cellSize . " minutes");
}
}
private function addCourses($courses) {
foreach($courses as $course) {
$this->addCourse($course);
}
}
private function addCourse(CourseHydrated $course) {
$t = $course->getStartTime();
if (array_key_exists($t->format('H:i'), $this->rows)) {
$this->rows[$t->format('H:i')]->addCell($course);
$timeCell = clone $course->getStartTime();
$timeCell->modify("+" . self::$cellSize . " minutes");
while ($timeCell < $course->getEndTime()) {
$timeIndex = $timeCell->format('H:i');
$this->rows[$timeIndex]->removeCell($course->getDayOfWeek(), $course->getClassRoomId());
$timeCell->modify("+" . self::$cellSize . " minutes");
}
}
}
private function sortCells() {
foreach ($this->rows as $time => $row) {
$this->rows[$time] = ksort($row->getCells());
foreach ($row as $day => $cells) {
$this->rows[$time][$day] = krsort($cells);
}
}
}
private function storeClassRoom($classRoomId, $classRoomLabel) {
if (! array_key_exists($classRoomId, $this->classRooms)) {
$this->classRooms[$classRoomId] = $classRoomLabel;
}
}
}
?>
Cellule:
<?php
namespace Virgule\Bundle\MainBundle\Entity\Planning;
use Virgule\Bundle\MainBundle\Entity\Planning\HeaderCell;
use Virgule\Bundle\MainBundle\Entity\Planning\PlanningCell;
use Virgule\Bundle\MainBundle\Entity\CourseHydrated;
class Planning {
// cells[jour][heure_debut]
private $dayStart;
private $dayEnd;
private $startTime;
private $endTime;
public static $cellSize = 30;
private $header = Array();
private $rows = Array();
private $classRooms = Array();
public function __construct($courses) {
$this->dayStart = 1;
$this->dayEnd = 6;
$this->startTime = new \DateTime('08:00');
$this->endTime = new \DateTime('21:30');
$this->initPlanning($courses);
$this->initHeader();
$this->addCourses($courses);
}
public function getRows() {
return $this->rows;
}
public function getHeader() {
return $this->header;
}
private function initHeader() {
for ($day = $this->dayStart; $day <= $this->dayEnd; $day++) {
$this->header[$day] = new HeaderCell($day);
foreach ($this->classRooms as $classRoomId => $classRoomName) {
$this->header[$day]->addClassRoom($classRoomId, $classRoomName);
}
}
}
private function initPlanning($courses) {
$startTimeCell = clone $this->startTime;
$endTimeCell = clone $this->startTime;
$endTimeCell->modify("+" . self::$cellSize . " minutes");
foreach ($courses as $course) {
$this->storeClassRoom($course->getClassRoomId(), $course->getClassRoomName());
}
if (count($this->classRooms) == 0) {
$this->storeClassRoom(0, "");
}
while ($startTimeCell <= $this->endTime) {
$timeIndex = $startTimeCell->format('H:i');
$this->rows[$timeIndex] = new PlanningRow($startTimeCell->format('H:i'), $endTimeCell->format('H:i'));
for ($day = $this->dayStart; $day <= $this->dayEnd; $day++) {
foreach ($this->classRooms as $classRoomId => $classRoomName) {
$this->rows[$timeIndex]->initCell($day, $classRoomId);
}
}
$startTimeCell->modify("+" . self::$cellSize . " minutes");
$endTimeCell->modify("+" . self::$cellSize . " minutes");
}
}
private function addCourses($courses) {
foreach($courses as $course) {
$this->addCourse($course);
}
}
private function addCourse(CourseHydrated $course) {
$t = $course->getStartTime();
if (array_key_exists($t->format('H:i'), $this->rows)) {
$this->rows[$t->format('H:i')]->addCell($course);
$timeCell = clone $course->getStartTime();
$timeCell->modify("+" . self::$cellSize . " minutes");
while ($timeCell < $course->getEndTime()) {
$timeIndex = $timeCell->format('H:i');
$this->rows[$timeIndex]->removeCell($course->getDayOfWeek(), $course->getClassRoomId());
$timeCell->modify("+" . self::$cellSize . " minutes");
}
}
}
private function sortCells() {
foreach ($this->rows as $time => $row) {
$this->rows[$time] = ksort($row->getCells());
foreach ($row as $day => $cells) {
$this->rows[$time][$day] = krsort($cells);
}
}
}
private function storeClassRoom($classRoomId, $classRoomLabel) {
if (! array_key_exists($classRoomId, $this->classRooms)) {
$this->classRooms[$classRoomId] = $classRoomLabel;
}
}
}
?>
Cellule d'en-tête:
<?php
namespace Virgule\Bundle\MainBundle\Entity\Planning;
class HeaderCell {
private $day;
private $classRooms = Array();
public function __construct($day) {
$this->day = $day;
}
public function getDay() {
return $this->day;
}
public function getClassRooms() {
return $this->classRooms;
}
public function addClassRoom($classRoomId, $classRoomName) {
$this->classRooms[$classRoomId] = $classRoomName;
}
}
?>
Classe de ligne:
<?php
namespace Virgule\Bundle\MainBundle\Entity\Planning;
use Virgule\Bundle\MainBundle\Entity\CourseHydrated;
use Virgule\Bundle\MainBundle\Entity\Planning\PlanningCell;
class PlanningRow {
private $startTime;
private $endTime;
private $cells = Array();
public function __construct($startTime, $endTime) {
$this->startTime = $startTime;
$this->endTime = $endTime;
}
public function getStartTime() {
return $this->startTime;
}
public function getEndTime() {
return $this->endTime;
}
public function getCells() {
return $this->cells;
}
public function initCell($day, $classRoom) {
$this->cells[$day][$classRoom] = new PlanningCell();
}
public function addCell(CourseHydrated $course = null) {
$this->cells[$course->getDayOfWeek()][$course->getClassRoomId()] = new PlanningCell($course);
}
public function removeCell($day, $classRoom) {
$this->cells[$day][$classRoom] = null;
}
}
?>
Ma classe de cours qui contient tout:
<?php
namespace Virgule\Bundle\MainBundle\Entity;
class CourseHydrated {
private $courseId;
private $dayOfWeek;
private $startTime;
private $endTime;
private $alternateStartdate;
private $alternateEnddate;
private $classLevelId;
private $classLevelLabel;
private $classLevelColorCode;
private $teachers = Array();
private $classRoomId;
private $classRoomName;
private $nbStudents;
public function __construct($id, $dayOfWeek, $startTime, $endTime, $alternateStartdate, $alternateEnddate, $nbStudents, $classLevelId, $classLevelLabel, $classLevelColorCode, $teachers, $classRoomId, $classRoomName) {
$this->courseId = $id;
$this->dayOfWeek = $dayOfWeek;
$this->startTime = $startTime;
$this->endTime = $endTime;
$this->alternateStartdate = $alternateStartdate;
$this->alternateEnddate = $alternateEnddate;
$this->classLevelId = $classLevelId;
$this->classLevelLabel = $classLevelLabel;
$this->classLevelColorCode = $classLevelColorCode;
$this->teachers = $teachers;
$this->classRoomId = $classRoomId;
$this->classRoomName = $classRoomName;
$this->nbStudents = $nbStudents;
}
public function getId() {
return $this->courseId;
}
public function getDayOfWeek() {
return $this->dayOfWeek;
}
public function getStartTime() {
return $this->startTime;
}
public function getEndTime() {
return $this->endTime;
}
public function getAlternateStartdate() {
return $this->alternateStartdate;
}
public function getAlternateEnddate() {
return $this->alternateEnddate;
}
public function getClassLevelId() {
return $this->classLevelId;
}
public function getClassLevelLabel() {
return $this->classLevelLabel;
}
public function getClassLevelColorCode() {
return $this->classLevelColorCode;
}
public function getTeachers() {
return $this->teachers;
}
public function getClassRoomId() {
return $this->classRoomId;
}
public function getClassRoomName() {
return $this->classRoomName;
}
public function getNbStudents() {
return $this->nbStudents;
}
}
?>
Template TWIG:
{% block main_content %}
{% set currentSemester = app.session.get('currentSemester') %}
<div class="widget-box">
<div class="widget-title">
<span class="icon">
<i class="icon-th"></i>
</span>
<h5>Planning du {{ currentSemester.startDate|date("d/m/Y") }} au {{ currentSemester.endDate|date("d/m/Y") }}</h5>
</div>
<div class="widget-content nopadding">
<table id="planning" class="table table-bordered">
<thead>
<tr>
<th rowspan="2"> </th>
{% for headerCell in headerCells %}
<th colspan="{{ headerCell.classRooms | length }}">{{ headerCell.day | day }}</th>
{% endfor %}
</tr>
<tr>
{% for headerCell in headerCells %}
{% for classRoom in headerCell.classRooms %}
<th>{{ classRoom }}</th>
{% endfor %}
{% endfor %}
</tr>
</thead>
{% for row in planningRows %}
<tr>
<th>{{ row.startTime | date('H:i') }} - {{ row.endTime | date('H:i')}}</th>
{% for dayCells in row.cells %}
{% for classRoomCell in dayCells %}
{% if classRoomCell is not null %}
<td class="center" {% if classRoomCell.rowspan > 0 %} rowspan="{{ classRoomCell.rowspan }}" style="border: 3px solid {{ classRoomCell.course.classLevelColorCode }}"{% endif %}>
{% if classRoomCell.course is not null %}
<div class="transbox">
<p>
<strong>Niveau {{ classRoomCell.course.classLevelLabel }}</strong>
<br/>
{{ classRoomCell.course.startTime | date('H:i') }} - {{ classRoomCell.course.endTime | date('H:i') }}
<br />
{% for teacher in classRoomCell.course.teachers %}
{{ teacher['teacher_firstName'] }} {{ teacher['teacher_lastName'] }}<br />
{% endfor %}
{% if classRoomCell.course.alternateStartDate is not empty or classRoomCell.course.alternateStartDate is not empty %}
{% set currentSemester = app.session.get('currentSemester') %}
{% if classRoomCell.course.alternateStartDate is not empty %}
à partir du {{ classRoomCell.course.alternateStartDate | date("d/m/Y") }}
<br />
{%endif %}
{% if classRoomCell.course.alternateEndDate is not empty %}
jusqu'au {{ classRoomCell.course.alternateEndDate | date("d/m/Y") }}
<br />
{%endif %}
{% endif %}
<a href="{{ path('course_show', { 'id': classRoomCell.course.id }) }}">Détail</a>
</p>
</div>
{% else %}
{{ classRoomCell.content | raw }}
{% endif %}
</td>
{% endif %}
{% endfor %}
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
Construction:
private function generatePlanning() {
$semesterId = $this->getSelectedSemesterId();
$courses = $this->getManager()->getAllHydratedCourses($semesterId);
// $organizationBranchId = $this->getSelectedOrganizationBranchId();
// $classRooms = $this->getEntityManager()->getRepository('VirguleMainBundle:ClassRoom')->getClassRoomsForOrganizationBranch($organizationBranchId);
$planning = new Planning($courses);
return Array('headerCells' => $planning->getHeader(), 'planningRows' => $planning->getRows());
}
Le planning en l'état construit les colonnes de salles à partir de celles contenues dans les cours passés en paramètres, donc si vous avez une salle qui ne contient aucun cours, elle n'apparaîtra pas, mais ça se change facilement.Sûrement trop tard, mais j'ai modifié pour ma part le PlanningCellule.php comme suit dans la fonction __set :Voici :
Merci,Code : Tout sélectionner
<?php include('Planning.php'); include('PlanningCellule.php'); include('PlanningMapper.php'); $contenusCellules[] = new PlanningCellule(1,'17:15:00','19:00:00','#008000','<b>Zeus</b><br />B1/1'); $contenusCellules[] = new PlanningCellule(1,'19:00:00','21:00:00','#7CCAF4','<b>Ryle</b><br />A2'); $planning = new Planning(1, 6, 540, 1320, 15, $contenusCellules); $planning->afficherHtmlTable(); ?>
Fabrice
Code : Tout sélectionner
if ($tabHeure[1] == 15)
$value += 0.25;
if ($tabHeure[1] == 30)
$value += 0.5;
if ($tabHeure[1] == 45)
$value += 0.75;