项目作者: Edofre

项目描述 :
Yii 2 component for easy fullcalendar integration
高级语言: PHP
项目地址: git://github.com/Edofre/yii2-fullcalendar.git
创建时间: 2016-03-14T23:31:49Z
项目社区:https://github.com/Edofre/yii2-fullcalendar

开源协议:MIT License

下载


Yii2 fullcalendar component

Latest Stable Version
Total Downloads
Latest Unstable Version
License
composer.lock

Installation

The preferred way to install this extension is through composer.

To install, either run

  1. $ php composer.phar require edofre/yii2-fullcalendar "V1.0.11"

or add

  1. "edofre/yii2-fullcalendar": "V1.0.11"

to the require section of your composer.json file.

Usage

Fullcalendar can be created as following, all options are optional, below is just an example of most options

  1. <?= edofre\fullcalendar\Fullcalendar::widget([
  2. 'options' => [
  3. 'id' => 'calendar',
  4. 'language' => 'nl',
  5. ],
  6. 'clientOptions' => [
  7. 'weekNumbers' => true,
  8. 'selectable' => true,
  9. 'defaultView' => 'agendaWeek',
  10. 'eventResize' => new JsExpression("
  11. function(event, delta, revertFunc, jsEvent, ui, view) {
  12. console.log(event);
  13. }
  14. "),
  15. ],
  16. 'events' => Url::to(['calendar/events', 'id' => $uniqid]),
  17. ]);
  18. ?>

Events can be added in three ways, PHP array, Javascript array or JSON feed

PHP array

  1. <?php
  2. $events = [
  3. new Event([
  4. 'title' => 'Appointment #' . rand(1, 999),
  5. 'start' => '2016-03-18T14:00:00',
  6. ]),
  7. // Everything editable
  8. new Event([
  9. 'id' => uniqid(),
  10. 'title' => 'Appointment #' . rand(1, 999),
  11. 'start' => '2016-03-17T12:30:00',
  12. 'end' => '2016-03-17T13:30:00',
  13. 'editable' => true,
  14. 'startEditable' => true,
  15. 'durationEditable' => true,
  16. ]),
  17. // No overlap
  18. new Event([
  19. 'id' => uniqid(),
  20. 'title' => 'Appointment #' . rand(1, 999),
  21. 'start' => '2016-03-17T15:30:00',
  22. 'end' => '2016-03-17T19:30:00',
  23. 'overlap' => false, // Overlap is default true
  24. 'editable' => true,
  25. 'startEditable' => true,
  26. 'durationEditable' => true,
  27. ]),
  28. // Only duration editable
  29. new Event([
  30. 'id' => uniqid(),
  31. 'title' => 'Appointment #' . rand(1, 999),
  32. 'start' => '2016-03-16T11:00:00',
  33. 'end' => '2016-03-16T11:30:00',
  34. 'startEditable' => false,
  35. 'durationEditable' => true,
  36. ]),
  37. // Only start editable
  38. new Event([
  39. 'id' => uniqid(),
  40. 'title' => 'Appointment #' . rand(1, 999),
  41. 'start' => '2016-03-15T14:00:00',
  42. 'end' => '2016-03-15T15:30:00',
  43. 'startEditable' => true,
  44. 'durationEditable' => false,
  45. ]),
  46. ];
  47. ?>
  48. <?= edofre\fullcalendar\Fullcalendar::widget([
  49. 'events' => $events
  50. ]);
  51. ?>

Javascript array

  1. <?= edofre\fullcalendar\Fullcalendar::widget([
  2. 'events' => new JsExpression('[
  3. {
  4. "id":null,
  5. "title":"Appointment #776",
  6. "allDay":false,
  7. "start":"2016-03-18T14:00:00",
  8. "end":null,
  9. "url":null,
  10. "className":null,
  11. "editable":false,
  12. "startEditable":false,
  13. "durationEditable":false,
  14. "rendering":null,
  15. "overlap":true,
  16. "constraint":null,
  17. "source":null,
  18. "color":null,
  19. "backgroundColor":"grey",
  20. "borderColor":"black",
  21. "textColor":null
  22. },
  23. {
  24. "id":"56e74da126014",
  25. "title":"Appointment #928",
  26. "allDay":false,
  27. "start":"2016-03-17T12:30:00",
  28. "end":"2016-03-17T13:30:00",
  29. "url":null,
  30. "className":null,
  31. "editable":true,
  32. "startEditable":true,
  33. "durationEditable":true,
  34. "rendering":null,
  35. "overlap":true,
  36. "constraint":null,
  37. "source":null,
  38. "color":null,
  39. "backgroundColor":"grey",
  40. "borderColor":"black",
  41. "textColor":null
  42. },
  43. {
  44. "id":"56e74da126050",
  45. "title":"Appointment #197",
  46. "allDay":false,
  47. "start":"2016-03-17T15:30:00",
  48. "end":"2016-03-17T19:30:00",
  49. "url":null,
  50. "className":null,
  51. "editable":true,
  52. "startEditable":true,
  53. "durationEditable":true,
  54. "rendering":null,
  55. "overlap":false,
  56. "constraint":null,
  57. "source":null,
  58. "color":null,
  59. "backgroundColor":"grey",
  60. "borderColor":"black",
  61. "textColor":null
  62. },
  63. {
  64. "id":"56e74da126080",
  65. "title":"Appointment #537",
  66. "allDay":false,
  67. "start":"2016-03-16T11:00:00",
  68. "end":"2016-03-16T11:30:00",
  69. "url":null,
  70. "className":null,
  71. "editable":false,
  72. "startEditable":false,
  73. "durationEditable":true,
  74. "rendering":null,
  75. "overlap":true,
  76. "constraint":null,
  77. "source":null,
  78. "color":null,
  79. "backgroundColor":"grey",
  80. "borderColor":"black",
  81. "textColor":null
  82. },
  83. {
  84. "id":"56e74da1260a7",
  85. "title":"Appointment #465",
  86. "allDay":false,
  87. "start":"2016-03-15T14:00:00",
  88. "end":"2016-03-15T15:30:00",
  89. "url":null,
  90. "className":null,
  91. "editable":false,
  92. "startEditable":true,
  93. "durationEditable":false,
  94. "rendering":null,
  95. "overlap":true,
  96. "constraint":null,
  97. "source":null,
  98. "color":null,
  99. "backgroundColor":"grey",
  100. "borderColor":"black",
  101. "textColor":null
  102. },
  103. ]'),
  104. ]);
  105. ?>

JSON feed

  1. <?= edofre\fullcalendar\Fullcalendar::widget([
  2. 'events' => Url::to(['calendar/events', 'id' => $uniqid]),
  3. ]);
  4. ?>

Your controller action would then return an array as following

  1. /**
  2. * @param $id
  3. * @param $start
  4. * @param $end
  5. * @return array
  6. */
  7. public function actionEvents($id, $start, $end)
  8. {
  9. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  10. return [
  11. // minimum
  12. new Event([
  13. 'title' => 'Appointment #' . rand(1, 999),
  14. 'start' => '2016-03-18T14:00:00',
  15. ]),
  16. // Everything editable
  17. new Event([
  18. 'id' => uniqid(),
  19. 'title' => 'Appointment #' . rand(1, 999),
  20. 'start' => '2016-03-17T12:30:00',
  21. 'end' => '2016-03-17T13:30:00',
  22. 'editable' => true,
  23. 'startEditable' => true,
  24. 'durationEditable' => true,
  25. ]),
  26. // No overlap
  27. new Event([
  28. 'id' => uniqid(),
  29. 'title' => 'Appointment #' . rand(1, 999),
  30. 'start' => '2016-03-17T15:30:00',
  31. 'end' => '2016-03-17T19:30:00',
  32. 'overlap' => false, // Overlap is default true
  33. 'editable' => true,
  34. 'startEditable' => true,
  35. 'durationEditable' => true,
  36. ]),
  37. // Only duration editable
  38. new Event([
  39. 'id' => uniqid(),
  40. 'title' => 'Appointment #' . rand(1, 999),
  41. 'start' => '2016-03-16T11:00:00',
  42. 'end' => '2016-03-16T11:30:00',
  43. 'startEditable' => false,
  44. 'durationEditable' => true,
  45. ]),
  46. // Only start editable
  47. new Event([
  48. 'id' => uniqid(),
  49. 'title' => 'Appointment #' . rand(1, 999),
  50. 'start' => '2016-03-15T14:00:00',
  51. 'end' => '2016-03-15T15:30:00',
  52. 'startEditable' => true,
  53. 'durationEditable' => false,
  54. ]),
  55. ];
  56. }

Callbacks

Callbacks have to be wrapped in a JsExpression() object. For example if you want to use the eventResize you would add the following to the fullcalendar clientOptions

  1. <?= edofre\fullcalendar\Fullcalendar::widget([
  2. 'clientOptions' => [
  3. 'eventResize' => new JsExpression("
  4. function(event, delta, revertFunc, jsEvent, ui, view) {
  5. console.log(event.id);
  6. console.log(delta);
  7. }
  8. "),
  9. ],
  10. ]);
  11. ?>