Commit f28ae5c3 by semenov

start widget

parents
codecept.phar
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 02.04.2015
*/
namespace skeeks\widget\fullcalendar;
use Yii;
use yii\web\AssetBundle;
/**
* Class CoreAsset
* @package skeeks\widget\fullcalendar
*/
class CoreAsset extends AssetBundle
{
/**
* [$sourcePath description]
* @var string
*/
public $sourcePath = '@bower/fullcalendar/dist';
/**
* the language the calender will be displayed in
* @var string ISO2 code for the wished display language
*/
public $language = NULL;
/**
* [$autoGenerate description]
* @var boolean
*/
public $autoGenerate = true;
/**
* tell the calendar, if you like to render google calendar events within the view
* @var boolean
*/
public $googleCalendar = false;
/**
* [$css description]
* @var array
*/
public $css = [
'fullcalendar.css',
];
/**
* [$js description]
* @var array
*/
public $js = [
'fullcalendar.js',
'lang-all.js',
];
/**
* [$depends description]
* @var array
*/
public $depends = [
'yii2fullcalendar\MomentAsset',
'yii2fullcalendar\PrintAsset',
'yii\jui\JuiAsset'
];
/**
* @inheritdoc
*/
public function registerAssetFiles($view)
{
$language = $this->language ? $this->language : Yii::$app->language;
if ($language != 'en-us')
{
$this->js[] = "lang/{$language}.js";
}
if($this->googleCalendar)
{
$this->js[] = 'gcal.js';
}
parent::registerAssetFiles($view);
}
}
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 02.04.2015
*/
namespace skeeks\widget\fullcalendar;
use Yii;
use yii\base\Model;
use yii\web\View;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
use yii\base\Widget;
/**
* Class FullCalendarWidget
* @package skeeks\widget\fullcalendar
*/
class FullCalendarWidget extends Widget
{
/**
* @var array options the HTML attributes (name-value pairs) for the field container tag.
* The values will be HTML-encoded using [[Html::encode()]].
* If a value is null, the corresponding attribute will not be rendered.
*/
public $options = [
'class' => 'fullcalendar',
];
/**
* @var array clientOptions the HTML attributes for the widget container tag.
*/
public $clientOptions = [
'weekends' => true,
'default' => 'month',
'editable' => false,
];
/**
* Holds an array of Event Objects
* @var array events of yii2fullcalendar\models\Event
* @todo add the event class and write docs
**/
public $events = [];
/**
* Define the look n feel for the calendar header, known placeholders are left, center, right
* @var array header format
*/
public $header = [
'center'=>'title',
'left'=>'prev,next today',
'right'=>'month,agendaWeek'
];
/**
* Will hold an url to json formatted events!
* @var url to json service
*/
public $ajaxEvents = NULL;
/**
* wheather the events will be "sticky" on pagination or not
* @var boolean
*/
public $stickyEvents = true;
/**
* tell the calendar, if you like to render google calendar events within the view
* @var boolean
*/
public $googleCalendar = false;
/**
* the text that will be displayed on changing the pages
* @var string
*/
public $loading = 'Loading ...';
/**
* internal marker for the name of the plugin
* @var string
*/
private $_pluginName = 'fullCalendar';
/**
* The javascript function to us as en eventRender callback
* @var string the javascript code that implements the eventRender function
*/
public $eventRender = "";
/**
* The javascript function to us as en eventAfterRender callback
* @var string the javascript code that implements the eventAfterRender function
*/
public $eventAfterRender = "";
/**
* The javascript function to us as en eventAfterAllRender callback
* @var string the javascript code that implements the eventAfterAllRender function
*/
public $eventAfterAllRender = "";
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
//checks for the element id
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
//checks for the element id
if (!isset($this->options['class'])) {
$this->options['class'] = 'fullcalendar';
}
parent::init();
}
/**
* Renders the widget.
*/
public function run()
{
$this->options['data-plugin-name'] = $this->_pluginName;
if (!isset($this->options['class'])) {
$this->options['class'] = 'fullcalendar';
}
echo Html::beginTag('div', $this->options) . "\n";
echo Html::beginTag('div',['class'=>'fc-loading','style' => 'display:none;']);
echo Html::encode($this->loading);
echo Html::endTag('div')."\n";
echo Html::endTag('div')."\n";
$this->registerPlugin();
}
/**
* Registers the FullCalendar javascript assets and builds the requiered js for the widget and the related events
*/
protected function registerPlugin()
{
$id = $this->options['id'];
$view = $this->getView();
/** @var \yii\web\AssetBundle $assetClass */
$assets = CoreAsset::register($view);
if (isset($this->options['lang']))
{
$assets->language = $this->options['lang'];
}
if ($this->googleCalendar)
{
$asset->googleCalendar = $this->googleCalendar;
}
$js = array();
if($this->ajaxEvents != NULL){
$this->clientOptions['events'] = $this->ajaxEvents;
}
if(is_array($this->header) && isset($this->clientOptions['header']))
{
$this->clientOptions['header'] = array_merge($this->header,$this->clientOptions['header']);
} else {
$this->clientOptions['header'] = $this->header;
}
$cleanOptions = $this->getClientOptions();
$js[] = "$('#$id').fullCalendar($cleanOptions);";
//lets check if we have an event for the calendar...
if(count($this->events)>0)
{
foreach($this->events AS $event)
{
$jsonEvent = Json::encode($event);
$isSticky = $this->stickyEvents;
$js[] = "$('#$id').fullCalendar('renderEvent',$jsonEvent,$isSticky);";
}
}
$view->registerJs(implode("\n", $js),View::POS_READY);
}
/**
* @return array the options for the text field
*/
protected function getClientOptions()
{
$id = $this->options['id'];
$options['loading'] = new JsExpression("function(isLoading, view ) {
$('#{$id}').find('.fc-loading').toggle(isLoading);
}");
if ($this->eventRender){
$options['eventRender'] = new JsExpression($this->eventRender);
}
if ($this->eventAfterRender){
$options['eventAfterRender'] = new JsExpression($this->eventAfterRender);
}
if ($this->eventAfterAllRender){
$options['eventAfterAllRender'] = new JsExpression($this->eventAfterAllRender);
}
$options = array_merge($options, $this->clientOptions);
return Json::encode($options);
}
}
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 02.04.2015
*/
namespace skeeks\widget\fullcalendar;
use yii\web\AssetBundle;
/**
* Class MomentAsset
* @package skeeks\widget\fullcalendar
*/
class MomentAsset extends AssetBundle
{
/**
* [$sourcePath description]
* @var string
*/
public $sourcePath = '@bower/moment';
/**
* [$js description]
* @var array
*/
public $js = [
'moment.js'
];
}
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 02.04.2015
*/
namespace skeeks\widget\fullcalendar;
use yii\web\AssetBundle;
/**
* Class PrintAsset
* @package skeeks\widget\fullcalendar
*/
class PrintAsset extends AssetBundle
{
/**
* [$sourcePath description]
* @var string
*/
public $sourcePath = '@bower/fullcalendar/dist';
/**
* [$css description]
* @var array
*/
public $css = [
'fullcalendar.print.css'
];
/**
* options for the css file beeing published
* @var [type]
*/
public $cssOptions = [
'media' => 'print'
];
}
yii2fullcalendar
================
Installation
============
Package is although registered at packagist.org - so you can just add one line of code, to let it run!
add the following line to your composer.json require section:
```json
"skeeks/yii2-widget-highcharts": "*",
```
And ensure, that you have the follwing plugin installed global:
> php composer.phar global require "fxp/composer-asset-plugin:~1.0"
Changelog
---------
Usage
=====
Quickstart Looks like this:
```php
$events = array();
//Testing
$Event = new \skeeks\widget\fullcalendar\models\Event();
$Event->id = 1;
$Event->title = 'Testing';
$Event->start = date('Y-m-d\TH:m:s\Z');
$events[] = $Event;
$Event = new \yii2fullcalendar\models\Event();
$Event->id = 2;
$Event->title = 'Testing';
$Event->start = date('Y-m-d\TH:m:s\Z',strtotime('tomorrow 6am'));
$events[] = $Event;
?>
<?= \skeeks\widget\fullcalendar\yii2fullcalendar::widget(array(
'events'=> $events,
));
```
Note, that this will only view the events without any detailed view or option to add a new event.. etc.
AJAX Usage
==========
If you wanna use ajax loader, this could look like this:
```php
<?= \skeeks\widget\fullcalendar\yii2fullcalendar::widget([
'options' => [
'language' => 'de',
//... more options to be defined here!
],
'ajaxEvents' => Url::to(['/timetrack/default/jsoncalendar'])
]);
?>
```
and inside your referenced controller, the action should look like this:
```php
public function actionJsoncalendar($start=NULL,$end=NULL,$_=NULL){
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$times = \app\modules\timetrack\models\Timetable::find()->where(array('category'=>\app\modules\timetrack\models\Timetable::CAT_TIMETRACK))->all();
$events = array();
foreach ($times AS $time){
//Testing
$Event = new \skeeks\widget\fullcalendar\models\Event();
$Event->id = $time->id;
$Event->title = $time->categoryAsString;
$Event->start = date('Y-m-d\TH:i:s\Z',strtotime($time->date_start.' '.$time->time_start));
$Event->end = date('Y-m-d\TH:i:s\Z',strtotime($time->date_end.' '.$time->time_end));
$events[] = $Event;
}
return $events;
}
```
> [![skeeks!](https://gravatar.com/userimage/74431132/13d04d83218593564422770b616e5622.jpg)](http://www.skeeks.com)
<i>Web development has never been so fun!</i>
[www.skeeks.com](http://www.skeeks.com)
\ No newline at end of file
{
"name": "skeeks/yii2-widget-fullcalendar",
"description": "Yii2 fullcalendar Widgets",
"keywords": ["yii2", "extension", "widget", "fullcalendar"],
"type": "yii2-extension",
"homepage": "http://www.skeeks.com/",
"license": "BSD 3-Clause",
"support": {
"issues": "http://www.skeeks.com/",
"wiki": "http://git.skeeks.com/skeeks/yii2-widget-highcharts/blob/master/README.md",
"source": "http://git.skeeks.com/skeeks/yii2-widget-highcharts"
},
"authors": [
{
"name": "Semenov Alexander",
"email": "semenov@skeeks.com"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2" : "*",
"yiisoft/yii2-jui": "*",
"skeeks/yii2-sx": "*",
"bower-asset/fullcalendar" : "*"
},
"require-dev": {
"codeception/codeception": "*"
},
"autoload": {
"psr-4": { "skeeks\\widget\\fullcalendar\\": "" }
}
}
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 02.04.2015
*/
namespace skeeks\widget\fullcalendar\models;
use yii\base\Model;
class Event extends Model
{
/**
* the id of the shown event
* @var integer
*/
public $id;
/**
* The text on an event's element
* @var string
*/
public $title;
/**
* Whether an event occurs at a specific time-of-day. This property affects whether an event's time is shown. Also, in the agenda views, determines if it is displayed in the "all-day" section.
* If this value is not explicitly specified, allDayDefault will be used if it is defined.
* If all else fails, FullCalendar will try to guess. If either the start or end value has a "T" as part of the ISO8601 date string, allDay will become false. Otherwise, it will be true.
* Don't include quotes around your true/false. This value is a boolean, not a string!
* @var boolean
*/
public $allDay;
/**
* The date/time an event begins. Required.
* A Moment-ish input, like an ISO8601 string. Throughout the API this will become a real Moment object.
* @var datetime
*/
public $start;
/**
* The exclusive date/time an event ends. Optional.
* A Moment-ish input, like an ISO8601 string. Throughout the API this will become a real Moment object.
* It is the moment immediately after the event has ended. For example, if the last full day of an event is Thursday, the exclusive end of the event will be 00:00:00 on Friday!
* @var datetime
*/
public $end;
/**
* A URL that will be visited when this event is clicked by the user. For more information on controlling this behavior, see the eventClick callback.
* @var [type]
*/
public $url;
/**
* A CSS class (or array of classes) that will be attached to this event's element.
* @var [type]
*/
public $className;
/**
* Overrides the master editable option for this single event.
* @var boolean
*/
public $editable;
/**
* Overrides the master eventStartEditable option for this single event.
* @var [type]
*/
public $startEditable;
/**
* Overrides the master eventDurationEditable option for this single event.
* @var [type]
*/
public $durationEditable;
/**
* A reference to the event source that this event came from.
* @var [type]
*/
public $source;
/**
* Sets an event's background and border color just like the calendar-wide eventColor option.
* @var [type]
*/
public $color;
/**
* Sets an event's background color just like the calendar-wide eventBackgroundColor option.
* @var [type]
*/
public $backgroundColor;
/**
* Sets an event's border color just like the the calendar-wide eventBorderColor option.
* @var [type]
*/
public $borderColor;
/**
* Sets an event's text color just like the calendar-wide eventTextColor option.
* @var [type]
*/
public $textColor;
public function rules()
{
return [
['id', 'integer'],
['title, allDay, start, end, url, className, source, color, backgroundColor, borderColor, textColor', 'safe'],
['editable, startEditable, durationEditable', 'boolean'],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment