Documentation

GoogleDrive
in package

Google Drive Class to give support to GoogleDocuments Beginning Sept. 30, 2020, you will no longer be able to place a file in multiple parent https://developers.google.com/drive/api/guides/about-files

Table of Contents

Properties

$error  : mixed
$errorCode  : mixed
$errorMsg  : mixed
$lastQuery  : string
$maxRecursiveLevels  : int
$pageToken  : string
$drive  : Drive
$driveFile  : DriveFile
$drivePermission  : Permission
$googleClient  : Client
$version  : mixed
$core  : Core7

Methods

__construct()  : mixed
CloudFramework GoogleDocument class
assignDrivePermissions()  : bool
Assign to a $user_email priveleges over a $document_id with a specific rol https://stackoverflow.com/questions/37846076/create-a-spreadsheet-api-v4 https://developers.google.com/drive/api/v3/ref-roles $permissions_examples: permissions = [ { 'type': 'user', 'role': 'writer', 'emailAddress': 'user@example.com' }, { 'type': 'domain', 'role': 'writer', 'domain': 'example.com' }]
copyDriveFile()  : bool
Copy a file with the option to change the name
copyDriveFiles()  : bool
Copy all the files where parent is $folderId to $destId with a max of 10.000 docs
createDriveFolder()  : array<string|int, mixed>|void
Create a folder under a parent
createDriveFolderStructure()  : array<string|int, mixed>|void
Creat and Drive structure based on $structure
deleteDriveFile()  : bool
Delete a file in drive of any kind The error codes can be: 404 = not found, 403 = insufficient permissions
deleteDriveFiles()  : bool
Delete all the files where parent is $folderId to $destId with a max of 10.000 docs
deleteDriveFolder()  : bool
Delete a folder in drive
downloadDriveFile()  : array<string|int, mixed>|void
Create a folder under a parent
export()  : array<string|int, mixed>|void
Export a file https://developers.google.com/drive/api/guides/manage-downloads https://developers.google.com/drive/api/guides/ref-export-formats Documents Microsoft Word application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx OpenDocument application/vnd.oasis.opendocument.text .odt Rich Text application/rtf .rtf PDF application/pdf .pdf Plain Text text/plain .txt Web Page (HTML) application/zip .zip EPUB application/epub+zip .epub Spreadsheets Microsoft Excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx OpenDocument application/x-vnd.oasis.opendocument.spreadsheet .ods PDF application/pdf .pdf Web Page (HTML) application/zip .zip Comma Separated Values (first-sheet only) text/csv .csv Tab Separated Values (first-sheet only) text/tab-separated-values .tsv Presentations Microsoft PowerPoint application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx ODP application/vnd.oasis.opendocument.presentation .odp PDF application/pdf .pdf Plain Text text/plain .txt JPEG (first-slide only) image/jpeg .jpg PNG (first-slide only) image/png .png Scalable Vector Graphics (first-slide only) image/svg+xml .svg Drawings PDF application/pdf .pdf JPEG image/jpeg .jpg PNG image/png .png Scalable Vector Graphics image/svg+xml .svg Apps Script JSON application/vnd.google-apps.script+json .json
getDriveFile()  : array<string|int, mixed>|void
Create a folder under a parent
getDriveFiles()  : array<string|int, mixed>|void
Return all files under $parent_id except folders
getDriveFolders()  : array<string|int, mixed>|void
Return all folder files under $parent_id
getDriveFolderTree()  : bool
Get folder structure
getDrivePermissions()  : bool
List permissions of a $document_id
getSharedDriveInfo()  : array<string|int, mixed>|mixed|void
moveDriveFile()  : array<string|int, mixed>|void
Move a file in drive of any kind The error codes can be: 404 = not found, 403 = insufficient permissions
moveDriveFiles()  : bool
Move all the files where parent is $folderId to $destId
searchDriveFiles()  : array<string|int, mixed>|void
Search files in the user Drive Based on: https://developers.google.com/drive/api/guides/ref-search-terms#operators
updateDriveFile()  : array<string|int, mixed>|void
Update a file in drive of any kind
uploadDriveFile()  : array<string|int, mixed>|void
Upload $content to $file_name drive
uploadDriveFileAsDoc()  : mixed
Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.document
uploadDriveFileAsPresentation()  : mixed
Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.presentation
uploadDriveFileAsSpreadSheet()  : mixed
Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.spreadsheet
addError()  : mixed
Add an error into the classs
getArrayFromDriveFile()  : array<string|int, mixed>
Return an array structured taking a DriveFile
getDriveFolderRecursiveStructure()  : array<string|int, mixed>
Create under $parent drive folder the structure defined in $structure
getGoogleClient()  : mixed
Return a Google Client with the scopes necessary to manage Google Documents
getUrlFromMimeType()  : string
Return the URL to drive object based on $file->getMimeType();
recursiveFolderTree()  : bool|void
Recursive function to create a tree

Properties

$maxRecursiveLevels

public int $maxRecursiveLevels = 10

Max recursive levels for a tree

$drive

protected Drive $drive = \null

will manage the drive access properties

$driveFile

protected DriveFile $driveFile = \null

will manage files in general

$drivePermission

protected Permission $drivePermission = \null

will manage files in general

$googleClient

protected Client $googleClient = \null

will manage the drive access properties

Methods

__construct()

CloudFramework GoogleDocument class

public __construct(Core7 &$core[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$core : Core7
$config : array<string|int, mixed> = []

assignDrivePermissions()

Assign to a $user_email priveleges over a $document_id with a specific rol https://stackoverflow.com/questions/37846076/create-a-spreadsheet-api-v4 https://developers.google.com/drive/api/v3/ref-roles $permissions_examples: permissions = [ { 'type': 'user', 'role': 'writer', 'emailAddress': 'user@example.com' }, { 'type': 'domain', 'role': 'writer', 'domain': 'example.com' }]

public assignDrivePermissions( $document_id,  $user_email[, string $role = 'writer' ]) : bool
Parameters
$document_id :
$user_email :
$role : string = 'writer'

values can be: reader, writer, commenter, fileOrganizer(only shared drives), organizer(only shared drives), owner

Return values
bool

copyDriveFile()

Copy a file with the option to change the name

public copyDriveFile(string $fileId[, string $newName = null ][, string $newFolder = null ]) : bool
Parameters
$fileId : string
$newName : string = null
$newFolder : string = null
Return values
bool

copyDriveFiles()

Copy all the files where parent is $folderId to $destId with a max of 10.000 docs

public copyDriveFiles(string $folderId, string $destId) : bool
Parameters
$folderId : string
$destId : string

id of the folder dest

Return values
bool

createDriveFolder()

Create a folder under a parent

public createDriveFolder(string $folder_name[, string $parent_id = "" ]) : array<string|int, mixed>|void
Parameters
$folder_name : string
$parent_id : string = ""

value of the parent folder id

Return values
array<string|int, mixed>|void

createDriveFolderStructure()

Creat and Drive structure based on $structure

public createDriveFolderStructure(string $parent, array<string|int, mixed> $structure) : array<string|int, mixed>|void
Parameters
$parent : string
$structure : array<string|int, mixed>
Return values
array<string|int, mixed>|void

deleteDriveFile()

Delete a file in drive of any kind The error codes can be: 404 = not found, 403 = insufficient permissions

public deleteDriveFile(string $fileId) : bool
Parameters
$fileId : string
Return values
bool

deleteDriveFiles()

Delete all the files where parent is $folderId to $destId with a max of 10.000 docs

public deleteDriveFiles(string $folderId) : bool
Parameters
$folderId : string
Return values
bool

deleteDriveFolder()

Delete a folder in drive

public deleteDriveFolder(mixed $folderId) : bool
Parameters
$folderId : mixed
Return values
bool

downloadDriveFile()

Create a folder under a parent

public downloadDriveFile(string $id, string $file_path) : array<string|int, mixed>|void
Parameters
$id : string
$file_path : string
Return values
array<string|int, mixed>|void

export()

Export a file https://developers.google.com/drive/api/guides/manage-downloads https://developers.google.com/drive/api/guides/ref-export-formats Documents Microsoft Word application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx OpenDocument application/vnd.oasis.opendocument.text .odt Rich Text application/rtf .rtf PDF application/pdf .pdf Plain Text text/plain .txt Web Page (HTML) application/zip .zip EPUB application/epub+zip .epub Spreadsheets Microsoft Excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx OpenDocument application/x-vnd.oasis.opendocument.spreadsheet .ods PDF application/pdf .pdf Web Page (HTML) application/zip .zip Comma Separated Values (first-sheet only) text/csv .csv Tab Separated Values (first-sheet only) text/tab-separated-values .tsv Presentations Microsoft PowerPoint application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx ODP application/vnd.oasis.opendocument.presentation .odp PDF application/pdf .pdf Plain Text text/plain .txt JPEG (first-slide only) image/jpeg .jpg PNG (first-slide only) image/png .png Scalable Vector Graphics (first-slide only) image/svg+xml .svg Drawings PDF application/pdf .pdf JPEG image/jpeg .jpg PNG image/png .png Scalable Vector Graphics image/svg+xml .svg Apps Script JSON application/vnd.google-apps.script+json .json

public export(string $id, string $file_path[, string $mimeType = 'application/pdf' ]) : array<string|int, mixed>|void
Parameters
$id : string

of the document in drive

$file_path : string

where to store the exported file

$mimeType : string = 'application/pdf'

for the file to produce. By default 'application/pdf'

Return values
array<string|int, mixed>|void

getDriveFile()

Create a folder under a parent

public getDriveFile(string $id) : array<string|int, mixed>|void
Parameters
$id : string
Return values
array<string|int, mixed>|void

getDriveFiles()

Return all files under $parent_id except folders

public getDriveFiles([string $parent_id = 'root' ][, int $maxFiles = 1000 ]) : array<string|int, mixed>|void
Parameters
$parent_id : string = 'root'
$maxFiles : int = 1000
Tags
see
getDriveFolders
Return values
array<string|int, mixed>|void

getDriveFolders()

Return all folder files under $parent_id

public getDriveFolders([string $parent_id = 'root' ][, int $maxFiles = 1000 ]) : array<string|int, mixed>|void
Parameters
$parent_id : string = 'root'
$maxFiles : int = 1000
Tags
see
getDriveFiles
Return values
array<string|int, mixed>|void

getDriveFolderTree()

Get folder structure

public getDriveFolderTree(mixed $folderId) : bool
Parameters
$folderId : mixed
Return values
bool

getDrivePermissions()

List permissions of a $document_id

public getDrivePermissions( $document_id) : bool
Parameters
$document_id :
Return values
bool

getSharedDriveInfo()

public getSharedDriveInfo( $id_drive) : array<string|int, mixed>|mixed|void
Parameters
$id_drive :
Return values
array<string|int, mixed>|mixed|void

moveDriveFile()

Move a file in drive of any kind The error codes can be: 404 = not found, 403 = insufficient permissions

public moveDriveFile(string $fileId, string $destId) : array<string|int, mixed>|void
Parameters
$fileId : string
$destId : string

id of the folder dest

Return values
array<string|int, mixed>|void

moveDriveFiles()

Move all the files where parent is $folderId to $destId

public moveDriveFiles(string $folderId, string $destId) : bool
Parameters
$folderId : string
$destId : string

id of the folder dest

Return values
bool

searchDriveFiles()

Search files in the user Drive Based on: https://developers.google.com/drive/api/guides/ref-search-terms#operators

public searchDriveFiles([array<string|int, mixed> $options = ['q' => '', 'trashed' => false, 'name' => '', 'parent' => 'root', 'fields' => '*', 'maxFiles' => 100, 'pageToken' => '', 'orderBy' => 'createdTime desc'] ]) : array<string|int, mixed>|void
Parameters
$options : array<string|int, mixed> = ['q' => '', 'trashed' => false, 'name' => '', 'parent' => 'root', 'fields' => '*', 'maxFiles' => 100, 'pageToken' => '', 'orderBy' => 'createdTime desc']

options of the search

Tags
options

string q Query string. Some examples of queries: "'me' in owners and trashed = false" or "sharedWithMe"

options

string name object name in drive. If q is sent the the string " and name='{$name}'" is added

options

string parent id of the parent of the object. 'root' as default . If q is sent the the string " and '{$parent}' in parents" is added

options

bool onlyFolders If true then it returns only folders

options

bool onlyFiles If true then it returns all files but folders

options

bool trashed Search in files where trashed is true or false. 'false' as default

options

bool sharedWithMe Search shared with me

options

string fields to show in the response. '*' as default

options

int maxFiles max number of results to return

options

string pageToken token to use based on last result taken from $this->pageToken

options

string orderBy A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier. Example usage: ?orderBy=folder,modifiedTime desc,name. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored. 'createdTime desc' as default

Return values
array<string|int, mixed>|void

updateDriveFile()

Update a file in drive of any kind

public updateDriveFile(string $fileId, array<string|int, mixed> $data) : array<string|int, mixed>|void
Parameters
$fileId : string
$data : array<string|int, mixed>

Data to update. Variables allowd: 'name'

Return values
array<string|int, mixed>|void

uploadDriveFile()

Upload $content to $file_name drive

public uploadDriveFile( &$content,  $file_name[, string $parent_id = "" ][, string $mime_type = '' ]) : array<string|int, mixed>|void
Parameters
$content :
$file_name :
$parent_id : string = ""

optionally assign the document to a specific parent

$mime_type : string = ''

optionally you can assign a mimeType

Return values
array<string|int, mixed>|void

uploadDriveFileAsDoc()

Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.document

public uploadDriveFileAsDoc(mixed &$content, mixed $file_name[, mixed $parent_id = "" ]) : mixed
Parameters
$content : mixed
$file_name : mixed
$parent_id : mixed = ""
Tags
see
uploadDriveFile

uploadDriveFileAsPresentation()

Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.presentation

public uploadDriveFileAsPresentation(mixed &$content, mixed $file_name[, mixed $parent_id = "" ]) : mixed
Parameters
$content : mixed
$file_name : mixed
$parent_id : mixed = ""
Tags
see
uploadDriveFile

uploadDriveFileAsSpreadSheet()

Call to uploadDriveFile passing $mime_type = application/vnd.google-apps.spreadsheet

public uploadDriveFileAsSpreadSheet(mixed &$content, mixed $file_name[, mixed $parent_id = "" ]) : mixed
Parameters
$content : mixed
$file_name : mixed
$parent_id : mixed = ""
Tags
see
uploadDriveFile

addError()

Add an error into the classs

protected addError(mixed $code,  $msg) : mixed
Parameters
$code : mixed
$msg :

getArrayFromDriveFile()

Return an array structured taking a DriveFile

protected getArrayFromDriveFile(DriveFile &$file[, bool $avoid_empty_fields = false ][, array<string|int, mixed> $extra_data = [] ]) : array<string|int, mixed>
Parameters
$file : DriveFile
$avoid_empty_fields : bool = false
$extra_data : array<string|int, mixed> = []
Return values
array<string|int, mixed>

getDriveFolderRecursiveStructure()

Create under $parent drive folder the structure defined in $structure

private getDriveFolderRecursiveStructure(string $parent, array<string|int, mixed> $structure) : array<string|int, mixed>
Parameters
$parent : string
$structure : array<string|int, mixed>
Return values
array<string|int, mixed>

getGoogleClient()

Return a Google Client with the scopes necessary to manage Google Documents

private getGoogleClient(mixed &$config) : mixed
Parameters
$config : mixed

getUrlFromMimeType()

Return the URL to drive object based on $file->getMimeType();

private getUrlFromMimeType(DriveFile $file) : string
Parameters
$file : DriveFile
Return values
string

recursiveFolderTree()

Recursive function to create a tree

private recursiveFolderTree( $parent_id,  &$folder[, int $level = 0 ]) : bool|void
Parameters
$parent_id :
$folder :
$level : int = 0

current level of recursivity. 0 default value

Return values
bool|void

        
On this page

Search results