Avail feature updated
[ninja.git] / application / helpers / notify.php
blob5b0d091e5ade08c97a06dccbc05d1210300b589b
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Ninja notification facility PHP interface
5 */
6 class notify {
8 private static $settings = array(
9 /* Can be info, warning, critical. Will grant the
10 notification-body the classes: jq-notify-type-<type> */
11 "type" => "info",
13 /* true/false, A sticky notification does not fade out and
14 must be removed manually */
15 "sticky" => false,
17 /* true/false, Should the notification have a remove button
18 in the upper right corner */
19 "removable" => true,
21 /* Milliseconds before a non-sticky notification fades out,
22 set to string "auto" and it will fade out depending on the
23 length of the message. */
24 "fadetime" => "auto",
26 /* Should the notification be configurable, i.e. should
27 it be possible to remove this type of notification for
28 the "duration of the session"/"this user" */
29 "configurable" => false,
31 /* Buttons can be added to the notification, set the buttons
32 property of the options to an object where each key will
33 be used as title and the value used as the callback */
34 "buttons" => false,
36 /**/
37 "signature" => false
40 private static $notifications = array();
42 /**
43 * Creates a new notification in the User-interface with the
44 * provided message and options.
46 public function __construct ( $message, $options = false ) {
48 $this->message = $message;
49 $this->options = self::$settings;
51 if ( $options != false && gettype( $options ) == "array" ) {
52 foreach ( $this->options as $key => $val ) {
53 if ( isset( $options[ $key ] ) ) {
54 $this->options[ $key ] = $options[ $key ];
59 self::$notifications[] = $this;
63 /**
64 * Renders all notifications provided with PHP to the jquery
65 * notification facility
67 public static function render () {
69 echo '<script>$(window).load( function () {';
70 foreach ( self::$notifications as $notification ) {
71 echo '$.notify( \'' . $notification->message . '\', ' . json_encode( $notification->options ) . ' );';
73 echo '});</script>';