/**
  * Getting a color palette
  * For now we only have a hsv palette, could be extended with more options
  *
  * Potential options:
  * Standard CKEditor color palette
  * http://stackoverflow.com/questions/13455922/display-only-few-desired-colors-in-a-ckeditor-palette
  * 000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF
  *
  * Consider adding color names like this:
  * http://stackoverflow.com/questions/2993970/function-that-converts-hex-color-values-to-an-approximate-color-name
  *
  * Color variation:
  * http://stackoverflow.com/questions/1177826/simple-color-variation
  *
  * @param int $numColors Number of colors - default: 30
  * @return null
  */
 public static function get_palette($numColors = 50, $type = 'hsv')
 {
     //overwriting with the palette from the calendar settings
     $s = CalendarConfig::subpackage_settings('colors');
     $arr = $s['basepalette'];
     return $arr;
     if ($type == 'hsv') {
         $s = 1;
         $v = 1;
         $arr = array();
         for ($i = 0; $i <= $numColors; $i++) {
             $c = new Color();
             $h = $i / $numColors;
             $hex = $c->fromHSV($h, $s, $v)->toHexString();
             $arr[$hex] = $hex;
         }
         return $arr;
     } elseif ($type == 'websafe') {
         //websafe colors
         $cs = array('00', '33', '66', '99', 'CC', 'FF');
         $arr = array();
         for ($i = 0; $i < 6; $i++) {
             for ($j = 0; $j < 6; $j++) {
                 for ($k = 0; $k < 6; $k++) {
                     $c = $cs[$i] . $cs[$j] . $cs[$k];
                     $arr["{$c}"] = "#{$c}";
                 }
             }
         }
         return $arr;
     }
 }
 /**
  * Contructor
  * @param type $controller
  * @param type $name
  */
 function __construct($controller, $name)
 {
     //Administering calendars
     if (CalendarConfig::subpackage_enabled('calendars')) {
         //Configuration for calendar grid field
         $gridCalendarConfig = GridFieldConfig_RecordEditor::create();
         $gridCalendarConfig->removeComponentsByType('GridFieldDataColumns');
         $gridCalendarConfig->addComponent($dataColumns = new GridFieldDataColumns(), 'GridFieldEditButton');
         $c = singleton('Calendar');
         $summaryFields = $c->summaryFields();
         //$summaryFields = array(
         //	'Title' => 'Title',
         //	//'SubscriptionOptIn' => 'Opt In',
         //	//'Shaded' => 'Shaded'
         //);
         $s = CalendarConfig::subpackage_settings('calendars');
         //show shading info in the gridfield
         if ($s['shading']) {
             $summaryFields['Shaded'] = 'Shaded';
         }
         $dataColumns->setDisplayFields($summaryFields);
         //settings for the case that colors are enabled
         if ($s['colors']) {
             $dataColumns->setFieldFormatting(array("Title" => '<div style=\\"height:20px;width:20px;display:inline-block;vertical-align:middle;margin-right:6px;background:$Color\\"></div> $Title'));
         }
         $GridFieldCalendars = new GridField('Calendars', '', PublicCalendar::get(), $gridCalendarConfig);
         $fields = new FieldList($GridFieldCalendars);
         $actions = new FieldList();
         $this->addExtraClass('CalendarsForm');
         parent::__construct($controller, $name, $fields, $actions);
     }
 }
 /**
  * Handles returning the JSON events data for a time range.
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function publicevents($request, $json = true, $calendars = null, $offset = 30)
 {
     $calendarsSupplied = false;
     if ($calendars) {
         $calendarsSupplied = true;
     }
     $events = PublicEvent::get()->filter(array('StartDateTime:GreaterThan' => $this->eventlistOffsetDate('start', $request->postVar('start'), $offset), 'EndDateTime:LessThan' => $this->eventlistOffsetDate('end', $request->postVar('end'), $offset)));
     //If shaded events are enabled we need to filter shaded calendars out
     //note that this only takes effect when no calendars have been supplied
     //if calendars are supplied, this needs to be taken care of from that method
     $sC = CalendarConfig::subpackage_settings('calendars');
     if ($sC['shading']) {
         if (!$calendars) {
             $calendars = PublicCalendar::get();
             $calendars = $calendars->filter(array('shaded' => false));
         }
     }
     if ($calendars) {
         $calIDList = $calendars->getIdList();
         //adding in 0 to allow for showing events without a calendar
         if (!$calendarsSupplied) {
             $calIDList[0] = 0;
         }
         //Debug::dump($calIDList);
         $events = $events->filter('CalendarID', $calIDList);
     }
     $result = array();
     if ($events) {
         foreach ($events as $event) {
             $calendar = $event->Calendar();
             $bgColor = '#999';
             //default
             $textColor = '#FFF';
             //default
             $borderColor = '#555';
             if ($calendar->exists()) {
                 $bgColor = $calendar->getColorWithHash();
                 $textColor = '#FFF';
                 $borderColor = $calendar->getColorWithHash();
             }
             $resultArr = self::format_event_for_fullcalendar($event);
             $resultArr = array_merge($resultArr, array('backgroundColor' => $bgColor, 'textColor' => '#FFF', 'borderColor' => $borderColor));
             $result[] = $resultArr;
         }
     }
     if ($json) {
         $response = new SS_HTTPResponse(Convert::array2json($result));
         $response->addHeader('Content-Type', 'application/json');
         return $response;
     } else {
         return $result;
     }
 }
 public function CalendarViewLink()
 {
     $s = CalendarConfig::subpackage_settings('pagetypes');
     $indexSetting = $s['calendarpage']['index'];
     $link = $this->Link();
     if ($indexSetting == 'eventlist') {
         return $link . 'calendarview/';
     } elseif ($indexSetting == 'calendarview') {
         return $link;
     }
 }