/** * Generate representative username by name and set new username * * @param Representative $representative * @param int $iteration * * @return string New username */ public function generateRepresentativeUsername(Representative $representative, $iteration = 0) { // Generate canonical name $name = $representative->getFirstName() . $representative->getLastName(); $name = preg_replace('/[^\\w]/i', '', $name); $name = strtolower($name); $name = $iteration ? $name . $iteration : $name; $representByUsername = $this->entityManager->getRepository('CivixCoreBundle:Representative')->findOneBy(array('username' => $name)); if (is_null($representByUsername)) { $representative->setUsername($name); } else { $name = $this->generateRepresentativeUsername($representative, ++$iteration); } return $name; }
/** * Save representative from api in representative storage. * Set link between representative and representative storage * * @param Object $resultApiCollection Object from Cicero API * @param Representative $representative Representative object * * @return District */ protected function updateRepresentativeStorage($resultApiCollection, Representative $representative) { $lastReprDistrict = false; foreach ($resultApiCollection as $repr) { $storRepr = $this->entityManager->getRepository('CivixCoreBundle:RepresentativeStorage')->findOneByStorageId($repr->id); if (!$storRepr) { $storRepr = $this->createStorRepresentativeByApiObj($repr); $this->entityManager->persist($storRepr); } //Update link between representative and representative storage $representative->setStorageId($storRepr->getStorageId()); $lastReprDistrict = $storRepr->getDistrict(); } $this->entityManager->flush(); return $lastReprDistrict; }
/** * Remove localRepresentatives * * @param \Civix\CoreBundle\Entity\Representative $localRepresentatives */ public function removeLocalRepresentative(\Civix\CoreBundle\Entity\Representative $localRepresentative) { $localRepresentative->setLocalGroup(null); $this->localRepresentatives->removeElement($localRepresentative); }
public static function toRepresentativeOwnerData(Representative $representative) { $data = ['id' => $representative->getId(), 'type' => $representative->getType(), 'official_title' => $representative->getOfficialTitle(), 'first_name' => $representative->getFirstName(), 'last_name' => $representative->getLastName(), 'avatar_file_path' => $representative->getAvatarFileName()]; if ($representative->getStorageId()) { $data['storage_id'] = $representative->getStorageId(); } return $data; }
public function sendToApprovedRepresentative(Representative $representative, $username, $password) { $message = $this->createMessage('Representative Registration approved', $representative->getEmail(), 'CivixFrontBundle:Superuser:email/representative_approved.html.twig', array('name' => $representative->getFirstName() . ' ' . $representative->getLastName(), 'username' => $username, 'password' => $password)); $this->mailer->send($message); }
public function load(ObjectManager $manager) { // Create representative /** @var $representative Representative */ $representative = new Representative(); $representative->setFirstName(self::REPRESENTATIVE_NAME); $representative->setLastName(self::REPRESENTATIVE_NAME); $representative->setUsername(self::REPRESENTATIVE_NAME); $representative->setOfficialTitle(self::REPRESENTATIVE_TITLE); $representative->setOfficialAddress(self::REPRESENTATIVE_ADDRESS); $representative->setOfficialPhone(self::REPRESENTATIVE_PHONE); $representative->setEmail(self::REPRESENTATIVE_EMAIL); $representative->setCountry(self::REPRESENTATIVE_COUNTRY); $representative->setCity(self::REPRESENTATIVE_CITY); $representative->setDistrict($this->getReference('district_us')); //encode password according configuration $factory = $this->container->get('security.encoder_factory'); $encoder = $factory->getEncoder($representative); $password = $encoder->encodePassword(self::REPRESENTATIVE_PASSWORD, $representative->getSalt()); $representative->setPassword($password); $this->addReference('representative1', $representative); $manager->persist($representative); $manager->flush(); }
public function getAddressArray() { $this->__load(); return parent::getAddressArray(); }
public function load(ObjectManager $manager) { $representative = new Representative(); $representative->setFirstName('Joseph'); $representative->setLastName('Biden'); $representative->setUsername('JosephBiden'); $representative->setOfficialTitle('Vice President'); $representative->setCity('Washington'); $representative->setOfficialAddress('1600 Pennsylvania Avenue NW'); $representative->setOfficialPhone(''); $representative->setEmail('*****@*****.**'); $representative->setDistrict($this->getReference('district_us')); $representative->setRepresentativeStorage($this->getReference('vice_president')); $this->addReference('vice_president_representative', $representative); $manager->persist($representative); $manager->flush($representative); }
public function removeRepresentative(\Civix\CoreBundle\Entity\Representative $representative) { $this->getEntityManager()->createQueryBuilder()->update('CivixCoreBundle:Poll\\Question\\Representative r')->set('r.user', 'NULL')->where('r.user = :representativeId')->setParameter('representativeId', $representative->getId())->getQuery()->execute(); $this->getEntityManager()->createQueryBuilder()->update('CivixCoreBundle:Activity a')->set('a.representative', 'NULL')->where('a.representative = :representativeId')->setParameter('representativeId', $representative->getId())->getQuery()->execute(); $this->getEntityManager()->createQueryBuilder()->delete('CivixCoreBundle:Representative r')->where('r.id = :representativeId')->setParameter('representativeId', $representative->getId())->getQuery()->execute(); }