/** * @param string $where This is expected to be a valid (and safe!) SQL expression */ function move( $dirn, $where = '', $ordering = 'ordering' ) { $k = $this->_tbl_key; $sql = "SELECT $this->_tbl_key, $ordering FROM $this->_tbl"; if ($dirn < 0) { $sql .= "\n WHERE $ordering < " . (int) $this->$ordering; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\n ORDER BY $ordering DESC"; } else if ($dirn > 0) { $sql .= "\n WHERE $ordering > " . (int) $this->$ordering; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\n ORDER BY $ordering"; } else { $sql .= "\nWHERE $ordering = " . (int) $this->$ordering; $sql .= ($where ? "\n AND $where" : ''); $sql .= "\n ORDER BY $ordering"; } $this->_db->setQuery( $sql, 0, 1 ); $row = null; if ($this->_db->loadObject( $row )) { $query = "UPDATE $this->_tbl" . "\n SET $ordering = " . (int) $row->$ordering . "\n WHERE $this->_tbl_key = " . $this->_db->Quote( $this->$k ) ; $this->_db->setQuery( $query ); if (!$this->_db->query()) { $err = $this->_db->getErrorMsg(); die( $err ); } $query = "UPDATE $this->_tbl" . "\n SET $ordering = " . (int) $this->$ordering . "\n WHERE $this->_tbl_key = " . $this->_db->Quote( $row->$k ) ; $this->_db->setQuery( $query ); if (!$this->_db->query()) { $err = $this->_db->getErrorMsg(); die( $err ); } $this->$ordering = $row->$ordering; } else { $query = "UPDATE $this->_tbl" . "\n SET $ordering = " . (int) $this->$ordering . "\n WHERE $this->_tbl_key = " . $this->_db->Quote( $this->$k ) ; $this->_db->setQuery( $query ); if (!$this->_db->query()) { $err = $this->_db->getErrorMsg(); die( $err ); } } }
/** * gets statistics * * @param int $basketId Basket id for which payments have been done * @param string $txnIdToNotCount (optional) txn_id of payment(s) to ignore in sum * @return boolean true if could load */ public function getBasketPaidTotal( $basketId, $txnIdToNotCount = null ) { $sql = "SELECT COUNT(*) AS count, SUM(mc_gross) AS total " . "\n FROM #__cbsubs_payments " . "\n WHERE payment_basket_id = " . (int) $basketId . "\n AND payment_status = " . $this->_db->Quote( 'Completed' ) ; if ( $txnIdToNotCount ) { $sql .= "\n AND txn_id <> " . $this->_db->Quote( $txnIdToNotCount ); } $this->_db->setQuery( $sql ); return $this->_db->loadObject( $this ); }