/** * Saves an export map to the database. * * @param array $settings * @param array $map */ public function saveMap(array $settings, array $map) { // Unset non-map settings unset($settings['limit'], $settings['offset']); ksort($settings); // Set criteria $criteria = new \CDbCriteria(); $criteria->condition = 'settings = :settings'; $criteria->params = array(':settings' => JsonHelper::encode($settings)); // Check if we have a map already $mapRecord = Export_MapRecord::model()->find($criteria); if (!count($mapRecord) || $mapRecord->settings != $settings) { // Save settings and map to database $mapRecord = new Export_MapRecord(); $mapRecord->settings = $settings; } // Save new map to db $mapRecord->map = $map; $mapRecord->save(false); }
/** * Return entry fields. * * @param array $settings * @param bool $reset * * @return array */ public function getFields(array $settings, $reset) { // Set criteria $criteria = new \CDbCriteria(); $criteria->condition = 'settings = :settings'; $criteria->params = array(':settings' => JsonHelper::encode($settings)); // Check if we have a map already $stored = Export_MapRecord::model()->find($criteria); if (!count($stored) || $reset) { // Get section id $section = $settings['elementvars']['section']; // Get entrytype id(s) $entrytype = $settings['elementvars']['entrytype']; // If "All" if (empty($entrytype)) { // Get entrytype models $entrytypes = craft()->sections->getEntryTypesBySectionId($section); } else { // Get entrytype model $entrytypes = array(craft()->sections->getEntryTypeById($entrytype)); } // Create a nice field map $fields = array(); // With multiple or one entry type foreach ($entrytypes as $entrytype) { // Set the static fields for this type $layout = array(ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), ExportModel::HandleTitle . '_' . $entrytype->id => array('name' => $entrytype->hasTitleField ? $entrytype->titleLabel : Craft::t('Title'), 'checked' => 1, 'entrytype' => $entrytype->id), ExportModel::HandleSlug => array('name' => Craft::t('Slug'), 'checked' => 0), ExportModel::HandleParent => array('name' => Craft::t('Parent'), 'checked' => 0), ExportModel::HandleAncestors => array('name' => Craft::t('Ancestors'), 'checked' => 0), ExportModel::HandleAuthor => array('name' => Craft::t('Author'), 'checked' => 0), ExportModel::HandlePostDate => array('name' => Craft::t('Post Date'), 'checked' => 0), ExportModel::HandleExpiryDate => array('name' => Craft::t('Expiry Date'), 'checked' => 0), ExportModel::HandleEnabled => array('name' => Craft::t('Enabled'), 'checked' => 0), ExportModel::HandleStatus => array('name' => Craft::t('Status'), 'checked' => 0)); // Set the dynamic fields for this type $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs(); foreach ($tabs as $tab) { $fieldData = array(); foreach ($tab->getFields() as $field) { $data = $field->getField(); $fieldData[$data->handle] = array('name' => $data->name, 'checked' => 1); } $layout += $fieldData; } // Set the static fields also $fields += $layout; } } else { // Get the stored map $fields = $stored->map; } // Return fields return $fields; }
/** * Return user fields. * * @param array $settings * @param bool $reset * * @return array */ public function getFields(array $settings, $reset) { // Set criteria $criteria = new \CDbCriteria(); $criteria->condition = 'settings = :settings'; $criteria->params = array(':settings' => JsonHelper::encode($settings)); // Check if we have a map already $stored = Export_MapRecord::model()->find($criteria); if (!count($stored) || $reset) { // Set the static fields for this type $fields = array(ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), ExportModel::HandleUsername => array('name' => Craft::t('Username'), 'checked' => 1), ExportModel::HandleFirstName => array('name' => Craft::t('First Name'), 'checked' => 1), ExportModel::HandleLastName => array('name' => Craft::t('Last Name'), 'checked' => 1), ExportModel::HandleEmail => array('name' => Craft::t('Email'), 'checked' => 1), ExportModel::HandlePreferredLocale => array('name' => Craft::t('Preferred Locale'), 'checked' => 0), ExportModel::HandleWeekStartDay => array('name' => Craft::t('Week Start Day'), 'checked' => 0), ExportModel::HandleStatus => array('name' => Craft::t('Status'), 'checked' => 0), ExportModel::HandleLastLoginDate => array('name' => Craft::t('Last Login Date'), 'checked' => 0), ExportModel::HandleInvalidLoginCount => array('name' => Craft::t('Invalid Login Count'), 'checked' => 0), ExportModel::HandleLastInvalidLoginDate => array('name' => Craft::t('Last Invalid Login Date'), 'checked' => 0)); // Set the dynamic fields for this type foreach (craft()->fields->getLayoutByType(ElementType::User)->getFields() as $field) { $data = $field->getField(); $fields[$data->handle] = array('name' => $data->name, 'checked' => 1); } } else { // Get the stored map $fields = $stored->map; } // Return fields return $fields; }
/** * Return category fields. * * @param array $settings * @param bool $reset * * @return array */ public function getFields(array $settings, $reset) { // Set criteria $criteria = new \CDbCriteria(); $criteria->condition = 'settings = :settings'; $criteria->params = array(':settings' => JsonHelper::encode($settings)); // Check if we have a map already $stored = Export_MapRecord::model()->find($criteria); if (!count($stored) || $reset) { // Set the static fields for this type $fields = array(ExportModel::HandleId => array('name' => Craft::t('ID'), 'checked' => 0), ExportModel::HandleTitle => array('name' => Craft::t('Title'), 'checked' => 1), ExportModel::HandleSlug => array('name' => Craft::t('Slug'), 'checked' => 0), ExportModel::HandleParent => array('name' => Craft::t('Parent'), 'checked' => 0), ExportModel::HandleAncestors => array('name' => Craft::t('Ancestors'), 'checked' => 0)); // Set the dynamic fields for this type foreach (craft()->fields->getLayoutByType(ElementType::Category)->getFields() as $field) { $data = $field->getField(); $fields[$data->handle] = array('name' => $data->name, 'checked' => 1); } } else { // Get the stored map $fields = $stored->map; } // Return fields return $fields; }
/** * @codeCoverageIgnore * * @param \CDbCriteria $criteria * * @return Export_MapRecord|array|null */ public function findMap(\CDbCriteria $criteria) { return Export_MapRecord::model()->find($criteria); }