本文整理匯總了PHP中Sabre\VObject\Property::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Property::create方法的具體用法?PHP Property::create怎麽用?PHP Property::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sabre\VObject\Property
的用法示例。
在下文中一共展示了Property::create方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGroupProperty
public function testGroupProperty()
{
$arr = array('Home', 'work', 'Friends, Family');
$property = \Sabre\VObject\Property::create('CATEGORIES');
$property->setParts($arr);
// Test parsing and serializing
$this->assertEquals('Home,work,Friends\\, Family', $property->value);
$this->assertEquals('CATEGORIES:Home,work,Friends\\, Family' . "\r\n", $property->serialize());
$this->assertEquals(3, count($property->getParts()));
// Test add
$property->addGroup('Coworkers');
$this->assertTrue($property->hasGroup('coworkers'));
$this->assertEquals(4, count($property->getParts()));
$this->assertEquals('Home,work,Friends\\, Family,Coworkers', $property->value);
// Test remove
$this->assertTrue($property->hasGroup('Friends, fAmIlY'));
$property->removeGroup('Friends, fAmIlY');
$this->assertEquals(3, count($property->getParts()));
$parts = $property->getParts();
$this->assertEquals('Coworkers', $parts[2]);
// Test rename
$property->renameGroup('work', 'Work');
$parts = $property->getParts();
$this->assertEquals('Work', $parts[1]);
//$this->assertEquals(true, false);
}
示例2: calendarAction
/**
* Create online calendar for user
*
* @Route("/{username}.ics")
*
* @param string $username User to create the calendar for
* @return Symfony\Component\HttpFoundation\Response
*/
public function calendarAction($username)
{
$user = $this->get('user_provider')->loadUserByUsername($username);
$om = $this->getObjectManager('VIB\\FliesBundle\\Entity\\Vial');
$calendar = VObject\Component::create('VCALENDAR');
$calendar->VERSION = '2.0';
$field = 'X-WR-CALNAME';
$calendar->{$field} = $user->getShortName() . '\'s flywork';
$stockDates = $om->getRepository('VIB\\FliesBundle\\Entity\\StockVial')->getFlipDates($user);
foreach ($stockDates as $stockDate) {
$event = VObject\Component::create('VEVENT');
$calendar->add($event);
$event->SUMMARY = 'Transfer stocks';
$dtstart = VObject\Property::create('DTSTART');
$dtstart->setDateTime($stockDate, VObject\Property\DateTime::DATE);
$event->DTSTART = $dtstart;
$alarm = VObject\Component::create('VALARM');
$event->add($alarm);
$alarm->TRIGGER = 'PT8H';
$alarm->ACTION = 'DISPLAY';
}
$crossDates = $om->getRepository('VIB\\FliesBundle\\Entity\\CrossVial')->getFlipDates($user);
foreach ($crossDates as $crossDate) {
$crossDates[] = $crossDate;
$event = VObject\Component::create('VEVENT');
$calendar->add($event);
$event->SUMMARY = 'Check crosses';
$dtstart = VObject\Property::create('DTSTART');
$dtstart->setDateTime($crossDate, VObject\Property\DateTime::DATE);
$event->DTSTART = $dtstart;
$alarm = VObject\Component::create('VALARM');
$event->add($alarm);
$alarm->TRIGGER = 'PT8H';
$alarm->ACTION = 'DISPLAY';
}
return new Response($calendar->serialize(), 200, array('Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'inline; filename="calendar.ics"'));
}
示例3: setPropertyByName
/**
* Set a property by the property name.
* It is up to the caller to call ->save()
*
* @param string $name Property name
* @param mixed $value
* @param array $parameters
* @return bool
*/
public function setPropertyByName($name, $value, $parameters = array())
{
// TODO: parameters are ignored for now.
switch ($name) {
case 'BDAY':
try {
$date = new \DateTime($value);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' DateTime exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$value = $date->format('Y-m-d');
$this->BDAY = $value;
$this->BDAY->add('VALUE', 'DATE');
//\OCP\Util::writeLog('contacts', __METHOD__.' BDAY: '.$this->BDAY->serialize(), \OCP\Util::DEBUG);
break;
case 'CATEGORIES':
case 'N':
case 'ORG':
$property = $this->select($name);
if (count($property) === 0) {
$property = \Sabre\VObject\Property::create($name);
$this->add($property);
} else {
// Actually no idea why this works
$property = array_shift($property);
}
if (is_array($value)) {
$property->setParts($value);
} else {
$this->{$name} = $value;
}
break;
default:
\OCP\Util::writeLog('contacts', __METHOD__ . ' adding: ' . $name . ' ' . $value, \OCP\Util::DEBUG);
$this->{$name} = $value;
break;
}
$this->setSaved(false);
return true;
}
示例4: getOrCreateVCardProperty
/**
* @brief returns the vcard property corresponding to the parameter
* creates the property if it doesn't exists yet
* @param $vcard the vcard to get or create the properties with
* @param $importEntry the parameter to find
* @return the property|false
*/
protected function getOrCreateVCardProperty(&$vcard, $importEntry)
{
if (isset($vcard) && isset($importEntry)) {
// looking for a property with the same name
$properties = $vcard->select($importEntry['property']);
foreach ($properties as $property) {
if ($importEntry['type'] == null && !isset($importEntry->additional_property)) {
return $property;
}
foreach ($property->parameters as $parameter) {
// Filtering types
if ($parameter->name == 'TYPE' && !strcmp($parameter->value, $importEntry['type'])) {
$found = 0;
if (isset($importEntry->additional_property)) {
// Filtering additional properties if necessary (I know, there are a lot of inner loops, sorry)
foreach ($importEntry->additional_property as $additional_property) {
if ((string) $parameter->name == $additional_property['name']) {
$found++;
}
}
if ($found == count($importEntry->additional_property)) {
return $property;
}
}
return $property;
}
}
if (isset($importEntry['group']) && $property->group == $importEntry['group']) {
return $property;
}
}
// Property not found, creating one
$property = \Sabre\VObject\Property::create($importEntry['property']);
$vcard->add($property);
if ($importEntry['type'] != null) {
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', '' . StringUtil::convertToUTF8($importEntry['type']));
switch ($importEntry['property']) {
case "ADR":
$property->setValue(";;;;;;");
break;
case "FN":
$property->setValue(";;;;");
break;
}
}
if ($importEntry['group'] != null) {
$property->group = $importEntry['group'];
}
return $property;
} else {
return false;
}
}
示例5: convertElementToProperty
/**
* @brief converts an LDIF element into a VCard property
* and updates the VCard
* @param $value the LDIF value
* @param $importEntry the VCard entry to modify
* @param $dest the VCard to modify (for adding a X-FAVOURITE property)
*/
private function convertElementToProperty($value, $importEntry, &$dest) {
if (isset($importEntry->vcard_favourites)) {
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
if (strcasecmp((string)$vcardFavourite, trim($value)) == 0) {
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
$dest->add($property);
} else {
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
if (isset($importEntry['image']) && $importEntry['image'] == "true") {
$this->updateImageProperty($property, $value);
} else {
$this->updateProperty($property, $importEntry, $value);
}
}
}
} else {
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
if (isset($importEntry['image']) && $importEntry['image'] == "true") {
$this->updateImageProperty($property, $value);
} else {
$this->updateProperty($property, $importEntry, $value);
}
}
}
示例6: substr
$vcard->add($property);
$checksum = substr(md5($property->serialize()), 0, 8);
try {
VCard::edit($id, $vcard);
} catch (Exception $e) {
bailOut($e->getMessage());
}
\OCP\JSON::success(array('data' => array('checksum' => $checksum, 'oldchecksum' => $_POST['checksum'])));
exit;
}
} else {
$element = $name;
$property = $vcard->select($name);
debug('propertylist: ' . get_class($property));
if (count($property) === 0) {
$property = VObject\Property::create($name);
$vcard->add($property);
} else {
$property = array_shift($property);
}
}
/* preprocessing value */
switch ($element) {
case 'BDAY':
$date = new \DateTime($value);
$value = $date->format('Y-m-d');
break;
case 'FN':
if (!$value) {
// create a method thats returns an alternative for FN.
//$value = getOtherValue();
示例7: createOrUpdate
/**
* @param $properties
* @return mixed
*/
public function createOrUpdate($properties)
{
$id = null;
/**
* @var \OCA\Contacts\VObject\VCard
*/
$vcard = null;
if (array_key_exists('id', $properties)) {
// TODO: test if $id belongs to this addressbook
$id = $properties['id'];
// TODO: Test $vcard
$vcard = $this->addressBook->getChild($properties['id']);
foreach (array_keys($properties) as $name) {
if (isset($vcard->{$name})) {
unset($vcard->{$name});
}
}
} else {
$vcard = \Sabre\VObject\Component::create('VCARD');
$uid = substr(md5(rand() . time()), 0, 10);
$vcard->add('UID', $uid);
try {
$id = $this->addressBook->addChild($vcard);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
foreach ($properties as $name => $value) {
switch ($name) {
case 'ADR':
case 'N':
if (is_array($value)) {
$property = \Sabre\VObject\Property::create($name);
$property->setParts($value);
$vcard->add($property);
} else {
$vcard->{$name} = $value;
}
break;
case 'BDAY':
// TODO: try/catch
$date = new \DateTime($value);
$vcard->BDAY = $date->format('Y-m-d');
$vcard->BDAY->VALUE = 'DATE';
break;
case 'EMAIL':
case 'TEL':
case 'IMPP':
// NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
// NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
case 'URL':
if (is_array($value)) {
foreach ($value as $val) {
$vcard->add($name, strip_tags($val));
}
} else {
$vcard->add($name, strip_tags($value));
}
default:
$vcard->{$name} = $value;
break;
}
}
try {
VCard::edit($id, $vcard);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$asarray = VCard::structureContact($vcard);
$asarray['id'] = $id;
return $asarray;
}
示例8: convertElementToVCard
/**
* @brief converts a VCard into a owncloud VCard
* @param $element the VCard element to convert
* @return VCard|false
*/
public function convertElementToVCard($element) {
try {
$source = VObject\Reader::read($element, VObject\Reader::OPTION_FORGIVING);
} catch (VObject\ParseException $error) {
return false;
}
$dest = \Sabre\VObject\Component::create('VCARD');
foreach ($source->children() as $sourceProperty) {
$importEntry = $this->getImportEntry($sourceProperty, $source);
if ($importEntry) {
$value = $sourceProperty->value;
if (isset($importEntry['remove'])) {
$value = str_replace($importEntry['remove'], '', $sourceProperty->value);
}
$values = array($value);
if (isset($importEntry['separator'])) {
$values = explode($importEntry['separator'], $value);
}
foreach ($values as $oneValue) {
if (isset($importEntry->vcard_favourites)) {
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
$dest->add($property);
} else {
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
$this->updateProperty($property, $importEntry, trim($oneValue));
}
}
} else {
$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
$this->updateProperty($property, $importEntry, $sourceProperty->value);
}
}
} else {
$property = clone $sourceProperty;
$dest->add($property);
}
}
$dest->validate(\Sabre\VObject\Component\VCard::REPAIR);
return $dest;
}
示例9: _to_ical
/**
* Build a valid iCal format block from the given event
*
* @param array Hash array with event/task properties from libkolab
* @param object VCalendar object to append event to or false for directly sending data to stdout
* @param callable Callback function to fetch attachment contents, false if no attachment export
* @param object RECURRENCE-ID property when serializing a recurrence exception
*/
private function _to_ical($event, $vcal, $get_attachment, $recurrence_id = null)
{
$type = $event['_type'] ?: 'event';
$ve = VObject\Component::create($this->type_component_map[$type]);
$ve->add('UID', $event['uid']);
// set DTSTAMP according to RFC 5545, 3.8.7.2.
$dtstamp = !empty($event['changed']) && !empty($this->method) ? $event['changed'] : new DateTime();
$ve->add($this->datetime_prop('DTSTAMP', $dtstamp, true));
// all-day events end the next day
if ($event['allday'] && !empty($event['end'])) {
$event['end'] = clone $event['end'];
$event['end']->add(new \DateInterval('P1D'));
$event['end']->_dateonly = true;
}
if (!empty($event['created'])) {
$ve->add($this->datetime_prop('CREATED', $event['created'], true));
}
if (!empty($event['changed'])) {
$ve->add($this->datetime_prop('LAST-MODIFIED', $event['changed'], true));
}
if (!empty($event['start'])) {
$ve->add($this->datetime_prop('DTSTART', $event['start'], false, (bool) $event['allday']));
}
if (!empty($event['end'])) {
$ve->add($this->datetime_prop('DTEND', $event['end'], false, (bool) $event['allday']));
}
if (!empty($event['due'])) {
$ve->add($this->datetime_prop('DUE', $event['due'], false));
}
// we're exporting a recurrence instance only
if (!$recurrence_id && $event['recurrence_date'] && $event['recurrence_date'] instanceof DateTime) {
$recurrence_id = $this->datetime_prop('RECURRENCE-ID', $event['recurrence_date'], false, (bool) $event['allday']);
if ($event['thisandfuture']) {
$recurrence_id->add('RANGE', 'THISANDFUTURE');
}
}
if ($recurrence_id) {
$ve->add($recurrence_id);
}
$ve->add('SUMMARY', $event['title']);
if ($event['location']) {
$ve->add($this->is_apple() ? new vobject_location_property('LOCATION', $event['location']) : new VObject\Property('LOCATION', $event['location']));
}
if ($event['description']) {
$ve->add('DESCRIPTION', strtr($event['description'], array("\r\n" => "\n", "\r" => "\n")));
}
// normalize line endings
if (isset($event['sequence'])) {
$ve->add('SEQUENCE', $event['sequence']);
}
if ($event['recurrence'] && !$recurrence_id) {
$exdates = $rdates = null;
if (isset($event['recurrence']['EXDATE'])) {
$exdates = $event['recurrence']['EXDATE'];
unset($event['recurrence']['EXDATE']);
// don't serialize EXDATEs into RRULE value
}
if (isset($event['recurrence']['RDATE'])) {
$rdates = $event['recurrence']['RDATE'];
unset($event['recurrence']['RDATE']);
// don't serialize RDATEs into RRULE value
}
if ($event['recurrence']['FREQ']) {
$ve->add('RRULE', libcalendaring::to_rrule($event['recurrence'], (bool) $event['allday']));
}
// add EXDATEs each one per line (for Thunderbird Lightning)
if (is_array($exdates)) {
foreach ($exdates as $ex) {
if ($ex instanceof \DateTime) {
$exd = clone $event['start'];
$exd->setDate($ex->format('Y'), $ex->format('n'), $ex->format('j'));
$exd->setTimeZone(new \DateTimeZone('UTC'));
$ve->add(new VObject\Property('EXDATE', $exd->format('Ymd\\THis\\Z')));
}
}
}
// add RDATEs
if (is_array($rdates) && !empty($rdates)) {
$sample = $this->datetime_prop('RDATE', $rdates[0]);
$rdprop = new VObject\Property\MultiDateTime('RDATE', null);
$rdprop->setDateTimes($rdates, $sample->getDateType());
$ve->add($rdprop);
}
}
if ($event['categories']) {
$cat = VObject\Property::create('CATEGORIES');
$cat->setParts((array) $event['categories']);
$ve->add($cat);
}
if (!empty($event['free_busy'])) {
$ve->add('TRANSP', $event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE');
// for Outlook clients we provide the X-MICROSOFT-CDO-BUSYSTATUS property
//.........這裏部分代碼省略.........
示例10: convertElementToVCard
/**
* @brief converts a unique element into a owncloud VCard
* @param $element the element to convert
* @return VCard, all unconverted elements are stored in X-Unknown-Element parameters
*/
public function convertElementToVCard($element, $title = null)
{
$vcard = \Sabre\VObject\Component::create('VCARD');
$nbElt = count($element);
for ($i = 0; $i < $nbElt; $i++) {
if ($element[$i] != '') {
//$importEntry = false;
// Look for the right import_entry
if (isset($this->configContent->import_core->base_parsing)) {
if (strcasecmp((string) $this->configContent->import_core->base_parsing, 'position') == 0) {
$importEntry = $this->getImportEntryFromPosition((string) $i);
} else {
if (strcasecmp((string) $this->configContent->import_core->base_parsing, 'name') == 0 && isset($title[$i])) {
$importEntry = $this->getImportEntryFromName($title[$i]);
}
}
}
if ($importEntry) {
// Create a new property and attach it to the vcard
$value = $element[$i];
if (isset($importEntry['remove'])) {
$value = str_replace($importEntry['remove'], '', $element[$i]);
}
$values = array($value);
if (isset($importEntry['separator'])) {
$values = explode($importEntry['separator'], $value);
}
foreach ($values as $oneValue) {
if (isset($importEntry->vcard_favourites)) {
foreach ($importEntry->vcard_favourites as $vcardFavourite) {
if (strcasecmp((string) $vcardFavourite, trim($oneValue)) == 0) {
$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
$vcard->add($property);
} else {
$property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
$this->updateProperty($property, $importEntry, trim($oneValue));
}
}
} else {
$property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
$this->updateProperty($property, $importEntry, trim($oneValue));
}
}
} else {
if (isset($element[$i]) && isset($title[$i])) {
$property = \Sabre\VObject\Property::create("X-Unknown-Element", StringUtil::convertToUTF8($element[$i]));
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', '' . StringUtil::convertToUTF8($title[$i]));
$vcard->add($property);
}
}
}
}
$vcard->validate(\Sabre\VObject\Component\VCard::REPAIR);
return $vcard;
}
示例11: getOrCreateVCardProperty
/**
* @brief returns the vcard property corresponding to the ldif parameter
* creates the property if it doesn't exists yet
* @param $vcard the vcard to get or create the properties with
* @param $v_param the parameter the find
* @param $index the position of the property in the vcard to find
*/
public function getOrCreateVCardProperty(&$vcard, $v_param, $index)
{
// looking for one
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' entering '.$vcard->serialize(), \OCP\Util::DEBUG);
$properties = $vcard->select($v_param['property']);
$counter = 0;
foreach ($properties as $property) {
if ($v_param['type'] == null) {
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' property '.$v_param['type'].' found', \OCP\Util::DEBUG);
return $property;
}
foreach ($property->parameters as $parameter) {
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->value.' <> '.$v_param['type'], \OCP\Util::DEBUG);
if (!strcmp($parameter->value, $v_param['type'])) {
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' parameter '.$parameter->value.' found', \OCP\Util::DEBUG);
if ($counter == $index) {
return $property;
}
$counter++;
}
}
}
// Property not found, creating one
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', create one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
$line = count($vcard->children) - 1;
$property = \Sabre\VObject\Property::create($v_param['property']);
$vcard->add($property);
if ($v_param['type'] != null) {
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', creating one '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
//\OC_Log::write('ldapconnector', __METHOD__.', creating one '.$v_param['property'].';TYPE='.$v_param['type'], \OC_Log::DEBUG);
$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', '' . $v_param['type']);
switch ($v_param['property']) {
case "ADR":
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', we have an address '.$v_param['property'].';TYPE='.$v_param['type'], \OCP\Util::DEBUG);
$property->setValue(";;;;;;");
break;
case "FN":
$property->setValue(";;;;");
break;
}
}
//OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' exiting '.$vcard->serialize(), \OCP\Util::DEBUG);
return $property;
}