コード例 #1
0
ファイル: BaseController.php プロジェクト: dwsla/deal
 /**
  * Build a query condition for a single field.
  * 
  * <p>Created as a separate method so that subclasses can selectively
  * override handling on a single field<p>
  * 
  * @param strong $field
  * @param srray $queryData
  */
 protected function getFindConditionByField($field, $queryData)
 {
     // build condition based upon the operator
     if (!isset($queryData['operator'])) {
         throw new \RuntimeException('No operator specified for field ' . $field);
     }
     $fieldSchema = $this->model->getSchema($field);
     $type = !empty($fieldSchema['type']) ? $fieldSchema['type'] : '';
     // Use the model to cast the query value to the right type.
     // If type is array or unknown, just leave it as string
     $v = !in_array($type, ['', 'array']) ? $this->model->castField($field, $queryData['value']) : $queryData['value'];
     $queryValue = 'eq' == $queryData['operator'] ? $v : array('$' . $queryData['operator'] => $v);
     return array($field => $queryValue);
 }