/
Mapper.php
77 lines (62 loc) · 2.63 KB
/
Mapper.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
<?php
/**
* Classe de mapeamento do registro da tabela papel
*/
class Auth_Model_Conta_Mapper extends Auth_Model_Conta_Crud_Mapper {
private $_oldHierarquia = '';
private $_idPaiOld = '';
protected function _beforeSave() {
parent::_beforeSave();
$this->_oldHierarquia = $this->getHierarquia();
$hirarquia = $this->getNome(true)->toPhp();
$idPai = $this->getIdPapelPai(true)->toPhp();
if ($idPai) {
$_mapper = new Auth_Model_Conta_Mapper();
$_mapper->setId($idPai)->retrieve();
$hirarquia = $_mapper->getHierarquia(true)->toPhp() . '.' . $hirarquia;
}
$this->setHierarquia($hirarquia);
if ($this->_action == 'update') {
$this->_idPaiOld = $this->getValueOld()->getIdPapelPai(true)->toPhp();
}
}
protected function _afterSave() {
parent::_afterSave();
if ($this->_action == 'update') {
$_where = new ZendT_Db_Where();
$_where->addFilter($this->getModel()->getName() . '.hierarquia', $this->_oldHierarquia, '?%');
$_where->addFilter($this->getModel()->getName() . '.id', $this->getId(), '!=');
$_mapper = new Auth_DataView_Conta_MapperView();
$_mapper->findAll($_where, '*');
while ($_mapper->fetch()) {
$_mapper->update();
}
$idPai = $this->getIdPapelPai(true)->toPhp();
if ($this->_idPaiOld && $this->_idPaiOld != $idPai) {
$_relation = new Auth_Model_ContaRel_Mapper();
$_relation->setIdPapel($this->getId())
->setIdPapelRel($this->_idPaiOld)
->retrieve();
if ($idPai) {
$_relation->setIdPapelRel($idPai)->update();
} else {
$_relation->delete();
}
}
} elseif ($this->_action == 'insert') {
$_relation = new Auth_Model_ContaRel_Mapper();
$_relation->setIdPapel($this->getId())
->setIdPapelRel($this->getId())
->setStatus('A')
->insert();
if ($this->getIdPapelPai(true)->toPhp()) {
$_relation->newRow()
->setIdPapel($this->getId())
->setIdPapelRel($this->getIdPapelPai())
->setStatus('A')
->insert();
}
}
}
}
?>