Created
March 8, 2016 15:03
-
-
Save nitriques/aee4861337ca34d957e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(TOOLKIT . '/class.datasource.php'); | |
Class datasourcemonth_calendar extends Datasource { | |
public $dsParamROOTELEMENT = 'month-calendar'; | |
public $dsParamORDER = 'asc'; | |
public $dsParamREDIRECTONEMPTY = 'no'; | |
public function __construct(&$parent, $env=NULL, $process_params=true){ | |
parent::__construct($parent, $env, $process_params); | |
} | |
public function about(){ | |
return array( | |
'name' => 'Month Calendar', | |
'author' => array( | |
'name' => 'Deux Huit Huit', | |
'website' => 'https://deuxhuithuit.com/', | |
'email' => 'open-source (at) deuxhuithuit.com' | |
), | |
'version' => '1.2', | |
'release-date' => '2015-09-17' | |
); | |
} | |
public function getSource(){ | |
return 'calendar'; | |
} | |
public function allowEditorToParse(){ | |
return false; | |
} | |
public function grab(&$param_pool=NULL){ | |
$result = new XMLElement($this->dsParamROOTELEMENT); | |
$env_params = Symphony::Engine()->Page()->Env(); | |
$startDateValue = '2016-01-01'; | |
// only get year-month | |
$startDateValue = date_format(date_create($startDateValue), 'Y-m-01'); | |
try { | |
$this->__generateXML($result, $startDateValue); | |
} catch(FrontendPageNotFoundException $e){ | |
// Work around. This ensures the 404 page is displayed and | |
// is not picked up by the default catch() statement below | |
FrontendPageNotFoundExceptionHandler::render($e); | |
} catch(Exception $e){ | |
$result->appendChild(new XMLElement('error', $e->getMessage())); | |
return $result; | |
} | |
if($this->_force_empty_result) $result = $this->emptyXMLSet(); | |
return $result; | |
} | |
protected function __generateXML(&$result, &$startDateValue) { | |
$now = date_create(); | |
$curEntries = array(); | |
$now_month = date_format($now, 'm'); | |
$now_year = date_format($now, 'Y'); | |
$env_params = Symphony::Engine()->Page()->Env(); | |
$now_month_date = date_create("{$now_year}-{$now_month}-01"); | |
$selectedDate = null; | |
for($c = 0; $c < 12; $c++) { | |
$startDate = date('Y-m-d', strtotime($startDateValue. ' +' . $c .' month')); | |
$endDate = date('Y-m-d', strtotime($startDateValue. ' +' . ($c + 1) .' month')); | |
$month = new XMLElement('item'); | |
$month->setAttribute('date', $startDate); | |
if ($now_month_date > date_create($startDate)) { | |
$month->setAttribute('is-past', 'Yes'); | |
} | |
$result->appendChild($month); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment