Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
fix(sorts): simplify sorting registration
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Apr 29, 2018
1 parent 54b96ba commit e00d199
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion classes/hypeJunction/Lists/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ final public function getSearchFields() {

foreach ($classes as $class) {
if (!is_subclass_of($class, SearchFieldInterface::class)) {
throw new \InvalidParameterException($class . ' must implement ' . SearchFieldInterface::class);
throw new \InvalidArgumentException($class . ' must implement ' . SearchFieldInterface::class);
}

/* @var $class \hypeJunction\Lists\SearchFieldInterface */
Expand Down
14 changes: 7 additions & 7 deletions classes/hypeJunction/Lists/DefaultEntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public function getURL() {
*/
public function getSortOptions() {
return [
Alpha::id() => Alpha::class,
TimeCreated::id() => TimeCreated::class,
LastAction::id() => LastAction::class,
LikesCount::id() => LikesCount::class,
FriendCount::id() => FriendCount::class,
MemberCount::id() => MemberCount::class,
ResponsesCount::id() => ResponsesCount::class,
Alpha::class,
TimeCreated::class,
LastAction::class,
LikesCount::class,
FriendCount::class,
MemberCount::class,
ResponsesCount::class,
];
}

Expand Down
4 changes: 2 additions & 2 deletions classes/hypeJunction/Lists/EntityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EntityList extends Entities {
public function addSort($class, $direction = null) {

if (!is_subclass_of($class, SorterInterface::class)) {
throw new \InvalidParameterException($class . ' must implement ' . SorterInterface::class);
throw new \InvalidArgumentException($class . ' must implement ' . SorterInterface::class);
}

/* @var $class SorterInterface */
Expand Down Expand Up @@ -75,7 +75,7 @@ public function setSearchQuery($query = '') {
*/
public function addFilter($class, ElggEntity $target = null, array $params = []) {
if (!is_subclass_of($class, FilterInterface::class)) {
throw new \InvalidParameterException($class . ' must implement ' . FilterInterface::class);
throw new \InvalidArgumentException($class . ' must implement ' . FilterInterface::class);
}

/* @var $class FilterInterface */
Expand Down
9 changes: 8 additions & 1 deletion classes/hypeJunction/Lists/SearchFields/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace hypeJunction\Lists\SearchFields;

use hypeJunction\Lists\FilterInterface;

class Sort extends SearchField {

/**
Expand All @@ -22,7 +24,12 @@ public function getField() {
}

$sort_options_values = [];
foreach ($sort_options as $id =>$class) {
foreach ($sort_options as $class) {
if (!is_subclass_of($class, FilterInterface::class)) {
throw new \InvalidArgumentException($class . ' must implement ' . FilterInterface::class);
}

$id = $class::id();
foreach (['asc', 'desc'] as $direction) {
$sort_options_values["$id::$direction"] = elgg_echo("sort:{$this->collection->getType()}:{$id}::{$direction}");
}
Expand Down

0 comments on commit e00d199

Please sign in to comment.