예제 #1
0
 /**
  * Accessor:
  * Returns a field in specified format
  *
  * @param  FieldTable  $field
  * @param  UserTable   $user
  * @param  string      $output               'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit'
  * @param  string      $reason               'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches
  * @param  int         $list_compare_types   IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
  * @return mixed
  */
 public function getField(&$field, &$user, $output, $reason, $list_compare_types)
 {
     $valuesArray = array();
     foreach ($field->getTableColumns() as $col) {
         $valuesArray[] = $user->get($col);
     }
     $value = implode(', ', $valuesArray);
     switch ($output) {
         case 'html':
         case 'rss':
             return $this->formatFieldValueLayout($this->_formatFieldOutput($field->name, $value, $output, true), $reason, $field, $user);
         case 'htmledit':
             if ($reason == 'search') {
                 return $this->_fieldSearchModeHtml($field, $user, $this->_fieldEditToHtml($field, $user, $reason, 'input', $field->type, $value, ''), 'text', $list_compare_types);
             } else {
                 return $this->_fieldEditToHtml($field, $user, $reason, 'input', $field->type, $value, $this->getDataAttributes($field, $user, $output, $reason));
             }
         default:
             return $this->_formatFieldOutput($field->name, $value, $output, false);
     }
 }
예제 #2
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;
 }