Example #1
0
 protected function build_single_crit_to_words(Utils_RecordBrowser_CritsSingle $crits)
 {
     $value = $crits->get_value();
     $operator = $crits->get_operator();
     list($field, $subfield) = Utils_RecordBrowser_CritsSingle::parse_subfield($crits->get_field());
     $negation = $crits->get_negation();
     $field_definition = $this->get_field_definition($field);
     $subquery_generated = false;
     if ($subfield) {
         $tab2 = isset($field_definition['ref_table']) ? $field_definition['ref_table'] : false;
         $single_tab = !($tab2 == '__RECORDSETS__' || count(explode(',', $tab2)) > 1);
         if ($tab2 && $single_tab) {
             $cb = new self($tab2);
             $cb->enable_html_decoration($this->html_decoration);
             $value = $cb->to_words(new Utils_RecordBrowser_CritsSingle($subfield, $operator, $value, $negation, $crits->get_raw_sql_value()));
             $subquery_generated = true;
         }
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     foreach ($value as $k => $v) {
         if (is_bool($v)) {
             $value[$k] = $v ? __('true') : __('false');
         } elseif ($v === '' || $v === null) {
             $value[$k] = __('empty');
         } else {
             if ($field == ':Created_on' || $field == ':Edited_on') {
                 if (isset(Utils_RecordBrowserCommon::$date_values[$v])) {
                     $value[$k] = Utils_RecordBrowserCommon::$date_values[$v];
                 } else {
                     $value[$k] = Base_RegionalSettingsCommon::time2reg($v);
                 }
             } elseif ($field == ':Created_by') {
                 if (is_numeric($v)) {
                     $value[$k] = Base_UserCommon::get_user_login($v);
                 }
             } elseif ($field_definition) {
                 $vv = explode('::', $v, 2);
                 if (!(isset($vv[1]) && is_callable($vv)) && (is_numeric($v) || $field_definition['commondata'] || !isset($field_definition['ref_table']))) {
                     $new_val = Utils_RecordBrowserCommon::get_val($this->tab, $field, array($field => $v), true);
                     if ($new_val) {
                         $value[$k] = $new_val;
                     }
                 }
             }
         }
         if ($this->html_decoration) {
             if (!$subquery_generated) {
                 $value[$k] = '<strong>' . $value[$k] . '</strong>';
             }
         }
     }
     if ($operator == '!=') {
         $negation ^= $operator == '!=';
         $operator = '=';
     }
     switch ($field) {
         case ':Fav':
             $field = __('Favorite status');
             break;
         case ':Recent':
             $field = __('Recently viewed');
             break;
         case ':Sub':
             $field = __('Subscription status');
             break;
         case ':Created_by':
             $field = __('Created by');
             break;
         case ':Created_on':
             $field = __('Created on');
             break;
         case ':Edited_on':
             $field = __('Edited on');
             break;
         case 'id':
             $field = __('ID');
             break;
         default:
             if ($field_definition) {
                 $field = _V($field_definition['name']);
             }
     }
     if ($this->html_decoration) {
         $field = "<strong>{$field}</strong>";
     }
     if ($subquery_generated) {
         $operand = __('is set to record where');
     } else {
         switch ($operator) {
             case '<':
                 $operand = $negation ? __('is not smaller than') : __('is smaller than');
                 break;
             case '<=':
                 $operand = $negation ? __('is not smaller or equal to') : __('is smaller or equal to');
                 break;
             case '>':
                 $operand = $negation ? __('is not greater than') : __('is greater than');
                 break;
             case '>=':
                 $operand = $negation ? __('is not greater than') : __('is greater or equal to');
                 break;
             case 'LIKE':
                 $operand = $negation ? __('is not like') : __('is like');
                 break;
             case 'NOT LIKE':
                 $operand = $negation ? __('is like') : __('is not like');
                 break;
             default:
                 $operand = $negation ? __('is not equal to') : __('is equal to');
         }
     }
     $value_str = implode(' ' . __('or') . ' ', $value);
     if (count($value) > 1) {
         $value_str = "({$value_str})";
     }
     $ret = "{$field} {$operand} {$value_str}";
     if (!$this->html_decoration) {
         $ret = html_entity_decode($ret);
     }
     return array('str' => $ret, 'multiple' => false);
 }