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 where for query filtering * * @param array $where * @param array $join * @param array $filtering * @param string $defaultkey */ static public function where( &$where, &$join, $filtering = array(), $defaultkey = null ) { global $_CB_database; if ( $filtering ) { if ( is_array( $filtering[0] ) ) { foreach ( $filtering as $filter ) { cbgjData::where( $where, $join, $filter, $defaultkey ); } } else { $var = ( isset( $filtering[0] ) ? $filtering[0] : null ); if ( $var ) { $operator = ( isset( $filtering[1] ) ? strtoupper( $filtering[1] ) : '=' ); $input = ( isset( $filtering[2] ) ? $filtering[2] : '' ); $or_case = ( isset( $filtering[3] ) ? $filtering[3] : null ); 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 . '.'; } if ( is_int( $input ) ) { $input = (int) $input; } elseif ( is_float( $input ) ) { $input = (float) $input; } elseif ( is_array( $input ) ) { foreach ( $input as $k => $v ) { if ( ( ! is_int( $v ) ) || ( ! is_float( $v ) ) ) { if ( $v === null ) { $input[$k] = 'NULL'; } else { $input[$k] = $_CB_database->Quote( $v ); } } } switch ( $operator ) { case '!=': case '!IN': $operator = 'NOT IN'; break; case '=': default: $operator = 'IN'; break; } $input = '( ' . implode( ', ', $input ) . ' )'; } elseif ( is_string( $input ) ) { switch ( $operator ) { case 'IN': case '!IN': case 'NOT IN': if ( $operator == '!IN' ) { $operator = 'NOT IN'; } $input = explode( ',', $input ); foreach ( $input as $k => $v ) { if ( ( ! is_int( $v ) ) || ( ! is_float( $v ) ) ) { if ( $v === null ) { $input[$k] = 'NULL'; } else { $input[$k] = $_CB_database->Quote( $v ); } } } $input = '( ' . implode( ', ', $input ) . ' )'; break; case 'CONTAINS': case 'LIKE': case '!CONTAINS': case 'NOT LIKE': $input = $_CB_database->Quote( '%' . $_CB_database->getEscaped( $input, true ) . '%', false ); break; default: $input = $_CB_database->Quote( $input ); break; } } elseif ( $input === null ) { $input = 'NULL'; } else { $input = $_CB_database->Quote( '' ); } switch ( $operator ) { case 'EMPTY': case 'IS EMPTY': case 'IS NULL': $operator = 'IS NULL'; $input = null; break; case '!EMPTY': case 'NOT EMPTY': case 'IS NOT NULL': $operator = 'IS NOT NULL'; $input = null; break; case 'CONTAINS': case 'LIKE': $operator = 'LIKE'; break; case '!CONTAINS': case 'NOT LIKE': $operator = 'NOT LIKE'; break; case 'REGEX': case 'REGEXP': $operator = 'REGEXP'; break; case '!REGEX': case '!REGEXP': case 'NOT REGEXP': $operator = 'NOT REGEXP'; break; } if ( $or_case ) { $or_cases = $filtering; unset( $or_cases[0] ); unset( $or_cases[1] ); unset( $or_cases[2] ); $or_cases = array_values( $or_cases ); $or = array(); cbgjData::where( $or, $join, $or_cases, $defaultkey ); if ( is_array( $or_case ) ) { if ( is_array( $or_case[0] ) ) { $add_or = ( count( $or ) ? ' AND ' . implode( ' AND ', $or ) : null ); } else { $add_or = ( count( $or ) ? ' OR ' . implode( ' OR ', $or ) : null ); } } else { $add_or = ( count( $or ) ? ' AND ' . implode( ' AND ', $or ) : null ); } } else { $add_or = null; } $where[] = ( $add_or ? '( ' : null ) . '( ' . $key . $_CB_database->NameQuote( $var ) . ' ' . $operator . ( $input !== null ? ' ' . $input : null ) . ' )' . $add_or . ( $add_or ? ' )' : null ); } } } }