Microweber\Providers\FieldsManager::get PHP Метод

get() публичный Метод

public get ( $table, $id, $return_full = false, $field_for = false, $debug = false, $field_type = false, $for_session = false )
    public function get($table, $id = 0, $return_full = false, $field_for = false, $debug = false, $field_type = false, $for_session = false)
    {
        $params = array();
        $no_cache = false;
        $table_assoc_name = false;
        // $id = intval ( $id );
        if (is_string($table)) {
            $params = $params2 = parse_params($table);
            if (!is_array($params2) or is_array($params2) and count($params2) < 2) {
                $id = trim($id);
                $table = $this->app->database_manager->escape_string($table);
                if ($table != false) {
                    $table_assoc_name = $this->app->database_manager->assoc_table_name($table);
                } else {
                    $table_assoc_name = 'MW_ANY_TABLE';
                }
                if ($table_assoc_name == false) {
                    $table_assoc_name = $this->app->database_manager->assoc_table_name($table_assoc_name);
                }
                $params['rel_type'] = $table_assoc_name;
            } else {
                $params = $params2;
            }
        } elseif (is_array($table)) {
            $params = $table;
        }
        $params = $this->unify_params($params);
        if (!isset($table_assoc_name)) {
            if (isset($params['for'])) {
                $params['rel_type'] = $table_assoc_name = $this->app->database_manager->assoc_table_name($params['for']);
            }
        } else {
            // $params['rel_type'] = $table_assoc_name;
        }
        if (isset($params['debug'])) {
            $debug = $params['debug'];
        }
        if (isset($params['for'])) {
            if (!isset($params['rel_type']) or $params['rel_type'] == false) {
                $params['for'] = $params['rel_type'];
            }
        }
        if (isset($params['for_id'])) {
            $params['rel_id'] = $id = $this->app->database_manager->escape_string($params['for_id']);
        }
        if (isset($params['field_type'])) {
            $params['type'] = $params['field_type'];
        }
        if (isset($params['field_value'])) {
            $params['value'] = $params['field_value'];
        }
        if (isset($params['no_cache'])) {
            $no_cache = $params['no_cache'];
        }
        if (isset($params['return_full'])) {
            $return_full = $params['return_full'];
        }
        if (isset($params['is_active']) and strtolower(trim($params['is_active'])) == 'any') {
        } elseif (isset($params['is_active']) and $params['is_active'] == 0) {
            $custom_field_is_active = 0;
        } else {
            $custom_field_is_active = 1;
        }
        $table_custom_field = $this->table;
        $params['table'] = $table_custom_field;
        if (isset($custom_field_is_active)) {
            $params['is_active'] = $custom_field_is_active;
        }
        if (strval($table_assoc_name) != '') {
            if ($field_for != false) {
                $field_for = trim($field_for);
                $field_for = $this->app->database_manager->escape_string($field_for);
                $params['name'] = $field_for;
            }
            if (isset($params['rel_type']) and $params['rel_type'] == 'MW_ANY_TABLE') {
                unset($params['rel_type']);
            }
            $sidq = '';
            if (intval($id) == 0 and $for_session != false) {
                if (is_admin() != false) {
                    $sid = mw()->user_manager->session_id();
                    $params['session_id'] = $sid;
                }
            }
            if ($id != 'all' and $id != 'any') {
                $id = $this->app->database_manager->escape_string($id);
                $params['rel_id'] = $id;
            }
        }
        if (isset($params['content'])) {
            unset($params['content']);
        }
        if (!isset($params['order_by']) and !isset($params['orderby'])) {
            $params['order_by'] = 'position asc';
        }
        if (empty($params)) {
            return false;
        }
        $q = $this->app->database_manager->get($params);
        if (!empty($q)) {
            $get_values = array();
            $fields = array();
            foreach ($q as $k => $v) {
                $get_values[] = $v['id'];
            }
            $vals = $this->get_values($get_values);
            foreach ($q as $k => $v) {
                if (isset($v['options']) and is_string($v['options'])) {
                    $v['options'] = $this->_decode_options($v['options']);
                }
                $default_values = $v;
                $default_values['values_plain'] = '';
                $default_values['value'] = '';
                $default_values['values'] = array();
                if (!empty($vals)) {
                    foreach ($vals as $val) {
                        if ($val['custom_field_id'] == $v['id']) {
                            $default_values['value'][] = $val['value'];
                            $default_values['values'][] = $val['value'];
                        }
                    }
                }
                if (!empty($default_values['value'])) {
                    $default_values['value_plain'] = implode(',', $default_values['value']);
                    if (count($default_values['value']) == 1) {
                        $default_values['value'] = reset($default_values['value']);
                    }
                } else {
                    $default_values['value'] = false;
                }
                $fields[$k] = $default_values;
            }
            $q = $fields;
        }
        if (isset($params['fields'])) {
            return $q;
        }
        if (!empty($q)) {
            $the_data_with_custom_field__stuff = array();
            if ($return_full == true) {
                $to_ret = array();
                $i = 1;
                foreach ($q as $it) {
                    $it = $this->decode_array_vals($it);
                    //  $it['type'] = $it['type'];
                    $it['position'] = $i;
                    if (isset($it['options']) and is_string($it['options'])) {
                        // $it['options'] = $this->_decode_options($it['options']);
                    }
                    $it['title'] = $it['name'];
                    $to_ret[] = $it;
                    ++$i;
                }
                return $to_ret;
            }
            $append_this = array();
            if (is_array($q) and !empty($q)) {
                foreach ($q as $q2) {
                    $i = 0;
                    $the_name = false;
                    $the_val = false;
                    foreach ($q2 as $cfk => $cfv) {
                        if ($cfk == 'name') {
                            $the_name = $cfv;
                        }
                        if ($cfk == 'value') {
                            $the_val = $cfv;
                        }
                        ++$i;
                    }
                    if ($the_name != false and $the_val !== null) {
                        if ($return_full == false) {
                            $the_name = strtolower($the_name);
                            $the_data_with_custom_field__stuff[$the_name] = $the_val;
                        } else {
                            $the_data_with_custom_field__stuff[$the_name] = $q2;
                        }
                    }
                }
            }
            $result = $the_data_with_custom_field__stuff;
            //$result = (array_change_key_case($result, CASE_LOWER));
            $result = $this->app->url_manager->replace_site_url_back($result);
            //
            return $result;
        }
        return $q;
    }