Exemple #1
0
 protected function _buildResultQuery()
 {
     $query = new K2StoreQuery();
     $query->select($this->getState('select', 'COUNT(*)'));
     $this->_buildQueryFrom($query);
     $this->_buildQueryJoins($query);
     $this->_buildQueryWhere($query);
     $this->_buildQueryGroup($query);
     $this->_buildQueryHaving($query);
     return $query;
 }
Exemple #2
0
 /**
  * Loads a row from the database and binds the fields to the object properties
  *
  * @access	public
  * @param	mixed	Optional primary key.  If not specifed, the value of current key is used
  * @return	boolean	True if successful
  */
 function load($oid = null, $reset = true)
 {
     if (!is_array($oid)) {
         // load by primary key if not array
         $keyName = $this->getKeyName();
         $oid = array($keyName => $oid);
     }
     if (empty($oid)) {
         // if empty, use the value of the current key
         $keyName = $this->getKeyName();
         $oid = $this->{$keyName};
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_("Cannot load with empty key"));
             return false;
         }
     }
     // allow $oid to be an array of key=>values to use when loading
     $oid = (array) $oid;
     if (!empty($reset)) {
         $this->reset();
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new K2StoreQuery();
     $query->select('*');
     $query->from($this->getTableName());
     foreach ($oid as $key => $value) {
         // Check that $key is field in table
         if (!in_array($key, array_keys($this->getProperties()))) {
             $this->setError(get_class($this) . ' does not have the field ' . $key);
             return false;
         }
         // add the key=>value pair to the query
         $value = $db->Quote($db->escape(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($result = $db->loadAssoc()) {
         $result = $this->bind($result);
         if ($result) {
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onLoad' . $this->get('_suffix'), array(&$this));
         }
         return $result;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }