-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRowsIndex.php
90 lines (67 loc) · 2.15 KB
/
RowsIndex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/orm/blob/master/LICENSE
*/
namespace Quid\Orm;
// rowsIndex
// class for a collection of rows within different tables (keys are indexed)
class RowsIndex extends RowsMap
{
// trait
use _mapIndex;
// dynamique
protected ?array $mapAllow = ['add','unset','remove','empty','sequential','filter','sort','clone']; // méthodes permises
protected array $mapAfter = ['sequential']; // sequential après chaque appel qui modifie, sequential ne crée pas de clone
protected static string $collectionType = 'rows'; // type de collection
// config
protected static array $config = [];
// hasCell
// retourne vrai si toutes les lignes dans l'objet ont la cellule
final public function hasCell($key):bool
{
return $this->every(fn($row) => $row->hasCell($key));
}
// primaries
// retourne un tableau multidimensionnel avec toutes les ids de lignes séparés par le nom de table
final public function primaries():array
{
$return = [];
foreach ($this->arr() as $value)
{
$id = $value->primary();
$table = $value->table()->name();
if(!array_key_exists($table,$return))
$return[$table] = [];
$return[$table][] = $id;
}
return $return;
}
// alive
// vérifie l'existence des ligne, fait une requête par table
// retourne faux si une des tables n'a pas les lignes
final public function alive():bool
{
$return = false;
foreach ($this->groupByTable() as $table => $rows)
{
$return = $rows->alive();
if($return === false)
break;
}
return $return;
}
// refresh
// rafraichit les lignes, fait une requête par table
final public function refresh():self
{
foreach ($this->groupByTable() as $table => $rows)
{
$rows->refresh();
}
return $this->checkAfter();
}
}
?>