/**
  * Deserializes a Json into readable datas
  * @param string $string
  *
  * @return ArrayCollection
  */
 public static function deserialize($string)
 {
     if ($string == "") {
         throw new \Exception('File is empty.');
     }
     $collection = new ArrayCollection();
     $array = json_decode($string, true);
     foreach ($array as $groupAssoc) {
         if (!empty($groupAssoc["roles"]) && !empty($groupAssoc["name"])) {
             $group = new Group();
             $group->setName($groupAssoc['name']);
             foreach ($groupAssoc["roles"] as $role) {
                 $role = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($role['name']);
                 $group->addRole($role);
             }
             $collection[] = $group;
         }
     }
     return $collection;
 }
Exemplo n.º 2
0
 /**
  * @param array                        $data
  * @param RZ\Roadiz\Core\Entities\Group $group
  *
  * @return RZ\Roadiz\Core\Entities\User
  */
 private function addRole($data, Group $group)
 {
     if ($data['groupId'] == $group->getId()) {
         $role = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Role', (int) $data['roleId']);
         if ($role !== null) {
             $group->addRole($role);
             $this->getService('em')->flush();
             return $role;
         }
     }
 }