-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Eigene Workflows einbinden
Wokflows erweitern Watson um zusätzliche Funktionen und Suchen.
Das nachfolgende Beispiel bindet eine Suche für eine Tabelle eines AddOns an.
Zunächst benötigt man einen Provider, diesen (hier StoreProvider.php) legt man im Lib-Ordner des eigenen oder des project-AddOns an.
Hier der Provider für ein Store-AddOn
namespace Watson\Workflows\Store;
use Watson\Foundation\SupportProvider;
use Watson\Foundation\Workflow;
class StoreProvider extends SupportProvider
{
/**
* Register the directory to search a translation file.
*
* @return string
*/
public function i18n()
{
return __DIR__;
}
/**
* Register the service provider.
*
* @return Workflow|array
*/
public function register()
{
if (\rex_addon::get('store')->isAvailable()) {
return $this->registerStoreSearch();
}
return [];
}
/**
* Register store search.
*
* @return Workflow
*/
public function registerStoreSearch()
{
return new StoreSearch();
}
}Die Suche für den Store wird in einer separaten Datei StoreSearch.php angelegt.
<?php
namespace Watson\Workflows\Store;
use Watson\Foundation\Command;
use Watson\Foundation\Documentation;
use Watson\Foundation\Result;
use Watson\Foundation\ResultEntry;
use Watson\Foundation\Watson;
use Watson\Foundation\Workflow;
class StoreSearch extends Workflow
{
/**
* Provide the commands of the search.
*
* @return array
*/
public function commands()
{
return ['st'];
}
/**
* @return Documentation
*/
public function documentation()
{
$documentation = new Documentation();
$documentation->setDescription(Watson::translate('watson_store_documentation_description'));
$documentation->setUsage('st keyword');
$documentation->setExample('st Phrase');
return $documentation;
}
/**
* Return array of registered page params.
*
* @return array
*/
public function registerPageParams()
{
return [];
}
/**
* Execute the command for the given Command.
*
* @param Command $command
*
* @return Result
*/
public function fire(Command $command)
{
$result = new Result();
$fields = ['text_1', 'teaser_1', 'name_1', 'price', 'updatedate', ];
$sql_query = '
SELECT *
FROM ' . Watson::getTable('store_products') . '
WHERE ' . $command->getSqlWhere($fields) . '
ORDER BY name_1';
$items = $this->getDatabaseResults($sql_query);
if (count($items))
{
$counter = 0;
foreach ($items as $item)
{
$url = Watson::getUrl(['page' => 'store/list_form', 'base_path' => 'store/products/products', 'id' => $item['id'], 'func' => 'edit']);
++$counter;
$entry = new ResultEntry();
if ($counter == 1)
{
$entry->setLegend('Store');
}
if (isset($item['name_1']))
{
$entry->setValue($item['name_1'] . '', '(' . $item['id'] . ')');
}
else
{
$entry->setValue($item['id']);
}
$entry->setDescription($item['price'] . ' € | ' . $item['updatedate']);
$entry->setIcon('watson-icon-yform');
$entry->setUrl($url);
$entry->setQuickLookUrl($url);
$result->addEntry($entry);
}
}
return $result;
}
}Tipps:
- Das Query wird per
$this->getDatabaseResults($sql_query);ausgelöst $entry->setQuickLookUrl($url);definiert die URL die zur Vorschau im Quickview verwendet wird.
In diesem Beispiel führt sie zur identischen URL wie das Suchergebnis. Alternativ kann man hier auch die URL zum Frontend hinterlegen.$entry->setValue()definiert den Ergebnistext. (HTML-Formatierung wird nicht unterstützt)$entry->setDescriptionzeigt die (kleine graue( Beschreibung an.
Um die Suche nun anmelden zu können, muss man den Provider registrieren. Das erfolgt in der boot.php des eigenen oder des project- AddOns über den Extenstionpoint WATSON_PROVIDER
function register_storesearch(rex_extension_point $ep)
{
$subject = $ep->getSubject();
$subject[] = 'Watson\Workflows\Store\StoreProvider';
return $subject;
}
rex_extension::register('WATSON_PROVIDER', 'register_storesearch', rex_extension::LATE); Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels