2014-04-27 14:44:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Script\Features;
|
|
|
|
|
|
|
|
use FML\Controls\Label;
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\Script\Script;
|
2014-04-27 14:44:40 +02:00
|
|
|
use FML\Script\ScriptInclude;
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\Script\ScriptLabel;
|
2014-04-27 14:44:40 +02:00
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Script Feature showing the current time on a Label
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @author steeffeen
|
2014-04-27 14:44:40 +02:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
2014-05-14 23:24:00 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
class Clock extends ScriptFeature {
|
|
|
|
/*
|
2014-06-21 03:18:21 +02:00
|
|
|
* Protected properties
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
2014-05-14 23:24:00 +02:00
|
|
|
/** @var Label $label */
|
2014-04-27 14:44:40 +02:00
|
|
|
protected $label = null;
|
|
|
|
protected $showSeconds = null;
|
|
|
|
protected $showFullDate = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Clock Feature
|
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @param Label $label (optional) Clock Label
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param bool $showSeconds (optional) Whether the seconds should be shown
|
|
|
|
* @param bool $showFullDate (optional) Whether the date should be shown
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false) {
|
2014-08-11 23:15:53 +02:00
|
|
|
if ($label !== null) {
|
2014-06-21 03:18:21 +02:00
|
|
|
$this->setLabel($label);
|
|
|
|
}
|
2014-04-27 14:44:40 +02:00
|
|
|
$this->setShowSeconds($showSeconds);
|
|
|
|
$this->setShowFullDate($showFullDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Label
|
|
|
|
*
|
|
|
|
* @param Label $label Clock Label
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function setLabel(Label $label) {
|
2014-06-21 03:18:21 +02:00
|
|
|
$this->label = $label->checkId();
|
2014-04-27 14:44:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Set whether seconds should be shown
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param bool $showSeconds Whether seconds should be shown
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function setShowSeconds($showSeconds) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->showSeconds = (bool)$showSeconds;
|
2014-04-27 14:44:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Set whether the full date should be shown
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param bool $showFullDate Whether the full date should be shown
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-27 14:44:40 +02:00
|
|
|
*/
|
|
|
|
public function setShowFullDate($showFullDate) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->showFullDate = (bool)$showFullDate;
|
2014-04-27 14:44:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Script\Features\ScriptFeature::prepare()
|
|
|
|
*/
|
|
|
|
public function prepare(Script $script) {
|
|
|
|
$script->setScriptInclude(ScriptInclude::TEXTLIB);
|
|
|
|
$script->appendGenericScriptLabel(ScriptLabel::TICK, $this->getScriptText(), true);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Get the script text
|
2014-04-27 14:44:40 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getScriptText() {
|
2014-06-21 03:18:21 +02:00
|
|
|
$controlId = $this->label->getId(true, true);
|
2014-04-27 14:44:40 +02:00
|
|
|
$scriptText = "
|
2014-06-21 03:18:21 +02:00
|
|
|
declare ClockLabel <=> (Page.GetFirstChild({$controlId}) as CMlLabel);
|
2014-04-27 14:44:40 +02:00
|
|
|
declare TimeText = CurrentLocalDateText;";
|
|
|
|
if (!$this->showSeconds) {
|
|
|
|
$scriptText .= "
|
|
|
|
TimeText = TextLib::SubText(TimeText, 0, 16);";
|
|
|
|
}
|
|
|
|
if (!$this->showFullDate) {
|
|
|
|
$scriptText .= "
|
|
|
|
TimeText = TextLib::SubText(TimeText, 11, 9);";
|
|
|
|
}
|
|
|
|
$scriptText .= "
|
|
|
|
ClockLabel.Value = TimeText;";
|
|
|
|
return $scriptText;
|
|
|
|
}
|
|
|
|
}
|