Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
pdf-customizer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
0542149d
authored
2016-09-15 19:37:10 -0400
by
Jeff Balicki
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add group folders
1 parent
26ddd802
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
10 deletions
app/Http/Controllers/GoogledriveuploadpdfController.php
app/pdfModel.php
public/files/js/interfaceGdrive.js
app/Http/Controllers/GoogledriveuploadpdfController.php
View file @
0542149
...
...
@@ -28,6 +28,16 @@ class GoogledriveuploadpdfController extends Controller
public
function
google_drive_upload
(
$folder
,
$filename
,
$PdfId
,
$cust_id
)
{
//error_log($cust_id);
$save_folder
=
$this
->
isGoogleFolderCreated
(
$cust_id
);
$group_ids
=
preg_split
(
'/-/'
,
$cust_id
);
$group_id
=
ltrim
(
rtrim
(
$group_ids
[
1
]));
$cust_id
=
ltrim
(
rtrim
(
$group_ids
[
0
]));
session_start
();
$pdffile
=
new
FileEntryController
();
$pdfFile
=
$pdffile
->
getPDF
(
$folder
,
$filename
);
...
...
@@ -44,13 +54,6 @@ class GoogledriveuploadpdfController extends Controller
$client
->
setRedirectUri
(
$user
[
0
]
->
redirect_uri
);
$client
->
setAccessType
(
'offline'
);
// error_log(print_r($client,true));
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
...
...
@@ -66,7 +69,7 @@ class GoogledriveuploadpdfController extends Controller
$file
=
new
\Google_Service_Drive_DriveFile
();
$parent
=
new
\Google_Service_Drive_ParentReference
();
$parent
->
setId
(
$
user
[
0
]
->
save_folder
);
$parent
->
setId
(
$
save_folder
[
0
]
->
subfolder_id
);
$file
->
setParents
(
array
(
$parent
));
...
...
@@ -82,12 +85,13 @@ class GoogledriveuploadpdfController extends Controller
$file
->
setMimeType
(
$mimetype
);
$data
=
$pdfFile
;
//error_log(print_r($file ,true));
$createdFile
=
$dr_service
->
files
->
insert
(
$file
,
array
(
'data'
=>
$data
,
'mimeType'
=>
$mimetype
,
//text/plain',
'uploadType'
=>
$uploadType
));
$GoogleId
=
$createdFile
->
getId
();
$pdfId
=
new
pdfModel
();
$pdfId
=
$pdfId
->
setPdfGoogleId
(
$GoogleId
,
$PdfId
);
...
...
@@ -95,6 +99,99 @@ class GoogledriveuploadpdfController extends Controller
}
public
function
isGoogleFolderCreated
(
$cust_id
)
{
$group_ids
=
preg_split
(
'/-/'
,
$cust_id
);
$group_id
=
ltrim
(
rtrim
(
$group_ids
[
1
]));
$cust_id
=
ltrim
(
rtrim
(
$group_ids
[
0
]));
$saveFolderId
=
new
pdfModel
();
$saveFolderId
=
$saveFolderId
->
checkIsGoogleFolderCreated
(
$group_id
);
if
(
empty
(
$saveFolderId
)){
$this
->
createFolderGoogle
(
$cust_id
);
$saveFolderId
=
$saveFolderId
->
checkIsGoogleFolderCreated
(
$group_id
);
return
$saveFolderId
;
}
else
{
return
$saveFolderId
;
}
}
public
function
createFolderGoogle
(
$cust_id
)
{
$user
=
new
pdfModel
();
$user
=
$user
->
getGoogleUserOath
(
$cust_id
)
->
get
();;
$client
=
new
\Google_Client
();
$client
->
setScopes
(
array
(
'https://www.googleapis.com/auth/drive.file'
));
$client
->
setClientId
(
$user
[
0
]
->
google_client_id
);
$client
->
setClientSecret
(
$user
[
0
]
->
google_client_secret
);
$client
->
setRedirectUri
(
$user
[
0
]
->
redirect_uri
);
$client
->
setAccessType
(
'offline'
);
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$client
->
refreshToken
(
$user
[
0
]
->
refresh_token
);
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$dr_service
=
new
\Google_Service_Drive
(
$client
);
$service
=
new
\Google_Service_Drive
(
$client
);
$group_ids
=
preg_split
(
'/-/'
,
$cust_id
);
$group_id
=
ltrim
(
rtrim
(
$group_ids
[
1
]));
$cust_id
=
ltrim
(
rtrim
(
$group_ids
[
0
]));
$files
=
$service
->
files
->
listFiles
();
foreach
(
$files
[
'items'
]
as
$item
)
{
if
(
$item
[
'title'
]
==
$group_id
)
{
$folderId
=
$item
[
'id'
];
break
;
}
}
if
(
$client
->
getAccessToken
())
{
$file
=
new
\Google_Service_Drive_DriveFile
();
//Setup the Folder to Create
$file
->
setTitle
(
'User Made'
);
$file
->
setDescription
(
'Made by user'
);
$file
->
setMimeType
(
'application/vnd.google-apps.folder'
);
//Set the ProjectsFolder Parent
$parent
=
new
\Google_Service_Drive_ParentReference
();
$parent
->
setId
(
$folderId
);
$file
->
setParents
(
array
(
$parent
));
//create the ProjectFolder in the Parent
$createdFile
=
$service
->
files
->
insert
(
$file
,
array
(
'mimeType'
=>
'application/vnd.google-apps.folder'
,
));
$group_id
=
preg_split
(
'/-/'
,
$cust_id
);
$group_id
=
ltrim
(
rtrim
(
$group_id
[
1
]));
$saveFolderId
=
new
pdfModel
();
$saveFolderId
->
saveFolderId
(
$group_id
,
$folderId
,
$createdFile
->
id
);
}
}
public
function
GoogleToken
()
...
...
app/pdfModel.php
View file @
0542149
...
...
@@ -27,6 +27,24 @@ class pdfModel extends Model
return
$rows
;
}
public
function
checkIsGoogleFolderCreated
(
$id
){
$rows
=
DB
::
table
(
'googleFolderIds'
)
->
select
(
'*'
)
->
where
(
'googleFolderIds.group_id'
,
'='
,
$id
)
->
get
();
error_log
(
print_r
(
$rows
,
true
));
return
$rows
;
}
public
function
saveFolderId
(
$group_id
,
$folderId
,
$createdFile
){
$apiCallId
=
DB
::
table
(
'googleFolderIds'
)
->
insertGetId
(
array
(
'group_id'
=>
$group_id
,
'folder_id'
=>
$folderId
,
'subfolder_id'
=>
$createdFile
)
);
}
public
function
getPdf
(
$id
){
...
...
public/files/js/interfaceGdrive.js
View file @
0542149
...
...
@@ -641,7 +641,7 @@ function returnOptions(form, preview) {
var
jsonReturn
=
'{"pdf":[{"name":"'
+
json
[
0
].
name
+
'", "folder":"'
+
json
[
0
].
folder
+
'", "pdfLocation":"'
+
json
[
0
].
file
+
'","pageWidth":"'
+
json
[
0
].
pwidth
+
'","pageHeight":"'
+
json
[
0
].
pheight
+
'", "custId":"'
+
user_id
+
'"}],"changes":['
var
jsonReturn
=
'{"pdf":[{"name":"'
+
json
[
0
].
name
+
'", "folder":"'
+
json
[
0
].
folder
+
'", "pdfLocation":"'
+
json
[
0
].
file
+
'","pageWidth":"'
+
json
[
0
].
pwidth
+
'","pageHeight":"'
+
json
[
0
].
pheight
+
'", "custId":"'
+
user_id
+
'-'
+
broker_id
+
'"}],"changes":['
var
o
=
1
;
var
e
=
1
;
...
...
@@ -666,6 +666,7 @@ function returnOptions(form, preview) {
}
jsonReturn
+=
' ]}'
;
//console.log(jsonReturn );
if
(
preview
==
false
)
{
url
=
'update'
;
...
...
Please
register
or
sign in
to post a comment