Skip to content

Commit

Permalink
changed: timeline viz events now loaded segmentally via ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
pollen8 committed Sep 24, 2012
1 parent c6b5a83 commit 0d0d53f
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@ public function display()
{
echo $model->$pluginTask();
}
else
{
$task = JRequest::getVar('task');

$path = JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/controllers/' . $viz->plugin . '.php';
if (file_exists($path))
{
require_once $path;
}
else
{
JError::raiseNotice(400, 'could not load viz:' . $viz->plugin);
return;
}

$controllerName = 'FabrikControllerVisualization' . $viz->plugin;
$controller = new $controllerName();
$controller->addViewPath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/views');
$controller->addViewPath(COM_FABRIK_FRONTEND . '/views');

//add the model path
$modelpaths = JModel::addIncludePath(JPATH_SITE . '/plugins/fabrik_visualization/' . $viz->plugin . '/models');
$modelpaths = JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models');

$origId = JRequest::getInt('visualizationid');
JRequest::setVar('visualizationid', $id);
$controller->$task();

}
}

public function getPluginHTML()
Expand Down
2 changes: 1 addition & 1 deletion components/com_fabrik/models/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -8943,7 +8943,7 @@ public function setRenderContext($id = null)
else
{
if (((JRequest::getVar('task') == 'list.view' || JRequest::getVar('task') == 'list.delete') && JRequest::getVar('format') == 'raw') || JRequest::getVar('layout') == '_advancedsearch'
|| JRequest::getVar('task') === 'list.elementFilter')
|| JRequest::getVar('task') === 'list.elementFilter' || JRequest::getVar('setListRefFromRequest') == 1)
{
// Testing for ajax nav in content plugin or in advanced search
$this->setRenderContextFromRequest();
Expand Down
16 changes: 16 additions & 0 deletions plugins/fabrik_visualization/timeline/controllers/timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@
* @subpackage Fabrik.visualization.timeline
* @since 3.0
*/

class FabrikControllerVisualizationtimeline extends FabrikControllerVisualization
{

/**
* Get a series of timeline events
*
* @return void
*/

public function ajax_getEvents()
{
$viewName = 'timeline';
$usersConfig = JComponentHelper::getParams('com_fabrik');
$model = $this->getModel($viewName);
$id = JRequest::getInt('visualizationid', 0);
$model->setId($id);
$model->onAjax_getEvents();
}
}
274 changes: 262 additions & 12 deletions plugins/fabrik_visualization/timeline/models/timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,258 @@
class fabrikModelTimeline extends FabrikFEModelVisualization
{

/**
* Number of ajax records to return each time
*
* @var int
*/
protected $step = 40;

/**
* Get a slice of the total events.
*
* @return string json encoded event list
*/

public function onAjax_getEvents()
{
$params = $this->getParams();
$lists = $params->get('timeline_table', array());

$session = JFactory::getSession();

$key = 'com_fabrik.timeline.total.' . JRequest::getInt('visualizationid');
if (!$session->has($key))
{
$totals = $this->getTotal();
$session->set($key, $totals);
}
else
{
$totals = $session->get($key);
}
$currentList = JRequest::getInt('currentList', 0);
$start = JRequest::getInt('start', 0);

$res = new stdClass;
$fabrik = new stdClass;
$json_data = array ();
$res->events = array();
$fabrik->total = array_sum($totals);
$fabrik->done = 0;

if ($start <= $totals[$currentList])
{
$fabrik->next = $start + $this->step;
$fabrik->currentList = $currentList;

$c = array_search($currentList, $lists);
$res->events = $this->jsonEvents($currentList, $totals[$currentList], $start, $c);


if ($start + $this->step > $totals[$currentList])
{
// Move onto next list?
$nextListId = JArrayHelper::getValue($lists, $c + 1, null);
$fabrik->nextListId = $nextListId;
if (is_null($nextListId))
{
// No more lists to search
$this->endAjax_getEvents($fabrik);
}
else
{
$c = array_search($nextListId, $lists);
$res->events = array_merge($res->events, $this->jsonEvents($nextListId, $totals[$nextListId], 0, $c));
}
}
}
else
{
// Move onto next list?
$nextListId = JArrayHelper::getValue($lists, $c + 1, null);
$fabrik->nextListId = $nextListId;
if (is_null($nextListId))
{
// No more lists to search
$this->endAjax_getEvents($fabrik);
}
else
{
$fabrik->next = 0;
$fabrik->currentList = $nextListId;
$c = array_search($nextListId, $lists);
$fabrik->nextC = $c;
$res->events = array_merge($res->events, $this->jsonEvents($nextListId, $totals[$nextListId], 0, $c));
}
}

$res->dateTimeFormat = 'ISO8601';

$json_data = array (
//Timeline attributes
//'wiki-url'=>'http://simile.mit.edu/shelf',
//'wiki-section'=>'Simile Cubism Timeline',
//'dateTimeFormat'=>'Gregorian', //JSON!
//Event attributes
'events'=> $res
);
$return = new stdClass;
$return->timeline = $json_data;
$return->fabrik = $fabrik;

echo json_encode($return);
}

protected function endAjax_getEvents(&$res)
{
$session = JFactory::getSession();
$key = 'com_fabrik.timeline.total.' . JRequest::getInt('visualizationid');

$res->done = 1;
$session->clear($key);
}

/**
* Get JSON events
*
* @param int $listId list id
* @param int $total total list record count
* @param int $start where to start from
* @param int $c list order in timeline params
*
* @return array of events
*/

protected function jsonEvents($listId, $total, $start, $c)
{
$app = JFactory::getApplication();
$params = $this->getParams();
$document = JFactory::getDocument();
$timeZone = new DateTimeZone(JFactory::getConfig()->get('offset'));
$w = new FabrikWorker;
jimport('string.normalise');
$templates = (array) $params->get('timeline_detailtemplate', array());
$startdates = (array) $params->get('timeline_startdate', array());
$enddates = (array) $params->get('timeline_enddate', array());
$labels = (array) $params->get('timeline_label', array());
$colours = (array) $params->get('timeline_colour', array());
$textColours = (array) $params->get('timeline_text_color', array());
$classNames = (array) $params->get('timeline_class', array());

$template = JArrayHelper::getValue($templates, $c);
$colour = JArrayHelper::getValue($colours, $c);
$startdate = JArrayHelper::getValue($startdates, $c);
$enddate = JArrayHelper::getValue($enddates, $c);
$title = JArrayHelper::getValue($labels, $c);
$textColour = JArrayHelper::getValue($textColours, $c);
$className = JArrayHelper::getValue($classNames, $c);


$listModel = JModel::getInstance('List', 'FabrikFEModel');
$listModel->setId($listId);

$eventdata = array();
JRequest::setVar('limit' . $listId, $this->step);
JRequest::setVar('limitstart' . $listId, $start);
$listModel->setLimits();


if ($listModel->canView() || $listModel->canEdit())
{
$data = $listModel->getData();
$elements = $listModel->getElements();
$enddate2 = $enddate;
$startdate2 = $startdate;
$endKey = FabrikString::safeColName($enddate2);
$startKey = FabrikString::safeColName($startdate2);
if (!array_key_exists($endKey, $elements))
{
$endKey = $startKey;
$enddate2 = $startdate2;
}
$endElement = $elements[$endKey];

if (!array_key_exists($startKey, $elements))
{
JError::raiseError(500, $startdate2 . " not found in the list, is it published?");
}
$startElement = $elements[$startKey];
$endParams = $endElement->getParams();
$startParams = $startElement->getParams();

foreach ($data as $group)
{
if (is_array($group))
{
foreach ($group as $row)
{
$event = new stdClass;
$html = $w->parseMessageForPlaceHolder($template, JArrayHelper::fromObject($row));
$event->description = $html;
$event->start = array_key_exists($startdate . '_raw', $row) ? $row->{$startdate . '_raw'} : $row->$startdate;
$event->end = $event->start;
if (trim($enddate) !== '')
{
$end = array_key_exists($enddate . '_raw', $row) ? $row->{$enddate . '_raw'} : @$row->$enddate;
$event->end = ($end >= $event->start) ? $end : '';

$sDate = JFactory::getDate($event->end);
$sDate->setTimezone($timeZone);
$event->end = $sDate->toISO8601(true);
$bits = explode('+', $event->end);
$event->end = $bits[0] . '+00:00';
}
$sDate = JFactory::getDate($event->start);
$sDate->setTimezone($timeZone);
$event->start = $sDate->toISO8601(true);
$bits = explode('+', $event->start);
$event->start = $bits[0] . '+00:00';

$event->title = strip_tags(@$row->$title);
$url = $this->getLinkURL($listModel, $row, $c);
$event->link = ($listModel->getOutPutFormat() == 'json') ? '#' : $url;
$event->image = '';
$event->color = $colour;
$event->textColor = $textColour;
$event->classname = isset($row->$className) ? $row->$className : '';
$event->classname = strip_tags($event->classname);
$event->classname = $this->toVariable($event->classname);
if ($event->start !== '' && !is_null($event->start))
{
if ($event->end == $event->start)
{
$event->end = '';
}
$eventdata[] = $event;
}
}
}
}
}
return $eventdata;
}

/**
* Get total number of Events
*
* @return array of ints keyed on list id
*/

protected function getTotal()
{
$params = $this->getParams();
$lists = $params->get('timeline_table', array());
$totals = array();
foreach ($lists as $listid)
{
$listModel = JModel::getInstance('List', 'FabrikFEModel');
$listModel->setId($listid);
$totals[$listid] = $listModel->getTotalRecords();
}
return $totals;
}

/**
* Internally render the plugin, and add required script declarations
* to the document
Expand Down Expand Up @@ -52,7 +304,7 @@ public function render()

$lists = $params->get('timeline_table', array());
$eventdata = array();
foreach ($lists as $listid)
/* foreach ($lists as $listid)
{
$template = JArrayHelper::getValue($templates, $c);
$listModel = JModel::getInstance('List', 'FabrikFEModel');
Expand Down Expand Up @@ -120,15 +372,7 @@ public function render()
$event->start = $bits[0] . '+00:00';
$event->title = strip_tags(@$row->$title);
/* if ($app->isAdmin())
{
$url = 'index.php?option=com_fabrik&task=' . $nextview . '.view&formid=' . $table->form_id . '&rowid=' . $row->__pk_val;
}
else
{
$url = 'index.php?option=com_fabrik&view=' . $nextview . '&formid=' . $table->form_id . '&rowid=' . $row->__pk_val
. '&listid=' . $listid;
} */
$url = $this->getLinkURL($listModel, $row, $c);
$event->link = ($listModel->getOutPutFormat() == 'json') ? '#' : $url;
$event->image = '';
Expand All @@ -150,15 +394,21 @@ public function render()
}
}
$c++;
}
} */
$json = new StdClass;
$json->dateTimeFormat = 'ISO8601';
$json->events = $eventdata;
$json->events = array();
$json->bands = $this->getBandInfo();
$json = json_encode($json);
$options = new stdClass;
$options->id = $this->getId();
$options->listRef ='list' . $lists[0] . '_' . JFactory::getApplication()->scope . '_' . $lists[0];
// $options->listRef = 'list43_mod_fabrik_visualization_43';
$options->step = $this->step;
$options->admin = (bool) $app->isAdmin();
$options->dateFormat = $params->get('timeline_date_format', '%c');
$options->orientation = $params->get('timeline_orientation', 'horizontal');
$options->currentList = $lists[0];
$options = json_encode($options);
$ref = $this->getJSRenderContext();
$str = "var " . $ref . " = new FbVisTimeline($json, $options);";
Expand Down
2 changes: 1 addition & 1 deletion plugins/fabrik_visualization/timeline/timeline-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d0d53f

Please sign in to comment.