Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ViewRepository.php
Go to the documentation of this file.
1<?php
2
4
8
19 private string $model;
20 private View $view;
21
22 private function setViewVarsAndReturn(string $viewVar, $instance, $r) {
23 $this->view->setVar ( $viewVar, $instance );
24 $this->view->setVar ( 'status', $r );
25 return $r;
26 }
27
28 public function __construct(Controller $ctrl, string $model) {
29 $this->view = $ctrl->getView ();
30 $this->model = $model;
31 }
32
43 public function all(string $condition = '', $included = false, array $parameters = [ ], bool $useCache = false, string $viewVar = 'all'): array {
44 $this->view->setVar ( $viewVar, $r = DAO::getAll ( $this->model, $condition, $included, $parameters, $useCache ) );
45 return $r;
46 }
47
57 public function byId($keyValues, $included = true, bool $useCache = false, string $viewVar = 'byId'): ?object {
58 $this->view->setVar ( $viewVar, $r = DAO::getById ( $this->model, $keyValues, $included, $useCache ) );
59 return $r;
60 }
61
73 public function one(string $condition = '', $included = true, array $parameters = [ ], bool $useCache = false, string $viewVar = 'one'): ?object {
74 $this->view->setVar ( $viewVar, $r = DAO::getOne ( $this->model, $condition, $included, $parameters, $useCache ) );
75 return $r;
76 }
77
88 public function insert(object $instance, $insertMany = false, string $viewVar = 'inserted'): bool {
89 $r = DAO::insert ( $instance, $insertMany );
90 return $this->setViewVarsAndReturn ( $viewVar, $instance, $r );
91 }
92
102 public function update(object $instance, $insertMany = false, string $viewVar = 'updated'): bool {
103 $r = DAO::update ( $instance, $insertMany );
104 return $this->setViewVarsAndReturn ( $viewVar, $instance, $r );
105 }
106
116 public function save(object $instance, $insertMany = false, string $viewVar = 'saved') {
117 $r = DAO::save ( $instance, $insertMany );
118 return $this->setViewVarsAndReturn ( $viewVar, $instance, $r );
119 }
120
128 public function remove(object $instance, string $viewVar = 'removed'): ?int {
129 $r = DAO::remove ( $instance );
130 return $this->setViewVarsAndReturn ( $viewVar, $instance, $r );
131 }
132}
Base class for controllers.
getView()
Returns the associated view instance.
Gateway class between database and object model.
Definition DAO.php:33
A repository for managing CRUD operations on a model, displayed in a view.
insert(object $instance, $insertMany=false, string $viewVar='inserted')
Insert a new instance $instance into the database and add the instance in a view variable (inserted).
byId($keyValues, $included=true, bool $useCache=false, string $viewVar='byId')
Load one instance by id in a view variable named byId.
all(string $condition='', $included=false, array $parameters=[], bool $useCache=false, string $viewVar='all')
Load all instances in a view variable named all.
save(object $instance, $insertMany=false, string $viewVar='saved')
Save (insert or update) an instance $instance in the database and add the instance in a view variable...
one(string $condition='', $included=true, array $parameters=[], bool $useCache=false, string $viewVar='one')
Load one instance in a view variable named one.
setViewVarsAndReturn(string $viewVar, $instance, $r)
update(object $instance, $insertMany=false, string $viewVar='updated')
Update an instance $instance in the database and add the instance in a view variable (updated).
__construct(Controller $ctrl, string $model)
Represents a view.
Definition View.php:17