Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
+188
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Components\Database\SqlQuery\SelectQuery;
|
||||
use Xentral\Modules\SuperSearch\Exception\FormatterFailureException;
|
||||
use Xentral\Modules\SuperSearch\Exception\InvalidReturnTypeException;
|
||||
use Xentral\Modules\SuperSearch\Exception\SuperSearchExceptionInterface;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Collection\ItemFormatterCollection;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexIdentifier;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexItem;
|
||||
|
||||
abstract class AbstractBulkIndexDatabaseProvider implements
|
||||
SearchIndexProviderInterface,
|
||||
BulkIndexProviderInterface,
|
||||
ItemIndexProviderInterface,
|
||||
DiffIndexProviderInterface
|
||||
{
|
||||
/** @var Database $db */
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @param Database $database
|
||||
*/
|
||||
public function __construct(Database $database)
|
||||
{
|
||||
$this->db = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectQuery $query
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function configureBaseQuery(SelectQuery $query);
|
||||
|
||||
/**
|
||||
* @param SelectQuery $baseQuery
|
||||
* @param int|string $indexId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function configureItemQuery(SelectQuery $baseQuery, $indexId);
|
||||
|
||||
/**
|
||||
* @param SelectQuery $baseQuery
|
||||
* @param DateTimeInterface $since
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since);
|
||||
|
||||
/**
|
||||
* @param SelectQuery $baseQuery
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function configureCountQuery(SelectQuery $baseQuery);
|
||||
|
||||
/**
|
||||
* @return Closure
|
||||
*/
|
||||
abstract protected function getRowFormatter();
|
||||
|
||||
/**
|
||||
* @return int Anzahl der IndexItems die in einem Durchlauf geschrieben werden
|
||||
*/
|
||||
public function getBulkSize()
|
||||
{
|
||||
return 20000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IndexIdentifier $identifier
|
||||
*
|
||||
* @throws InvalidReturnTypeException
|
||||
*
|
||||
* @return IndexItem|null
|
||||
*/
|
||||
public function getItem(IndexIdentifier $identifier)
|
||||
{
|
||||
$select = $this->db->select();
|
||||
$this->configureBaseQuery($select);
|
||||
$this->configureItemQuery($select, $identifier->getId());
|
||||
|
||||
$row = $this->db->fetchRow(
|
||||
$select->getStatement(),
|
||||
$select->getBindValues()
|
||||
);
|
||||
|
||||
if (empty($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Formatter aufrufen
|
||||
$formatter = $this->getRowFormatter();
|
||||
$item = $formatter($row);
|
||||
} catch (SuperSearchExceptionInterface $exception) {
|
||||
throw new FormatterFailureException(
|
||||
sprintf('Formatter failed. Row data: %s', var_export($row, true)),
|
||||
$exception->getCode(),
|
||||
$exception
|
||||
);
|
||||
}
|
||||
|
||||
// Prüfen ob Formatter den richtigen Typ zurückliefert
|
||||
if (!$item instanceof IndexItem) {
|
||||
$itemType = gettype($item);
|
||||
if ($itemType === 'object') {
|
||||
$itemType = get_class($item);
|
||||
}
|
||||
throw new InvalidReturnTypeException(sprintf(
|
||||
'"%s::getRowFormatter()" returned invalid type. Required type "%s". Returned type "%s".',
|
||||
get_class($this),
|
||||
IndexItem::class,
|
||||
$itemType
|
||||
));
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getItemsSince(DateTimeInterface $since)
|
||||
{
|
||||
$select = $this->db->select();
|
||||
$this->configureBaseQuery($select);
|
||||
$this->configureSinceQuery($select, $since);
|
||||
|
||||
$callback = $this->getRowFormatter();
|
||||
$data = $this->db->fetchAll(
|
||||
$select->getStatement(),
|
||||
$select->getBindValues()
|
||||
);
|
||||
|
||||
return new ItemFormatterCollection($data, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTotalCount()
|
||||
{
|
||||
$select = $this->db->select();
|
||||
$this->configureBaseQuery($select);
|
||||
$select->resetCols();
|
||||
$this->configureCountQuery($select);
|
||||
|
||||
return (int)$this->db->fetchValue(
|
||||
$select->getStatement(),
|
||||
$select->getBindValues()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
* @param int $count
|
||||
*
|
||||
* @throws InvalidReturnTypeException
|
||||
* @throws Exception
|
||||
*
|
||||
* @return ItemFormatterCollection
|
||||
*/
|
||||
public function getBulkItems($offset, $count)
|
||||
{
|
||||
$select = $this->db->select();
|
||||
$this->configureBaseQuery($select);
|
||||
|
||||
$select->offset($offset);
|
||||
$select->limit($count);
|
||||
|
||||
$callback = $this->getRowFormatter();
|
||||
$data = $this->db->fetchAll(
|
||||
$select->getStatement(),
|
||||
$select->getBindValues()
|
||||
);
|
||||
|
||||
return new ItemFormatterCollection($data, $callback);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?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 AddressProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'adresse';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'addresses';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Adressen';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'a.id',
|
||||
'a.projekt',
|
||||
'a.name',
|
||||
'a.abteilung',
|
||||
'a.unterabteilung',
|
||||
'a.ansprechpartner',
|
||||
'a.strasse',
|
||||
'a.ort',
|
||||
'a.plz',
|
||||
'a.adresszusatz',
|
||||
'a.telefon',
|
||||
'a.telefax',
|
||||
'a.mobil',
|
||||
'a.email',
|
||||
'a.ustid',
|
||||
'a.kundennummer',
|
||||
'a.lieferantennummer',
|
||||
'a.mitarbeiternummer',
|
||||
])
|
||||
->from('adresse AS a')
|
||||
->where('a.geloescht = ?', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'];
|
||||
$title = $row['name'];
|
||||
$link = sprintf('index.php?module=adresse&action=edit&id=%d', $row['id']);
|
||||
$data = new IndexData($title, $link, $projectId);
|
||||
if (!empty($row['kundennummer'])) {
|
||||
$data->addAdditionalInfo(sprintf('Kunde %s', $row['kundennummer']));
|
||||
}
|
||||
if (!empty($row['lieferantennummer'])) {
|
||||
$data->addAdditionalInfo(sprintf('Lieferant %s', $row['lieferantennummer']));
|
||||
}
|
||||
if (!empty($row['mitarbeiternummer'])) {
|
||||
$data->addAdditionalInfo(sprintf('Mitarbeiter %s', $row['mitarbeiternummer']));
|
||||
}
|
||||
|
||||
$data->addSearchWord($row['name']);
|
||||
$data->addSearchWord($row['abteilung']);
|
||||
$data->addSearchWord($row['unterabteilung']);
|
||||
$data->addSearchWord($row['ansprechpartner']);
|
||||
$data->addSearchWord($row['strasse']);
|
||||
$data->addSearchWord($row['ort']);
|
||||
$data->addSearchWord($row['plz']);
|
||||
$data->addSearchWord($row['adresszusatz']);
|
||||
$data->addSearchWord($row['telefon']);
|
||||
$data->addSearchWord($row['telefax']);
|
||||
$data->addSearchWord($row['mobil']);
|
||||
$data->addSearchWord($row['email']);
|
||||
$data->addSearchWord($row['ustid']);
|
||||
$data->addSearchWord($row['kundennummer']);
|
||||
$data->addSearchWord($row['lieferantennummer']);
|
||||
$data->addSearchWord($row['mitarbeiternummer']);
|
||||
|
||||
$identifier = new IndexIdentifier('addresses', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use Appstore;
|
||||
use Exception;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Collection\ItemFormatterCollection;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexData;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexIdentifier;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexItem;
|
||||
|
||||
final class AppProvider implements FullIndexProviderInterface, ItemIndexProviderInterface
|
||||
{
|
||||
/** @var Appstore $appstore */
|
||||
private $appstore;
|
||||
|
||||
/**
|
||||
* @param Appstore $appstore
|
||||
*/
|
||||
public function __construct(Appstore $appstore)
|
||||
{
|
||||
$this->appstore = $appstore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'appstore';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'apps';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Apps';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getItem(IndexIdentifier $identifier)
|
||||
{
|
||||
$moduleKey = $identifier->getId();
|
||||
$modules = $this->appstore->BuildModuleList();
|
||||
if (!isset($modules[$moduleKey])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$formatter = $this->getRowFormatter();
|
||||
|
||||
return $formatter($modules[$moduleKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAllItems()
|
||||
{
|
||||
$callback = $this->getRowFormatter();
|
||||
|
||||
$modules = $this->appstore->BuildModuleList();
|
||||
unset($modules['appstore_extern']);
|
||||
|
||||
// Module ohne Link entfernen
|
||||
foreach ($modules as $moduleName => $moduleData) {
|
||||
if (empty($moduleData['module_link'])) {
|
||||
unset($modules[$moduleName]);
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemFormatterCollection($modules, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRowFormatter()
|
||||
{
|
||||
return static function (array $module) {
|
||||
$projectId = 0;
|
||||
$data = new IndexData($module['title'], $module['module_link'], $projectId);
|
||||
$data->addSearchWord($module['title']);
|
||||
$data->addSearchWord(html_entity_decode($module['title']));
|
||||
$data->addSearchWord($module['description']);
|
||||
$data->addSearchWord($module['category']);
|
||||
$identifier = new IndexIdentifier('apps', $module['key']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?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 ArticleProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'artikel';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'articles';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Artikel';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'a.id',
|
||||
'a.projekt',
|
||||
'a.nummer',
|
||||
'a.name_de',
|
||||
'a.kurztext_de',
|
||||
'a.herstellernummer',
|
||||
'a.ean',
|
||||
])
|
||||
->from('artikel AS a')
|
||||
->where('a.geloescht = ?', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'];
|
||||
$link = sprintf('index.php?module=artikel&action=edit&id=%d', $row['id']);
|
||||
|
||||
$data = new IndexData($row['nummer'], $link, $projectId);
|
||||
$data->setSubTitle($row['name_de']);
|
||||
$data->addSearchWord($row['nummer']);
|
||||
$data->addSearchWord($row['name_de']);
|
||||
$data->addSearchWord($row['kurztext_de']);
|
||||
$data->addSearchWord($row['herstellernummer']);
|
||||
$data->addSearchWord($row['ean']);
|
||||
|
||||
$identifier = new IndexIdentifier('articles', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Collection\ItemFormatterCollection;
|
||||
|
||||
interface BulkIndexProviderInterface extends SearchIndexProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns a range of the index items
|
||||
*
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return ItemFormatterCollection
|
||||
*/
|
||||
public function getBulkItems($start, $limit);
|
||||
|
||||
/**
|
||||
* Returns the number of items to process in one transaction
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBulkSize();
|
||||
|
||||
/**
|
||||
* Returns the total count for all items
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCount();
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?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 CreditNoteProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'gutschrift';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'creditnotes';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Gutschriften';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'gs.id',
|
||||
'gs.projekt',
|
||||
'gs.status',
|
||||
'gs.datum',
|
||||
'gs.belegnr',
|
||||
'gs.rechnung',
|
||||
'gs.name',
|
||||
'gs.kundennummer',
|
||||
'gs.internebemerkung',
|
||||
'gs.ihrebestellnummer',
|
||||
'gs.soll',
|
||||
'gs.zahlungsstatus',
|
||||
'gs.waehrung',
|
||||
])
|
||||
->from('gutschrift AS gs')
|
||||
->where('gs.belegnr != ?', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureItemQuery(SelectQuery $baseQuery, $indexId)
|
||||
{
|
||||
$baseQuery->where('gs.id = ?', (int)$indexId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureCountQuery(SelectQuery $baseQuery)
|
||||
{
|
||||
$baseQuery->cols(['COUNT(gs.id)' => 'total_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since)
|
||||
{
|
||||
$baseQuery->where('gs.logdatei > ?', $since->format('Y-m-d H:m:i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRowFormatter()
|
||||
{
|
||||
return static function (array $row) {
|
||||
|
||||
$projectId = (int)$row['projekt'];
|
||||
$rechnungsDatum = date('d.m.Y', strtotime($row['datum']));
|
||||
$title = $row['belegnr'];
|
||||
$link = sprintf('index.php?module=gutschrift&action=edit&id=%d', $row['id']);
|
||||
|
||||
$data = new IndexData($title, $link, $projectId);
|
||||
$data->setSubTitle($row['name']);
|
||||
$data->addAdditionalInfo($rechnungsDatum);
|
||||
$data->addAdditionalInfo(ucfirst($row['status']));
|
||||
$data->addAdditionalInfo(sprintf('%s %s', number_format($row['soll'], 2, ',', '.'), $row['waehrung']));
|
||||
|
||||
$data->addSearchWord('gutschrift');
|
||||
$data->addSearchWord($row['belegnr']);
|
||||
$data->addSearchWord($row['rechnung']);
|
||||
$data->addSearchWord($row['status']);
|
||||
$data->addSearchWord($row['name']);
|
||||
$data->addSearchWord($row['kundennummer']);
|
||||
$data->addSearchWord($row['internebemerkung']);
|
||||
$data->addSearchWord($row['ihrebestellnummer']);
|
||||
|
||||
$identifier = new IndexIdentifier('creditnotes', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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 DeliveryNoteProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'lieferschein';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'deliverynote';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Lieferscheine';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'l.id',
|
||||
'l.projekt',
|
||||
'l.datum',
|
||||
'l.belegnr',
|
||||
'l.status',
|
||||
'l.name',
|
||||
'l.kundennummer',
|
||||
'l.internebezeichnung'
|
||||
])
|
||||
->from('lieferschein AS l')
|
||||
->where('l.belegnr != ?', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureItemQuery(SelectQuery $baseQuery, $indexId)
|
||||
{
|
||||
$baseQuery->where('l.id = ?', (int)$indexId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureCountQuery(SelectQuery $baseQuery)
|
||||
{
|
||||
$baseQuery->cols(['COUNT(l.id)' => 'total_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since)
|
||||
{
|
||||
$baseQuery->where('l.logdatei > ?', $since->format('Y-m-d H:m:i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRowFormatter()
|
||||
{
|
||||
return static function (array $row) {
|
||||
|
||||
$projectId = (int)$row['projekt'];
|
||||
$lieferscheinDatum = date('d.m.Y', strtotime($row['datum']));
|
||||
$title = $row['belegnr'];
|
||||
$link = sprintf('index.php?module=lieferschein&action=edit&id=%d', $row['id']);
|
||||
|
||||
$data = new IndexData($title, $link, $projectId);
|
||||
$data->addSearchWord('lieferschein');
|
||||
$data->addSearchWord($row['belegnr']);
|
||||
$data->addSearchWord($row['name']);
|
||||
$data->addSearchWord($row['kundennummer']);
|
||||
$data->addSearchWord($row['internebezeichnung']);
|
||||
|
||||
$data->setSubTitle($row['name']);
|
||||
|
||||
$data->addAdditionalInfo($lieferscheinDatum);
|
||||
$data->addAdditionalInfo($row['status']);
|
||||
|
||||
|
||||
$identifier = new IndexIdentifier('deliverynote', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Collection\ItemFormatterCollection;
|
||||
|
||||
interface DiffIndexProviderInterface extends SearchIndexProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns index items that were changed or created since the passed date time
|
||||
*
|
||||
* @param DateTimeInterface $since
|
||||
*
|
||||
* @return ItemFormatterCollection
|
||||
*/
|
||||
public function getItemsSince(DateTimeInterface $since);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Collection\ItemFormatterCollection;
|
||||
|
||||
interface FullIndexProviderInterface extends SearchIndexProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns all items; No sectioning, just all items
|
||||
*
|
||||
* Use BulkIndexProviderInterface for large datasets instead
|
||||
*
|
||||
* @return ItemFormatterCollection
|
||||
*/
|
||||
public function getAllItems();
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?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 InvoiceProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'rechnung';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'invoices';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Rechnungen';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'r.id',
|
||||
'r.projekt',
|
||||
'r.datum',
|
||||
'r.belegnr',
|
||||
'r.auftrag',
|
||||
'r.name',
|
||||
'r.kundennummer',
|
||||
'r.internebemerkung',
|
||||
'r.ihrebestellnummer',
|
||||
'r.soll',
|
||||
'r.zahlungsstatus',
|
||||
'r.waehrung',
|
||||
])
|
||||
->from('rechnung AS r')
|
||||
->where('r.belegnr != ?', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureItemQuery(SelectQuery $baseQuery, $indexId)
|
||||
{
|
||||
$baseQuery->where('r.id = ?', (int)$indexId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureCountQuery(SelectQuery $baseQuery)
|
||||
{
|
||||
$baseQuery->cols(['COUNT(r.id)' => 'total_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since)
|
||||
{
|
||||
$baseQuery->where('r.logdatei > ?', $since->format('Y-m-d H:m:i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRowFormatter()
|
||||
{
|
||||
return static function (array $row) {
|
||||
|
||||
$projectId = (int)$row['projekt'];
|
||||
$rechnungsDatum = date('d.m.Y', strtotime($row['datum']));
|
||||
$title = $row['belegnr'];
|
||||
$link = sprintf('index.php?module=rechnung&action=edit&id=%d', $row['id']);
|
||||
|
||||
$data = new IndexData($title, $link, $projectId);
|
||||
$data->setSubTitle($row['name']);
|
||||
$data->addAdditionalInfo($rechnungsDatum);
|
||||
$data->addAdditionalInfo(ucfirst($row['zahlungsstatus']));
|
||||
$data->addAdditionalInfo(sprintf('%s %s', number_format($row['soll'], 2, ',', '.'), $row['waehrung']));
|
||||
|
||||
$data->addSearchWord('rechnung');
|
||||
$data->addSearchWord($row['belegnr']);
|
||||
$data->addSearchWord($row['auftrag']);
|
||||
$data->addSearchWord($row['name']);
|
||||
$data->addSearchWord($row['kundennummer']);
|
||||
$data->addSearchWord($row['internebemerkung']);
|
||||
$data->addSearchWord($row['ihrebestellnummer']);
|
||||
|
||||
$identifier = new IndexIdentifier('invoices', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexIdentifier;
|
||||
use Xentral\Modules\SuperSearch\SearchIndex\Data\IndexItem;
|
||||
|
||||
interface ItemIndexProviderInterface extends SearchIndexProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns a single item for writing into the search index
|
||||
*
|
||||
* @param IndexIdentifier $identifier
|
||||
*
|
||||
* @return IndexItem|null
|
||||
*/
|
||||
public function getItem(IndexIdentifier $identifier);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?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 OrderProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'auftrag';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'orders';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Aufträge';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'a.id',
|
||||
'a.projekt',
|
||||
'a.datum',
|
||||
'a.belegnr',
|
||||
'a.internet',
|
||||
'a.angebot', // Angebotsnummer
|
||||
'a.status',
|
||||
'a.name',
|
||||
'a.kundennummer',
|
||||
'a.internebezeichnung',
|
||||
'a.ihrebestellnummer',
|
||||
'a.gesamtsumme',
|
||||
'a.waehrung',
|
||||
])
|
||||
->from('auftrag 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=auftrag&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('auftrag');
|
||||
$data->addSearchWord($row['belegnr']);
|
||||
$data->addSearchWord($row['internet']);
|
||||
$data->addSearchWord($row['angebot']);
|
||||
$data->addSearchWord($row['name']);
|
||||
$data->addSearchWord($row['kundennummer']);
|
||||
$data->addSearchWord($row['internebezeichnung']);
|
||||
$data->addSearchWord($row['ihrebestellnummer']);
|
||||
|
||||
$identifier = new IndexIdentifier('orders', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\SuperSearch\SearchIndex\Provider;
|
||||
|
||||
interface SearchIndexProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return string Nur Kleinbuchstaben erlaubt
|
||||
*/
|
||||
public function getIndexName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIndexTitle();
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getModuleName();
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?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 TrackingNumberProvider extends AbstractBulkIndexDatabaseProvider
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
return 'lieferschein';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexName()
|
||||
{
|
||||
return 'trackingnumber';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIndexTitle()
|
||||
{
|
||||
return 'Trackingnummer';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureBaseQuery(SelectQuery $query)
|
||||
{
|
||||
$query
|
||||
->cols([
|
||||
'v.id',
|
||||
'v.tracking',
|
||||
'v.lieferschein',
|
||||
'v.projekt',
|
||||
'v.versendet_am'
|
||||
])
|
||||
->from('versand AS v')
|
||||
->where('v.tracking != ?', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureItemQuery(SelectQuery $baseQuery, $indexId)
|
||||
{
|
||||
$baseQuery->where('v.id = ?', (int)$indexId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureCountQuery(SelectQuery $baseQuery)
|
||||
{
|
||||
$baseQuery->cols(['COUNT(v.id)' => 'total_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configureSinceQuery(SelectQuery $baseQuery, DateTimeInterface $since)
|
||||
{
|
||||
$baseQuery->where('v.versendet_am > ?', $since->format('Y-m-d H:m:i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRowFormatter()
|
||||
{
|
||||
return static function (array $row) {
|
||||
|
||||
$projectId = (int)$row['projekt'];
|
||||
$versandDatum = date('d.m.Y', strtotime($row['versendet_am']));
|
||||
$title = $row['tracking'];
|
||||
$link = sprintf('index.php?module=lieferschein&action=edit&id=%d', $row['lieferschein']);
|
||||
|
||||
$data = new IndexData($title, $link, $projectId);
|
||||
$data->addSearchWord('trackingnummer');
|
||||
$data->addSearchWord($row['tracking']);
|
||||
|
||||
$data->setSubTitle('');
|
||||
|
||||
$data->addAdditionalInfo('Versendet: '.$versandDatum);
|
||||
|
||||
$identifier = new IndexIdentifier('trackingnumber', (int)$row['id']);
|
||||
|
||||
return new IndexItem($identifier, $data);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user