/** * Method to get the content types. * * @return array An array of JContentType objects. * * @since 12.1 * @throws RuntimeException */ public function getTypes() { $types = array(); // Get the cache store id. $storeId = $this->getStoreId('getTypes'); // Attempt to retrieve the types from cache first. $cached = $this->retrieve($storeId); // Check if the cached value is usable. if (is_array($cached)) { return $cached; } // Build the query to get the content types. $query = $this->db->getQuery(true); $query->select('a.*'); $query->from($query->qn('#__content_types') . ' AS a'); // Get the content types. $this->db->setQuery($query); $results = $this->db->loadObjectList(); // Reorganize the type information. foreach ($results as $result) { // Create a new JContentType object. $type = $this->factory->getType(); // Bind the type data. $type->bind($result); // Add the type, keyed by alias. $types[$result->alias] = $type; } // Store the types in cache. return $this->store($storeId, $types); }
/** * Constructor. */ public function __construct() { if (!$this->table) { throw new DomainException('Table name missing from ' . get_class($this)); } $this->db = JFactory::getDbo(); $this->query = $this->db->getQuery(true); $this->query->from($this->table . ' AS a'); }
/** * Execute the application. * * @return void */ public function doExecute() { // Get the query builder class from the database and set it up // to select everything in the 'db' table. $query = $this->dbo->getQuery(true)->select('*')->from($this->dbo->qn('db')); // Push the query builder object into the database connector. $this->dbo->setQuery($query); // Get all the returned rows from the query as an array of objects. $rows = $this->dbo->loadObjectList(); // Just dump the value returned. var_dump($rows); }
public function cleanBeforeMigrate() { $db = $this->dbo; $query = $this->dbo->getQuery(true); $query->delete($db->quoteName('#__akrecipes_recipe')); $this->dbo->setQuery($query); $this->dbo->execute(); // now content items $query = $this->dbo->getQuery(true); $conditions = array($db->quoteName('id') . ' <> 1'); $query->delete($db->quoteName('#__content')); $query->where($conditions); $this->dbo->setQuery($query); $this->dbo->execute(); // now categories $query = $this->dbo->getQuery(true); $conditions = array($db->quoteName('extension') . ' = ' . $db->quote('com_akrecipes')); $query->delete($db->quoteName('#__categories')); $query->where($conditions); $this->dbo->setQuery($query); $this->dbo->execute(); // now categories $query = $this->dbo->getQuery(true); $conditions = array($db->quoteName('extension') . ' = ' . $db->quote('com_content'), '!(' . $db->quoteName('id') . ' = 2 OR ' . $db->quoteName('id') . ' = 26)'); $query->delete($db->quoteName('#__categories')); $query->where($conditions); $this->dbo->setQuery($query); //$this->dbo->execute(); }
/** * Method to load an object by primary id. * * @return void * * @since 12.1 * @throws RuntimeException */ protected function doLoad() { // Get the primary key. $primaryKey = $this->getTableKey('primary', 'primary'); $primaryTable = $this->getTableExpression('primary'); // Build the query object. $query = $this->db->getQuery(true); $query->select($this->getTableKeyExpression('primary', '*')); $query->from($primaryTable); $query->where($this->getTableKeyExpression('primary', 'primary') . ' = ' . (int) $this->{$primaryKey}); // Get the subtables. $tables = $this->tables; unset($tables['primary']); // Add additional tables to the query. foreach ($tables as $alias => $table) { // Add the table select and join clauses. $query->select($this->getTableKeyExpression($alias, '*')); $query->join('INNER', $this->getTableExpression($alias)); } // Get the content data. $this->db->setQuery($query); $data = $this->db->loadObject(); // Check the type data. if (empty($data)) { throw new RuntimeException(JText::sprintf('JDATABASEOBJECT_NOT_FOUND', $this->{$primaryKey}, $primaryTable)); } // Bind the data. $this->bind($data); }
/** * Generic check for whether dependencies exist for this object in the database schema * * Can be overloaded/supplemented by the child class * * @param mixed $pk An optional primary key value check the row for. If not * set the instance property value is used. * @param array $joins An optional array to compiles standard joins formatted like: * [label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field'] * * @return boolean True on success. * * @deprecated 12.1 * @link http://docs.joomla.org/JTable/canDelete * @since 11.1 */ public function canDelete($pk = null, $joins = null) { // Deprecation warning. JLog::add('JTable::canDelete() is deprecated.', JLog::WARNING, 'deprecated'); // Initialise variables. $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; // If no primary key is given, return false. if ($pk === null) { return false; } if (is_array($joins)) { // Get a query object. $query = $this->_db->getQuery(true); // Setup the basic query. $query->select($this->_db->quoteName($this->_tbl_key)); $query->from($this->_db->quoteName($this->_tbl)); $query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->{$k})); $query->group($this->_db->quoteName($this->_tbl_key)); // For each join add the select and join clauses to the query object. foreach ($joins as $table) { $query->select('COUNT(DISTINCT ' . $table['idfield'] . ') AS ' . $table['idfield']); $query->join('LEFT', $table['name'] . ' ON ' . $table['joinfield'] . ' = ' . $k); } // Get the row object from the query. $this->_db->setQuery((string) $query, 0, 1); $row = $this->_db->loadObject(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } $msg = array(); $i = 0; foreach ($joins as $table) { $k = $table['idfield'] . $i; if ($row->{$k}) { $msg[] = JText::_($table['label']); } $i++; } if (count($msg)) { $this->setError("noDeleteRecord" . ": " . implode(', ', $msg)); return false; } else { return true; } } return true; }
function jotcache_upgrade(JDatabase $db) { $message = ''; $query = $db->getQuery(true); $query->select('COUNT(*)')->from('#__jotcache_exclude')->where('type=1'); $tplex_count = $db->setQuery($query)->loadResult(); if ($tplex_count == 0) { return false; } $query->clear('where'); $query->where('type=4'); $count = $db->setQuery($query)->loadResult(); if ($count == 0) { $query->clear('select')->clear('where'); $query->select($db->quoteName('value'))->from($db->quoteName('#__template_styles', 's'))->where('name=s.id')->where('type=1')->order('s.home'); $defs = $db->setQuery($query)->loadResultArray(); $positions = array(); foreach ($defs as $def) { $def_array = unserialize($def); $positions = array_merge($positions, $def_array); } $query->clear(); $query->select('position')->from('#__modules')->where('client_id = 0')->where('published = 1')->where('position <>' . $db->quote(''))->group('position')->order('position'); $db->setQuery($query); $items = $db->loadResultArray(); $cleaned_positions = array(); foreach ($items as $item) { if (array_key_exists($item, $positions)) { $cleaned_positions[$item] = $positions[$item]; } } $defs = serialize($cleaned_positions); $query->clear(); $query->insert('#__jotcache_exclude')->columns('name,value,type')->values('1,' . $db->quote($defs) . ',4'); if ($db->setQuery($query)->query()) { $message = "TABLE #__jotcache_exclude has been upgraded. Check JotCache TPL exclude definitions for correct values."; } else { JError::raiseNotice(100, $db->getErrorMsg()); } return $message; } }
/** * Description * * @access public * @param $oid * @param $log */ function hit() { if (!in_array('hits', array_keys($this->getProperties()))) { return; } $k = $this->_tbl_key; $query = $this->_db->getQuery(true); $query->update($this->_db->quoteName($this->_tbl)); $query->set(' hits = ( hits + 1 ) '); // check whether all fields are filled and build where statement for ($i = 0; $i < count($k); $i++) { if ($this->{$k}[$i] === null) { return false; } else { $query->where(' ' . $this->_db->quoteName($k[$i]) . ' = ' . $this->_db->Quote($this->{$k}[$i]) . ' '); } } $this->_db->setQuery($query); $this->_db->query(); $this->hits++; }
/** * Custom doExecute method. * * This method loads a list of the published plugins from the 'cron' group, * then loads the plugins and registers them against the 'doCron' event. * The event is then triggered and results logged. * * Any configuration for the cron plugins is done via the Joomla CMS * administrator interface and plugin parameters. * * @return void * * @since 11.3 */ public function doExecute() { // // Check we have some critical information. // if (!defined('JPATH_PLUGINS') || !is_dir(JPATH_PLUGINS)) { throw new Exception('JPATH_PLUGINS not defined'); } // Add a start message. JLog::add('Starting cron run.'); // // Prepare the plugins // // Get the quey builder class from the database. $query = $this->dbo->getQuery(true); // Get a list of the plugins from the database. $query->select('p.*')->from('#__extensions AS p')->where('p.enabled = 1')->where('p.type = ' . $this->dbo->quote('plugin'))->where('p.folder = ' . $this->dbo->quote('cron'))->order('p.ordering'); // Push the query builder object into the database connector. $this->dbo->setQuery($query); // Get all the returned rows from the query as an array of objects. $plugins = $this->dbo->loadObjectList(); // Log how many plugins were loaded from the database. JLog::add(sprintf('.loaded %d plugin(s).', count($plugins))); // Loop through each of the results from the database query. foreach ($plugins as $plugin) { // Build the class name of the plugin. $className = 'plg' . ucfirst($plugin->folder) . ucfirst($plugin->element); $element = preg_replace('#[^A-Z0-9-~_]#i', '', $plugin->element); // If the class doesn't already exist, try to load it. if (!class_exists($className)) { // Compute the path to the plugin file. $path = sprintf(rtrim(JPATH_PLUGINS, '\\/') . '/cron/%s/%s.php', $element, $element); // Check if the file exists. if (is_file($path)) { // Include the file. include $path; // Double check if we have a valid class. if (!class_exists($className)) { // Log a warning and contine to the next record. JLog::add(sprintf('..plugin class for `%s` not found in file.', $element), JLog::WARNING); continue; } } else { // Log a warning and contine to the next record. JLog::add(sprintf('..plugin file for `%s` not found.', $element), JLog::WARNING); continue; } } JLog::add(sprintf('..registering `%s` plugin.', $element)); // Register the event. $this->registerEvent('doCron', new $className($this->dispatcher, array('params' => new JRegistry($plugin->params)))); } // // Run the cron plugins. // // Each plugin should have been installed in the Joomla CMS site // and must include a 'doCron' method. Configuration of the plugin // is done via plugin parameters. // JLog::add('.triggering `doCron` event.'); // Trigger the event and let the Joomla plugins do all the work. $results = $this->triggerEvent('doCron'); // Log the results. foreach ($this->triggerEvent('doCron') as $result) { JLog::add(sprintf('..plugin returned `%s`.', var_export($result, true))); } JLog::add('Finished cron run.'); }
/** * @return string The current value of the internal SQL vairable */ public function getQuery() { return $this->_db->getQuery(); }
function sortearEliminatoria(array $equipos, $numRows_eq, JDatabase $db_ins_part, $id_grupo, JDatabase $db_ins_jor) { $cantidad_equipos = $numRows_eq; $cantidad_partidos = $cantidad_equipos - 1; $cantidad_jornadas = ceil(log($cantidad_equipos, 2)); $preliminares = $cantidad_equipos - pow(2, floor(log($cantidad_equipos, 2))); $standby = $cantidad_equipos - $preliminares * 2; $partidos_potencia2 = $cantidad_equipos / 2; $partidos_ronda2 = ($standby + $preliminares) / 2; // echo "Equipos:".$cantidad_equipos."<br>"; // echo "Partidos:".$cantidad_partidos."<br>"; // echo "Jornadas:".$cantidad_jornadas."<br>"; // echo "Preliminares:".$preliminares."<br>"; // echo "Espera:".$standby."<br>"; // echo "Partidos potencia 2: ".$partidos_potencia2."<br>"; // echo "Partidos ronda 2: ".$partidos_ronda2."<br>"; $partidos = array(); $equipos_partido = array(); $nombre_jornadas = array('Final', 'Semifinal', 'Cuartos de Final', 'Octavos de Final', 'Primera Ronda', 'Preliminares'); $x = 0; // $y=0; // $y=$cantidad_equipos-1; $y = $preliminares * 2 - 1; //Insertar primer jornada for ($i = 0; $i < $cantidad_jornadas; $i++) { if ($preliminares == 0) { switch ($i) { case 0: $descr_jor = $nombre_jornadas[$i]; case 1: $descr_jor = $nombre_jornadas[$i]; case 2: $descr_jor = $nombre_jornadas[$i]; case 3: $descr_jor = $nombre_jornadas[$i]; case 4: $descr_jor = $nombre_jornadas[$i]; case 5: $descr_jor = $nombre_jornadas[$i]; } } else { switch ($i) { case 0: $descr_jor = $nombre_jornadas[$i]; case 1: $descr_jor = $nombre_jornadas[$i]; case 2: $descr_jor = $nombre_jornadas[$i]; case 3: $descr_jor = $nombre_jornadas[$i]; case 4: $descr_jor = $nombre_jornadas[$i]; case 5: $descr_jor = $nombre_jornadas[$i]; } } try { $query_ins_jor = $db_ins_jor->getQuery(true); $columns = array('descripcion', 'id_grupo', 'numero'); $values = array($db_ins_jor->quote($descr_jor), $id_grupo, $i + 1); $query_ins_jor->insert($db_ins_jor->quoteName('jornada'))->columns($db_ins_jor->quoteName($columns))->values(implode(',', $values)); $db_ins_jor->setQuery($query_ins_jor); $db_ins_jor->execute(); $id_jornada = $db_ins_jor->insertid(); } catch (Exception $e) { echo $e; } if ($preliminares != 0) { $partidos_ronda = pow(2, $i); if ($i == $cantidad_jornadas - 1) { $partidos_ronda = $preliminares; } for ($j = 0; $j < $partidos_ronda; $j++) { if ($i == $cantidad_jornadas - 1) { $equipos_partido[0] = $equipos[$x]; $equipos_partido[1] = $equipos[$x + 1]; $partidos[$j] = $equipos_partido; try { $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_torneo', 'id_jornada'); // Insert values. $values = array($_SESSION['id_torneo'], $id_jornada); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); $id_partido = $db_ins_part->insertid(); $equipos_p = $partidos[$j]; $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_equipo1', 'id_equipo2', 'id_partido'); // Insert values. $values = array($equipos_p[0]->id_eq, $equipos_p[1]->id_eq, $id_partido); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido_equipos'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); } catch (Exception $e) { echo $e; } $x++; $x++; } elseif ($i == $cantidad_jornadas - 2) { $dividido = ceil($preliminares / 2); $equipos_partido[0] = $equipos[$y]; if (isset($equipos[$y + 1])) { $equipos_partido[1] = $equipos[$y + 1]; } $partidos[$j] = $equipos_partido; if ($preliminares % 2 == 0) { if ($j < $dividido) { $equipos_partido[0] = 26; $equipos_partido[1] = 26; $partidos[$j] = $equipos_partido; } } else { if ($j < $dividido) { if ($j == $dividido - 1) { $equipos_partido[0] = 26; $equipos_partido[1] = $equipos[$y + 1]; $partidos[$j] = $equipos_partido; } elseif ($j < $dividido - 1) { $equipos_partido[0] = 26; $equipos_partido[1] = 26; $partidos[$j] = $equipos_partido; } } } try { $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_torneo', 'id_jornada'); // Insert values. $values = array($_SESSION['id_torneo'], $id_jornada); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); $id_partido = $db_ins_part->insertid(); $equipos_p = $partidos[$j]; $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_equipo1', 'id_equipo2', 'id_partido'); // Insert values. if ($j < $dividido) { if ($preliminares % 2 == 0) { $values = array($equipos_p[0], $equipos_p[1], $id_partido); } else { if ($j == $dividido - 1) { $values = array($equipos_p[0], $equipos_p[1]->id_eq, $id_partido); } else { $values = array($equipos_p[0], $equipos_p[1], $id_partido); } } } elseif ($j >= $dividido) { $values = array($equipos_p[0]->id_eq, $equipos_p[1]->id_eq, $id_partido); } // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido_equipos'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); } catch (Exception $e) { echo $e; } $y++; $y++; } else { try { $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_torneo', 'id_jornada'); // Insert values. $values = array($_SESSION['id_torneo'], $id_jornada); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); $id_partido = $db_ins_part->insertid(); // $equipos_p = $partidos[$j]; $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_equipo1', 'id_equipo2', 'id_partido'); // Insert values. $values = array(26, 26, $id_partido); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido_equipos'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); } catch (Exception $e) { echo $e; } } } } else { $partidos_ronda = pow(2, $i); for ($j = 0; $j < $partidos_ronda; $j++) { if ($i == $cantidad_jornadas - 1) { $equipos_partido[0] = $equipos[$x]; $equipos_partido[1] = $equipos[$x + 1]; $partidos[$j] = $equipos_partido; try { $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_torneo', 'id_jornada'); // Insert values. $values = array($_SESSION['id_torneo'], $id_jornada); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); $id_partido = $db_ins_part->insertid(); $equipos_p = $partidos[$j]; $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_equipo1', 'id_equipo2', 'id_partido'); // Insert values. $values = array($equipos_p[0]->id_eq, $equipos_p[1]->id_eq, $id_partido); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido_equipos'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); } catch (Exception $e) { echo $e; } $x++; $x++; } else { try { $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_torneo', 'id_jornada'); // Insert values. $values = array($_SESSION['id_torneo'], $id_jornada); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); $id_partido = $db_ins_part->insertid(); // $equipos_p = $partidos[$j]; $query_ins_part = $db_ins_part->getQuery(true); // Insert columns. $columns = array('id_equipo1', 'id_equipo2', 'id_partido'); // Insert values. $values = array(26, 26, $id_partido); // Prepare the insert query. $query_ins_part->insert($db_ins_part->quoteName('partido_equipos'))->columns($db_ins_part->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db_ins_part->setQuery($query_ins_part); $db_ins_part->execute(); } catch (Exception $e) { echo $e; } } } } } }
/** * Returns a new configuration registry from a source configuration * SQL table. This method uses the JDatabase object. * * @param JDatabase $handler Connected and active JDatabase object. * @param string $table Database table to use. * * @return JRegistry Registry of configuration. * * @since 2.0 */ protected static function createDBConfig(JDatabase $handler, $table) { // Create the registry with a default namespace of config $registry = new JRegistry; $query = $handler->getQuery(true); // Do the SQL query ensuring only platform specific entries are returned $query->select($query->quoteName('name')) ->select($query->quoteName('value')) ->from($query->quoteName($table)) ->order($query->quoteName('id')); $handler->setQuery($query); // Load the SQL query into an associative array $array = $handler->loadAssocList('name', 'value'); if (!is_null($array)) { foreach ($array as $key => $value) { // Ensure compatibility between group.config and group:config $registry->set(str_replace(':', '.', $key), $value); $registry->set(str_replace('.', ':', $key), $value); } } return $registry; }
/** */ public function __construct() { $this->db = JFactory::getDbo(); $this->query = $this->db->getQuery(true); $this->setBaseQuery(); }