1<?php 2 3namespace dokuwiki\plugin\sentry\conf; 4 5use dokuwiki\plugin\config\core\Setting\SettingNumeric; 6use dokuwiki\plugin\sentry\Event; 7 8/** 9 * Custom settings class 10 */ 11class Setting extends SettingNumeric 12{ 13 /** @inheritdoc */ 14 public function initialize($default = null, $local = null, $protected = null) 15 { 16 parent::initialize($default, $local, $protected); 17 18 // our default is PHP's error reporting 19 $this->default = error_reporting(); 20 if ($local == 0) { 21 $this->local = $this->default; 22 } 23 } 24 25 /** @inheritdoc */ 26 protected function cleanValue($value) 27 { 28 if ($value === null) return null; 29 if (is_array($value)) $value = array_sum($value); 30 31 return (int)$value; 32 } 33 34 /** @inheritdoc */ 35 public function isDefault() 36 { 37 return parent::isDefault() || (error_reporting() == $this->local); 38 } 39 40 /** @inheritdoc */ 41 public function html(\admin_plugin_config $plugin, $echo = false) 42 { 43 44 if ($echo) { 45 $current = $this->input; 46 } else { 47 $current = $this->local; 48 } 49 50 $label = '<label>' . $this->prompt($plugin) . '</label>'; 51 $input = ''; 52 53 foreach (Event::CORE_ERRORS as $val => $info) { 54 $checked = ''; 55 if ($current & $val) { 56 $checked = 'checked="checked"'; 57 } 58 59 $class = 'selection'; 60 if (error_reporting() & $val) { 61 if ($current & $val) { 62 $class .= ' selectiondefault'; 63 } 64 } else { 65 if (!($current & $val)) { 66 $class .= ' selectiondefault'; 67 } 68 } 69 70 $inputId = 'config___' . $this->key . '_' . $val; 71 72 $input .= '<div class="' . $class . '">'; 73 $input .= '<label for="' . $inputId . '">' . hsc($info[1]) . '</label>'; 74 $input .= '<input type="checkbox" id="' . $inputId . '" name="config[' . $this->key . '][]" ' . 75 'value="' . $val . '" ' . $checked . ' />'; 76 $input .= '</div>'; 77 } 78 79 $input .= '<div class="selection">' . $current . '</div>'; 80 81 return [$label, $input]; 82 } 83 84} 85