Skip to content

Commit

Permalink
Fixing how fieldUri's are fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
Garethp committed Dec 4, 2015
1 parent 9a3ace4 commit 8909a08
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## 0.6.6 - 2015-11-*
## 0.6.6 - 2015-12-04
* getAttachment not returns the mimeContent of the attachment, which will allow for saving the file
* Added `ItemAttachmentType::getItemAttachment()` which will return whichever item is not null
* Field URI's for updating items are now case insensitive and will either return preference:name or item:name or throw
and exception

## 0.6.5 - 2015-11-25
* Fixed a bug in `CalendarAPI::createCalendarItems()` that caused options not to be overridden
Expand Down
31 changes: 17 additions & 14 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ public function setupFieldUris()

//Loop through all URI's to list them in an array
foreach ($constants as $constant) {
$constantName = explode(":", $constant);
$name = array_pop($constantName);
$exploded = explode(":", $constant);
if (count($exploded) == 1) {
$exploded = ['item', $exploded[0]];
}

$name = strtolower($exploded[1]);
$category = strtolower($exploded[0]);

if (!isset($constantsFound[$name])) {
$constantsFound[$name] = array();
}
$constantsFound[$name][] = $constant;
$constantsFound[$name][$category] = $constant;
}

$this->fieldUris = $constantsFound;
}

public function getFieldUriByName($fieldName, $preferance = null)
public function getFieldUriByName($fieldName, $preference = 'item')
{
$fieldName = strtolower($fieldName);
$preference = strtolower($preference);

if (empty($this->fieldUris)) {
$this->setupFieldUris();
}
Expand All @@ -74,20 +82,15 @@ public function getFieldUriByName($fieldName, $preferance = null)
return false;
}

$constants = $this->fieldUris[$fieldName];

if (count($constants) == 1) {
return $constants[0];
if (!isset($this->fieldUris[$fieldName][$preference])) {
$preference = 'item';
}

foreach ($constants as $constant) {
$parts = explode(":", $constant);
if ($parts[0] == $preferance) {
return $constant;
}
if (!isset($this->fieldUris[$fieldName][$preference])) {
throw new \Exception("Could not find uri $preference:$fieldName");
}

return $this->fieldUris[$fieldName][0];
return $this->fieldUris[$fieldName][$preference];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/src/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function testGetFieldURIByName()
{
$mock = $this->getClient();

$this->assertEquals('item:Subject', $mock->getFieldURIByName('Subject'));
$this->assertEquals('calendar:Start', $mock->getFieldURIByName('Start'));
$this->assertEquals('calendar:Recurrence', $mock->getFieldURIByName('Recurrence'));
$this->assertEquals('item:Subject', $mock->getFieldURIByName('Subject', 'item'));
$this->assertEquals('calendar:Start', $mock->getFieldURIByName('Start', 'calendar'));
$this->assertEquals('calendar:Recurrence', $mock->getFieldURIByName('Recurrence', 'calendar'));
$this->assertEquals('task:Recurrence', $mock->getFieldURIByName('Recurrence', 'task'));
$this->assertEquals('calendar:Recurrence', $mock->getFieldURIByName('Recurrence', 'somePreference'));
$this->assertEquals('calendar:Recurrence', $mock->getFieldURIByName('Recurrence', 'calendar'));
$this->assertFalse($mock->getFieldURIByName('thisShouldntExist'));
}

Expand Down

0 comments on commit 8909a08

Please sign in to comment.