コード例 #1
0
 public function top()
 {
     $this->breadcrumb->add('Rating');
     $this->header();
     $filter = new CustomDataFilter($this->flightPage->getPosition());
     $filter->fieldForeign('categories', 'name', 'airlineName');
     $filter->fieldForeign('categories', 'id', 'airlineId');
     $filter->fieldCalculation('rating', '(AVG(vdr_rating)+AVG(bord_rating)+AVG(service_rating))/3');
     $filter->join('categories', 'id', 'airline');
     $filter->condition('published', 1);
     $filter->orderBy('rating', false);
     $filter->groupBy('airline');
     $this->flightPage->overview('/Airlines/top', 0, $filter);
     $this->footer();
 }
コード例 #2
0
 public static function getAverageFields(CustomDataPosition $pos, array $params = array())
 {
     $filter = new CustomDataFilter($pos);
     $filter->field(null);
     $fields = $pos->getFieldsForClassPath(self::$classPath);
     foreach ($fields as $field) {
         $fieldName = Sanitize::saveDb($field->getFieldName());
         $filter->fieldCalculation($fieldName, "AVG({$fieldName})");
     }
     foreach ($params as $field => $value) {
         $filter->condition($field, $value);
     }
     $result = $filter->execute();
     if ($result) {
         $data = new CustomData($pos);
         $row = Database::getObject()->fetchAssoc($result);
         if ($row) {
             $data = new CustomData($pos);
             $data->set($row, true, $fields);
             return $data->getFields(array_keys($fields));
         }
     }
     return array();
 }