Skip to content

Commit 523f26d

Browse files
committed
Merge pull request #56 from dnna/master
Add writeToFolder functionality
2 parents 2377a86 + 8150e6d commit 523f26d

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/Thybag/SharePointAPI.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,19 @@ public function write ($list_name, array $data) {
478478
return $this->writeMultiple($list_name, array($data));
479479
}
480480

481+
/**
482+
* WriteToFolder
483+
* Create new item in a sharepoint list
484+
*
485+
* @param String $list_name Name of List
486+
* @param String $folderPath Path of folder
487+
* @param Array $data Associative array describing data to store
488+
* @return Array
489+
*/
490+
public function writeToFolder ($list_name, $folderPath, array $data) {
491+
return $this->writeMultipleToFolder($list_name, $folderPath, array($data));
492+
}
493+
481494
// Alias (Identical to above)
482495
public function add ($list_name, array $data) { return $this->write($list_name, $data); }
483496
public function insert ($list_name, array $data) { return $this->write($list_name, $data); }
@@ -494,6 +507,19 @@ public function writeMultiple ($list_name, array $items) {
494507
return $this->modifyList($list_name, $items, 'New');
495508
}
496509

510+
/**
511+
* WriteMultipleToFolder
512+
* Batch create new items in a sharepoint list and place them in specified folder
513+
*
514+
* @param String $list_name Name of List
515+
* @param String $folderPath Path of folder
516+
* @param Array of arrays Associative array's describing data to store
517+
* @return Array
518+
*/
519+
public function writeMultipleToFolder ($list_name, $folderPath, array $items) {
520+
return $this->modifyList($list_name, $items, 'New', $folderPath);
521+
}
522+
497523
// Alias (Identical to above)
498524
public function addMultiple ($list_name, array $items) { return $this->writeMultiple($list_name, $items); }
499525
public function insertMultiple ($list_name, array $items) { return $this->writeMultiple($list_name, $items); }
@@ -869,16 +895,22 @@ public function viewFieldsXML(array $fields){
869895
* @param $method New/Update/Delete
870896
* @return Array|Object
871897
*/
872-
public function modifyList ($list_name, array $items, $method) {
898+
public function modifyList ($list_name, array $items, $method, $folderPath = null) {
873899
// Get batch XML
874900
$commands = $this->prepBatch($items, $method);
875901

902+
$rootFolderAttr = '';
903+
if($folderPath != null && $folderPath != '/') {
904+
$sitePath = substr($this->spWsdl, 0, strpos($this->spWsdl, '_vti_bin'));
905+
$rootFolderAttr = ' RootFolder="'.$sitePath.$list_name.'/'.$folderPath.'"';
906+
}
907+
876908
// Wrap in CAML
877909
$CAML = '
878910
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
879911
<listName>' . $list_name . '</listName>
880912
<updates>
881-
<Batch ListVersion="1" OnError="Continue">
913+
<Batch ListVersion="1" OnError="Continue"'.$rootFolderAttr.'>
882914
' . $commands . '
883915
</Batch>
884916
</updates>

0 commit comments

Comments
 (0)