Horde_Icalendar::newComponent PHP Метод

newComponent() публичный статический Метод

Return a reference to a new component.
public static newComponent ( string $type, Horde_Icalendar $container ) : object
$type string The type of component to return
$container Horde_Icalendar A container that this component will be associated with.
Результат object Reference to a Horde_Icalendar_* object as specified.
    public static function newComponent($type, $container)
    {
        $type = Horde_String::lower($type);
        $class = __CLASS__ . '_' . Horde_String::ucfirst($type);
        if (class_exists($class)) {
            $component = new $class();
            if ($container !== false) {
                $component->_container = $container;
                // Use version of container, not default set by component
                // constructor.
                $component->setVersion($container->getAttribute('VERSION'));
            }
        } else {
            // Should return an dummy x-unknown type class here.
            $component = false;
        }
        return $component;
    }

Usage Example

Пример #1
0
 /**
  */
 protected function _create($mbox, $subject, $body)
 {
     global $notification, $registry;
     $list = str_replace(self::TASKLIST_EDIT, '', $mbox);
     /* Create a new iCalendar. */
     $vCal = new Horde_Icalendar();
     $vCal->setAttribute('PRODID', '-//The Horde Project//IMP ' . $registry->getVersion() . '//EN');
     $vCal->setAttribute('METHOD', 'PUBLISH');
     /* Create a new vTodo object using this message's contents. */
     $vTodo = Horde_Icalendar::newComponent('vtodo', $vCal);
     $vTodo->setAttribute('SUMMARY', $subject);
     $vTodo->setAttribute('DESCRIPTION', $body);
     $vTodo->setAttribute('PRIORITY', '3');
     /* Get the list of editable tasklists. */
     $lists = $this->getTasklists(true);
     /* Attempt to add the new vTodo item to the requested tasklist. */
     try {
         $res = $registry->call('tasks/import', array($vTodo, 'text/calendar', $list));
     } catch (Horde_Exception $e) {
         $notification->push($e);
         return;
     }
     if (!$res) {
         $notification->push(_("An unknown error occured while creating the new task."), 'horde.error');
     } elseif (!empty($lists)) {
         $name = '"' . htmlspecialchars($subject) . '"';
         /* Attempt to convert the object name into a hyperlink. */
         if ($registry->hasLink('tasks/show')) {
             $name = sprintf('<a href="%s">%s</a>', Horde::url($registry->link('tasks/show', array('uid' => $res))), $name);
         }
         $notification->push(sprintf(_("%s was successfully added to \"%s\"."), $name, htmlspecialchars($lists[$list]->get('name'))), 'horde.success', array('content.raw'));
     }
 }
All Usage Examples Of Horde_Icalendar::newComponent