Skip to content

Commit

Permalink
Add Criterias
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Nov 4, 2022
1 parent e2b90b3 commit 78fdb07
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/Data/Query/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Generally, the operator is defined by the class type and the
* the value by getValue().
*/
interface Criteria {
interface Criteria
{
/**
* Get the value of the comparison.
*/
Expand Down
9 changes: 6 additions & 3 deletions src/Data/Query/Criteria/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
* An EndsWith criteria represents a search for values that
* the string representation of ends with a certain value.
*/
class EndsWith implements \LORIS\Data\Query\Criteria {
class EndsWith implements \LORIS\Data\Query\Criteria
{
/**
* Construct an EndsWith criteria
*
* @param mixed $suffix The suffix that values must end with
*/
public function __construct(private $suffix) {
public function __construct(private $suffix)
{
}

public function getValue() {
public function getValue()
{
return $this->suffix;
}
}
11 changes: 8 additions & 3 deletions src/Data/Query/Criteria/Equal.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<?php
namespace LORIS\Data\Query\Criteria;

use LORIS\Data\Query\Criteria;

/**
* An Equal criteria matches data which equals a given
* value.
*/
class Equal implements Criteria {
class Equal implements Criteria
{
/**
* Construct an Equal criteria.
*
* @param mixed $value The value that must be equal
*/
public function __construct(private $value) {}
public function __construct(private $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue() {
public function getValue()
{
return $this->value;
}
}
26 changes: 26 additions & 0 deletions src/Data/Query/Criteria/GreaterThan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace LORIS\Data\Query\Criteria;

use LORIS\Data\Query\Criteria;

/**
* A GreaterThan Criteria specifies that an item must be strictly
* > a given value.
*/
class GreaterThan implements Criteria
{
/**
* Construct a GreaterThan comparison
*/
public function __construct(protected $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->value;
}
}
26 changes: 26 additions & 0 deletions src/Data/Query/Criteria/GreaterThanOrEqual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace LORIS\Data\Query\Criteria;

use LORIS\Data\Query\Criteria;

/**
* A GreaterThanOrEqual criteria denotes a criteria that must
* be >= a given value.
*/
class GreaterThanOrEqual implements Criteria
{
/**
* Constructor
*/
public function __construct(protected $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->value;
}
}
30 changes: 30 additions & 0 deletions src/Data/Query/Criteria/In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* In represents a criteria specifying that the value must be
* in a given set of choices.
*/
class In implements \LORIS\Data\Query\Criteria
{
protected array $val;

/**
* Construct an In criteria.
*
* @param $val The set that the value must be in.
*/
public function __construct(...$val)
{
$this->val = $val;
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->val;
}
}
24 changes: 24 additions & 0 deletions src/Data/Query/Criteria/IsNull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* Criteria to compare if a value is null
*/
class IsNull implements \LORIS\Data\Query\Criteria
{
/**
* Constructor
*/
public function __construct()
{
}

/**
* Stub to implement Criteria interface
*/
public function getValue()
{
return null;
}
}
25 changes: 25 additions & 0 deletions src/Data/Query/Criteria/LessThan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* Criteria to specify that a given item must be strictly <
* a comparison value.
*/
class LessThan implements \LORIS\Data\Query\Criteria
{
/**
* Constructor
*/
public function __construct(protected $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->value;
}
}
27 changes: 27 additions & 0 deletions src/Data/Query/Criteria/LessThanOrEqual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* A Criteria to determine that a DictionaryItem must be <= a
* given value
*/
class LessThanOrEqual implements \LORIS\Data\Query\Criteria
{
/**
* Constructor
*
* @param mixed $value The comparison value
*/
public function __construct(protected $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->value;
}
}
27 changes: 27 additions & 0 deletions src/Data/Query/Criteria/NotEqual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace LORIS\Data\Query\Criteria;

use LORIS\Data\Query\Criteria;

/**
* A NotEqual Criteria specifies that the value should be compared
* against not being a given value.
*/
class NotEqual implements Criteria
{
/**
* Construct a NotEqual criteria
*/
public function __construct(protected $value)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->value;
}
}
25 changes: 25 additions & 0 deletions src/Data/Query/Criteria/NotNull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* A Criteria to specify querying for items that must not be
* null
*/
class NotNull implements \LORIS\Data\Query\Criteria
{
/**
* Constructor
*/
public function __construct()
{
}

/**
* Stub to implement Criteria interface
*/
public function getValue()
{
return null;
}
}
25 changes: 25 additions & 0 deletions src/Data/Query/Criteria/StartsWith.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* A Criteria to specify that the string serialization must
* start with a given prefix.
*/
class StartsWith implements \LORIS\Data\Query\Criteria
{
/**
* Construct a StartsWith
*/
public function __construct(protected $prefix)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->prefix;
}
}
28 changes: 28 additions & 0 deletions src/Data/Query/Criteria/Substring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LORIS\Data\Query\Criteria;

/**
* Criteria to specify that the string serialization of a
* value must contain a substring.
*/
class Substring implements \LORIS\Data\Query\Criteria
{
/**
* Construct a Substring criteria
*
* @param string $substr The substring that must be contained in
* the value
*/
public function __construct(protected $substr)
{
}

/**
* {@inheritDoc}
*/
public function getValue()
{
return $this->substr;
}
}
18 changes: 15 additions & 3 deletions src/Data/Query/QueryEngine.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php declare(strict_types=1);
namespace LORIS\Data\Query;

use \LORIS\StudyEntities\Candidate\CandID;
use \LORIS\Data\Dictionary\DictionaryItem;
use \LORIS\Data\DataInstance;

/**
* A QueryEngine is an entity which represents a set of data and
* the ability to query against them.
Expand All @@ -11,7 +16,8 @@
* There is usually one query engine per module that deals with
* candidate data.
*/
interface QueryEngine {
interface QueryEngine
{
/**
* Return a data dictionary of data types managed by this QueryEngine.
* DictionaryItems are grouped into categories and an engine may know
Expand All @@ -27,7 +33,10 @@ public function getDataDictionary() : iterable;
* If visitlist is provided, session scoped variables will match
* if the criteria is met for at least one of those visit labels.
*/
public function getCandidateMatches(QueryTerm $criteria, ?array $visitlist=null) : iterable;
public function getCandidateMatches(
QueryTerm $criteria,
?array $visitlist = null
) : iterable;

/**
* Retrieve the data for a given list of DictionaryItems from this
Expand All @@ -48,5 +57,8 @@ public function getCandidateData(array $items, iterable $candidates, ?array $vis
*
* @return string[]
*/
public function getVisitList(\LORIS\Data\Dictionary\Category $inst, \LORIS\Data\Dictionary\DictionaryItem $item) : iterable;
public function getVisitList(
\LORIS\Data\Dictionary\Category $inst,
\LORIS\Data\Dictionary\DictionaryItem $item
) : iterable;
}
Loading

0 comments on commit 78fdb07

Please # to comment.