Exemplo n.º 1
0
 /**
  * Creates a searchcondition for the field,
  * was once part of searchCondition, however,
  * searchcondition() also immediately adds the search condition.
  *
  * @param Query $query The query object where the search condition should be placed on
  * @param string $table The name of the table in which this attribute
  *                           is stored
  * @param mixed $value The value the user has entered in the searchbox
  * @param string $searchmode The searchmode to use. This can be any one
  *                           of the supported modes, as returned by this
  *                           attribute's getSearchModes() method.
  * @param string $fieldname
  *
  * @return string The searchcondition to use.
  */
 public function getSearchCondition(Query $query, $table, $value, $searchmode, $fieldname = '')
 {
     $searchcondition = '';
     if (is_array($value) && count($value) > 0 && $value[0] != '') {
         // This last condition is for when the user selected the 'search all' option, in which case, we don't add conditions at all.
         $field = $table . '.' . $this->fieldName();
         if (count($value) == 1) {
             // exactly one value
             $query->addSearchCondition($field . ' & ' . $value[0]);
         } else {
             $mask = '(' . implode('|', $value) . ')';
             $searchcondition = $field . '&' . $mask . '=' . $mask;
         }
     }
     return $searchcondition;
 }
Exemplo n.º 2
0
 /**
  * Creates an search condition for a given search value.
  *
  * @param Query $query The query to which the condition will be added.
  * @param string $table The name of the table in which this attribute
  *                                 is stored
  * @param mixed $value The value the user has entered in the searchbox
  * @param string $searchmode The searchmode to use. This can be any one
  *                                 of the supported modes, as returned by this
  *                                 attribute's getSearchModes() method.
  * @param string $fieldaliasprefix optional prefix for the fieldalias in the table
  */
 public function searchCondition($query, $table, $value, $searchmode, $fieldaliasprefix = '')
 {
     $ownerFields = $this->getOwnerFields();
     // We only support 'exact' matches.
     // But you can select more than one value, which we search using the IN() statement,
     // which should work in any ansi compatible database.
     if (is_array($value) && count($value) > 0 && $value[0] != '') {
         // This last condition is for when the user selected the 'search all' option, in which case, we don't add conditions at all.
         $this->createLink();
         $query->addJoin($this->m_linkInstance->m_table, $this->fieldName(), $table . '.' . $ownerFields[0] . '=' . $this->fieldName() . '.' . $this->getLocalKey(), false);
         $query->setDistinct(true);
         if (count($value) == 1) {
             // exactly one value
             $query->addSearchCondition($query->exactCondition($this->fieldName() . '.' . $this->getRemoteKey(), $this->escapeSQL($value[0])));
         } else {
             // search for more values using IN()
             $query->addSearchCondition($this->fieldName() . '.' . $this->getRemoteKey() . " IN ('" . implode("','", $value) . "')");
         }
     }
 }