domos/schema

尚未准备公开使用。domos/schema 是用 PHP 编写的 domos 房地产数据方案的参考实现。

0.0.8 2024-09-05 12:32 UTC

This package is auto-updated.

Last update: 2024-09-05 12:33:39 UTC


README

logo
domos/schema

© 2024 domos GmbH

警告

尚未准备公开使用。API 接口可能会更改。


domos/schema 是用 PHP 编写的 domos 房地产数据方案的参考实现。

composer install domos/schema

方案文档

目录

  1. 简介
  2. 在 WordPress 中访问房地产数据
  3. 核心模型
  4. 位置模型
  5. 媒体模型
  6. 财务模型
  7. 网络展示模型
  8. 实用模型

简介

本文件提供了关于 PHP 实现的房地产数据方案的全面概述。该方案旨在表示房地产的各种方面,包括建筑、可出租空间、位置、媒体资产和网络展示。它使用现代 PHP 功能,如类型属性、枚举和接口,以创建一个强大且灵活的系统,用于管理房地产数据。

在 WordPress 中访问房地产数据

EstatePost 类提供了一个连接房地产数据方案和 WordPress 的桥梁,允许您检索和显示存储为 WordPress 文章的房地产信息。本节解释了如何使用 EstatePost 类在 WordPress 环境中访问房地产数据,重点关注与网站建设相关的任务。

查找房地产

通过外部 ID 获取房地产

$externalId = 'your-external-id';
$estatePost = EstatePost::find($externalId);

if ($estatePost !== null) {
    $estate = $estatePost->data; // This is an instance of SchemaImmo\Estate
    echo "Estate Name: " . $estate->name;
    echo "Estate Address: " . $estate->address->street . " " . $estate->address->number;
} else {
    echo "Estate not found";
}

在 WordPress 模板中访问房地产数据

在 WordPress 模板中处理房地产数据时,您可以使用 EstatePost::fromPost() 方法从当前文章获取房地产数据

global $post;

if ($post->post_type === EstatePost::POST_TYPE) {
    $estatePost = EstatePost::fromPost($post);
    $estate = $estatePost->data;

    // Now you can access all the estate data
    echo "<h1>{$estate->name}</h1>";
    echo "<p>Address: {$estate->address->street} {$estate->address->number}, {$estate->address->city}</p>";

    if ($estate->media->thumbnail) {
        echo "<img src='{$estate->media->thumbnail->src}' alt='{$estate->media->thumbnail->alt}'>";
    }

    // Display features
    if (!empty($estate->features)) {
        echo "<h2>Features:</h2><ul>";
        foreach ($estate->features as $feature => $value) {
            echo "<li>{$feature}: {$value}</li>";
        }
        echo "</ul>";
    }

    // Display rentable spaces
    if (!empty($estate->buildings)) {
        foreach ($estate->buildings as $building) {
            echo "<h2>Building: {$building->name}</h2>";
            foreach ($building->rentables as $rentable) {
                echo "<h3>Rentable Space: {$rentable->name}</h3>";
                echo "<p>Area: {$rentable->area} sqm</p>";
                echo "<p>Price: {$rentable->price->base->amount} {$rentable->price->base->currency->value}</p>";
            }
        }
    }
}

以下示例演示了如何在 WordPress 模板中访问和显示房地产数据的各个方面。

查找多个房地产

要获取多个房地产,您可以使用 WordPress 的 WP_Query 类与 EstatePost::fromPost() 结合使用

$args = array(
    'post_type' => EstatePost::POST_TYPE,
    'posts_per_page' => 10,
    // Add any other query arguments as needed
);

$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        $estatePost = EstatePost::fromPost($query->post);
        $estate = $estatePost->data;

        // Display estate information
        echo "<h2>{$estate->name}</h2>";
        echo "<p>{$estate->address->city}, {$estate->address->country}</p>";
        // Add more fields as needed
    }
    wp_reset_postdata();
} else {
    echo "No estates found";
}

以下示例演示了如何查询多个房地产并显示每个房地产的基本信息。

房地产管理操作(内部使用)

以下操作主要用于内部使用和数据管理

  • 创建新的房地产EstatePost::create($externalId, $estateData)
  • 更新现有房地产EstatePost::update($externalId, $updatedEstateData)
  • 删除房地产EstatePost::delete($externalId)
  • 查找不必要的房地产EstatePost::findUnneeded($activeIds)

应谨慎使用这些方法,通常在管理界面或后台过程中使用,而不是在面向公众的网站代码中使用。

通过使用 EstatePost 类,您可以无缝地将房地产数据方案与 WordPress 集成,以便在 WordPress 网站上轻松检索和显示复杂的房地产信息。

核心模型

房地产

Estate 类是表示房地产的核心模型。

用法

$estate = new Estate(
    id: '123',
    slug: 'sample-estate',
    name: 'Sample Estate',
    address: new Address(
        street: 'Main St',
        number: '123',
        postal_code: '12345',
        city: 'Sample City',
        country: 'US'
    )
);
$arrayRepresentation = $estate->toArray();

建筑

Building 类表示房地产内的特定建筑。

用法

$building = new Building(
    id: 'B1',
    name: 'Building 1',
    area: 1000.0,
    media: new Media()
);
$arrayRepresentation = $building->toArray();

可出租空间

Rentable 类表示可在建筑内出租或出售的空间。

用法

$rentable = new Rentable(
    id: 'R1',
    name: 'Office Space 1',
    area: 100.0,
    transaction_type: TransactionType::Rent,
    price: new Price(
        base: new Money(1000.0, Currency::Euro)
    )
);
$arrayRepresentation = $rentable->toArray();

位置模型

地址

Address 类表示物理地址。

用法

$address = new Address(
    street: 'Main St',
    number: '123',
    postal_code: '12345',
    city: 'Sample City',
    country: 'US'
);
$arrayRepresentation = $address->toArray();

坐标

Coordinates 类表示地理坐标。

用法

$coordinates = new Coordinates(
    latitude: 40.7128,
    longitude: -74.0060
);
$arrayRepresentation = $coordinates->toArray();

位置

Location 类表示房产的位置,包括附近地点。

用法

$location = new Location();
$location->places[] = new Place(
    type: Place\Type::from('restaurant'),
    name: 'Sample Restaurant',
    coordinates: new Coordinates(40.7128, -74.0060)
);
$arrayRepresentation = $location->toArray();

媒体模型

图像

Image 类表示图像资产。

用法

$image = new Image();
$image->src = 'https://example.com/image.jpg';
$image->alt = 'Sample Image';
$arrayRepresentation = $image->toArray();

媒体

Media 类表示房产的媒体资产集合。

用法

$media = new Media();
$media->thumbnail = new Image();
$media->thumbnail->src = 'https://example.com/thumbnail.jpg';
$arrayRepresentation = $media->toArray();

视频

Video 类表示视频资产。

用法

$video = new Video(
    type: Video\Type::Embed,
    thumbnail_url: 'https://example.com/video_thumbnail.jpg'
);
$arrayRepresentation = $video->toArray();

扫描

Scan 类表示3D扫描或虚拟游览。

用法

$scan = new Scan(
    type: Scan\Type::Embed,
    provider: 'Matterport'
);
$arrayRepresentation = $scan->toArray();

摄像头流

CameraFeed 类表示实时摄像头流。

用法

$cameraFeed = new CameraFeed(
    type: CameraFeed\Type::Embed,
    provider: 'Sample Provider'
);
$arrayRepresentation = $cameraFeed->toArray();

财务模型

金钱

Money 类表示货币价值。

用法

$money = new Money(
    amount: 1000.0,
    currency: Currency::Euro
);
$arrayRepresentation = $money->toArray();

价格

Price 类表示可出租空间的定价。

用法

$price = new Price(
    base: new Money(1000.0, Currency::Euro),
    extra_costs: new Money(100.0, Currency::Euro)
);
$arrayRepresentation = $price->toArray();

网络展示模型

网络展示

WebExpose 类表示基于网页的房产展示结构。

用法

$webExpose = new WebExpose();
$webExpose->sidebar_features = ['feature1', 'feature2'];
$webExpose->blocks[] = new TextBlock('Sample text content');
$arrayRepresentation = $webExpose->toArray();

Block 类是网页展示中各种类型内容块的抽象基类。

使用方法(以 TextBlock 为例)

$block = new TextBlock(
    text: 'Sample text content',
    id: 'block1'
);
$arrayRepresentation = $block->toArray();

实用模型

联系

Contact 类表示联系信息。

用法

$contact = new Contact(
    name: 'John Doe',
    email: 'john@example.com',
    phone: '+1234567890'
);
$arrayRepresentation = $contact->toArray();

认证

Certifications 类表示房产的各种认证。

用法

$certifications = new Certifications();
$certifications->dgnb = DGNBCertification::Gold;
$certifications->co2_neutral = true;
$arrayRepresentation = $certifications->toArray();