pdfModel.php 4.05 KB
<?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 getPdfid($id){



        $rows = DB::table('googleDriveID')
		    ->select('pdfid')
            ->where('googleDriveID.googledriveId','=', $id);

        return $rows;
}

    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;


    }

}