54 lines
1.3 KiB
PHP
Executable File
54 lines
1.3 KiB
PHP
Executable File
<?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;
|
|
}
|
|
} |