/** * match columns together with the csv data based on the data passed */ private function _match_columns_to_insert() { // we're going through all of the selected value in each dropdown when importing foreach ($this->_match as $csv_column_number => $column_in_user_table) { // Reduce matching twice the same column if ($this->_is_column_matched($column_in_user_table)) { continue; } // Ignore `nomatch` columns if ($column_in_user_table == 'nomatch') { continue; } // Check if maybe it's a new field preg_match($this->_regex_new_field, $column_in_user_table, $maybe_newfield); if (!empty($maybe_newfield) && in_array($maybe_newfield[1], array('date', 'input'))) { // TODO need to change to WJ_Field I guess when Marco is done moving the files // saving a new custom field $custom_field = new WJ_Field(); $custom_field->set(array('name' => $maybe_newfield[2], 'type' => $maybe_newfield[1], 'required' => false, 'settings' => array('label' => $maybe_newfield[2], 'date_type' => 'year_month_day', 'is_default_today' => 0, 'date_order' => 'mm/dd/yyyy'))); $custom_field->save(); // this is the column name in the database so this is where we need to import that field $column_in_user_table = $custom_field->user_column_name(); $this->_match[$csv_column_number] = $column_in_user_table; } // keep the match of CSV column number to column key in our database // not sure why do we trim the column key ... $this->_data_to_insert[$csv_column_number] = trim($column_in_user_table); // this column is the email column, let's keep track of it for later validation etc.. if ($column_in_user_table == 'email') { $this->_email_key = $csv_column_number; } } $this->_set_custom_fields(); // if the status column is not matched, we make sure that we have an entry for the status column so that we default it to some value on import if (!in_array('status', $this->_data_to_insert)) { $this->_data_to_insert['status'] = 'status'; } }
function wysija_form_manage_field() { $response = array('result' => true, 'error' => null); // get data $data = $this->_wysija_form_get_data(); $form_id = (int) $_REQUEST['form_id']; // check for required fields if (!isset($data['type']) || isset($data['type']) && strlen(trim($data['type'])) === 0) { $response['error'] = __('You need to select a type for this field', WYSIJA); $response['result'] = false; } if (!isset($data['name']) || isset($data['name']) && strlen(trim($data['name'])) === 0) { $response['error'] = __('You need to specify a name for this field', WYSIJA); $response['result'] = false; } // only proceed if there is no error if ($response['error'] === null) { $is_required = isset($data['params']['required']) ? WJ_Utils::to_bool($data['params']['required']) : false; if (isset($data['field_id']) && (int) $data['field_id'] > 0) { // it's an update $custom_field = WJ_Field::get($data['field_id']); if ($custom_field !== NULL) { $data['params'] = array_merge($custom_field->settings, $data['params']); // update fields $custom_field->name = $data['name']; $custom_field->type = $data['type']; $custom_field->required = $is_required; $custom_field->settings = $data['params']; $custom_field->save(); } else { // throw error if field does not exist $response['error'] = __('This field does not exist', WYSIJA); $response['result'] = false; } } else { // create new custom field $custom_field = new WJ_Field(); $custom_field->set(array('name' => $data['name'], 'type' => $data['type'], 'required' => $is_required, 'settings' => $data['params'])); $custom_field->save(); } if ($response['error'] === null) { $helper_form_engine = WYSIJA::get('form_engine', 'helper'); // need to update each block instance of this custom field $block = $helper_form_engine->refresh_custom_field($form_id, array('name' => $data['name'], 'field' => $custom_field->user_column_name(), 'type' => $data['type'], 'required' => $is_required, 'settings' => $data['params'])); // render editor toolbar & templates $response['data'] = array('toolbar' => base64_encode($helper_form_engine->render_editor_toolbar()), 'templates' => base64_encode($helper_form_engine->render_editor_templates())); if ($block !== null) { // refresh block using this custom field in the current form $block_template = $helper_form_engine->render_editor_template($block); if ($block_template !== null) { $response['data']['block'] = base64_encode($block_template); } } } } return $response; }