示例#1
0
 /**
  * Finder:
  * Prepares field data for saving to database (safe transfer from $postdata to $user)
  * Override
  *
  * @param  FieldTable  $field
  * @param  UserTable   $searchVals  RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
  * @param  array       $postdata    Typically $_POST (but not necessarily), filtering required.
  * @param  int         $list_compare_types   IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
  * @param  string      $reason      'edit' for save profile edit, 'register' for registration, 'search' for searches
  * @return cbSqlQueryPart[]
  */
 public function bindSearchCriteria(&$field, &$searchVals, &$postdata, $list_compare_types, $reason)
 {
     $query = array();
     foreach ($field->getTableColumns() as $col) {
         $minNam = $col . '__minval';
         $maxNam = $col . '__maxval';
         $searchMode = $this->_bindSearchRangeMode($field, $searchVals, $postdata, $minNam, $maxNam, $list_compare_types);
         if ($searchMode) {
             $minVal = (double) cbGetParam($postdata, $minNam, 0);
             $maxVal = (double) cbGetParam($postdata, $maxNam, 0);
             if ($minVal && cbGetParam($postdata, $minNam, '') !== '') {
                 $searchVals->{$minNam} = $minVal;
                 $operator = $searchMode == 'isnot' ? $minVal == $maxVal ? '<' : '<=' : '>=';
                 $min = $this->_floatToSql($field, $col, $minVal, $operator, $searchMode);
             } else {
                 $min = null;
             }
             if ($maxVal && cbGetParam($postdata, $maxNam, '') !== '') {
                 $searchVals->{$maxNam} = $maxVal;
                 $operator = $searchMode == 'isnot' ? $maxVal == $minVal ? '>' : '>=' : '<=';
                 $max = $this->_floatToSql($field, $col, $maxVal, $operator, $searchMode);
             } else {
                 $max = null;
             }
             if ($min && $max) {
                 $sql = new cbSqlQueryPart();
                 $sql->tag = 'column';
                 $sql->name = $col;
                 $sql->table = $field->table;
                 $sql->type = 'sql:operator';
                 $sql->operator = $searchMode == 'isnot' ? 'OR' : 'AND';
                 $sql->searchmode = $searchMode;
                 $sql->addChildren(array($min, $max));
                 $query[] = $sql;
             } elseif ($min) {
                 $query[] = $min;
             } elseif ($max) {
                 $query[] = $max;
             }
         }
     }
     return $query;
 }
示例#2
0
 /**
  * Applies (binds) the $searchVals to the $searchableFields and gets the compiled query to execute the search.
  *
  * @param  FieldTable[]  $searchableFields    Fields that are searchable
  * @param  StdClass      $searchVals          Values to search
  * @param  array         $postdata            _POST input
  * @param  int           $list_compare_types  IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
  * @param  string        $reason              'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches
  * @return cbSqlQueryPart
  */
 public function applySearchableContents(&$searchableFields, &$searchVals, &$postdata, $list_compare_types, $reason = 'search')
 {
     global $_PLUGINS;
     $searches = new cbSqlQueryPart();
     $searches->tag = 'where';
     $searches->type = 'sql:operator';
     $searches->operator = 'AND';
     $searchVals = new stdClass();
     foreach ($searchableFields as $field) {
         $fieldSearches = $_PLUGINS->callField($field->type, 'bindSearchCriteria', array(&$field, &$searchVals, &$postdata, $list_compare_types, $reason), $field);
         if (count($fieldSearches) > 0) {
             $searches->addChildren($fieldSearches);
         }
     }
     return $searches;
 }
 /**	 * Finder:
  * Prepares field data for saving to database (safe transfer from $postdata to $user)
  * Override
  *
  * @param  moscomprofilerFields  $field
  * @param  moscomprofilerUser    $searchVals  RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
  * @param  array                 $postdata    Typically $_POST (but not necessarily), filtering required.
  * @param  int                   $list_compare_types   IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
  * @param  string                $reason      'edit' for save profile edit, 'register' for registration, 'search' for searches
  * @return array of cbSqlQueryPart
  */
 function bindSearchCriteria(&$field, &$searchVals, &$postdata, $list_compare_types, $reason)
 {
     $query = array();
     $searchMode = $this->_bindSearchMode($field, $searchVals, $postdata, 'none', $list_compare_types);
     $col = $field->name;
     $colapproved = $col . 'approved';
     $value = cbGetParam($postdata, $col);
     if ($value === '0') {
         $value = 0;
     } elseif ($value == '1') {
         $value = 1;
     } else {
         $value = null;
     }
     if ($value !== null) {
         $searchVals->{$col} = $value;
         // $this->validate( $field, $user, $col, $value, $postdata, $reason );
         $sql = new cbSqlQueryPart();
         $sql->tag = 'column';
         $sql->name = $colapproved;
         $sql->table = $field->table;
         $sql->type = 'sql:operator';
         $sql->operator = $value ? 'AND' : 'OR';
         $sql->searchmode = $searchMode;
         $sqlpict = new cbSqlQueryPart();
         $sqlpict->tag = 'column';
         $sqlpict->name = $col;
         $sqlpict->table = $field->table;
         $sqlpict->type = 'sql:field';
         $sqlpict->operator = $value ? 'IS NOT' : 'IS';
         $sqlpict->value = 'NULL';
         $sqlpict->valuetype = 'const:null';
         $sqlpict->searchmode = $searchMode;
         $sqlapproved = new cbSqlQueryPart();
         $sqlapproved->tag = 'column';
         $sqlapproved->name = $colapproved;
         $sqlapproved->table = $field->table;
         $sqlapproved->type = 'sql:field';
         $sqlapproved->operator = $value ? '>' : '=';
         $sqlapproved->value = 0;
         $sqlapproved->valuetype = 'const:int';
         $sqlapproved->searchmode = $searchMode;
         $sql->addChildren(array($sqlpict, $sqlapproved));
         $query[] = $sql;
     }
     return $query;
 }