Project

General

Profile

Bug #1925 ยป 1925.patch

krileon, 17 August 2010 19:28

View differences:

components/com_comprofiler/plugin/user/plug_cbcore/cb.core.php
* @return array of cbSqlQueryPart
*/
function bindSearchCriteria( &$field, &$searchVals, &$postdata, $list_compare_types, $reason ) {
$search_by = $field->params->get( 'field_search_by', 0 );
list( $yMinMin, $yMaxMax ) = $this->_yearsRange( $field, $search_by );
$query = array();
$search_by = $field->params->get( 'field_search_by', 0 );
list( $yMinMin, $yMaxMax ) = $this->_yearsRange( $field, $search_by );
$query = array();
foreach ( $field->getTableColumns() as $col ) {
$minNam = $col . '__minval';
$maxNam = $col . '__maxval';
$searchMode = $this->_bindSearchRangeMode( $field, $searchVals, $postdata, $minNam, $maxNam, $list_compare_types );
$minNam = $col . '__minval';
$maxNam = $col . '__maxval';
$searchMode = $this->_bindSearchRangeMode( $field, $searchVals, $postdata, $minNam, $maxNam, $list_compare_types );
if ( $searchMode ) {
if ( $search_by == 1 ) {
// search by years:
// list( $y, $c, $d, $h, $m, $s ) = sscanf( date( 'Y-m-d H:i:s' ), '%d-%d-%d %d:%d:%d' );
list( $y, $c, $d ) = sscanf( date( 'Y-m-d' ), '%d-%d-%d' );
$minValIn = (int) cbGetParam( $postdata, $minNam, 0 );
$maxValIn = (int) cbGetParam( $postdata, $maxNam, 0 );
if ( $maxValIn && ( $maxValIn < $yMaxMax ) ) {
$yMin = $y - $maxValIn -1; // yes, crossed: the more years back, the smaller the date... add 1 year for searches from 24 to 24 (INCLUDED)
$minVal = sprintf( '%04d-%02d-%02d', $yMin, $c, $d );
list( $y, $c, $d ) = sscanf( date( 'Y-m-d' ), '%d-%d-%d' );
$minValIn = (int) cbGetParam( $postdata, $minNam, 0 );
$maxValIn = (int) cbGetParam( $postdata, $maxNam, 0 );
if ( ( $maxValIn && ( $maxValIn <= $yMaxMax ) ) && ( $minValIn && ( $minValIn > $yMinMin ) ) ) {
$yMin = $y - $maxValIn -1; // yes, crossed: the more years back, the smaller the date... add 1 year for searches from 24 to 24 (INCLUDED)
$minVal = sprintf( '%04d-%02d-%02d', $yMin, $c, $d );
} else {
$minVal = null;
$minVal = null;
}
if ( $minValIn && ( $minValIn > $yMinMin ) ) {
$yMax = $y - $minValIn;
$maxVal = sprintf( '%04d-%02d-%02d', $yMax, $c, $d );
if ( ( $minValIn && ( $minValIn >= $yMinMin ) ) && ( $maxValIn && ( $maxValIn < $yMaxMax ) ) ) {
$yMax = $y - $minValIn;
$maxVal = sprintf( '%04d-%02d-%02d', $yMax, $c, $d );
} else {
$maxVal = null;
$maxVal = null;
}
} else {
$minValIn = $this->_displayDateToSql( stripslashes( cbGetParam( $postdata, $minNam ) ) );
$maxValIn = $this->_displayDateToSql( stripslashes( cbGetParam( $postdata, $maxNam ) ) );
$minVal = $minValIn;
$maxVal = $maxValIn;
$minValIn = $this->_displayDateToSql( stripslashes( cbGetParam( $postdata, $minNam ) ) );
$maxValIn = $this->_displayDateToSql( stripslashes( cbGetParam( $postdata, $maxNam ) ) );
$minVal = $minValIn;
$maxVal = $maxValIn;
}
if ( $minVal && ( $minVal !== '0000-00-00' ) ) {
$query[] = $this->_dateToSql( $field, $col, $minVal, '>=', $searchMode );
$query[] = $this->_dateToSql( $field, $col, $minVal, '>=', $searchMode );
// Finally store the selected drop-down values so they can be pre-selected on display:
$searchVals->$minNam = $minValIn;
$searchVals->$minNam = $minValIn;
if ( ( ! $maxVal ) && $maxValIn ) {
$searchVals->$maxNam = $maxValIn;
}
}
if ( $maxVal && ( $maxVal !== '0000-00-00' ) ) {
$query[] = $this->_dateToSql( $field, $col, $maxVal, '<=', $searchMode );
$query[] = $this->_dateToSql( $field, $col, $maxVal, '<=', $searchMode );
if ( ( ! ( $minVal && ( $minVal !== '0000-00-00' ) ) ) && ( ! in_array( $field->name, array( 'lastupdatedate', 'lastvisitDate' ) ) ) ) {
$query[] = $this->_dateToSql( $field, $col, '0000-00-00', '>', $searchMode );
$query[] = $this->_dateToSql( $field, $col, '0000-00-00', '>', $searchMode );
}
// Finally store the selected drop-down values so they can be pre-selected on display:
$searchVals->$maxNam = $maxValIn;
if ( ( ! $minVal ) && $minValIn ) {
$searchVals->$minNam = $minValIn;
}
$searchVals->$maxNam = $maxValIn;
}
}
}
return $query;
}
function _dateToSql( &$field, $col, $value, $operator, $searchMode ) {
    (1-1/1)