/** * @return Organization */ public static function createOrga() { $orga = new Organization(); $orga->setName('Orga ORGA'); $orga->setLogin('orga'); $orga->setContactMail('*****@*****.**'); $orga->testingContext = true; $reflection = new \ReflectionObject($orga); $property = $reflection->getProperty('id'); $property->setAccessible(true); $property->setValue($orga, 1); return $orga; }
/** * @param Organization $orga * @param EmbedBag $includes * @return array */ private function getIncludes(Organization $orga, EmbedBag $includes) { $embed = ['members' => []]; if ($includes->has('members')) { foreach ($orga->getMemberships() as $membership) { $embed['members'][] = $this->orgaMemberTransformer->transform($membership, new EmbedBag(['user'])); } } else { foreach ($orga->getMemberships() as $membership) { $embed['members'][] = $this->orgaMemberTransformer->transform($membership, new EmbedBag()); } } return ['_embed' => $embed]; }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void * @throws \RuntimeException */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $output->writeln(' Welcome to the EtuUTT organizations manager This command helps you to create an organization using the command. '); /** @var EntityManager $em */ $em = $this->getContainer()->get('doctrine')->getManager(); $orga = new Organization(); $orga->setName($dialog->ask($output, 'Name: ')); $orga->setLogin($dialog->ask($output, 'Identifier: ')); $em->persist($orga); $em->flush(); $output->writeln("\nDone.\n"); }
/** * Import a user in the database * * @param Organization $bdeOrga * @param bool $flush * @return \Etu\Core\UserBundle\Entity\User */ protected function importUser($bdeOrga = null, $flush = false) { $imagine = new Imagine(); $webDirectory = __DIR__ . '/../../../../../../../web'; $avatar = $this->element->getLogin() . '.jpg'; if (!file_exists($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg')) { // Resize photo try { $image = $imagine->open('http://local-sig.utt.fr/Pub/trombi/individu/' . $this->element->getStudentId() . '.jpg'); $image->copy()->thumbnail(new Box(200, 200), Image::THUMBNAIL_OUTBOUND)->save($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg'); } catch (\Exception $e) { $avatar = 'default-avatar.png'; } } $niveau = null; $branch = $this->element->getNiveau(); preg_match('/^[^0-9]+/i', $this->element->getNiveau(), $match); if (isset($match[0])) { $branch = $match[0]; $niveau = str_replace($branch, '', $this->element->getNiveau()); } $user = new \Etu\Core\UserBundle\Entity\User(); $user->setAvatar($avatar); $user->setLogin($this->element->getLogin()); $user->setFullName($this->element->getFullName()); $user->setFirstName($this->element->getFirstName()); $user->setLastName($this->element->getLastName()); $user->setFiliere($this->element->getFiliere()); $user->setFormation(ucfirst(strtolower($this->element->getFormation()))); $user->setNiveau($niveau); $user->setBranch($branch); $user->setMail($this->element->getMail()); $user->setPhoneNumber($this->element->getPhoneNumber()); $user->setRoom($this->element->getRoom()); $user->setStudentId($this->element->getStudentId()); $user->setTitle($this->element->getTitle()); $user->setIsStudent($this->element->getIsStudent()); $user->setKeepActive(false); $user->setUvs(implode('|', $this->element->getUvs())); $this->doctrine->getManager()->persist($user); // Subscribe to BDE if ($bdeOrga) { $subscription = new Subscription(); $subscription->setEntityType('orga')->setEntityId($bdeOrga->getId())->setUser($user); $this->doctrine->getManager()->persist($subscription); } // Subscribe to all events $subscription = new Subscription(); $subscription->setEntityType('event')->setEntityId(0)->setUser($user); $this->doctrine->getManager()->persist($subscription); // Flush if needed if ($flush) { $this->doctrine->getManager()->flush(); } return $user; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $admin = new User(); $admin->setFullName('Admin ADMIN'); $admin->setLogin('admin'); $admin->setMail('*****@*****.**'); $admin->setIsAdmin(true); $admin->setAvatar('admin.png'); $admin->setBirthday(new \DateTime()); $admin->setLastVisitHome(new \DateTime()); $admin->setReadOnlyExpirationDate(new \DateTime()); $user = new User(); $user->setFullName('User USER'); $user->setLogin('user'); $user->setMail('*****@*****.**'); $user->setIsAdmin(false); $user->setAvatar('user.png'); $user->setBirthday(new \DateTime()); $user->setLastVisitHome(new \DateTime()); $user->setReadOnlyExpirationDate(new \DateTime()); $orga = new Organization(); $orga->setName('Orga ORGA'); $orga->setLogin('orga'); $orga->setContactMail('*****@*****.**'); $manager->persist($admin); $manager->persist($user); $manager->persist($orga); $membership = new Member(); $membership->setOrganization($orga); $membership->setUser($user); $membership->addPermission('daymail'); $manager->persist($membership); $manager->flush(); $this->addReference('user_admin', $admin); $this->addReference('user_user', $user); $this->addReference('user_orga', $orga); $this->addReference('user_membership', $orga); }
/** * @param Category $category * @return bool */ public function canDelete(Category $category) { if ($this->user instanceof Organization) { return false; } if ($this->user->getIsAdmin()) { return true; } if (!$this->user->getIsReadOnly()) { $permissions = new Permissions(); foreach ($category->getPermissions() as $value) { if ($value->getType() == 1) { $permissions = $value; } } if ($permissions->getDelete()) { return true; } foreach ($category->getPermissions() as $value) { if ($value->getType() == 2) { foreach ($this->memberships as $membership) { if ($value->getOrganization() == $membership->getOrganization()) { $permissions = $value; if ($permissions->getDelete()) { return true; } } } } if ($value->getType() == 3) { if ($value->getUser() == $this->user) { $permissions = $value; if ($permissions->getDelete()) { return true; } } } } } }
/** * View a given organization members and their associated informations. * * @ApiDoc( * section = "Organization - Public data", * description = "List of a given organization members (scope: public)", * parameters={ * { "name"="login", "dataType"="string", "required"=true, "description"="Organization login" } * } * ) * * @Route("/public/orgas/{login}/members", name="api_public_orgas_members") * @Method("GET") */ public function membersAction(Organization $orga) { return $this->format(['data' => $this->get('etu.api.orga_member.transformer')->transform($orga->getMemberships()->toArray(), new EmbedBag(['user']))]); }