You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

335 lines
8.2 KiB

  1. <?php
  2. namespace modl;
  3. class SessionxDAO extends SQL {
  4. function init(Sessionx $s) {
  5. $this->_sql = '
  6. update sessionx
  7. set username = :username,
  8. password = :password,
  9. hash = :hash,
  10. resource = :resource,
  11. rid = :rid,
  12. sid = :sid,
  13. id = :id,
  14. port = :port,
  15. host = :host,
  16. domain = :domain,
  17. config = :config,
  18. active = :active,
  19. start = :start,
  20. timestamp = :timestamp,
  21. mechanism = :mechanism
  22. where session = :session';
  23. $this->prepare(
  24. 'Sessionx',
  25. array(
  26. 'session' => $s->session,
  27. 'username' => $s->username,
  28. 'password' => $s->password,
  29. 'hash' => $s->hash,
  30. 'resource' => $s->resource,
  31. 'rid' => $s->rid,
  32. 'sid' => $s->sid,
  33. 'id' => $s->id,
  34. 'port' => $s->port,
  35. 'host' => $s->host,
  36. 'domain' => $s->domain,
  37. 'config' => $s->config,
  38. 'active' => $s->active,
  39. 'start' => $s->start,
  40. 'timestamp' => $s->timestamp,
  41. 'mechanism' => $s->mechanism
  42. )
  43. );
  44. $this->run('Sessionx');
  45. if(!$this->_effective) {
  46. $this->_sql = '
  47. insert into sessionx
  48. (session,
  49. username,
  50. password,
  51. hash,
  52. resource,
  53. rid,
  54. sid,
  55. id,
  56. port,
  57. host,
  58. domain,
  59. config,
  60. active,
  61. start,
  62. timestamp,
  63. mechanism)
  64. values
  65. (:session,
  66. :username,
  67. :password,
  68. :hash,
  69. :resource,
  70. :rid,
  71. :sid,
  72. :id,
  73. :port,
  74. :host,
  75. :domain,
  76. :config,
  77. :active,
  78. :start,
  79. :timestamp,
  80. :mechanism)';
  81. $this->prepare(
  82. 'Sessionx',
  83. array(
  84. 'session' => $s->session,
  85. 'username' => $s->username,
  86. 'password' => $s->password,
  87. 'hash' => $s->hash,
  88. 'resource' => $s->resource,
  89. 'rid' => $s->rid,
  90. 'sid' => $s->sid,
  91. 'id' => $s->id,
  92. 'port' => $s->port,
  93. 'host' => $s->host,
  94. 'domain' => $s->domain,
  95. 'config' => $s->config,
  96. 'active' => $s->active,
  97. 'start' => $s->start,
  98. 'timestamp' => $s->timestamp,
  99. 'mechanism' => $s->mechanism
  100. )
  101. );
  102. $this->run('Sessionx');
  103. }
  104. }
  105. function update($session, $key, $value) {
  106. $this->_sql = '
  107. update sessionx
  108. set
  109. '.$key.' = :'.$key.',
  110. timestamp = :timestamp
  111. where
  112. session = :session';
  113. $this->prepare(
  114. 'Sessionx',
  115. array(
  116. 'session' => $session,
  117. $key => $value,
  118. 'timestamp' => date(DATE_ISO8601)
  119. )
  120. );
  121. $this->run('Sessionx');
  122. }
  123. function get($session) {
  124. $this->_sql = '
  125. select * from sessionx
  126. where
  127. session = :session';
  128. $this->prepare(
  129. 'Sessionx',
  130. array(
  131. 'session' => $session
  132. )
  133. );
  134. return $this->run('Sessionx', 'item');
  135. }
  136. function getHash($hash) {
  137. $this->_sql = '
  138. select * from sessionx
  139. where
  140. hash = :hash';
  141. $this->prepare(
  142. 'Sessionx',
  143. array(
  144. 'hash' => $hash
  145. )
  146. );
  147. return $this->run('Sessionx', 'item');
  148. }
  149. function getId($session) {
  150. $this->_sql = '
  151. select id from sessionx
  152. where
  153. session = :session';
  154. $this->prepare(
  155. 'Sessionx',
  156. array(
  157. 'session' => $session
  158. )
  159. );
  160. $value = $this->run(null, 'array');
  161. $value = $value[0]['id'];
  162. $this->_sql = '
  163. update sessionx
  164. set
  165. id = :id,
  166. timestamp = :timestamp
  167. where
  168. session = :session';
  169. $this->prepare(
  170. 'Sessionx',
  171. array(
  172. 'session' => $session,
  173. 'id' => $value+1,
  174. 'timestamp' => date(DATE_ISO8601)
  175. )
  176. );
  177. $this->run();
  178. return $value;
  179. }
  180. function getRid($session) {
  181. $this->_sql = '
  182. select rid from sessionx
  183. where
  184. session = :session';
  185. $this->prepare(
  186. 'Sessionx',
  187. array(
  188. 'session' => $session
  189. )
  190. );
  191. $value = $this->run(null, 'array');
  192. $value = $value[0]['rid'];
  193. $this->_sql = '
  194. update sessionx
  195. set
  196. rid = :rid,
  197. timestamp = :timestamp
  198. where
  199. session = :session';
  200. $this->prepare(
  201. 'Sessionx',
  202. array(
  203. 'session' => $session,
  204. 'rid' => $value+1,
  205. 'timestamp' => date(DATE_ISO8601)
  206. )
  207. );
  208. $this->run();
  209. return $value;
  210. }
  211. function delete($session) {
  212. $this->_sql = '
  213. delete from sessionx
  214. where
  215. session = :session';
  216. $this->prepare(
  217. 'Sessionx',
  218. array(
  219. 'session' => $session
  220. )
  221. );
  222. return $this->run('Sessionx');
  223. }
  224. /*function clean() {
  225. $this->_sql = '
  226. delete from sessionx
  227. where timestamp < :timestamp';
  228. $this->prepare(
  229. 'Sessionx',
  230. array(
  231. 'timestamp' => date(DATE_ISO8601, time() - 3600)
  232. )
  233. );
  234. $this->run('Sessionx');
  235. }*/
  236. function clear() {
  237. $this->_sql = '
  238. truncate table sessionx';
  239. $this->prepare(
  240. 'Sessionx',
  241. array(
  242. )
  243. );
  244. $this->run('Sessionx');
  245. }
  246. function getAll() {
  247. $this->_sql = '
  248. select * from sessionx';
  249. $this->prepare(
  250. 'Sessionx',
  251. array()
  252. );
  253. return $this->run('Sessionx');
  254. }
  255. function getConnected() {
  256. $this->_sql = '
  257. select count(*) from sessionx';
  258. $this->prepare(
  259. 'Sessionx',
  260. array(
  261. )
  262. );
  263. $results = $this->run(null, 'array');
  264. $results = array_values($results[0]);
  265. return (int)$results[0];
  266. }
  267. function checkConnected($username, $host)
  268. {
  269. $this->_sql = '
  270. select count(*) from sessionx
  271. where
  272. username = :username
  273. and host = :host';
  274. $this->prepare(
  275. 'Sessionx',
  276. array(
  277. 'username' => $username,
  278. 'host' => $host
  279. )
  280. );
  281. $results = $this->run(null, 'array');
  282. $results = array_values($results[0]);
  283. return (int)$results[0];
  284. }
  285. }