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 Zend\Db\Sql\Expression
;
24 use Zend\Db\TableGateway\TableGateway
;
25 use Zend\Db\Sql\Predicate
;
26 use \Application\Model\ApplicationTable
;
27 use Zend\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 = \Zend\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 $db['password'] = my_encrypt($db['password']);
79 unset($db['password']);
83 $this->tableGateway
->update($db, array('id' => $id));
85 $this->tableGateway
->insert($db);
89 public function deleteMultidbById($id)
91 $this->tableGateway
->delete(array('id' => (int)$id));
94 public function getMultipledbById($id)
97 $rowset = $this->tableGateway
->select(array('id' => $id));
98 $row = $rowset->current();
101 //throw new \Exception("Could not find row $serial_no");
108 public function randomSafeKey()
110 $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$%&#@(){}[]<>~=?.*+-!';
111 $pass = array(); //remember to declare $pass as an array
112 $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
113 for ($i = 0; $i < 32; $i++
) {
114 $n = mt_rand(0, $alphaLength);
115 $pass[] = $alphabet[$n];
118 return implode($pass); //turn the array into a string