Initial commit
This commit is contained in:
54
formwidgets/CalendarSelector.php
Normal file
54
formwidgets/CalendarSelector.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php namespace NicoSt\GCalendar\FormWidgets;
|
||||
|
||||
use Backend\Classes\FormWidgetBase;
|
||||
use Log;
|
||||
use Flash;
|
||||
use Lang;
|
||||
|
||||
use NicoSt\GCalendar\Models\Settings;
|
||||
use NicoSt\GCalendar\Classes\GoogleCalendarService;
|
||||
|
||||
class CalendarSelector extends FormWidgetBase {
|
||||
|
||||
protected $defaultAlias = 'calendarSelector';
|
||||
|
||||
public function getSaveValue($value) {
|
||||
if(!isset($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$calendarsToSave = [];
|
||||
foreach ($value as &$calendar) {
|
||||
if (array_key_exists('checked', $calendar)) {
|
||||
$calendarsToSave[] = $calendar;
|
||||
}
|
||||
}
|
||||
return $calendarsToSave;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$service = new GoogleCalendarService();
|
||||
$calendars = $service->calendarList();
|
||||
|
||||
if (isset($calendars['error'])) {
|
||||
$calendars = '';
|
||||
}
|
||||
|
||||
$this->vars['calendars'] = $calendars;
|
||||
$this->vars['saved_selector'] = $this->extractIds();
|
||||
|
||||
return $this->makePartial('selector');
|
||||
}
|
||||
|
||||
private function extractIds() {
|
||||
$calendarSelectors = Settings::get('calendar_selector', []);
|
||||
|
||||
$ids = [];
|
||||
foreach ($calendarSelectors as &$selector) {
|
||||
$ids[] = $selector['id'];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user