/**
  * Export all settings in a Json file (.rzt).
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function exportAllAction(Request $request)
 {
     $this->validateAccessForRole('ROLE_ACCESS_SETTINGS');
     $groups = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\SettingGroup')->findAll();
     $lonelySettings = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Setting')->findBy(['settingGroup' => null]);
     $tmpGroup = new SettingGroup();
     $tmpGroup->setName('__default__');
     $tmpGroup->addSettings($lonelySettings);
     $groups[] = $tmpGroup;
     $data = SettingCollectionJsonSerializer::serialize($groups);
     $response = new Response($data, Response::HTTP_OK, []);
     $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'setting-all-' . date("YmdHis") . '.rzt'));
     // Rezo-Zero Type
     $response->prepare($request);
     return $response;
 }
 /**
  * Deserializes a json file into a readable ArrayCollection of setting.
  *
  * @param string $jsonString
  *
  * @return Doctrine\Common\Collections\ArrayCollection
  */
 public static function deserialize($jsonString)
 {
     if ($jsonString == "") {
         throw new \Exception('File is empty.');
     }
     $collection = new ArrayCollection();
     $groups = json_decode($jsonString, true);
     foreach ($groups as $group) {
         if (!empty($group['name'])) {
             $newGroup = new SettingGroup();
             $newGroup->setName($group['name']);
             if (isset($group['inMenu'])) {
                 $newGroup->setInMenu($group['inMenu']);
             }
             if (!empty($group['settings'])) {
                 foreach ($group['settings'] as $setting) {
                     // do not use !empty on type as it can be 0.
                     if (!empty($setting['name']) && isset($setting['type'])) {
                         $newSetting = new Setting();
                         $newSetting->setName($setting['name']);
                         $newSetting->setType($setting['type']);
                         if ($setting['type'] == NodeTypeField::DATETIME_T) {
                             $dt = new \DateTime($setting['value']['date'], new \DateTimeZone($setting['value']['timezone']));
                             $newSetting->setValue($dt);
                         } else {
                             $newSetting->setValue($setting['value']);
                         }
                         $newSetting->setVisible($setting['visible']);
                         $newGroup->addSetting($newSetting);
                         $newSetting->setSettingGroup($newGroup);
                     }
                 }
             }
             $collection[] = $newGroup;
         }
     }
     return $collection;
 }
 /**
  * @param RZ\Roadiz\Core\Entities\SettingGroup $settingGroup
  *
  * @return \Symfony\Component\Form\Form
  */
 private function buildDeleteForm(SettingGroup $settingGroup)
 {
     $builder = $this->createFormBuilder()->add('settingGroupId', 'hidden', ['data' => $settingGroup->getId(), 'constraints' => [new NotBlank()]]);
     return $builder->getForm();
 }