/** * Method to get the list of database options. * * This method produces a drop down list of available databases supported * by JDatabaseDriver classes that are also supported by the application. * * @return array The field option objects. * * @since 11.3 * @see JDatabaseDriver::getConnectors() */ protected function getOptions() { // This gets the connectors available in the platform and supported by the server. $available = JDatabaseDriver::getConnectors(); /** * This gets the list of database types supported by the application. * This should be entered in the form definition as a comma separated list. * If no supported databases are listed, it is assumed all available databases * are supported. */ $supported = $this->element['supported']; if (!empty($supported)) { $supported = explode(',', $supported); foreach ($supported as $support) { if (in_array($support, $available)) { $options[$support] = JText::_(ucfirst($support)); } } } else { foreach ($available as $support) { $options[$support] = JText::_(ucfirst($support)); } } // This will come into play if an application is installed that requires // a database that is not available on the server. if (empty($options)) { $options[''] = JText::_('JNONE'); } return $options; }
/** * Validate project owner. * * <code> * $projectId = 1; * $userId = 2; * * $owner = new Crowdfunding\Validator\Project\Owner(\JFactory::getDbo(), $projectId, $userId); * if(!$owner->isValid()) { * ...... * } * </code> * * @return bool */ public function isValid() { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_projects', 'a'))->where('a.id = ' . (int) $this->projectId)->where('a.user_id = ' . (int) $this->userId); $this->db->setQuery($query, 0, 1); return (bool) $this->db->loadResult(); }
/** * Get table columns. * * @param string $table Table name. * * @return array Table columns with type. */ public function getColumns($table) { if (empty(self::$columnCache[$table])) { self::$columnCache[$table] = $this->db->getTableColumns($table); } return self::$columnCache[$table]; }
/** * Remove an extra image from database and file system. * * <code> * $imageId = 1; * $imagesFolder = "/.../folder"; * * $image = new CrowdFundingImageRemoverExtra(JFactory::getDbo(), $image, $imagesFolder); * $image->remove(); * </code> */ public function remove() { // Get the image $query = $this->db->getQuery(true); $query->select("a.image, a.thumb")->from($this->db->quoteName("#__crowdf_images", "a"))->where("a.id = " . (int) $this->imageId); $this->db->setQuery($query); $row = $this->db->loadObject(); if (!empty($row)) { // Remove the image from the filesystem $file = JPath::clean($this->imagesFolder . DIRECTORY_SEPARATOR . $row->image); if (JFile::exists($file)) { JFile::delete($file); } // Remove the thumbnail from the filesystem $file = JPath::clean($this->imagesFolder . DIRECTORY_SEPARATOR . $row->thumb); if (JFile::exists($file)) { JFile::delete($file); } // Delete the record $query = $this->db->getQuery(true); $query->delete($this->db->quoteName("#__crowdf_images"))->where($this->db->quoteName("id") . " = " . (int) $this->imageId); $this->db->setQuery($query); $this->db->execute(); } }
/** * This method loads data about e-mail template from a database. * * <code> * $emailId = 1; * * $email = new Emailtemplates\Email(); * $email->setDb(JFactory::getDbo()); * $email->load($emailId); * </code> * * @param int $id */ public function load($id) { $query = $this->db->getQuery(true); $query->select('a.id, a.title, a.subject, a.body, a.sender_name, a.sender_email, a.catid')->from($this->db->quoteName('#__emailtemplates_emails', 'a'))->where('a.id = ' . (int) $id); $this->db->setQuery($query); $result = (array) $this->db->loadAssoc(); $this->bind($result); }
/** * Validate project owner. * * <code> * $projectId = 1; * $userId = 2; * * $owner = new Crowdfunding\Validator\Project\Owner(\JFactory::getDbo(), $projectId, $userId); * if(!$owner->isValid()) { * ...... * } * </code> * * @return bool */ public function isValid() { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.id = " . (int) $this->projectId)->where("a.user_id = " . (int) $this->userId); $this->db->setQuery($query, 0, 1); $result = $this->db->loadResult(); return (bool) $result; }
protected function load() { $query = $this->db->getQuery(true); $query->select('a.id, a.name')->from($this->db->quoteName('#__itpsc_countries', 'a'))->order('a.name ASC'); // Get the options. $this->db->setQuery($query); $this->data = $this->db->loadAssocList('id', 'name'); }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\Gravatar(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (!empty($ids)) { $query = $this->db->getQuery(true); $query->select("a.id AS user_id, a.email, MD5(a.email) as hash")->from($this->db->quoteName("#__users", "a"))->where("a.id IN ( " . implode(",", $ids) . ")"); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList("user_id"); } }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\Gravatar(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (count($ids) > 0) { $query = $this->db->getQuery(true); $query->select('a.id AS user_id, a.email, MD5(a.email) as hash')->from($this->db->quoteName('#__users', 'a'))->where('a.id IN ( ' . implode(',', $ids) . ')'); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList('user_id'); } }
/** * Is an id exists? * * @param int|string $id The id to find. * * @return boolean True if exists. */ public function exists($id) { $query = $this->db->getQuery(true); $query->select($this->pkName)->from($this->table)->where($query->format('%n = %q', $this->pkName, $id)); if ($this->db->setQuery($query)->loadResult()) { return true; } return false; }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\JomSocial(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (count($ids) > 0) { $query = $this->db->getQuery(true); $query->select('a.userid AS user_id, a.avatar, a.thumb')->from($this->db->quoteName('#__community_users', 'a'))->where('a.userid IN ( ' . implode(',', $ids) . ')'); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList('user_id'); } }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\JomSocial(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (!empty($ids)) { $query = $this->db->getQuery(true); $query->select("a.userid AS user_id, a.avatar, a.thumb")->from($this->db->quoteName("#__community_users", "a"))->where("a.userid IN ( " . implode(",", $ids) . ")"); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList("user_id"); } }
/** * Remove all address for the user name * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was successfully stored in the database * @param string $msg Message * * @return boolean * * @since 1.6 */ public function onUserAfterDelete($user, $success, $msg) { if (!$success) { return false; } $query = $this->db->getQuery(true)->delete($this->db->quoteName('#__dogecointipping_address'))->where($this->db->quoteName('user_id') . ' = ' . (int) $user['id']); $this->db->setQuery($query)->execute(); return true; }
/** * Load country data from database. * * <code> * $countryId = 1; * * $country = new CrowdFundingCountry(JFactory::getDbo()); * $country->load($countryId); * </code> * * @param int $id */ public function load($id) { $query = $this->db->getQuery(true); $query->select("a.id, a.name, a.code, a.code4, a.latitude, a.longitude, a.currency, a.code")->from($this->db->quoteName("#__crowdf_countries", "a"))->where("a.id = " . (int) $id); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!empty($result)) { $this->bind($result); } }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\Kunena(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $userIds */ public function load(array $userIds) { if (count($userIds) > 0) { // Create a new query object. $query = $this->db->getQuery(true); $query->select('a.userid AS user_id, a.avatar')->from($this->db->quoteName('#__kunena_users', 'a'))->where('a.userid IN ( ' . implode(',', $userIds) . ')'); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList('user_id'); } }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\Kunena(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (!empty($ids)) { // Create a new query object. $query = $this->db->getQuery(true); $query->select("a.userid AS user_id, a.avatar")->from($this->db->quoteName("#__kunena_users", "a"))->where("a.userid IN ( " . implode(",", $ids) . ")"); $this->db->setQuery($query); $this->profiles = (array) $this->db->loadObjectList("user_id"); } }
/** * This method loads data about e-mail template from a database. * * <code> * $emailId = 1; * * $email = new UserIdeasEmail(); * $email->setDb(JFactory::getDbo()); * $email->load($emailId); * </code> */ public function load($id) { $query = $this->db->getQuery(true); $query->select("a.id, a.title, a.subject, a.body, a.sender_name, a.sender_email")->from($this->db->quoteName("#__uideas_emails", "a"))->where("a.id = " . (int) $id); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!empty($result)) { $this->bind($result); } }
/** * Load location data from database. * * <code> * $locationId = 1; * * $location = new Crowdfunding\Location(\JFactory::getDbo()); * $location->load($locationId); * </code> * * @param int $id */ public function load($id) { $query = $this->db->getQuery(true); $query->select("a.id, a.name, a.latitude, a.longitude, a.country_code, a.state_code, a.timezone, a.published")->from($this->db->quoteName("#__crowdf_locations", "a"))->where("a.id = " . (int) $id); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!empty($result)) { $this->bind($result); } }
/** * Load data of a record from database. * * <code> * $id = 1; * * $partner = new CrowdfundingPartners\Partner(); * $partner->setDb(\JFactory::getDbo()); * $partner->load($id); * </code> * * @param int $keys * @param array $options */ public function load($keys, $options = array()) { $query = $this->db->getQuery(true); $query->select("a.id, a.name, a.project_id, a.partner_id")->from($this->db->quoteName("#__cfpartners_partners", "a"))->where("a.id = " . (int) $keys); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!$result) { $result = array(); } $this->bind($result); }
/** * Get total amount of all transactions. * * <code> * $statistics = new CrowdFundingStatisticsBasic(JFactory::getDbo()); * $total = $statistics->getTotalAmount(); * </code> */ public function getTotalAmount() { $query = $this->db->getQuery(true); $query->select("SUM(a.txn_amount)")->from($this->db->quoteName("#__crowdf_transactions", "a")); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Load a data about a type from database. * * @param int $id Type ID * * <code> * $typeId = 1; * * $type = new CrowdFundingType(JFactory::getDbo()); * $type->load($typeId); * </code> */ public function load($id) { $query = $this->db->getQuery(true); $query->select("a.id, a.title, a.description, a.params")->from($this->db->quoteName("#__crowdf_types", "a"))->where("a.id = " . (int) $id); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!$result) { $result = array(); } $this->bind($result); }
/** * This method returns a number of all comments. * * @return int */ public function getTotalComments() { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__uideas_comments", "a")); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Load user data * * <code> * $userId = 1; * * $profile = new ITPrismIntegrateProfileGravatar(); * $profile->load($userId); * </code> * * @param int $id */ public function load($id) { $query = $this->db->getQuery(true); $query->select("a.id AS user_id, a.email")->from($this->db->quoteName("#__users", "a"))->where("a.id = " . (int) $id); $this->db->setQuery($query); $result = $this->db->loadAssoc(); if (!empty($result)) { // Set values to variables $this->bind($result); } }
/** * Allows the application to load a custom or default database driver. * * @param JDatabaseDriver $driver An optional database driver object. If omitted, the application driver is created. * * @return JApplicationBase This method is chainable. * * @since 12.1 */ public function loadDatabase(JDatabaseDriver $driver = null) { if ($driver === null) { $this->db = JDatabaseDriver::getInstance(array('driver' => $this->get('db_driver'), 'host' => $this->get('db_host'), 'user' => $this->get('db_user'), 'password' => $this->get('db_pass'), 'database' => $this->get('db_name'), 'prefix' => $this->get('db_prefix'))); // Select the database. $this->db->select($this->get('db_name')); } else { $this->db = $driver; } // Set the database to our static cache. JFactory::$database = $this->db; return $this; }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new ITPrismIntegrateProfilesGravatar(); * $profiles->load($ids); * </code> * * @param $ids */ public function load($ids) { if (!empty($ids)) { $query = $this->db->getQuery(true); $query->select("a.id AS user_id, a.email")->from($this->db->quoteName("#__users", "a"))->where("a.id IN ( " . implode(",", $ids) . ")"); $this->db->setQuery($query); $results = $this->db->loadObjectList(); if (!empty($results)) { foreach ($results as $result) { $this->profiles[$result->user_id] = $result; } } } }
/** * Load images from database. * * <code> * $projectId = 1; * * $options = array( * "order_direction" => "DESC" * ); * * $images = new CrowdFundingImages(JFactory::getDbo()); * $images->load($projectId, $options); * * foreach($images as $image) { * echo '<img src="'.$image["thumb"].'" />'; * echo '<img src="'.$image["image"].'" />'; * } * </code> * * @param $id * @param array $options * * @return array|mixed */ public function load($id, $options = array()) { $query = $this->db->getQuery(true); $query->select("a.id, a.image, a.thumb, a.project_id")->from($this->db->quoteName("#__crowdf_images", "a"))->where("a.project_id = " . (int) $id); if (isset($options["order_direction"])) { $orderDir = strcmp("DESC", $options["order_direction"]) ? "DESC" : "ASC"; $query->order("a.id " . $this->db->escape($orderDir)); } $this->db->setQuery($query); $results = $this->db->loadObjectList(); if (!$results) { $results = array(); } $this->items = $results; }
/** * {@inheritdoc} * * @param array $options Configuration options * * @return JDatabaseDriver * * @since 1.0 */ public static function getInstance($options = array()) { $options['driver'] = isset($options['driver']) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $options['driver']) : 'mysqli'; $options['database'] = isset($options['database']) ? $options['database'] : null; $options['select'] = isset($options['select']) ? $options['select'] : true; // Get an option hash to identify the instance $driverSignature = md5(serialize($options)); // Check if the driver has been already instantiated if (empty(self::$instances[$driverSignature])) { // If the class doesn't exists, we cannot work with this driver. if (!self::isMySQL($options['driver'])) { // Let's using parent method return parent::getInstance($options); } // Let's create our driver instance using the options given.s try { /* @var $instance NenoDatabaseDriverMysqlx */ $instance = new NenoDatabaseDriverMysqlx($options); $instance->refreshTranslatableTables(); } catch (RuntimeException $ex) { throw new RuntimeException(sprintf('Unable to connect to the database. Error: %s', $ex->getMessage())); } // Save the instance into the instances set. self::$instances[$driverSignature] = $instance; // Load the tables configured to be translatable $instance->refreshTranslatableTables(); } return self::$instances[$driverSignature]; }
/** * Method to unlock the database table for writing. * * @return boolean True on success. * * @since 11.1 */ protected function _unlock() { $this->_db->unlockTables(); $this->_locked = false; return true; }
/** * Save the plugin parameters * * @return boolean * * @since 3.5 */ private function saveParams() { // Update params $this->params->set('lastrun', time()); $this->params->set('unique_id', $this->getUniqueId()); $interval = (int) $this->params->get('interval', 12); $this->params->set('interval', $interval ? $interval : 12); $query = $this->db->getQuery(true)->update($this->db->quoteName('#__extensions'))->set($this->db->quoteName('params') . ' = ' . $this->db->quote($this->params->toString('JSON')))->where($this->db->quoteName('type') . ' = ' . $this->db->quote('plugin'))->where($this->db->quoteName('folder') . ' = ' . $this->db->quote('system'))->where($this->db->quoteName('element') . ' = ' . $this->db->quote('stats')); try { // Lock the tables to prevent multiple plugin executions causing a race condition $this->db->lockTable('#__extensions'); } catch (Exception $e) { // If we can't lock the tables it's too risky to continue execution return false; } try { // Update the plugin parameters $result = $this->db->setQuery($query)->execute(); $this->clearCacheGroups(array('com_plugins'), array(0, 1)); } catch (Exception $exc) { // If we failed to execute $this->db->unlockTables(); $result = false; } try { // Unlock the tables after writing $this->db->unlockTables(); } catch (Exception $e) { // If we can't lock the tables assume we have somehow failed $result = false; } return $result; }
/** * Tests the JDatabaseDriver::truncateTable method. * * @return void * * @since 12.1 */ public function testTruncateTable() { $this->assertNull( $this->db->truncateTable('#__dbtest'), 'truncateTable should not return anything if successful.' ); }