PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_jevents/libraries/dbmodel.php

https://github.com/bhavan/newv1
PHP | 1862 lines | 1334 code | 292 blank | 236 comment | 163 complexity | 39a9a185407e40ed78009cd9cbef577b MD5 | raw file
Possible License(s): 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. list($year, $month, $day) = explode('-', $startdate);
  662. list($thisyear, $thismonth, $thisday) = JEVHelper::getYMD();
  663. //$startdate = $this->cfg->getValue("showyearpast",1)?mktime( 0, 0, 0, intval($month),intval($day),intval($year) ):mktime( 0, 0, 0, $thismonth,$thisday, $thisyear );
  664. $startdate =mktime( 0, 0, 0, intval($month),intval($day),intval($year) );
  665. $startdate = strftime('%Y-%m-%d',$startdate);
  666. if (strlen($startdate)==10) $startdate.= " 00:00:00";
  667. if (strlen($enddate)==10) $enddate.= " 23:59:59";
  668. // This code is used by the iCals code with a spoofed user so check if this is what is happening
  669. if (JRequest::getString("jevtask","")=="icals.export"){
  670. $registry =& JRegistry::getInstance("jevents");
  671. $user = $registry->getValue("jevents.icaluser",false);
  672. if (!$user) $user = JFactory::getUser();
  673. }
  674. else {
  675. $user = JFactory::getUser();
  676. }
  677. $db =& JFactory::getDBO();
  678. $lang =& JFactory::getLanguage();
  679. $langtag = $lang->getTag();
  680. // process the new plugins
  681. // get extra data and conditionality from plugins
  682. $extrawhere =array();
  683. $extrajoin = array();
  684. $extrafields = ""; // must have comma prefix
  685. $extratables = ""; // must have comma prefix
  686. $needsgroup = false;
  687. if (!$filters){
  688. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","search"));
  689. $filters->setWhereJoin($extrawhere,$extrajoin);
  690. $needsgroup = $filters->needsGroupBy();
  691. $dispatcher =& JDispatcher::getInstance();
  692. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  693. }
  694. else {
  695. $filters->setWhereJoin($extrawhere,$extrajoin);
  696. }
  697. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  698. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  699. // This version picks the details from the details table
  700. if ($count){
  701. $query = "SELECT rpt.rp_id";
  702. }
  703. else {
  704. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  705. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  706. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  707. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  708. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn";
  709. }
  710. $query .= "\n FROM #__jevents_repetition as rpt"
  711. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  712. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid "
  713. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  714. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = rpt.eventid"
  715. . $extrajoin
  716. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  717. . "\n AND rpt.endrepeat >= '$startdate' AND rpt.startrepeat <= '$enddate'"
  718. // Must suppress multiday events that have already started
  719. . "\n AND NOT (rpt.startrepeat < '$startdate' AND det.multiday=0) "
  720. . $extrawhere
  721. . "\n AND ev.access <= ".$user->aid
  722. . " AND icsf.state=1 AND icsf.access <= ".$user->aid
  723. ;
  724. if (!$showrepeats){
  725. $query .="\n GROUP BY ev.ev_id";
  726. }
  727. else if ($needsgroup){
  728. $query .="\n GROUP BY rpt.rp_id";
  729. }
  730. if ($order !="") {
  731. $query .= " ORDER BY ".$order;
  732. }
  733. if ($limit !="" && $limit!=0) {
  734. $query .= " LIMIT ".($limitstart!=""?$limitstart.",":"").$limit;
  735. }
  736. $cache=& JFactory::getCache(JEV_COM_COMPONENT);
  737. $rows = $cache->call('JEventsDBModel::_cachedlistIcalEvents', $query, $langtag, $count );
  738. $dispatcher =& JDispatcher::getInstance();
  739. $dispatcher->trigger( 'onDisplayCustomFieldsMultiRowUncached', array( &$rows ));
  740. return $rows;
  741. }
  742. function countIcalEventsByYear( $year,$showrepeats = true) {
  743. $startdate = mktime( 0, 0, 0, 1, 1, $year );
  744. $enddate = mktime( 23, 59, 59, 12, 31, $year );
  745. return $this->listIcalEventsByYear($year,"","",$showrepeats,"",false,"","",true);
  746. }
  747. function countIcalEventsByRange( $startdate, $enddate,$showrepeats = true) {
  748. return $this->listIcalEventsByRange($startdate, $enddate,"","",$showrepeats,"",false,"","",true);
  749. }
  750. function listEventsById( $rpid, $includeUnpublished=0, $jevtype="icaldb" ) {
  751. $user =& JFactory::getUser();
  752. $db =& JFactory::getDBO();
  753. $frontendPublish = JEVHelper::isEventPublisher();
  754. if ($jevtype=="icaldb"){
  755. // process the new plugins
  756. // get extra data and conditionality from plugins
  757. $extrafields = ""; // must have comma prefix
  758. $extratables = ""; // must have comma prefix
  759. $extrawhere =array();
  760. $extrajoin = array();
  761. $dispatcher =& JDispatcher::getInstance();
  762. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  763. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  764. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  765. $query = "SELECT ev.*, ev.state as published, rpt.*, rr.*, det.* $extrafields, ev.created as created "
  766. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  767. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  768. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  769. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  770. . "\n FROM (#__jevents_vevent as ev $extratables)"
  771. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  772. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  773. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  774. . $extrajoin
  775. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  776. . "\n AND ev.access <= ".$user->aid
  777. . $extrawhere
  778. . "\n AND rpt.rp_id = '$rpid'";
  779. $query .="\n GROUP BY rpt.rp_id";
  780. }
  781. else {
  782. die("invalid jevtype in listEventsById - more changes needed");
  783. }
  784. $db->setQuery( $query );
  785. //echo $db->_sql;
  786. $rows = $db->loadObjectList();
  787. // iCal agid uses GUID or UUID as identifier
  788. if( $rows ){
  789. if (strtolower($jevtype)=="icaldb"){
  790. $row = new jIcalEventRepeat($rows[0]);
  791. }
  792. else if (strtolower($jevtype)=="jevent"){
  793. $row = new jEventCal($rows[0]);
  794. }
  795. }else{
  796. $row=null;
  797. }
  798. return $row;
  799. }
  800. /**
  801. * Get Event by ID (not repeat Id) result is based on first repeat
  802. *
  803. * @param event_id $evid
  804. * @param boolean $includeUnpublished
  805. * @param string $jevtype
  806. * @return jeventcal (or desencent)
  807. */
  808. function getEventById( $evid, $includeUnpublished=0, $jevtype="icaldb" ) {
  809. $user =& JFactory::getUser();
  810. $db =& JFactory::getDBO();
  811. $frontendPublish = JEVHelper::isEventPublisher();
  812. if ($jevtype=="icaldb"){
  813. // process the new plugins
  814. // get extra data and conditionality from plugins
  815. $extrafields = ""; // must have comma prefix
  816. $extratables = ""; // must have comma prefix
  817. $extrawhere =array();
  818. $extrajoin = array();
  819. $dispatcher =& JDispatcher::getInstance();
  820. $dispatcher->trigger('onListEventsById', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin));
  821. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ".implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  822. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  823. // make sure we pick up the event state
  824. $query = "SELECT ev.*, rpt.*, rr.*, det.* $extrafields , ev.state as state "
  825. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  826. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  827. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  828. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  829. . "\n FROM (#__jevents_vevent as ev $extratables)"
  830. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  831. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  832. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  833. . $extrajoin
  834. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  835. . "\n AND ev.access <= ".$user->aid
  836. . $extrawhere
  837. . "\n AND ev.ev_id = '$evid'"
  838. . "\n GROUP BY rpt.rp_id"
  839. . "\n LIMIT 1";
  840. }
  841. else {
  842. die("invalid jevtype in listEventsById - more changes needed");
  843. }
  844. $db->setQuery( $query );
  845. //echo $db->_sql;
  846. $rows = $db->loadObjectList();
  847. // iCal agid uses GUID or UUID as identifier
  848. if( $rows ){
  849. if (strtolower($jevtype)=="icaldb"){
  850. $row = new jIcalEventRepeat($rows[0]);
  851. }
  852. else if (strtolower($jevtype)=="jevent"){
  853. $row = new jEventCal($rows[0]);
  854. }
  855. }else{
  856. $row=null;
  857. }
  858. return $row;
  859. }
  860. function listEventsByCreator( $creator_id, $limitstart, $limit ){
  861. if (!$this->legacyEvents) {
  862. return array();
  863. }
  864. }
  865. function listIcalEventsByCreator ( $creator_id, $limitstart, $limit, $orderby='dtstart ASC'){
  866. $user =& JFactory::getUser();
  867. $db =& JFactory::getDBO();
  868. $cfg = & JEVConfig::getInstance();
  869. $rows_per_page = $limit;
  870. if( empty( $limitstart) || !$limitstart ){
  871. $limitstart = 0;
  872. }
  873. $limit = "";
  874. if ($limitstart>0 || $rows_per_page>0){
  875. $limit = "LIMIT $limitstart, $rows_per_page";
  876. }
  877. $frontendPublish = JEVHelper::isEventPublisher();
  878. $adminCats = JEVHelper::categoryAdmin();
  879. $where = '';
  880. if( $creator_id == 'ADMIN' ){
  881. $where = "";
  882. }
  883. else if ( $adminCats && count($adminCats)>0){
  884. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  885. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  886. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  887. }
  888. else {
  889. $where = " AND ev.created_by = '$creator_id' ";
  890. }
  891. // State is manged by plugin
  892. /*
  893. $state = "\n AND ev.state=1";
  894. if ($frontendPublish){
  895. $state = "";
  896. }
  897. */
  898. // process the new plugins
  899. // get extra data and conditionality from plugins
  900. $extrawhere =array();
  901. $extrajoin = array();
  902. $extrafields = ""; // must have comma prefix
  903. $extratables = ""; // must have comma prefix
  904. $needsgroup = false;
  905. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  906. $filters->setWhereJoin($extrawhere,$extrajoin);
  907. $needsgroup = false;
  908. $dispatcher =& JDispatcher::getInstance();
  909. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  910. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  911. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  912. $query = "SELECT ev.*, rr.*, det.*, ev.state as published, count(rpt.rp_id) as rptcount $extrafields"
  913. . "\n , YEAR(dtstart) as yup, MONTH(dtstart ) as mup, DAYOFMONTH(dtstart ) as dup"
  914. . "\n , YEAR(dtend ) as ydn, MONTH(dtend ) as mdn, DAYOFMONTH(dtend ) as ddn"
  915. . "\n , HOUR(dtstart) as hup, MINUTE(dtstart) as minup, SECOND(dtstart ) as sup"
  916. . "\n , HOUR(dtend ) as hdn, MINUTE(dtend ) as mindn, SECOND(dtend ) as sdn"
  917. . "\n FROM #__jevents_vevent as ev"
  918. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  919. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  920. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = ev.detail_id"
  921. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  922. . $extrajoin
  923. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  924. . $extrawhere
  925. . $where
  926. //. "\n AND ev.access <= ".$user->aid
  927. . "\n AND icsf.state=1"
  928. . "\n GROUP BY ev.ev_id"
  929. . "\n ORDER BY "
  930. .$orderby//fixed
  931. . "\n $limit";
  932. $db->setQuery( $query );
  933. //echo $db->explain();
  934. $icalrows = $db->loadObjectList();
  935. echo $db->getErrorMsg();
  936. $icalcount = count($icalrows);
  937. for( $i = 0; $i < $icalcount ; $i++ ){
  938. // convert rows to jIcalEvents
  939. $icalrows[$i] = new jIcalEventDB($icalrows[$i]);
  940. }
  941. return $icalrows;
  942. }
  943. function listIcalEventRepeatsByCreator ( $creator_id, $limitstart, $limit, $orderby='rpt.startrepeat'){
  944. $user =& JFactory::getUser();
  945. $db =& JFactory::getDBO();
  946. $cfg = & JEVConfig::getInstance();
  947. $rows_per_page = $limit;
  948. if( empty( $limitstart) || !$limitstart ){
  949. $limitstart = 0;
  950. }
  951. $limit = "";
  952. if ($limitstart>0 || $rows_per_page>0){
  953. $limit = "LIMIT $limitstart, $rows_per_page";
  954. }
  955. $adminCats = JEVHelper::categoryAdmin();
  956. $where = '';
  957. if( $creator_id == 'ADMIN' ){
  958. $where = "";
  959. }
  960. else if ( $adminCats && count($adminCats)>0){
  961. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  962. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  963. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  964. }
  965. else {
  966. $where = " AND ev.created_by = '$creator_id' ";
  967. }
  968. $frontendPublish = JEVHelper::isEventPublisher();
  969. // process the new plugins
  970. // get extra data and conditionality from plugins
  971. $extrawhere =array();
  972. $extrajoin = array();
  973. $extrafields = ""; // must have comma prefix
  974. $extratables = ""; // must have comma prefix
  975. $needsgroup = false;
  976. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  977. $filters->setWhereJoin($extrawhere,$extrajoin);
  978. $needsgroup = false;
  979. $dispatcher =& JDispatcher::getInstance();
  980. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  981. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  982. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  983. if( $frontendPublish ){
  984. // TODO fine a single query way of doing this !!!
  985. $query = "SELECT rp_id"
  986. . "\n FROM #__jevents_repetition as rpt "
  987. . "\n LEFT JOIN #__jevents_vevent as ev ON rpt.eventid = ev.ev_id"
  988. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  989. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  990. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  991. . $extrajoin
  992. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  993. . $extrawhere
  994. . $where
  995. . "\n AND icsf.state=1"
  996. //. "\n AND ev.access <= ".$user->aid
  997. . "\n GROUP BY rpt.rp_id"
  998. . "\n ORDER BY "
  999. .$orderby//fixed
  1000. . "\n $limit";
  1001. ;
  1002. $db->setQuery( $query );
  1003. $rplist = $db->loadResultArray();
  1004. //echo $db->explain();
  1005. $rplist = implode(',', array_merge(array(-1), $rplist));
  1006. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published $extrafields"
  1007. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  1008. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  1009. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  1010. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  1011. . "\n FROM #__jevents_vevent as ev "
  1012. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1013. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1014. . "\n AND rpt.eventid = ev.ev_id"
  1015. . "\n AND rpt.rp_id IN($rplist)"
  1016. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1017. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1018. . $extrajoin
  1019. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1020. . $extrawhere
  1021. . $where
  1022. . "\n AND icsf.state=1"
  1023. //. "\n AND ev.access <= ".$user->aid
  1024. . "\n GROUP BY rpt.rp_id"
  1025. . "\n ORDER BY "
  1026. .$orderby//fixed
  1027. ;
  1028. }
  1029. else {
  1030. // TODO fine a single query way of doing this !!!
  1031. $query = "SELECT rp_id"
  1032. . "\n FROM #__jevents_vevent as ev "
  1033. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1034. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1035. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1036. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1037. . $extrajoin
  1038. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1039. . $extrawhere
  1040. . "\n AND icsf.state=1"
  1041. . $where
  1042. //. "\n AND ev.access <= ".$user->aid
  1043. . "\n GROUP BY rpt.rp_id"
  1044. . "\n ORDER BY "
  1045. .$orderby//fixed
  1046. . "\n $limit";
  1047. ;
  1048. $db->setQuery( $query );
  1049. $rplist = $db->loadResultArray();
  1050. $rplist = implode(',', array_merge(array(-1), $rplist));
  1051. $query = "SELECT ev.*, rpt.*, rr.*, det.*, ev.state as published"
  1052. . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup"
  1053. . "\n , YEAR(rpt.endrepeat ) as ydn, MONTH(rpt.endrepeat ) as mdn, DAYOFMONTH(rpt.endrepeat ) as ddn"
  1054. . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup"
  1055. . "\n , HOUR(rpt.endrepeat ) as hdn, MINUTE(rpt.endrepeat ) as mindn, SECOND(rpt.endrepeat ) as sdn"
  1056. . "\n FROM #__jevents_vevent as ev "
  1057. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1058. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1059. . "\n AND rpt.rp_id IN($rplist)"
  1060. . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id"
  1061. . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id"
  1062. . "\n WHERE ev.catid IN(".$this->accessibleCategoryList().")"
  1063. . $where
  1064. //. "\n AND ev.access <= ".$user->aid
  1065. . "\n AND icsf.state=1"
  1066. . "\n GROUP BY rpt.rp_id"
  1067. . "\n ORDER BY "
  1068. .$orderby//fixed
  1069. ;
  1070. }
  1071. $db->setQuery( $query );
  1072. $icalrows = $db->loadObjectList();
  1073. $icalcount = count($icalrows);
  1074. for( $i = 0; $i < $icalcount ; $i++ ){
  1075. // convert rows to jIcalEvents
  1076. $icalrows[$i] = new jIcalEventRepeat($icalrows[$i]);
  1077. }
  1078. return $icalrows;
  1079. }
  1080. function countEventsByCreator($creator_id){
  1081. if (!$this->legacyEvents) {
  1082. return 0;
  1083. }
  1084. }
  1085. function countIcalEventsByCreator($creator_id){
  1086. $user =& JFactory::getUser();
  1087. $db =& JFactory::getDBO();
  1088. $adminCats = JEVHelper::categoryAdmin();
  1089. $where = '';
  1090. if( $creator_id == 'ADMIN' ){
  1091. $where = "";
  1092. }
  1093. else if ( $adminCats && count($adminCats)>0){
  1094. //$adminCats = " OR (ev.state=0 AND ev.catid IN(".implode(",",$adminCats)."))";
  1095. $adminCats = " OR ev.catid IN(".implode(",",$adminCats).")";
  1096. $where = " AND ( ev.created_by = ".$user->id. $adminCats. ")";
  1097. }
  1098. else {
  1099. $where = " AND ev.created_by = '$creator_id' ";
  1100. }
  1101. // State is managed by plugin
  1102. /*
  1103. $frontendPublish = JEVHelper::isEventPublisher();
  1104. $state = "\n AND ev.state=1";
  1105. if ($frontendPublish){
  1106. $state = "";
  1107. }
  1108. */
  1109. // process the new plugins
  1110. // get extra data and conditionality from plugins
  1111. $extrawhere =array();
  1112. $extrajoin = array();
  1113. $extrafields = ""; // must have comma prefix
  1114. $extratables = ""; // must have comma prefix
  1115. $needsgroup = false;
  1116. $filters = jevFilterProcessing::getInstance(array("published","justmine","category","startdate","search"));
  1117. $filters->setWhereJoin($extrawhere,$extrajoin);
  1118. $needsgroup = false;
  1119. $dispatcher =& JDispatcher::getInstance();
  1120. $dispatcher->trigger('onListIcalEvents', array (& $extrafields, & $extratables, & $extrawhere, & $extrajoin, & $needsgroup));
  1121. $extrajoin = ( count( $extrajoin ) ? " \n LEFT JOIN ". implode( " \n LEFT JOIN ", $extrajoin ) : '' );
  1122. $extrawhere = ( count( $extrawhere ) ? ' AND '. implode( ' AND ', $extrawhere ) : '' );
  1123. $query = "SELECT MIN(rpt.rp_id) as rp_id"
  1124. . "\n FROM #__jevents_vevent as ev "
  1125. . "\n LEFT JOIN #__jevents_icsfile as icsf ON icsf.ics_id=ev.icsid"
  1126. . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id"
  1127. . "\n L…

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