1 | <?php |
||
16 | class Export_CategoryService extends BaseApplicationComponent implements IExportElementType |
||
17 | { |
||
18 | /** |
||
19 | * Return export template. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | 1 | public function getTemplate() |
|
27 | |||
28 | /** |
||
29 | * Get category groups. |
||
30 | * |
||
31 | * @return array|bool |
||
32 | */ |
||
33 | 1 | public function getGroups() |
|
38 | |||
39 | /** |
||
40 | * Return category fields. |
||
41 | * |
||
42 | * @param array $settings |
||
43 | * @param bool $reset |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | 2 | public function getFields(array $settings, $reset) |
|
48 | { |
||
49 | // Set criteria |
||
50 | 2 | $criteria = new \CDbCriteria(); |
|
51 | 2 | $criteria->condition = 'settings = :settings'; |
|
52 | 2 | $criteria->params = array( |
|
53 | 2 | ':settings' => JsonHelper::encode($settings), |
|
54 | ); |
||
55 | |||
56 | // Check if we have a map already |
||
57 | 2 | $stored = craft()->export->findMap($criteria); |
|
58 | |||
59 | 2 | if (!count($stored) || $reset) { |
|
60 | |||
61 | // Set the static fields for this type |
||
62 | $fields = array( |
||
63 | 1 | ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), |
|
64 | 1 | ExportModel::HandleTitle => array('name' => Craft::t('Title'), 'checked' => 1), |
|
65 | 1 | ExportModel::HandleSlug => array('name' => Craft::t('Slug'), 'checked' => 0), |
|
66 | 1 | ExportModel::HandleParent => array('name' => Craft::t('Parent'), 'checked' => 0), |
|
67 | 1 | ExportModel::HandleAncestors => array('name' => Craft::t('Ancestors'), 'checked' => 0), |
|
68 | 1 | ); |
|
69 | |||
70 | // Set the dynamic fields for this type |
||
71 | 1 | foreach (craft()->fields->getLayoutByType(ElementType::Category)->getFields() as $field) { |
|
72 | 1 | $data = $field->getField(); |
|
73 | 1 | $fields[$data->handle] = array('name' => $data->name, 'checked' => 1, 'fieldtype' => $data->type); |
|
74 | 1 | } |
|
75 | 1 | } else { |
|
76 | |||
77 | // Get the stored map |
||
78 | 1 | $fields = $stored->map; |
|
79 | } |
||
80 | |||
81 | // Return fields |
||
82 | 2 | return $fields; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Set entry criteria. |
||
87 | * |
||
88 | * @param array $settings |
||
89 | * |
||
90 | * @return ElementCriteriaModel |
||
91 | */ |
||
92 | 1 | public function setCriteria(array $settings) |
|
106 | |||
107 | /** |
||
108 | * Get category attributes. |
||
109 | * |
||
110 | * @param array $map |
||
111 | * @param BaseElementModel $element |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | 1 | public function getAttributes(array $map, BaseElementModel $element) |
|
145 | } |
||
146 |