Test Failed
Push — master ( 3ad9ef...cc0a1d )
by Gabor
05:00
created

getFilesystemCategoryByApplicationAndName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2018 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Data\Storage;
15
16
use WebHemi\Data\Entity\EntitySet;
17
use WebHemi\Data\Entity\FilesystemCategoryEntity;
18
use WebHemi\Data\Entity\FilesystemDirectoryDataEntity;
19
use WebHemi\Data\Entity\FilesystemDirectoryEntity;
20
use WebHemi\Data\Entity\FilesystemDocumentEntity;
21
use WebHemi\Data\Entity\FilesystemEntity;
22
use WebHemi\Data\Entity\FilesystemMetaEntity;
23
use WebHemi\Data\Entity\FilesystemPublishedDocumentEntity;
24
use WebHemi\Data\Entity\FilesystemTagEntity;
25
use WebHemi\Data\Query\QueryInterface;
26
27
/**
28
 * Class FilesystemStorage.
29
 *
30
 * @SuppressWarnings(PHPMD.TooManyFields)
31
 */
32
class FilesystemStorage extends AbstractStorage
33
{
34
    /**
35
     * Returns a set of filesystem data accroding to the application and directory ID.
36
     *
37
     * @param int $applicationId
38
     * @param int $directoryId
39
     * @param int $limit
40
     * @param int $offset
41
     * @return EntitySet
42
     */
43
    public function getFilesystemListByApplicationAndDirectory(
44
        int $applicationId,
45
        int $directoryId,
46
        int $limit = QueryInterface::MAX_ROW_LIMIT,
47
        int $offset = 0
48
    ) : EntitySet {
49
        $this->normalizeLimitAndOffset($limit, $offset);
50
51
        $data = $this->getQueryAdapter()->fetchData(
52
            'getFilesystemListByApplicationAndDirectory',
53
            [
54
                ':idApplication' => $applicationId,
55
                ':idDirectory' => $directoryId,
56
                ':limit' => $limit,
57
                ':offset' => $offset
58
            ]
59
        );
60
61
        return $this->getEntitySet(FilesystemEntity::class, $data);
62
    }
63
64
    /**
65
     * Returns filesystem information identified by (unique) ID.
66
     *
67
     * @param  int $identifier
68
     * @return null|FilesystemEntity
69
     */
70
    public function getFilesystemById(int $identifier) : ? FilesystemEntity
71
    {
72
        $data = $this->getQueryAdapter()->fetchData(
73
            'getFilesystemById',
74
            [
75
                ':idFilesystem' => $identifier
76
            ]
77
        );
78
79
        /** @var null|FilesystemEntity $entity */
80
        $entity = $this->getEntity(FilesystemEntity::class, $data[0] ?? []);
81
82
        return $entity;
83
    }
84
85
    /**
86
     * Returns filesystem information by application, basename and path.
87
     *
88
     * @param  int    $applicationId
89
     * @param  string $path
90
     * @param  string $baseName
91
     * @return null|FilesystemEntity
92
     */
93
    public function getFilesystemByApplicationAndPath(
94
        int $applicationId,
95
        string $path,
96
        string $baseName
97
    ) : ? FilesystemEntity {
98
        $data = $this->getQueryAdapter()->fetchData(
99
            'getFilesystemByApplicationAndPath',
100
            [
101
                ':idApplication' => $applicationId,
102
                ':path' => $path,
103
                ':baseName' => $baseName
104
            ]
105
        );
106
107
        /** @var null|FilesystemEntity $entity */
108
        $entity = $this->getEntity(FilesystemEntity::class, $data[0] ?? []);
109
110
        return $entity;
111
    }
112
113
    /**
114
     * Returns filesystem meta list identified by filesystem ID.
115
     *
116
     * @param  int $identifier
117
     * @param int $limit
118
     * @param int $offset
119
     * @return EntitySet
120
     */
121
    public function getFilesystemMetaListByFilesystem(
122
        int $identifier,
123
        int $limit = QueryInterface::MAX_ROW_LIMIT,
124
        int $offset = 0
125
    ) : EntitySet {
126
        $this->normalizeLimitAndOffset($limit, $offset);
127
128
        $data = $this->getQueryAdapter()->fetchData(
129
            'getFilesystemMetaListByFilesystem',
130
            [
131
                ':idFilesystem' => $identifier,
132
                ':limit' => $limit,
133
                ':offset' => $offset
134
            ]
135
        );
136
137
        return $this->getEntitySet(FilesystemMetaEntity::class, $data);
138
    }
139
140
    /**
141
     * Returns a simplified form of the filesystem meta list.
142
     *
143
     * @param  int $identifier
144
     * @param int $limit
145
     * @param int $offset
146
     * @return null|array
147
     */
148
    public function getSimpleFilesystemMetaListByFilesystem(
149
        int $identifier,
150
        int $limit = QueryInterface::MAX_ROW_LIMIT,
151
        int $offset = 0
152
    ) : ? array {
153
        $metaInfo = [];
154
        $entitySet = $this->getFilesystemMetaListByFilesystem($identifier, $limit, $offset);
155
156
        /** @var FilesystemMetaEntity $filesystemMetaEntity */
157
        foreach ($entitySet as $filesystemMetaEntity) {
158
            $metaInfo[$filesystemMetaEntity->getMetaKey()] = $filesystemMetaEntity->getMetaData();
159
        }
160
161
        return $metaInfo;
162
    }
163
164
    /**
165
     * Returns the full filesystem document data set.
166
     *
167
     * @param int $limit
168
     * @param int $offset
169
     * @return EntitySet
170
     */
171
    public function getFilesystemDocumentList(
172
        int $limit = QueryInterface::MAX_ROW_LIMIT,
173
        int $offset = 0
174
    ) : EntitySet {
175
        $this->normalizeLimitAndOffset($limit, $offset);
176
177
        $data = $this->getQueryAdapter()->fetchData(
178
            'getFilesystemDocumentList',
179
            [
180
                ':limit' => $limit,
181
                ':offset' => $offset
182
            ]
183
        );
184
185
        return $this->getEntitySet(FilesystemDocumentEntity::class, $data);
186
    }
187
188
    /**
189
     * Returns filesystem document information identified by (unique) ID.
190
     *
191
     * @param  int $identifier
192
     * @return null|FilesystemDocumentEntity
193
     */
194
    public function getFilesystemDocumentById(int $identifier) : ? FilesystemDocumentEntity
195
    {
196
        $data = $this->getQueryAdapter()->fetchData(
197
            'getFilesystemDocumentById',
198
            [
199
                ':idDocument' => $identifier
200
            ]
201
        );
202
203
        /** @var null|FilesystemDocumentEntity $entity */
204
        $entity = $this->getEntity(FilesystemDocumentEntity::class, $data[0] ?? []);
205
206
        return $entity;
207
    }
208
209
    /**
210
     * Returns published filesystem data along with the document data.
211
     *
212
     * @param int $applicationId
213
     * @param string|null $order
214
     * @param int $limit
215
     * @param int $offset
216
     * @return EntitySet
217
     */
218
    public function getFilesystemPublishedDocumentList(
219
        int $applicationId,
220
        string $order = null,
221
        int $limit = QueryInterface::MAX_ROW_LIMIT,
222
        int $offset = 0
223
    ) : EntitySet {
224
        $this->normalizeLimitAndOffset($limit, $offset);
225
226
        if (empty($order)) {
227
            $order = 'fs.`date_published` DESC';
228
        }
229
230
        $data = $this->getQueryAdapter()->fetchData(
231
            'getFilesystemPublishedDocumentList',
232
            [
233
                ':idApplication' => $applicationId,
234
                ':orderBy' => $order,
235
                ':limit' => $limit,
236
                ':offset' => $offset
237
            ]
238
        );
239
240
        return $this->getEntitySet(FilesystemPublishedDocumentEntity::class, $data);
241
    }
242
243
    /**
244
     * Returns published filesystem data along with the document data.
245
     *
246
     * @param int $applicationId
247
     * @param int $year
248
     * @param int $month
249
     * @param string|null $order
250
     * @param int $limit
251
     * @param int $offset
252
     * @return EntitySet
253
     */
254
    public function getFilesystemPublishedDocumentListByDate(
255
        int $applicationId,
256
        int $year,
257
        int $month,
258
        string $order = null,
259
        int $limit = QueryInterface::MAX_ROW_LIMIT,
260
        int $offset = 0
261
    ) : EntitySet {
262
        $this->normalizeLimitAndOffset($limit, $offset);
263
264
        if (empty($order)) {
265
            $order = 'fs.`date_published` DESC';
266
        }
267
268
        $data = $this->getQueryAdapter()->fetchData(
269
            'getFilesystemPublishedDocumentListByDate',
270
            [
271
                ':idApplication' => $applicationId,
272
                ':year' => $year,
273
                ':month' => $month,
274
                ':orderBy' => $order,
275
                ':limit' => $limit,
276
                ':offset' => $offset
277
            ]
278
        );
279
280
        return $this->getEntitySet(FilesystemPublishedDocumentEntity::class, $data);
281
    }
282
283
    /**
284
     * Returns published filesystem data along with the document data.
285
     *
286
     * @param int $applicationId
287
     * @param int $categoryId
288
     * @param string|null $order
289
     * @param int $limit
290
     * @param int $offset
291
     * @return EntitySet
292
     */
293
    public function getFilesystemPublishedDocumentListByCategory(
294
        int $applicationId,
295
        int $categoryId,
296
        string $order = null,
297
        int $limit = QueryInterface::MAX_ROW_LIMIT,
298
        int $offset = 0
299
    ) : EntitySet {
300
        $this->normalizeLimitAndOffset($limit, $offset);
301
302
        if (empty($order)) {
303
            $order = 'fs.`date_published` DESC';
304
        }
305
306
        $data = $this->getQueryAdapter()->fetchData(
307
            'getFilesystemPublishedDocumentListByCategory',
308
            [
309
                ':idApplication' => $applicationId,
310
                ':idCategory' => $categoryId,
311
                ':orderBy' => $order,
312
                ':limit' => $limit,
313
                ':offset' => $offset
314
            ]
315
        );
316
317
        return $this->getEntitySet(FilesystemPublishedDocumentEntity::class, $data);
318
    }
319
320
    /**
321
     * Returns published filesystem data according to a user ID along with the document data.
322
     *
323
     * @param int $applicationId
324
     * @param int $userId
325
     * @param string|null $order
326
     * @param int $limit
327
     * @param int $offset
328
     * @return EntitySet
329
     */
330
    public function getFilesystemPublishedDocumentListByAuthor(
331
        int $applicationId,
332
        int $userId,
333
        string $order = null,
334
        int $limit = QueryInterface::MAX_ROW_LIMIT,
335
        int $offset = 0
336
    ) : EntitySet {
337
        $this->normalizeLimitAndOffset($limit, $offset);
338
339
        if (empty($order)) {
340
            $order = 'fs.`date_published` DESC';
341
        }
342
343
        $data = $this->getQueryAdapter()->fetchData(
344
            'getFilesystemPublishedDocumentListByAuthor',
345
            [
346
                ':idApplication' => $applicationId,
347
                ':idUser' => $userId,
348
                ':orderBy' => $order,
349
                ':limit' => $limit,
350
                ':offset' => $offset
351
            ]
352
        );
353
354
        return $this->getEntitySet(FilesystemPublishedDocumentEntity::class, $data);
355
    }
356
357
    /**
358
     * Returns published filesystem data according to a tag ID along with the document data.
359
     *
360
     * @param int $applicationId
361
     * @param int $tagId
362
     * @param string|null $order
363
     * @param int $limit
364
     * @param int $offset
365
     * @return EntitySet
366
     */
367
    public function getFilesystemPublishedDocumentListByTag(
368
        int $applicationId,
369
        int $tagId,
370
        string $order = null,
371
        int $limit = QueryInterface::MAX_ROW_LIMIT,
372
        int $offset = 0
373
    ) : EntitySet {
374
        $this->normalizeLimitAndOffset($limit, $offset);
375
376
        if (empty($order)) {
377
            $order = 'fs.`date_published` DESC';
378
        }
379
380
        $data = $this->getQueryAdapter()->fetchData(
381
            'getFilesystemPublishedDocumentListByTag',
382
            [
383
                ':idApplication' => $applicationId,
384
                ':idTag' => $tagId,
385
                ':orderBy' => $order,
386
                ':limit' => $limit,
387
                ':offset' => $offset
388
            ]
389
        );
390
391
        return $this->getEntitySet(FilesystemPublishedDocumentEntity::class, $data);
392
    }
393
394
    /**
395
     * Returns filesystem information by application, basename and path.
396
     *
397
     * @param  int    $applicationId
398
     * @param  string $path
399
     * @param  string $baseName
400
     * @return null|FilesystemPublishedDocumentEntity
401
     */
402
    public function getFilesystemPublishedDocumentByApplicationAndPath(
403
        int $applicationId,
404
        string $path,
405
        string $baseName
406
    ) : ? FilesystemPublishedDocumentEntity {
407
        $data = $this->getQueryAdapter()->fetchData(
408
            'getFilesystemPublishedDocumentByApplicationAndPath',
409
            [
410
                ':idApplication' => $applicationId,
411
                ':path' => $path,
412
                ':baseName' => $baseName
413
            ]
414
        );
415
416
        /** @var null|FilesystemPublishedDocumentEntity $entity */
417
        $entity = $this->getEntity(FilesystemPublishedDocumentEntity::class, $data[0] ?? []);
418
419
        return $entity;
420
    }
421
422
    /**
423
     * Returns a simplified list of publication dates.
424
     *
425
     * @param int $applicationId
426
     * @param int $limit
427
     * @param int $offset
428
     * @return array
429
     */
430
    public function getFilesystemPublishedDocumentDateList(
431
        int $applicationId,
432
        int $limit = QueryInterface::MAX_ROW_LIMIT,
433
        int $offset = 0
434
    ) : array {
435
        $data = $this->getQueryAdapter()->fetchData(
436
            'getFilesystemPublishedDocumentDateList',
437
            [
438
                ':idApplication' => $applicationId,
439
                ':limit' => $limit,
440
                ':offset' => $offset
441
            ]
442
        );
443
444
        return $data ?? [];
445
    }
446
447
    /**
448
     * Returns the tags for a filesystem record.
449
     *
450
     * @param int $filesystemId
451
     * @param int $limit
452
     * @param int $offset
453
     * @return EntitySet
454
     */
455
    public function getFilesystemTagListByFilesystem(
456
        int $filesystemId,
457
        int $limit = QueryInterface::MAX_ROW_LIMIT,
458
        int $offset = 0
459
    ) : EntitySet {
460
        $this->normalizeLimitAndOffset($limit, $offset);
461
462
        $data = $this->getQueryAdapter()->fetchData(
463
            'getFilesystemTagListByFilesystem',
464
            [
465
                ':idFilesystem' => $filesystemId,
466
                ':limit' => $limit,
467
                ':offset' => $offset
468
            ]
469
        );
470
471
        return $this->getEntitySet(FilesystemTagEntity::class, $data);
472
    }
473
474
    /**
475
     * Returns the tags for an application.
476
     *
477
     * @param int $applicationId
478
     * @param int $limit
479
     * @param int $offset
480
     * @return EntitySet
481
     */
482
    public function getFilesystemTagListByApplication(
483
        int $applicationId,
484
        int $limit = QueryInterface::MAX_ROW_LIMIT,
485
        int $offset = 0
486
    ) : EntitySet {
487
        $this->normalizeLimitAndOffset($limit, $offset);
488
489
        $data = $this->getQueryAdapter()->fetchData(
490
            'getFilesystemTagListByApplication',
491
            [
492
                ':idApplication' => $applicationId,
493
                ':limit' => $limit,
494
                ':offset' => $offset
495
            ]
496
        );
497
498
        return $this->getEntitySet(FilesystemTagEntity::class, $data);
499
    }
500
501
    /**
502
     * Returns filesystem tag information identified by (unique) ID.
503
     *
504
     * @param int $identifier
505
     * @return null|FilesystemTagEntity
506
     */
507
    public function getFilesystemTagById(int $identifier) : ? FilesystemTagEntity
508
    {
509
        $data = $this->getQueryAdapter()->fetchData(
510
            'getFilesystemTagById',
511
            [
512
                ':idTag' => $identifier
513
            ]
514
        );
515
516
        /** @var null|FilesystemTagEntity $entity */
517
        $entity = $this->getEntity(FilesystemTagEntity::class, $data[0] ?? []);
518
519
        return $entity;
520
    }
521
522
    /**
523
     * Returns filesystem tag information identified by (unique) ID.
524
     *
525
     * @param int $applicationId
526
     * @param string $name
527
     * @return null|FilesystemTagEntity
528
     */
529
    public function getFilesystemTagByApplicationAndName(
530
        int $applicationId,
531
        string $name
532
    ) : ? FilesystemTagEntity {
533
        $data = $this->getQueryAdapter()->fetchData(
534
            'getFilesystemTagByApplicationAndName',
535
            [
536
                ':idApplication' => $applicationId,
537
                ':name' => $name
538
            ]
539
        );
540
541
        /** @var null|FilesystemTagEntity $entity */
542
        $entity = $this->getEntity(FilesystemTagEntity::class, $data[0] ?? []);
543
544
        return $entity;
545
    }
546
547
    /**
548
     * Returns the categories for an application.
549
     *
550
     * @param int $applicationId
551
     * @param int $limit
552
     * @param int $offset
553
     * @return EntitySet
554
     */
555
    public function getFilesystemCategoryListByApplication(
556
        int $applicationId,
557
        int $limit = QueryInterface::MAX_ROW_LIMIT,
558
        int $offset = 0
559
    )  : EntitySet {
560
        $this->normalizeLimitAndOffset($limit, $offset);
561
562
        $data = $this->getQueryAdapter()->fetchData(
563
            'getFilesystemCategoryListByApplication',
564
            [
565
                ':idApplication' => $applicationId,
566
                ':limit' => $limit,
567
                ':offset' => $offset
568
            ]
569
        );
570
571
        return $this->getEntitySet(FilesystemCategoryEntity::class, $data);
572
    }
573
574
    /**
575
     * Returns filesystem category information identified by (unique) ID.
576
     *
577
     * @param int $identifier
578
     * @return null|FilesystemCategoryEntity
579
     */
580
    public function getFilesystemCategoryById(int $identifier) : ? FilesystemCategoryEntity
581
    {
582
        $data = $this->getQueryAdapter()->fetchData(
583
            'getFilesystemCategoryById',
584
            [
585
                ':idCategory' => $identifier
586
            ]
587
        );
588
589
        /** @var null|FilesystemCategoryEntity $entity */
590
        $entity = $this->getEntity(FilesystemCategoryEntity::class, $data[0] ?? []);
591
592
        return $entity;
593
    }
594
595
    /**
596
     * Returns filesystem category information identified by application ID and category name.
597
     *
598
     * @param int $applicationId
599
     * @param string $categoryName
600
     * @return null|FilesystemCategoryEntity
601
     */
602
    public function getFilesystemCategoryByApplicationAndName(
603
        int $applicationId,
604
        string $categoryName
605
    ) : ? FilesystemCategoryEntity {
606
        $data = $this->getQueryAdapter()->fetchData(
607
            'getFilesystemCategoryByApplicationAndName',
608
            [
609
                ':idApplication' => $applicationId,
610
                ':categoryName' => $categoryName
611
            ]
612
        );
613
614
        /** @var null|FilesystemCategoryEntity $entity */
615
        $entity = $this->getEntity(FilesystemCategoryEntity::class, $data[0] ?? []);
616
617
        return $entity;
618
    }
619
620
    /**
621
     * Returns filesystem directory information identified by (unique) ID.
622
     *
623
     * @param int $identifier
624
     * @return null|FilesystemDirectoryEntity
625
     */
626
    public function getFilesystemDirectoryById(int $identifier) : ? FilesystemDirectoryEntity
627
    {
628
        $data = $this->getQueryAdapter()->fetchData(
629
            'getFilesystemDirectoryById',
630
            [
631
                ':idDirectory' => $identifier
632
            ]
633
        );
634
635
        /** @var null|FilesystemDirectoryEntity $entity */
636
        $entity = $this->getEntity(FilesystemDirectoryEntity::class, $data[0] ?? []);
637
638
        return $entity;
639
    }
640
641
    /**
642
     * Returns filesystem directory information identified by its proxy.
643
     *
644
     * @param string $proxy
645
     * @return null|FilesystemDirectoryEntity
646
     */
647
    public function getFilesystemDirectoryByProxy(string $proxy) : ? FilesystemDirectoryEntity
648
    {
649
        $data = $this->getQueryAdapter()->fetchData(
650
            'getFilesystemDirectoryByProxy',
651
            [
652
                ':proxy' => $proxy
653
            ]
654
        );
655
656
        /** @var null|FilesystemDirectoryEntity $entity */
657
        $entity = $this->getEntity(FilesystemDirectoryEntity::class, $data[0] ?? []);
658
659
        return $entity;
660
    }
661
662
    /**
663
     * Returns a combined information of the filesystem and directory according to the application and the proxy.
664
     *
665
     * @param int $applicationId
666
     * @param string $proxy
667
     * @return null|FilesystemDirectoryDataEntity
668
     */
669
    public function getFilesystemDirectoryDataByApplicationAndProxy(
670
        int $applicationId,
671
        string $proxy
672
    ) : ? FilesystemDirectoryDataEntity {
673
        $data = $this->getQueryAdapter()->fetchData(
674
            'getFilesystemDirectoryDataByApplicationAndProxy',
675
            [
676
                ':idApplication' => $applicationId,
677
                ':proxy' => $proxy
678
            ]
679
        );
680
681
        /** @var null|FilesystemDirectoryDataEntity $entity */
682
        $entity = $this->getEntity(FilesystemDirectoryDataEntity::class, $data[0] ?? []);
683
684
        return $entity;
685
    }
686
}
687