本文整理汇总了PHP中Horde_Icalendar::getComponentCount方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Icalendar::getComponentCount方法的具体用法?PHP Horde_Icalendar::getComponentCount怎么用?PHP Horde_Icalendar::getComponentCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Icalendar
的用法示例。
在下文中一共展示了Horde_Icalendar::getComponentCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exit
*/
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: replace
/**
* 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));
}