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.

447 lines
15 KiB

  1. <?php
  2. namespace modl;
  3. class ContactDAO extends SQL {
  4. function __construct() {
  5. parent::__construct();
  6. }
  7. function get($jid) {
  8. $this->_sql = '
  9. select *, privacy.value as privacy from contact
  10. left outer join privacy
  11. on contact.jid = privacy.pkey
  12. where jid = :jid';
  13. $this->prepare(
  14. 'Contact',
  15. array(
  16. 'jid' => $jid
  17. )
  18. );
  19. return $this->run('Contact', 'item');
  20. }
  21. function set(Contact $contact) {
  22. $this->_sql = '
  23. update contact
  24. set fn = :fn,
  25. name = :name,
  26. date = :date,
  27. url = :url,
  28. email = :email,
  29. adrlocality = :adrlocality,
  30. adrpostalcode = :adrpostalcode,
  31. adrcountry = :adrcountry,
  32. gender = :gender,
  33. marital = :marital,
  34. description = :description,
  35. mood = :mood,
  36. activity = :activity,
  37. nickname = :nickname,
  38. tuneartist = :tuneartist,
  39. tunelenght = :tunelenght,
  40. tunerating = :tunerating,
  41. tunesource = :tunesource,
  42. tunetitle = :tunetitle,
  43. tunetrack = :tunetrack,
  44. loclatitude = :loclatitude,
  45. loclongitude = :loclongitude,
  46. localtitude = :localtitude,
  47. loccountry = :loccountry,
  48. loccountrycode = :loccountrycode,
  49. locregion = :locregion,
  50. locpostalcode = :locpostalcode,
  51. loclocality = :loclocality,
  52. locstreet = :locstreet,
  53. locbuilding = :locbuilding,
  54. loctext = :loctext,
  55. locuri = :locuri,
  56. loctimestamp = :loctimestamp,
  57. twitter = :twitter,
  58. skype = :skype,
  59. yahoo = :yahoo
  60. where contact.jid = :jid';
  61. $this->prepare(
  62. 'Contact',
  63. array(
  64. 'fn' => $contact->fn,
  65. 'name' => $contact->name,
  66. 'date' => $contact->date,
  67. 'url' => $contact->url,
  68. 'email' => $contact->email,
  69. 'adrlocality' => $contact->adrlocality,
  70. 'adrpostalcode' => $contact->adrpostalcode,
  71. 'adrcountry' => $contact->adrcountry,
  72. 'gender' => $contact->gender,
  73. 'marital' => $contact->marital,
  74. 'description' => $contact->description,
  75. // User Mood (contain serialized array) - XEP 0107
  76. 'mood' => $contact->mood,
  77. // User Activity (contain serialized array) - XEP 0108
  78. 'activity' => $contact->activity,
  79. // User Nickname - XEP 0172
  80. 'nickname' => $contact->nickname,
  81. // User Tune - XEP 0118
  82. 'tuneartist' => $contact->tuneartist,
  83. 'tunelenght' => $contact->tunelenght,
  84. 'tunerating' => $contact->tunerating,
  85. 'tunesource' => $contact->tunesource,
  86. 'tunetitle' => $contact->tunetitle,
  87. 'tunetrack' => $contact->tunetrack,
  88. // User Location
  89. 'loclatitude' => $contact->loclatitude,
  90. 'loclongitude' => $contact->loclongitude,
  91. 'localtitude' => $contact->localtitude,
  92. 'loccountry' => $contact->loccountry,
  93. 'loccountrycode' => $contact->loccountrycode,
  94. 'locregion' => $contact->locregion,
  95. 'locpostalcode' => $contact->locpostalcode,
  96. 'loclocality' => $contact->loclocality,
  97. 'locstreet' => $contact->locstreet,
  98. 'locbuilding' => $contact->locbuilding,
  99. 'loctext' => $contact->loctext,
  100. 'locuri' => $contact->locuri,
  101. 'loctimestamp' => $contact->loctimestamp,
  102. 'twitter' => $contact->twitter,
  103. 'skype' => $contact->skype,
  104. 'yahoo' => $contact->yahoo,
  105. 'jid' => $contact->jid
  106. )
  107. );
  108. $this->run('Contact');
  109. if(!$this->_effective) {
  110. $this->_sql = '
  111. insert into contact
  112. (
  113. fn,
  114. name,
  115. date,
  116. url,
  117. email,
  118. adrlocality,
  119. adrpostalcode,
  120. adrcountry,
  121. gender,
  122. marital,
  123. description,
  124. mood,
  125. activity,
  126. nickname,
  127. tuneartist,
  128. tunelenght,
  129. tunerating,
  130. tunesource,
  131. tunetitle,
  132. tunetrack,
  133. loclatitude,
  134. loclongitude,
  135. localtitude,
  136. loccountry,
  137. loccountrycode,
  138. locregion,
  139. locpostalcode,
  140. loclocality,
  141. locstreet,
  142. locbuilding,
  143. loctext,
  144. locuri,
  145. loctimestamp,
  146. twitter,
  147. skype,
  148. yahoo,
  149. jid)
  150. values (
  151. :fn,
  152. :name,
  153. :date,
  154. :url,
  155. :email,
  156. :adrlocality,
  157. :adrpostalcode,
  158. :adrcountry,
  159. :gender,
  160. :marital,
  161. :description,
  162. :mood,
  163. :activity,
  164. :nickname,
  165. :tuneartist,
  166. :tunelenght,
  167. :tunerating,
  168. :tunesource,
  169. :tunetitle,
  170. :tunetrack,
  171. :loclatitude,
  172. :loclongitude,
  173. :localtitude,
  174. :loccountry,
  175. :loccountrycode,
  176. :locregion,
  177. :locpostalcode,
  178. :loclocality,
  179. :locstreet,
  180. :locbuilding,
  181. :loctext,
  182. :locuri,
  183. :loctimestamp,
  184. :twitter,
  185. :skype,
  186. :yahoo,
  187. :jid)';
  188. $this->prepare(
  189. 'Contact',
  190. array(
  191. 'fn' => $contact->fn,
  192. 'name' => $contact->name,
  193. 'date' => $contact->date,
  194. 'url' => $contact->url,
  195. 'email' => $contact->email,
  196. 'adrlocality' => $contact->adrlocality,
  197. 'adrpostalcode' => $contact->adrpostalcode,
  198. 'adrcountry' => $contact->adrcountry,
  199. 'gender' => $contact->gender,
  200. 'marital' => $contact->marital,
  201. 'description' => $contact->description,
  202. // User Mood (contain serialized array) - XEP 0107
  203. 'mood' => $contact->mood,
  204. // User Activity (contain serialized array) - XEP 0108
  205. 'activity' => $contact->activity,
  206. // User Nickname - XEP 0172
  207. 'nickname' => $contact->nickname,
  208. // User Tune - XEP 0118
  209. 'tuneartist' => $contact->tuneartist,
  210. 'tunelenght' => $contact->tunelenght,
  211. 'tunerating' => $contact->tunerating,
  212. 'tunesource' => $contact->tunesource,
  213. 'tunetitle' => $contact->tunetitle,
  214. 'tunetrack' => $contact->tunetrack,
  215. // User Location
  216. 'loclatitude' => $contact->loclatitude,
  217. 'loclongitude' => $contact->loclongitude,
  218. 'localtitude' => $contact->localtitude,
  219. 'loccountry' => $contact->loccountry,
  220. 'loccountrycode' => $contact->loccountrycode,
  221. 'locregion' => $contact->locregion,
  222. 'locpostalcode' => $contact->locpostalcode,
  223. 'loclocality' => $contact->loclocality,
  224. 'locstreet' => $contact->locstreet,
  225. 'locbuilding' => $contact->locbuilding,
  226. 'loctext' => $contact->loctext,
  227. 'locuri' => $contact->locuri,
  228. 'loctimestamp' => $contact->loctimestamp,
  229. 'twitter' => $contact->twitter,
  230. 'skype' => $contact->skype,
  231. 'yahoo' => $contact->yahoo,
  232. 'jid' => $contact->jid
  233. )
  234. );
  235. $this->run('Contact');
  236. }
  237. }
  238. function getAll() {
  239. $this->_sql =
  240. 'select *, privacy.value as privacy from contact
  241. left outer join privacy
  242. on contact.jid = privacy.pkey';
  243. $this->prepare('Contact');
  244. return $this->run('Contact');
  245. }
  246. function getAllPublic() {
  247. $this->_sql =
  248. 'select *, privacy.value as privacy from contact
  249. left outer join privacy
  250. on contact.jid = privacy.pkey
  251. where privacy.value = 1';
  252. $this->prepare('Contact');
  253. return $this->run('Contact');
  254. }
  255. function cleanRoster() {
  256. $this->_sql = '
  257. delete from rosterlink
  258. where session = :session';
  259. $this->prepare(
  260. 'RosterLink',
  261. array(
  262. 'session' => $this->_user
  263. )
  264. );
  265. return $this->run('RosterLink');
  266. }
  267. function getRoster() {
  268. $this->_sql = '
  269. select * from rosterlink
  270. left outer join presence
  271. on rosterlink.jid = presence.jid and rosterlink.session = presence.session
  272. left outer join contact
  273. on rosterlink.jid = contact.jid
  274. where rosterlink.session = :session
  275. order by groupname, rosterlink.jid, presence.value';
  276. $this->prepare(
  277. 'RosterLink',
  278. array(
  279. 'session' => $this->_user
  280. )
  281. );
  282. return $this->run('RosterContact');
  283. }
  284. // limit 1
  285. function getRosterChat() {
  286. $this->_sql = '
  287. select * from rosterlink
  288. left outer join (
  289. select * from presence
  290. order by presence.priority desc
  291. ) as presence
  292. on rosterlink.jid = presence.jid
  293. left outer join contact
  294. on rosterlink.jid = contact.jid
  295. where rosterlink.session = :session
  296. and rosterlink.chaton > 0
  297. order by rosterlink.groupname, rosterlink.jid, presence.value';
  298. $this->prepare(
  299. 'RosterLink',
  300. array(
  301. 'session' => $this->_user
  302. )
  303. );
  304. return $this->run('RosterContact');
  305. }
  306. function getRosterItem($jid, $item = false) {
  307. $this->_sql = '
  308. select * from rosterlink
  309. left outer join presence
  310. on rosterlink.jid = presence.jid and rosterlink.session = presence.session
  311. left outer join contact
  312. on rosterlink.jid = contact.jid
  313. where rosterlink.session = :session
  314. and rosterlink.jid = :jid
  315. order by groupname, rosterlink.jid, presence.value';
  316. $this->prepare(
  317. 'RosterLink',
  318. array(
  319. 'session' => $this->_user,
  320. 'jid' => $jid
  321. )
  322. );
  323. if($item)
  324. return $this->run('RosterContact');
  325. else
  326. return $this->run('RosterContact', 'item');
  327. }
  328. function getMe($item = false) {
  329. $this->_sql = '
  330. select * from contact
  331. left outer join presence on contact.jid = presence.jid
  332. where contact.jid = :jid
  333. and presence.session = :session';
  334. $this->prepare(
  335. 'RosterLink',
  336. array(
  337. 'session' => $this->_user,
  338. 'jid' => $this->_user
  339. )
  340. );
  341. if($item)
  342. return $this->run('RosterContact');
  343. else
  344. return $this->run('RosterContact', 'item');
  345. }
  346. function getStatistics() {
  347. $this->_sql = '
  348. select
  349. (select count(*) from postn where postn.session = :session ) as post,
  350. (select count(*) from rosterlink where rosterlink.session= :session ) as rosterlink,
  351. (select count(*) from presence where presence.session= :session ) as presence,
  352. (select count(*) from message where message.session = :session) as message;';
  353. $this->prepare(
  354. 'Postn',
  355. array(
  356. 'session' => $this->_user
  357. )
  358. );
  359. return $this->run(null, 'array');
  360. }
  361. }