summaryrefslogtreecommitdiff
path: root/src/Model/Collection.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Collection.php')
-rw-r--r--src/Model/Collection.php54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/Model/Collection.php b/src/Model/Collection.php
index 62bbf98..c4900fb 100644
--- a/src/Model/Collection.php
+++ b/src/Model/Collection.php
@@ -3,19 +3,19 @@
namespace App\Model;
use App\Model\Model;
+use App\Script\Input;
use ArrayAccess;
+use Countable;
+use DateTime;
use Exception;
use Iterator;
-use App\Script\Input;
-use DateTime;
-use Countable;
/**
* A collection of models
*
* @author Phil Burton <phil@pgburton.com>
*/
-class Collection implements ArrayAccess, Iterator, Countable
+class Collection implements ArrayAccess, Countable, Iterator
{
/**
* Raw array of models
@@ -171,6 +171,17 @@ class Collection implements ArrayAccess, Iterator, Countable
}
/**
+ * Return the count of the models in this collection
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return int
+ */
+ public function count(): int
+ {
+ return count($this->models);
+ }
+
+ /**
* Filter by input
*
* @author Phil Burton <phil@pgburton.com>
@@ -193,6 +204,13 @@ class Collection implements ArrayAccess, Iterator, Countable
}
}
+ /**
+ * Filter this collection by a given date and time
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $date
+ * @param string $time
+ */
public function filterByDateTime(string $date, string $time)
{
$dateTime = DateTime::createFromFormat('d/m/y G:i', $date . ' ' . $time);
@@ -213,6 +231,12 @@ class Collection implements ArrayAccess, Iterator, Countable
$this->models = $out;
}
+ /**
+ * Filter this collection by a given location postcode
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $location
+ */
public function filterByLocation(string $location)
{
$location = substr($location, 0, 2);
@@ -228,6 +252,12 @@ class Collection implements ArrayAccess, Iterator, Countable
$this->models = $out;
}
+ /**
+ * Filter this collection by a given max covers integer
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param int $covers
+ */
public function filterByCovers(int $covers)
{
$out = [];
@@ -241,8 +271,20 @@ class Collection implements ArrayAccess, Iterator, Countable
$this->models = $out;
}
- public function count()
+ /**
+ * Return string representation of this collection
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return string
+ */
+ public function toString() : string
{
- return count($this->models);
+ $out = [];
+
+ foreach ($this->models as $model) {
+ $out[] = $model->toString();
+ }
+
+ return implode("\n\n", $out);
}
}