public function createInwicastUserIfNotExists(User $user, $token, Mediacenter $mediacenter) { $connection = $this->connectionFactory->createConnection($mediacenter->getDatabaseParameters()); $qb = $connection->createQueryBuilder(); $qb->select('usr.username, usr.token')->from('mdcr_inwicast_user_tokens', 'usr')->where('usr.username = :username')->andWhere('usr.tokenapp = :platform')->setParameter("username", $user->getUsername())->setParameter("platform", $this->platformName); $result = $qb->execute()->fetch(); if (!$result) { //$qb_insert = $connection->createQueryBuilder(); $sql = "INSERT INTO mdcr_inwicast_user_tokens" . " (`username`, `firstname`, `lastname`, `email`, `userrole`, `token`, `tokendate`, `tokenapp`)" . " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; $query = $connection->prepare($sql); $query->bindValue(1, $user->getUsername()); $query->bindValue(2, $user->getFirstName()); $query->bindValue(3, $user->getLastName()); $query->bindValue(4, $user->getMail()); $query->bindValue(5, $user->getPlatformRole()->getName()); $query->bindValue(6, $token); $query->bindValue(7, date('Y-m-d H:i:s')); $query->bindValue(8, $this->platformName); $query->execute(); } else { $qb_update = $connection->createQueryBuilder(); $qb_update->update('mdcr_inwicast_user_tokens')->set('token', '?')->set('tokendate', '?')->set('tokenapp', '?')->where('username = ?')->setParameter(0, $token)->setParameter(1, date('Y-m-d H:i:s'))->setParameter(2, $this->platformName)->setParameter(3, $user->getUsername()); $qb_update->execute(); } return true; }
public function __construct(Cursus $cursus, User $user) { $details = []; $details['username'] = $user->getUsername(); $details['firsName'] = $user->getFirstName(); $details['lastName'] = $user->getLastName(); $details['cursusId'] = $cursus->getId(); $details['cursusTitle'] = $cursus->getTitle(); $details['cursusCode'] = $cursus->getCode(); parent::__construct(self::ACTION, $details, $user); }
public function __construct(CourseSession $session, User $user) { $course = $session->getCourse(); $details = array(); $details['username'] = $user->getUsername(); $details['firsName'] = $user->getFirstName(); $details['lastName'] = $user->getLastName(); $details['sessionId'] = $session->getId(); $details['sessionName'] = $session->getName(); $details['sessionCreationDate'] = $session->getCreationDate()->format('d/m/Y H:i:s'); $details['courseId'] = $course->getId(); $details['courseTitle'] = $course->getTitle(); $details['courseCode'] = $course->getCode(); parent::__construct(self::ACTION, $details, $user); }
public function __construct(SessionEvent $sessionEvent, User $user) { $session = $sessionEvent->getSession(); $course = $session->getCourse(); $details = []; $details['username'] = $user->getUsername(); $details['firsName'] = $user->getFirstName(); $details['lastName'] = $user->getLastName(); $details['sessionEventId'] = $sessionEvent->getId(); $details['sessionEventName'] = $sessionEvent->getName(); $details['sessionId'] = $session->getId(); $details['sessionName'] = $session->getName(); $details['courseId'] = $course->getId(); $details['courseTitle'] = $course->getTitle(); $details['courseCode'] = $course->getCode(); parent::__construct(self::ACTION, $details, $user); }
/** * @param User $user */ public function setUser(User $user) { $this->user = $user; $this->userName = $user->getFirstName() . ' ' . $user->getLastName(); }
/** * @EXT\Route( * "user/{user}/infos/request", * name="claro_user_infos_request", * options = {"expose"=true} * ) */ public function userInfosRequestAction(User $user) { $datas = array('id' => $user->getId(), 'firstName' => $user->getFirstName(), 'lastName' => $user->getLastName(), 'username' => $user->getUsername(), 'mail' => $user->getMail(), 'phone' => $user->getPhone(), 'picture' => $user->getPicture()); return new JsonResponse($datas, 200); }
public function createRemoteUser(User $user) { $url = 'api/users.json'; $tmppw = uniqid(); $payload = array('profile_form_creation[username]' => $user->getUsername(), 'profile_form_creation[firstName]' => $user->getFirstName(), 'profile_form_creation[lastName]' => $user->getLastName(), 'profile_form_creation[mail]' => $user->getMail(), 'profile_form_creation[administrativeCode]' => $user->getUsername(), 'profile_form_creation[plainPassword][first]' => $tmppw, 'profile_form_creation[plainPassword][second]' => $tmppw); $serverOutput = $this->apiManager->url($this->targetFriend, $url, $payload, 'POST'); $datas = json_decode($serverOutput, true); return $datas; }
/** * @param User $user * @param int $try * * @return string */ public function generatePublicUrl(User $user) { $publicUrl = $user->getFirstName() . '.' . $user->getLastName(); $publicUrl = strtolower(str_replace(' ', '-', $publicUrl)); $searchedUsers = $this->objectManager->getRepository('ClarolineCoreBundle:User')->findOneByPublicUrl($publicUrl); if (null !== $searchedUsers) { $publicUrl .= '_' . uniqid(); } return $publicUrl; }
public function sendTicketMail(User $user, Ticket $ticket, $type = '', Comment $comment = null) { $contactMail = null; $receivers = []; $extra = []; switch ($type) { case 'new_ticket': $contactIds = $this->getConfigurationContactsOption(); $contactMail = $ticket->getContactMail(); if (count($contactIds) > 0) { $receivers = $this->userManager->getUsersByIds($contactIds); $subject = '[' . $this->translator->trans('new_ticket', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle(); $content = $ticket->getDescription() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>'; } break; case 'ticket_edition': $contactIds = $this->getConfigurationContactsOption(); $contactMail = $ticket->getContactMail(); if (count($contactIds) > 0) { $receivers = $this->userManager->getUsersByIds($contactIds); $subject = '[' . $this->translator->trans('ticket_edition', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle(); $content = $ticket->getDescription() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>'; } break; case 'ticket_deletion': $contactIds = $this->getConfigurationContactsOption(); if (count($contactIds) > 0) { $receivers = $this->userManager->getUsersByIds($contactIds); $subject = '[' . $this->translator->trans('ticket_deletion', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle(); $content = $this->translator->trans('ticket_deletion', [], 'support') . '<br><br>'; } break; case 'new_admin_comment': $extra['to'] = [$ticket->getContactMail()]; if (!is_null($comment)) { $subject = '[' . $this->translator->trans('new_comment', [], 'support') . '][' . $this->translator->trans('ticket', [], 'support') . ' #' . $ticket->getNum() . '] ' . $ticket->getTitle(); $content = $comment->getContent() . '<br><br>'; } break; case 'new_comment': $contactIds = $this->getConfigurationContactsOption(); $contactMail = $ticket->getContactMail(); if (count($contactIds) > 0 && !is_null($comment)) { $receivers = $this->userManager->getUsersByIds($contactIds); $subject = '[' . $this->translator->trans('new_comment', [], 'support') . '][' . $user->getFirstName() . ' ' . $user->getLastName() . '] ' . $ticket->getTitle(); $content = $comment->getContent() . '<br><br>' . $this->translator->trans('mail', [], 'platform') . ' : ' . $ticket->getContactMail() . '<br>' . $this->translator->trans('phone', [], 'platform') . ' : ' . $ticket->getContactPhone() . '<br><br>'; } break; default: break; } if (count($receivers) > 0 || count($extra) > 0) { $this->mailManager->send($subject, $content, $receivers, null, $extra, false, $contactMail); } }
/** * @param string $subject * @param string $body * @param User[] $users * @param User $from * @param array $extra * @param bool $force * @param string $replyToMail * * @return bool */ public function send($subject, $body, array $users, $from = null, array $extra = [], $force = false, $replyToMail = null) { if (count($users) === 0) { //obviously, if we're not going to send anything to anyone, it's better to stop return false; } if ($this->isMailerAvailable()) { $to = []; $layout = $this->contentManager->getTranslatedContent(['type' => 'claro_mail_layout']); $fromEmail = $this->getMailerFrom(); $locale = count($users) === 1 ? $users[0]->getLocale() : $this->ch->getParameter('locale_language'); if (!$locale) { $locale = $this->ch->getParameter('locale_language'); } $usedLayout = $layout[$locale]['content']; $body = str_replace('%content%', $body, $usedLayout); $body = str_replace('%platform_name%', $this->ch->getParameter('name'), $body); if ($from) { $body = str_replace('%first_name%', $from->getFirstName(), $body); $body = str_replace('%last_name%', $from->getLastName(), $body); } else { $body = str_replace('%first_name%', $this->ch->getParameter('name'), $body); $body = str_replace('%last_name%', '', $body); } foreach ($users as $user) { $mail = $user->getMail(); if ($user->isMailValidated() || $force) { if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { $to[] = $mail; } } } if (isset($extra['to'])) { foreach ($extra['to'] as $mail) { if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { $to[] = $mail; } } } $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setReplyTo($replyToMail)->setBody($body, 'text/html'); if ($from !== null && filter_var($from->getMail(), FILTER_VALIDATE_EMAIL)) { $message->setReplyTo($from->getMail()); } if (count($to) > 1) { $message->setBcc($to); } else { $message->setTo($to); } if (isset($extra['attachment'])) { $message->attach(\Swift_Attachment::fromPath($extra['attachment'], 'application/octet-stream')); } return $this->mailer->send($message) ? true : false; } return false; }
/** * @ApiDoc( * description="Returns a user", * views = {"user"} * ) * @Get("/user/{user}/public", name="get_public_user", options={ "method_prefix" = false }) */ public function getPublicUserAction(User $user) { $settingsProfile = $this->facetManager->getVisiblePublicPreference(); $publicUser = []; foreach ($settingsProfile as $property => $isViewable) { if ($isViewable || $user === $this->container->get('security.token_storage')->getToken()->getUser()) { switch ($property) { case 'baseData': $publicUser['lastName'] = $user->getLastName(); $publicUser['firstName'] = $user->getFirstName(); $publicUser['username'] = $user->getUsername(); $publicUser['picture'] = $user->getPicture(); $publicUser['description'] = $user->getAdministrativeCode(); break; case 'email': $publicUser['mail'] = $user->getMail(); break; case 'phone': $publicUser['phone'] = $user->getPhone(); break; case 'sendMail': $publicUser['mail'] = $user->getMail(); $publicUser['allowSendMail'] = true; break; case 'sendMessage': $publicUser['allowSendMessage'] = true; $publicUser['id'] = $user->getId(); break; } } } return $publicUser; }
/** * @param string $subject * @param string $body * @param User[] $users * @param User $from * * @return boolean */ public function send($subject, $body, array $users, $from = null, array $extra = array()) { if ($this->isMailerAvailable()) { $to = []; $layout = $this->contentManager->getTranslatedContent(array('type' => 'claro_mail_layout')); $fromEmail = 'noreply@' . $this->ch->getParameter('domain_name'); $locale = count($users) === 1 ? $users[0]->getLocale() : $this->ch->getParameter('locale_language'); if (!$locale) { $locale = $this->ch->getParameter('locale_language'); } $usedLayout = $layout[$locale]['content']; $body = str_replace('%content%', $body, $usedLayout); $body = str_replace('%platform_name%', $this->ch->getParameter('name'), $body); if ($from) { $body = str_replace('%first_name%', $from->getFirstName(), $body); $body = str_replace('%last_name%', $from->getLastName(), $body); } else { $body = str_replace('%first_name%', $this->ch->getParameter('name'), $body); $body = str_replace('%last_name%', '', $body); } foreach ($users as $user) { $mail = $user->getMail(); if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { $to[] = $mail; } } if (isset($extra['to'])) { foreach ($extra['to'] as $mail) { if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { $to[] = $mail; } } } $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setBody($body, 'text/html'); if (count($to) > 1) { $message->setBcc($to); } else { $message->setTo($to); } if (isset($extra['attachment'])) { $message->attach(\Swift_Attachment::fromPath($extra['attachment'], "application/octet-stream")); } return $this->mailer->send($message) ? true : false; } return false; }