Source of file NotificationDataExtension.php
Size: 2,101 Bytes - Last Modified: 2022-02-21T10:01:58+00:00
/var/www/docs.ssmods.com/process/src/code/data_extensions/NotificationDataExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?php /** * Provides notification/flash messages to SiteTree classes. * * Add this extension to a SiteConfig instance * by adding this to your _config.php: * * Object::add_extension('Page', 'NotificationDataExtension'); * * @package cleanutilities * @subpackage data_extensions * * @author arillo */ class NotificationDataExtension extends DataExtension { /** * Session variable name * @var string */ public static $session_store = 'CleanUtilities.Notifications'; /** * Adds a message $str to notifications with a certain $mode. * This static version of this function makes this usable from everywhere. * * @param string $str * @param string $mode */ public static function set_session_message($str = '', $mode = 'success') { $sm = Session::get(self::$session_store); $ret = array(); $ret['Msg'] = $str; $ret['Mode'] = $mode; if (isset($sm)) { $sm[] = $ret; } else { $sm = array(); $sm[] = $ret; } Session::set(self::$session_store, $sm); } /** * Adds a message $str to notifications with a certain $mode. * * @param string $str * @param string $mode */ public function setSessionMessage($str = '', $mode = 'success') { self::set_session_message($str, $mode); } /** * Indicates if current notifications do exist. * * @return bool */ public function HaveMessages() { $msgs = Session::get(self::$session_store); return isset($msgs); } /** * Returns all current notifications. * * @return ArrayList */ public function SessionMessages() { $msgs = Session::get(self::$session_store); Session::clear(self::$session_store); if (is_array($msgs)) { return new ArrayList( array_map(function ($item) { return new ArrayData($item); }, $msgs) ); } } } |