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
;
32 protected $tableGateway;
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();
53 $rs = $this->tableGateway
->select();
55 $rsArray[] = get_object_vars($r);
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) {
73 public function storeMultipledb($id = 0, $db = array())
76 if ($db['password']) {
77 $cryptoGen = new CryptoGen();
78 $db['password'] = $cryptoGen->encryptStandard($db['password']);
80 unset($db['password']);
84 $this->tableGateway
->update($db, array('id' => $id));
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();
102 //throw new \Exception("Could not find row $serial_no");
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