Turba::createShare PHP Method

createShare() public static method

Create a new Turba share.
public static createShare ( string $share_name, array $params ) : Horde_Share
$share_name string The id for the new share.
$params array Parameters for the new share.
return Horde_Share The new share object.
    public static function createShare($share_name, $params)
    {
        if (isset($params['name'])) {
            $name = $params['name'];
            unset($params['name']);
        } else {
            /* Sensible default for empty display names */
            $name = sprintf(_("Address book of %s"), $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create()->getName());
        }
        /* Generate the new share. */
        try {
            $turba_shares = $GLOBALS['injector']->getInstance('Turba_Shares');
            $share = $turba_shares->newShare($GLOBALS['registry']->getAuth(), $share_name, $name);
            /* Now any other params. */
            foreach ($params as $key => $value) {
                if (!is_scalar($value)) {
                    $value = serialize($value);
                }
                $share->set($key, $value);
            }
            $turba_shares->addShare($share);
            $share->save();
        } catch (Horde_Share_Exception $e) {
            Horde::log($e, 'ERR');
            throw new Turba_Exception($e);
        }
        return $share;
    }

Usage Example

Example #1
0
     } catch (Horde_Exception $e) {
         $notification->push($e);
         Horde::url('search.php', true)->redirect();
     }
     /* We create the vbook and redirect before we try to search
      * since we are not displaying the search results on this page
      * anyway. */
     $vname = $vars->vbook_name;
     if (empty($vname)) {
         $notification->push(_("You must provide a name for virtual address books."), 'horde.error');
         Horde::url('search.php', true)->redirect();
     }
     /* Create the vbook. */
     $params = array('name' => $vname, 'params' => serialize(array('type' => 'vbook', 'source' => $source, 'criteria' => $criteria)));
     try {
         $share = Turba::createShare(strval(new Horde_Support_Randomid()), $params);
         $vid = $share->getName();
     } catch (Horde_Share_Exception $e) {
         $notification->push(sprintf(_("There was a problem creating the virtual address book: %s"), $e->getMessage()), 'horde.error');
         Horde::url('search.php', true)->redirect();
     }
     $notification->push(sprintf(_("Successfully created virtual address book \"%s\""), $vname), 'horde.success');
     Horde::url('browse.php', true)->add('source', $vid)->redirect();
 }
 /* Perform a search. */
 if ($search_mode == 'duplicate') {
     try {
         $duplicates = $driver->searchDuplicates();
         $view = new Turba_View_Duplicates($duplicates, $driver, $vars->type, $vars->dupe);
         $page_output->addScriptFile('tables.js', 'horde');
     } catch (Exception $e) {
All Usage Examples Of Turba::createShare