/**
  * insert dtb_csv
  *
  * @param EntityManager $em
  */
 private function dtb_csv(EntityManager $em)
 {
     $filter = $em->getFilters()->getFilter('soft_delete');
     $filter->setExcludes(array('Eccube\\Entity\\Member'));
     $CsvType = $em->getRepository('Eccube\\Entity\\Master\\CsvType')->find(CsvType::CSV_TYPE_PRODUCT);
     $Member = $em->getRepository('Eccube\\Entity\\Member')->find(1);
     $Csv = $em->getRepository('Eccube\\Entity\\Csv')->findOneBy(array('CsvType' => $CsvType), array('rank' => 'DESC'));
     $rank = $Csv->getRank();
     foreach ($this->csv_datas as $data) {
         $rank++;
         $Csv = new Csv();
         $Csv->setCsvType($CsvType)->setCreator($Member)->setEntityName($data['entity_name'])->setFieldName($data['field_name'])->setReferenceFieldName($data['reference_field_name'])->setDispName($data['disp_name'])->setRank($rank)->setEnableFlg(Constant::ENABLED);
         $em->persist($Csv);
     }
 }
 /**
  * CSV出力項目と比較し, 合致するデータを返す.
  *
  * @param \Eccube\Entity\Csv $Csv
  * @param $entity
  * @return mixed|null|string|void
  */
 public function getData(\Eccube\Entity\Csv $Csv, $entity)
 {
     // エンティティ名が一致するかどうかチェック.
     $csvEntityName = str_replace('\\\\', '\\', $Csv->getEntityName());
     $entityName = str_replace('\\\\', '\\', get_class($entity));
     if ($csvEntityName !== $entityName) {
         return null;
     }
     // カラム名がエンティティに存在するかどうかをチェック.
     if (!$entity->offsetExists($Csv->getFieldName())) {
         return null;
     }
     // データを取得.
     $data = $entity->offsetGet($Csv->getFieldName());
     // one to one の場合は, dtb_csv.referece_field_nameと比較し, 合致する結果を取得する.
     if ($data instanceof \Eccube\Entity\AbstractEntity) {
         if (EntityUtil::isNotEmpty($data)) {
             return $data->offsetGet($Csv->getReferenceFieldName());
         }
     } elseif ($data instanceof \Doctrine\Common\Collections\Collection) {
         // one to manyの場合は, カンマ区切りに変換する.
         $array = array();
         foreach ($data as $elem) {
             if (EntityUtil::isNotEmpty($elem)) {
                 $array[] = $elem->offsetGet($Csv->getReferenceFieldName());
             }
         }
         return implode($this->config['csv_export_multidata_separator'], $array);
     } elseif ($data instanceof \DateTime) {
         // datetimeの場合は文字列に変換する.
         return $data->format($this->config['csv_export_date_format']);
     } else {
         // スカラ値の場合はそのまま.
         return $data;
     }
     return null;
 }
Example #3
0
 protected function createCsv($csvType = CsvType::CSV_TYPE_PRODUCT, $field = 'id', $entity = 'Eccube\\Entity\\Product', $ref = null)
 {
     $CsvType = $this->app['eccube.repository.master.csv_type']->find($csvType);
     $Creator = $this->app['eccube.repository.member']->find(2);
     $csv = $this->app['eccube.repository.csv']->findOneBy(array('CsvType' => $CsvType), array('rank' => 'DESC'));
     $rank = 1;
     if ($csv) {
         $rank = $csv->getRank() + 1;
     }
     $Csv = new Csv();
     $Csv->setCsvType($CsvType);
     $Csv->setCreator($Creator);
     $Csv->setEntityName($entity);
     $Csv->setFieldName($field);
     $Csv->setReferenceFieldName($ref);
     $Csv->setDispName('Test');
     $Csv->setEnableFlg(Constant::DISABLED);
     $Csv->setRank($rank);
     $this->app['orm.em']->persist($Csv);
     $this->app['orm.em']->flush();
     return $Csv;
 }