1
|
|
|
<?php |
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
3
|
|
|
/** |
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
5
|
|
|
* on 23.03.16 at 11:45 |
6
|
|
|
*/ |
7
|
|
|
namespace samsoncms\api\generator\analyzer; |
8
|
|
|
|
9
|
|
|
use samsoncms\api\Field; |
10
|
|
|
use samsoncms\api\generator\exception\ParentEntityNotFound; |
11
|
|
|
use samsoncms\api\generator\metadata\VirtualMetadata; |
12
|
|
|
use samsoncms\api\Navigation; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Generic entities metadata analyzer. |
16
|
|
|
* |
17
|
|
|
* @package samsoncms\api\analyzer |
18
|
|
|
*/ |
19
|
|
|
class GalleryAnalyzer extends VirtualAnalyzer |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Analyze virtual entities and gather their metadata. |
23
|
|
|
* |
24
|
|
|
* @return \samsoncms\api\generator\metadata\VirtualMetadata[] |
25
|
|
|
* @throws ParentEntityNotFound |
26
|
|
|
*/ |
27
|
|
|
public function analyze() |
28
|
|
|
{ |
29
|
|
|
/** @var VirtualMetadata[] $metadataCollection Set pointer to global metadata collection */ |
30
|
|
|
$metadataCollection = []; |
31
|
|
|
|
32
|
|
|
// Iterate all structures, parents first |
33
|
|
|
foreach ($this->getVirtualEntities() as $structureRow) { |
34
|
|
|
$navigationID = $structureRow[Navigation::F_PRIMARY]; |
35
|
|
|
|
36
|
|
|
// Iterate entity fields |
37
|
|
|
foreach ($this->getEntityFields($navigationID) as $fieldID => $fieldRow) { |
38
|
|
|
// We need only gallery fields |
39
|
|
|
if ((int)$fieldRow[Field::F_TYPE] === Field::TYPE_GALLERY) { |
|
|
|
|
40
|
|
|
|
41
|
|
|
// Avoid GalleryGallery |
42
|
|
|
$entity = ucfirst($this->fieldName($fieldRow[Field::F_IDENTIFIER])); |
43
|
|
|
// Avoid GalleryGallery |
44
|
|
|
$entity = $entity !== 'Gallery' ? $entity . 'Gallery' : $entity; |
45
|
|
|
$className = $this->fullEntityName($entity); |
46
|
|
|
|
47
|
|
|
// Fill in entity metadata |
48
|
|
|
$metadata = new \samsoncms\api\generator\metadata\GalleryMetadata($className); |
49
|
|
|
|
50
|
|
|
$metadata->parentClassName = $this->entityName($structureRow[Navigation::F_NAME]); |
|
|
|
|
51
|
|
|
$metadata->entity = $entity; |
52
|
|
|
// Prepend Entity name |
53
|
|
|
$metadata->entity = $metadata->parentClassName . $metadata->entity; |
54
|
|
|
$metadata->realName = $fieldRow[Field::F_IDENTIFIER]; |
55
|
|
|
$metadata->fieldID = $fieldID; |
|
|
|
|
56
|
|
|
$metadata->parentID = $navigationID; |
57
|
|
|
|
58
|
|
|
// Store metadata by entity identifier |
59
|
|
|
$metadataCollection[$navigationID] = $metadata; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $metadataCollection; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
//[PHPCOMPRESSOR(remove,end)] |