php-ews how to search calender event by Calender Subject - php

I am using https://github.com/jamesiarmes/php-ews for connecting php to exchange server so far no problem using the code below . i can connect to specific user mail box and can retrieve all his calender events . right now its pulling all the events what i want is to pull only those calendar events which has lets say 'Student Appt.' in Subject line.Is it possible . ?
require_once('bug/dBug.php');
require_once('EWSType.php');
require_once('ExchangeWebServices.php');
require_once('NTLMSoapClient.php');
require_once('NTLMSoapClient/Exchange.php');
require_once('EWS_Exception.php');
require_once('EWSType/FindItemType.php');
require_once('EWSType/ItemQueryTraversalType.php');
require_once('EWSType/ItemResponseShapeType.php');
require_once('EWSType/DefaultShapeNamesType.php');
require_once('EWSType/CalendarViewType.php');
require_once('EWSType/NonEmptyArrayOfBaseFolderIdsType.php');
require_once('EWSType/DistinguishedFolderIdType.php');
require_once('EWSType/DistinguishedFolderIdNameType.php');
require_once('EWSType/EmailAddressType.php');
require_once('EWSType/UserIdType.php');
require_once('EWSType/CalendarEventDetails.php');
$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$version = 'Exchange2010';
$start = " 2013-04-17T15:18:34+03:00";
$end = " 2013-04-30T15:18:34+03:00";
$ews = new ExchangeWebServices($host, $username, $password, $version);
//new dBug ($ews);
// Set init class
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate = $start ;// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $end ; // an ISO8601 date later than the above
// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
// if you want to get to someones folder
while($info = mysql_fetch_array( $call_pri_result )){
$EmailAddy = 'abc#exchangeserver.com';
$mailBox = new EWSType_EmailAddressType();
$mailBox->EmailAddress = $EmailAddy;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = $mailBox;
echo 'Now Looping for Consular ID '.$EmailAddy.'<br>' ;
// Send request
$response = $ews->FindItem($request);
// Loop through each item if event(s) were found in the timeframe specified
if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
$events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
foreach ($events as $event){
$id = $event->ItemId->Id;
$change_key = $event->ItemId->ChangeKey;
$start = $event->Start;
$end = $event->End;
$subject = $event->Subject;
//$location = $event->Location;
}
}
else {
// No items returned
}
}

From my digging you cannot add restrictions or sort order to a CalendarView. I added the code found here to my code to get calendar items and I got the following MessageText:
Restrictions and sort order may not be specified for a CalendarView.
It looks like the full list of FieldURI variables is listed at this MSDN page.
What I would do in your case is put a regular expression, strpos() or similar in your foreach() loop of events. Then if that case matches perform your function. Yes you will have extra events that you will do nothing with but you will at least be able to filter out your desired events.

Related

how to use multiple filter in google analytics reporting api v4?

https://developers.google.com/analytics/devguides/reporting/core/v4/samples for find data from google analytic.
I want to find data using multiple dimension filter but not able to do it.
i am using the code.
function buildSimpleSegment($segmentName, $dimension, $dimensionFilterExpression) {
// Create the segment dimension.
$segmentDimensions = new Google_Service_AnalyticsReporting_Dimension();
$segmentDimensions->setName("ga:segment");
// Create Dimension Filter.
$dimensionFilter = new Google_Service_AnalyticsReporting_SegmentDimensionFilter();
$dimensionFilter->setDimensionName($dimension);
$dimensionFilter->setOperator("EXACT");
$dimensionFilter->setExpressions(array($dimensionFilterExpression));
//print_r($dimensionFilter);die;
// Create Segment Filter Clause.
$segmentFilterClause = new Google_Service_AnalyticsReporting_SegmentFilterClause();
$segmentFilterClause->setDimensionFilter($dimensionFilter);
// Create the Or Filters for Segment.
$orFiltersForSegment = new Google_Service_AnalyticsReporting_OrFiltersForSegment();
$orFiltersForSegment->setSegmentFilterClauses(array($segmentFilterClause));
// Create the Simple Segment.
$simpleSegment = new Google_Service_AnalyticsReporting_SimpleSegment();
$simpleSegment->setOrFiltersForSegment(array($orFiltersForSegment));
// Create the Segment Filters.
$segmentFilter = new Google_Service_AnalyticsReporting_SegmentFilter();
$segmentFilter->setSimpleSegment($simpleSegment);
// Create the Segment Definition.
$segmentDefinition = new Google_Service_AnalyticsReporting_SegmentDefinition();
$segmentDefinition->setSegmentFilters(array($segmentFilter));
// Create the Dynamic Segment.
$dynamicSegment = new Google_Service_AnalyticsReporting_DynamicSegment();
$dynamicSegment->setSessionSegment($segmentDefinition);
$dynamicSegment->setName($segmentName);
// Create the Segments object.
$segment = new Google_Service_AnalyticsReporting_Segment();
$segment->setDynamicSegment($dynamicSegment);
return $segment;
}
function getReport($analyticsreporting) {
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
if (isset($_GET['startdat']) && isset($_GET['enddate'])) {
$dateRange->setStartDate($_GET['startdat']);
$dateRange->setEndDate($_GET['enddate']);
} else {
$dateRange->setStartDate(date('Y-m-d', strtotime(date('Y-m-d') . ' - 1 month')));
$dateRange->setEndDate(date('Y-m-d'));
}
$domain = $_GET['domain'];
$VIEW_ID = "xyz";
// Create the Metrics object.
$totalevent = new Google_Service_AnalyticsReporting_Metric();
$totalevent->setExpression("ga:totalEvents");
$totalevent->setAlias("totalEvent");
$source = new Google_Service_AnalyticsReporting_Dimension();
$source->setName("ga:source");
$eventAction = new Google_Service_AnalyticsReporting_Dimension();
$eventAction->setName("ga:eventAction");
$eventLabel = new Google_Service_AnalyticsReporting_Dimension();
$eventLabel->setName("ga:eventLabel");
$eventCategory = new Google_Service_AnalyticsReporting_Dimension();
$eventCategory->setName("ga:eventCategory");
// Create the segment dimension.
$segmentDimensions = new Google_Service_AnalyticsReporting_Dimension();
$segmentDimensions->setName("ga:segment");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges(array($dateRange));
$request->setDimensions(array($source, $eventAction, $eventLabel, $eventCategory, $segmentDimensions));
$request->setMetrics(array($totalevent));
$sourceSegment = buildSimpleSegment("Source", "ga:source", $domain);
$videoSegment = buildSimpleSegment("Category", "ga:eventCategory", "JW Player Video Plays");
$request->setSegments(array($sourceSegment, $videoSegment));
// Call the batchGet method.
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests(array($request));
return $response = $analyticsreporting->reports->batchGet($body);
}
A bit late but still useful, I think, because I couldn't find any answer to it on SO.
To define multiple filters you need to instance the class Google_Service_AnalyticsReporting_DimensionFilter multiple times. For example:
$filter1 = new Google_Service_AnalyticsReporting_DimensionFilter();
$filter1->setDimensionName('first_dimension_name');
$filter1->setOperator('first_operator');
$filter1->setExpressions('first_expression');
$filter2 = new Google_Service_AnalyticsReporting_DimensionFilter();
$filter2->setDimensionName('second_dimension_name');
$filter2->setOperator('second_operator');
$filter2->setExpressions('second_expression');
Then define the filter clause which tie the filters defined above:
$filter_clause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
$filter_clause->setOperator('your_filter_operator');
$filter_clause->setFilters(array($filter1, $filter2));
Then do the request as usual.
The answer #Maurizio provided is great but I needed a solution for a variable number of campaigns. Client may track one or five. Here's where I landed in case it helps anyone dealing with Google's (fairly terrible API documentation).
// Create DimensionFilters for each campaign.
// note: $campaigns is an array supplied above this code and used below
$dimension_filters = array(); // set up an empty array
for($i = 0; $i < count($campaigns); $i++){
${"dimensionFilter$i"} = new Google_Service_AnalyticsReporting_DimensionFilter();
${"dimensionFilter$i"}->setDimensionName('ga:campaign');
${"dimensionFilter$i"}->setOperator('EXACT');
${"dimensionFilter$i"}->setExpressions(array($campaigns[$i]));
$dimension_filters[] = ${"dimensionFilter$i"}; // push our new DimensionFilter instance onto the array
}
// Create the DimensionFilterClauses
$dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
$dimensionFilterClause->setFilters(array($dimension_filters)); // now supply our final array of DimensionFilter instances

PHPEWS create event on public calendar

I'm attempting to plug a php based calendar management system into exchange 2007 calendars.
I have the below code setup at present.
$subject = 'Appointment with ..';
$request = new EWSType_CreateItemType();
$request->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$request->Items->CalendarItem = new EWSType_CalendarItemType();
$request->Items->CalendarItem->Subject = $subject;
$date1 = new DateTime('2015-05-10T15:00:00+03:00');
$DateStart = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateStart);
$request->Items->CalendarItem->Start = $date->format('c');
$date1 = new DateTime('2015-05-10T17:00:00+03:00');
$DateEnd = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateEnd);
$request->Items->CalendarItem->End = $date->format('c');
$request->Items->CalendarItem->ReminderIsSet = false;
$request->Items->CalendarItem->ReminderMinutesBeforeStart = 15;
$request->Items->CalendarItem->Body = new EWSType_BodyType();
$request->Items->CalendarItem->Body->BodyType = EWSType_BodyTypeType::HTML;
$request->Items->CalendarItem->Body->_ = <<<EOD
<p><strong>Staff Attending</strong>:bob</p>
EOD;
$request->Items->CalendarItem->ItemClass = new EWSType_ItemClassType();
$request->Items->CalendarItem->ItemClass->_ = EWSType_ItemClassType::APPOINTMENT;
$request->Items->CalendarItem->Sensitivity = new EWSType_SensitivityChoicesType();
$request->Items->CalendarItem->Sensitivity->_ = EWSType_SensitivityChoicesType::NORMAL;
$request->Items->CalendarItem->Categories = new EWSType_ArrayOfStringsType();
$request->Items->CalendarItem->Categories->String = array(
'Client Meeting (Scheduled)'
);
$request->Items->CalendarItem->Location = "Showroom";
$request->SendMeetingInvitations = EWSType_CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->EmailAddress = "user#domain.com";
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->RoutingType = 'SMTP';
$n = 1;
$response = $ews->CreateItem($request);
This will setup an event in the users personal calendar just fine, but what I need to do is to get it to post to a public folder calendar which I have the folderID for.
If anyone could assist it would be greatly appreciated!
Try adding the line:
$request->SavedItemFolderId->FolderId->Id=$folder_id;
after the
$request = new EWSType_CreateItemType();
where $folder_id is your stupidly long microsoft folder id!!!!
I'm doing the same right now.
You have to replace the SEND_ONLY_TO_ALL with SEND_TO_NONE.
This means that we cannot send meeting invitations for appointments stored in a public folder (I've been trying to find a workaround for this problem for a couple weeks now).
I'm not sure if there are other problems in your request but this is surely an issue.

Not collected Exception: Wrong Version PHP-EWS

Im trying to connect with the PHP-EWS and my Exchange server.
I use the Script from https://github.com/jamesiarmes/php-ews/wiki
But everytime i load my script the browser tells me
Not collected Exception: Wrong Version
Here is my script (The Autoloader is in a extra File so dont worry it works)
$server = "***********";
$username="***********";
$password="*******";
$version= "2010"; // or Exchange 2010; Exchange 2010 SP1
$ews = new ExchangeWebServices($server, $username, $password, $version);
$request = new EWSType_FindFolderType();
$request->Traversal = EWSType_FolderQueryTraversalType::SHALLOW;
$request->FolderShape = new EWSType_FolderResponseShapeType();
$request->FolderShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
// configure the view
$request->IndexedPageFolderView = new EWSType_IndexedPageViewType();
$request->IndexedPageFolderView->BasePoint = 'Beginning';
$request->IndexedPageFolderView->Offset = 0;
// set the starting folder as the inbox
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
// make the actual call
$response = $ews->FindFolder($request);
?>
Does anybody know why i keep getting
Not collected Exception: Wrong Version
and knew what to do?
Your version is wrong, you should use one of the pre-defined constants in ExchangeWebServices.
E.g: $version = ExchangeWebServices::VERSION_2010
You should have a look at "ExchangeWebServices.php" in order to see which other versions are defined.

Netsuite PHP API: how to update custom field on item record

I have looked at some answers on here and tried putting them into action in my script; but it's not working, and I'm not sure why.
I am trying to update a custom field on an already-existing inventory item. Here is what I have so far
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$item = new InventoryItem();
$item->internalId = 72309;
$customFieldList = new CustomFieldList();
$customField = new StringCustomFieldRef();
$customField->value = utf8_encode("12345");
$customField->internalId = 'custitem_testinput';
$customFieldList->customField[] = $customField;
$item->customFieldList = $customFieldList;
$request = new UpdateRequest();
$request->record = $item;
$response = $service->update($request);
?>
I'm trying to pull the item record up by its internalID, and then update just 1 of its many custom fields.
This code doesn't error out, but it doesn't seem to do anything either. Looking at the var_dump of the objects, I can see an item object with just the parameters I've set populated, and everything else null.
What am I doing wrong?
This is a basic example showing how to update custom field in an existing record using PHP toolkit.
<?php
require_once 'PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$ItemId = '72309';
$ItemRecord= new InventoryItem();
//StringCustomFieldRef
$itemField= new StringCustomFieldRef();
$itemField->scriptId = 'custitem_part_lookup';
$itemField->value = 'test';
$customFieldList = new customFieldList();
$customFieldList->customField = array($itemField);
$ItemRecord->internalId = $ItemId ;
$ItemRecord->customFieldList = $customFieldList;
$updateRequest = new UpdateRequest();
$updateRequest->record = $ItemRecord;
$updateResponse = $service->update($updateRequest);
?>
For additional information you can visit Net Suite User Group

Google Calendar API batch request PHP

i am trying to send a bunch of events via an Batch Request to Google Calendar.
But i cant figur out how to do. https://developers.google.com/google-apps/calendar/batch doesnt help me.
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
$client = new Google_Client();
$client->setUseBatch(true);
$batch = new Google_BatchRequest();
$uri = 'http://www.google.com/calendar/feeds/default/private/full/batch';
$batchContent = file_get_contents('xxxxx/google-api-php-client/batch.xml');
$batch->add($batchContent);
batch.xml contains 2 -items.
Thats all so far. But nothing happened.
I also have tried
$batch->execute()
But thats throws error without message.
My question: How to send a Batch via PHP to Google Calendar ?
I'm using the latest version of Google APIs Client Library for PHP (Google Calendar v.3). I use batch operations for pushing instructor lessons to Google Calendar. Here is my example of code for you (multipleInsert function). Good luck!
<?php
require_once(APPPATH . 'libraries/Google/Client.php');
require_once(APPPATH . 'libraries/Google/Http/Batch.php');
require_once(APPPATH . 'libraries/Google/Service/Calendar.php');
class My_google_calendar
{
...
/** Add single Event for Student */
function addEvent($lesson, $instructor, $return_request = false, $enable_attendees = false)
{
$calendar = $this->getGoogleCalendar(); // get calendar service variable
$lesson_from = date(DATE_RFC3339, $lesson->from);
$lesson_to = date(DATE_RFC3339, $lesson->from + $lesson->duration);
$event = new Google_Service_Calendar_Event();
$event->setSummary('Lesson with student: '$lesson->student_full_name);
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($lesson_from);
$start->setTimeZone($this->getGoogleCalendarTimeZone());
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($lesson_to);
$end->setTimeZone($this->getGoogleCalendarTimeZone());
$event->setEnd($end);
$event->setColorId(4);
$description = "...";
$event->setDescription($description);
if (isset($student->email) && $enable_attendees) {
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setResponseStatus('needsAction');
$attendee1->setEmail($student->email);
$attendees = array($attendee1);
$event->setAttendees($attendees);
}
$createdEvent = $this->calendar->events->insert($this->calendar_id, $event, array('fields' => 'id'));
return $return_request ? $createdEvent : $createdEvent->getId();
}
/** Push group of events to the Calendar */
function multipleInsert ($lessons, $instructor)
{
$this->use_batch = true;
$this->client->setUseBatch($this->use_batch);
$batch = new Google_Http_Batch($this->client);
$optParams = array('fields' => 'status,updates');
foreach($lessons as $time => $lesson) {
$lesson = array_shift($group['lessons']);
$req = $this->addEvent($lesson, $instructor, true);
$batch->add($req, $time);
}
}
$results = $batch->execute();
return $results;
}
}
in the newer versions, you should use
$batch = $service->createBatch();
instead of
$batch = new Google_Http_Batch($this->client);
reference

Categories