Skip to content

Instantly share code, notes, and snippets.

@klaftertief
Created July 5, 2010 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaftertief/464199 to your computer and use it in GitHub Desktop.
Save klaftertief/464199 to your computer and use it in GitHub Desktop.
<?php
require_once(TOOLKIT . '/class.datasource.php');
Class datasourcedays extends Datasource{
public $dsParamROOTELEMENT = 'days';
public $dsParamURL = 'http://symphony.dev';
public $dsParamXPATH = '/';
public $dsParamCACHE = '60';
public $dsParamFILTERS = array(
'start' => '{$start: -2 months}',
'end' => '{$end: today}',
);
public function __construct(&$parent, $env=NULL, $process_params=true){
parent::__construct($parent, $env, $process_params);
$this->_dependencies = array();
}
public function about(){
return array(
'name' => 'Days',
'author' => array(
'name' => 'Jonas Coch',
'website' => 'http://symphony.dev',
'email' => 'jonas@klaftertief.de'),
'version' => '1.0',
'release-date' => '2010-07-04T15:49:57+00:00');
}
public function allowEditorToParse(){
return false;
}
public function grab(&$param_pool){
$result = new XMLElement($this->dsParamROOTELEMENT);
if((isset($this->_env) && is_array($this->_env)) && is_array($this->dsParamFILTERS) && !empty($this->dsParamFILTERS)){
foreach($this->dsParamFILTERS as $key => $value){
$value = stripslashes($value);
$new_value = $this->__processParametersInString($value, $this->_env);
if(strlen(trim($new_value)) == 0) unset($this->dsParamFILTERS[$key]);
else $this->dsParamFILTERS[$key] = $new_value;
}
}
$start = strtotime($this->dsParamFILTERS['start']);
$end = strtotime($this->dsParamFILTERS['end']);
$time = $start;
$year = date('Y', $start);
$month = date('m', $start);
$week = date('W', $start);
$xmlYear = new XMLElement('year', NULL, array('year' => $year));
$xmlMonth = new XMLElement('month', NULL, array('month' => $month));
$xmlYear->appendChild($xmlMonth);
$result->appendChild($xmlYear);
while ($time <= $end) {
if ($year != date('Y', $time)) {
$year = date('Y', $time);
$xmlYear = new XMLElement('year', NULL, array('year' => $year));
$result->appendChild($xmlYear);
}
if ($month != date('m', $time)) {
$month = date('m', $time);
$xmlMonth = new XMLElement('month', NULL, array('month' => $month));
$xmlYear->appendChild($xmlMonth);
}
$xmlDate = new XMLElement('date', sprintf("%04d-%02d-%02d", $year, date('m', $time), date('d', $time)), array('day-of-year' => date('z', $time), 'weekday'=> date('w', $time), 'calendar-week'=> date('W', $time)));
$xmlMonth->appendChild($xmlDate);
$time = $time + (24 * 60 * 60);
}
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment