NotificationTarget::getInstanceByType PHP Method

getInstanceByType() static public method

Get a notificationtarget class by giving an itemtype
static public getInstanceByType ( $itemtype, $event = '', $options = [] ) : a
$itemtype the itemtype of the object which raises the event
$event the event which will be used (default '')
$options array of options
return a notificationtarget class or false
    static function getInstanceByType($itemtype, $event = '', $options = array())
    {
        if ($itemtype && ($item = getItemForItemtype($itemtype))) {
            return self::getInstance($item, $event, $options);
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * Display debug information for an object
  *
  * @param $item            the object
  * @param $options   array
  **/
 static function debugEvent($item, $options = array())
 {
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . _n('Notification', 'Notifications', Session::getPluralNumber()) . "</th><th colspan='2'><font color='blue'> (" . $item->getTypeName(1) . ")</font></th></tr>";
     $events = array();
     if ($target = NotificationTarget::getInstanceByType(get_class($item))) {
         $events = $target->getAllEvents();
         if (count($events) > 0) {
             echo "<tr><th>" . self::getTypeName(Session::getPluralNumber()) . '</th><th>' . _n('Recipient', 'Recipients', Session::getPluralNumber()) . "</th>";
             echo "<th>" . _n('Notification template', 'Notification templates', Session::getPluralNumber()) . "</th>" . "<th>" . _n('Email', 'Emails', Session::getPluralNumber()) . "</th></tr>";
             foreach ($events as $event => $label) {
                 self::raiseEvent($event, $item, $options, $label);
             }
         } else {
             echo "<tr class='tab_bg_2 center'><td colspan='4'>" . __('No item to display') . "</td></tr>";
         }
     }
     echo "</table></div>";
 }
All Usage Examples Of NotificationTarget::getInstanceByType