add multi database option along with related zend configuration module (#439)
[openemr.git] / interface / modules / zend_modules / module / Multipledb / src / Multipledb / Model / MultipledbTable.php
blobaddd733557d0302e0d01695c886f3dd3915ccb6f
1 <?php
3 /* +-----------------------------------------------------------------------------+
4 * Copyright 2016 matrix israel
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 3
8 * of the License, or (at your option) any later version.
9 * This program 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 General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see
15 * http://www.gnu.org/licenses/licenses.html#GPL
16 * @author Oshri Rozmarin <oshri.rozmarin@gmail.com>
17 * +------------------------------------------------------------------------------+
21 namespace Multipledb\Model;
22 use Zend\Db\Sql\Expression;
23 use Zend\Db\TableGateway\TableGateway;
24 use Zend\Db\Sql\Predicate;
25 use \Application\Model\ApplicationTable;
26 use Zend\Db\Adapter\Adapter;
27 class MultipledbTable
30 protected $tableGateway;
31 protected $adapter;
34 /**
35 * MultipledbTable constructor.
36 * @param TableGateway $tableGateway
38 public function __construct(TableGateway $tableGateway)
40 $this->tableGateway = $tableGateway;
41 $adapter = \Zend\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter();
42 $this->adapter = $adapter;
45 public function fetchAll()
47 /* $resultSet = $this->tableGateway->select();
48 return $resultSet;*/
50 $rsArray = array();
51 $rs = $this->tableGateway->select();
52 foreach ($rs as $r) {
53 $rsArray[] = get_object_vars($r);
56 return $rsArray;
60 public function storeMultipledb($id = 0,$db = array()){
62 if($db['password']){
63 $db['password'] = my_encrypt($db['password']);
64 }else{
65 unset($db['password']);
68 if($id){
69 $this->tableGateway->update($db, array('id' => $id));
70 }else{
71 $this->tableGateway->insert($db);
76 public function deleteMultidbById($id){
77 $this->tableGateway->delete(array('id' => (int)$id));
80 public function getMultipledbById($id){
82 $rowset = $this->tableGateway->select(array('id' => $id));
83 $row = $rowset->current();
84 if (!$row) {
85 return false;
86 //throw new \Exception("Could not find row $serial_no");
89 return $row;
93 public function randomSafeKey() {
94 $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$%&#@(){}[]<>~=?.*+-!';
95 $pass = array(); //remember to declare $pass as an array
96 $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
97 for ($i = 0; $i < 32; $i++) {
98 $n = mt_rand(0, $alphaLength);
99 $pass[] = $alphabet[$n];
101 return implode($pass); //turn the array into a string