namespace Friendica\Navigation\Notifications\Collection;
use Friendica\BaseCollection;
-use Friendica\Navigation\Notifications\Entity;
+use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
class Notifications extends BaseCollection
{
- /**
- * @return Entity\Notification
- */
- public function current(): Entity\Notification
+ public function current(): NotificationEntity
{
return parent::current();
}
public function setSeen(): Notifications
{
- return $this->map(function (Entity\Notification $Notification) {
- $Notification->setSeen();
- });
+ $class = get_class($this);
+
+ return new $class(
+ array_map(
+ function (NotificationEntity $notification) {
+ $notification->setSeen();
+ },
+ $this->getArrayCopy()
+ ),
+ $this->getTotalCount(),
+ );
}
public function setDismissed(): Notifications
{
- return $this->map(function (Entity\Notification $Notification) {
- $Notification->setDismissed();
- });
+ $class = get_class($this);
+
+ return new $class(
+ array_map(
+ function (NotificationEntity $notification) {
+ $notification->setDismissed();
+ },
+ $this->getArrayCopy(),
+ ),
+ $this->getTotalCount(),
+ );
+
}
public function countUnseen(): int
{
- return array_reduce($this->getArrayCopy(), function (int $carry, Entity\Notification $Notification) {
- return $carry + ($Notification->seen ? 0 : 1);
+ return array_reduce($this->getArrayCopy(), function (int $carry, NotificationEntity $notification) {
+ return $carry + ($notification->seen ? 0 : 1);
}, 0);
}
}
namespace Friendica\Navigation\Notifications\Collection;
use Friendica\BaseCollection;
-use Friendica\Navigation\Notifications\Entity;
+use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity;
class Notifies extends BaseCollection
{
- /**
- * @return Entity\Notify
- */
- public function current(): Entity\Notify
+ public function current(): NotifyEntity
{
return parent::current();
}
public function setSeen(): Notifies
{
- return $this->map(function (Entity\Notify $Notify) {
- $Notify->setSeen();
- });
+ $class = get_class($this);
+
+ return new $class(array_map(
+ function (NotifyEntity $notify) {
+ $notify->setSeen();
+ },
+ $this->getArrayCopy()), $this->getTotalCount(),
+ );
}
}
LIMIT 50
", ...$values);
- $Entities = new NotificationsCollection();
+ $entities = new NotificationsCollection();
+
+ if (!is_iterable($rows)) {
+ return $entities;
+ }
+
foreach ($rows as $fields) {
- $Entities[] = $this->factory->createFromTableRow($fields);
+ $entities[] = $this->factory->createFromTableRow($fields);
}
- return $Entities;
+ return $entities;
}
public function selectAllForUser(int $uid): NotificationsCollection