PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
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
← All changes | app/src/Database/Repository/DocumentRepository.php +64 -12 1.3.21.9.2 View file →
@@ -197,19 +197,31 @@
197 197 /**
198 198 * Save changes directly to current document
199 199 *
200 200 * @param array $fields
201 + * @param array $args
201 202 *
202 203 * @return array
203 204 * @throws Exception
204 205 */
205 - public function getList( array $fields = [] )
206 + public function getList( array $fields = [], $args = [] )
206 207 {
207 208 $columnsName = !empty( $fields ) ? $fields : ['id', 'name', 'slug', 'author', 'sections_count', 'created_at', 'modified_at', 'thumbnail', 'status'];
208 - $documents = $this->document()->reselect( $columnsName )
209 - ->where('parent', '0')
210 - ->findAll()->get();
209 + $numberOfPages = '';
210 + if ( !empty( $args['page'] ) && !empty( $args['perPage'] ) ) {
211 + $pager = $this->select( $fields )->paginate( $args['perPage'], $args['page'] );
212 + if ( $pager ) {
213 + $numberOfPages = $pager->getNumberOfPages();
214 + $documents = $pager->getResults();
215 + } else {
216 + $documents = [];
217 + }
211 218
219 + } else {
220 + $documents = $this->select( $fields )->findAll()->get();
221 + }
222 +
223 +
212 224 $documents = $documents ? $documents->toArray() : [];
213 225
214 226 if ( $documents && empty( $fields ) ) {
215 227 $uploadDir = wp_upload_dir();
@@ -223,12 +235,36 @@
223 235 }
224 236 }
225 237 }
226 238
239 + if ( !empty( $numberOfPages ) ) {
240 + return [
241 + 'page' => $args['page'],
242 + 'perPage' => $args['perPage'],
243 + 'numberOfPages' => $numberOfPages,
244 + 'documents' => $documents
245 + ];
246 + }
247 +
227 248 return $documents;
228 249 }
229 250
230 251 /**
252 + * Queries records of documents with specified fields
253 + *
254 + * @param array $fields
255 + *
256 + * @return Document
257 + * @throws Exception
258 + */
259 + public function select( array $fields = [] )
260 + {
261 + $columnsName = !empty( $fields ) ? $fields : ['id', 'name', 'slug', 'author', 'sections_count', 'created_at', 'modified_at', 'thumbnail', 'status'];
262 + return $this->document()->reselect( $columnsName )
263 + ->where('parent', '0');
264 + }
265 +
266 + /**
231 267 * Save changes directly to current document
232 268 *
233 269 * @param array $fields
234 270 *
@@ -393,9 +429,9 @@
393 429 * @return mixed
394 430 */
395 431 public function findById( int $id )
396 432 {
397 - return $this->document->findById( $id );
433 + return $this->document()->findById( $id );
398 434 }
399 435
400 436 /**
401 437 * Finds or creates new document in database
@@ -635,21 +671,21 @@
635 671 return $documentEntity;
636 672 }
637 673
638 674 /**
639 - * Whether the document exists and is not published or not
675 + * Whether the document has been published so far or not
640 676 *
641 677 * @param int $documentId
642 - * @param array $where
643 678 *
644 679 * @return bool
645 - * @throws Exception
646 680 */
647 - public function isNotPublished( $documentId, $where = [] ){
648 - if( ! $documentEntity = $this->findOne( $documentId, $where ) ){
649 - if( $documentEntity = $this->findOne( $documentId, [ 'status' => 'draft' ] ) ){
681 + public function isPublishedBefore( $documentId ){
682 + try{
683 + if( $this->getRecentRevision( $documentId ) ){
650 684 return true;
651 685 }
686 + } catch ( \Exception $exception ) {
687 + return false;
652 688 }
653 689
654 690 return false;
655 691 }
@@ -663,12 +699,28 @@
663 699 * @throws Exception
664 700 */
665 701 public function isPublished( $documentId ){
666 702 try{
667 - return $this->findOne( $documentId, [ 'status' => 'publish' ] );
703 + return $this->getStatus( $documentId ) === 'publish';
668 704 } catch ( \Exception $exception ) {
669 705 return false;
670 706 }
707 + }
708 +
709 + /**
710 + * Get status of document
711 + *
712 + * @param int $documentId
713 + *
714 + * @return string
715 + */
716 + public function getStatus( $documentId ) {
717 + if( $document = $this->findById( $documentId ) ){
718 + $document = $document->toArray();
719 + return $document['status'];
720 + }
721 +
722 + return '';
671 723 }
672 724
673 725 /**
674 726 * Retrieves the url to preview image of document if exists