OpenXE/classes/Modules/SuperSearch/SearchIndex/Provider/OfferProvider.php

116 lines
3.1 KiB
PHP
Raw Normal View History

2021-05-21 08:49:41 +02:00
<?php
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
use DateTimeInterface;
use Xentral\Components\Database\SqlQuery\SelectQuery;
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexData;
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexIdentifier;
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexItem;
final class OfferProvider extends AbstractBulkIndexDatabaseProvider
{
/**
* @inheritDoc
*/
public function getModuleName()
{
return 'angebot';
}
/**
* @inheritDoc
*/
public function getIndexName()
{
return 'offers';
}
/**
* @inheritDoc
*/
public function getIndexTitle()
{
return 'Angebote';
}
/**
* @inheritDoc
*/
protected function configureBaseQuery(SelectQuery $query)
{
$query
->cols([
'a.id',
'a.projekt',
'a.datum',
'a.belegnr',
'a.auftrag', // Auftragsnummer
'a.status',
'a.name',
'a.kundennummer',
'a.internebezeichnung',
'a.anfrage',
'a.gesamtsumme',
'a.waehrung',
])
->from('angebot AS a')
->where('a.belegnr != ?', '');
}
/**
* @inheritDoc
*/
protected function configureItemQuery(SelectQuery $baseQuery, $indexId)
{
$baseQuery->where('a.id = ?', (int)$indexId);
}
/**
* @inheritDoc
*/
protected function configureCountQuery(SelectQuery $baseQuery)
{
$baseQuery->cols(['COUNT(a.id)' => 'total_count']);
}
/**
* @inheritDoc
*/
protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since)
{
$baseQuery->where('a.logdatei > ?', $since->format('Y-m-d H:m:i'));
}
/**
* @inheritDoc
*/
protected function getRowFormatter()
{
return static function (array $row) {
$projectId = (int)$row['projekt'];
$documentDate = date('d.m.Y', strtotime($row['datum']));
$title = $row['belegnr'];
$link = sprintf('index.php?module=angebot&action=edit&id=%d', $row['id']);
$data = new IndexData($title, $link, $projectId);
$data->setSubTitle($row['name']);
$data->addAdditionalInfo($documentDate);
$data->addAdditionalInfo(ucfirst($row['status']));
$data->addAdditionalInfo(number_format($row['gesamtsumme'], 2, ',', '.') . ' ' . $row['waehrung']);
$data->addSearchWord('angebot');
$data->addSearchWord($row['belegnr']);
$data->addSearchWord($row['auftrag']);
$data->addSearchWord($row['name']);
$data->addSearchWord($row['kundennummer']);
$data->addSearchWord($row['internebezeichnung']);
$data->addSearchWord($row['anfrage']);
$identifier = new IndexIdentifier('offers', (int)$row['id']);
return new IndexItem($identifier, $data);
};
}
}