XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
blockposition.php
Go to the documentation of this file.
1 <?php
2 // $Id: blocks.php 825 2011-12-09 00:06:11Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
12 {
13 
14  public function __construct($id=''){
15 
16  $this->db =& XoopsDatabaseFactory::getDatabaseConnection();
17  $this->_dbtable = $this->db->prefix("rmc_blocks_positions");
18  $this->setNew();
19  $this->initVarsFromTable();
20 
21  if ($id=='') return;
22 
23  if ($this->loadValues($id)){
24  $this->unsetNew();
25  return;
26  }
27 
28  $this->primary = 'tag';
29  if($this->loadValues($id))
30  $this->unsetNew();
31 
32  $this->primary = 'id_position';
33 
34  }
35 
43  public function save(){
44 
45  if($this->isNew())
46  return $this->saveToTable();
47  else
48  return $this->updateTable();
49 
50  }
51 
58  public function delete(){
59 
60  $result = $this->db->query("SELECT bid FROM ".$this->db->prefix("rmc_blocks")." WHERE canvas=".$this->id());
61  $ids = array();
62  while($row = $this->db->fetchArray($result)){
63  $ids[] = $row['bid'];
64  }
65 
66  if (!$this->db->queryF("DELETE FROM ".$this->db->prefix("rmc_bkmod")." WHERE bid IN(". implode(',', $ids) .")")){
67  $this->addError($this->db->error());
68  return false;
69  }
70  if (!$this->db->queryF("DELETE FROM ".$this->db->prefix("group_permission")." WHERE gperm_itemid IN (".implode(',',$ids).") AND gperm_name='block_read'")){
71  $this->addError($this->db->error());
72  return false;
73  }
74  if (!$this->db->queryF("DELETE FROM ".$this->db->prefix("rmc_blocks")." WHERE bid IN (".implode(',',$ids).")")){
75  $this->addError($this->db->error());
76  return false;
77  }
78 
79  return $this->deleteFromTable();
80 
81  }
82 
83 }