</nav>
</header>
+<form method="post" action="{link controller='DevtoolsProjectPipEntryList' id=$project->projectID pip=$pip}{/link}">
+ <section class="section">
+ <h2 class="sectionTitle">{lang}wcf.global.filter{/lang}</h2>
+
+ <dl>
+ <dt></dt>
+ <dd>
+ <input type="text" id="search" name="entryFilter" value="{$entryFilter}" placeholder="{lang}wcf.global.filter{/lang}" class="long">
+ </dd>
+ </dl>
+
+ <div class="formSubmit">
+ <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
+ {@SECURITY_TOKEN_INPUT_TAG}
+ </div>
+ </section>
+</form>
+
{hascontent}
<div class="paginationTop">
{content}
use wcf\system\devtools\pip\DevtoolsPip;
use wcf\system\devtools\pip\IDevtoolsPipEntryList;
use wcf\system\exception\IllegalLinkException;
+use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\StringUtil;
*/
public $endIndex = 0;
+ /**
+ * entry filter string
+ * @var string
+ */
+ public $entryFilter;
+
/**
* pip entry list
* @var IDevtoolsPipEntryList
*/
public $entryType;
+ /**
+ * @inheritDoc
+ */
+ public $forceCanonicalURL = true;
+
/**
* number of items shown per page
* @var integer
/**
* @inheritDoc
+ * @throws IllegalLinkException
*/
public function readParameters() {
parent::readParameters();
if ($this->entryType !== null) {
$this->linkParameters .= '&entryType=' . $this->entryType;
}
+
+ if (isset($_REQUEST['entryFilter'])) $this->entryFilter = StringUtil::trim($_REQUEST['entryFilter']);
+
+ if ($this->entryFilter !== null && $this->entryFilter !== '') {
+ $this->linkParameters .= '&entryFilter=' . $this->entryFilter;
+ }
+
+ $this->canonicalURL = LinkHandler::getInstance()->getLink('DevtoolsProjectPipEntryList', [
+ 'id' => $this->project->projectID,
+ ], $this->linkParameters);
}
/**
/** @var IDevtoolsPipEntryList entryList */
$this->entryList = $this->pipObject->getPip()->getEntryList();
+ if ($this->entryFilter !== null && $this->entryFilter !== '') {
+ $this->entryList->filterEntries($this->entryFilter);
+ }
+
$this->items = count($this->entryList->getEntries());
$this->pages = intval(ceil($this->items / $this->itemsPerPage));
WCF::getTPL()->assign([
'endIndex' => $this->endIndex,
+ 'entryFilter' => $this->entryFilter,
'entryList' => $this->entryList,
'entryType' => $this->entryType,
'items' => $this->items,
$this->entries[$id] = $entry;
}
+ /**
+ * @inheritDoc
+ */
+ public function filterEntries($filter) {
+ $filterType = gettype($filter);
+
+ switch ($filterType) {
+ case 'array':
+ $unknownFilters = array_diff(array_keys($filter), array_keys($this->keys));
+
+ if (!empty($unknownFilters)) {
+ throw new \InvalidArgumentException("Unknown filter" . (count($unknownFilters) > 1 ? 's' : '') . " '". implode(', ', $unknownFilters) ."'.");
+ }
+
+ $filteredEntries = [];
+ foreach ($this->entries as $id => $entry) {
+ foreach ($filter as $filterKey => $filterString) {
+ if (isset($entry[$filterKey]) && strpos($entry[$filterKey], $filterString) !== false) {
+ $filteredEntries[$id] = $entry;
+ }
+ }
+ }
+
+ $this->entries = $filteredEntries;
+
+ break;
+
+ case 'string':
+ $filteredEntries = [];
+ foreach ($this->entries as $id => $entry) {
+ foreach ($this->keys as $key => $label) {
+ if (isset($entry[$key]) && strpos($entry[$key], $filter) !== false) {
+ $filteredEntries[$id] = $entry;
+ }
+ }
+ }
+
+ $this->entries = $filteredEntries;
+
+ break;
+
+ default:
+ throw new \InvalidArgumentException("Cannot use '{$filterType}' to filter entries.");
+ }
+ }
+
/**
* @inheritDoc
*/
*/
public function addEntry($id, array $entry);
+ /**
+ * Internally filters the entries using the given filter.
+ * `getEntries()` will only return filter entries afterwards.
+ *
+ * This filter is applied to the elements currently in the list.
+ * Entries added afterwards are not affected by this filter.
+ *
+ * Applying a second filter will filter the pre-filtered entries.
+ *
+ * @param string|array $filter either a string that is used to search all entry elements or filter map `key => searchString`
+ */
+ public function filterEntries($filter);
+
/**
* Returns all entries in the list.
*