MkFramework
 All Data Structures Functions
abstract_row.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 abstract class abstract_row{
24 
25  private $_bChooseUpdate=false;
26  protected $_tProperty=array();
27  protected $_tPropertyToUpdate;
28 
33  public function __construct($tRow=null){
34  if($tRow!=null){
35  $this->_tProperty=$tRow;
36  $this->chooseUpdate();
37  }
38  }
44  public function getModel(){
45  $sModel=$this->sClassModel;
46  return call_user_func(array($sModel,'getInstance'));
47  }
52  public function save(){
53  if($this->_bChooseUpdate == true){
54  $this->update();
55  }else{
56  $this->setId($this->insert());
57  }
58  }
63  public function update(){
64  $this->getModel()->update($this);
65  }
70  public function insert(){
71  return $this->getModel()->insert($this);
72  }
73 
78  public function delete(){
79  return $this->getModel()->delete($this);
80  }
81 
86  public function isEmpty(){
87  if(empty($this->_tProperty) and empty($this->_tPropertyToUpdate)){
88  return true;
89  }
90  return false;
91  }
92 
93  public function chooseUpdate(){
94  $this->_bChooseUpdate=true;
95  }
101  public function getToUpdate(){
102  $tToUpdate=array();
103  if($this->_tPropertyToUpdate){
104  foreach($this->_tPropertyToUpdate as $sVar){
105  $tToUpdate[$sVar]=$this->_tProperty[$sVar];
106  }
107  }
108  return $tToUpdate;
109  }
115  public function getWhere(){
116  $tWhereId=array();
117  $tId=$this->getModel()->getIdTab();
118  if($tId){
119  foreach($tId as $sVar){
120  if(isset($this->_tProperty[$sVar])){
121  $tWhereId[$sVar]=(int)$this->_tProperty[$sVar];
122  }
123  }
124  }
125  return $tWhereId;
126  }
127 
131  public function __set($sVar,$sVal){
132  $this->_tProperty[$sVar]=$sVal;
133  $this->_tPropertyToUpdate[]=$sVar;
134  }
138  public function __get($sVar){
139  if(array_key_exists( (string)$sVar,$this->_tProperty)){
140  return $this->_tProperty[$sVar];
141  }
142  return null;
143  }
147  public function __isset($sVar){
148  return isset($this->_tProperty[$sVar]);
149  }
150 
154  public function __unset($sVar){
155  unset($this->_tProperty[$sVar]);
156  }
161  public function setId($uId){
162  if($uId == null){ return false; }
163  $tColumnId=$this->getModel()->getIdTab();
164  $sColumnId=$tColumnId[0];
165 
166  $this->_tProperty[$sColumnId]=$uId;
167 
168  $this->chooseUpdate();
169  }
170 
171  public function getId(){
172  return implode('::',$this->getWhere());
173  }
174 
175  public function getTab(){
176  return $this->_tProperty;
177  }
178 
179 }
__construct($tRow=null)
__set($sVar, $sVal)