PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
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.3.3, at app/src/Document/Manager.php

174 lines 3.7 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 * Converts document slug or alias to document ID
78 *
79 * @param string|array $documentIDs A document ID/Slug/Alias or list of them
80 *
81 * @return mixed
82 */
83 public function getID( $documentIDs ){
84 if( empty( $documentIDs ) ){
85 return false;
86 }
87
88 try{
89 if( is_array( $documentIDs ) ){
90 $realDocumentIDs = [];
91 foreach( $documentIDs as $documentID ){
92 $realDocumentIDs = $this->getID( $documentID );
93 }
94 return $realDocumentIDs;
95
96 } elseif ( ! is_numeric( $documentIDs ) && is_string( $documentIDs ) ) {
97 if ( $document = \Depicter::document()->repository()->findOne( null, ['slug' => $documentIDs] ) ) {
98 return $document->getID();
99 }
100 } else {
101 return $documentIDs;
102 }
103 } catch( \Exception $e ){
104 return false;
105 }
106
107 return false;
108 }
109
110 /**
111 * Get a document model by ID
112 *
113 * @param $documentId
114 * @param array $where
115 *
116 * @return bool|Document
117 * @throws EntityException
118 * @throws \JsonMapper_Exception
119 */
120 public function getModel( $documentId, $where = [] ){
121 $startSection = 0;
122
123 if( array_key_exists( 'start', $where ) ){
124 $startSection = (int) $where['start'];
125 unset( $where['start'] );
126 }
127
128 if ( ! $editorDataArray = $this->getEditorData( $documentId, $where ) ) {
129 return false;
130 }
131
132 $editorDataArray->startSection = $startSection;
133
134 $mapper = new Mapper();
135 return $mapper->hydrate( $editorDataArray, $documentId )->get();
136 }
137
138 /**
139 * Retrieves custom css file of a document if exists
140 *
141 * @param int $documentId
142 * @param array $where
143 *
144 * @return bool|string
145 */
146 public function getCssFileUrl( $documentId, $where = [] ){
147 try{
148 if( $document = $this->getModel( $documentId, $where = [] ) ){
149 if( $cssFile = $document->styleGenerator()->getCssFileUrl() ){
150 return $cssFile;
151 }
152 }
153 } catch( \Exception $e ){}
154
155 return false;
156 }
157
158
159 /**
160 * Get status of document
161 *
162 * @param int $documentID
163 * @return string
164 */
165 public function getStatus( $documentID ) {
166 if( $document = \Depicter::document()->repository()->findById( $documentID ) ){
167 $document = $document->toArray();
168 return $document['status'];
169 }
170
171 return '';
172 }
173 }
174