Merge pull request #7535 from stephenwaite/bug_fix_w1
[openemr.git] / interface / modules / zend_modules / module / Multipledb / src / Multipledb / Model / MultipledbTable.php
blobc400657e41075fa53ecddef8a1abe9a56a67c5af
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;
23 use OpenEMR\Common\Crypto\CryptoGen;
24 use Laminas\Db\Sql\Expression;
25 use Laminas\Db\TableGateway\TableGateway;
26 use Laminas\Db\Sql\Predicate;
27 use Application\Model\ApplicationTable;
28 use Laminas\Db\Adapter\Adapter;
30 class MultipledbTable
32 protected $tableGateway;
33 protected $adapter;
36 /**
37 * MultipledbTable constructor.
38 * @param TableGateway $tableGateway
40 public function __construct(TableGateway $tableGateway)
42 $this->tableGateway = $tableGateway;
43 $adapter = \Laminas\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter();
44 $this->adapter = $adapter;
47 public function fetchAll()
49 /* $resultSet = $this->tableGateway->select();
50 return $resultSet;*/
52 $rsArray = array();
53 $rs = $this->tableGateway->select();
54 foreach ($rs as $r) {
55 $rsArray[] = get_object_vars($r);
58 return $rsArray;
61 public function checknamespace($namespace)
63 $rowset = $this->tableGateway->select(array('namespace' => $namespace));
64 $count = $rowset->count();
66 if ($count and $_SESSION['multiple_edit_id'] == 0) {
67 return 1;
68 } else {
69 return 0;
73 public function storeMultipledb($id = 0, $db = array())
76 if ($db['password']) {
77 $cryptoGen = new CryptoGen();
78 $db['password'] = $cryptoGen->encryptStandard($db['password']);
79 } else {
80 unset($db['password']);
83 if ($id) {
84 $this->tableGateway->update($db, array('id' => $id));
85 } else {
86 $this->tableGateway->insert($db);
90 public function deleteMultidbById($id)
92 $this->tableGateway->delete(array('id' => (int)$id));
95 public function getMultipledbById($id)
98 $rowset = $this->tableGateway->select(array('id' => $id));
99 $row = $rowset->current();
100 if (!$row) {
101 return false;
102 //throw new \Exception("Could not find row $serial_no");
105 return $row;
109 public function randomSafeKey()
111 $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$%&#@(){}[]<>~=?.*+-!';
112 $pass = array(); //remember to declare $pass as an array
113 $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
114 for ($i = 0; $i < 32; $i++) {
115 $n = mt_rand(0, $alphaLength);
116 $pass[] = $alphabet[$n];
119 return implode($pass); //turn the array into a string