function getStamp($params) { $iCparams = JComponentHelper::getParams('com_icagenda'); $eventTimeZone = null; // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID) $iC_list_menus = icagendaMenus::iClistMenuItemsInfo(); $nb_menu = count($iC_list_menus); $nolink = $nb_menu ? false : true; $app = JFactory::getApplication(); $menu = $app->getMenu(); $isSef = $app->getCfg('sef'); $date_var = $isSef == 1 ? '?date=' : '&date='; // Check if GD is enabled on the server if (extension_loaded('gd') && function_exists('gd_info')) { $thumb_generator = $iCparams->get('thumb_generator', 1); } else { $thumb_generator = 0; } $datetime_today = JHtml::date('now', 'Y-m-d H:i'); $timeformat = $iCparams->get('timeformat', 1); $lang_time = $timeformat == 1 ? 'H:i' : 'h:i A'; // Check if fopen is allowed $result = ini_get('allow_url_fopen'); $fopen = empty($result) ? false : true; $this->start($params); // Get the database $db = JFactory::getDbo(); $query = $db->getQuery(true); // Build the query $query->select('e.*, e.place as place_name, c.title as cat_title, c.alias as cat_alias, c.color as cat_color, c.ordering as cat_order ')->from($db->qn('#__icagenda_events') . ' AS e')->leftJoin($db->qn('#__icagenda_category') . ' AS c ON ' . $db->qn('c.id') . ' = ' . $db->qn('e.catid')); // Where Category is Published $query->where('c.state = 1'); // Where State is Published $query->where('e.state = 1'); // Where event is Approved $query->where('e.approval = 0'); // Add filters if (isset($this->filter)) { foreach ($this->filter as $filter) { $query->where($filter); } } // Check Access Levels $user = JFactory::getUser(); $userID = $user->id; $userLevels = $user->getAuthorisedViewLevels(); if (version_compare(JVERSION, '3.0', 'lt')) { $userGroups = $user->getAuthorisedGroups(); } else { $userGroups = $user->groups; } $userAccess = implode(', ', $userLevels); if (!in_array('8', $userGroups)) { $query->where('e.access IN (' . $userAccess . ')'); } // Features - extract the number of displayable icons per event $query->select('feat.count AS features'); $sub_query = $db->getQuery(true); $sub_query->select('fx.event_id, COUNT(*) AS count'); $sub_query->from('`#__icagenda_feature_xref` AS fx'); $sub_query->innerJoin("`#__icagenda_feature` AS f ON fx.feature_id=f.id AND f.state=1 AND f.icon<>'-1'"); $sub_query->group('fx.event_id'); $query->leftJoin('(' . (string) $sub_query . ') AS feat ON e.id=feat.event_id'); // Registrations total $query->select('r.count AS registered, r.date AS reg_date'); $sub_query = $db->getQuery(true); $sub_query->select('r.eventid, sum(r.people) AS count, r.date AS date'); $sub_query->from('`#__icagenda_registration` AS r'); $sub_query->where('r.state > 0'); $sub_query->group('r.eventid'); $query->leftJoin('(' . (string) $sub_query . ') AS r ON e.id=r.eventid'); // Run the query $db->setQuery($query); // Invoke the query $result = $db->loadObjectList(); $registrations = icagendaEventsData::registeredList(); foreach ($result as $record) { $record_registered = array(); foreach ($registrations as $reg_by_event) { $ex_reg_by_event = explode('@@', $reg_by_event); if ($ex_reg_by_event[0] == $record->id) { $record_registered[] = $ex_reg_by_event[0] . '@@' . $ex_reg_by_event[1] . '@@' . $ex_reg_by_event[2]; } } $record->registered = $record_registered; } // Set start/end dates of the current month $days = self::getNbOfDaysInMonth($this->date_start); $current_date_start = $this->date_start; $month_start = date('m', strtotime($current_date_start)); $month_end = date('m', strtotime('+1 month', strtotime($current_date_start))); $day_end = date('m', strtotime('+' . $days . ' days', strtotime($current_date_start))); $year_end = $month_start == '12' ? date('Y', strtotime("+1 year", strtotime($this->date_start))) : date('Y', strtotime($this->date_start)); $current_date_end = $year_end . '-' . $month_end . '-' . $day_end; $days = $this->getDays($this->date_start, 'Y-m-d H:i'); $total_items = 0; $displayed_items = 0; foreach ($result as $item) { // Extract the feature details, if needed $features = array(); if (is_null($item->features) || empty($this->features_icon_size)) { $item->features = array(); } else { $item->features = icagendaEvents::featureIcons($item->id); } if (isset($item->features) && is_array($item->features)) { foreach ($item->features as $feature) { $features[] = array('icon' => $feature->icon, 'icon_alt' => $feature->icon_alt); } } // list calendar dates $AllDates = array(); $next = isset($next) ? $next : ''; $allSingleDates_array = $this->getDatelist($item->dates, $next); // If Single Dates, added to all dates for this event if (isset($datemultiplelist) && $datemultiplelist != NULL && is_array($datemultiplelist)) { $allSingleDates_array = array_merge($AllDates, $datemultiplelist); } foreach ($allSingleDates_array as $sd) { $this_date = JHtml::date($sd, 'Y-m-d', null); if (strtotime($this_date) >= strtotime($current_date_start) && strtotime($this_date) < strtotime($current_date_end)) { array_push($AllDates, $sd); } } // Get WeekDays Array $WeeksDays = iCDatePeriod::weekdaysToArray($item->weekdays); // Get Period Dates $StDate = JHtml::date($item->startdate, 'Y-m-d H:i', $eventTimeZone); $EnDate = JHtml::date($item->enddate, 'Y-m-d H:i', $eventTimeZone); $perioddates = iCDatePeriod::listDates($item->startdate, $item->enddate, $eventTimeZone); $onlyStDate = isset($this->onlyStDate) ? $this->onlyStDate : ''; // Check the period if individual dates $only_startdate = $item->weekdays || $item->weekdays == '0' ? false : true; // if (isset($perioddates) && $perioddates != NULL) // { if ($onlyStDate == 1) { if (strtotime($StDate) >= strtotime($current_date_start) && strtotime($StDate) < strtotime($current_date_end)) { array_push($AllDates, date('Y-m-d H:i', strtotime($item->startdate))); } } else { foreach ($perioddates as $Dat) { $this_date = JHtml::date($Dat, 'Y-m-d', null); if (in_array(date('w', strtotime($Dat)), $WeeksDays)) { $SingleDate = date('Y-m-d H:i', strtotime($Dat)); if (strtotime($this_date) >= strtotime($current_date_start) && strtotime($this_date) < strtotime($current_date_end)) { array_push($AllDates, $SingleDate); } } } } // } rsort($AllDates); // requĂȘte Itemid $iCmenuitem = $params->get('iCmenuitem', ''); if (is_numeric($iCmenuitem)) { $linkid = $iCmenuitem; } else { $linkid = icagendaMenus::thisEventItemid($item->next, $item->catid, $iC_list_menus); } $eventnumber = $item->id ? $item->id : null; $event_slug = $item->alias ? $item->id . ':' . $item->alias : $item->id; $total_items = $total_items + 1; if ($linkid && !$nolink && JComponentHelper::getComponent('com_icagenda', true)->enabled) { $displayed_items = $displayed_items + 1; $urlevent = JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . $event_slug . '&Itemid=' . (int) $linkid); } else { $urlevent = '#'; } $descShort = icagendaEvents::shortDescription($item->desc, true, $this->filtering_shortDesc, $this->limit); /** * Get Thumbnail */ // START iCthumb // Set if run iCthumb if ($item->image && $thumb_generator == 1) { // Generate small thumb if not exist $thumb_img = icagendaThumb::sizeSmall($item->image); } elseif ($item->image && $thumb_generator == 0) { $thumb_img = $item->image; } else { $thumb_img = $item->image ? 'media/com_icagenda/images/nophoto.jpg' : ''; } // END iCthumb $evtParams = ''; $evtParams = new JRegistry($item->params); // Display Time $r_time = $params->get('dp_time', 1) ? true : false; // Display City $r_city = $params->get('dp_city', 1) ? $item->city : false; // Display Country $r_country = $params->get('dp_country', 1) ? $item->country : false; // Display Venue Name $r_place = $params->get('dp_venuename', 1) ? $item->place_name : false; // Display Intro Text $dp_shortDesc = $params->get('dp_shortDesc', ''); // Short Description if ($dp_shortDesc == '1') { $descShort = $item->shortdesc ? $item->shortdesc : false; } elseif ($dp_shortDesc == '2') { $descShort = $descShort ? $descShort : false; } elseif ($dp_shortDesc == '0') { $descShort = false; } else { $e_shortdesc = $item->shortdesc ? $item->shortdesc : $descShort; $descShort = $e_shortdesc ? $e_shortdesc : $item->metadesc; } // Display Registration Infos $dp_regInfos = $params->get('dp_regInfos', 1); $maxTickets = $dp_regInfos == 1 ? $evtParams->get('maxReg', '1000000') : false; $typeReg = $dp_regInfos == 1 ? $evtParams->get('typeReg', '1') : false; $event = array('id' => (int) $item->id, 'Itemid' => (int) $linkid, 'title' => $item->title, 'next' => $this->formatDate($item->next), 'image' => $thumb_img, 'file' => $item->file, 'address' => $item->address, 'city' => $r_city, 'country' => $r_country, 'place' => $r_place, 'description' => $item->desc, 'descShort' => $descShort, 'cat_title' => $item->cat_title, 'cat_order' => $item->cat_order, 'cat_color' => $item->cat_color, 'nb_events' => count($item->id), 'no_image' => JTEXT::_('MOD_ICCALENDAR_NO_IMAGE'), 'params' => $item->params, 'features_icon_size' => $this->features_icon_size, 'features_icon_root' => $this->features_icon_root, 'show_icon_title' => $this->show_icon_title, 'features' => $features, 'item' => $item); // Access Control $access = $item->access ? $item->access : '1'; // Language Control $languages = array(JFactory::getLanguage()->getTag(), '*'); $eventLang = isset($item->language) ? $item->language : '*'; // Get Option Dislay Time $displaytime = isset($item->displaytime) ? $item->displaytime : ''; $events_per_day = array(); // Get List of Dates if ((in_array($access, $userLevels) || in_array('8', $userGroups)) && in_array($eventLang, $languages) && is_array($event) && $linkid) { $past_dates = 0; foreach ($AllDates as $d) { // Control if date is past if (strtotime($d) < strtotime($datetime_today)) { $past_dates = $past_dates + 1; } } foreach ($AllDates as $d) { $this_date_control = date('Y-m-d H:i', strtotime($d)); if ($only_startdate && in_array($this_date_control, $perioddates)) { $set_date_in_url = ''; } else { $set_date_in_url = $date_var . iCDate::dateToAlias($d, 'Y-m-d H:i'); } if ($r_time) { $time = array('time' => date($lang_time, strtotime($d)), 'displaytime' => $displaytime, 'url' => $urlevent . $set_date_in_url); } else { $time = array('time' => '', 'displaytime' => '', 'url' => $urlevent . $set_date_in_url); } $event = array_merge($event, $time); $this_date = $item->reg_date ? date('Y-m-d H:i:s', strtotime($d)) : 'period'; $registrations = $dp_regInfos == 1 ? true : false; $registered = $dp_regInfos == 1 ? self::getNbTicketsBooked($this_date, $item->registered, $eventnumber, $set_date_in_url) : false; $maxTickets = $maxTickets != '1000000' ? $maxTickets : false; $TicketsLeft = $dp_regInfos == 1 && $maxTickets ? $maxTickets - self::getNbTicketsBooked($this_date, $item->registered, $eventnumber, $set_date_in_url) : false; // If period started, and registration is set to "for all dates of the event" if ($maxTickets && $past_dates && $typeReg == 2) { $date_sold_out = JText::_('MOD_ICCALENDAR_REGISTRATION_CLOSED'); } elseif ($maxTickets) { $date_sold_out = $TicketsLeft <= 0 ? JText::_('MOD_ICCALENDAR_REGISTRATION_DATE_NO_TICKETS_LEFT') : false; } else { $date_sold_out = false; } $reg_infos = array('registrations' => $registrations, 'registered' => $registered, 'maxTickets' => $maxTickets, 'TicketsLeft' => $TicketsLeft, 'date_sold_out' => $date_sold_out); $event = array_merge($event, $reg_infos); foreach ($days as $k => $dy) { // $d_date = JHtml::date($d, 'Y-m-d', $eventTimeZone); $d_date = date('Y-m-d', strtotime($d)); $dy_date = date('Y-m-d', strtotime($dy['date'])); if ($d_date == $dy_date) { array_push($days[$k]['events'], $event); } } } } } $i = ''; if ($nolink || !JComponentHelper::getComponent('com_icagenda', true)->enabled) { do { echo '<div style="color:#a40505; text-align: center;"><b>info :</b></div><div style="color:#a40505; font-size: 0.8em; text-align: center;">' . JText::_('MOD_ICCALENDAR_COM_ICAGENDA_MENULINK_UNPUBLISHED_MESSAGE') . '</div>'; } while ($i > 0); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id AS nbevt')->from('`#__icagenda_events` AS e')->where('e.state > 0'); $db->setQuery($query); $nbevt = $db->loadResult(); $nbevt = count($nbevt); $no_event_message = '<div class="ic-msg-no-event">' . JText::_('MOD_ICCALENDAR_NO_EVENT') . '</div>'; if ($nbevt == NULL) { echo $no_event_message; } // To be Checked $total_items = count($result); if ($displayed_items == '0' && $total_items > 0) { echo $no_event_message; } if ($total_items > $displayed_items) { $not_displayed = $total_items - $displayed_items; $user = JFactory::getUser(); if ($user->authorise('core.admin')) { echo '<div class="alert alert-warning">' . JText::sprintf('IC_MODULE_ALERT_EVENTS_NOT_DISPLAYED', $not_displayed) . '</div>'; } } return $days; }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * @since 3.4.0 */ protected function getListQuery() { // Get the current user for authorisation checks $user = JFactory::getUser(); // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'e.*')); $query->from($db->qn('#__icagenda_events') . ' AS e'); // Join over the language $query->select('l.title AS language_title')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = e.language'); // Join over the users for the checked out user. // $query->select('uc.name AS editor'); // $query->join('LEFT', '#__users AS uc ON uc.id=e.checked_out'); // Join over the asset groups. // $query->select('ag.title AS access_level') // ->join('LEFT', '#__viewlevels AS ag ON ag.id = e.access'); // Join the category $query->select('c.id AS cat_id, c.title AS cat_title, c.color AS cat_color, c.desc AS cat_desc, c.title AS category, c.color AS catcolor'); $query->join('LEFT', '#__icagenda_category AS c ON c.id = e.catid'); $query->where('c.state = 1'); // Features - extract the number of displayable icons per event $query->select('feat.count AS features'); $sub_query = $db->getQuery(true); $sub_query->select('fx.event_id, COUNT(*) AS count'); $sub_query->from('`#__icagenda_feature_xref` AS fx'); $sub_query->innerJoin("`#__icagenda_feature` AS f ON fx.feature_id=f.id AND f.state=1 AND f.icon<>'-1'"); $sub_query->group('fx.event_id'); $query->leftJoin('(' . (string) $sub_query . ') AS feat ON e.id=feat.event_id'); // Join Total of registrations $query->select('r.count AS registered'); $sub_query = $db->getQuery(true); $sub_query->select('r.state, r.date, r.eventid, sum(r.people) AS count'); $sub_query->from('`#__icagenda_registration` AS r'); $sub_query->where('r.state > 0'); $sub_query->group('r.date, r.eventid'); $query->leftJoin('(' . (string) $sub_query . ') AS r ON ((e.next = r.date OR r.date = "") AND e.id = r.eventid)'); // Join over the users for the author. // $query->select('ua.name AS author_name, ua.username AS author_username') // ->join('LEFT', '#__users AS ua ON ua.id = e.created_by'); // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('e.state = ' . (int) $published); } elseif ($published === '') { $query->where('(e.state IN (0, 1))'); } $userGroups = $user->groups; $groupid = JComponentHelper::getParams('com_icagenda')->get('approvalGroups', array("8")); $groupid = is_array($groupid) ? $groupid : array($groupid); // Test if user login have Approval Rights if (!array_intersect($userGroups, $groupid) && !in_array('8', $userGroups)) { $query->where('e.approval <> 1'); } else { $query->where('e.approval < 2'); } // Filter by access level. $access = $this->getState('filter.access'); if (!empty($access) && !in_array('8', $userGroups)) { $access_levels = implode(',', $user->getAuthorisedViewLevels()); $query->where('e.access IN (' . $access_levels . ')'); // ->where('c.access IN (' . $access_levels . ')'); // To be added later, when access integrated to category } // Filter by language if ($this->getState('filter.language')) { $query->where('e.language in (' . $db->q(JFactory::getLanguage()->getTag()) . ',' . $db->q('*') . ')'); } // Filter by search in title // $search = $this->getState('filter.search'); // if (!empty($search)) // { // if (stripos($search, 'id:') === 0) // { // $query->where('e.id = '.(int) substr($search, 3)); // } // else // { // $search = $db->Quote('%'.$db->escape($search, true).'%'); // $query->where('( e.title LIKE '.$search.' OR e.username LIKE '.$search.' OR e.id LIKE '.$search.' OR e.email LIKE '.$search.' OR e.file LIKE '.$search.' OR e.place LIKE '.$search.' OR e.city LIKE '.$search.' OR e.country LIKE '.$search.' OR e.desc LIKE '.$search.' OR c.title LIKE '.$search.')'); // } // } // Filter by categories. $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId) && !empty($categoryId)) { $query->where('e.catid = ' . $categoryId . ''); } elseif (is_array($categoryId) && !empty($categoryId) && !in_array('0', $categoryId)) { JArrayHelper::toInteger($categoryId); $categoryId = implode(',', $categoryId); $query->where('e.catid IN (' . $categoryId . ')'); } // Filter by Dates $dates_filter = $this->getState('filter.upcoming', '0'); // Get today date and datetime based on Joomla Config Timezone. $datetime_today = JHtml::date('now', 'Y-m-d H:i:s'); $date_today = JHtml::date('now', 'Y-m-d'); $all_dates_with_id = icagendaEventsData::getAllDates($dates_filter, '2', $this->state->get('list.direction'), 'no'); $dpp_array = $dpp_dates = array(); foreach ($all_dates_with_id as $dpp) { $dpp_alldates_array = explode('_', $dpp); $dpp_date = $dpp_alldates_array['0']; $dpp_id = $dpp_alldates_array['1']; $dpp_dates[] = $dpp_date; $dpp_array[] = $dpp_id; } $list_id = implode(', ', $dpp_array); if (count($dpp_array)) { $query->where('e.id IN (' . $list_id . ')'); } else { return false; } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); if ($orderCol && $orderDirn) { $query->order($db->escape($orderCol . ' ' . $orderDirn)); } return $query; }
/** * Get Records. * * @return object list. * @since 3.3.8 */ public function getRecords() { // Get the current user for authorisation checks $user = JFactory::getUser(); // Get Params for current view $app = JFactory::getApplication(); $params = $app->getParams(); // Select the required fields from the table. $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('e.*')->from($db->qn('#__icagenda_events') . ' AS e'); // Join over the language $query->select('l.title AS language_title')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = e.language'); // Join over the users for the checked out user. // $query->select('uc.name AS editor'); // $query->join('LEFT', '#__users AS uc ON uc.id=e.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = e.access'); // Join the category $query->select('c.title AS category, c.color AS catcolor'); $query->join('LEFT', '#__icagenda_category AS c ON c.id = e.catid'); $query->where('c.state = 1'); // Join over the users for the author. // $query->select('ua.name AS author_name, ua.username AS author_username') // ->join('LEFT', '#__users AS ua ON ua.id = e.created_by'); // Filter by published state $query->where('e.state = 1'); // Event is approved $query->where('e.approval <> 1'); // Filter by access level. $access_levels = implode(',', $user->getAuthorisedViewLevels()); $query->where('e.access IN (' . $db->q($access_levels) . ')'); // ->where('c.access IN (' . $db->q($access_levels) . ')'); // To be added later, when access integrated to category // Filter by language $query->where('e.language in (' . $db->q(JFactory::getLanguage()->getTag()) . ',' . $db->q('*') . ')'); // Filter by Features $query->where(icagendaEventsData::getFeaturesFilter()); // Filter by dates $dates_filter = $params->get('time', 1); // Default Current and Upcoming Events // Get today date and datetime based on Joomla Config Timezone. $datetime_today = JHtml::date('now', 'Y-m-d H:i:s'); $date_today = JHtml::date('now', 'Y-m-d'); if (!empty($dates_filter)) { // COM_ICAGENDA_OPTION_TODAY_AND_UPCOMING if ($dates_filter == '1') { $where_current_upcoming = $db->qn('e.next') . ' >= ' . $db->q($date_today); $where_current_upcoming .= ' OR (' . $db->qn('e.next') . ' < ' . $db->q($datetime_today) . ' AND ' . $db->qn('e.startdate') . ' <> "0000-00-00 00:00:00" AND ' . $db->qn('e.enddate') . ' > ' . $db->q($datetime_today) . ')'; $query->where($where_current_upcoming); } elseif ($dates_filter == '2') { $where_past = '('; // Period dates with no weekdays filter $where_past .= $db->qn('e.next') . ' < ' . $db->q($datetime_today) . ')'; $where_past .= ' AND (' . $db->qn('e.enddate') . ' < ' . $db->q($datetime_today); $where_past .= ' )'; $query->where($where_past); } elseif ($dates_filter == '3') { $where_upcoming = '('; $where_upcoming .= $db->qn('e.next') . ' > ' . $db->q($datetime_today); $where_upcoming .= ' )'; $query->where($where_upcoming); } elseif ($dates_filter == '4') { $where_today = '( '; // One day dates filter $where_today .= ' ('; $where_today .= ' (' . $db->qn('e.next') . ' >= ' . $db->q($datetime_today) . ')'; $where_today .= ' AND (' . $db->qn('e.next') . ' < ' . $db->q($date_today) . ' + INTERVAL 1 DAY)'; $where_today .= ' )'; // Period dates with no weekdays filter $where_today .= ' OR ( '; $where_today .= ' (' . $db->qn('e.next') . ' > ' . $db->q($date_today) . ')'; $where_today .= ' AND (' . $db->qn('e.weekdays') . ' = "")'; $where_today .= ' AND ' . $db->qn('e.enddate') . ' <> "0000-00-00 00:00:00" AND (' . $db->qn('e.enddate') . ' >= ' . $db->q($date_today) . ')'; $where_today .= ' AND ' . $db->qn('e.startdate') . ' <> "0000-00-00 00:00:00" AND (' . $db->qn('e.startdate') . ' < ' . $db->q($date_today) . ')'; $where_today .= ' )'; $where_today .= ' )'; $query->where($where_today); } } // Order Next Date DESC $orderby = $params->get('orderby', 2); // Default ASC $ordering = $orderby == 1 ? 'DESC' : 'ASC'; $query->order('e.next ' . $ordering); // Tell the database connector what query to run. $db->setQuery($query); // Invoke the query or data retrieval helper. $db_list = $db->loadObjectList(); return $db_list; }
/** * Fetch data from DB */ protected function getDBitems() { // Check valid NEXT DATE icagendaEventsData::getNext(); $app = JFactory::getApplication(); $jinput = $app->input; $params = $app->getParams(); // Get Settings $filterTime = $params->get('time', 1); $jlayout = JRequest::getCmd('layout', ''); $layouts_array = array('event', 'registration', 'actions'); $layout = in_array($jlayout, $layouts_array) ? $jlayout : ''; // Set vars $nodate = '0000-00-00 00:00:00'; $eventTimeZone = null; $datetime_today = JHtml::date('now', 'Y-m-d H:i:s'); // Joomla Time Zone $date_today = JHtml::date('now', 'Y-m-d'); // Joomla Time Zone $time_today = JHtml::date('now', 'H:i:s'); // Joomla Time Zone // Get List Type option (list of events / list of dates) $allDatesDisplay = $this->options['datesDisplay']; // Preparing connection to db $db = Jfactory::getDbo(); // Preparing the query $query = $db->getQuery(true); // Selectable items $query->select('e.*, e.place as place_name, e.coordinate as coordinate, e.lat as lat, e.lng as lng, c.id as cat_id, c.title as cat_title, c.color as cat_color, c.desc as cat_desc, c.alias as cat_alias'); // join $query->from('`#__icagenda_events` AS e'); $query->leftJoin('`#__icagenda_category` AS c ON c.id = e.catid'); $query->where('c.state = 1'); // Where (filters) $filters = $this->filters; $where = 'e.state = ' . $filters['state']; $user = JFactory::getUser(); $userLevels = $user->getAuthorisedViewLevels(); $userGroups = $user->groups; $groupid = JComponentHelper::getParams('com_icagenda')->get('approvalGroups', array("8")); $groupid = is_array($groupid) ? $groupid : array($groupid); // Test if user login have Approval Rights if (!array_intersect($userGroups, $groupid) && !in_array('8', $userGroups)) { $where .= ' AND e.approval <> 1'; } else { $where .= ' AND e.approval < 2'; } // ACCESS Filtering (if not list, use layout access control (event, registration)) if (!$layout && !in_array('8', $userGroups)) { $useraccess = implode(', ', $userLevels); $where .= ' AND e.access IN (' . $useraccess . ')'; } // LANGUAGE Filtering $where .= ' AND (e.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . '))'; unset($filters['state']); $k = '0'; $this_id = null; if (isset($filters)) { foreach ($filters as $k => $v) { // normal cases if ($k != 'key' && $k != 'next' && $k != 'e.catid' && $k != 'id') { $where .= ' AND ' . $k . ' LIKE "%' . $v . '%"'; } // in case of search if ($k == 'key') { $keys = explode(' ', $v); foreach ($keys as $ke) { $where .= ' AND (e.title LIKE \'%' . $ke . '%\' OR '; $where .= ' e.desc LIKE \'%' . $ke . '%\' OR '; $where .= ' e.address LIKE \'%' . $ke . '%\' OR '; $where .= ' e.place LIKE \'%' . $ke . '%\' OR '; $where .= ' c.title LIKE \'%' . $ke . '%\')'; } } // in the case of category $mcatidtrue = $this->options['mcatid']; if (!is_array($mcatidtrue)) { $catold = $mcatidtrue; $mcatid = array($mcatidtrue); } else { $catold = '0'; $mcatid = $mcatidtrue; } if (!in_array('0', $mcatid) || $catold != 0) { if ($k == 'e.catid') { if (!is_array($v)) { $v = array('' . $v . ''); } $v = implode(', ', $v); $where .= ' AND ' . $k . ' IN (' . $v . ')'; } } // in case of id if ($k == 'id') { //check if ID is a number if (is_numeric($v)) { $this_id = (int) $v; // if event id is set in url $where .= ' AND e.id=' . $v; } else { //ERROR Message } } } } // Features - extract the number of displayable icons per event $query->select('feat.count AS features'); $sub_query = $db->getQuery(true); $sub_query->select('fx.event_id, COUNT(*) AS count'); $sub_query->from('`#__icagenda_feature_xref` AS fx'); $sub_query->innerJoin("`#__icagenda_feature` AS f ON fx.feature_id=f.id AND f.state=1 AND f.icon<>'-1'"); $sub_query->group('fx.event_id'); $query->leftJoin('(' . (string) $sub_query . ') AS feat ON e.id=feat.event_id'); // Filter by Features if (!$layout) { $query->where(icagendaEventsData::getFeaturesFilter()); } // Registrations total $query->select('r.count AS registered'); $sub_query = $db->getQuery(true); $sub_query->select('r.eventid, sum(r.people) AS count'); $sub_query->from('`#__icagenda_registration` AS r'); $get_date = JRequest::getVar('date', ''); if ($get_date) { $ex = explode('-', $get_date); if (strlen(iCDate::dateToNumeric($get_date)) != '12') { $event_url = JURI::getInstance()->toString(); $cleanurl = preg_replace('/&date=[^&]*/', '', $event_url); $cleanurl = preg_replace('/\\?date=[^\\?]*/', '', $cleanurl); // redirect and remove date var, if not correctly set // $app->redirect($cleanurl , JText::_( 'COM_ICAGENDA_ERROR_URL_DATE_NOT_FOUND' )); $app->redirect($cleanurl); return false; } if (count($ex) == 5) { $dateday = $ex['0'] . '-' . $ex['1'] . '-' . $ex['2'] . ' ' . $ex['3'] . ':' . $ex['4'] . ':00'; $sub_query->where('r.date = ' . $db->q($dateday)); } } $sub_query->where('r.state > 0'); $sub_query->group('r.eventid'); $query->leftJoin('(' . (string) $sub_query . ') AS r ON e.id=r.eventid'); if (!$layout) { $number_per_page = $this->options['number']; $orderdate = $this->options['orderby']; $getpage = JRequest::getVar('page', '1'); $start = $number_per_page * ($getpage - 1); $all_dates_with_id = icagendaEventsData::getAllDates(); $count_all_dates = count($all_dates_with_id); // Set list of PAGE:IDS $pages = ceil($count_all_dates / $number_per_page); $list_id = array(); for ($n = 1; $n <= $pages; $n++) { $dpp_array = array(); $page_nb = $number_per_page * ($n - 1); $dates_per_page = array_slice($all_dates_with_id, $page_nb, $number_per_page, true); foreach ($dates_per_page as $dpp) { $dpp_alldates_array = explode('_', $dpp); $dpp_date = $dpp_alldates_array['0']; $dpp_id = $dpp_alldates_array['1']; $dpp_array[] = $dpp_id; } $list_id[] = implode(', ', $dpp_array) . '::' . $n; } $this_ic_ids = ''; if ($list_id) { foreach ($list_id as $a) { $ex_listid = explode('::', $a); $ic_page = $ex_listid[1]; $ic_ids = $ex_listid[0]; if ($ic_page == $getpage) { $this_ic_ids = $ic_ids ? $ic_ids : '0'; } } if ($this_ic_ids) { $where .= ' AND (e.id IN (' . $this_ic_ids . '))'; } else { return false; // No Event (if 'All Dates' option selected) } } } // Query $where list $query->where($where); $db->setQuery($query); $loaddb = $db->loadObjectList(); $registrations = icagendaEventsData::registeredList($this_id); // Extract the feature details, if needed foreach ($loaddb as $record) { if (is_null($record->features)) { $record->features = array(); } else { $query = $db->getQuery(true); $query->select('DISTINCT f.icon, f.icon_alt'); $query->from('`#__icagenda_feature_xref` AS fx'); $query->innerJoin("`#__icagenda_feature` AS f ON fx.feature_id=f.id AND f.state=1 AND f.icon<>'-1'"); $query->where('fx.event_id=' . $record->id); $query->order('f.ordering DESC'); // Order descending because the icons are floated right $db->setQuery($query); $record->features = $db->loadObjectList(); } // if (is_null($record->registered)) // { // $record->registered = array(); // } // else // { $record_registered = array(); foreach ($registrations as $reg_by_event) { $ex_reg_by_event = explode('@@', $reg_by_event); if ($ex_reg_by_event[0] == $record->id) { $record_registered[] = $ex_reg_by_event[0] . '@@' . $ex_reg_by_event[1] . '@@' . $ex_reg_by_event[2]; } } $record->registered = $record_registered; // } } if (!$layout && count($all_dates_with_id) > 0 || $layout) { return $loaddb; } }
/** * Execute and display a template script. * * @param string $tpl The name of the template file to parse; automatically searches through the template paths. * * @return mixed A string if successful, otherwise a Error object. */ public function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $this->params = $app->getParams(); $params = $this->params; // For Dev. $time_loading = $params->get('time_loading', ''); if ($time_loading) { $starttime_list = iCLibrary::getMicrotime(); } // loading data $this->data = $this->getModel()->getData(); $this->getAllDates = icagendaEventsData::getAllDates(); $this->form = $this->getModel()->getForm(); // Registration Form $this->state = $this->get('State'); //Following variables used more than once // $this->sortColumn = $this->state->get('list.ordering'); // $this->sortDirection = $this->state->get('list.direction'); $this->searchterms = $this->state->get('filter.search'); // Menu Options $this->atlist = $params->get('atlist', 0); $this->template = $params->get('template'); $this->title = $params->get('title'); $this->number = $params->get('number', 5); $this->orderby = $params->get('orderby', 2); $this->time = $params->get('time', 1); // Component Options $this->iconPrint_global = $params->get('iconPrint_global', 0); $this->iconAddToCal_global = $params->get('iconAddToCal_global', 0); $this->iconAddToCal_options = $params->get('iconAddToCal_options', 0); $this->copy = $params->get('copy'); $this->navposition = $params->get('navposition', 1); $this->arrowtext = $params->get('arrowtext', 1); $this->GoogleMaps = $params->get('GoogleMaps', 1); $this->pagination = $params->get('pagination', 1); $this->day_display_global = $params->get('day_display_global', 1); $this->month_display_global = $params->get('month_display_global', 1); $this->year_display_global = $params->get('year_display_global', 1); $this->time_display_global = $params->get('time_display_global', 0); $this->venue_display_global = $params->get('venue_display_global', 1); $this->city_display_global = $params->get('city_display_global', 1); $this->country_display_global = $params->get('country_display_global', 1); $this->shortdesc_display_global = $params->get('shortdesc_display_global', ''); $this->statutReg = $params->get('statutReg', 0); $this->dates_display = $params->get('datesDisplay', 1); $this->reg_captcha = $params->get('reg_captcha', 0); $this->reg_form_validation = $params->get('reg_form_validation', ''); $this->cat_description = $params->get('displayCatDesc_menu', 'global') == 'global' ? $params->get('CatDesc_global', '0') : $params->get('displayCatDesc_menu', ''); $cat_options = $params->get('displayCatDesc_menu', 'global') == 'global' ? $params->get('CatDesc_checkbox', '') : $params->get('displayCatDesc_checkbox', ''); $this->cat_options = is_array($cat_options) ? $cat_options : array(); $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $vcal = $app->input->get('vcal'); if ($vcal) { $tpl = 'vcal'; } // Process the content plugins. JPluginHelper::importPlugin('content'); if (version_compare(JVERSION, '3.0', 'ge')) { $this->dispatcher = JEventDispatcher::getInstance(); } else { $this->dispatcher = JDispatcher::getInstance(); } $eventid = $app->input->get('id'); if ($eventid) { // Set Item Object $this_item = (array) $this->data->items; $item = array_shift($this_item); $this->actions = $this->dispatcher->trigger('onRegistrationActions', array('com_icagenda.actions', &$item, &$this->params)); } $this->_prepareDocument(); $isVcal = JRequest::getVar('vcal', ''); if (!$isVcal) { icagendaInfo::commentVersion(); } // Loads jQuery Library if (version_compare(JVERSION, '3.0', 'lt')) { // Joomla 2.5 JHtml::stylesheet('com_icagenda/icagenda-front.j25.css', false, true); JHtml::_('behavior.mootools'); // load jQuery, if not loaded before $scripts = array_keys($document->_scripts); $scriptFound = false; for ($i = 0; $i < count($scripts); $i++) { if (stripos($scripts[$i], 'jquery.min.js') !== false || stripos($scripts[$i], 'jquery.js') !== false) { $scriptFound = true; } } // jQuery Library Loader if (!$scriptFound) { // load jQuery, if not loaded before if (!$app->get('jquery')) { $app->set('jquery', true); // Add jQuery Library $document->addScript('https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'); JHtml::script('com_icagenda/jquery.noconflict.js', false, true); } } } else { JHtml::_('bootstrap.framework'); JHtml::_('jquery.framework'); } parent::display($tpl); // For Dev. if ($time_loading) { $endtime_list = iCLibrary::getMicrotime(); echo '<center style="font-size:8px;">Time to create page: ' . round($endtime_list - $starttime_list, 3) . ' seconds</center>'; } icagendaEvents::isListOfEvents(); $jlayout = JRequest::getCmd('layout', ''); $layouts_array = array('event', 'registration', 'actions'); $layout = in_array($jlayout, $layouts_array) ? $jlayout : ''; // Loading Script tipTip used for iCtips JHtml::script('com_icagenda/jquery.tipTip.js', false, true); if (!$layout || $layout == 'list') { // Add RSS Feeds $menu = $app->getMenu()->getActive()->id; $feed = 'index.php?option=com_icagenda&view=list&Itemid=' . (int) $menu . '&format=feed'; $rss = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); $document->addHeadLink(JRoute::_($feed . '&type=rss'), 'alternate', 'rel', $rss); } }