77 * Simple PHP API for reading/writing and modifying SharePoint list items.
88 *
99 * @author Carl Saggs
10- * @version 0.6.2
10+ * @version 0.6.4
1111 * @licence MIT License
1212 * @source: http://github.com/thybag/PHP-SharePoint-Lists-API
1313 *
@@ -136,9 +136,10 @@ class SharePointAPI {
136136 * @param string $spUsername User account to authenticate with. (Must have read/write/edit permissions to given Lists)
137137 * @param string $spPassword Password to use with authenticating account.
138138 * @param string $spWsdl WSDL file for this set of lists ( sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL )
139- * @param Whether to authenticate with NTLM
139+ * @param string $mode Authenticaton method to use (Defaults to basic auth, also supports SPONLINE & NTLM)
140+ * @param array $options Options for SoapClient
140141 */
141- public function __construct ($ spUsername , $ spPassword , $ spWsdl , $ mode = 'STANDARD ' ) {
142+ public function __construct ($ spUsername , $ spPassword , $ spWsdl , $ mode = 'STANDARD ' , $ options = array () ) {
142143 // Check if required class is found
143144 assert (class_exists ('SoapClient ' ));
144145
@@ -148,10 +149,9 @@ public function __construct ($spUsername, $spPassword, $spWsdl, $mode = 'STANDAR
148149 $ this ->spWsdl = $ spWsdl ;
149150
150151 /*
151- * General options
152- * NOTE: You can set all these parameters, see class ExampleSharePointAPI for an example)
152+ * defaults
153153 */
154- $ options = array (
154+ $ defaultOptions = array (
155155 'trace ' => $ this ->soap_trace ,
156156 'exceptions ' => $ this ->soap_exceptions ,
157157 'keep_alive ' => $ this ->soap_keep_alive ,
@@ -160,6 +160,8 @@ public function __construct ($spUsername, $spPassword, $spWsdl, $mode = 'STANDAR
160160 'compression ' => $ this ->soap_compression ,
161161 'encoding ' => $ this ->internal_encoding ,
162162 );
163+ // $options will overwrite defaults if provided
164+ $ options = array_merge ($ defaultOptions , $ options );
163165
164166 // Is login set?
165167 if (!empty ($ this ->spUsername )) {
@@ -639,6 +641,36 @@ public function addAttachment ($list_name, $list_item_id, $file_name) {
639641 return true ;
640642 }
641643
644+ /**
645+ * deleteAttachment
646+ * Remove an attachment from a SharePoint list item
647+ *
648+ * @param $list_name Name of list
649+ * @param $list_item_id ID of record item is attached to
650+ * @param $url
651+ */
652+ public function deleteAttachment ($ list_name , $ list_item_id , $ url ) {
653+ // Wrap in CAML
654+ $ CAML = '
655+ <DeleteAttachment xmlns="http://schemas.microsoft.com/sharepoint/soap/">
656+ <listName> ' . $ list_name . '</listName>
657+ <listItemID> ' . $ list_item_id . '</listItemID>
658+ <url> ' . $ url . '</url>
659+ </DeleteAttachment> ' ;
660+
661+ $ xmlvar = new \SoapVar ($ CAML , XSD_ANYXML );
662+
663+ // Attempt to run operation
664+ try {
665+ $ this ->soapClient ->DeleteAttachment ($ xmlvar );
666+ } catch (\SoapFault $ fault ) {
667+ $ this ->onError ($ fault );
668+ }
669+
670+ // Return true on success
671+ return true ;
672+ }
673+
642674 /**
643675 * getAttachment
644676 * Return an attachment from a SharePoint list item
@@ -835,12 +867,12 @@ public function getSortFromValue ($value) {
835867 $ value = strtolower ($ value );
836868
837869 // Default is descending
838- $ sort = 'false ' ;
870+ $ sort = 'FALSE ' ;
839871
840872 // Is value set to allow ascending sorting?
841873 if ($ value == 'asc ' || $ value == 'true ' || $ value == 'ascending ' ) {
842874 // Sort ascending
843- $ sort = 'true ' ;
875+ $ sort = 'TRUE ' ;
844876 }
845877
846878 // Return it
@@ -1085,61 +1117,16 @@ public function getFieldVersions ($list, $id, $field) {
10851117 }
10861118 public function getColumnVersions ($ list , $ id , $ field ) { return $ this ->getFieldVersions ($ list , $ id , $ field ); }
10871119
1088- /**
1089- * getItemVersions
1090- * Get previous versions of an item
1091- *
1092- * @param $list Name or GUID of list
1093- * @param $id ID of item to find versions for
1094- * @return array | object
1095- */
1096- public function getItemVersions ($ list , $ id , $ exclude_hidden = true ) {
1097- $ fields = $ this ->readListMeta ($ list , $ exclude_hidden );
1098-
1099- // Parse results
1100- $ results = array ();
1101- // Format data in to array or object
1102- foreach ($ fields as $ counter => $ field ) {
1103- // Modified always returns an error
1104- if ($ field ['name ' ] == 'Modified ' ) { continue ; }
1105-
1106- // Get all the fields
1107- $ field_versions = $ this ->getFieldVersions ($ list , $ id , $ field ['name ' ]);
1108-
1109- // Get the versions for each field
1110- if (sizeof ($ field_versions ) !== 0 ) {
1111- foreach ($ field_versions as $ key => $ value ) {
1112- if ($ this ->lower_case_indexs ) {
1113- $ results [$ key ][strtolower ($ field ['name ' ])] = $ value [strtolower ($ field ['name ' ])];
1114- } else {
1115- $ results [$ key ][$ field ['name ' ]] = $ value [$ field ['name ' ]];
1116- }
1117- }
1118- //Make object if needed
1119- if ($ this ->returnType === 1 ) settype ($ results [$ counter ], "object " );
1120- }
1121- }
1122-
1123- // Add error array if stuff goes wrong.
1124- if (!isset ($ results )) $ results = array ('warning ' => 'No data returned. ' );
1125-
1126- return $ results ;
1127- }
1128-
11291120 /**
11301121 * getVersions
1131- * Get previous versions of an item or field
1122+ * Get previous versions of a field
11321123 *
11331124 * @param $list Name or GUID of list
11341125 * @param $id ID of item to find versions for
11351126 * @param $field optional name of column to get versions for
11361127 * @return array | object
11371128 */
1138- public function getVersions ($ list , $ id , $ field = null , $ exclude_hidden = true ) {
1139- if ($ field === null ) {
1140- return $ this ->getItemVersions ($ list , $ id , $ exclude_hidden );
1141- } else {
1142- return $ this ->getFieldVersions ($ list , $ id , $ field );
1143- }
1129+ public function getVersions ($ list , $ id , $ field = null ) {
1130+ return $ this ->getFieldVersions ($ list , $ id , $ field );
11441131 }
11451132}
0 commit comments