PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Manager.php

Manager.php in Depicter — Popup & Slider Builder 1.2.0, at app/src/Document/Manager.php

126 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document;
3
4
5 use Averta\WordPress\Utility\JSON;
6 use Depicter\Database\Repository\DocumentRepository;
7 use Depicter\Document\Models\Document;
8 use Depicter\Exception\DocumentNoContentException;
9 use Depicter\Exception\EntityException;
10 use Depicter\Front\Preview;
11
12 class Manager
13 {
14
15 public function bootstrap()
16 {
17 }
18
19 /**
20 * Returns the instance of preview class
21 *
22 * @return Preview
23 */
24 public function preview()
25 {
26 return \Depicter::resolve('depicter.front.document.preview');
27 }
28
29 /**
30 * Returns the instance of documentRepository class
31 *
32 * @return DocumentRepository
33 */
34 public function repository()
35 {
36 return \Depicter::resolve('depicter.database.repository.document');
37 }
38
39 /**
40 * Retrieves object of document editor data
41 *
42 * @param $documentId
43 * @param array $where
44 *
45 * @return bool|mixed
46 * @throws EntityException
47 */
48 public function getEditorData( $documentId, $where = [] ){
49 if( ! $documentEditorJson = $this->repository()->geContent( $documentId, $where ) ){
50 throw new DocumentNoContentException( 'No content yet.', 0, $where );
51 }
52 $data = JSON::decode( $documentEditorJson, false );
53 unset( $data->computedValues );
54 return $data;
55 }
56
57 /**
58 * Retrieves json of document editor data
59 *
60 * @param $documentId
61 * @param array $where
62 *
63 * @return bool|mixed
64 */
65 public function getEditorRawData( $documentId, $where = [] ){
66 try{
67 if( ! $documentEditorJson = $this->repository()->geContent( $documentId, $where ) ){
68 return '';
69 }
70 } catch( \Exception $e ){
71 return '';
72 }
73 return $documentEditorJson;
74 }
75
76 /**
77 * Get a document model by ID
78 *
79 * @param $documentId
80 * @param array $where
81 *
82 * @return bool|Document
83 * @throws EntityException
84 * @throws \JsonMapper_Exception
85 */
86 public function getModel( $documentId, $where = [] ){
87 $startSection = 0;
88
89 if( array_key_exists( 'start', $where ) ){
90 $startSection = (int) $where['start'];
91 unset( $where['start'] );
92 }
93
94 if ( ! $editorDataArray = $this->getEditorData( $documentId, $where ) ) {
95 return false;
96 }
97
98 $editorDataArray->startSection = $startSection;
99
100 $mapper = new Mapper();
101 return $mapper->hydrate( $editorDataArray, $documentId )->get();
102 }
103
104 /**
105 * Retrieves custom css file of a document if exists
106 *
107 * @param int $documentId
108 * @param array $where
109 *
110 * @return bool|string
111 */
112 public function getCssFileUrl( $documentId, $where = [] ){
113 try{
114 if( $document = $this->getModel( $documentId, $where = [] ) ){
115 if( $cssFile = $document->styleGenerator()->getCssFileUrl() ){
116 return $cssFile;
117 }
118 }
119 } catch( \Exception $e ){}
120
121 return false;
122 }
123
124
125 }
126