Dateline widget renders my JavaScript Dateline. The event data for the dateline are provided by a Yii DataProvider (any object implementing yii\data\DataProviderInterface).
A demonstration of Dateline widget is here.
See it in action at Moordatlas.nl (Dutch). At Weltliteratur is a nice example of the underlying JavaScript widget.
Install Dateline with Composer. Either add the following to the require section of your composer.json
file:
"sjaakp/yii2-dateline": "*"
Or run:
composer require sjaakp/yii2-dateline "*"
You can manually install Dateline by downloading the source in ZIP-format.
Yii2-dateline implements a widget of the class Dateline
.
It gets its data from an ActiveDataProvider
, ArrayDataProvider
,
or other class derived from BaseDataProvider
Using it is not unlike using a GridView.
For instance, in the Controller you might have something like:
<?php
// ...
public function actionFoo() {
$dataProvider = new ActiveDataProvider([
'query' => InterestingEvent::find(),
'pagination' => false
]);
return $this->render('foo', [
'dataProvider' => $dataProvider
]);
}
// ...
?>
An example of rendering a Dateline
in the View
is:
use sjaakp\dateline\Dateline;
/* ... */
<?php $dl = Dateline::begin([
'dataProvider' => $dataProvider,
'attributes' => [
'id' => 'id',
'start' => 'date1',
'text' => 'name'
],
'options' => [
/* ... */
]
]);
$dl->band([
'size' => '75%',
'scale' => Dateline::WEEK,
'interval'=> 90,
])
->band([
'size' => '25%',
'layout' => 'overview',
'scale' => Dateline::YEAR,
'interval'=> 80
]);
Dateline::end();
?>
Dateline has the following options:
function($model)
returning {model attribute value}.Dateline consists of one or more Bands. They each display the Events in a different time resolution.
A Band is defined by the Dateline method band()
.
public function band( $options )
$options
is an array with the following keys:
'overview'
; all other values (including none) default to 'normal'
, which is the layout of the main bandDateline::MILLISECOND
Dateline::SECOND
Dateline::MINUTE
Dateline::HOUR
Dateline::DAY
Dateline::WEEK
Dateline::MONTH
Dateline::YEAR
Dateline::DECADE
Dateline::CENTURY
Dateline::MILLENNIUM
Note that we're not talking about PHP or JavaScript events here!
Dateline displays Events. These are Models or ActiveRecords characterized by a moment in time.
The Dateline::attributes property holds the translation from Model attributes to Dateline attributes.
A few attributes are essential for Dateline. The Dateline names are:
Events come in two types:
These are the basic Events, having just one point in time. Dateline displays them as dot icons. Only the above attributes are required.
These have a certain duration. Dateline displays them as a piece of 'tape'. Apart from the above, also required is:
Duration Events also have some optional attributes, making the Event imprecise:
post_start: optional. Indicates a degree of uncertainty in start
.
pre_stop: optional. Indicates a degree of uncertainty in stop
.
The imprecise part of a Duration Event is displayed as faded tape.
Dateline understands a lot of date formats (in the options and in the Event data). Every date can be provided in one of the following formats:
string
, recognized by JavaScript Date,
that is in RFC2822 or ISO-8601 format; among them MySQL date
and datetime
fieldsinteger
: Unix time stamp (seconds since the Unix Epoch, 1-1-1970,
return value of PHP time()
)
Comments