public function main()
 {
     $page = Request::get(0, VAR_URI);
     if (preg_match('/^(\\d+)-/', $page, $matches) > 0 && !empty($matches[1])) {
         $airlineData = new CustomData($this->airlinePage->getPosition());
         if ($airlineData->load($matches[1])) {
             $uri = AirlineTools::buildUri($airlineData->getId(), $airlineData->getData('name'), true);
             $this->flightPage->setBaseUri($uri);
             $this->breadcrumb->add($airlineData->getData('name'), URI::build($uri));
             $flight = Request::get(1, VAR_INT);
             if (is_id($flight)) {
                 $this->flight($flight);
             } else {
                 $this->airline($matches[1]);
             }
         } else {
             $this->header();
             $this->notFoundError();
             $this->footer();
         }
     } else {
         $this->header();
         $this->airlinePage->overview('/Airlines/categories');
         $this->footer();
     }
 }
 public function remove()
 {
     $id = Request::get(1, VAR_INT);
     $data = new CustomData($this->position);
     if ($data->load($id)) {
         if (Request::get(2) == 'yes') {
             if ($data->remove()) {
                 CmsPage::ok("Der Datensatz wurde erfolgreich gelöscht.");
             } else {
                 CmsPage::error("Der Datensatz konnte leider nicht gelöscht werden.");
             }
         } else {
             CmsPage::yesNo("Möchten Sie den gewählten Datensatz inkl. aller evtl. verknüpften Daten wirklich löschen?", URI::build($this->baseUri . '/remove/' . $id . '/yes'), URI::build($this->baseUri));
         }
     } else {
         CmsPage::error('Der Datensatz wurde nicht gefunden.');
     }
 }
 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();
 }
 public function retrieveTo(CustomData $obj)
 {
     $result = $this->execute();
     $row = Database::getObject()->fetchAssoc($result);
     if ($row) {
         $obj->set($row, true);
         $obj->setCalculated($row, $this->getForeignCalcFields());
         return true;
     } else {
         return false;
     }
 }