File tree Expand file tree Collapse file tree
examples/SharePoint/ListItems Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ();
Original file line number Diff line number Diff line change 1010
1111class 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
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments