GoogleDocuments
extends GoogleDrive
in package
[$gdocs = $this->core->loadClass('GoogleDocuments');] Class to facilitate GoogleDocuments integration
Table of Contents
Properties
- $error : mixed
- $errorCode : mixed
- $errorMsg : mixed
- $lastQuery : string
- $maxRecursiveLevels : int
- $pageToken : string
- $spreedsheet : Sheets
- $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' }]
- convertToWorkSpaceSpreadSheet() : void
- Create a Spreadsheet file
- 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
- createSpreadSheet() : void
- Create a Spreadsheet file
- 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
- insertSpreadSheet() : array<string|int, mixed>|void
- Insert data in SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
- 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
- readSpreadSheet() : array<string|int, mixed>|void
- Read data from SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
- 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
- updateSpreadSheet() : array<string|int, mixed>|void
- Update SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
- 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
$error
public
mixed
$error
= \false
$errorCode
public
mixed
$errorCode
= 0
$errorMsg
public
mixed
$errorMsg
= []
$lastQuery
public
string
$lastQuery
= ''
query of last search
$maxRecursiveLevels
public
int
$maxRecursiveLevels
= 10
Max recursive levels for a tree
$pageToken
public
string
$pageToken
= ''
last pageToken used
$spreedsheet
public
Sheets
$spreedsheet
= \null
will manage the drive access properties
$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
$version
protected
mixed
$version
= '20230913'
$core
private
Core7
$core
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
boolconvertToWorkSpaceSpreadSheet()
Create a Spreadsheet file
public
convertToWorkSpaceSpreadSheet(mixed $fileId) : void
Parameters
- $fileId : mixed
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
boolcopyDriveFiles()
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
boolcreateDriveFolder()
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>|voidcreateDriveFolderStructure()
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>|voidcreateSpreadSheet()
Create a Spreadsheet file
public
createSpreadSheet(string $spreadsheet_name[, string $parent_id = "" ]) : void
Parameters
- $spreadsheet_name : string
- $parent_id : string = ""
-
value of the parent folder id
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
booldeleteDriveFiles()
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
booldeleteDriveFolder()
Delete a folder in drive
public
deleteDriveFolder(mixed $folderId) : bool
Parameters
- $folderId : mixed
Return values
booldownloadDriveFile()
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>|voidexport()
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>|voidgetDriveFile()
Create a folder under a parent
public
getDriveFile(string $id) : array<string|int, mixed>|void
Parameters
- $id : string
Return values
array<string|int, mixed>|voidgetDriveFiles()
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
Return values
array<string|int, mixed>|voidgetDriveFolders()
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
Return values
array<string|int, mixed>|voidgetDriveFolderTree()
Get folder structure
public
getDriveFolderTree(mixed $folderId) : bool
Parameters
- $folderId : mixed
Return values
boolgetDrivePermissions()
List permissions of a $document_id
public
getDrivePermissions( $document_id) : bool
Parameters
Return values
boolgetSharedDriveInfo()
public
getSharedDriveInfo( $id_drive) : array<string|int, mixed>|mixed|void
Parameters
Return values
array<string|int, mixed>|mixed|voidinsertSpreadSheet()
Insert data in SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
public
insertSpreadSheet(string $fileId, array<string|int, mixed> $values[, string $range = 'A1' ]) : array<string|int, mixed>|void
Parameters
- $fileId : string
- $values : array<string|int, mixed>
-
Array of [ rows [cols]]
- $range : string = 'A1'
-
Where to start the update
Return values
array<string|int, mixed>|voidmoveDriveFile()
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>|voidmoveDriveFiles()
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
boolreadSpreadSheet()
Read data from SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
public
readSpreadSheet(string $fileId[, string $range = 'A1' ]) : array<string|int, mixed>|void
Parameters
- $fileId : string
- $range : string = 'A1'
-
Where to start the update
Return values
array<string|int, mixed>|voidsearchDriveFiles()
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
Return values
array<string|int, mixed>|voidupdateDriveFile()
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>|voidupdateSpreadSheet()
Update SpreadSheet The error codes can be: 404 = not found, 403 = insufficient permissions
public
updateSpreadSheet(string $fileId, array<string|int, mixed> $values[, string $range = 'A1' ]) : array<string|int, mixed>|void
Parameters
- $fileId : string
- $values : array<string|int, mixed>
-
Array of [ rows [cols]]
- $range : string = 'A1'
-
Where to start the update
Return values
array<string|int, mixed>|voiduploadDriveFile()
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>|voiduploadDriveFileAsDoc()
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
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
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
addError()
Add an error into the classs
protected
addError(mixed $code, $msg) : mixed
Parameters
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
stringrecursiveFolderTree()
Recursive function to create a tree
private
recursiveFolderTree( $parent_id, &$folder[, int $level = 0 ]) : bool|void