getComponentCount() public method

Number of components in this container.
public getComponentCount ( ) : integer
return integer Number of components in this container.
コード例 #1
0
ファイル: parser.php プロジェクト: jubinpatel/horde
 */
require_once 'Horde/Cli.php';
require_once 'Horde/Icalendar.php';
// This only works on the command line.
if (!Horde_Cli::runningFromCLI()) {
    exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
$cli = Horde_Cli::init();
if (empty($argv[1])) {
    $cli->fatal('No file specified on the command line.');
}
$input_file = $argv[1];
if (!file_exists($input_file)) {
    $cli->fatal($input_file . ' does not exist.');
}
if (!is_readable($input_file)) {
    $cli->fatal($input_file . ' is not readable.');
}
$cli->writeln($cli->blue('Parsing ' . $input_file . ' ...'));
$data = file_get_contents($input_file);
$ical = new Horde_Icalendar();
if (!$ical->parseVCalendar($data)) {
    $cli->fatal('iCalendar parsing failed.');
}
$cli->writeln($cli->green('Parsing successful, found ' . $ical->getComponentCount() . ' component(s).'));
$components = $ical->getComponents();
foreach ($components as $component) {
    var_dump($component->toHash(true));
}
コード例 #2
0
ファイル: Api.php プロジェクト: Gomez/horde
 /**
  * Replaces the contact identified by UID with the content represented in
  * the specified contentType.
  *
  * @param string $uid            Idenfity the contact to replace.
  * @param mixed  $content        The content of the contact.
  * @param string $contentType    What format is the data in? Currently
  *                               supports array, text/directory,
  *                               text/vcard, text/x-vcard and activesync.
  * @param string|array $sources  The source(s) where the contact will be
  *                               replaced.
  *
  * @return boolean  Success or failure.
  * @throws Turba_Exception
  */
 public function replace($uid, $content, $contentType, $sources = null)
 {
     if (empty($uid)) {
         throw new Turba_Exception(_("Invalid contact unique ID"));
     }
     $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver');
     foreach ($this->_getSources($sources) as $source) {
         $sdriver = $driver->create($source);
         // Check permissions.
         if (!$sdriver->hasPermission(Horde_Perms::EDIT)) {
             continue;
         }
         $result = $sdriver->search(array('__uid' => $uid));
         if (!count($result)) {
             continue;
         } elseif (count($result) > 1) {
             throw new Turba_Exception(sprintf(_("Multiple contacts found with same unique ID %s."), $uid));
         }
         $object = $result->objects[0];
         switch ($contentType) {
             case 'activesync':
                 $content = $sdriver->fromASContact($content);
                 foreach ($content as $attribute => $value) {
                     if ($attribute != '__key') {
                         $object->setValue($attribute, $value);
                     }
                 }
                 return $object->store();
             case 'array':
                 break;
             case 'text/x-vcard':
             case 'text/vcard':
             case 'text/directory':
                 $iCal = new Horde_Icalendar();
                 if (!$iCal->parsevCalendar($content)) {
                     throw new Turba_Exception(_("There was an error importing the iCalendar data."));
                 }
                 switch ($iCal->getComponentCount()) {
                     case 0:
                         throw new Turba_Exception(_("No vCard data was found."));
                     case 1:
                         $content = $sdriver->toHash($iCal->getComponent(0));
                         break;
                     default:
                         throw new Turba_Exception(_("Only one vcard supported."));
                 }
                 break;
             default:
                 throw new Turba_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
         }
         foreach ($content as $attribute => $value) {
             if ($attribute != '__key') {
                 $object->setValue($attribute, $value);
             }
         }
         return $object->store();
     }
     throw new Turba_Exception(sprintf(_("Object %s not found."), $uid));
 }