Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created August 16, 2012 14:07
Show Gist options
  • Save objectivehtml/3370357 to your computer and use it in GitHub Desktop.
Save objectivehtml/3370357 to your computer and use it in GitHub Desktop.
<?php
public function settings()
{
$this->EE->cp->set_right_nav(array(
'&larr; Back to Schemas' => $this->cp_url('schemas'),
));
$fields = array(
'settings' => array(
'title' => 'Import Settings',
'attributes' => array(
'class' => 'mainTable padTable',
'border' => 0,
'cellpadding' => 0,
'cellspacing' => 0
),
'wrapper' => 'div',
'fields' => array(
'id' => array(
'label' => 'ID',
'description' => 'Since you can save multiple variations of settings to import, your must give a unique identifier for these settings.',
'type' => 'input'
),
'channel' => array(
'label' => 'Channel',
'description' => 'This is the channel where your data will be imported.',
'type' => 'select',
'settings' => array(
'options' => 'CHANNEL_DROPDOWN'
)
),
'gmap_field' => array(
'label' => 'Map Field',
'description' => 'This is the name of Google Maps for ExpressionEngine fieldtype to store your data.',
'type' => 'select',
'settings' => array(
'options' => 'FIELD_DROPDOWN'
)
),
'geocode_fields' => array(
'label' => 'Geocode Fields',
'description' => 'This field is used to define the channel fields and column(s) in the .CSV you wish to use for geocoding. The fields are used to prevent existing entries from getting geocoded unnecessarily. The .csv fields are what are actually used to create the address string.',
'type' => 'matrix',
'settings' => array(
'columns' => array(
1 => array(
'name' => 'field_name',
'title' => 'Channel Field Name'
),
0 => array(
'name' => 'column_name',
'title' => 'CSV Column Name'
),
),
'attributes' => array(
'class' => 'mainTable padTable',
'border' => 0,
'cellpadding' => 0,
'cellspacing' => 0
)
)
),
'author_id' => array(
'label' => 'Author ID',
'description' => 'This is the author id that will be assigned to the imported entries.',
'type' => 'input'
),
'channel_fields' => array(
'label' => 'Channel Fields',
'description' => 'Use this field to pair up your channel fields with the columns in the .csv file. Be sure to make sure the names are an exact match.',
'id' => 'field_map_fields',
'type' => 'matrix',
'settings' => array(
'columns' => array(
0 => array(
'name' => 'field_name',
'title' => 'Channel Field Name'
),
1 => array(
'name' => 'column_name',
'title' => 'CSV Column Name'
)
),
'attributes' => array(
'class' => 'mainTable padTable',
'border' => 0,
'cellpadding' => 0,
'cellspacing' => 0
)
)
),
'group_by' => array(
'label' => 'Group By',
'description' => 'This is the unique identifier for each row that will group your entries together. If there are duplicate rows, define the column in the .csv that stores the ID.',
'type' => 'input'
),
'duplicate_fields' => array(
'label' => 'Duplicate Data',
'description' => 'Defines fields and columns used to check for duplicate data. If multiple fields are defined, that must all match an entry to trigger an update vs. creating a new record.',
'id' => 'field_map_fields',
'type' => 'matrix',
'settings' => array(
'columns' => array(
0 => array(
'name' => 'field_name',
'title' => 'Channel Field Name'
),
1 => array(
'name' => 'column_name',
'title' => 'CSV Column Name'
)
),
'attributes' => array(
'class' => 'mainTable padTable',
'border' => 0,
'cellpadding' => 0,
'cellspacing' => 0
)
)
),
'status' => array(
'label' => 'Status',
'description' => 'This is the status that is assigned to each entry that is imported.',
'type' => 'input'
),
'title' => array(
'label' => 'Title',
'description' => 'This is the title assigned to each entry. It can be a combination of channel fields, or a static string.',
'type' => 'input'
),
'title_prefix' => array(
'label' => 'Title Prefix',
'description' => 'This is the prefix that gets prepended to the title if the title contains only numbers.',
),
'category_column' => array(
'label' => 'Category Column',
'description' => 'This is the name of the column that stores the category.',
'type' => 'input'
),
'category_column_type' => array(
'label' => 'Category Column Type',
'description' => 'This is the type of data stored in the cateogry column.',
'type' => 'select',
'settings' => array(
'options' => array(
'cat_name' => 'Category Name',
'cat_url_title' => 'Category URL Title',
'cat_id' => 'Category ID',
)
)
),
'create_category' => array(
'label' => 'Create Category',
'description' => 'Creates a category if one doesn\'t exist based on the category column type. Be sure your category is stored as a Category Name for the best results.',
'type' => 'select',
'settings' => array(
'options' => array(
'false' => 'No',
'true' => 'Yes',
)
)
),
'category_group_id' => array(
'label' => 'Category Group ID',
'description' => 'If creating a category, you need to define a group_id to which it will be assigned.',
'type' => 'input'
),
)
)
);
$id = $this->EE->input->get('id');
if($id)
{
$data = (array) $this->EE->data_import_model->get_setting($id);
}
else
{
$data = array();
}
$this->EE->interface_builder->data = $data;
$this->EE->interface_builder->add_fieldsets($fields);
$vars = array(
'return' => $this->cp_url('schemas'),
'header' => $this->EE->input->get('id') ? 'Edit' : 'New',
'action' => $this->EE->google_maps->base_url().'?ACT='.$this->EE->channel_data->get_action_id('Gmap_mcp', 'import_csv_save_settings_action'),
'interface_builder' => $this->EE->theme_loader->theme_url().'third_party/gmap/javascript/InterfaceBuilder.js',
'settings' => $this->EE->interface_builder->fieldsets(),
'schema_id' => $this->EE->input->get('id') ? $this->EE->input->get('id') : NULL
);
return $this->EE->load->view('csv_import', $vars, TRUE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment