Ejemplo n.º 1
0
 /**
  * Get SubFolders of a SharePoint Folder
  *
  * @param   SPSite $site        SharePoint Site
  * @param   string $relativeUrl SharePoint Folder relative URL
  * @param   array  $settings    Instantiation settings
  * @throws  SPRuntimeException
  * @return  array
  */
 public static function getSubFolders(SPSite $site, $relativeUrl, array $settings = [])
 {
     $json = $site->request("_api/web/GetFolderByServerRelativeUrl('" . $relativeUrl . "')/Folders", ['headers' => ['Authorization' => 'Bearer ' . $site->getSPAccessToken(), 'Accept' => 'application/json'], 'query' => ['$expand' => 'ListItemAllFields/ParentList,Properties']]);
     $folders = [];
     foreach ($json['value'] as $subFolder) {
         // Skip System Folders
         if (!static::isSystemFolder($subFolder['Name'])) {
             $folders[$subFolder['UniqueId']] = new static($site, $subFolder, $settings);
         }
     }
     return $folders;
 }
 /**
  * Create a SharePoint Recycle Bin Item Collection
  *
  * @param   SPSite $site  SharePoint Site
  * @param   array  $extra Extra properties to map
  * @throws  \Impensavel\Spoil\Exception\SPRuntimeException
  * @return  SPRecycleBinItemCollection
  */
 public static function create(SPSite $site, array $extra = [])
 {
     $json = $site->request("_api/web/RecycleBin", ['headers' => ['Authorization' => 'Bearer ' . $site->getSPAccessToken(), 'Accept' => 'application/json']]);
     $collection = new static();
     foreach ($json['value'] as $item) {
         $collection[$item['Id']] = new SPRecycleBinItem($site, $item, $extra);
     }
     return $collection;
 }
Ejemplo n.º 3
0
 /**
  * Create a SharePoint List
  *
  * @param   SPSite $site       SharePoint Site
  * @param   array  $properties SharePoint List properties (Title, Description, ...)
  * @param   array  $settings   Instantiation settings
  * @throws  SPRuntimeException
  * @return  SPList
  */
 public static function create(SPSite $site, array $properties, array $settings = [])
 {
     $properties = array_replace_recursive(['BaseTemplate' => static::TPL_DOCUMENTLIBRARY], $properties, ['odata.type' => 'SP.List']);
     $body = json_encode($properties);
     $json = $site->request('_api/web/Lists', ['headers' => ['Authorization' => 'Bearer ' . $site->getSPAccessToken(), 'Accept' => 'application/json', 'X-RequestDigest' => $site->getSPContextInfo()->getFormDigest(), 'Content-type' => 'application/json', 'Content-length' => strlen($body)], 'query' => ['$expand' => 'RootFolder'], 'body' => $body], 'POST');
     return new static($site, $json, $settings);
 }
Ejemplo n.º 4
0
 /**
  * Create a SharePoint Access Token (App-only Policy)
  *
  * @param   SPSite $site  SharePoint Site
  * @param   array  $extra Extra payload values to map
  * @throws  SPBadMethodCallException|SPInvalidArgumentException
  * @return  SPAccessToken
  */
 public static function createAppOnlyPolicy(SPSite $site, array $extra = [])
 {
     $config = $site->getConfig();
     if (empty($config['secret'])) {
         throw new SPBadMethodCallException('The Secret is empty/not set');
     }
     if (empty($config['acs'])) {
         throw new SPBadMethodCallException('The Azure Access Control Service URL is empty/not set');
     }
     if (!filter_var($config['acs'], FILTER_VALIDATE_URL)) {
         throw new SPInvalidArgumentException('The Azure Access Control Service URL is invalid');
     }
     if (empty($config['client_id'])) {
         throw new SPBadMethodCallException('The Client ID is empty/not set');
     }
     if (empty($config['resource'])) {
         throw new SPBadMethodCallException('The Resource is empty/not set');
     }
     $json = $site->request($config['acs'], ['headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], 'body' => http_build_query(['grant_type' => 'client_credentials', 'client_id' => $config['client_id'], 'client_secret' => $config['secret'], 'resource' => $config['resource']])], 'POST');
     return new static($json, $extra);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getSPContextInfo()
 {
     return $this->site->getSPContextInfo();
 }
Ejemplo n.º 6
0
 /**
  * Get a SharePoint File by Relative URL
  *
  * @param   SPSite $site        SharePoint Site
  * @param   string $relativeUrl SharePoint Folder relative URL
  * @param   array  $extra       Extra payload values to map
  * @throws  SPRuntimeException
  * @return  SPFile
  */
 public static function getByRelativeUrl(SPSite $site, $relativeUrl, array $extra = [])
 {
     $json = $site->request("_api/web/GetFileByServerRelativeUrl('" . $relativeUrl . "')", ['headers' => ['Authorization' => 'Bearer ' . $site->getSPAccessToken(), 'Accept' => 'application/json'], 'query' => ['$expand' => 'ListItemAllFields,Author']]);
     $folder = SPFolder::getByRelativeUrl($site, dirname($relativeUrl));
     return new static($folder, $json, $extra);
 }
Ejemplo n.º 7
0
 /**
  * Get a SharePoint User by Account
  *
  * @param   SPSite $site    SharePoint Site object
  * @param   string $account SharePoint User account
  * @param   array  $extra   Extra payload values to map
  * @throws  SPRuntimeException
  * @return  SPUser
  */
 public static function getByAccount(SPSite $site, $account, array $extra = [])
 {
     $json = $site->request('_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)', ['headers' => ['Authorization' => 'Bearer ' . $site->getSPAccessToken(), 'Accept' => 'application/json'], 'query' => ['@v' => "'" . $account . "'"]], 'POST');
     return new static($site, $json, $extra);
 }