Beispiel #1
0
 /**
  * (non-PHPdoc)
  * @see sample/admin/tables/DSCTable#delete($oid)
  */
 function delete($oid = '')
 {
     if (empty($oid)) {
         // if empty, use the values of the current keys
         $keynames = $this->getKeyNames();
         foreach ($keynames as $key => $value) {
             $oid[$key] = $this->{$key};
         }
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_("Cannot delete with empty key"));
             return false;
         }
     }
     $oid = (array) $oid;
     $before = JFactory::getApplication()->triggerEvent('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new DSCQuery();
     $query->delete();
     $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->q($db->escape(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         JFactory::getApplication()->triggerEvent('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Beispiel #2
0
 /**
  * Loads a row from the database and binds the fields to the object properties
  * If $load_eav is true, binds also the eav fields linked to this entity
  *
  * @access	public
  * @param	mixed	Optional primary key.  If not specifed, the value of current key is used
  * @param	bool	reset the object values?
  * @param	bool	load the eav values for this object
  *
  * @return	boolean	True if successful
  */
 function load($oid = null, $reset = true, $load_eav = true)
 {
     $eavs = array();
     /* Get the application */
     $app = JFactory::getApplication();
     $editable_by = $app->isAdmin() ? 1 : 2;
     if ($app->isAdmin()) {
         $view = $app->input->get('view', '');
         //$view = JRequest::get('view', '' );
         if ($view == 'pos') {
             // display all for POS
             $editable_by = array(1, 2);
         }
     }
     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::_('COM_CITRUSCART_CANNOT_LOAD_WITH_EMPTY_KEY'));
             return false;
         }
     }
     // allow $oid to be an array of key=>values to use when loading
     $oid = (array) $oid;
     $this->_linked_table_key = isset($this->_linked_table_key) ? $this->_linked_table_key : (isset($oid[$this->_linked_table_key_name]) ? $oid[$this->_linked_table_key_name] : '');
     if (!empty($reset)) {
         $this->reset();
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new DSCQuery();
     $query->select('*');
     $query->from($this->getTableName());
     if ($load_eav) {
         Citruscart::load("CitruscartHelperBase", 'helpers._base');
         $eav_helper = CitruscartHelperBase::getInstance('Eav');
         $k = $this->_tbl_key;
         $id = $this->{$k};
         // Get the custom fields for this entities
         Citruscart::load('CitruscartHelperEav', 'helpers.eav');
         $eavs = CitruscartHelperEav::getAttributes($this->get('_suffix'), $id, true, $editable_by);
         // Is this a mirrored table (see decription at the beginning of this file)
         if (strlen($this->_linked_table) && $this->_linked_table_key) {
             // Copy the custom field value to this table
             $mirrored_eavs = $eav_helper->getAttributes($this->_linked_table, $this->_linked_table_key, true, $editable_by);
             $eavs = array_merge($eavs, $mirrored_eavs);
         }
     }
     foreach ($oid as $key => $value) {
         // Check that $key is field in table
         if (!in_array($key, array_keys($this->getProperties()))) {
             // Check if it is a eav field
             if ($load_eav) {
                 // loop through until the key is found or the eav are finished
                 $found = false;
                 $i = 0;
                 while (!$found && $i < count($eavs)) {
                     // Does the key exists?
                     if ($key == $eavs[$i]->eavattribute_alias) {
                         $found = true;
                     } else {
                         $i++;
                     }
                 }
                 // Was the key found?
                 if (!$found) {
                     // IF not return an error
                     $this->setError(get_class($this) . ' does not have the field ' . $key);
                     return false;
                 }
                 // key was found -> add this EAV field
                 $value_tbl_name = 'value_' . $eavs[$i]->eavattribute_alias;
                 // for some reason MySQL makes spaces around '-' charachter
                 // (which is often charachter in aliases) that's why we replace it with '_'
                 $value_tbl_name = str_replace("-", "_", $value_tbl_name);
                 // Join the table based on the type of the value
                 $table_type = $eav_helper->getType($eavs[$i]->eavattribute_alias);
                 // Join the tables
                 $query->join('LEFT', '#__citruscart_eavvalues' . $table_type . ' AS ' . $value_tbl_name . ' ON ( ' . $value_tbl_name . '.eavattribute_id = ' . $eavs[$i]->eavattribute_id . ' AND ' . $value_tbl_name . '.eaventity_id =  ' . $this->_tbl_key . ' )');
                 // Filter using '='
                 $query->where($value_tbl_name . ".eavvalue_value = '" . $value . "'");
                 // else let the store() method worry over this
             } else {
                 $this->setError(get_class($this) . ' does not have the field ' . $key);
                 return false;
             }
         } else {
             // add the key=>value pair to the query
             $value = $db->q($db->escape(trim(strtolower($value))));
             $query->where($key . ' = ' . $value);
         }
     }
     $db->setQuery((string) $query);
     if ($result = $db->loadAssoc()) {
         $result = $this->bind($result);
         if ($result) {
             // Only now load the eav, in necessary
             // Check if it is a eav field
             if ($load_eav) {
                 $k = $this->_tbl_key;
                 $id = $this->{$k};
                 // Get the custom fields for this entities
                 Citruscart::load('CitruscartHelperEav', 'helpers.eav');
                 $eavs = CitruscartHelperEav::getAttributes($this->get('_suffix'), $id, false, $editable_by);
                 // Is this a mirrored table (see decription at the beginning of this file)
                 if (strlen($this->_linked_table) && $this->_linked_table_key) {
                     // Copy the custom field value to this table
                     $mirrored_eavs = $eav_helper->getAttributes($this->_linked_table, $this->_linked_table_key);
                     $eavs = array_merge($eavs, $mirrored_eavs);
                 }
                 if (count($eavs)) {
                     foreach ($eavs as $eav) {
                         $key = $eav->eavattribute_alias;
                         $value = $eav_helper->getAttributeValue($eav, $this->get('_suffix'), $id);
                         $this->{$key} = $value;
                     }
                 }
             }
             $app->triggerEvent('onLoad' . $this->get('_suffix'), array(&$this));
         }
         return $result;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Beispiel #3
0
 /**
  * Builds a generic SELECT COUNT(*) query that takes group by into account
  */
 protected function _buildResultQuery()
 {
     $grouped_query = new DSCQuery();
     $grouped_query->select($this->getState('select', 'COUNT(tbl.product_id)'));
     $field = array();
     $filter_quantity_from = $this->getState('filter_quantity_from');
     $filter_quantity_to = $this->getState('filter_quantity_to');
     $filter_price_from = $this->getState('filter_price_from');
     $filter_price_to = $this->getState('filter_price_to');
     if (strlen($filter_price_from) || strlen($filter_price_to)) {
         // This subquery returns the default price for the product and allows for sorting by price
         $date = JFactory::getDate()->toMysql();
         $default_group = Tienda::getInstance()->get('default_user_group', '1');
         $filter_group = (int) $this->getState('filter_group');
         if (empty($filter_group)) {
             $filter_group = $default_group;
         }
         $field[] = "(\n            SELECT\n            prices.product_price\n            FROM\n            #__tienda_productprices AS prices\n            WHERE\n            prices.product_id = tbl.product_id\n            AND prices.group_id = '{$filter_group}'\n            AND prices.product_price_startdate <= '{$date}'\n            AND (prices.product_price_enddate >= '{$date}' OR prices.product_price_enddate = '0000-00-00 00:00:00' )\n            ORDER BY prices.price_quantity_start ASC\n            LIMIT 1\n            )\n            AS price";
     }
     if (strlen($filter_quantity_from) || strlen($filter_quantity_to)) {
         $field[] = "\n            (\n            SELECT\n            SUM(quantities.quantity)\n            FROM\n            #__tienda_productquantities AS quantities\n            WHERE\n            quantities.product_id = tbl.product_id\n            AND quantities.vendor_id = '0'\n            )\n            AS product_quantity ";
     }
     if (count($field)) {
         $grouped_query->select($field);
     }
     $this->_buildQueryFrom($grouped_query);
     $this->_buildQueryJoins($grouped_query);
     $this->_buildQueryWhere($grouped_query);
     $this->_buildQueryGroup($grouped_query);
     $this->_buildQueryHaving($grouped_query);
     $query = new DSCQuery();
     $query->select('COUNT(*)');
     $query->from('(' . $grouped_query . ') as grouped_count');
     // Allow plugins to edit the query object
     $suffix = ucfirst($this->getName());
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterBuildResultQuery' . $suffix, array(&$query));
     return $query;
 }
Beispiel #4
0
 public static function findItemid($url)
 {
     //TODO add CACHING
     $db = JFactory::getDBO();
     $query = new DSCQuery();
     $query->select('*');
     $query->from(' #__menu as m');
     $query->where(' m.link = ' . $db->q($url));
     $query->where(' m.client_id = ' . $db->q(0));
     //means frontend only
     $query->where(' m.published = ' . $db->q(1));
     //means turned on
     $db->setQuery($query, 0, 1);
     $item = $db->loadObject();
     if ($item) {
         return $item->id;
     }
 }
Beispiel #5
0
 /**
  * (non-PHPdoc)
  * @see tienda/admin/tables/TiendaTable#delete($oid)
  */
 function delete($oid = '')
 {
     if (empty($oid)) {
         // if empty, use the values of the current keys
         $keynames = $this->getKeyNames();
         foreach ($keynames as $key => $value) {
             $oid[$key] = $this->{$key};
         }
         if (empty($oid)) {
             // if still empty, fail
             $this->setError(JText::_('COM_TIENDA_CANNOT_DELETE_WITH_EMPTY_KEY'));
             return false;
         }
     }
     if (!is_array($oid)) {
         $keyName = $this->getKeyName();
         $arr = array();
         $arr[$keyName] = $oid;
         $oid = $arr;
     }
     $dispatcher = JDispatcher::getInstance();
     $before = $dispatcher->trigger('onBeforeDelete' . $this->get('_suffix'), array($this, $oid));
     if (in_array(false, $before, true)) {
         return false;
     }
     $db = $this->getDBO();
     // initialize the query
     $query = new DSCQuery();
     $query->delete();
     $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->getEscaped(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($db->query()) {
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterDelete' . $this->get('_suffix'), array($this, $oid));
         return true;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Beispiel #6
0
 /**
  * Finds out if a component is installed
  *
  * @param string $option
  *
  * @return  True or False based on if the component exists or not
  */
 public function isComponentInstalled($option)
 {
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         $db = JFactory::getDBO();
         $q = new DSCQuery();
         $q->select('extension_id');
         $q->from('#__extensions');
         $q->where('type = \'component\'');
         $q->where('enabled = 1');
         $q->where('element = ' . $db->q($option));
         $db->setQuery($q);
         $res = $db->loadObject();
         return $res !== null;
     } else {
         // Joomla! 1.5 code here
         return JComponentHelper::getComponent($option, true)->enabled;
     }
 }
Beispiel #7
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)
 {
     JPluginHelper::importPlugin('citruscart');
     $app = JFactory::getApplication();
     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 DSCQuery();
     $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->q($db->escape(trim(strtolower($value))));
         $query->where($key . ' = ' . $value);
     }
     $db->setQuery((string) $query);
     if ($result = $db->loadAssoc()) {
         $result = $this->bind($result);
         if ($result) {
             $app->triggerEvent('onLoad' . $this->get('_suffix'), array(&$this));
         }
         return $result;
     } else {
         $this->setError($db->getErrorMsg());
         return false;
     }
 }
Beispiel #8
0
 /**
  * Generates a created/modified select list
  *
  * @param string The value of the HTML name attribute
  * @param string Additional HTML attributes for the <select> tag
  * @param mixed The key that is selected
  * @returns string HTML for the radio list
  */
 public static function paymentType($selected, $name = 'filter_type', $attribs = array('class' => 'inputbox'), $idtag = null, $allowAny = false, $title = 'COM_TIENDA_SELECT_TYPE')
 {
     $list = array();
     if ($allowAny) {
         $list[] = self::option('', "- " . JText::_($title) . " -");
     }
     $db = JFactory::getDbo();
     $q = new DSCQuery();
     $q->select('DISTINCT orderpayment_type as type');
     $q->from('#__tienda_orderpayments');
     $db->setQuery($q);
     $items = $db->loadObjectList();
     foreach ($items as $item) {
         $list[] = JHTML::_('select.option', $item->type, JText::_($item->type));
     }
     return self::genericlist($list, $name, $attribs, 'value', 'text', $selected, $idtag);
 }