PageRenderTime 64ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_jevents/libraries/dbmodel.php

https://github.com/bhavan/v3
PHP | 1867 lines | 1336 code | 294 blank | 237 comment | 163 complexity | 47dc7b13eb439975c79739fda633ea15 MD5 | raw file
Possible License(s): BSD-2-Clause, MIT, BSD-3-Clause, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * JEvents Component for Joomla 1.5.x
  4. *
  5. * @version $Id: dbmodel.php 1869 2010-12-17 11:54:52Z geraint $
  6. * @package JEvents
  7. * @copyright Copyright (C) 2008-2009 GWE Systems Ltd, 2006-2008 JEvents Project Group
  8. * @license GNU/GPLv2, see http://www.gnu.org/licenses/gpl-2.0.html
  9. * @link http://www.jevents.net
  10. */
  11. defined( '_JEXEC' ) or die( 'Restricted access' );
  12. // load language constants
  13. JEVHelper::loadLanguage('front');
  14. class JEventsDBModel {
  15. var $cfg = null;
  16. var $datamodel = null;
  17. var $legacyEvents = null;
  18. function JEventsDBModel(&$datamodel){
  19. $this->cfg = & JEVConfig::getInstance();
  20. // TODO - remove legacy code
  21. $this->legacyEvents = 0;
  22. $this->datamodel =& $datamodel;
  23. }
  24. function accessibleCategoryList($aid=null, $catids=null, $catidList=null) {
  25. global $mainframe;
  26. $db =& JFactory::getDBO();
  27. if (is_null($aid)) {
  28. $aid = $this->datamodel->aid;
  29. }
  30. if (is_null($catids)) {
  31. $catids = $this->datamodel->catids;
  32. }
  33. if (is_null($catidList)) {
  34. $catidList = $this->datamodel->catidList;
  35. }
  36. $cfg = & JEVConfig::getInstance();
  37. $sectionname = JEV_COM_COMPONENT;
  38. static $instances;
  39. if (!$instances) {
  40. $instances = array();
  41. }
  42. // calculate unique index identifier
  43. $index = $aid . '+' . $catidList;
  44. // if catidList = 0 then the result is the same as a blank so slight time saving
  45. if (is_null($catidList) || $catidList==0) {
  46. $index = $aid . '+';
  47. }
  48. $where = "";
  49. if (!array_key_exists($index,$instances)) {
  50. if (count($catids)>0 && !is_null($catidList) && $catidList!="0") {
  51. $where = ' AND (c.id IN (' . $catidList .') OR p.id IN (' . $catidList .') OR gp.id IN (' . $catidList .') OR ggp.id IN (' . $catidList .'))';
  52. }
  53. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  54. $query = "SELECT c.id"
  55. . "\n FROM #__categories AS c"
  56. . ' LEFT JOIN #__categories AS p ON p.id=c.parent_id'
  57. . ' LEFT JOIN #__categories AS gp ON gp.id=p.parent_id '
  58. . ' LEFT JOIN #__categories AS ggp ON ggp.id=gp.parent_id '
  59. . "\n WHERE c.access <= $aid"
  60. . $q_published
  61. . "\n AND c.section = '".$sectionname."'"
  62. . "\n " . $where;
  63. ;
  64. $db->setQuery($query);
  65. $catlist = $db->loadResultArray();
  66. $instances[$index] = implode(',', array_merge(array(-1), $catlist));
  67. $dispatcher =& JDispatcher::getInstance();
  68. $dispatcher->trigger('onGetAccessibleCategories', array (& $instances[$index]));
  69. }
  70. return $instances[$index];
  71. }
  72. function getCategoryInfo($catids=null,$aid=null){
  73. global $mainframe;
  74. $db =& JFactory::getDBO();
  75. if (is_null($aid)) {
  76. $aid = $this->datamodel->aid;
  77. }
  78. if (is_null($catids)) {
  79. $catids = $this->datamodel->catids;
  80. }
  81. $catidList = implode(",", $catids);
  82. $cfg = & JEVConfig::getInstance();
  83. $sectionname = JEV_COM_COMPONENT;
  84. static $instances;
  85. if (!$instances) {
  86. $instances = array();
  87. }
  88. // calculate unique index identifier
  89. $index = $aid . '+' . $catidList;
  90. $where = null;
  91. if (!array_key_exists($index,$instances)) {
  92. if (count($catids)>0 && $catidList!="0" && strlen($catidList)!="") {
  93. $where = ' AND c.id IN (' . $catidList .') ';
  94. }
  95. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  96. $query = "SELECT c.*"
  97. . "\n FROM #__categories AS c"
  98. . "\n WHERE c.access <= $aid"
  99. . $q_published
  100. . "\n AND c.section = '".$sectionname."'"
  101. . "\n " . $where;
  102. ;
  103. $db->setQuery($query);
  104. $catlist = $db->loadObjectList('id');
  105. $instances[$index] = $catlist;
  106. }
  107. return $instances[$index];
  108. }
  109. function getChildCategories($catids=null,$levels=1,$aid=null){
  110. global $mainframe;
  111. $db =& JFactory::getDBO();
  112. if (is_null($aid)) {
  113. $aid = $this->datamodel->aid;
  114. }
  115. if (is_null($catids)) {
  116. $catids = $this->datamodel->catids;
  117. }
  118. $catidList = implode(",", $catids);
  119. $cfg = & JEVConfig::getInstance();
  120. $sectionname = JEV_COM_COMPONENT;
  121. static $instances;
  122. if (!$instances) {
  123. $instances = array();
  124. }
  125. // calculate unique index identifier
  126. $index = $aid . '+' . $catidList;
  127. $where = null;
  128. if (!array_key_exists($index,$instances)) {
  129. if (count($catids)>0 && $catidList!="0" && strlen($catidList)!="") {
  130. $where = ' AND (p.id IN (' . $catidList .') '.($levels>1?' OR gp.id IN (' . $catidList .')':'').($levels>2?' OR ggp.id IN (' . $catidList .')':'').')';
  131. }
  132. // TODO check if this should also check abncestry based on $levels
  133. $where .= ' AND p.id IS NOT NULL ';
  134. $q_published = $mainframe->isAdmin() ? "\n AND c.published >= 0" : "\n AND c.published = 1";
  135. $query = "SELECT c.*"
  136. . "\n FROM #__categories AS c"
  137. . ' LEFT JOIN #__categories AS p ON p.id=c.parent_id'
  138. . ($levels>1?' LEFT JOIN #__categories AS gp ON gp.id=p.parent_id ':'')
  139. . ($levels>2?' LEFT JOIN #__categories AS ggp ON ggp.id=gp.parent_id ':'')
  140. . "\n WHERE c.access <= $aid"
  141. . $q_published
  142. . "\n AND c.section = '".$sectionname."'"
  143. . "\n " . $where;
  144. ;
  145. $db->setQuery($query);
  146. $catlist = $db->loadObjectList('id');
  147. $instances[$index] = $catlist;
  148. }
  149. return $instances[$index];
  150. }
  151. function listEvents( $startdate, $enddate, $order=""){
  152. if (!$this->legacyEvents) {
  153. return array();
  154. }
  155. }
  156. function _cachedlistEvents($query, $langtag,$count=false){
  157. $db =& JFactory::getDBO();
  158. $db->setQuery( $query );
  159. if ($count){
  160. $db->query();
  161. return $db->getNumRows();
  162. }
  163. $rows = $db->loadObjectList();
  164. $rowcount = count($rows);
  165. if ($rowcount>0) {
  166. usort( $rows, array('JEventsDBModel','sortEvents') );
  167. }
  168. for( $i = 0; $i < $rowcount; $i++ ){
  169. $rows[$i] = new jEventCal($rows[$i]);
  170. }
  171. return $rows;
  172. }
  173. /**
  174. * Fetch recently created events
  175. */
  176. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  177. function recentIcalEvents($startdate,$enddate, $limit=10, $noRepeats=0){
  178. $user =& JFactory::getUser();
  179. $db =& JFactory::getDBO();
  180. $lang =& JFactory::getLanguage();
  181. $langtag = $lang->getTag();
  182. if (strpos($startdate,"-")===false) {
  183. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  184. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  185. }
  186. // process the new plugins
  187. // get extra data and conditionality from plugins
  188. $extrawhere =array();
  189. $extrajoin = array();
  190. $extrafields = ""; // must have comma prefix
  191. $extratables = ""; // must have comma prefix
  192. $needsgroup = false;
  193. $filterarray = array("published","justmine","category","search");
  194. // If there are extra filters from the module then apply them now
  195. $reg =& JFactory::getConfig();
  196. $modparams = $reg->getValue("jev.modparams",false);
  197. if ($modparams && $modparams->getValue("extrafilters",false)){
  198. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  199. }
  200. $filters = jevFilterProcessing::getInstance($filterarray);
  201. $filters->setWhereJoin($extrawhere,$extrajoin );
  202. $needsgroup = $filters->needsGroupBy();
  203. $dispatcher =& JDispatcher::getInstance();
  204. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  205. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  206. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  207. // get the event ids first
  208. $query = "SELECT ev.ev_id FROM #__jevents_repetition as rpt"
  209. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  210. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  211. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  212. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  213. . $extrajoin
  214. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  215. . "\n AND ev.created >= '$startdate' AND ev.created <= '$enddate'"
  216. . $extrawhere
  217. . "\n AND ev.access <= ".$user->aid
  218. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  219. // published state is now handled by filter
  220. . "\n GROUP BY ev.ev_id";
  221. // always in reverse created date order!
  222. $query .= " ORDER BY ev.created DESC ";
  223. // This limit will always be enough
  224. $query .= " LIMIT ".$limit;
  225. $db = JFactory::getDBO();
  226. $db->setQuery($query);
  227. $ids = $db->loadResultArray();
  228. array_push($ids,0);
  229. $ids = implode(",",$ids);
  230. $groupby = "\n GROUP BY rpt.rp_id";
  231. if ($noRepeats) $groupby = "\n GROUP BY ev.ev_id";
  232. // This version picks the details from the details table
  233. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  234. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  235. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  236. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  237. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  238. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  239. . "\n FROM #__jevents_repetition as rpt"
  240. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  241. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  242. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  243. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  244. . $extrajoin
  245. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  246. . "\n AND ev.created >= '$startdate' AND ev.created <= '$enddate'"
  247. . $extrawhere
  248. . "\n AND ev.access <= ".$user->aid
  249. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  250. . " AND ev.ev_id IN (".$ids.")"
  251. // published state is now handled by filter
  252. //. "\n AND ev.state=1"
  253. . ($needsgroup?$groupby:"");
  254. $query .= " ORDER BY ev.created DESC ";
  255. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  256. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  257. $dispatcher =& JDispatcher::getInstance();
  258. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  259. return $rows;
  260. }
  261. /* Special version for Latest events module */
  262. function listLatestIcalEvents($startdate,$enddate, $limit=10, $noRepeats=0){
  263. $user =& JFactory::getUser();
  264. $db =& JFactory::getDBO();
  265. $lang =& JFactory::getLanguage();
  266. $langtag = $lang->getTag();
  267. if (strpos($startdate,"-")===false) {
  268. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  269. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  270. }
  271. // process the new plugins
  272. // get extra data and conditionality from plugins
  273. $extrawhere =array();
  274. $extrajoin = array();
  275. $extrafields = ""; // must have comma prefix
  276. $extratables = ""; // must have comma prefix
  277. $needsgroup = false;
  278. $filterarray = array("published","justmine","category","search");
  279. // If there are extra filters from the module then apply them now
  280. $reg =& JFactory::getConfig();
  281. $modparams = $reg->getValue("jev.modparams",false);
  282. if ($modparams && $modparams->getValue("extrafilters",false)){
  283. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  284. }
  285. $filters = jevFilterProcessing::getInstance($filterarray);
  286. $filters->setWhereJoin($extrawhere,$extrajoin );
  287. $needsgroup = $filters->needsGroupBy();
  288. $dispatcher =& JDispatcher::getInstance();
  289. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  290. // What if join multiplies the rows?
  291. // Useful MySQL link http://forums.mysql.com/read.php?10,228378,228492#msg-228492
  292. // concat with group
  293. // http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
  294. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  295. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  296. // get the event ids first - split into 2 queries to pick up the ones after now and the ones before
  297. $t_datenow = JEVHelper::getNow();
  298. $t_datenowSQL = $t_datenow->toMysql();
  299. /*
  300. $query = "SELECT ev.ev_id FROM #__jevents_repetition as rpt"
  301. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  302. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  303. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  304. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  305. . $extrajoin
  306. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  307. // New equivalent but simpler test
  308. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  309. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  310. . "\n AND ((rpt.startrepeat >= '$startdate' AND det.multiday=0) OR det.multiday=1)"
  311. . $extrawhere
  312. . "\n AND ev.access <= ".$user->aid
  313. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  314. // published state is now handled by filter
  315. . "\n GROUP BY ev.ev_id";
  316. // This limit will always be enough
  317. $query .= " LIMIT ".$limit;
  318. */
  319. // Find the ones after now
  320. $query = "SELECT DISTINCT rpt.eventid FROM #__jevents_repetition as rpt"
  321. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  322. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  323. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  324. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  325. . $extrajoin
  326. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  327. // New equivalent but simpler test
  328. . "\n AND rpt.endrepeat >= '$t_datenowSQL' AND rpt.startrepeat <= '$enddate'"
  329. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  330. . "\n AND ((rpt.startrepeat >= '$t_datenowSQL' AND det.multiday=0) OR det.multiday=1)"
  331. . $extrawhere
  332. . "\n AND ev.access <= ".$user->aid
  333. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  334. // published state is now handled by filter
  335. . "\n AND rpt.startrepeat=(SELECT MIN(startrepeat) FROM #__jevents_repetition as rpt2 WHERE rpt2.eventid=rpt.eventid AND rpt2.startrepeat >= '$t_datenowSQL' AND rpt2.endrepeat <= '$enddate')"
  336. //. "\n GROUP BY rpt.eventid"
  337. . "\n ORDER BY rpt.startrepeat ASC"
  338. ;
  339. // This limit will always be enough
  340. $query .= " LIMIT ".$limit;
  341. $db = JFactory::getDBO();
  342. $db->setQuery($query);
  343. //echo $db->explain();
  344. //echo $db->_sql."<br/>";
  345. $ids1 = $db->loadResultArray();
  346. // Before now
  347. $query = "SELECT rpt.eventid FROM #__jevents_repetition as rpt"
  348. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  349. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  350. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  351. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  352. . $extrajoin
  353. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  354. // New equivalent but simpler test
  355. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$t_datenowSQL'"
  356. // We only show events on their first day if they are not to be shown on multiple days so also add this condition
  357. . "\n AND ((rpt.startrepeat >= '$startdate' AND det.multiday=0) OR det.multiday=1)"
  358. . $extrawhere
  359. . "\n AND ev.access <= ".$user->aid
  360. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  361. // published state is now handled by filter
  362. . "\n AND rpt.startrepeat=(SELECT MAX(startrepeat) FROM #__jevents_repetition as rpt2 WHERE rpt2.eventid=rpt.eventid AND rpt2.startrepeat <= '$t_datenowSQL' AND rpt2.startrepeat >= '$startdate')"
  363. . "\n GROUP BY rpt.eventid "
  364. . "\n ORDER BY rpt.startrepeat DESC"
  365. ;
  366. // This limit will always be enough
  367. $query .= " LIMIT ".$limit;
  368. $db = JFactory::getDBO();
  369. $db->setQuery($query);
  370. //echo $db->explain();die();
  371. //echo $db->_sql; die();
  372. $ids2 = $db->loadResultArray();
  373. $ids = array_merge($ids1, $ids2);
  374. array_push($ids,0);
  375. $ids = array_unique($ids);
  376. // As an alternative to avoid the temporary table we could use php array_unique and array_slice to get the list of ids - with no memory issues.
  377. $ids = implode(",",$ids);
  378. $groupby = "\n GROUP BY rpt.rp_id";
  379. if ($noRepeats) $groupby = "\n GROUP BY ev.ev_id";
  380. // This version picks the details from the details table
  381. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  382. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  383. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  384. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  385. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  386. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  387. . "\n FROM #__jevents_repetition as rpt"
  388. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  389. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  390. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  391. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  392. . $extrajoin
  393. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  394. // New equivalent but simpler test
  395. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  396. . $extrawhere
  397. . "\n AND ev.access <= ".$user->aid
  398. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  399. . " AND ev.ev_id IN (".$ids.")"
  400. // published state is now handled by filter
  401. . ($needsgroup?$groupby:"");
  402. ;
  403. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  404. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  405. $dispatcher =& JDispatcher::getInstance();
  406. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  407. return $rows;
  408. }
  409. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  410. function listIcalEvents($startdate,$enddate, $order="", $filters = false, $extrafields="", $extratables="", $limit=""){
  411. $user =& JFactory::getUser();
  412. $db =& JFactory::getDBO();
  413. $lang =& JFactory::getLanguage();
  414. $langtag = $lang->getTag();
  415. if (strpos($startdate,"-")===false) {
  416. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  417. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  418. }
  419. // process the new plugins
  420. // get extra data and conditionality from plugins
  421. $extrawhere =array();
  422. $extrajoin = array();
  423. // $extrafields = ""; // must have comma prefix
  424. // $extratables = ""; // must have comma prefix
  425. $needsgroup = false;
  426. if (!$filters){
  427. $filterarray = array("published","justmine","category","search");
  428. // If there are extra filters from the module then apply them now
  429. $reg =& JFactory::getConfig();
  430. $modparams = $reg->getValue("jev.modparams",false);
  431. if ($modparams && $modparams->getValue("extrafilters",false)){
  432. $filterarray = array_merge($filterarray, explode(",",$modparams->getValue("extrafilters",false)));
  433. }
  434. $filters = jevFilterProcessing::getInstance($filterarray);
  435. $filters->setWhereJoin($extrawhere,$extrajoin );
  436. $needsgroup = $filters->needsGroupBy();
  437. $dispatcher =& JDispatcher::getInstance();
  438. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  439. // What if join multiplies the rows?
  440. // Useful MySQL link http://forums.mysql.com/read.php?10,228378,228492#msg-228492
  441. // concat with group
  442. // http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
  443. }
  444. else {
  445. $filters->setWhereJoin($extrawhere,$extrajoin);
  446. }
  447. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  448. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  449. // This version picks the details from the details table
  450. // ideally we should check if the event is a repeat but this involves extra queries unfortunately
  451. $query = "SELECT rpt.*, ev.*, rr.*, det.*, ev.state as published, ev.created as created $extrafields"
  452. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  453. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  454. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  455. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  456. . "\n FROM #__jevents_repetition as rpt"
  457. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  458. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  459. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  460. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  461. . $extrajoin
  462. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  463. // New equivalent but simpler test
  464. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  465. /*
  466. . "\n AND ((rpt.startrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate')"
  467. . "\n OR (rpt.endrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  468. // This is redundant!!
  469. //. "\n OR (rpt.startrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  470. // This slows the query down
  471. . "\n OR (rpt.startrepeat <= '$startdate' AND rpt.endrepeat >= '$enddate')"
  472. . "\n )"
  473. */
  474. // Radical alternative - seems slower though
  475. /*
  476. . "\n WHERE rpt.rp_id IN (SELECT rbd.rp_id
  477. FROM jos_jevents_repbyday as rbd
  478. WHERE rbd.catid IN(".$this->accessibleCategoryList().")
  479. AND rbd.rptday >= '$startdate' AND rbd.rptday <= '$enddate' )"
  480. */
  481. . $extrawhere
  482. . "\n AND ev.access <= ".$user->aid
  483. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  484. // published state is now handled by filter
  485. //. "\n AND ev.state=1"
  486. . ($needsgroup?"\n GROUP BY rpt.rp_id":"")
  487. ;
  488. if ($order !="") {
  489. $query .= " ORDER BY ".$order;
  490. }
  491. if ($limit !="") {
  492. $query .= " LIMIT ".$limit;
  493. }
  494. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  495. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag );
  496. $dispatcher =& JDispatcher::getInstance();
  497. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  498. //rint_r($rows)
  499. return $rows;
  500. }
  501. function _cachedlistIcalEvents($query, $langtag,$count=false){
  502. $db =& JFactory::getDBO();
  503. $db->setQuery( $query );
  504. $user = JFactory::getUser();
  505. if ($user->usertype=="Super Administrator"){
  506. //echo $db->_sql;
  507. //echo $db->explain();
  508. }
  509. //echo $db->_sql;
  510. if ($count){
  511. $db->query();
  512. return $db->getNumRows();
  513. }
  514. $icalrows = $db->loadObjectList();
  515. if ($user->usertype=="Super Administrator"){
  516. echo $db->getErrorMsg();
  517. }
  518. $icalcount = count($icalrows);
  519. $valid = true;
  520. for( $i = 0; $i < $icalcount ; $i++ ){
  521. // only convert rows when necessary
  522. if ($i==0 && count(get_object_vars($icalrows[$i]))<5) {
  523. $valid = false;
  524. break;
  525. }
  526. // convert rows to jIcalEvents
  527. $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]);
  528. }
  529. if (!$valid) return $icalrows;
  530. $dispatcher =& JDispatcher::getInstance();
  531. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRow', array( &$icalrows ));
  532. return $icalrows;
  533. }
  534. function listEventsByDateNEW( $select_date ){
  535. return $this->listEvents($select_date." 00:00:00",$select_date." 23:59:59");
  536. }
  537. function listIcalEventsByDay($targetdate){
  538. // targetdate is midnight at start of day - but just in case
  539. list ($y,$m,$d) = explode(":",strftime( '%Y:%m:%d',$targetdate));
  540. $startdate = mktime( 0, 0, 0, $m, $d, $y );
  541. $enddate = mktime( 23, 59, 59, $m, $d, $y );
  542. return $this->listIcalEvents($startdate,$enddate);
  543. }
  544. function listEventsByWeekNEW( $weekstart, $weekend){
  545. return $this->listEvents($weekstart, $weekend);
  546. }
  547. function listIcalEventsByWeek( $weekstart, $weekend){
  548. return $this->listIcalEvents( $weekstart, $weekend);
  549. }
  550. function listEventsByMonthNew( $year, $month, $order){
  551. $db =& JFactory::getDBO();
  552. $month = str_pad($month, 2, '0', STR_PAD_LEFT);
  553. $select_date = $year.'-'.$month.'-01 00:00:00';
  554. $select_date_fin = $year.'-'.$month.'-'.date('t',mktime(0,0,0,($month+1),0,$year)).' 23:59:59';
  555. return $this->listEvents($select_date,$select_date_fin,$order);
  556. }
  557. function listIcalEventsByMonth( $year, $month){
  558. $startdate = mktime( 0, 0, 0, $month, 1, $year );
  559. $enddate = mktime( 23, 59, 59, $month, date( 't', $startdate), $year );
  560. return $this->listIcalEvents($startdate,$enddate,"");
  561. }
  562. function listEventsByYearNEW( $year, $limitstart=0, $limit=0 ) {
  563. if (!$this->legacyEvents) {
  564. return array();
  565. }
  566. }
  567. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  568. function listIcalEventsByYear( $year, $limitstart, $limit, $showrepeats = true, $order="", $filters = false, $extrafields="", $extratables="", $count=false) {
  569. list($xyear,$month,$day) = JEVHelper::getYMD();
  570. $thisyear = new JDate("+0 seconds");
  571. list($thisyear,$thismonth,$thisday) = explode("-",$thisyear->toFormat("%Y-%m-%d"));
  572. if (!$this->cfg->getValue("showyearpast",1) && $year<$thisyear){
  573. return array();
  574. }
  575. $startdate = ($this->cfg->getValue("showyearpast",1) || $year>$thisyear)?mktime( 0, 0, 0, 1, 1, $year ):mktime( 0, 0, 0,$thismonth,$thisday, $thisyear );
  576. $enddate = mktime( 23, 59, 59, 12, 31, $year );
  577. if (!$count){
  578. $order = "rpt.startrepeat asc";
  579. }
  580. $user =& JFactory::getUser();
  581. $db =& JFactory::getDBO();
  582. $lang =& JFactory::getLanguage();
  583. $langtag = $lang->getTag();
  584. if (strpos($startdate,"-")===false) {
  585. $startdate = strftime('%Y-%m-%d 00:00:00',$startdate);
  586. $enddate = strftime('%Y-%m-%d 23:59:59',$enddate);
  587. }
  588. // process the new plugins
  589. // get extra data and conditionality from plugins
  590. $extrawhere =array();
  591. $extrajoin = array();
  592. $extrafields = ""; // must have comma prefix
  593. $extratables = ""; // must have comma prefix
  594. $needsgroup = false;
  595. if (!$filters){
  596. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","search"));
  597. $filters->setWhereJoin($extrawhere,$extrajoin);
  598. $needsgroup = $filters->needsGroupBy();
  599. $dispatcher =& JDispatcher::getInstance();
  600. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  601. }
  602. else {
  603. $filters->setWhereJoin($extrawhere,$extrajoin);
  604. }
  605. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  606. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  607. // This version picks the details from the details table
  608. if ($count){
  609. $query = "SELECT rpt.rp_id";
  610. }
  611. else {
  612. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  613. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  614. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  615. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  616. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn";
  617. }
  618. $query .= "\n FROM #__jevents_repetition as rpt"
  619. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  620. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  621. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  622. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  623. . $extrajoin
  624. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  625. // New equivalent but simpler test
  626. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  627. /*
  628. . "\n AND ((rpt.startrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate')"
  629. . "\n OR (rpt.endrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  630. //. "\n OR (rpt.startrepeat >= '$startdate' AND rpt.endrepeat <= '$enddate')"
  631. . "\n OR (rpt.startrepeat <= '$startdate' AND rpt.endrepeat >= '$enddate'))"
  632. */
  633. . $extrawhere
  634. . "\n AND ev.access <= ".$user->aid
  635. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  636. // published state is not handled by filter
  637. //. "\n AND ev.state=1"
  638. ;
  639. if (!$showrepeats){
  640. $query .="\n GROUP BY ev.ev_id";
  641. }
  642. else if ($needsgroup){
  643. $query .="\n GROUP BY rpt.rp_id";
  644. }
  645. if ($order !="") {
  646. $query .= " ORDER BY ".$order;
  647. }
  648. if ($limit !="" && $limit!=0) {
  649. $query .= " LIMIT ".($limitstart!=""?$limitstart.",":"").$limit;
  650. }
  651. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  652. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag, $count );
  653. if (!$count){
  654. $dispatcher =& JDispatcher::getInstance();
  655. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  656. }
  657. return $rows;
  658. }
  659. // Allow the passing of filters directly into this function for use in 3rd party extensions etc.
  660. function listIcalEventsByRange( $startdate, $enddate, $limitstart, $limit, $showrepeats = true, $order = "rpt.startrepeat asc, rpt.endrepeat ASC, det.summary ASC", $filters = false, $extrafields="", $extratables="", $count=false) {
  661. /* Saturday and sunday date session varialbe by Yogi */
  662. $_SESSION['saturday_date'] = $startdate;
  663. $_SESSION['sunday_date'] = $enddate;
  664. list($year, $month, $day) = explode('-', $startdate);
  665. list($thisyear, $thismonth, $thisday) = JEVHelper::getYMD();
  666. //$startdate = $this->cfg->getValue("showyearpast",1)?mktime( 0, 0, 0, intval($month),intval($day),intval($year) ):mktime( 0, 0, 0, $thismonth,$thisday, $thisyear );
  667. $startdate =mktime( 0, 0, 0, intval($month),intval($day),intval($year) );
  668. $startdate = strftime('%Y-%m-%d',$startdate);
  669. if (strlen($startdate)==10) $startdate.= " 00:00:00";
  670. if (strlen($enddate)==10) $enddate.= " 23:59:59";
  671. // This code is used by the iCals code with a spoofed user so check if this is what is happening
  672. if (JRequest::getString("jevtask","")=="icals.export"){
  673. $registry =& JRegistry::getInstance("jevents");
  674. $user = $registry->getValue("jevents.icaluser",false);
  675. if (!$user) $user = JFactory::getUser();
  676. }
  677. else {
  678. $user = JFactory::getUser();
  679. }
  680. $db =& JFactory::getDBO();
  681. $lang =& JFactory::getLanguage();
  682. $langtag = $lang->getTag();
  683. // process the new plugins
  684. // get extra data and conditionality from plugins
  685. $extrawhere =array();
  686. $extrajoin = array();
  687. $extrafields = ""; // must have comma prefix
  688. $extratables = ""; // must have comma prefix
  689. $needsgroup = false;
  690. if (!$filters){
  691. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","search"));
  692. $filters->setWhereJoin($extrawhere,$extrajoin);
  693. $needsgroup = $filters->needsGroupBy();
  694. $dispatcher =& JDispatcher::getInstance();
  695. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  696. }
  697. else {
  698. $filters->setWhereJoin($extrawhere,$extrajoin);
  699. }
  700. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  701. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  702. // This version picks the details from the details table
  703. if ($count){
  704. $query = "SELECT rpt.rp_id";
  705. }
  706. else {
  707. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  708. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  709. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  710. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  711. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn";
  712. }
  713. $query .= "\n FROM #__jevents_repetition as rpt"
  714. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  715. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  716. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  717. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  718. . $extrajoin
  719. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  720. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  721. // Must suppress multiday events that have already started
  722. . "\n AND NOT (rpt.startrepeat < '$startdate' AND det.multiday=0) "
  723. . $extrawhere
  724. . "\n AND ev.access <= ".$user->aid
  725. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  726. ;
  727. if (!$showrepeats){
  728. $query .="\n GROUP BY ev.ev_id";
  729. }
  730. else if ($needsgroup){
  731. $query .="\n GROUP BY rpt.rp_id";
  732. }
  733. if ($order !="") {
  734. $query .= " ORDER BY ".$order;
  735. }
  736. if ($limit !="" && $limit!=0) {
  737. $query .= " LIMIT ".($limitstart!=""?$limitstart.",":"").$limit;
  738. }
  739. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  740. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag, $count );
  741. $dispatcher =& JDispatcher::getInstance();
  742. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  743. return $rows;
  744. }
  745. function countIcalEventsByYear( $year,$showrepeats = true) {
  746. $startdate = mktime( 0, 0, 0, 1, 1, $year );
  747. $enddate = mktime( 23, 59, 59, 12, 31, $year );
  748. return $this->listIcalEventsByYear($year,"","",$showrepeats,"",false,"","",true);
  749. }
  750. function countIcalEventsByRange( $startdate, $enddate,$showrepeats = true) {
  751. return $this->listIcalEventsByRange($startdate, $enddate,"","",$showrepeats,"",false,"","",true);
  752. }
  753. function listEventsById( $rpid, $includeUnpublished=0, $jevtype="icaldb" ) {
  754. $user =& JFactory::getUser();
  755. $db =& JFactory::getDBO();
  756. $frontendPublish = JEVHelper::isEventPublisher();
  757. if ($jevtype=="icaldb"){
  758. // process the new plugins
  759. // get extra data and conditionality from plugins
  760. $extrafields = ""; // must have comma prefix
  761. $extratables = ""; // must have comma prefix
  762. $extrawhere =array();
  763. $extrajoin = array();
  764. $dispatcher =& JDispatcher::getInstance();
  765. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  766. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  767. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  768. $query = "SELECT ev.*, ev.state as published, rpt.*, rr.*, det.* $extrafields, ev.created as created "
  769. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  770. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  771. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  772. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  773. . "\n FROM (#__jevents_vevent as ev $extratables)"
  774. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  775. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  776. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  777. . $extrajoin
  778. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  779. . "\n AND ev.access <= ".$user->aid
  780. . $extrawhere
  781. . "\n AND rpt.rp_id = '$rpid'";
  782. $query .="\n GROUP BY rpt.rp_id";
  783. }
  784. else {
  785. die("invalid jevtype in listEventsById - more changes needed");
  786. }
  787. $db->setQuery( $query );
  788. //echo $db->_sql;
  789. $rows = $db->loadObjectList();
  790. // iCal agid uses GUID or UUID as identifier
  791. if( $rows ){
  792. if (strtolower($jevtype)=="icaldb"){
  793. $row = new jIcalEventRepeat($rows[0]);
  794. }
  795. else if (strtolower($jevtype)=="jevent"){
  796. $row = new jEventCal($rows[0]);
  797. }
  798. }else{
  799. $row=null;
  800. }
  801. return $row;
  802. }
  803. /**
  804. * Get Event by ID (not repeat Id) result is based on first repeat
  805. *
  806. * @param event_id $evid
  807. * @param boolean $includeUnpublished
  808. * @param string $jevtype
  809. * @return jeventcal (or desencent)
  810. */
  811. function getEventById( $evid, $includeUnpublished=0, $jevtype="icaldb" ) {
  812. $user =& JFactory::getUser();
  813. $db =& JFactory::getDBO();
  814. $frontendPublish = JEVHelper::isEventPublisher();
  815. if ($jevtype=="icaldb"){
  816. // process the new plugins
  817. // get extra data and conditionality from plugins
  818. $extrafields = ""; // must have comma prefix
  819. $extratables = ""; // must have comma prefix
  820. $extrawhere =array();
  821. $extrajoin = array();
  822. $dispatcher =& JDispatcher::getInstance();
  823. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  824. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  825. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  826. // make sure we pick up the event state
  827. $query = "SELECT ev.*, rpt.*, rr.*, det.* $extrafields , ev.state as state "
  828. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  829. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  830. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  831. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  832. . "\n FROM (#__jevents_vevent as ev $extratables)"
  833. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  834. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  835. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  836. . $extrajoin
  837. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  838. . "\n AND ev.access <= ".$user->aid
  839. . $extrawhere
  840. . "\n AND ev.ev_id = '$evid'"
  841. . "\n GROUP BY rpt.rp_id"
  842. . "\n LIMIT 1";
  843. }
  844. else {
  845. die("invalid jevtype in listEventsById - more changes needed");
  846. }
  847. $db->setQuery( $query );
  848. //echo $db->_sql;
  849. $rows = $db->loadObjectList();
  850. // iCal agid uses GUID or UUID as identifier
  851. if( $rows ){
  852. if (strtolower($jevtype)=="icaldb"){
  853. $row = new jIcalEventRepeat($rows[0]);
  854. }
  855. else if (strtolower($jevtype)=="jevent"){
  856. $row = new jEventCal($rows[0]);
  857. }
  858. }else{
  859. $row=null;
  860. }
  861. return $row;
  862. }
  863. function listEventsByCreator( $creator_id, $limitstart, $limit ){
  864. if (!$this->legacyEvents) {
  865. return array();
  866. }
  867. }
  868. function listIcalEventsByCreator ( $creator_id, $limitstart, $limit, $orderby='dtstart ASC'){
  869. $user =& JFactory::getUser();
  870. $db =& JFactory::getDBO();
  871. $cfg = & JEVConfig::getInstance();
  872. $rows_per_page = $limit;
  873. if( empty( $limitstart) || !$limitstart ){
  874. $limitstart = 0;
  875. }
  876. $limit = "";
  877. if ($limitstart>0 || $rows_per_page>0){
  878. $limit = "LIMIT $limitstart, $rows_per_page";
  879. }
  880. $frontendPublish = JEVHelper::isEventPublisher();
  881. $adminCats = JEVHelper::categoryAdmin();
  882. $where = '';
  883. if( $creator_id == 'ADMIN' ){
  884. $where = "";
  885. }
  886. else if ( $adminCats && count($adminCats)>0){
  887. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  888. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  889. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  890. }
  891. else {
  892. $where = " AND ev.created_by = '$creator_id' ";
  893. }
  894. // State is manged by plugin
  895. /*
  896. $state = "\n AND ev.state=1";
  897. if ($frontendPublish){
  898. $state = "";
  899. }
  900. */
  901. // process the new plugins
  902. // get extra data and conditionality from plugins
  903. $extrawhere =array();
  904. $extrajoin = array();
  905. $extrafields = ""; // must have comma prefix
  906. $extratables = ""; // must have comma prefix
  907. $needsgroup = false;
  908. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  909. $filters->setWhereJoin($extrawhere,$extrajoin);
  910. $needsgroup = false;
  911. $dispatcher =& JDispatcher::getInstance();
  912. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  913. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  914. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  915. $query = "SELECT ev.*, rr.*, det.*, ev.state as published, count(rpt.rp_id) as rptcount $extrafields"
  916. . "\n , YEAR(dtstart) as yup, MONTH(dtstart ) as mup, DAYOFMONTH(dtstart ) as dup"
  917. . "\n , YEAR(dtend ) as ydn, MONTH(dtend ) as mdn, DAYOFMONTH(dtend ) as ddn"
  918. . "\n , HOUR(dtstart) as hup, MINUTE(dtstart) as minup, SECOND(dtstart ) as sup"
  919. . "\n , HOUR(dtend ) as hdn, MINUTE(dtend ) as mindn, SECOND(dtend ) as sdn"
  920. . "\n FROM #__jevents_vevent as ev"
  921. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  922. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  923. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = ev.detail_id"
  924. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  925. . $extrajoin
  926. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  927. . $extrawhere
  928. . $where
  929. //. "\n AND ev.access <= ".$user->aid
  930. . "\n AND icsf.state=1"
  931. . "\n GROUP BY ev.ev_id"
  932. . "\n ORDER BY "
  933. .$orderby//fixed
  934. . "\n $limit";
  935. $db->setQuery( $query );
  936. //echo $db->explain();
  937. $icalrows = $db->loadObjectList();
  938. echo $db->getErrorMsg();
  939. $icalcount = count($icalrows);
  940. for( $i = 0; $i < $icalcount ; $i++ ){
  941. // convert rows to jIcalEvents
  942. $icalrows[$i] = new jIcalEventDB($icalrows[$i]);
  943. }
  944. return $icalrows;
  945. }
  946. function listIcalEventRepeatsByCreator ( $creator_id, $limitstart, $limit, $orderby='rpt.startrepeat'){
  947. $user =& JFactory::getUser();
  948. $db =& JFactory::getDBO();
  949. $cfg = & JEVConfig::getInstance();
  950. $rows_per_page = $limit;
  951. if( empty( $limitstart) || !$limitstart ){
  952. $limitstart = 0;
  953. }
  954. $limit = "";
  955. if ($limitstart>0 || $rows_per_page>0){
  956. $limit = "LIMIT $limitstart, $rows_per_page";
  957. }
  958. $adminCats = JEVHelper::categoryAdmin();
  959. $where = '';
  960. if( $creator_id == 'ADMIN' ){
  961. $where = "";
  962. }
  963. else if ( $adminCats && count($adminCats)>0){
  964. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  965. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  966. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  967. }
  968. else {
  969. $where = " AND ev.created_by = '$creator_id' ";
  970. }
  971. $frontendPublish = JEVHelper::isEventPublisher();
  972. // process the new plugins
  973. // get extra data and conditionality from plugins
  974. $extrawhere =array();
  975. $extrajoin = array();
  976. $extrafields = ""; // must have comma prefix
  977. $extratables = ""; // must have comma prefix
  978. $needsgroup = false;
  979. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  980. $filters->setWhereJoin($extrawhere,$extrajoin);
  981. $needsgroup = false;
  982. $dispatcher =& JDispatcher::getInstance();
  983. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  984. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  985. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  986. if( $frontendPublish ){
  987. // TODO fine a single query way of doing this !!!
  988. $query = "SELECT rp_id"
  989. . "\n FROM #__jevents_repetition as rpt "
  990. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  991. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  992. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  993. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  994. . $extrajoin
  995. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  996. . $extrawhere
  997. . $where
  998. . "\n AND icsf.state=1"
  999. //. "\n AND ev.access <= ".$user->aid
  1000. . "\n GROUP BY rpt.rp_id"
  1001. . "\n ORDER BY "
  1002. .$orderby//fixed
  1003. . "\n $limit";
  1004. ;
  1005. $db->setQuery( $query );
  1006. $rplist = $db->loadResultArray();
  1007. //echo $db->explain();
  1008. $rplist = implode(',', array_merge(array(-1), $rplist));
  1009. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  1010. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  1011. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  1012. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  1013. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  1014. . "\n FROM #__jevents_vevent as ev "
  1015. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1016. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1017. . "\n AND rpt.eventid = ev.ev_id"
  1018. . "\n AND rpt.rp_id IN($rplist)"
  1019. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1020. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1021. . $extrajoin
  1022. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1023. . $extrawhere
  1024. . $where
  1025. . "\n AND icsf.state=1"
  1026. //. "\n AND ev.access <= ".$user->aid
  1027. . "\n GROUP BY rpt.rp_id"
  1028. . "\n ORDER BY "
  1029. .$orderby//fixed
  1030. ;
  1031. }
  1032. else {
  1033. // TODO fine a single query way of doing this !!!
  1034. $query = "SELECT rp_id"
  1035. . "\n FROM #__jevents_vevent as ev "
  1036. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1037. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1038. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1039. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1040. . $extrajoin
  1041. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1042. . $extrawhere
  1043. . "\n AND icsf.state=1"
  1044. . $where
  1045. //. "\n AND ev.access <= ".$user->aid
  1046. . "\n GROUP BY rpt.rp_id"
  1047. . "\n ORDER BY "
  1048. .$orderby//fixed
  1049. . "\n $limit";
  1050. ;
  1051. $db->setQuery( $query );
  1052. $rplist = $db->loadResultArray();
  1053. $rplist = implode(',', array_merge(array(-1), $rplist));
  1054. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published"
  1055. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  1056. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  1057. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  1058. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  1059. . "\n FROM #__jevents_vevent as ev "
  1060. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1061. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1062. . "\n AND rpt.rp_id IN($rplist)"
  1063. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1064. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1065. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1066. . $where
  1067. //. "\n AND ev.access <= ".$user->aid
  1068. . "\n AND icsf.state=1"
  1069. . "\n GROUP BY rpt.rp_id"
  1070. . "\n ORDER BY "
  1071. .$orderby//fixed
  1072. ;
  1073. }
  1074. $db->setQuery( $query );
  1075. $icalrows = $db->loadObjectList();
  1076. $icalcount = count($icalrows);
  1077. for( $i = 0; $i < $icalcount ; $i++ ){
  1078. // convert rows to jIcalEvents
  1079. $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]);
  1080. }
  1081. return $icalrows;
  1082. }
  1083. function countEventsByCreator($creator_id){
  1084. if (!$this->legacyEvents) {
  1085. return 0;
  1086. }
  1087. }
  1088. function countIcalEventsByCreator($creator_id){
  1089. $user =& JFactory::getUser();
  1090. $db =& JFactory::getDBO();
  1091. $adminCats = JEVHelper::categoryAdmin();
  1092. $where = '';
  1093. if( $creator_id == 'ADMIN' ){
  1094. $where = "";
  1095. }
  1096. else if ( $adminCats && count($adminCats)>0){
  1097. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  1098. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  1099. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  1100. }
  1101. else {
  1102. $where = " AND ev.created_by = '$creator_id' ";
  1103. }
  1104. // State is managed by plugin
  1105. /*
  1106. $frontendPublish = JEVHelper::isEventPublisher();
  1107. $state = "\n AND ev.state=1";
  1108. if ($frontendPublish){
  1109. $state = "";
  1110. }
  1111. */
  1112. // process the new plugins
  1113. // get extra data and conditionality from plugins
  1114. $extrawhere =array();
  1115. $extrajoin = array();
  1116. $extrafields = ""; // must have comma prefix
  1117. $extratables = ""; // must have comma prefix
  1118. $needsgroup = false;
  1119. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  1120. $filters->setWhereJoin($extrawhere,$extrajoin);
  1121. $needsgroup = false;
  1122. $dispatcher =& JDispatcher::getInstance();
  1123. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  1124. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  1125. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  1126. $query = "SELECT MIN(rpt.rp_id) as rp_id"
  1127. . "\n FROM #__jevents_vevent as ev "
  1128. .

Large files files are truncated, but you can click here to view the full file