ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBookingScheduleGUI Class Reference

Class ilBookingScheduleGUI. More...

+ Collaboration diagram for ilBookingScheduleGUI:

Public Member Functions

 __construct ($a_parent_obj)
 Constructor.
 executeCommand ()
 main switch
 render ()
 Render list of booking schedules.
 create ()
 Render creation form.
 edit ()
 Render edit form.
 initForm ($a_mode="create", $id=NULL)
 Build property form.
 save ()
 Create new dataset.
 update ()
 Update dataset.
 confirmDelete ()
 Confirm delete.
 delete ()
 Delete schedule.

Protected Member Functions

 setDefinitionFromPost (ilPropertyFormGUI $form)
 Reload definition values from post data.
 formToObject ($form, $schedule)
 Convert incoming form data to schedule object.
 parseTime ($raw)
 Parse/normalize incoming time values.

Detailed Description

Constructor & Destructor Documentation

ilBookingScheduleGUI::__construct (   $a_parent_obj)

Constructor.

Parameters
object$a_parent_obj

Definition at line 19 of file class.ilBookingScheduleGUI.php.

{
$this->ref_id = $a_parent_obj->ref_id;
$this->slots_no = $a_parent_obj->object->getNumberOfSlots();
}

Member Function Documentation

ilBookingScheduleGUI::confirmDelete ( )

Confirm delete.

Definition at line 455 of file class.ilBookingScheduleGUI.php.

References $_GET, $ilCtrl, $lng, $tpl, and $type.

{
global $ilCtrl, $lng, $tpl, $ilTabs;
include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
$conf = new ilConfirmationGUI();
$conf->setFormAction($ilCtrl->getFormAction($this));
$conf->setHeaderText($lng->txt('book_confirm_delete'));
include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
$type = new ilBookingSchedule((int)$_GET['schedule_id']);
$conf->addItem('schedule_id', (int)$_GET['schedule_id'], $type->getTitle());
$conf->setConfirm($lng->txt('delete'), 'delete');
$conf->setCancel($lng->txt('cancel'), 'render');
$tpl->setContent($conf->getHTML());
}
ilBookingScheduleGUI::create ( )

Render creation form.

Definition at line 69 of file class.ilBookingScheduleGUI.php.

References $ilCtrl, $lng, $tpl, and initForm().

{
global $tpl, $ilCtrl, $ilTabs, $lng;
$ilTabs->clearTargets();
$ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
$form = $this->initForm();
$tpl->setContent($form->getHTML());
}

+ Here is the call graph for this function:

ilBookingScheduleGUI::delete ( )

Delete schedule.

Definition at line 476 of file class.ilBookingScheduleGUI.php.

References $_POST, $ilCtrl, $lng, and ilUtil\sendSuccess().

{
global $ilCtrl, $lng;
include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
$obj = new ilBookingSchedule((int)$_POST['schedule_id']);
$obj->delete();
ilUtil::sendSuccess($lng->txt('book_schedule_deleted'), true);
$ilCtrl->redirect($this, 'render');
}

+ Here is the call graph for this function:

ilBookingScheduleGUI::edit ( )

Render edit form.

Definition at line 83 of file class.ilBookingScheduleGUI.php.

References $_GET, $ilCtrl, $lng, $tpl, and initForm().

{
global $tpl, $ilCtrl, $ilTabs, $lng;
$ilTabs->clearTargets();
$ilTabs->setBackTarget($lng->txt('book_back_to_list'), $ilCtrl->getLinkTarget($this, 'render'));
$form = $this->initForm('edit', (int)$_GET['schedule_id']);
$tpl->setContent($form->getHTML());
}

+ Here is the call graph for this function:

ilBookingScheduleGUI::executeCommand ( )

main switch

Definition at line 28 of file class.ilBookingScheduleGUI.php.

References $cmd, $ilCtrl, and $tpl.

{
global $tpl, $ilTabs, $ilCtrl;
$next_class = $ilCtrl->getNextClass($this);
switch($next_class)
{
default:
$cmd = $ilCtrl->getCmd("render");
$this->$cmd();
break;
}
return true;
}
ilBookingScheduleGUI::formToObject (   $form,
  $schedule 
)
protected

Convert incoming form data to schedule object.

Parameters
object$form
object$schedule

Definition at line 329 of file class.ilBookingScheduleGUI.php.

References parseTime().

Referenced by save(), and update().

{
global $ilObjDataCache;
$schedule->setTitle($form->getInput("title"));
$schedule->setPoolId($ilObjDataCache->lookupObjId($this->ref_id));
$schedule->setDeadline($form->getInput("deadline"));
/*
if($form->getInput("type") == "flexible")
{
$schedule->setRaster($form->getInput("raster"));
$schedule->setMinRental($form->getInput("rent_min"));
$schedule->setMaxRental($form->getInput("rent_max"));
$schedule->setAutoBreak($form->getInput("break"));
}
else
{
$schedule->setRaster(NULL);
$schedule->setMinRental(NULL);
$schedule->setMaxRental(NULL);
$schedule->setAutoBreak(NULL);
}
*/
$definition = array();
foreach($form->getInput("days") as $day_id)
{
$day_slots = array();
foreach($form->getInput($day_id."_slot") as $slot)
{
if(trim($slot))
{
$fromto = explode("-", $slot);
if(sizeof($fromto) == 2)
{
$from = $this->parseTime($fromto[0]);
$to = $this->parseTime($fromto[1]);
if($from && $to)
{
$definition[$day_id][] = $from."-".$to;
}
}
}
}
if(!sizeof($definition[$day_id]))
{
$definition[$day_id] = array("00:00-23:59");
}
}
// slots may not overlap
foreach($definition as $day_id => $slots)
{
$old = 0;
sort($slots);
foreach($slots as $idx => $slot)
{
$slot = explode('-', $slot);
$from = $slot[0];
$to = $slot[1];
if($from < $old)
{
$from = $old;
$slots[$idx] = $from.'-'.$to;
if($to < $from)
{
unset($slots[$idx]);
}
}
$old = $to;
}
$definition[$day_id] = $slots;
}
$schedule->setDefinition($definition);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingScheduleGUI::initForm (   $a_mode = "create",
  $id = NULL 
)

Build property form.

Parameters
string$a_mode
int$id
Returns
object

Definition at line 100 of file class.ilBookingScheduleGUI.php.

References $ilCtrl, $lng, $title, and ilFormPropertyGUI\setInfo().

Referenced by create(), edit(), save(), and update().

{
global $lng, $ilCtrl;
$lng->loadLanguageModule("dateplaner");
include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
$form_gui = new ilPropertyFormGUI();
$title = new ilTextInputGUI($lng->txt("title"), "title");
$title->setRequired(true);
$title->setSize(40);
$title->setMaxLength(120);
$form_gui->addItem($title);
/*
$type = new ilRadioGroupInputGUI($lng->txt("book_schedule_type"), "type");
$type->setRequired(true);
$form_gui->addItem($type);
$fix = new ilRadioOption($lng->txt("book_schedule_type_fix"), "fix");
$fix->setInfo($lng->txt("book_schedule_type_fix_info"));
$type->addOption($fix);
$flex = new ilRadioOption($lng->txt("book_schedule_type_flexible"), "flexible");
$flex->setInfo($lng->txt("book_schedule_type_flexible_info"));
$type->addOption($flex);
$raster = new ilNumberInputGUI($lng->txt("book_schedule_raster"), "raster");
$raster->setRequired(true);
$raster->setInfo($lng->txt("book_schedule_raster_info"));
$raster->setMinValue(1);
$raster->setSize(3);
$raster->setMaxLength(3);
$raster->setSuffix($lng->txt("book_minutes"));
$flex->addSubItem($raster);
$rent_min = new ilNumberInputGUI($lng->txt("book_schedule_rent_min"), "rent_min");
$rent_min->setInfo($lng->txt("book_schedule_rent_info"));
$rent_min->setMinValue(1);
$rent_min->setSize(3);
$rent_min->setMaxLength(3);
$flex->addSubItem($rent_min);
$rent_max = new ilNumberInputGUI($lng->txt("book_schedule_rent_max"), "rent_max");
$rent_max->setInfo($lng->txt("book_schedule_rent_info"));
$rent_max->setMinValue(1);
$rent_max->setSize(3);
$rent_max->setMaxLength(3);
$flex->addSubItem($rent_max);
$break = new ilNumberInputGUI($lng->txt("book_schedule_break"), "break");
$break->setInfo($lng->txt("book_schedule_break_info"));
$break->setMinValue(1);
$break->setSize(3);
$break->setMaxLength(3);
$flex->addSubItem($break);
*/
$definition = new ilCheckboxGroupInputGUI($lng->txt("book_schedule_days"), "days");
$definition->setInfo($lng->txt("book_schedule_days_info"));
$definition->setRequired(true);
$form_gui->addItem($definition);
$days = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
foreach($days as $day_id)
{
$day = new ilCheckboxOption($lng->txt(ucfirst($day_id)."_long"), $day_id);
$definition->addOption($day);
for($loop = 1; $loop <= $this->slots_no; $loop++)
{
$hours[$day_id][$loop] = new ilTextInputGUI($lng->txt("book_schedule_slot")." ".$loop, $day_id."_slot[]");
$hours[$day_id][$loop]->setSize(14);
$hours[$day_id][$loop]->setMaxLength(14);
$day->addSubItem($hours[$day_id][$loop]);
}
}
$deadline = new ilNumberInputGUI($lng->txt("book_deadline"), "deadline");
$deadline->setInfo($lng->txt("book_deadline_info"));
$deadline->setSuffix($lng->txt("book_hours"));
$deadline->setMinValue(0);
$deadline->setSize(3);
$deadline->setMaxLength(3);
$form_gui->addItem($deadline);
if ($a_mode == "edit")
{
$form_gui->setTitle($lng->txt("book_edit_schedule"));
$item = new ilHiddenInputGUI('schedule_id');
$item->setValue($id);
$form_gui->addItem($item);
include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
$schedule = new ilBookingSchedule($id);
$title->setValue($schedule->getTitle());
$deadline->setValue($schedule->getDeadline());
/*
if($schedule->getRaster())
{
$type->setValue("flexible");
$raster->setValue($schedule->getRaster());
$rent_min->setValue($schedule->getMinRental());
$rent_max->setValue($schedule->getMaxRental());
$break->setValue($schedule->getAutoBreak());
}
else
{
$type->setValue("fix");
}
*/
$def = $schedule->getDefinition();
$definition->setValue(array_keys($def));
foreach($def as $day_id => $slots)
{
foreach($slots as $idx => $slot)
{
if(isset($hours[$day_id][$idx+1]))
{
$hours[$day_id][$idx+1]->setValue($slot);
}
}
}
$form_gui->addCommandButton("update", $lng->txt("save"));
}
else
{
$form_gui->setTitle($lng->txt("book_add_schedule"));
$form_gui->addCommandButton("save", $lng->txt("save"));
$form_gui->addCommandButton("render", $lng->txt("cancel"));
}
$form_gui->setFormAction($ilCtrl->getFormAction($this));
return $form_gui;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingScheduleGUI::parseTime (   $raw)
protected

Parse/normalize incoming time values.

Parameters
string$raw

Definition at line 411 of file class.ilBookingScheduleGUI.php.

Referenced by formToObject().

{
$raw = strtolower(trim($raw));
$am = $pm = false;
$min = 0;
if(substr($raw, -2) == 'pm')
{
$pm = true;
$raw = substr($raw, 0, -2);
}
else if(substr($raw, -2) == 'am')
{
$am = true;
$raw = substr($raw, 0, -2);
}
if($colon = strpos($raw, ':'))
{
$min = (int)substr($raw, $colon+1);
$raw = substr($raw, 0, $colon);
}
$hours = (int)$raw;
if(!$min)
{
$min = "0";
}
if($pm && $hours < 12)
{
$hours += 12;
}
else if($am && $hours == 12)
{
$hours -= 12;
}
if($hours > 23 || $min > 59)
{
return false;
}
return str_pad($hours, 2, "0", STR_PAD_LEFT).":".
str_pad($min, 2, "0", STR_PAD_LEFT);
}

+ Here is the caller graph for this function:

ilBookingScheduleGUI::render ( )

Render list of booking schedules.

uses ilBookingSchedulesTableGUI

Definition at line 49 of file class.ilBookingScheduleGUI.php.

References $ilCtrl, $lng, $tpl, and ilToolbarGUI\addButton().

Referenced by save(), and update().

{
global $tpl, $lng, $ilCtrl, $ilAccess;
if ($ilAccess->checkAccess('write', '', $this->ref_id))
{
include_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
$bar = new ilToolbarGUI;
$bar->addButton($lng->txt('book_add_schedule'), $ilCtrl->getLinkTarget($this, 'create'));
$bar = $bar->getHTML();
}
include_once 'Modules/BookingManager/classes/class.ilBookingSchedulesTableGUI.php';
$table = new ilBookingSchedulesTableGUI($this, 'render', $this->ref_id);
$tpl->setContent($bar.$table->getHTML());
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingScheduleGUI::save ( )

Create new dataset.

Definition at line 243 of file class.ilBookingScheduleGUI.php.

References $lng, $tpl, formToObject(), initForm(), render(), ilUtil\sendSuccess(), and setDefinitionFromPost().

{
global $tpl, $lng;
$form = $this->initForm();
if($form->checkInput())
{
include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
$obj = new ilBookingSchedule;
$this->formToObject($form, $obj);
$obj->save();
ilUtil::sendSuccess($lng->txt("book_schedule_added"));
$this->render();
}
else
{
$form->setValuesByPost();
$this->setDefinitionFromPost($form);
$tpl->setContent($form->getHTML());
}
}

+ Here is the call graph for this function:

ilBookingScheduleGUI::setDefinitionFromPost ( ilPropertyFormGUI  $form)
protected

Reload definition values from post data.

Parameters
ilPropertyFormGUI$form

Definition at line 297 of file class.ilBookingScheduleGUI.php.

References ilPropertyFormGUI\getInput(), and ilPropertyFormGUI\getItemByPostVar().

Referenced by save(), and update().

{
$days = $form->getInput("days");
if($days)
{
$days_group = $form->getItemByPostVar("days");
foreach($days_group->getOptions() as $option)
{
$days_fields[$option->getValue()] = $option;
}
foreach($days as $day)
{
$slot = $form->getInput($day."_slot");
$subs = $days_fields[$day]->getSubItems();
if($slot[0])
{
$subs[0]->setValue($slot[0]);
}
if($slot[1])
{
$subs[1]->setValue($slot[1]);
}
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingScheduleGUI::update ( )

Update dataset.

Definition at line 269 of file class.ilBookingScheduleGUI.php.

References $_POST, $lng, $tpl, formToObject(), initForm(), render(), ilUtil\sendSuccess(), and setDefinitionFromPost().

{
global $tpl, $lng;
$form = $this->initForm('edit', (int)$_POST['schedule_id']);
if($form->checkInput())
{
include_once 'Modules/BookingManager/classes/class.ilBookingSchedule.php';
$obj = new ilBookingSchedule((int)$_POST['schedule_id']);
$this->formToObject($form, $obj);
$obj->update();
ilUtil::sendSuccess($lng->txt("book_schedule_updated"));
$this->render();
}
else
{
$form->setValuesByPost();
$this->setDefinitionFromPost($form);
$tpl->setContent($form->getHTML());
}
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: