示例#1
0
 /**
  * Test loadObjectList method
  *
  * @return  void
  *
  * @since   11.4
  */
 public function testLoadObjectList()
 {
     $query = $this->object->getQuery(true);
     $query->select('*');
     $query->from('jos_dbtest');
     $query->order('id');
     $this->object->setQuery($query);
     $result = $this->object->loadObjectList();
     $expected = array();
     $objCompare = new stdClass();
     $objCompare->id = 1;
     $objCompare->title = 'Testing';
     $objCompare->start_date = '1980-04-18 00:00:00';
     $objCompare->description = 'one';
     $expected[] = clone $objCompare;
     $objCompare = new stdClass();
     $objCompare->id = 2;
     $objCompare->title = 'Testing2';
     $objCompare->start_date = '1980-04-18 00:00:00';
     $objCompare->description = 'one';
     $expected[] = clone $objCompare;
     $objCompare = new stdClass();
     $objCompare->id = 3;
     $objCompare->title = 'Testing3';
     $objCompare->start_date = '1980-04-18 00:00:00';
     $objCompare->description = 'three';
     $expected[] = clone $objCompare;
     $objCompare = new stdClass();
     $objCompare->id = 4;
     $objCompare->title = 'Testing4';
     $objCompare->start_date = '1980-04-18 00:00:00';
     $objCompare->description = 'four';
     $expected[] = clone $objCompare;
     $this->assertThat($result, $this->equalTo($expected), __LINE__);
 }
示例#2
0
 /**
  * Load a list of database objects
  *
  * @param string $key
  * @throws SPException
  * @return array If <var>key</var> is empty as sequential list of returned records.
  */
 public function loadObjectList($key = null)
 {
     try {
         $r = $this->db->loadObjectList($key);
         $this->count++;
     } catch (Exception $e) {
     }
     if ($this->db->getErrorNum()) {
         throw new SPException($this->db->stderr());
     } else {
         return $r;
     }
 }
示例#3
0
 /**
  * Query to database
  * @param JBDatabaseQuery $select
  * @param bool            $isOne
  * @param bool            $toArray
  * @return mixed
  */
 protected function _query(JBDatabaseQuery $select, $isOne = false, $toArray = false)
 {
     //jbdump::sql($select);
     $selectSql = (string) $select;
     $this->app->jbdebug->sql($selectSql);
     $this->_db->setQuery($selectSql);
     if (!$toArray) {
         if ((bool) $isOne) {
             $result = $this->_db->loadObject();
         } else {
             $result = $this->_db->loadObjectList();
         }
     } else {
         if ((bool) $isOne) {
             $result = $this->_db->loadAssoc();
         } else {
             $result = $this->_db->loadAssocList();
         }
     }
     return $result;
 }
示例#4
0
 /**
  * Load countries and prepare them as an array with options.
  *
  * <code>
  * $filters    = new CrowdFundingFilters(JFactory::getDbo());
  * $options = $filters->getCountries();
  * </code>
  *
  * @param string $value This is a column that will be used as a value of an option. Possible values: id, code or code4.
  *
  * @return array
  */
 public function getCountries($value = "id")
 {
     if (!isset($this->options["countries"])) {
         $query = $this->db->getQuery(true);
         switch ($value) {
             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;
 }
 public function loadObjectList($key = '', $class = "stdClass", $translate = true, $language = null, $asObject = true, $onlytransFields = true)
 {
     $this->translate = $translate;
     if ($this->skipjf || $translate === false) {
         return parent::loadObjectList($key, $class);
     }
     $pfunc = $this->profile();
     // we can't call the query twice!
     if (!($cur = $this->query())) {
         return null;
     }
     $fields = array();
     if (!$this->doTranslate($fields)) {
         $array = array();
         while ($row = mysqli_fetch_object($cur, $class)) {
             if ($key) {
                 $array[$row->{$key}] = $row;
             } else {
                 $array[] = $row;
             }
         }
         mysqli_free_result($cur);
         return $array;
     }
     $jfdata = array();
     if ($key != "") {
         while ($row = mysqli_fetch_array($cur, MYSQLI_BOTH)) {
             $jfdata[$row[$key]] = $row;
         }
     } else {
         while ($row = mysqli_fetch_array($cur, MYSQLI_BOTH)) {
             $jfdata[] = $row;
         }
     }
     if (count($jfdata) == 0) {
         return $jfdata;
     }
     // Before joomfish manager is created since we can't translate so skip this anaylsis
     $jfManager = JoomFishManager::getInstance();
     if (!$jfManager) {
         return $jfdata;
     }
     if (isset($jfManager)) {
         $this->setLanguage($language);
     }
     if ($jfManager->getCfg("transcaching", 1)) {
         $this->orig_limit = $this->get("limit");
         $this->orig_offset = $this->get("offset");
         // cache the results
         // special Joomfish database cache
         // $cache = $jfManager->getCache($language);
         // $jfdata = $cache->get(array("JoomFish", 'translateListArrayCached'), array($jfdata, $language, $fields));
         $cache = JFactory::getCache('com_joomfish', 'callback');
         $jfdata = $cache->get("JoomFish::translateListArrayCached", array(&$jfdata, $language, $fields, $onlytransFields));
         $this->orig_limit = 0;
         $this->orig_offset = 0;
     } else {
         $this->orig_limit = $this->get("limit");
         $this->orig_offset = $this->get("offset");
         JoomFish::translateListArray($jfdata, $language, $fields, $onlytransFields);
         $this->orig_limit = 0;
         $this->orig_offset = 0;
     }
     mysqli_free_result($cur);
     if ($asObject) {
         $array = array();
         foreach ($jfdata as $row) {
             $obj = new stdClass();
             $fieldcount = 0;
             foreach ($fields as $field) {
                 $fieldname = $field->name;
                 $obj->{$fieldname} = $row[$fieldcount];
                 $fieldcount++;
             }
             if ($key) {
                 $array[$obj->{$key}] = $obj;
             } else {
                 $array[] = $obj;
             }
         }
         $pfunc = $this->profile($pfunc);
         return $array;
     }
     $pfunc = $this->profile($pfunc);
     return $jfdata;
 }