protected function modifyQuery(JDatabaseQuery &$query)
 {
     $query->where("NOT deleted");
     if (isset($this->leader)) {
         if ($this->leader instanceof Leader) {
             $query->where("leaderid = " . $this->leader->id);
         } else {
             if (is_int($this->leader)) {
                 $query->where("leaderid = " . $this->leader);
             } else {
                 if (ctype_digit($this->leader)) {
                     $query->where("leaderid = " . (int) $this->leader);
                 }
             }
         }
     }
     if (isset($this->walkProgramme)) {
         if ($this->walkProgramme instanceof WalkProgramme) {
             $wpID = $this->walkProgramme->id;
         } else {
             $wpID = (int) $this->walkProgramme;
         }
         $query->join('INNER', 'walkprogrammewalklinks ON WalkProgrammeWalkID = walkprogrammewalks.SequenceID');
         $query->where("walkprogrammewalklinks.ProgrammeID = " . $wpID);
     }
     if (isset($this->startTimeMax)) {
         $query->where("meettime <= '" . strftime("%H:%M", $this->startTimeMax) . "'");
     }
 }
Example #2
0
 /**
  * Prepare result ordering.
  *
  * @param \JDatabaseQuery $query
  * @param array $options
  */
 protected function prepareOrder(&$query, $options)
 {
     // Filter by state.
     if (array_key_exists('order', $options)) {
         // Prepare direction of ordering.
         $direction = !array_key_exists('order_dir', $options) ? 'DESC' : $options['order_dir'];
         if (!in_array($direction, $this->allowedDirections, true)) {
             $direction = 'DESC';
         }
         switch ($options['order']) {
             case Constants::ORDER_BY_LOCATION_NAME:
                 // Order by location name.
                 $query->order('l.name ' . $direction);
                 break;
             case Constants::ORDER_BY_NUMBER_OF_PROJECTS:
                 // Order by location name.
                 $query->order('project_number ' . $direction);
                 break;
             default:
                 // Order by project title.
                 $query->order('a.title ' . $direction);
                 break;
         }
     }
 }
 /**
  * Adds fields on this event to a query being prepared to go into the database
  * @param JDatabaseQuery &$query Query being prepared. Modified in place.
  */
 public function toDatabase(JDatabaseQuery &$query)
 {
     foreach ($this->dbmappings as $var => $dbField) {
         if (isset($this->{$var})) {
             $query->set($dbField . " = '" . $query->escape($this->{$var}) . "'");
         }
     }
 }
Example #4
0
 /**
  * Implements custom filtering
  *
  * @param   \JDatabaseQuery  $query           The model query we're operating on
  * @param   bool             $overrideLimits  Are we told to override limits?
  *
  * @return  void
  */
 protected function onBeforeBuildQuery(\JDatabaseQuery &$query, $overrideLimits = false)
 {
     $db = $this->getDbo();
     $fltSearch = $this->getState('search', null, 'string');
     if ($fltSearch) {
         $fltSearch = "%{$fltSearch}%";
         $query->where($db->qn('title') . ' LIKE ' . $db->q($fltSearch));
     }
 }
 protected function modifyQuery(JDatabaseQuery &$query)
 {
     $showWhat = array();
     if ($this->getNormal) {
         $showWhat[] = "shownormal";
     }
     if ($this->getNewMember) {
         $showWhat[] = "shownewmember";
     }
     $query->where("(" . implode(" OR ", $showWhat) . ")");
 }
 /**
  * add filter to query
  *
  * @param   JDatabaseQuery  $query  query object
  *
  * @return JDatabaseQuery
  */
 public function addFilter(JDatabaseQuery $query)
 {
     if (!$this->filterField) {
         return $query;
     }
     $db = JFactory::getDbo();
     //since joomla 3.0 filter_value can be '' too not only filterNullValue
     if (isset($this->filter_value) && strlen($this->filter_value) > 0 && $this->filter_value != $this->filterNullValue) {
         $query->where(" c." . $this->filterField . " = " . $db->escape($this->filter_value, true));
     }
     return $query;
 }
 /**
  * add filter to query
  *
  * @param   JDatabaseQuery  $query  query object
  *
  * @return JDatabaseQuery
  */
 public function addFilter(JDatabaseQuery $query)
 {
     if (!$this->filterField) {
         return $query;
     }
     $db = JFactory::getDbo();
     //since joomla 3.0 filter_value can be '' too not only filterNullValue
     if (isset($this->filter_value) && strlen($this->filter_value) > 0 && $this->filter_value != $this->filterNullValue) {
         $query->join('INNER', '#__rwf_fields AS rwff ON rwff.id = c.field_id');
         $query->where("rwff.form_id = " . $db->escape($this->filter_value, true));
     }
     return $query;
 }
Example #8
0
 /**
  * Converts an array of values to a string that can be used in SQL to set
  * the according values in a query.
  *
  * @param   array           $data  Values that should be processed.
  * @param   JDatabaseQuery  $q     Optional query object for escaping.
  *
  * @return array
  */
 public static function sqlValues($data, $q = null)
 {
     $output = array();
     foreach ($data as $key => $value) {
         if ($value !== null) {
             if ($q) {
                 $value = $q->escape($value);
             }
             $output[] = $key . ' = "' . $value . '"';
         }
     }
     return $output;
 }
 protected function modifyQuery(JDatabaseQuery &$query)
 {
     $showWhat = array();
     if ($this->getWithWalks) {
         $showWhat[] = "showWithWalks";
     }
     if ($this->getWithSocials) {
         $showWhat[] = "showWithSocials";
     }
     if ($this->getWithWeekends) {
         $showWhat[] = "showWithWeekends";
     }
     $query->where("(" . implode(" OR ", $showWhat) . ")");
 }
Example #10
0
 /**
  * Implements custom filtering
  *
  * @param   \JDatabaseQuery  $query           The model query we're operating on
  * @param   bool             $overrideLimits  Are we told to override limits?
  *
  * @return  void
  */
 protected function onBeforeBuildQuery(\JDatabaseQuery &$query, $overrideLimits = false)
 {
     $db = $this->getDbo();
     $fltItemText = $this->getState('itemtext', null, 'string');
     $fltUserText = $this->getState('usertext', null, 'string');
     $fltCategory = $this->getState('category', null, 'int');
     $fltVersion = $this->getState('version', null, 'int');
     if ($fltItemText) {
         // This extra query approach is required for performance on very large log tables (multiple millions of rows)
         $itemIDs = $this->getItems($fltItemText);
         if (empty($itemIDs)) {
             $query->where('FALSE');
         } else {
             $itemIDs = array_map(array($db, 'quote'), $itemIDs);
             $ids = implode(',', $itemIDs);
             $query->where($db->qn('item_id') . ' IN(' . $ids . ')');
         }
     }
     if ($fltUserText) {
         // This extra query approach is required for performance on very large log tables (multiple millions of rows)
         $userIDs = $this->getUsers($fltUserText);
         if (empty($userIDs)) {
             $query->where('FALSE');
         } else {
             $userIDs = array_map(array($db, 'quote'), $userIDs);
             $ids = implode(',', $userIDs);
             $query->where($db->qn('user_id') . ' IN(' . $ids . ')');
         }
     }
     if ($fltCategory) {
         // We use the double nested subquery instead of whereHas() for memory conservation reasons at the expense of
         // performance.
         $query_inner = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__ars_releases'))->where($db->qn('category_id') . ' = ' . $db->q($fltCategory));
         $query_outer = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__ars_items'))->where($db->qn('release_id') . ' IN (' . $query_inner . ')');
         $db->setQuery($query_outer);
         $ids = $db->loadColumn();
         $clause = '(' . implode(", ", $ids) . ')';
         $query->where($db->qn('item_id') . ' IN ' . $clause);
     }
     if ($fltVersion) {
         // We use the nested subquery instead of whereHas() for memory conservation reasons at the expense of
         // performance.
         $query_outer = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__ars_items'))->where($db->qn('release_id') . ' = ' . $db->q($fltVersion));
         $db->setQuery($query_outer);
         $ids = $db->loadColumn();
         $clause = '(' . implode(", ", $ids) . ')';
         $query->where($db->qn('item_id') . ' IN ' . $clause);
     }
 }
Example #11
0
 /**
  * Prepare result ordering.
  *
  * @param \JDatabaseQuery $query
  * @param array $options
  */
 protected function prepareOrder(&$query, $options)
 {
     // Filter by state.
     if (isset($options["order"])) {
         // Prepare direction of ordering.
         $direction = !isset($options["order_dir"]) ? "DESC" : $options["order_dir"];
         if (!in_array($direction, $this->allowedDirections)) {
             $direction = "DESC";
         }
         switch ($options["order"]) {
             case Constants::ORDER_BY_LOCATION_NAME:
                 // Order by location name.
                 $query->order("l.name " . $direction);
                 break;
             case Constants::ORDER_BY_NUMBER_OF_PROJECTS:
                 // Order by location name.
                 $query->order("project_number " . $direction);
                 break;
             default:
                 // Order by project title.
                 $query->order("a.title " . $direction);
                 break;
         }
     }
 }
Example #12
0
 /**
  * Filter by field.
  *
  * @param  string        $field       Field name.
  * @param  string        $operation   Operation (>|>=|<|<=|=|IN|NOT IN)
  * @param  string|array  $value       Value.
  *
  * @return $this
  */
 public function where($field, $operation, $value)
 {
     $operation = strtoupper($operation);
     switch ($operation) {
         case '>':
         case '>=':
         case '<':
         case '<=':
         case '=':
             $this->query->where("{$this->db->quoteName($field)} {$operation} {$this->db->quote($value)}");
             break;
         case 'BETWEEN':
             list($a, $b) = (array) $value;
             $this->query->where("{$this->db->quoteName($field)} BETWEEN {$this->db->quote($a)} AND {$this->db->quote($b)}");
             break;
         case 'IN':
         case 'NOT IN':
             $value = (array) $value;
             if (empty($value)) {
                 // WHERE field IN (nothing).
                 $this->query->where('0');
             } else {
                 $list = implode(',', $value);
                 $this->query->where("{$this->db->quoteName($field)} {$operation} ({$list})");
             }
             break;
     }
     return $this;
 }
Example #13
0
 /**
  * Adds Count Items for Category Manager.
  *
  * @param   JDatabaseQuery  $query  The query object of com_categories
  *
  * @return  JDatabaseQuery
  *
  * @since   3.4
  */
 public static function countItems($query)
 {
     // Join articles to categories and count published items
     $query->select('COUNT(DISTINCT cp.id) AS count_published');
     $query->join('LEFT', '#__newsfeeds AS cp ON cp.catid = a.id AND cp.published = 1');
     // Count unpublished items
     $query->select('COUNT(DISTINCT cu.id) AS count_unpublished');
     $query->join('LEFT', '#__newsfeeds AS cu ON cu.catid = a.id AND cu.published = 0');
     // Count archived items
     $query->select('COUNT(DISTINCT ca.id) AS count_archived');
     $query->join('LEFT', '#__newsfeeds AS ca ON ca.catid = a.id AND ca.published = 2');
     // Count trashed items
     $query->select('COUNT(DISTINCT ct.id) AS count_trashed');
     $query->join('LEFT', '#__newsfeeds AS ct ON ct.catid = a.id AND ct.published = -2');
     return $query;
 }
 /**
  * Magic function to convert the query to a string.
  *
  * @return  string	The completed query.
  *
  * @since   11.1
  */
 public function __toString()
 {
     $query = '';
     switch ($this->type) {
         case 'insert':
             $query .= (string) $this->insert;
             // Set method
             if ($this->set) {
                 $query .= (string) $this->set;
             } elseif ($this->values) {
                 if ($this->columns) {
                     $query .= (string) $this->columns;
                 }
                 $elements = $this->insert->getElements();
                 $tableName = array_shift($elements);
                 $query .= 'VALUES ';
                 $query .= (string) $this->values;
                 if ($this->autoIncrementField) {
                     $query = 'SET IDENTITY_INSERT ' . $tableName . ' ON;' . $query . 'SET IDENTITY_INSERT ' . $tableName . ' OFF;';
                 }
                 if ($this->where) {
                     $query .= (string) $this->where;
                 }
             }
             break;
         default:
             $query = parent::__toString();
             break;
     }
     return $query;
 }
Example #15
0
 /**
  * Implements custom filtering
  *
  * @param   \JDatabaseQuery  $query           The model query we're operating on
  * @param   bool             $overrideLimits  Are we told to override limits?
  *
  * @return  void
  */
 protected function onBeforeBuildQuery(\JDatabaseQuery &$query, $overrideLimits = false)
 {
     $db = $this->getDbo();
     $fltUsername = $this->getState('username', null, 'string');
     if ($fltUsername) {
         $fltUsername = '******' . $fltUsername . '%';
         $q = $db->getQuery(true)->select(array($db->qn('id')))->from($db->qn('#__users'))->where($db->qn('username') . ' LIKE ' . $db->q($fltUsername), 'OR')->where($db->qn('name') . ' LIKE ' . $db->q($fltUsername))->where($db->qn('email') . ' LIKE ' . $db->q($fltUsername));
         $db->setQuery($q);
         $ids = $db->loadColumn();
         if (!empty($ids)) {
             $ids = array_map(array($db, 'quote'), $ids);
             $query->where($db->qn('user_id') . 'IN (' . implode(',', $ids) . ')');
         } else {
             $query->where($db->qn('user_id') . '=' . $db->q(0));
         }
     }
 }
 /**
  * Tests the JDatabaseQuery::unionAll method.
  *
  * @return  void
  *
  * @since   13.1
  */
 public function testUnionAllTwo()
 {
     TestReflection::setValue($this->_instance, 'unionAll', null);
     $this->_instance->unionAll('SELECT name FROM foo');
     $this->_instance->unionAll('SELECT name FROM bar');
     $teststring = (string) TestReflection::getValue($this->_instance, 'unionAll');
     $this->assertThat($teststring, $this->equalTo(PHP_EOL . "UNION ALL (SELECT name FROM foo)" . PHP_EOL . "UNION ALL (SELECT name FROM bar)"), 'Tests rendered query with two union alls sequentially.');
 }
Example #17
0
 /**
  * Method to get a list of options for a list input.
  *
  * @return      array           An array of JHtml options.
  */
 protected function getOptions()
 {
     $db = JFactory::getDBO();
     $query = new JDatabaseQuery();
     $query->select('#__helloworld.id as id,greeting,#__categories.title as category,catid');
     $query->from('#__helloworld');
     $query->leftJoin('#__categories on catid=#__categories.id');
     $db->setQuery((string) $query);
     $messages = $db->loadObjectList();
     $options = array();
     if ($messages) {
         foreach ($messages as $message) {
             $options[] = JHtml::_('select.option', $message->id, $message->greeting . ($message->catid ? ' (' . $message->category . ')' : ''));
         }
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #18
0
 /**
  * Method to get a list of options for a list input.
  *
  * @return      array           An array of JHtml options.
  */
 protected function getOptions()
 {
     $db = JFactory::getDBO();
     $query = new JDatabaseQuery();
     $query->select('#__jpaudiotracks.id as id,
                                                    pathatweb,
                                                    pathatlocal,
                                                    file,
                                                    title,
                                                    alias,
                                                    tracknumber,
                                                    mediatype,
                                                    bit_rate,
                                                    sample_rate,
                                                    channels,
                                                    channelmode,
                                                    filesize,
                                                    length,
                                                    catid,
                                                    add_datetime,
                                                    artist,
                                                    album,
                                                    year,
                                                    description,
                                                    lyrics,
                                                    frontcover,
                                                    backcover,
                                                    encoder,
                                                    metakey,
                                                    metadesc,
                             #__categories.title as category,catid');
     $query->from('#__jpaudiotracks');
     $query->leftJoin('#__categories on catid=#__categories.id');
     $db->setQuery((string) $query);
     $tracks = $db->loadObjectList();
     $options = array();
     if ($tracks) {
         foreach ($tracks as $track) {
             $options[] = JHtml::_('select.option', $track->id, $track->name . ($track->catid ? ' (' . $track->category . ')' : ''));
         }
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
	static function &getModules()
	{
		static $modules;
		
		if (!is_null($modules))
			return $modules;

		$mainframe = JFactory::getApplication();

		$user =& JFactory::getUser();
		$db	=& JFactory::getDBO();
		$aid = $user->get('aid', 0);

		$groups	= implode(',', $user->getAuthorisedViewLevels());
		$query = new JDatabaseQuery;
		$query->select('id, title, module, position, content, showtitle, params, mm.menuid');
		$query->from('#__modules AS m');
		$query->join('LEFT','#__modules_menu AS mm ON mm.moduleid = m.id');
		$query->where('m.published = 1');

		if (!$user->authorise('core.admin',1)) {
			$query->where('m.access IN (' . $groups . ')');
		}

		$query->where('m.client_id = ' . (int)$mainframe->getClientId());
		$query->order('position, ordering'); 

		$db->setQuery($query);
		$modules = $db->loadObjectList('id');

		if ($db->getErrorNum()) 
		{
			$modules = array();
		}

		foreach ($modules as $key => $mod)
		{
			$module =& $modules[$key];
			$file = $module->module;
			$custom = substr($file, 0, 4) == 'mod_' ? 0 : 1;
			$module->user = $custom;
			$module->name = $custom ? $module->title : substr( $file, 4 );
			$module->style	= null;
			$module->position = strtolower($module->position);
		}
			
		return $modules;
	}
Example #20
0
 /**
  * Method to get a list of options for a list input.
  *
  * @return      array           An array of JHtml options.
  */
 protected function getOptions()
 {
     $db = JFactory::getDBO();
     $query = new JDatabaseQuery();
     $query->select('#__quipforum_boards.id as id,topic');
     $query->from('#__quipforum_boards');
     $db->setQuery((string) $query);
     $messages = $db->loadObjectList();
     $options = array();
     if ($messages) {
         //if($this->allow_all)
         //	$options[] = JHtml::_('select.option', 0, 'Any');
         foreach ($messages as $message) {
             $options[] = JHtml::_('select.option', $message->id, $message->topic);
         }
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #21
0
File: helper.php Project: akksi/jcg
 /**
  * Get a list of logged users.
  *
  * @param	JObject	The module parameters.
  * @return	mixed	An array of articles, or false on error.
  */
 public static function getList($params)
 {
     // Initialise variables
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $query = new JDatabaseQuery();
     $query->select('s.time, s.client_id, u.id, u.name, u.username');
     $query->from('#__session AS s');
     $query->leftJoin('#__users AS u ON s.userid = u.id');
     $query->where('s.guest = 0');
     $db->setQuery($query, 0, $params->get('count', 5));
     $results = $db->loadObjectList();
     // Check for database errors
     if ($error = $db->getErrorMsg()) {
         JError::raiseError(500, $error);
         return false;
     }
     foreach ($results as $k => $result) {
         $results[$k]->logoutLink = '';
         if ($user->authorise('core.manage', 'com_users')) {
             $results[$k]->editLink = JRoute::_('index.php?option=com_users&task=user.edit&id=' . $result->id);
             $results[$k]->logoutLink = JRoute::_('index.php?option=com_login&task=logout&uid=' . $result->id . '&' . JUtility::getToken() . '=1');
         }
         if ($params->get('name', 1) == 0) {
             $results[$k]->name = $results[$k]->username;
         }
     }
     return $results;
 }
 /**
  * @param array $filters
  * @param array $sort_filters
  */
 public function process(array $filters, array $sort_filters = array(), $showUnpublished = false)
 {
     $this->showUnpublished = $showUnpublished;
     $this->setAccessWhere();
     $this->setDisplayedWhere();
     foreach ($filters as $filtertype => $fitlerdata) {
         if (!method_exists($this, $filtertype)) {
             //throw new RokSprocket_Exception(rc__('Unknown Filter %s', $filtertype));
         } else {
             $this->{$filtertype}($fitlerdata);
         }
     }
     foreach ($sort_filters as $sort_filtertype => $sort_fitlerdata) {
         $sort_function = 'sort_' . $sort_filtertype;
         if (!method_exists($this, 'sort_' . $sort_filtertype)) {
             //throw new RokSprocket_Exception(rc__('Unknown Filter %s', $filtertype));
         } else {
             $this->{$sort_function}($sort_fitlerdata);
         }
     }
     if (!empty($this->access_where)) {
         $access_where = sprintf('(%s)', implode(' AND ', $this->access_where));
         $article_where_parts[] = $access_where;
         $filter_where_parts[] = $access_where;
     }
     if (!empty($this->displayed_where)) {
         $displayed_where = sprintf('(%s)', implode(' AND ', $this->displayed_where));
         $article_where_parts[] = $displayed_where;
         $filter_where_parts[] = $displayed_where;
     }
     if (!empty($this->article_where)) {
         $article_where_parts[] = implode(' AND ', $this->article_where);
         $this->query->where(sprintf('(%s)', implode(' AND ', $article_where_parts)), 'OR');
     }
     if (!empty($this->filter_where)) {
         $filter_where_parts[] = implode(' AND ', $this->filter_where);
         $this->query->where(sprintf('(%s)', implode(' AND ', $filter_where_parts)), 'OR');
     }
     if (empty($this->article_where) && empty($this->filter_where)) {
         $this->query->where('0=1');
     }
     if ($this->manualSort) {
         $this->query->join('LEFT OUTER', sprintf('(select rsi.provider_id, rsi.order from #__roksprocket_items as rsi where module_id = %d) rsi on a.id = rsi.provider_id', $this->moduleId));
         array_unshift($this->sort_order, 'rsi.order');
         if ($this->manualAppend == 'after') {
             array_unshift($this->sort_order, 'IF(ISNULL(rsi.order),1,0)');
         }
     }
     foreach ($this->sort_order as $sort) {
         $this->query->order($sort);
     }
 }
 /**
  * @param array $filters
  * @param array $sort_filters
  */
 public function process(array $filters, array $sort_filters = array(), $showUnpublished = false)
 {
     $this->showUnpublished = $showUnpublished;
     $this->setAccessWhere();
     foreach ($filters as $filtertype => $fitlerdata) {
         if (!method_exists($this, $filtertype)) {
             //throw new RokSprocket_Exception(rc__('Unknown Filter %s', $filtertype));
         } else {
             $this->{$filtertype}($fitlerdata);
         }
     }
     foreach ($sort_filters as $sort_filtertype => $sort_fitlerdata) {
         $sort_function = 'sort_' . $sort_filtertype;
         if (!method_exists($this, 'sort_' . $sort_filtertype)) {
             //throw new RokSprocket_Exception(rc__('Unknown Filter %s', $filtertype));
         } else {
             $this->{$sort_function}($sort_fitlerdata);
         }
     }
     if (!empty($this->access_where)) {
         $access_where = sprintf('(%s)', implode(' AND ', $this->access_where));
         $article_where_parts[] = $access_where;
         $filter_where_parts[] = $access_where;
     }
     if (!empty($this->article_where)) {
         $article_where_parts[] = implode(' AND ', $this->article_where);
         $this->query->where(sprintf('(%s)', implode(' AND ', $article_where_parts)), 'OR');
     }
     if (!empty($this->filter_where)) {
         $filter_where_parts[] = implode(' AND ', $this->filter_where);
         $this->query->where(sprintf('(%s)', implode(' AND ', $filter_where_parts)), 'OR');
     }
     if (empty($this->article_where) && empty($this->filter_where)) {
         $this->query->where('0=1');
     }
     foreach ($this->sort_order as $sort) {
         $this->query->order($sort);
     }
 }
Example #24
0
 /**
  * Modify the query to filter list objects by n:n relation.
  *
  * @param F0FModel       $model The model on which operate.
  * @param JDatabaseQuery $query The query to alter.
  */
 public function onAfterBuildQuery(&$model, &$query)
 {
     $input = new F0FInput();
     $db = $model->getDbo();
     // Retrieve the relations configuration for this table
     $table = $model->getTable();
     $key = $table->getConfigProviderKey() . '.relations';
     $relations = $table->getConfigProvider()->get($key, array());
     // For each multiple type relation add the filter query
     foreach ($relations as $relation) {
         if ($relation['type'] == 'multiple') {
             // Get complete relation fields
             $relation = array_merge(array('itemName' => $relation['itemName']), $table->getRelations()->getRelation($relation['itemName'], $relation['type']));
             // Model only save $table->getKnownFields as state, so we look into the input
             $filter_name = $relation['itemName'];
             $model_filter_value = $input->getInt($filter_name);
             // Build the conditions based on relation configuration
             if (!empty($model_filter_value)) {
                 $query->innerJoin(sprintf('%1$s ON %1$s.%2$s = %3$s.%4$s', $db->qn($relation['pivotTable']), $db->qn($relation['ourPivotKey']), $db->qn($table->getTableName()), $db->qn($relation['localKey'])));
                 $query->where(sprintf('%s.%s = %s', $db->qn($relation['pivotTable']), $db->qn($relation['theirPivotKey']), $model_filter_value));
             }
         }
     }
 }
	/**
	 * Tests the JDatabaseQuery::format method.
	 *
	 * @return  void
	 *
	 * @covers  JDatabaseQuery::format
	 * @since   12.3
	 */
	public function testFormat()
	{
		$result = $this->_instance->format('SELECT %n FROM %n WHERE %n = %a', 'foo', '#__bar', 'id', 10);
		$expected = 'SELECT ' . $this->_instance->qn('foo') . ' FROM ' . $this->_instance->qn('#__bar') .
			' WHERE ' . $this->_instance->qn('id') . ' = 10';
		$this->assertThat(
			$result,
			$this->equalTo($expected),
			'Line: ' . __LINE__ . '.'
		);

		$result = $this->_instance->format('SELECT %n FROM %n WHERE %n = %t OR %3$n = %Z', 'id', '#__foo', 'date');
		$expected = 'SELECT ' . $this->_instance->qn('id') . ' FROM ' . $this->_instance->qn('#__foo') .
			' WHERE ' . $this->_instance->qn('date') . ' = ' . $this->_instance->currentTimestamp() .
			' OR ' . $this->_instance->qn('date') . ' = ' . $this->_instance->nullDate(true);
		$this->assertThat(
			$result,
			$this->equalTo($expected),
			'Line: ' . __LINE__ . '.'
		);

	}
 /**
  * Prepare filter by funding state.
  *
  * @param JDatabaseQuery $query
  */
 protected function prepareFilterFundingState(&$query)
 {
     $db = JFactory::getDbo();
     // Filter by funding state.
     $filter = (int) $this->getState($this->context . '.filter_funding_state');
     switch ($filter) {
         case 1:
             // Successfully funded.
             jimport('joomla.date.date');
             $date = new JDate();
             $today = $date->toSql();
             $query->where('a.funding_end < ' . $db->quote($today) . ' AND a.funded >= a.goal');
             break;
     }
 }
Example #27
0
 /**
  * Method to get the database query
  *
  * @return	JDatabaseQuery	The database query
  * @since	1.6
  */
 protected function getListQuery()
 {
     $enabled = $this->getState('filter.enabled');
     $type = $this->getState('filter.type');
     $client = $this->getState('filter.client_id');
     $group = $this->getState('filter.group');
     $hideprotected = $this->getState('filter.hideprotected');
     $query = new JDatabaseQuery();
     $query->select('*');
     $query->from('#__extensions');
     $query->where('state=0');
     if ($hideprotected) {
         $query->where('protected!=1');
     }
     if ($enabled != '') {
         $query->where('enabled=' . intval($enabled));
     }
     if ($type) {
         $query->where('type=' . $this->_db->Quote($type));
     }
     if ($client != '') {
         $query->where('client_id=' . intval($client));
     }
     if ($group != '' && in_array($type, array('plugin', 'library', ''))) {
         $query->where('folder=' . $this->_db->Quote($group == '*' ? '' : $group));
     }
     // Filter by search in id
     $search = $this->getState('filter.search');
     if (!empty($search) && stripos($search, 'id:') === 0) {
         $query->where('extension_id = ' . (int) substr($search, 3));
     }
     return $query;
 }
Example #28
0
 /**
  * Load published modules
  *
  * @return	array
  */
 protected static function &_load()
 {
     static $clean;
     if (isset($clean)) {
         return $clean;
     }
     $Itemid = JRequest::getInt('Itemid');
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $lang = JFactory::getLanguage()->getTag();
     $clientId = (int) $app->getClientId();
     $cache = JFactory::getCache('com_modules', '');
     $cacheid = md5(serialize(array($Itemid, $groups, $clientId, $lang)));
     if (!($clean = $cache->get($cacheid))) {
         $db = JFactory::getDbo();
         $query = new JDatabaseQuery();
         $query->select('id, title, module, position, content, showtitle, params, mm.menuid');
         $query->from('#__modules AS m');
         $query->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id');
         $query->where('m.published = 1');
         $date = JFactory::getDate();
         $now = $date->toMySQL();
         $nullDate = $db->getNullDate();
         $query->where('(m.publish_up = ' . $db->Quote($nullDate) . ' OR m.publish_up <= ' . $db->Quote($now) . ')');
         $query->where('(m.publish_down = ' . $db->Quote($nullDate) . ' OR m.publish_down >= ' . $db->Quote($now) . ')');
         $query->where('m.access IN (' . $groups . ')');
         $query->where('m.client_id = ' . $clientId);
         $query->where('(mm.menuid = ' . (int) $Itemid . ' OR mm.menuid <= 0)');
         // Filter by language
         if ($app->isSite() && $app->getLanguageFilter()) {
             $query->where('m.language IN (' . $db->Quote($lang) . ',' . $db->Quote('*') . ')');
         }
         $query->order('position, ordering');
         // Set the query
         $db->setQuery($query);
         $modules = $db->loadObjectList();
         $clean = array();
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg()));
             return $clean;
         }
         // Apply negative selections and eliminate duplicates
         $negId = $Itemid ? -(int) $Itemid : false;
         $dupes = array();
         for ($i = 0, $n = count($modules); $i < $n; $i++) {
             $module =& $modules[$i];
             // The module is excluded if there is an explicit prohibition, or if
             // the Itemid is missing or zero and the module is in exclude mode.
             $negHit = $negId === (int) $module->menuid || !$negId && (int) $module->menuid < 0;
             if (isset($dupes[$module->id])) {
                 // If this item has been excluded, keep the duplicate flag set,
                 // but remove any item from the cleaned array.
                 if ($negHit) {
                     unset($clean[$module->id]);
                 }
                 continue;
             }
             $dupes[$module->id] = true;
             // Only accept modules without explicit exclusions.
             if (!$negHit) {
                 //determine if this is a custom module
                 $file = $module->module;
                 $custom = substr($file, 0, 4) == 'mod_' ? 0 : 1;
                 $module->user = $custom;
                 // Custom module name is given by the title field, otherwise strip off "com_"
                 $module->name = $custom ? $module->title : substr($file, 4);
                 $module->style = null;
                 $module->position = strtolower($module->position);
                 $clean[$module->id] = $module;
             }
         }
         unset($dupes);
         // Return to simple indexing that matches the query order.
         $clean = array_values($clean);
         $cache->store($clean, $cacheid);
     }
     return $clean;
 }
Example #29
0
	/**
	 * Method to append the primary keys for this table to a query.
	 *
	 * @param   JDatabaseQuery  $query  A query object to append.
	 * @param   mixed           $pk     Optional primary key parameter.
	 *
	 * @return  void
	 *
	 * @since   12.3
	 */
	public function appendPrimaryKeys($query, $pk = null)
	{
		if (is_null($pk))
		{
			foreach ($this->_tbl_keys as $k)
			{
				$query->where($this->_db->quoteName($k) . ' = ' . $this->_db->quote($this->$k));
			}
		}
		else
		{
			if (is_string($pk))
			{
				$pk = array($this->_tbl_key => $pk);
			}

			$pk = (object) $pk;

			foreach ($this->_tbl_keys AS $k)
			{
				$query->where($this->_db->quoteName($k) . ' = ' . $this->_db->quote($pk->$k));
			}
		}
	}
Example #30
0
 /**
  * Magic function to convert the query to a string.
  *
  * @return  string	The completed query.
  *
  * @since   11.1
  */
 public function __toString()
 {
     $query = '';
     switch ($this->type) {
         case 'select':
             $query .= (string) $this->select;
             $query .= (string) $this->from;
             // Get the limit and offset values from JDatabase
             $limit = $this->db->getLimit();
             $offset = $this->db->getOffset();
             if ($limit > 0 || $offset > 0) {
                 if ($this->order) {
                     $query .= (string) $this->order;
                 }
                 $query = $this->processLimit($query, $limit, $offset);
             }
             if ($this->join) {
                 // special case for joins
                 foreach ($this->join as $join) {
                     $query .= (string) $join;
                 }
             }
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             if ($this->group) {
                 $query .= (string) $this->group;
             }
             if ($this->having) {
                 $query .= (string) $this->having;
             }
             break;
         case 'insert':
             $query .= (string) $this->insert;
             // Set method
             if ($this->set) {
                 $query .= (string) $this->set;
             } elseif ($this->values) {
                 if ($this->columns) {
                     $query .= (string) $this->columns;
                 }
                 $elements = $this->insert->getElements();
                 $tableName = array_shift($elements);
                 $query .= 'VALUES ';
                 $query .= (string) $this->values;
                 if ($this->autoIncrementField) {
                     $query = 'SET IDENTITY_INSERT ' . $tableName . ' ON;' . $query . 'SET IDENTITY_INSERT ' . $tableName . ' OFF;';
                 }
                 if ($this->where) {
                     $query .= (string) $this->where;
                 }
             }
             break;
         default:
             $query = parent::__toString();
             break;
     }
     return $query;
 }