static public function getAutos( $access = array(), $filtering = array(), $ordering = array(), $limits = 0, $list = true ) { global $_CB_database; static $cache = array(); if ( ! $access ) { $access = array(); } if ( ! $filtering ) { $filtering = array(); } if ( ! $ordering ) { $ordering = array(); } $id = cbgjClass::getStaticID( array( $filtering, $ordering ) ); if ( ! isset( $cache[$id] ) ) { $where = array(); $join = array(); if ( $filtering ) { cbgjData::where( $where, $join, $filtering ); } $orderBy = array(); if ( $ordering ) { cbgjData::order( $orderBy, $join, $ordering ); } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_auto' ) . ( count( $where ) ? "\n WHERE " . implode( "\n AND ", $where ) : null ) . "\n ORDER BY " . ( count( $orderBy ) ? implode( ', ', $orderBy ) : $_CB_database->NameQuote( 'ordering' ) . " ASC" ); $_CB_database->setQuery( $query ); $cache[$id] = $_CB_database->loadObjectList( 'id', 'cbgjAuto', array( & $_CB_database ) ); } $rows = $cache[$id]; if ( $rows ) { if ( $access ) { cbgjData::access( $rows, $access ); } if ( $limits ) { cbgjData::limit( $rows, $limits ); } } if ( ! $rows ) { $rows = array(); } if ( $list ) { return $rows; } else { $rows = array_shift( $rows ); if ( ! $rows ) { $rows = new cbgjAuto( $_CB_database ); } return $rows; } }
/** * prepare SQL safe order byfor query filtering * * @param array $orderby * @param array $join * @param array $ordering * @param string $defaultkey */ static public function order( &$orderby, &$join, $ordering = array(), $defaultkey = null ) { global $_CB_database; if ( $ordering ) { if ( is_array( $ordering[0] ) ) { foreach ( $ordering as $order ) { cbgjData::order( $orderby, $join, $order, $defaultkey ); } } else { $var = ( isset( $ordering[0] ) ? $ordering[0] : null ); if ( $var ) { $dir = ( isset( $ordering[1] ) ? strtoupper( $ordering[1] ) : 'ASC' ); if ( stristr( $var, '.' ) ) { $key_var = explode( '.', $var ); $key = ( isset( $key_var[0] ) ? $key_var[0] : null ); $var = ( isset( $key_var[1] ) ? $key_var[1] : null ); } else { $key = $defaultkey; } if ( $key ) { $key = preg_replace( '/[^-a-zA-Z0-9]/', '', $key ); if ( $key != $defaultkey ) { $join[] = $key; } $key = $key . '.'; } $orderby[] = $key . $_CB_database->NameQuote( $var ) . ( $dir == 'DESC' ? ' DESC' : null ); } } } }