/** * @param Type\FolderIdType $folderId * @param array $options * @return Type\ContactItemType[] */ public function getContacts($folderId = null, $options = array()) { if (!$folderId) { $folderId = $this->getFolderId(); } $request = array('Traversal' => 'Shallow', 'ItemShape' => array('BaseShape' => 'AllProperties'), 'ParentFolderIds' => array('FolderId' => $folderId->toXmlObject())); $request = array_replace_recursive($request, $options); $request = Type::buildFromArray($request); return $this->getClient()->FindItem($request); }
public function createTestMail($message = null) { $client = $this->getClient(); if (!$message) { //Create a new message $message = new Type\MessageType(); $message->setSubject('Test Message'); $message->setBody('Test Draft Body'); } //Set the message as not a draft $extended = new Type\ExtendedPropertyType(); $fieldUri = new Type\ExtendedFieldURI(); $fieldUri->setPropertyTag("0x0E07"); $fieldUri->setPropertyType(Enumeration\MapiPropertyTypeType::INTEGER); $extended->setExtendedFieldURI($fieldUri); $extended->setValue(1); $message->addExtendedProperty($extended); //Save the message to our Test Folder $itemId = $client->sendMail($message, array('MessageDisposition' => 'SaveOnly')); $client->getClient()->MoveItem(Type::buildFromArray(array('ToFolderId' => array('FolderId' => $this->getTestFolder()->getFolderId()->toArray()), 'ItemIds' => array('ItemId' => $itemId->toArray())))); return $itemId; }
/** * Get a list of sync changes on a folder * * @param Type\FolderIdType $folderId * @param null $syncState * @param array $options * @return SyncFolderItemsResponseMessageType */ public function listItemChanges($folderId, $syncState = null, $options = array()) { $request = array('ItemShape' => array('BaseShape' => 'AllProperties'), 'SyncFolderId' => array('FolderId' => $folderId->toXmlObject()), 'SyncScope' => 'NormalItems', 'MaxChangesReturned' => '100'); if ($syncState != null) { $request['SyncState'] = $syncState; $request['ItemShape']['BaseShape'] = 'AllProperties'; } $request = array_replace_recursive($request, $options); $request = Type::buildFromArray($request); $response = $this->getClient()->SyncFolderItems($request); return $response; }
<?php require_once "vendor/autoload.php"; use garethp\ews\API\Type; $api = MailApi::withUsernameAndPassword('server', 'username', 'password'); //Create the message item $message = new Type\MessageType(); $message->setSubject('Test Message'); $message->setBody('Test Draft Body'); //Set the message as not a draft using extended property types $extended = new Type\ExtendedPropertyType(); $fieldUri = new Type\ExtendedFieldURI(); $fieldUri->setPropertyTag("0x0E07"); $fieldUri->setPropertyType(\garethp\ews\API\Enumeration\MapiPropertyTypeType::INTEGER); $extended->setExtendedFieldURI($fieldUri); $extended->setValue(1); $message->addExtendedProperty($extended); //Pass it to the Send Mail function, but to SaveOnly without actually sending the email $itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly')); //Move the mail message from the sent folder to whatever folder we want to send it to $api->getClient()->MoveItem(Type::buildFromArray(array('ToFolderId' => array('FolderId' => $folderId->toArray()), 'ItemIds' => array('ItemId' => $itemId->toArray()))));
public function testClone() { $start = new DateTime('8:00 AM'); $end = new DateTime('9:00 AM'); $request = array('Items' => array('CalendarItem' => array('Start' => $start->format('c'), 'End' => $end->format('c'), 'Body' => array('BodyType' => Enumeration\BodyTypeType::HTML, '_value' => 'This is <b>the</b> body'), 'ItemClass' => Enumeration\ItemClassType::APPOINTMENT, 'Sensitivity' => Enumeration\SensitivityChoicesType::NORMAL, 'Categories' => array('Testing', 'php-ews'), 'Importance' => Enumeration\ImportanceChoicesType::NORMAL)), 'SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE); $request = Type::buildFromArray($request); $this->assertEquals($request, clone $request); }
/** * Get a list of calendar items between two dates/times * * @param string|DateTime $start * @param string|DateTime $end * @param array $options * @return CalendarItemType[]|Type\FindItemParentType */ public function getCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) { if (!$start instanceof DateTime) { $start = new DateTime($start); } if (!$end instanceof DateTime) { $end = new DateTime($end); } $request = array('Traversal' => 'Shallow', 'ItemShape' => array('BaseShape' => 'AllProperties'), 'CalendarView' => array('MaxEntriesReturned' => 100, 'StartDate' => $start->format('c'), 'EndDate' => $end->format('c')), 'ParentFolderIds' => array('FolderId' => $this->getFolderId()->toXmlObject())); $request = array_replace_recursive($request, $options); $request = Type::buildFromArray($request); $response = $this->getClient()->FindItem($request); $items = $response; return $items; }
<?php /** * Building Requests * * This file is an example on how to build requests manually and execute them directly instead of relying on the * simple use section of the library. Essentially, you can create your requests in arrays, pass them through * Type::buildFromArray($array) and then post them straight to the API Client. */ //Include the API use garethp\ews\API; use garethp\ews\API\Enumeration; use garethp\ews\API\Type; //Create and build the client $api = API::withUsernameAndPassword('server', 'username', 'password'); //Build the request as an array $request = array('FolderShape' => array('BaseShape' => array('_' => 'Default')), 'FolderIds' => array('DistinguishedFolderId' => array('Id' => 'calendar'))); //Turn the array in to an object to pass to the API $request = Type::buildFromArray($request); //Send the request and get the response $response = $api->getClient()->GetFolder($request);