/** * Get the path to specified area. Returns relative by default with the exception of cache and log * which will be absolute regardless of $fullPath setting. * * @param string $name * @param bool $fullPath * * @return string * * @throws \InvalidArgumentException */ public function getSystemPath($name, $fullPath = false) { if ($name == 'currentTheme' || $name == 'current_theme') { $path = $this->paths['themes'] . '/' . $this->theme; } elseif ($name == 'cache' || $name == 'logs') { //these are absolute regardless as they are configurable return $name === 'cache' ? $this->kernelCacheDir : $this->kernelLogsDir; } elseif ($name == 'images') { $path = $this->imagePath; if (substr($path, -1) === '/') { $path = substr($path, 0, -1); } } elseif ($name == 'dashboard.user' || $name == 'dashboard.global') { //these are absolute regardless as they are configurable $globalPath = $this->dashboardImportDir; if (substr($globalPath, -1) === '/') { $globalPath = substr($globalPath, 0, -1); } if ($name == 'dashboard.global') { return $globalPath; } if (!($userPath = $this->dashboardUserImportDir)) { $userPath = $globalPath; } elseif (substr($userPath, -1) === '/') { $userPath = substr($userPath, 0, -1); } $userPath .= '/' . $this->user->getId(); // @todo check is_writable if (!is_dir($userPath) && !file_exists($userPath)) { mkdir($userPath, 0755); } return $userPath; } elseif (isset($this->paths[$name])) { $path = $this->paths[$name]; } elseif (strpos($name, '_root') !== false) { // Assume system root if one is not set specifically $path = $this->paths['root']; } else { throw new \InvalidArgumentException("{$name} does not exist."); } if ($fullPath) { $rootPath = !empty($this->paths[$name . '_root']) ? $this->paths[$name . '_root'] : $this->paths['root']; return $rootPath . '/' . $path; } return $path; }
/** * Get a lead's upcoming events. * * @param array $options * * @return array * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getUpcomingEvents(array $options = null) { $leadIps = []; $query = $this->_em->getConnection()->createQueryBuilder(); $today = new DateTimeHelper(); $query->from(MAUTIC_TABLE_PREFIX . 'campaign_lead_event_log', 'll')->select('ll.event_id, ll.campaign_id, ll.trigger_date, ll.lead_id, e.name AS event_name, e.description AS event_description, c.name AS campaign_name, c.description AS campaign_description, CONCAT(CONCAT(l.firstname, \' \'), l.lastname) AS lead_name')->leftJoin('ll', MAUTIC_TABLE_PREFIX . 'campaign_events', 'e', 'e.id = ll.event_id')->leftJoin('ll', MAUTIC_TABLE_PREFIX . 'campaigns', 'c', 'c.id = e.campaign_id')->leftJoin('ll', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'l.id = ll.lead_id')->where($query->expr()->gte('ll.trigger_date', ':today'))->setParameter('today', $today->toUtcString()); if (isset($options['lead'])) { /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ foreach ($options['lead']->getIpAddresses() as $ip) { $leadIps[] = $ip->getId(); } $query->andWhere('ll.lead_id = :leadId')->setParameter('leadId', $options['lead']->getId()); } if (isset($options['scheduled'])) { $query->andWhere('ll.is_scheduled = :scheduled')->setParameter('scheduled', $options['scheduled'], 'boolean'); } if (isset($options['eventType'])) { $query->andwhere('e.event_type = :eventType')->setParameter('eventType', $options['eventType']); } if (isset($options['type'])) { $query->andwhere('e.type = :type')->setParameter('type', $options['type']); } if (isset($options['limit'])) { $query->setMaxResults($options['limit']); } else { $query->setMaxResults(10); } $query->orderBy('ll.trigger_date'); if (!empty($ipIds)) { $query->orWhere('ll.ip_address IN (' . implode(',', $ipIds) . ')'); } if (!empty($options['canViewOthers']) && isset($this->currentUser)) { $query->andWhere('c.created_by = :userId')->setParameter('userId', $this->currentUser->getId()); } return $query->execute()->fetchAll(); }
/** * @param \Doctrine\ORM\QueryBuilder $q * @param object $filter * * @return array */ protected function addStandardSearchCommandWhereClause(&$q, $filter) { $command = $filter->command; $unique = $this->generateRandomParameterName(); $returnParameter = true; //returning a parameter that is not used will lead to a Doctrine error $expr = false; $prefix = $this->getTableAlias(); switch ($command) { case $this->translator->trans('mautic.core.searchcommand.ispublished'): $expr = $q->expr()->eq("{$prefix}.isPublished", ":{$unique}"); $forceParameters = array($unique => true); break; case $this->translator->trans('mautic.core.searchcommand.isunpublished'): $expr = $q->expr()->eq("{$prefix}.isPublished", ":{$unique}"); $forceParameters = array($unique => false); break; case $this->translator->trans('mautic.core.searchcommand.isuncategorized'): $expr = $q->expr()->orX($q->expr()->isNull("{$prefix}.category"), $q->expr()->eq("{$prefix}.category", $q->expr()->literal(''))); $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.ismine'): $expr = $q->expr()->eq("IDENTITY({$prefix}.createdBy)", $this->currentUser->getId()); $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.category'): $expr = $q->expr()->like("c.alias", ":{$unique}"); $filter->strict = true; break; } if ($expr && $filter->not) { $expr = $q->expr()->not($expr); } if (!empty($forceParameters)) { $parameters = $forceParameters; } elseif (!$returnParameter) { $parameters = array(); } else { $string = $filter->strict ? $filter->string : "%{$filter->string}%"; $parameters = array("{$unique}" => $string); } return array($expr, $parameters); }
/** * Set checkedOutBy * * @param User $checkedOutBy * * @return mixed */ public function setCheckedOutBy($checkedOutBy = null) { if ($checkedOutBy != null && !$checkedOutBy instanceof User) { $this->checkedOutBy = $checkedOutBy; } else { $this->checkedOutBy = $checkedOutBy != null ? $checkedOutBy->getId() : null; if ($checkedOutBy != null) { $this->checkedOutByUser = $checkedOutBy->getName(); } } return $this; }
/** * @param User $user * * @return array */ public function getUserClients(User $user) { $query = $this->createQueryBuilder($this->getTableAlias()); $query->join('c.users', 'u')->where($query->expr()->eq('u.id', ':userId'))->setParameter('userId', $user->getId()); return $query->getQuery()->getResult(); }
/** * @param \Doctrine\ORM\QueryBuilder $q * @param object $filter * * @return array */ protected function addStandardSearchCommandWhereClause(&$q, $filter) { $command = $filter->command; $unique = $this->generateRandomParameterName(); $returnParameter = true; //returning a parameter that is not used will lead to a Doctrine error $expr = false; $prefix = $this->getTableAlias(); switch ($command) { case $this->translator->trans('mautic.core.searchcommand.ispublished'): $expr = $q->expr()->eq("{$prefix}.isPublished", ":{$unique}"); $forceParameters = array($unique => true); break; case $this->translator->trans('mautic.core.searchcommand.isunpublished'): $expr = $q->expr()->eq("{$prefix}.isPublished", ":{$unique}"); $forceParameters = array($unique => false); break; case $this->translator->trans('mautic.core.searchcommand.isuncategorized'): $expr = $q->expr()->orX($q->expr()->isNull("{$prefix}.category"), $q->expr()->eq("{$prefix}.category", $q->expr()->literal(''))); $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.ismine'): $expr = $q->expr()->eq("IDENTITY({$prefix}.createdBy)", $this->currentUser->getId()); $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.category'): // Find the category prefix $joins = $q->getDQLPart('join'); $catPrefix = false; foreach ($joins as $joinPrefix => $joinStatements) { /** @var Query\Expr\Join $join */ foreach ($joinStatements as $join) { if (strpos($join->getJoin(), '.category') !== false) { $catPrefix = $join->getAlias(); break; } } if ($catPrefix !== false) { break; } } if (false === $catPrefix) { $catPrefix = 'c'; } $expr = $q->expr()->like("{$catPrefix}.alias", ":{$unique}"); $filter->strict = true; break; } if ($expr && $filter->not) { $expr = $q->expr()->not($expr); } if (!empty($forceParameters)) { $parameters = $forceParameters; } elseif (!$returnParameter) { $parameters = array(); } else { $string = $filter->strict ? $filter->string : "%{$filter->string}%"; $parameters = array("{$unique}" => $string); } return array($expr, $parameters); }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }
/** * Create/update user from authentication plugins. * * @param User $user * @param bool|true $createIfNotExists * * @return User */ public function saveUser(User $user, $createIfNotExists = true) { $isNew = !$user->getId(); if ($isNew) { // Check if user exists and create one if applicable try { $user = $this->loadUserByUsername($user->getUsername(), $user->getEmail()); } catch (UsernameNotFoundException $exception) { if (!$createIfNotExists) { throw new BadCredentialsException(); } } } // Validation for User objects returned by a plugin if (!$user->getRole()) { throw new AuthenticationException('mautic.integration.sso.error.no_role'); } if (!$user->getUsername()) { throw new AuthenticationException('mautic.integration.sso.error.no_username'); } if (!$user->getEmail()) { throw new AuthenticationException('mautic.integration.sso.error.no_email'); } if (!$user->getFirstName() || !$user->getLastName()) { throw new AuthenticationException('mautic.integration.sso.error.no_name'); } // Check for plain password $plainPassword = $user->getPlainPassword(); if ($plainPassword) { // Encode plain text $user->setPassword($this->encoder->getEncoder($user)->encodePassword($plainPassword, $user->getSalt())); } elseif (!($password = $user->getPassword())) { // Generate and encode a random password $user->setPassword($this->encoder->getEncoder($user)->encodePassword(EncryptionHelper::generateKey(), $user->getSalt())); } $event = new UserEvent($user, $isNew); if ($this->dispatcher->hasListeners(UserEvents::USER_PRE_SAVE)) { $event = $this->dispatcher->dispatch(UserEvents::USER_PRE_SAVE, $event); } $this->userRepository->saveEntity($user); if ($this->dispatcher->hasListeners(UserEvents::USER_POST_SAVE)) { $this->dispatcher->dispatch(UserEvents::USER_POST_SAVE, $event); } return $user; }