简体   繁体   English

TYPO3自定义扩展注册数据库中的印象

[英]TYPO3 custom extension register impressions in database

I wrote an extension that picks randomly a defined number of images with link (banners) to display. 我写了一个扩展程序,它随机选择要显示的带有链接(横幅)的定义数量的图像。

I want to count the times they get displayed (impressions). 我想计算它们显示的次数(展示次数)。 That is, after the random function has made its pick i'd like to increase the database field impressions for the selected entries by one. 也就是说,在随机函数选择之后,我想将所选条目的数据库字段impressions增加一倍。

This is the pertinent part of the domain repository: 这是域存储库的相关部分:

public function findPartnerList($entryNumber = 6) {

    $entries = $this->createQuery()->execute()->count();
    $offset = mt_rand(0, max(0, ($entries - $entryNumber)));

    ... // code refers to a class that picks random

    $result = $query->execute();

   ... // field:impressions should get increased by one for all uid's in $result

    return $results;
}
  • I don't know how to handle the object yielded by $query->execute() ... 我不知道如何处理$query->execute()产生的对象...
  • I don't know how to write to the database ... 我不知道如何写数据库...
  • I don't know how to increase the field impressions by one ... 我不知道如何将现场impressions增加一...

Basically you should perform manipulations to your domain objects in the controller only and not in the repository - the ORM layer is just the connection between the OOP domain model world and your database. 基本上,您应该只在控制器中而不是在存储库中对域对象执行操作-ORM层只是OOP域模型世界与数据库之间的连接。

In WhateverController for instance... 例如在WhateverController中...

...
/** @var Whatever[] $items */
$items = $this->whateverRepository->findPartnerList();
foreach ($items as $item) {
    $item->setImpressions($item->getImpressions() + 1);
    $this->whateverRepository->update($item);
}
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM