pdfModel.php
2.28 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
<?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]->name); // 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, 'pages' => $change->pages, 'content' => $change->content, 'z-index' => '')
);
}
}
}