Beispiel #1
0
    private function checkFieldList($par = '')
    {
        if (empty($this->class) && empty($this->fields)) {
            $field_id = 'r_field_id is NULL and ';
            if (is_array($this->parent_id)) {
                // Если несколько родителей
                $sql = '';
                while (list($num, $value) = each($this->parent_id)) {
                    $obj_id = is_array($value) ? $value['id'] : $value;
                    if (!empty($sql)) {
                        $sql .= ' OR ';
                    }
                    $sql .= ' r_parent_id = "' . $obj_id . '" ';
                }
                if (!empty($sql)) {
                    $sql = ' (' . $sql . ') and ';
                }
            } else {
                if (!empty($this->parent_id)) {
                    // Если это связь зависимости через depends()
                    if ($this->depends_link > 0 || $this->depends_link == 'all') {
                        $field_id = $this->depends_link == 'all' ? '' : 'r_field_id = "' . $this->depends_link . '" and ';
                        $sql = 'r_parent_id = "' . $this->parent_id . '" and ';
                    } else {
                        $sql = 'r_parent_id = "' . $this->parent_id . '" and ';
                    }
                } else {
                    if ($this->parent_id == 0 && $this->parent_id !== null) {
                        $sql = 'r_parent_id is NULL and ';
                    } else {
                        $sql = '';
                    }
                }
            }
            if ($this->find_page) {
                if (!empty($this->cur_lang_id) && !empty($this->cur_domain_id)) {
                    $sql .= ' lang_id = "' . $this->cur_lang_id . '" and domain_id = "' . $this->cur_domain_id . '" and ';
                }
                $sql .= ' p_obj_id = o_id and ';
                $table = ', <<pages>>';
            } else {
                $table = '';
            }
            $c = db::q('/* ' . $par . ' */SELECT c_id, c_sname
							FROM <<classes>>, <<objects>>, <<rels>>' . $table . '
							WHERE ' . $field_id . $sql . '
								r_children_id = o_id and
								o_to_trash = 0 and
								o_class_id = c_id and
								c_is_page = "' . $this->find_page . '"
							GROUP BY c_id;', records);
            $this->classesList = array();
            while (list($key, $val) = each($c)) {
                if (empty($key)) {
                    $this->class = ormClasses::get($val['c_id']);
                }
                $this->classesList[] = $val['c_sname'];
                $this->class_list[$val['c_id']] = $val['c_sname'];
            }
            // Создаем виртуальный класс, имееющий общие свойства классов из полученого списка
            //$this->class = 'virtual';
            $this->fields = ormClasses::getVirtual($this->classesList);
        }
    }