本文整理汇总了PHP中FrmField::destroy方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmField::destroy方法的具体用法?PHP FrmField::destroy怎么用?PHP FrmField::destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmField
的用法示例。
在下文中一共展示了FrmField::destroy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
public static function destroy()
{
check_ajax_referer('frm_ajax', 'nonce');
$field_id = FrmAppHelper::get_post_param('field_id', 0, 'absint');
FrmField::destroy($field_id);
wp_die();
}
示例2: import_xml_forms
public static function import_xml_forms($forms, $imported)
{
// Keep track of repeating sections and child forms that are imported
$repeat_fields = $child_forms_missing_parent = array();
foreach ($forms as $item) {
$form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
// if template, allow to edit if form keys match, otherwise, creation date must also match
$edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
if (!$form['is_template']) {
$edit_query['created_at'] = $form['created_at'];
}
$old_parent_form_id = self::maybe_replace_parent_form_id($imported['forms'], $form['parent_form_id']);
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
$this_form = FrmForm::getAll($edit_query, '', 1);
unset($edit_query);
if (!empty($this_form)) {
$old_id = $form_id = $this_form->id;
FrmForm::update($form_id, $form);
$imported['updated']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'updated';
$form_fields = FrmField::get_all_for_form($form_id);
$old_fields = array();
foreach ($form_fields as $f) {
$old_fields[$f->id] = $f;
$old_fields[$f->field_key] = $f->id;
unset($f);
}
$form_fields = $old_fields;
unset($old_fields);
} else {
$old_id = false;
//form does not exist, so create it
$form_id = FrmForm::create($form);
if ($form_id) {
$imported['imported']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'imported';
self::track_child_forms_missing_parent((int) $form_id, $old_parent_form_id, $child_forms_missing_parent);
}
}
self::import_xml_fields($item->field, $form_id, $this_form, $form_fields, $imported, $repeat_fields);
// Delete any fields attached to this form that were not included in the template
if (isset($form_fields) && !empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
FrmField::destroy($field->id);
}
unset($field);
}
unset($form_fields);
}
// Update field ids/keys to new ones
do_action('frm_after_duplicate_form', $form_id, $form, array('old_id' => $old_id));
$imported['forms'][(int) $item->id] = $form_id;
// Send pre 2.0 form options through function that creates actions
self::migrate_form_settings_to_actions($form['options'], $form_id, $imported, $switch = true);
unset($form, $item);
}
self::update_repeat_field_options($repeat_fields, $imported['forms']);
self::update_child_form_parents($child_forms_missing_parent, $imported['forms']);
return $imported;
}
示例3: import_xml_forms
public static function import_xml_forms($forms, $imported)
{
// Keep track of repeating sections that are created
$repeat_fields = array();
foreach ($forms as $item) {
$form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
// if template, allow to edit if form keys match, otherwise, creation date must also match
$edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
if (!$form['is_template']) {
$edit_query['created_at'] = $form['created_at'];
}
if (!empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']])) {
// replace the old parent id with the new one
$form['parent_form_id'] = $imported['forms'][$form['parent_form_id']];
}
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
$this_form = FrmForm::getAll($edit_query, '', 1);
unset($edit_query);
if (!empty($this_form)) {
$old_id = $form_id = $this_form->id;
FrmForm::update($form_id, $form);
$imported['updated']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'updated';
$form_fields = FrmField::get_all_for_form($form_id);
$old_fields = array();
foreach ($form_fields as $f) {
$old_fields[$f->id] = $f;
$old_fields[$f->field_key] = $f->id;
unset($f);
}
$form_fields = $old_fields;
unset($old_fields);
} else {
$old_id = false;
//form does not exist, so create it
$form_id = FrmForm::create($form);
if ($form_id) {
$imported['imported']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'imported';
}
}
foreach ($item->field as $field) {
$f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'hidden', 'password', 'tag', 'image'))) {
if (count($f['default_value']) === 1) {
$f['default_value'] = '[' . reset($f['default_value']) . ']';
} else {
$f['default_value'] = reset($f['default_value']);
}
}
$f = apply_filters('frm_duplicated_field', $f);
if (!empty($this_form)) {
// check for field to edit by field id
if (isset($form_fields[$f['id']])) {
FrmField::update($f['id'], $f);
$imported['updated']['fields']++;
unset($form_fields[$f['id']]);
//unset old field key
if (isset($form_fields[$f['field_key']])) {
unset($form_fields[$f['field_key']]);
}
} else {
if (isset($form_fields[$f['field_key']])) {
// check for field to edit by field key
unset($f['id']);
FrmField::update($form_fields[$f['field_key']], $f);
$imported['updated']['fields']++;
unset($form_fields[$form_fields[$f['field_key']]]);
//unset old field id
unset($form_fields[$f['field_key']]);
//unset old field key
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
// if no matching field id or key in this form, create the field
$imported['imported']['fields']++;
}
}
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
$imported['imported']['fields']++;
}
unset($field, $new_id);
}
// Delete any fields attached to this form that were not included in the template
if (isset($form_fields) && !empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
FrmField::destroy($field->id);
}
//.........这里部分代码省略.........
示例4: import_xml_forms
public static function import_xml_forms($forms, $imported)
{
$frm_form = new FrmForm();
$frm_field = new FrmField();
foreach ($forms as $item) {
$form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
// if template, allow to edit if form keys match, otherwise, creation date must also match
$edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
if (!$form['is_template']) {
$edit_query['created_at'] = $form['created_at'];
}
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
$this_form = $frm_form->getAll($edit_query, '', 1);
unset($edit_query);
if (!empty($this_form)) {
$form_id = $this_form->id;
$frm_form->update($form_id, $form);
$imported['updated']['forms']++;
$form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
$old_fields = array();
foreach ($form_fields as $f) {
$old_fields[$f->id] = $f;
$old_fields[$f->field_key] = $f->id;
unset($f);
}
$form_fields = $old_fields;
unset($old_fields);
} else {
//form does not exist, so create it
if ($form_id = $frm_form->create($form)) {
$imported['imported']['forms']++;
}
}
foreach ($item->field as $field) {
$f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag'))) {
if (count($f['default_value']) === 1) {
$f['default_value'] = '[' . reset($f['default_value']) . ']';
} else {
$f['default_value'] = reset($f['default_value']);
}
}
$f = apply_filters('frm_duplicated_field', $f);
if ($this_form) {
// check for field to edit by field id
if (isset($form_fields[$f['id']])) {
$frm_field->update($f['id'], $f);
$imported['updated']['fields']++;
unset($form_fields[$f['id']]);
//unset old field key
if (isset($form_fields[$f['field_key']])) {
unset($form_fields[$f['field_key']]);
}
} else {
if (isset($form_fields[$f['field_key']])) {
// check for field to edit by field key
unset($f['id']);
$frm_field->update($form_fields[$f['field_key']], $f);
$imported['updated']['fields']++;
unset($form_fields[$form_fields[$f['field_key']]]);
//unset old field id
unset($form_fields[$f['field_key']]);
//unset old field key
} else {
if ($frm_field->create($f)) {
// if no matching field id or key in this form, create the field
$imported['imported']['fields']++;
}
}
}
} else {
if ($frm_field->create($f)) {
$imported['imported']['fields']++;
}
}
unset($field);
}
// Delete any fields attached to this form that were not included in the template
if (isset($form_fields) && !empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
$frm_field->destroy($field->id);
}
unset($field);
}
unset($form_fields);
}
// Update field ids/keys to new ones
do_action('frm_after_duplicate_form', $form_id, $form);
$imported['forms'][(int) $item->id] = $form_id;
unset($form);
unset($item);
}
unset($frm_form);
unset($frm_field);
return $imported;
}
示例5: auto_add_end_section_fields
/**
* Automatically add end section fields if they don't exist (2.0 migration)
* @since 2.0
*
* @param boolean $reset_fields
*/
public static function auto_add_end_section_fields($form, $fields, &$reset_fields)
{
if (empty($fields)) {
return;
}
$end_section_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars('end_divider', $form->id));
$open = $prev_order = false;
$add_order = 0;
$last_field = false;
foreach ($fields as $field) {
if ($prev_order === $field->field_order) {
$add_order++;
}
if ($add_order) {
$reset_fields = true;
$field->field_order = $field->field_order + $add_order;
FrmField::update($field->id, array('field_order' => $field->field_order));
}
switch ($field->type) {
case 'divider':
// create an end section if open
self::maybe_create_end_section($open, $reset_fields, $add_order, $end_section_values, $field, 'move');
// mark it open for the next end section
$open = true;
break;
case 'break':
self::maybe_create_end_section($open, $reset_fields, $add_order, $end_section_values, $field, 'move');
break;
case 'end_divider':
if (!$open) {
// the section isn't open, so this is an extra field that needs to be removed
FrmField::destroy($field->id);
$reset_fields = true;
}
// There is already an end section here, so there is no need to create one
$open = false;
}
$prev_order = $field->field_order;
$last_field = $field;
unset($field);
}
self::maybe_create_end_section($open, $reset_fields, $add_order, $end_section_values, $last_field);
}
示例6: delete_removed_fields
/**
* Delete any fields attached to this form that were not included in the template
*/
private static function delete_removed_fields($form_fields)
{
if (!empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
FrmField::destroy($field->id);
}
unset($field);
}
}
}
示例7: destroy
public static function destroy()
{
$frm_field = new FrmField();
$field_id = $frm_field->destroy($_POST['field_id']);
die;
}