/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\EasySocial(\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.name, a.username, ' . 'b.alias, b.permalink, ' . 'c.small, c.medium, c.square, c.large')->from($this->db->quoteName('#__users', 'a'))->leftJoin($this->db->quoteName('#__social_users', 'b') . ' ON a.id = b.user_id')->leftJoin($this->db->quoteName('#__social_avatars', 'c') . ' ON a.id = c.uid')->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\EasySocial(\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.name, a.username, " . "b.alias, b.permalink, " . "c.small, c.medium, c.square, c.large")->from($this->db->quoteName("#__users", "a"))->leftJoin($this->db->quoteName("#__social_users", "b") . " ON a.id = b.user_id")->leftJoin($this->db->quoteName("#__social_avatars", "c") . " ON a.id = c.uid")->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\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"); } }
/** * 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'); } }
/** * 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\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\EasyProfile(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (count($ids) > 0) { // Create a new query object. $query = $this->db->getQuery(true); $query->select('a.id AS user_id, a.avatar, ' . $query->concatenate(array('b.id', 'b.username'), ':') . ' AS slug')->from($this->db->quoteName('#__jsn_users', 'a'))->innerJoin($this->db->quoteName('#__users', 'b') . ' ON a.id = b.id')->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\CommunityBuilder(\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.id AS user_id, a.name, " . "b.avatar, " . $query->concatenate(array("a.id", "a.username"), ":") . " AS slug")->from($this->db->quoteName("#__users", "a"))->innerJoin($this->db->quoteName("#__comprofiler", "b") . " ON a.id = b.user_id")->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\SocialCommunity(\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.id AS user_id, a.image_icon, a.image_small, a.image_square, a.image, " . $query->concatenate(array("a.id", "a.alias"), ":") . " AS slug, " . "b.name as location, b.country_code")->from($this->db->quoteName("#__itpsc_profiles", "a"))->leftJoin($this->db->quoteName("#__itpsc_locations", "b") . " ON a.location_id = b.id")->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\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"); } }
/** * Load data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new Prism\Integration\Profiles\SocialCommunity(\JFactory::getDbo()); * $profiles->load($ids); * </code> * * @param array $ids */ public function load(array $ids) { if (count($ids) > 0) { // Create a new query object. $query = $this->db->getQuery(true); $query->select('a.id AS user_id, a.image_icon, a.image_small, a.image_square, a.image, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug, ' . 'b.name as location, b.country_code')->from($this->db->quoteName('#__itpsc_profiles', 'a'))->leftJoin($this->db->quoteName('#__itpsc_locations', 'b') . ' ON a.location_id = b.id')->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 ITPrismIntegrateProfilesEasySocial(); * $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.name, a.username, " . "b.alias, b.permalink, " . "c.medium AS avatar")->from($this->db->quoteName("#__users", "a"))->leftJoin($this->db->quoteName("#__social_users", "b") . " ON a.id = b.user_id")->leftJoin($this->db->quoteName("#__social_avatars", "c") . " ON a.id = c.uid")->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 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 data about profiles from database. * * <code> * $ids = array(1, 2, 3, 4); * * $profiles = new ITPrismIntegrateProfilesSocialCommunity(); * $profiles->load($ids); * </code> * * @param array $ids */ public function load($ids) { if (!empty($ids)) { // Create a new query object. $query = $this->db->getQuery(true); $query->select("a.id AS user_id, a.image_square AS avatar, a.image_small as avatar_small, " . $query->concatenate(array("a.id", "a.alias"), ":") . " AS slug, " . "b.name as location, b.country_code")->from($this->db->quoteName("#__itpsc_profiles", "a"))->leftJoin($this->db->quoteName("#__itpsc_locations", "b") . " ON a.location_id = b.id")->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; } } } }
/** * Count project funders. * * @param array $data * @param array $options * * @throws \RuntimeException */ public function handle(&$data, array $options = array()) { $funders = array(); $ids = ArrayHelper::getIds($data, 'id'); if (count($ids) > 0) { $query = $this->db->getQuery(true); $query->select('a.project_id, COUNT(*) AS funders')->from($this->db->quoteName('#__crowdf_transactions', 'a'))->where('a.project_id IN (' . implode(',', $ids) . ')')->where('(a.txn_status = ' . $this->db->quote('completed') . ' OR a.txn_status = ' . $this->db->quote('pending') . ')')->group($this->db->quoteName('project_id')); $this->db->setQuery($query); $funders = (array) $this->db->loadObjectList('project_id'); } foreach ($data as $item) { $item->funders = array_key_exists($item->id, $funders) ? $funders[$item->id]->funders : 0; } unset($funders); }
/** * Sends the Email * * @param array $data Array holding data to be emailed. * * @return void * * @since 2.0 */ public function sendMail($data) { if (!$this->params->get('send_mail') || !$this->params->get('usergroup')) { return; } // Get recipients in the group $recipients = JAccess::getUsersByGroup($this->params->get('usergroup')); if ($recipients) { return; } $query = $this->db->getQuery(true); $query->select($this->db->quoteName(array('email, name')))->from('#__users')->where($this->db->quoteName('sendEmail') . ' = 1')->where($this->db->quoteName('id') . ' IN (' . implode(',', $recipients) . ')'); $this->db->setQuery($query); $recipients = $this->db->loadObjectList(); if ($recipients) { return; } $subject = JText::_('PLG_USER_USERLOGINTRACKING_MAIL_SUBJECT'); $body = JText::sprintf('PLG_USER_USERLOGINTRACKING_MAIL_SUBJECT', $data['user']->username, $data['user']->user->id, $data['timestamp'], $data['ip']); $mailer = JFactory::getMailer(); foreach ($recipients as $recipient) { $mailer->addRecipient($recipient->email, $recipient->name); } $mailer->setSender(array($this->app->get('mailfrom'), $this->app->get('fromname'))); $mailer->setSubject($subject); $mailer->setBody($body); $mailer->isHtml(true); $mailer->Send(); return; }
/** * Load transactions from database. * * <code> * $ids = array(1,2,3); * $options = array( * "txn_status" => "completed" * ); * * $transactions = new CrowdFundingTransactions(); * $transactions->setDb(JFactory::getDbo()); * $transactions->load($ids, $options); * * foreach($transactions as $transaction) { * echo $transaction->txn_id; * echo $transaction->txn_amount; * } * * </code> * * @param array $ids * @param array $options * * @throws UnexpectedValueException */ public function load($ids, $options = array()) { // Set the newest ids. if (!is_array($ids)) { throw new UnexpectedValueException(JText::_("LIB_CROWDFUNDING_TRANSACTIONS_IDS_ARRAY")); } JArrayHelper::toInteger($ids); if (!$ids) { return; } // Load project data $query = $this->db->getQuery(true); $query->select("a.id, a.txn_date, a.txn_id, a.txn_amount, a.txn_currency, a.txn_status, " . "a.extra_data, a.status_reason, a.project_id, a.reward_id, a.investor_id, " . "a.receiver_id, a.service_provider, a.reward_state")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.id IN ( " . implode(",", $ids) . " )"); // Filter by status. $status = JArrayHelper::getValue($options, "txn_status", null, "cmd"); if (!empty($status)) { $query->where("a.txn_status = " . $this->db->quote($status)); } $this->db->setQuery($query); $results = $this->db->loadObjectList(); // Convert JSON string into an array. if (!empty($results)) { foreach ($results as $key => $result) { if (!empty($result->extra_data)) { $result->extra_data = json_decode($result->extra_data, true); $results[$key] = $result; } } } else { $results = array(); } $this->items = $results; }
/** * Count and return transactions number. * * <code> * $usersIds = array(1,2,3); * * $statistics = new Crowdfunding\Statistics\Users(\JFactory::getDbo(), $usersIds); * $transactionsNumber = $statistics->getAmounts(); * </code> * * @return array */ public function getAmounts() { // If there are no IDs, return empty array. if (!$this->ids) { return array(); } $statistics = array("invested" => array(), "received" => array()); // Count invested amount and transactions. $query = $this->db->getQuery(true); $query->select("a.investor_id, COUNT(*) AS number, SUM(a.txn_amount) AS amount")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.investor_id IN (" . implode(",", $this->ids) . ")")->group("a.investor_id"); $this->db->setQuery($query); $results = $this->db->loadObjectList("investor_id"); if (!$results) { $results = array(); } $statistics["invested"] = $results; // Count received amount and transactions. $query = $this->db->getQuery(true); $query->select("a.receiver_id, COUNT(*) AS number, SUM(a.txn_amount) AS amount")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.receiver_id IN (" . implode(",", $this->ids) . ")")->group("a.receiver_id"); $this->db->setQuery($query); $results = $this->db->loadObjectList("receiver_id"); if (!$results) { $results = array(); } $statistics["received"] = $results; return $statistics; }
/** * Method to compact the ordering values of rows in a group of rows * defined by an SQL WHERE clause. * * @param string $where WHERE clause to use for limiting the selection of rows to compact the ordering values. * * @return mixed Boolean True on success. * * @link https://docs.joomla.org/JTable/reorder * @since 11.1 * @throws UnexpectedValueException */ public function reorder($where = '') { // If there is no ordering field set an error and return false. if (!property_exists($this, 'ordering')) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } $k = $this->_tbl_key; // Get the primary keys and ordering values for the selection. $query = $this->_db->getQuery(true)->select(implode(',', $this->_tbl_keys) . ', ordering')->from($this->_tbl)->where('ordering >= 0')->order('ordering'); // Setup the extra where and ordering clause data. if ($where) { $query->where($where); } $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); // Compact the ordering values. foreach ($rows as $i => $row) { // Make sure the ordering is a positive integer. if ($row->ordering >= 0) { // Only update rows that are necessary. if ($row->ordering != $i + 1) { // Update the row ordering field. $query->clear()->update($this->_tbl)->set('ordering = ' . ($i + 1)); $this->appendPrimaryKeys($query, $row); $this->_db->setQuery($query); $this->_db->execute(); } } } return true; }
/** * 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; }
/** * Get the Content Type from the table class name * * @param string $tableName The table for the type * * @return mixed The UCM Type data if found, false if no match is found * * @since 3.2 */ public function getTypeByTable($tableName) { $query = $this->db->getQuery(true); $query->select('ct.*'); $query->from($this->db->quoteName('#__content_types', 'ct')); // $query->where($this->db->quoteName('ct.type_alias') . ' = ' . (int) $typeAlias); $this->db->setQuery($query); $types = $this->db->loadObjectList(); foreach ($types as $type) { $tableFromType = json_decode($type->table); $tableNameFromType = $tableFromType->special->prefix . $tableFromType->special->type; if ($tableNameFromType == $tableName) { return $type; } } return false; }
/** * Load data of statuses from a database. * * <code> * $options = array( * "limit" => 10, * "sort_direction" => "DESC" * ); * * $statuses = new UserIdeasStatuses(JFactory::getDbo()); * $statuses->load($options); * </code> * * @param array $options */ public function load($options = array()) { $sortDir = !isset($options["sort_direction"]) ? "DESC" : $options["sort_direction"]; $sortDir = strcmp("DESC", $sortDir) == 0 ? "DESC" : "ASC"; $limit = (int) (!isset($options["limit"])) ? 0 : $options["limit"]; // Create a new query object. $query = $this->db->getQuery(true); $query->select("a.id, a.name, a.default")->from($this->db->quoteName("#__uideas_statuses", "a"))->order("a.name " . $sortDir); if (!empty($limit)) { $this->db->setQuery($query, 0, $limit); } else { $this->db->setQuery($query); } $results = $this->db->loadObjectList(); if (!empty($results)) { $this->items = $results; } }
/** * Count and return transactions number. * * <code> * $usersIds = array(1,2,3); * * $statistics = new Crowdfunding\Statistics\Users(\JFactory::getDbo(), $usersIds); * $transactionsNumber = $statistics->getAmounts(); * </code> * * @return array */ public function getAmounts() { // If there are no IDs, return empty array. if (!$this->ids) { return array(); } $statistics = array('invested' => array(), 'received' => array()); // Count invested amount and transactions. $query = $this->db->getQuery(true); $query->select('a.investor_id, COUNT(*) AS number, SUM(a.txn_amount) AS amount')->from($this->db->quoteName('#__crowdf_transactions', 'a'))->where('a.investor_id IN (' . implode(',', $this->ids) . ')')->group('a.investor_id'); $this->db->setQuery($query); $statistics['invested'] = (array) $this->db->loadObjectList('investor_id'); // Count received amount and transactions. $query = $this->db->getQuery(true); $query->select('a.receiver_id, COUNT(*) AS number, SUM(a.txn_amount) AS amount')->from($this->db->quoteName('#__crowdf_transactions', 'a'))->where('a.receiver_id IN (' . implode(',', $this->ids) . ')')->group('a.receiver_id'); $this->db->setQuery($query); $statistics['received'] = (array) $this->db->loadObjectList('receiver_id'); return $statistics; }
/** * Change the ordering of the records of the table * * @param string $where The WHERE clause of the SQL used to fetch the order * * @return boolean True is successful * * @throws UnexpectedValueException */ public function reorder($where = '') { if (!$this->onBeforeReorder($where)) { return false; } // If there is no ordering field set an error and return false. $order_field = $this->getColumnAlias('ordering'); if (!in_array($order_field, $this->getKnownFields())) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', $this->_tbl_key)); } $k = $this->_tbl_key; // Get the primary keys and ordering values for the selection. $query = $this->_db->getQuery(true); $query->select($this->_tbl_key . ', ' . $this->_db->qn($order_field)); $query->from($this->_tbl); $query->where($this->_db->qn($order_field) . ' >= ' . $this->_db->q(0)); $query->order($this->_db->qn($order_field)); // Setup the extra where and ordering clause data. if ($where) { $query->where($where); } $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); // Compact the ordering values. foreach ($rows as $i => $row) { // Make sure the ordering is a positive integer. if ($row->{$order_field} >= 0) { // Only update rows that are necessary. if ($row->{$order_field} != $i + 1) { // Update the row ordering field. $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set($this->_db->qn($order_field) . ' = ' . $this->_db->q($i + 1)); $query->where($this->_tbl_key . ' = ' . $this->_db->q($row->{$k})); $this->_db->setQuery($query); $this->_db->execute(); } } } $result = $this->onAfterReorder(); return $result; }
/** * Method to get the content types for one or more content items. * * @param mixed $contentIds An integer or array of integer content ids. * * @return array An array of JContentType objects. * * @since 1.0 * @throws RuntimeException */ protected function getTypes($contentIds) { // Check if only one content id was submitted. if (is_scalar($contentIds)) { $contentIds = array($contentIds); } // Sanitize the content ids. JArrayHelper::toInteger($contentIds); // Build a query to get the content types for the ids. $query = $this->db->getQuery(true); $query->select($query->qn('a.content_id')); $query->select($query->qn('b.alias', 'type')); $query->from($query->qn('#__content', 'a')); $query->innerJoin($query->qn('#__content_types', 'b') . ' ON ' . $query->qn('b.type_id') . ' = ' . $query->qn('a.type_id')); $query->where($query->qn('a.content_id') . ' IN(' . implode(',', $contentIds) . ')'); // Get the content types for the ids. $this->db->setQuery($query); $results = $this->db->loadObjectList('content_id'); return $results; }
/** * Count and return transactions number. * * <code> * $projectsIds = array(1,2,3); * * $projects = new CrowdFundingProjects(JFactory::getDbo()); * $transactionsNumber = $projects->getTransactionsNumber($projectsIds); * </code> * * @param array $ids Projects IDs * * @return array */ public function getTransactionsNumber($ids = array()) { // If it is missing IDs as parameter, get the IDs of the current items. if (!$ids and !empty($this->items)) { $ids = array(); foreach ($this->items as $item) { $ids[] = $item->id; } } // If there are no IDs, return empty array. if (!$ids) { return array(); } // Create a new query object. $query = $this->db->getQuery(true); $query->select("a.project_id, COUNT(*) as number")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.project_id IN (" . implode(",", $ids) . ")")->group("a.project_id"); $this->db->setQuery($query); $results = $this->db->loadObjectList("project_id"); if (!$results) { $results = array(); } return $results; }
/** * Load countries and prepare them as an array with options. * * <code> * $filters = new Crowdfunding\Filters(\JFactory::getDbo()); * $options = $filters->getCountries(); * </code> * * @param string $index This is a column that will be used as a value of an option. Possible values: id, code or code4. * @param bool $force Force loading data. * * @return array */ public function getCountries($index = "id", $force = false) { if (!isset($this->options["countries"]) or $force) { $query = $this->db->getQuery(true); switch ($index) { case "code": $query->select("a.code AS value, a.name AS text"); break; case "code4": $query->select("a.code4 AS value, a.name AS text"); break; default: $query->select("a.id AS value, a.name AS text"); break; } $query->from($this->db->quoteName("#__crowdf_countries", "a")); $this->db->setQuery($query); $results = $this->db->loadObjectList(); $this->options["countries"] = $results; } else { $results = $this->options["countries"]; } return $results; }
/** * Get a JSON formatted list of installed extensions * Needs to be public so we can call it from the audit. * * @return string */ public function getExtensions() { // connect/get the Joomla db object $this->db = JFactory::getDbo(); // crazy way of handling Joomla 1.5.x legacy :-( $one5 = FALSE; // Get Joomla 2.0+ Extensions $this->db->setQuery('SELECT e.extension_id, e.name, e.type, e.element, e.enabled, e.folder, ( SELECT title FROM #__menu AS m WHERE m.component_id = e.extension_id AND parent_id = 1 ORDER BY ID ASC LIMIT 1 ) AS title FROM #__extensions AS e WHERE protected = 0'); $installedExtensions = $this->db->loadObjectList(); // ok if we have none maybe we are Joomla < 1.5.26 if (!$installedExtensions) { // Yooo hoo I'm on a crap old, out of date, probably hackable Joomla version! $one5 = TRUE; // Get the extensions - used to be called components $this->db->setQuery('SELECT "component" as "type", name, `option` as "element", enabled FROM #__components WHERE iscore != 1 and parent = 0'); $components = $this->db->loadObjectList(); // Get the plugins $this->db->setQuery('SELECT "plugin" as "type", name, element, folder, published as enabled FROM #__plugins WHERE iscore != 1'); $plugins = $this->db->loadObjectList(); // get the modules $this->db->setQuery('SELECT "module" as "type", module, module as name, client_id, published as enabled FROM #__modules WHERE iscore != 1'); $modules = $this->db->loadObjectList(); /** * Get the templates - I n Joomla 1.5.x the templates are not in the * db unless published so we need to read the folders from the /templates folders * Note in Joomla 1.5.x there was no such think as admin templates */ $folders = array_merge(scandir(JPATH_BASE . '/templates'), scandir(JPATH_ADMINISTRATOR . '/templates')); $templates = array(); foreach ($folders as $templateFolder) { $f = JPATH_BASE . '/templates/' . trim($templateFolder); $a = JPATH_ADMINISTRATOR . '/templates/' . trim($templateFolder); // We dont want index.html etc... if (!is_dir($f) && !is_dir($a) || ($templateFolder == '.' || $templateFolder == '..')) { continue; } if (is_dir($a)) { $client_id = 1; } else { $client_id = 0; } // make it look like we want like Joomla 2.5+ would $template = array('type' => 'template', 'template' => $templateFolder, 'client_id' => $client_id, 'enabled' => 1); // Convert to an obj $templates[] = json_decode(json_encode($template)); } // Merge all the "extensions" we have found all over the place $installedExtensions = array_merge($components, $plugins, $modules, $templates); } $lang = JFactory::getLanguage(); // Load all the language strings up front incase any strings are shared foreach ($installedExtensions as $k => $ext) { $lang->load(strtolower($ext->element) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->element) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($ext->name) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->name) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($ext->title) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->title) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($ext->element), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->element), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($ext->name), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->name), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($ext->title), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($ext->title), JPATH_SITE, 'en-GB', TRUE); $element = str_replace('_TITLE', '', strtoupper($ext->element)); $name = str_replace('_TITLE', '', strtoupper($ext->name)); $title = str_replace('_TITLE', '', strtoupper($ext->title)); $lang->load(strtolower($element) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($element) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($name) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($name) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($title) . ".sys", JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($title) . ".sys", JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($element), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($element), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($name), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($name), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($title), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load(strtolower($title), JPATH_SITE, 'en-GB', TRUE); // templates $lang->load('tpl_' . strtolower($name), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load('tpl_' . strtolower($name), JPATH_SITE, 'en-GB', TRUE); // Joomla 1.5.x modules $lang->load('mod_' . strtolower($name), JPATH_ADMINISTRATOR, 'en-GB', TRUE); $lang->load('mod_' . strtolower($name), JPATH_SITE, 'en-GB', TRUE); // tut tut Akeeba - bad naming! $lang->load(strtolower('PLG_SYSTEM_SRP'), JPATH_ADMINISTRATOR, 'en-GB', TRUE); // should be plg_srp $lang->load(strtolower('PLG_SYSTEM_ONECLICKACTION'), JPATH_SITE, 'en-GB', TRUE); // should be plg_oneclickaction $lang->load(strtolower('PLG_SYSTEM_ONECLICKACTION'), JPATH_ADMINISTRATOR, 'en-GB', TRUE); // should be plg_oneclickaction // Joomla 1.5 plugins if ($ext->type == 'plugin') { $plg = 'plg_' . $ext->folder . '_' . $ext->element; $lang->load(strtolower($plg), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($plg), JPATH_ADMINISTRATOR, 'en-GB', TRUE); } if ($ext->type == 'template') { $plg = 'tpl_' . $ext->name; $lang->load(strtolower($plg), JPATH_SITE, 'en-GB', TRUE); $lang->load(strtolower($plg), JPATH_ADMINISTRATOR, 'en-GB', TRUE); } } // ok now we have the extensions - get the xml for further offline crunching foreach ($installedExtensions as $k => $ext) { // remove not supported types :-( if ($ext->type == 'file' || $ext->type == 'package') { unset($installedExtensions[$k]); continue; } $ext->xmlFile = $this->findManifest($ext); try { if ($ext->xmlFile !== FALSE) { $parts = explode('/', $ext->xmlFile); array_pop($parts); $ext->path = implode('/', $parts); bfLog::log('Loading XML file = ' . str_replace(JPATH_BASE, '', $ext->xmlFile)); $xml = trim(file_get_contents($ext->xmlFile)); $myXML = new SimpleXMLElement($xml); if (property_exists($myXML, 'description')) { $ext->desc = $myXML->description; } $ext->xmlFileContents = base64_encode(gzcompress($xml)); $ext->xmlFileCreated = filemtime($ext->xmlFile); } else { $ext->MANIFESTERROR = TRUE; } } catch (Exception $e) { bfLog::log('EXCEPTION = ' . $ext->xmlFile . ' ' . $e->getMessage()); die('Could not process XML file at: ' . str_replace(JPATH_BASE, '', $ext->xmlFile)); } $ext->name = JText::_($ext->name); $ext->title = JText::_($ext->title); $ext->desc = base64_encode(gzcompress(JText::_($ext->desc))); // remove base paths - we dont want to leak data :) $ext->xmlFile = $this->removeBase($ext->xmlFile); $ext->path = $this->removeBase($ext->path); // Sort so its pretty - not that anyone sees, but debugging is easier $ext = (array) $ext; ksort($ext); // push to the result $installedExtensions[$k] = $ext; } return json_encode($installedExtensions); }
public function getRows($class = null) { // get the subset (based on limits) of records $query = 'SELECT *' . ' FROM #__acctexp_' . $this->table . $this->getConstraints() . $this->getOrdering() . $this->getLimit(); $this->db->setQuery($query); $rows = $this->db->loadObjectList(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } if ($class) { foreach ($rows as $k => $obj) { $rows[$k] = new $class(); $rows[$k]->load($obj->id); } } return $rows; }