derhaeuptling/contao-immobilienscout24-import-bundle

Contao开源CMS的Immoscout24导入包

v3.0.0 2022-11-07 08:57 UTC

README

此包允许您将Immoscout24的房地产对象导入到您的Contao应用程序(4.8+)中,并以原生内容的形式显示。

警告:这是一个早期版本。可能缺少一些功能。使用时请自行承担风险。

如何开始

设置

  1. 安装此包并更新您的数据库。无需进一步配置。

    composer require derhaeuptling/contao-immobilienscout24-import-bundle
  2. 在后台添加至少一个 Immoscout24 账户 并输入您的API凭据。

  3. 设置一个cron作业,执行 immoscout24:sync 命令,或者自行运行以将API中的房地产对象导入到您的应用程序中。您可以将账户的ID或描述作为参数传递,仅同步此账户,或使用 --dry-run 仅查看将要更新的内容而不保存更改。使用选项 --purge 在之前完全清除数据库表和所有下载的文件。

  4. 我们使用Contao的虚拟文件系统功能。如果您还想调整下载附件的存储位置,只需将 immoscout24 目录挂载到另一个位置即可。有关此主题的更多信息,请参阅 Contao开发者文档

  5. 在您的主题中添加一个或多个Immoscout24模块,并在前端使用它

    • 房地产列表 显示房地产对象的列表。如果您想生成带有“阅读更多”链接的预告列表,请确保指定一个带有适当阅读器的“跳转”页面。

    • 房地产阅读器 根据URL参数(ID)显示单个房地产对象。

    • 可以通过使用过滤表达式单独限制列表项。
      一些过滤表达式示例

      • 按ID查找一个对象 realEstateId == 111111111
      • 按ID查找一些对象 realEstateId in [111111111,222222222,333333333]
      • 所有活动对象 state == STATUS_ACTIVE
      • 发布到主页频道的所有对象 'Homepage' in publishChannels
      • 具有空的API-Searchfield1的所有对象 apiSearchData1 != null
      • 标题字段中包含KEYWORD的所有对象 title matches "/KEYWORD/"
      • 组合过滤 'Homepage' in publishChannels && priceMarketingType == "Kauf"

模板和值

房地产列表包含大量字段 - 很可能您需要根据需要调整模板,只输出一些字段。为此,有一些方便的助手可用。

A) 房地产数据以 实体实例 的形式提供,您可以在模板中对其进行类型提示以获得IDE自动完成

  /** var Derhaeuptling\ContaoImmoscout24\Entity\RealEstate $realEstate */
  $realEstate

B) 您还可以获取所有 可用属性 的列表

  $this->attributes

  // array [name => label] of publicly accessible fields of the real estate objects
  // e.g. 'descriptionNote' that can be accessed via $realEstate->descriptionNote

C) 要 检索和格式化数据,您可以使用这些助手函数

  $this->hasData(RealEstate $realEstate, string $attribute) : bool
  // will return wether $realEstate holds data for the $attribute

  $this->getFormatted(RealEstate $realEstate, string $attribute) : string
  // will return the formatted value of $attribute - enumerations, dates and
  // booleans will resolved to a string representation based on the language
  // files

D) 如果您想自行解析枚举,您可以在 RealEstate 实体中找到所有公共常量。

某些枚举值可以多次出现。在这种情况下,它们被实现为二进制标志

  FLAG__TYPE_A = 1;
  FLAG__TYPE_B = 2;
  FLAG__TYPE_C = 4;
  FLAG__TYPE_D = 8;
  FLAG__TYPE_E = 16;

  // n-of-value selecting 'type A' and 'type E'
  $value = -(FLAG__TYPE_A | FLAG__TYPE_E); // = 17

请注意,标记的值以 负数 存储的,这样就可以很容易地将它们与常规枚举值区分开来。

附件

房地产对象可以有多个附件。注意:目前仅支持图像附件类型。

为了渲染附件(作为图像),您可以使用模板中提供的 getFigureFromAttachment() 函数。它允许通过第二个参数传入一个替代的图像大小

  $figure = $this->getFigureFromAttachment($realEstate->getTitlePictureAttachment());

  $figure = $this->getFigureFromAttachment(
      $realEstate->getTitlePictureAttachment(),
      $this->alternativeImageSize
  );

要输出 Figure,请将它的数据传递到您想要渲染的模板中。如果是传统的 image 模板,请确保在传递之前通过调用 getLegacyTemplateData() 函数扩展图像数据

  $this->insert('image', $titlePictureFigure->getLegacyTemplateData());

以下是完整示例,展示如何以容错的方式输出默认图像大小的标题图片

    <div>
        <h2>Title Picture</h2>
        <?php if(null !== ($titlePictureFigure = $this->getFigureFromAttachment($this->realEstate->getTitlePictureAttachment()))): ?>
            <?php $this->insert('image', $titlePictureFigure->getLegacyTemplateData()); ?>
        <?php else: ?>
            <span>There is no title picture.</span>
        <?php endif; ?>
    </div>