pdfModel.php
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class pdfModel extends Model
{
// protected $table="pdf";
// protected $table="changesPDF";
///returns all pdf data
public function getPdf($id){
$rows = DB::table('PDF')
->join('changesPDF', 'PDF_idPDF', '=', 'idPDF')
->join('stylesPDF', 'stylesPDF_idstylesPDF', '=', 'idstylesPDF')
->join('change_typePDF', 'idchange_typePDF', '=', 'change_typePDF_idchange_typePDF')
->where('PDF.idPDF','=', $id);
return $rows;
}
///returns all all pdfs data for customer by id
public function getList($id){
$rows = DB::table('PDF')->where('PDF.custId','=', $id);
return $rows;
}
/// add a record of api calls
public function addApiCall($custId, $json){
$apiCallId = DB::table('apiCall')->insertGetId(
array('custId' => $custId, 'jsonRec' => $json)
);
return $apiCallId;
}
// add a pdf with options to be created
public function addPdf($apiCallId, $json){
$json = json_decode($json);
$folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
$folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
$pdfLocation = $json->pdf[0]->pdfLocation;
$file = explode('/', $pdfLocation);
$fileName = end($file);
$fileName = explode('.', $fileName);
$pdfId = DB::table('PDF')->insertGetId(
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
);
foreach($json->changes as $change) {
$idstylesPDF = DB::table('stylesPDF')->insertGetId(
array('label' => $change->label, 'style' => $change->style)
);
$idchangesPDF = DB::table('changesPDF')->insertGetId(
array('PDF_idPDF' => $pdfId, 'change_typePDF_idchange_typePDF' => $change->change_type, 'stylesPDF_idstylesPDF' => $idstylesPDF, 'locationUp' => $change->locationUp, 'locationRight' => $change->locationRight, 'width' => $change->width, 'height' => $change->height, 'pages' => $change->pages, 'content' => $change->content, 'z-index' => '')
);
}
}
public function changePdf($apiCallId, $json){
$json = json_decode($json);
$folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
$folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
$pdfLocation = $json->pdf[0]->pdfLocation;
$file = explode('/', $pdfLocation);
$fileName = end($file);
$fileName = explode('.', $fileName);
$pdfId = DB::table('PDF')->insertGetId(
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
);
foreach($json->changes as $change) {
if ($change->change_type == 'img') {
$content = explode('\\', $change->content);
$content = end($content);
}else{
$content = $change->content;
}
$idstylesPDF = DB::table('stylesPDF')->insertGetId(
array('label' => $change->label, 'style' => $change->style)
);
$idchangesPDF = DB::table('changesPDF')->insertGetId(
array('PDF_idPDF' => $pdfId, 'change_typePDF_idchange_typePDF' => $change->idchange_typePDF, 'stylesPDF_idstylesPDF' => $idstylesPDF, 'locationUp' => $change->locationUp, 'locationRight' => $change->locationRight, 'width' => $change->width, 'height' => $change->height, 'pages' => $change->pages, 'content' => $content, 'z-index' => '')
);
}
return $pdfId;
}
}