コード例 #1
0
 protected function buildOptions(ReportParameter $parameter)
 {
     $options = array();
     if ($parameter->getType() == ReportParameter::TYPE_QUERY) {
         $stmt = $this->connection->prepare($parameter->getChoices());
         $stmt->execute();
         $results = $stmt->fetchAll();
         $values = array(null => '');
         $keySet = array_keys(current($results));
         $key = current(array_slice($keySet, 0, 1));
         $value = current(array_slice($keySet, 1, 1));
         foreach ($results as $result) {
             $values[$result[$value]] = $result[$key];
         }
         $options = array_merge($options, array('choices' => $values));
         $parameter->setType(ChoiceType::class);
     }
     $normalizer = new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer();
     $normalizer->setIgnoredAttributes(array('id', 'name', 'type', 'created', 'modified', 'active'));
     $serializer = new \Symfony\Component\Serializer\Serializer(array($normalizer));
     $options = array_merge($serializer->normalize($parameter), $options);
     foreach ($options as $key => $value) {
         if (is_null($value)) {
             unset($options[$key]);
         }
     }
     $this->handleConstraints($options);
     return $options;
 }
コード例 #2
0
ファイル: Depedencies.php プロジェクト: mardraze/core-bundle
 public function arrayToXml($data, $root = 'root')
 {
     $xmlEncoder = new \Symfony\Component\Serializer\Encoder\XmlEncoder($root);
     $encoders = array($xmlEncoder);
     $serializer = new \Symfony\Component\Serializer\Serializer(array(), $encoders);
     return $serializer->serialize($data, 'xml');
 }