Пример #1
0
	/**
	 * Method to auto-populate the model state.
	 */
	protected function populateState($ordering = null, $direction = null)
	{
		$app           = JFactory::getApplication();
		$jinput        = $app->input;
		$task          = $jinput->getCmd('task', '');
		$params        = $app->getParams();
		$top_category  = $params->get('top_category', 0);
		$startdayonly  = $params->get('show_only_start', false);
		$numberOfWeeks = $params->get('nrweeks', '1');
		$firstweekday  = $params->get('firstweekday', 1);

		# params
		$this->setState('params', $params);

		# publish state
		$this->_populatePublishState($task);

		###########
		## DATES ##
		###########

		#only select events within specified dates. (chosen weeknrs)

		$config = JFactory::getConfig();
		$offset = $config->get('offset');
		date_default_timezone_set($offset);
		$datetime = new DateTime();
		// If week starts Monday we use dayoffset 1, on Sunday we use 0 but 7 if today is Sunday.
		$dayoffset = ($firstweekday == 1) ? 1 : ((($firstweekday == 0) && ($datetime->format('N') == 7)) ? 7 : 0);
		$datetime->setISODate($datetime->format('Y'), $datetime->format('W'), $dayoffset);
		$filter_date_from = $datetime->format('Y-m-d');
		$datetime->modify('+'.$numberOfWeeks.' weeks'.' -1 day'); // just to be compatible to php < 5.3 ;-)
		$filter_date_to   = $datetime->format('Y-m-d');

		$where = ' DATEDIFF(IF (a.enddates IS NOT NULL, a.enddates, a.dates), ' . $this->_db->quote($filter_date_from) . ') >= 0';
		$this->setState('filter.calendar_from', $where);
		$this->setState('filter.date.from', $filter_date_from);

		$where = ' DATEDIFF(a.dates, ' . $this->_db->quote($filter_date_to) . ') <= 0';
		$this->setState('filter.calendar_to', $where);
		$this->setState('filter.date.to', $filter_date_to);


		##################
		## TOP-CATEGORY ##
		##################

		if ($top_category) {
			$children = JEMCategories::getChilds($top_category);
			if (count($children)) {
				$where = 'rel.catid IN ('. implode(',', $children) .')';
				$this->setState('filter.category_top', $where);
			}
		}

		# set filter
		$this->setState('filter.calendar_startdayonly', (bool)$startdayonly);
		$this->setState('filter.groupby', 'a.id');
	}
Пример #2
0
	/**
	 * Method to auto-populate the model state.
	 */
	protected function populateState($ordering = null, $direction = null)
	{
		# parent::populateState($ordering, $direction);
		$app 			= JFactory::getApplication();
		$jemsettings	= JemHelper::config();
		$jinput			= JFactory::getApplication()->input;
		$itemid 		= $jinput->getInt('id', 0) . ':' . $jinput->getInt('Itemid', 0);
		$params 		= $app->getParams();
		$task           = $jinput->get('task','','cmd');
		$top_category 	= $params->get('top_category', 0);
		$startdayonly 	= $params->get('show_only_start', false);

		# params
		$this->setState('params', $params);

		# publish state
		$this->_populatePublishState($task);

		###########
		## DATES ##
		###########

		#only select events within specified dates. (chosen month)
		$monthstart	= mktime(0, 0, 1, strftime('%m', $this->_date), 1, strftime('%Y', $this->_date));
		$monthend	= mktime(0, 0, -1, strftime('%m', $this->_date)+1, 1, strftime('%Y', $this->_date));

		$filter_date_from	= $this->_db->Quote(strftime('%Y-%m-%d', $monthstart));
		$filter_date_to		= $this->_db->Quote(strftime('%Y-%m-%d', $monthend));

		$where = ' DATEDIFF(IF (a.enddates IS NOT NULL, a.enddates, a.dates), '. $filter_date_from .') >= 0';
		$this->setState('filter.calendar_from',$where);

		$where = ' DATEDIFF(a.dates, '. $filter_date_to .') <= 0';
		$this->setState('filter.calendar_to',$where);

		##################
		## TOP-CATEGORY ##
		##################

		if ($top_category) {
			$children = JEMCategories::getChilds($top_category);
			if (count($children)) {
				$where = 'rel.catid IN ('. implode(',', $children) .')';
				$this->setState('filter.category_top', $where);
			}
		}

		# set filter
		$this->setState('filter.calendar_multiday',true);
		$this->setState('filter.calendar_startdayonly',(bool)$startdayonly);
		$this->setState('filter.groupby',array('a.id'));
	}
Пример #3
0
 /**
  * Build the where clause
  *
  * @access private
  * @return string
  */
 protected function _buildWhere()
 {
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $itemid = $jinput->getInt('id', 0) . ':' . $jinput->getInt('Itemid', 0);
     // Get the paramaters of the active menu item
     $params = $app->getParams();
     $top_category = $params->get('top_category', 1);
     $task = $jinput->getCmd('task');
     // First thing we need to do is to select only needed events
     if ($task == 'archive') {
         $where = ' WHERE a.published = 2';
     } else {
         $where = ' WHERE a.published = 1';
     }
     //$filter            = $jinput->getString('filter', '', 'request');
     //$filter_type       = $jinput->request->getString('filter_type');
     $filter = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_search', 'filter_search', '', 'string');
     $filter_type = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_type', 'filter_type', '', 'string');
     $filter_continent = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_continent', 'filter_continent', '', 'string');
     $filter_country = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_country', 'filter_country', '', 'string');
     $filter_city = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_city', 'filter_city', '', 'string');
     $filter_date_from = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_date_from', 'filter_date_from', '', 'string');
     $filter_date_to = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_date_to', 'filter_date_to', '', 'string');
     $filter_category = $app->getUserStateFromRequest('com_jem.search.' . $itemid . '.filter_category', 'filter_category', 0, 'int');
     $filter_category = $filter_category ? $filter_category : $top_category;
     // no result if no filter:
     if (!($filter || $filter_continent || $filter_country || $filter_city || $filter_date_from || $filter_date_to || $filter_category != $top_category)) {
         return ' WHERE 0 ';
     }
     if ($filter) {
         // clean filter variables
         $filter = JString::strtolower($filter);
         $filter = $this->_db->Quote('%' . $this->_db->escape($filter, true) . '%', false);
         $filter_type = JString::strtolower($filter_type);
         switch ($filter_type) {
             case 'title':
                 $where .= ' AND LOWER(a.title) LIKE ' . $filter;
                 break;
             case 'venue':
                 $where .= ' AND LOWER(l.venue) LIKE ' . $filter;
                 break;
             case 'city':
                 $where .= ' AND LOWER(l.city) LIKE ' . $filter;
                 break;
             default:
                 $where .= ' AND LOWER(a.title) LIKE ' . $filter;
                 break;
         }
     }
     // filter date
     if ($params->get('date_filter_type', 0) == 1) {
         if ($filter_date_from && strtotime($filter_date_from)) {
             $filter_date_from = $this->_db->Quote(strftime('%Y-%m-%d', strtotime($filter_date_from)));
             $where .= ' AND DATEDIFF(IF (a.enddates IS NOT NULL, a.enddates, a.dates), ' . $filter_date_from . ') >= 0';
         }
         if ($filter_date_to && strtotime($filter_date_to)) {
             $filter_date_to = $this->_db->Quote(strftime('%Y-%m-%d', strtotime($filter_date_to)));
             $where .= ' AND DATEDIFF(a.dates, ' . $filter_date_to . ') <= 0';
         }
     } else {
         // match only on start date
         if ($filter_date_from && strtotime($filter_date_from)) {
             $filter_date_from = $this->_db->Quote(strftime('%Y-%m-%d', strtotime($filter_date_from)));
             $where .= ' AND DATEDIFF(a.dates, ' . $filter_date_from . ') >= 0';
         }
         if ($filter_date_to && strtotime($filter_date_to)) {
             $filter_date_to = $this->_db->Quote(strftime('%Y-%m-%d', strtotime($filter_date_to)));
             $where .= ' AND DATEDIFF(a.dates, ' . $filter_date_to . ') <= 0';
         }
     }
     // filter country
     if ($filter_continent) {
         $where .= ' AND c.continent = ' . $this->_db->Quote($filter_continent);
     }
     // filter country
     if ($filter_country) {
         $where .= ' AND l.country = ' . $this->_db->Quote($filter_country);
     }
     // filter city
     if ($filter_country && $filter_city) {
         $where .= ' AND l.city = ' . $this->_db->Quote($filter_city);
     }
     // filter category
     if ($filter_category) {
         $cats = JEMCategories::getChilds((int) $filter_category);
         $where .= ' AND rel.catid IN (' . implode(', ', $cats) . ')';
     }
     return $where;
 }
Пример #4
0
 /**
  * Method to auto-populate the model state.
  */
 protected function populateState($ordering = null, $direction = null)
 {
     # parent::populateState($ordering, $direction);
     $app = JFactory::getApplication();
     $jemsettings = JemHelper::config();
     $jinput = JFactory::getApplication()->input;
     $itemid = $jinput->getInt('id', 0) . ':' . $jinput->getInt('Itemid', 0);
     $params = $app->getParams();
     $task = $jinput->getCmd('task');
     $top_category = $params->get('top_category', 0);
     $startdayonly = $params->get('show_only_start', false);
     $numberOfWeeks = $params->get('nrweeks', '1');
     $firstweekday = $params->get('firstweekday', 1);
     # params
     $this->setState('params', $params);
     # publish state
     $this->setState('filter.published', 1);
     # access
     $this->setState('filter.access', true);
     ###########
     ## DATES ##
     ###########
     #only select events within specified dates. (chosen weeknrs)
     $config = JFactory::getConfig();
     $offset = $config->get('offset');
     $year = date('Y');
     date_default_timezone_set($offset);
     $datetime = new DateTime();
     $datetime->setISODate($year, $datetime->format("W"), 7);
     if ($firstweekday == 1) {
         if (date('N', time()) == 1) {
             #it's monday and monday is startdate;
             $filter_date_from = $datetime->modify('-6 day');
             $filter_date_from = $datetime->format('Y-m-d') . "\n";
             $filter_date_to = $datetime->modify('+' . $numberOfWeeks . ' weeks' . '- 1 day');
             $filter_date_to = $datetime->format('Y-m-d') . "\n";
         } else {
             # it's not monday but monday is startdate;
             $filter_date_from = $datetime->modify('-6 day');
             $filter_date_from = $datetime->format('Y-m-d') . "\n";
             $filter_date_to = $datetime->modify('+' . $numberOfWeeks . ' weeks' . '- 1 day');
             $filter_date_to = $datetime->format('Y-m-d') . "\n";
         }
     }
     if ($firstweekday == 0) {
         if (date('N', time()) == 7) {
             #it's sunday and sunday is startdate;
             $filter_date_from = $datetime->format('Y-m-d') . "\n";
             $filter_date_to = $datetime->modify('+' . $numberOfWeeks . ' weeks' . '- 1 day');
             $filter_date_to = $datetime->format('Y-m-d') . "\n";
         } else {
             #it's not sunday and sunday is startdate;
             $filter_date_from = $datetime->modify('-7 day');
             $filter_date_from = $datetime->format('Y-m-d') . "\n";
             $filter_date_to = $datetime->modify('+' . $numberOfWeeks . ' weeks');
             $filter_date_to = $datetime->format('Y-m-d') . "\n";
         }
     }
     $where = ' DATEDIFF(IF (a.enddates IS NOT NULL, a.enddates, a.dates), \'' . $filter_date_from . '\') >= 0';
     $this->setState('filter.calendar_from', $where);
     $where = ' DATEDIFF(a.dates, \'' . $filter_date_to . '\') <= 0';
     $this->setState('filter.calendar_to', $where);
     ##################
     ## TOP-CATEGORY ##
     ##################
     if ($top_category) {
         $children = JEMCategories::getChilds($top_category);
         if (count($children)) {
             $where = 'rel.catid IN (' . implode(',', $children) . ')';
             $this->setState('filter.category_top', $where);
         }
     }
     $this->setState('filter.groupby', 'a.id');
     $this->setState('filter.calendar_startdayonly', $startdayonly);
 }
Пример #5
0
	/**
	 * Method to auto-populate the model state.
	 */
	protected function populateState($ordering = null, $direction = null)
	{
		# parent::populateState($ordering, $direction);

		$app               = JFactory::getApplication();
		$jemsettings       = JemHelper::config();
		$jinput            = JFactory::getApplication()->input;
		$itemid            = $jinput->getInt('id', 0) . ':' . $jinput->getInt('Itemid', 0);

		$params            = $app->getParams();
		$task              = $jinput->getCmd('task', '');
		$requestVenueId    = $jinput->getInt('locid', 0);
		$requestCategoryId = $jinput->getInt('catid', 0);
		$item              = $jinput->getInt('Itemid', 0);

		$locid = $app->getUserState('com_jem.venuecal.locid'.$item);
		if ($locid) {
			$this->setstate('filter.filter_locid',$locid);
		}

		// maybe list of venue ids from calendar module
		$locids = explode(',', $jinput->getString('locids', ''));
		foreach ($locids as $id) {
			if ((int)$id > 0) {
				$venues[] = (int)$id;
			}
		}
		if (!empty($venues)) {
			$this->setstate('filter.venue_id', $venues);
			$this->setstate('filter.venue_id.include', true);
		}

		$cal_category_catid = $app->getUserState('com_jem.categorycal.catid'.$item);
		if ($cal_category_catid) {
			$this->setState('filter.req_catid',$cal_category_catid);
		}

		// maybe list of venue ids from calendar module
		$catids = explode(',', $jinput->getString('catids', ''));
		foreach ($catids as $id) {
			if ((int)$id > 1) { // don't accept 'root'
				$cats[] = (int)$id;
			}
		}
		if (!empty($cats)) {
			$this->setstate('filter.category_id', $cats);
			$this->setstate('filter.category_id.include', true);
		}

		// maybe top category is given by calendar view
		$top_category = $jinput->getInt('topcat', 0);
		if ($top_category > 0) { // accept 'root'
			$children = JEMCategories::getChilds($top_category);
			if (count($children)) {
				$where = 'rel.catid IN ('. implode(',', $children) .')';
				$this->setState('filter.category_top', $where);
			}
		}

		# limit/start

		/* in J! 3.3.6 limitstart is removed from request - but we need it! */
		if ($app->input->getInt('limitstart', null) === null) {
			$app->setUserState('com_jem.day.'.$itemid.'.limitstart', 0);
		}

		$limit = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.limit', 'limit', $jemsettings->display_num, 'int');
		$this->setState('list.limit', $limit);

		$limitstart = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.limitstart', 'limitstart', 0, 'int');
		$limitstart = $limit ? (int)(floor($limitstart / $limit) * $limit) : 0;
		$this->setState('list.start', $limitstart);

		# Search
		$search = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.filter_search', 'filter_search', '', 'string');
		$this->setState('filter.filter_search', $search);

		# FilterType
		$filtertype = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.filter_type', 'filter_type', '', 'int');
		$this->setState('filter.filter_type', $filtertype);

		# filter_order
		$orderCol = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.filter_order', 'filter_order', 'a.dates', 'cmd');
		$this->setState('filter.filter_ordering', $orderCol);

		# filter_direction
		$listOrder = $app->getUserStateFromRequest('com_jem.day.'.$itemid.'.filter_order_Dir', 'filter_order_Dir', 'ASC', 'word');
		$this->setState('filter.filter_direction', $listOrder);

		if ($orderCol == 'a.dates') {
			$orderby = array('a.dates ' . $listOrder, 'a.times ' . $listOrder);
		} else {
			$orderby = $orderCol . ' ' . $listOrder;
		}
		$this->setState('filter.orderby', $orderby);

		# params
		$this->setState('params', $params);

		# published
		/// @todo bring given pub together with eventslist's unpub calculation (_populatePublishState())
		$pub = explode(',', $jinput->getString('pub', ''));
		$published = array();
		// sanitize remote data
		foreach ($pub as $val) {
			if (((int)$val >= 1) && ((int)$val <= 2)) {
				$published[] = (int)$val;
			}
		}
		// default to 'published'
		if (empty($published)) {
			//$published[] = 1;
			$this->_populatePublishState($task);
		} else {
			$this->setState('filter.published', $published);
		}

		# request venue-id
		if ($requestVenueId) {
			$this->setState('filter.req_venid',$requestVenueId);
		}

		# request cat-id
		if ($requestCategoryId) {
			$this->setState('filter.req_catid',$requestCategoryId);
		}

		# groupby
		$this->setState('filter.groupby',array('a.id'));
	}
Пример #6
0
 /**
  * Updating files: 302->303
  */
 private function update303()
 {
     ###############################
     ## # update calendar entries ##
     ###############################
     require_once JPATH_SITE . '/components/com_jem/classes/categories.class.php';
     $types = array('calendar', 'category', 'venue');
     foreach ($types as $type) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('id, link, params');
         $query->from('#__menu');
         if ($type == 'calendar') {
             $query->where(array("link LIKE 'index.php?option=com_jem&view=calendar'"));
         } else {
             $query->where(array("link LIKE 'index.php?option=com_jem&view=" . $type . "&layout=calendar%'"));
         }
         $query->order('id');
         $db->setQuery($query);
         $items = $db->loadObjectList();
         foreach ($items as $item) {
             # set params
             $params = json_decode($item->params, true);
             if ($type == 'category' || $type == 'venue') {
                 # get id nr
                 $id = strstr($item->link, '&id=');
                 $id = str_replace('&id=', '', $id);
                 if ($type == 'category') {
                     $params['catids'] = $id;
                     $params['catidsfilter'] = 1;
                 }
                 if ($type == 'venue') {
                     $params['venueids'] = $id;
                     $params['venueidsfilter'] = 1;
                 }
             }
             if ($type == 'calendar') {
                 # retrieve value 'top_category'
                 if (isset($params['top_category'])) {
                     $top_category = $params['top_category'];
                     $childs = JEMCategories::getChilds($top_category);
                     # see if we're dealing with root as first array value
                     # if so then we're taking that value and are hiding it so it will display all other categories
                     $first = reset($childs);
                     if ($first == 0 || $first == 1) {
                         $params['catids'] = 1;
                         $params['catidsfilter'] = 0;
                     } else {
                         if (count($childs) > 1) {
                             # strip of first value as that one is the category it's retreving childs from
                             $reorder = array_shift($childs);
                             $params['catids'] = $childs;
                             $params['catidsfilter'] = 1;
                         }
                     }
                 } else {
                     $params['catids'] = 1;
                     $params['catidsfilter'] = 0;
                 }
             }
             # store params + new link value
             $paramsString = json_encode($params);
             $query = $db->getQuery(true);
             $query->update('#__menu')->set(array('params = ' . $db->quote($paramsString), 'link = ' . $db->Quote('index.php?option=com_jem&view=calendar')))->where(array("id = " . $item->id));
             $db->setQuery($query);
             $db->execute();
         }
     }
 }