PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wire/modules/System/SystemNotifications/SystemNotificationsConfig.php

http://github.com/ryancramerdesign/ProcessWire
PHP | 204 lines | 165 code | 29 blank | 10 comment | 1 complexity | 6e1a3315a4c55cab9c48a535849d17e1 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Configuration class for the SystemNotifications module
  4. *
  5. */
  6. class SystemNotificationsConfig extends ModuleConfig {
  7. const ghostPosLeft = 1;
  8. const ghostPosRight = 2;
  9. const placementCombined = 0; // notifications and notices bundled together
  10. const placementSeparate = 1; // notifications are rendered separately from notices
  11. const placementNone = 2; // notifications are not rendered
  12. public function getDefaults() {
  13. if(empty($this->systemUserName)) $this->systemUserName = $this->users->get($this->config->superUserPageID)->name;
  14. return array(
  15. 'disabled' => 0, // SystemNotifications disabled?
  16. 'placement' => self::placementCombined, // placement of notifications relative to notices
  17. 'reverse' => 0, // reverse default sort order?
  18. 'systemUserID' => 41, // user that will receive system notifications
  19. 'systemUserName' => $this->systemUserName, // user that will receive system notifications (name)
  20. 'activeHooks' => array(0, 1, 2), // Indexes of $this->systemHooks that are active
  21. 'trackEdits' => 1, // Track page edits?
  22. 'updateDelay' => 5000, // delay between ajax updates (in ms) 5000+ recommended
  23. 'iconMessage' => 'check-square-o', // default icon for message notifications
  24. 'iconWarning' => 'exclamation-circle', // default icon for warning notifications
  25. 'iconError' => 'exclamation-triangle', // default icon for error notifications
  26. 'iconProgress' => 'spinner fa-spin', // icon for any item that has an active progress bar
  27. 'iconDebug' => 'bug', // default icon for debug-mode notification
  28. 'ghostDelay' => 1000, // how long a ghost appears on screen (in ms)
  29. 'ghostDelayError' => 2000, // how long an error ghost appears on screen (in ms)
  30. 'ghostFadeSpeed' => 'fast', // speed at which ghosts fade in or out, or blank for no fade
  31. 'ghostOpacity' => 0.85, // full opacity of ghost (when fully faded in)
  32. 'ghostPos' => 2, // ghost position: 1=left, 2=right
  33. 'ghostLimit' => 20, // only show 1 summary ghost if there are more than this number
  34. 'dateFormat' => 'rel', // date format to use in notifications (anything compatible with wireDate() function)
  35. );
  36. }
  37. /**
  38. * Configure notifications
  39. *
  40. * @return InputfieldWrapper
  41. *
  42. */
  43. public function getInputfields() {
  44. $form = parent::getInputfields();
  45. $modules = $this->wire('modules');
  46. $on = $this->_('On');
  47. $off = $this->_('Off');
  48. $f = $modules->get('InputfieldRadios');
  49. $f->attr('name', 'disabled');
  50. $f->label = __('Notifications status');
  51. $f->description = __('When turned off, notifications will not be rendered.');
  52. $f->addOption(0, $on);
  53. $f->addOption(1, $off);
  54. $f->optionColumns = 1;
  55. $f->columnWidth = 33;
  56. $form->add($f);
  57. $f = $modules->get('InputfieldRadios');
  58. $f->attr('name', 'trackEdits');
  59. $f->label = __('Track page edits?');
  60. $f->description = __('Notifies users when they try to edit a page that is already being edited.');
  61. $f->addOption(1, $on);
  62. $f->addOption(0, $off);
  63. $f->optionColumns = 1;
  64. $f->columnWidth = 34;
  65. $form->add($f);
  66. $f = $modules->get('InputfieldRadios');
  67. $f->attr('name', 'reverse');
  68. $f->label = __('Notification order');
  69. $f->description = __('Select what order the notifications should display in.');
  70. $f->addOption(0, __('Newest to oldest'));
  71. $f->addOption(1, __('Oldest to newest'));
  72. $f->optionColumns = 1;
  73. $f->columnWidth = 33;
  74. $form->add($f);
  75. $f = $modules->get('InputfieldCheckboxes');
  76. $f->attr('name', 'activeHooks');
  77. $f->label = __('Active automatic notification hooks');
  78. $f->description = __('Whenever one of these events occurs, the system user above will be notified.');
  79. $f->addOption(0, __('404 page not found'));
  80. $f->addOption(1, __('User login success and failure'));
  81. $f->addOption(2, __('User logout'));
  82. $f->notes = __('These are primarily just examples of notifications for the purpose of demonstration.');
  83. $f->columnWidth = 50;
  84. $form->add($f);
  85. $f = $modules->get('InputfieldName');
  86. $f->attr('name', 'systemUserName');
  87. $f->label = __('Name of user that receives system notifications');
  88. $f->columnWidth = 50;
  89. $form->add($f);
  90. $f = $modules->get('InputfieldInteger');
  91. $f->attr('name', 'updateDelay');
  92. $f->label = __('Time between updates');
  93. $f->description = __('How often to check for notification updates (in milliseconds). Example: 5000 means 5 seconds.');
  94. $f->columnWidth = 50;
  95. $form->add($f);
  96. $f = $modules->get('InputfieldText');
  97. $f->attr('name', 'dateFormat');
  98. $f->label = __('Date format');
  99. $f->description = __('Date format used for notifications. Use date() or strftime() format, or "relative" for relative date/time, "rel" for abbreviated date/time.');
  100. $f->columnWidth = 50;
  101. $form->add($f);
  102. $f = $modules->get('InputfieldIcon');
  103. $f->attr('name', 'iconMessage');
  104. $f->label = __('Message icon');
  105. $f->prefixValue = false;
  106. $form->add($f);
  107. $f = $modules->get('InputfieldIcon');
  108. $f->attr('name', 'iconWarning');
  109. $f->label = __('Warning icon');
  110. $f->prefixValue = false;
  111. $form->add($f);
  112. $f = $modules->get('InputfieldIcon');
  113. $f->attr('name', 'iconError');
  114. $f->label = __('Error icon');
  115. $f->prefixValue = false;
  116. $form->add($f);
  117. $f = $modules->get('InputfieldInteger');
  118. $f->attr('name', 'ghostDelay');
  119. $f->label = __('Ghost delay');
  120. $f->description = __('How long ghost messages appear for (in ms).');
  121. $f->columnWidth = 25;
  122. $form->add($f);
  123. $f = $modules->get('InputfieldInteger');
  124. $f->attr('name', 'ghostDelayError');
  125. $f->label = __('Ghost error delay');
  126. $f->description = __('How long ghost errors appear for (in ms).');
  127. $f->columnWidth = 25;
  128. $form->add($f);
  129. $f = $modules->get('InputfieldFloat');
  130. $f->attr('name', 'ghostOpacity');
  131. $f->label = __('Ghost full opacity');
  132. $f->description = __('Full opacity of ghosts (0.1-1.0)');
  133. $f->columnWidth = 25;
  134. $form->add($f);
  135. $f = $modules->get('InputfieldFloat');
  136. $f->attr('name', 'ghostLimit');
  137. $f->label = __('Ghost Limit');
  138. $f->description = __('Show summary ghost if more this.');
  139. $f->columnWidth = 25;
  140. $form->add($f);
  141. $f = $modules->get('InputfieldRadios');
  142. $f->attr('name', 'ghostFadeSpeed');
  143. $f->label = __('Ghost fade speed');
  144. $f->description = __('Speed at which ghosts fade in or out.');
  145. $f->addOption('', __('Immediate (no fade in/out)'));
  146. $f->addOption('fast', __('Fast'));
  147. $f->addOption('normal', __('Normal'));
  148. $f->addOption('slow', __('Slow'));
  149. $f->columnWidth = 50;
  150. $form->add($f);
  151. $f = $modules->get('InputfieldRadios');
  152. $f->attr('name', 'ghostPos');
  153. $f->label = __('Ghost position');
  154. $f->description = __('What side of the screen ghosts should float on.');
  155. $f->addOption(self::ghostPosLeft, $this->_('Left'));
  156. $f->addOption(self::ghostPosRight, $this->_('Right'));
  157. $f->columnWidth = 50;
  158. $form->add($f);
  159. $f = $modules->get('InputfieldRadios');
  160. $f->attr('name', 'placement');
  161. $f->label = __('Runtime/single-request notices');
  162. $f->addOption(self::placementCombined, __('Display as notifications'));
  163. $f->addOption(self::placementSeparate, __('Leave them alone'));
  164. $f->columnWidth = 50;
  165. $form->add($f);
  166. include_once(dirname(__FILE__) . "/Notification.php");
  167. $this->message('Example runtime message notification');
  168. $this->message('Example debug message notification', Notification::flagDebug);
  169. $this->warning('Example runtime warning notification');
  170. $this->warning('Example debug warning notification', Notification::flagDebug);
  171. $this->error('Example runtime error notification');
  172. $this->error('Example debug error notification', Notification::flagDebug);
  173. return $form;
  174. }
  175. }