/**
  * Get form submission values
  *
  * @param  \Pop\Module\Manager $modules
  * @return array
  */
 public function getValues(\Pop\Module\Manager $modules = null)
 {
     $values = [];
     $fieldNames = [];
     if (null !== $modules && $modules->isRegistered('phire-fields')) {
         $class = 'Phire\\Forms\\Model\\Form';
         $sql = \Phire\Fields\Table\Fields::sql();
         $sql->select()->where('models LIKE :models');
         $sql->select()->orderBy('order');
         $value = $sql->getDbType() == \Pop\Db\Sql::SQLITE ? '%' . $class . '%' : '%' . addslashes($class) . '%';
         $fields = \Phire\Fields\Table\Fields::execute((string) $sql, ['models' => $value]);
         foreach ($fields->rows() as $field) {
             if ($field->storage == 'eav') {
                 $fv = \Phire\Fields\Table\FieldValues::findBy(['field_id' => $field->id, 'model_id' => $this->id, 'model' => 'Phire\\Forms\\Model\\FormSubmission']);
                 foreach ($fv->rows() as $fv) {
                     $fieldNames[$field->name] = $field->type;
                     $values[$field->name] = json_decode($fv->value, true);
                 }
             } else {
                 $fv = new \Pop\Db\Record();
                 $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                 $fv->findRecordsBy(['model_id' => $this->id, 'model' => 'Phire\\Forms\\Model\\FormSubmission', 'revision' => 0]);
                 $fieldNames[$field->name] = $field->type;
                 if ($fv->count() > 1) {
                     $values[$field->name] = [];
                     foreach ($fv->rows() as $f) {
                         $fieldNames[$field->name] = $field->type;
                         $values[$field->name][] = $f->value;
                     }
                 } else {
                     $values[$field->name] = $fv->value;
                 }
             }
         }
     }
     return ['values' => $values, 'fields' => $fieldNames];
 }
Beispiel #2
0
 /**
  * Get all entity field names
  *
  * @param  array $rows
  * @return array
  */
 public function getAllFields(array $rows)
 {
     $fieldNames = [];
     foreach ($rows as $i => $row) {
         if (class_exists('Phire\\Fields\\Model\\FieldValue')) {
             $class = 'Phire\\Entities\\Model\\Entity';
             $sql = \Phire\Fields\Table\Fields::sql();
             $sql->select()->where('models LIKE :models');
             $sql->select()->orderBy('order');
             $value = $sql->getDbType() == \Pop\Db\Sql::SQLITE ? '%' . $class . '%' : '%' . addslashes($class) . '%';
             $fields = \Phire\Fields\Table\Fields::execute((string) $sql, ['models' => $value]);
             foreach ($fields->rows() as $field) {
                 $field->models = unserialize($field->models);
                 if ($this->isFieldAllowed($field->models, $row)) {
                     if ($field->storage == 'eav') {
                         $fv = \Phire\Fields\Table\FieldValues::findBy(['field_id' => $field->id, 'model_id' => $row->id, 'model' => 'Phire\\Entities\\Model\\Entity']);
                         foreach ($fv->rows() as $fv) {
                             if (!array_key_exists($field->name, $fieldNames)) {
                                 $fieldNames[$field->name] = $field->type;
                             }
                             $rows[$i][$field->name] = json_decode($fv->value, true);
                         }
                     } else {
                         $fv = new \Pop\Db\Record();
                         $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                         $fv->findRecordsBy(['model_id' => $row->id, 'model' => 'Phire\\Entities\\Model\\Entity', 'revision' => 0]);
                         if (!array_key_exists($field->name, $fieldNames)) {
                             $fieldNames[$field->name] = $field->type;
                         }
                         if ($fv->count() > 1) {
                             $rows[$i][$field->name] = [];
                             foreach ($fv->rows() as $f) {
                                 $rows[$i][$field->name][] = $f->value;
                             }
                         } else {
                             $rows[$i][$field->name] = $fv->value;
                         }
                     }
                 }
             }
         }
     }
     return $fieldNames;
 }