Source of file CountdownWidgetExtension.php
Size: 2,882 Bytes - Last Modified: 2021-12-23T10:51:11+00:00
/var/www/docs.ssmods.com/process/src/code/CountdownWidgetExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | <?php class CountdownWidgetExtension extends DataExtension { private static $db = array( 'EndDate' => 'Datetime', 'CountdownType' => 'Varchar', 'CountdownElementID' => 'Varchar', 'CountdownElementClass' => 'Varchar' ); private static $defaults = array( 'CountdownElementID' => 'clock', 'CountdownElementClass' => 'CountdownClock' ); private $options = array( 'DaysOnly' => array( 'Template' => 'CountdownDiv', 'Script' => 'countdown-days-only' ), 'CouponDays' => array( 'Template' => 'CountdownDiv', 'Script' => 'countdown-coupon-days' ), 'CouponWeeks' => array( 'Template' => 'CountdownSpan', 'Script' => 'countdown-coupon-weeks' ), 'Legacy' => array( 'Template' => 'CountdownDiv', 'Script' => 'countdown-legacy' ) ); public function updateCMSFields(FieldList $fields) { $countdownTypes = array(); foreach ($this->options as $key => $value) { $countdownTypes[$key] = $key; } $fields->addFieldsToTab('Root.Countdown', array( DateField::create('EndDate', 'EndDate') ->setConfig('showcalendar', true), DropdownField::create('CountdownType', 'CountdownType', $countdownTypes) ->setEmptyString('Select one'), TextField::create('CountdownElementID'), TextField::create('CountdownElementClass') ) ); } public function jsScripts() { Requirements::javascript('framework/thirdparty/jquery/jquery.js'); Requirements::javascript('countdown/thirdparty/jQuery.countdown/dist/jquery.countdown.js'); } public function formattedEndDate() { return gmdate(DATE_W3C, strtotime($this->owner->EndDate)); } public function HasEnded() { if (!$this->owner->EndDate || !$this->owner->CountdownType) { return false; } return $this->owner->dbObject('EndDate')->InPast(); } public function Countdown() { if (!$this->owner->EndDate || !$this->owner->CountdownType) { return; } $this->jsScripts(); $formatDate = $this->formattedEndDate(); $vars = array( 'EndDate' => $formatDate, 'ElementClass' => $this->owner->CountdownElementClass, 'ElementID' => $this->owner->CountdownElementID ); $script = $this->options[$this->owner->CountdownType]['Script']; $template = $this->options[$this->owner->CountdownType]['Template']; Requirements::javascriptTemplate("countdown/js/$script.js", $vars, true); return $this->owner->renderWith($template); } } |