Пример #1
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->add('fieldName', 'text', array('label' => 'redatasetfield.fieldname', 'required' => true, 'read_only' => true))->add('fieldType', 'choice', array('label' => 'redatasetfield.fieldtype', 'choices' => REDatasetField::getFieldTypes(), 'required' => true));
 }
Пример #2
0
 /**
  * Load a BundleGenerator into the symfony Kernel.
  *
  */
 public function datasetFieldAction($id)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $entity = $em->getRepository('LowbiConfiguratorBundle:REDataset')->find($id);
     $datasource = $entity->getDatasource();
     if ($datasource == null) {
         $myDatasource = null;
     } else {
         $myDatasource = $datasource->getName();
     }
     $query = $entity->getSqlStatement();
     $customEm = $this->getDoctrine()->getEntityManager($myDatasource);
     $conn = $customEm->getConnection();
     $result = $conn->fetchAll($query);
     $columns = array();
     $reDatasetFieldEntity = $em->getRepository('LowbiConfiguratorBundle:REDatasetField')->findByReDataset($entity->getId());
     foreach ($reDatasetFieldEntity as $item) {
         $em->remove($item);
     }
     $em->flush();
     $entityConfigurator = new EntityConfigurator();
     $entityConfigurator->setTableName($entity->getTableName());
     $entityConfigurator->setState('init');
     $entityConfigurator->setReadOnly(true);
     $em->persist($entityConfigurator);
     $em->flush();
     $fields = array();
     $i = 0;
     foreach ($result as $row) {
         foreach ($row as $key => $column) {
             $columns[] = $key;
             $reDatasetField = new REDatasetField();
             $reDatasetField->setFieldName($key);
             $reDatasetField->setFieldType('string');
             $reDatasetField->setReDataset($entity);
             $em->persist($reDatasetField);
             $field = new Field();
             $field->setFieldName($key);
             $field->setFieldType('string');
             $field->setFragment('text');
             $field->setPos($i);
             $field->setEntityConfigurator($entityConfigurator);
             $em->persist($field);
             $i++;
         }
         $em->flush();
         break;
     }
     return $this->redirect($this->generateUrl('entitygen_edit', array('id' => $entityConfigurator->getId())));
 }