Exemplo n.º 1
0
 public static function getFields()
 {
     return ['name' => ['class' => CharField::className()], 'place' => ['class' => OneToOneField::className(), 'modelClass' => Place::className(), 'primary' => true]];
 }
Exemplo n.º 2
0
 public static function getFields()
 {
     return ['name' => ['class' => CharField::className()], 'restaurant' => ['class' => OneToOneField::className(), 'modelClass' => Restaurant::className(), 'reversed' => true]];
 }
Exemplo n.º 3
0
 public function exportCsv(array $data = [])
 {
     $qs = $this->getQuerySet($this->getModel());
     if (isset($data['models'])) {
         $qs->filter(['pk__in' => $data['models']]);
     }
     $exportData = [];
     $header = [];
     $modelsIterator = $qs->batch(100);
     $noExportFieldsClassName = [ForeignField::className(), HasManyField::className(), ManyToManyField::className(), OneToOneField::className()];
     foreach ($modelsIterator as $models) {
         foreach ($models as $model) {
             $fields = $model->getFieldsInit();
             $line = [];
             foreach ($fields as $attribute => $field) {
                 if (in_array($field->className(), $noExportFieldsClassName)) {
                     continue;
                 }
                 $verboseName = $field->getVerboseName($model);
                 if (!array_key_exists($verboseName, $header)) {
                     $header[$verboseName] = $verboseName;
                 }
                 $line[] = $model->{$attribute};
             }
             $exportData[] = $line;
         }
     }
     $this->forceCsv($header, $exportData);
 }