1 | <?php |
||
16 | class Export_EntryService extends BaseApplicationComponent implements IExportElementType |
||
17 | { |
||
18 | /** |
||
19 | * Return export template. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | 1 | public function getTemplate() |
|
27 | |||
28 | /** |
||
29 | * Get entry sections. |
||
30 | * |
||
31 | * @return array|bool |
||
32 | */ |
||
33 | 1 | public function getGroups() |
|
48 | |||
49 | /** |
||
50 | * Return entry fields. |
||
51 | * |
||
52 | * @param array $settings |
||
53 | * @param bool $reset |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | 2 | public function getFields(array $settings, $reset) |
|
58 | { |
||
59 | // Set criteria |
||
60 | 2 | $criteria = new \CDbCriteria(); |
|
61 | 2 | $criteria->condition = 'settings = :settings'; |
|
62 | 2 | $criteria->params = array( |
|
63 | 2 | ':settings' => JsonHelper::encode($settings), |
|
64 | ); |
||
65 | |||
66 | // Check if we have a map already |
||
67 | 2 | $stored = craft()->export->findMap($criteria); |
|
68 | |||
69 | 2 | if (!count($stored) || $reset) { |
|
70 | |||
71 | // Get section id |
||
72 | 1 | $section = $settings['elementvars']['section']; |
|
73 | |||
74 | // Get entrytype id(s) |
||
75 | 1 | $entrytype = $settings['elementvars']['entrytype']; |
|
76 | |||
77 | // If "All" |
||
78 | 1 | $entrytypes = empty($entrytype) ? craft()->sections->getEntryTypesBySectionId($section) : array(craft()->sections->getEntryTypeById($entrytype)); |
|
79 | |||
80 | // Create a nice field map |
||
81 | 1 | $fields = array(); |
|
82 | |||
83 | // With multiple or one entry type |
||
84 | 1 | foreach ($entrytypes as $entrytype) { |
|
85 | |||
86 | // Set the static fields for this type |
||
87 | $layout = array( |
||
88 | 1 | ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), |
|
89 | 1 | ExportModel::HandleTitle.'_'.$entrytype->id => array('name' => $entrytype->hasTitleField ? $entrytype->titleLabel : Craft::t('Title'), 'checked' => 1, 'entrytype' => $entrytype->id), |
|
90 | 1 | ExportModel::HandleSlug => array('name' => Craft::t('Slug'), 'checked' => 0), |
|
91 | 1 | ExportModel::HandleParent => array('name' => Craft::t('Parent'), 'checked' => 0), |
|
92 | 1 | ExportModel::HandleAncestors => array('name' => Craft::t('Ancestors'), 'checked' => 0), |
|
93 | 1 | ExportModel::HandleAuthor => array('name' => Craft::t('Author'), 'checked' => 0), |
|
94 | 1 | ExportModel::HandlePostDate => array('name' => Craft::t('Post Date'), 'checked' => 0), |
|
95 | 1 | ExportModel::HandleExpiryDate => array('name' => Craft::t('Expiry Date'), 'checked' => 0), |
|
96 | 1 | ExportModel::HandleEnabled => array('name' => Craft::t('Enabled'), 'checked' => 0), |
|
97 | 1 | ExportModel::HandleStatus => array('name' => Craft::t('Status'), 'checked' => 0), |
|
98 | 1 | ); |
|
99 | |||
100 | // Set the dynamic fields for this type |
||
101 | 1 | $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs(); |
|
102 | 1 | foreach ($tabs as $tab) { |
|
103 | 1 | $fieldData = array(); |
|
104 | 1 | foreach ($tab->getFields() as $field) { |
|
105 | 1 | $data = $field->getField(); |
|
106 | 1 | $fieldData[$data->handle] = array('name' => $data->name, 'checked' => 1, 'fieldtype' => $data->type); |
|
107 | 1 | } |
|
108 | 1 | $layout += $fieldData; |
|
109 | 1 | } |
|
110 | |||
111 | // Set the static fields also |
||
112 | 1 | $fields += $layout; |
|
113 | 1 | } |
|
114 | 1 | } else { |
|
115 | |||
116 | // Get the stored map |
||
117 | 1 | $fields = $stored->map; |
|
118 | } |
||
119 | |||
120 | // Return fields |
||
121 | 2 | return $fields; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * Set entry criteria. |
||
126 | * |
||
127 | * @param array $settings |
||
128 | * |
||
129 | * @return ElementCriteriaModel |
||
130 | */ |
||
131 | 1 | public function setCriteria(array $settings) |
|
147 | |||
148 | /** |
||
149 | * Get entry attributes. |
||
150 | * |
||
151 | * @param array $map |
||
152 | * @param BaseElementModel $element |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | 1 | public function getAttributes(array $map, BaseElementModel $element) |
|
193 | } |
||
194 |