Skip to content

Commit 10d5746

Browse files
committed
SharePoint API: support for FieldLookupValue
1 parent cdecb53 commit 10d5746

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
require_once './../../vendor/autoload.php';
4+
$settings = include('./../../../tests/Settings.php');
5+
6+
7+
use Office365\Runtime\Auth\ClientCredential;
8+
use Office365\SharePoint\ClientContext;
9+
use Office365\SharePoint\FieldLookupValue;
10+
use Office365\SharePoint\ListItem;
11+
12+
$credentials = new ClientCredential($settings['ClientId'], $settings['ClientSecret']);
13+
$siteUrl = $settings['TeamSiteUrl'];
14+
$ctx = (new ClientContext($siteUrl))->withCredentials($credentials);
15+
16+
$list = $ctx->getWeb()->getLists()->getByTitle("Tasks");
17+
$items = $list->getItems()->get()->top(1)->executeQuery();
18+
if($items->getCount() !== 1){
19+
printf("Parent task not found");
20+
return;
21+
}
22+
$taskId = $items[0]->getProperty("Id");
23+
$taskProps = array(
24+
'Title' => "New task N#" . rand(1, 100000),
25+
'ParentTask' => new FieldLookupValue($taskId)
26+
);
27+
$item = $list->addItem($taskProps)->executeQuery();

src/SharePoint/FieldLookupValue.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
class FieldLookupValue extends ClientValue
1212
{
13+
public function __construct($LookupId)
14+
{
15+
$this->LookupId = $LookupId;
16+
parent::__construct();
17+
}
18+
1319
/**
1420
* Gets or sets the identifier (ID) of the list item that this instance of the lookup field is referring to.
1521
* @var int

src/SharePoint/ListItem.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,17 @@ public function getServerTypeName()
427427
return $this->typeName;
428428
}
429429

430+
431+
public function setProperty($name, $value, $persistChanges = true)
432+
{
433+
if($value instanceof FieldLookupValue){
434+
parent::setProperty("{$name}Id", $value->LookupId, true);
435+
parent::setProperty($name, $value, false);
436+
return $this;
437+
}
438+
return parent::setProperty($name, $value, $persistChanges);
439+
}
440+
430441
/**
431442
* @var string
432443
*/

0 commit comments

Comments
 (0)