1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
<?php
namespace hji\common\utils;
class GFHelper
{
static public function gravityFormsExists()
{
return class_exists('\GFForms');
}
static function importGravityForm($file)
{
require_once(\GFCommon::get_base_path() . "/export.php");
return \GFExport::import_file($file);
}
static function getFormByTitle($title)
{
$forms = \GFFormsModel::get_forms(null, 'title');
foreach ($forms as $form)
{
if (trim($form->title) == $title)
{
return $form;
}
}
}
public static function getFieldValue($field_id, $form)
{
if ($field = \GFFormsModel::get_field($form, $field_id))
{
return \GFFormsModel::get_field_value($field);
}
}
public static function getFormsByKey($key)
{
$forms = \GFFormsModel::get_forms(null, 'id');
$list = array();
$result = array();
foreach ($forms as $form)
{
$list[$form->id] = $form;
}
$meta = \RGFormsModel::get_form_meta_by_id(array_keys($list));
foreach ($meta as $form)
{
if (isset($form['hji_form_key']) && stristr($form['hji_form_key'], $key . ':'))
{
$result[] = $form;
}
else if (isset($form['hji_form_key']) && $form['hji_form_key'] == $key)
{
$result[] = $form;
}
}
return $result;
}
public static function getFormsListByKey($key)
{
$forms = self::getFormsByKey($key);
$list = array();
if (!empty($forms))
{
foreach ($forms as $form)
{
$list[$form['id']] = $form['title'];
}
}
return $list;
}
public static function getFieldByKey($form, $fieldKey)
{
foreach ($form['fields'] as $field)
{
if (isset($field['hji_field_key']) && $field['hji_field_key'] == $fieldKey)
{
return $field;
}
}
}
}