PodsData::table PHP Method

table() public method

Handle tables like they are Pods (for traversal in select/build)
public table ( array | string $table, string $object = '' )
$table array | string
$object string
    public function table($table, $object = '')
    {
        global $wpdb;
        if (!is_array($table)) {
            $object_type = '';
            if ($wpdb->users == $table) {
                $object_type = 'user';
            } elseif ($wpdb->posts == $table) {
                $object_type = 'post_type';
            } elseif ($wpdb->terms == $table) {
                $object_type = 'taxonomy';
            } elseif ($wpdb->options == $table) {
                $object_type = 'settings';
            }
        }
        if (!empty($object_type)) {
            $table = $this->api->get_table_info($object_type, $object);
        }
        if (!empty($table) && is_array($table)) {
            $table['id'] = pods_var('id', $table['pod'], 0, null, true);
            $table['name'] = pods_var('name', $table['pod'], $table['object_type'], null, true);
            $table['type'] = pods_var_raw('type', $table['pod'], $table['object_type'], null, true);
            $default_storage = 'meta';
            if ('taxonomy' == $table['type'] && !function_exists('get_term_meta')) {
                $default_storage = 'none';
            }
            $table['storage'] = pods_var_raw('storage', $table['pod'], $default_storage, null, true);
            $table['fields'] = pods_var_raw('fields', $table['pod'], array());
            $table['object_fields'] = pods_var_raw('object_fields', $table['pod'], $this->api->get_wp_object_fields($table['object_type']), null, true);
            $this->pod_data = $table;
            $this->pod_id = $this->pod_data['id'];
            $this->pod = $this->pod_data['name'];
            $this->fields = $this->pod_data['fields'];
            if (isset($this->pod_data['select'])) {
                $this->select = $this->pod_data['select'];
            }
            if (isset($this->pod_data['table'])) {
                $this->table = $this->pod_data['table'];
            }
            if (isset($this->pod_data['join'])) {
                $this->join = $this->pod_data['join'];
            }
            if (isset($this->pod_data['field_id'])) {
                $this->field_id = $this->pod_data['field_id'];
            }
            if (isset($this->pod_data['field_index'])) {
                $this->field_index = $this->pod_data['field_index'];
            }
            if (isset($this->pod_data['field_slug'])) {
                $this->field_slug = $this->pod_data['field_slug'];
            }
            if (isset($this->pod_data['where'])) {
                $this->where = $this->pod_data['where'];
            }
            if (isset($this->pod_data['where_default'])) {
                $this->where_default = $this->pod_data['where_default'];
            }
            if (isset($this->pod_data['orderby'])) {
                $this->orderby = $this->pod_data['orderby'];
            }
        }
    }