本文整理汇总了PHP中Mautic\CoreBundle\Helper\DateTimeHelper类的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeHelper类的具体用法?PHP DateTimeHelper怎么用?PHP DateTimeHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTimeHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onCalendarGenerate
/**
* Adds events to the calendar.
*
* @param CalendarGeneratorEvent $event
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$query = $this->em->getConnection()->createQueryBuilder();
$query->select('es.email_id, e.subject AS title, COUNT(es.id) AS quantity, es.date_sent AS start, e.plain_text AS description, cat.color, es.lead_id, l.firstname, l.lastname, l.email')->from(MAUTIC_TABLE_PREFIX . 'email_stats', 'es')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'emails', 'e', 'es.email_id = e.id')->leftJoin('e', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = e.category_id AND cat.bundle=:bundle')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'l.id = es.lead_id')->where($query->expr()->andX($query->expr()->gte('es.date_sent', ':start'), $query->expr()->lte('es.date_sent', ':end')))->groupBy('e.id, es.email_id, e.subject, es.date_sent, e.plain_text, cat.color, es.lead_id, l.firstname, l.lastname, l.email')->setParameter('bundle', 'email')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(15);
$results = $query->execute()->fetchAll();
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
$date = new DateTimeHelper($object['start']);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
if ($object['email_id']) {
$object['url'] = $this->router->generate('mautic_email_action', ['objectAction' => 'view', 'objectId' => $object['email_id']], true);
$object['attr'] = 'data-toggle="ajax"';
$object['description'] = html_entity_decode($object['description']);
$object['title'] = $this->translator->trans('mautic.email.event.sent', ['%email%' => $object['title'], '%x%' => $object['quantity']]);
} else {
if ($object['firstname'] || $object['lastname']) {
$contactName = trim($object['firstname'] . ' ' . $object['lastname']);
} elseif ($object['email']) {
$contactName = $object['email'];
} else {
$contactName = $this->translator->trans('mautic.lead.lead.anonymous');
}
$details = $this->translator->trans('mautic.email.event.sent.direct', ['%contact%' => $contactName]);
$object['url'] = $this->router->generate('mautic_contact_action', ['objectAction' => 'view', 'objectId' => $object['lead_id']], true);
$object['attr'] = 'data-toggle="ajax"';
$object['title'] = $details;
$object['description'] = $details;
}
}
$event->addEvents($results);
}
示例2: getDevice
/**
* @param $emailIds
* @param \DateTime $fromDate
*
* @return array
*/
public function getDevice($statIds, $lead, $deviceName = null, $deviceBrand = null, $deviceModel = null, \DateTime $fromDate = null, \DateTime $toDate = null)
{
$sq = $this->_em->getConnection()->createQueryBuilder();
$sq->select('es.id as id, es.device as device')->from(MAUTIC_TABLE_PREFIX . 'lead_devices', 'es');
if (!empty($statIds)) {
$inIds = !is_array($statIds) ? [(int) $statIds] : $statIds;
$sq->where($sq->expr()->in('es.id', $inIds));
}
if ($deviceName !== null) {
$sq->where($sq->expr()->eq('es.device', ':device'))->setParameter('device', $deviceName);
}
if ($deviceBrand !== null) {
$sq->where($sq->expr()->eq('es.device_brand', ':deviceBrand'))->setParameter('deviceBrand', $deviceBrand);
}
if ($deviceModel !== null) {
$sq->where($sq->expr()->eq('es.device_model', ':deviceModel'))->setParameter('deviceModel', $deviceModel);
}
if ($lead !== null) {
$sq->where($sq->expr()->eq('es.lead_id', $lead->getId()));
}
if ($fromDate !== null) {
//make sure the date is UTC
$dt = new DateTimeHelper($fromDate);
$sq->andWhere($sq->expr()->gte('es.date_added', $sq->expr()->literal($dt->toUtcString())));
}
if ($toDate !== null) {
//make sure the date is UTC
$dt = new DateTimeHelper($toDate);
$sq->andWhere($sq->expr()->lte('es.date_added', $sq->expr()->literal($dt->toUtcString())));
}
//get totals
$device = $sq->execute()->fetchAll();
return !empty($device) ? $device[0] : [];
}
示例3: onCalendarGenerate
/**
* Adds events to the calendar
*
* @param CalendarGeneratorEvent $event
*
* @return void
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$router = $this->factory->getRouter();
$now = new DateTimeHelper();
$commonSelect = 'cl.campaign_id, c.name AS campaign_name, l.firstname, l.lastname, ce.type AS event_type, ce.name as event_name, cat.color';
$eventTypes = array();
$eventTypes['triggered'] = array('dateName' => 'cl.date_triggered');
$eventTypes['upcoming'] = array('dateName' => 'cl.trigger_date');
$query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
$query->from(MAUTIC_TABLE_PREFIX . 'campaign_lead_event_log', 'cl')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'campaigns', 'c', 'cl.campaign_id = c.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'cl.lead_id = l.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'campaign_events', 'ce', 'cl.event_id = ce.id')->leftJoin('cl', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = c.category_id AND cat.bundle="campaign"')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(50);
foreach ($eventTypes as $eventKey => $eventType) {
$query->select($commonSelect . ', ' . $eventType['dateName'] . ' AS start')->where($query->expr()->andX($query->expr()->gte($eventType['dateName'], ':start'), $query->expr()->lte($eventType['dateName'], ':end')));
if ($eventKey == 'upcoming') {
$query->andWhere($query->expr()->gte($eventType['dateName'], ':now'))->setParameter('now', $now->toUtcString());
}
$results = $query->execute()->fetchAll();
// echo "<pre>";var_dump($results);die("</pre>");
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
if ($object['firstname'] || $object['lastname']) {
$leadName = $object['firstname'] . ' ' . $object['lastname'];
} else {
$leadName = $this->translator->trans('mautic.lead.lead.anonymous');
}
$date = new DateTimeHelper($object['start']);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
$object['url'] = $router->generate('mautic_campaign_action', array('objectAction' => 'view', 'objectId' => $object['campaign_id']), true);
$object['attr'] = 'data-toggle="ajax"';
$object['description'] = $this->translator->trans('mautic.campaign.event.' . $eventKey . '.description', array('%campaign%' => $object['campaign_name'], '%lead%' => $leadName));
$object['title'] = $this->translator->trans('mautic.campaign.event.' . $eventKey, array('%event%' => $object['event_name']));
}
$event->addEvents($results);
}
}
示例4: onCalendarGenerate
/**
* Adds events to the calendar.
*
* @param CalendarGeneratorEvent $event
*
* @todo This method is only a model and should be removed when actual data is being populated
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$commonSelect = 'p.title, p.id as page_id, c.color';
$eventTypes = ['publish.up' => ['dateName' => 'publish_up', 'setter' => 'PublishUp'], 'publish.down' => ['dateName' => 'publish_down', 'setter' => 'PublishDown']];
$query = $this->em->getConnection()->createQueryBuilder();
$query->from(MAUTIC_TABLE_PREFIX . 'pages', 'p')->leftJoin('p', MAUTIC_TABLE_PREFIX . 'categories', 'c', 'c.id = p.category_id AND c.bundle=:bundle')->setParameter('bundle', 'page')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(50);
foreach ($eventTypes as $eventKey => $eventType) {
$query->select($commonSelect . ', ' . $eventType['dateName'] . ' AS start')->where($query->expr()->andX($query->expr()->gte('p.' . $eventType['dateName'], ':start'), $query->expr()->lte('p.' . $eventType['dateName'], ':end')));
$results = $query->execute()->fetchAll();
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
$date = new DateTimeHelper($object['start']);
$eventTitle = $this->translator->trans('mautic.page.event.' . $eventKey, ['%page%' => $object['title']]);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
$object['setter'] = $eventType['setter'];
$object['entityId'] = $object['page_id'];
$object['entityType'] = 'page';
$object['editable'] = true;
$object['url'] = $this->router->generate('mautic_calendar_action', ['objectAction' => 'edit', 'source' => 'page', 'objectId' => $object['page_id'], 'startDate' => $date->toLocalString()], true);
$object['viewUrl'] = $this->router->generate('mautic_page_action', ['objectAction' => 'view', 'objectId' => $object['page_id']], true);
$object['attr'] = ['data-toggle' => 'ajaxmodal', 'data-target' => '#CalendarEditModal', 'data-header' => $eventTitle];
$object['description'] = $this->translator->trans('mautic.page.event.' . $eventKey . '.description', ['%page%' => $object['title']]);
$object['title'] = $eventTitle;
}
$event->addEvents($results);
}
}
示例5: updateOnlineStatuses
/**
* Last active updates every 2 minutes. If it didn't get updated, it means the user closed their browser and are thus
* now offline
*
*/
public function updateOnlineStatuses()
{
$dt = new DateTimeHelper();
$offlineDelay = $dt->getUtcDateTime();
$offlineDelay->setTimestamp(strtotime('15 minutes ago'));
$q = $this->_em->createQueryBuilder()->update('MauticUserBundle:User', 'u')->set('u.onlineStatus', ':status')->where('u.lastActive <= :delay')->setParameter('delay', $offlineDelay)->setParameter('status', 'offline');
$q->getQuery()->execute();
}
示例6: getLeadIpLogs
/**
* @param Lead $lead
* @param array $options
*
* @return array
*/
public function getLeadIpLogs(Lead $lead, array $options = [])
{
$qb = $this->getEntityManager()->getConnection()->createQueryBuilder();
$sqb = $this->getEntityManager()->getConnection()->createQueryBuilder();
// Just a check to ensure reused IDs (happens with innodb) doesn't infect data
$dt = new DateTimeHelper($lead->getDateAdded(), 'Y-m-d H:i:s', 'local');
$sqb->select('MAX(l.date_added) as date_added, l.ip_address')->from(MAUTIC_TABLE_PREFIX . 'audit_log', 'l')->where($sqb->expr()->andX($sqb->expr()->eq('l.bundle', $sqb->expr()->literal('lead')), $sqb->expr()->eq('l.object', $sqb->expr()->literal('lead')), $sqb->expr()->eq('l.action', $sqb->expr()->literal('ipadded')), $sqb->expr()->eq('l.object_id', $lead->getId()), $sqb->expr()->gte('l.date_added', $sqb->expr()->literal($dt->getUtcTimestamp()))))->groupBy('l.ip_address');
$qb->select('ip.date_added, ip.ip_address')->from(sprintf('(%s)', $sqb->getSQL()), 'ip');
return $this->getTimelineResults($qb, $options, 'ip.ip_address', 'ip.date_added', [], ['date_added']);
}
示例7: reverseTransform
public function reverseTransform($rawFilters)
{
if (!is_array($rawFilters)) {
return array();
}
foreach ($rawFilters as $k => $f) {
if ($f['type'] == 'datetime') {
$dt = new DateTimeHelper($f['filter'], 'Y-m-d H:i', 'local');
$rawFilters[$k]['filter'] = $dt->toUtcString();
}
}
return $rawFilters;
}
示例8: onCalendarGenerate
/**
* Adds events to the calendar
*
* @param CalendarGeneratorEvent $event
*
* @return void
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
$query->select('fs.referer AS url, f.name AS title, fs.date_submitted AS start')->from(MAUTIC_TABLE_PREFIX . 'form_submissions', 'fs')->leftJoin('fs', MAUTIC_TABLE_PREFIX . 'forms', 'f', 'fs.form_id = f.id')->where($query->expr()->andX($query->expr()->gte('fs.date_submitted', ':start'), $query->expr()->lte('fs.date_submitted', ':end')))->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(5);
$results = $query->execute()->fetchAll();
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
$date = new DateTimeHelper($object['start']);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
$object['title'] = $this->translator->trans('mautic.form.event.submission', array('%form%' => $object['title']));
}
$event->addEvents($results);
}
示例9: convertToDatabaseValue
/**
* @param \DateTime $value
* @param AbstractPlatform $platform
*
* @return string|null
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
}
if (!self::$utc) {
self::$utc = new \DateTimeZone('UTC');
}
if (!is_object($value)) {
$dateHelper = new DateTimeHelper($value);
$value = $dateHelper->getDateTime();
}
$tz = $value->getTimeZone();
$utcDatetime = new \DateTime($value->format($platform->getDateTimeFormatString()), $tz);
$utcDatetime->setTimezone(self::$utc);
return $utcDatetime->format($platform->getDateTimeFormatString());
}
示例10: reverseTransform
/**
* Form format to database format
*
* @param mixed $rawFilters
*
* @return array|mixed
*/
public function reverseTransform($rawFilters)
{
if (!is_array($rawFilters)) {
return array();
}
$rawFilters = array_values($rawFilters);
foreach ($rawFilters as $k => $f) {
if ($f['type'] == 'datetime') {
if (in_array($f['filter'], $this->relativeDateStrings)) {
continue;
}
$dt = new DateTimeHelper($f['filter'], 'Y-m-d H:i', 'local');
$rawFilters[$k]['filter'] = $dt->toUtcString();
}
}
return $rawFilters;
}
示例11: getSentCounts
/**
* Get sent counts based grouped by dynamic content Id.
*
* @param array $dynamicContentIds
* @param \DateTime $fromDate
*
* @return array
*/
public function getSentCounts($dynamicContentIds = [], \DateTime $fromDate = null)
{
$q = $this->_em->getConnection()->createQueryBuilder();
$q->select('s.dynamic_content_id, count(s.id) as sent_count')->from(MAUTIC_TABLE_PREFIX . 'dynamic_content_stats', 's')->andWhere($q->expr()->in('e.dynamic_content_id', $dynamicContentIds));
if ($fromDate !== null) {
//make sure the date is UTC
$dt = new DateTimeHelper($fromDate);
$q->andWhere($q->expr()->gte('e.date_sent', $q->expr()->literal($dt->toUtcString())));
}
$q->groupBy('e.dynamic_content_id');
//get a total number of sent emails first
$results = $q->execute()->fetchAll();
$counts = [];
foreach ($results as $r) {
$counts[$r['dynamic_content_id']] = $r['sent_count'];
}
return $counts;
}
示例12: reverseTransform
/**
* {@inheritdoc}
*
* @return array
*/
public function reverseTransform($filters)
{
if (!is_array($filters)) {
return [];
}
foreach ($filters as &$f) {
if (!isset($this->columns[$f['column']])) {
// Likely being called by form.pre_set_data after post
return $filters;
}
$type = $this->columns[$f['column']]['type'];
if (in_array($type, ['datetime', 'date', 'time'])) {
$dt = new DateTimeHelper($f['value'], '', 'local');
$f['value'] = $dt->toUtcString();
}
}
return $filters;
}
示例13: onCalendarGenerate
/**
* Adds events to the calendar
*
* @param CalendarGeneratorEvent $event
*
* @return void
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$router = $this->factory->getRouter();
$query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
$query->select('es.email_id, e.subject AS title, COUNT(es.id) AS quantity, es.date_sent AS start, e.plain_text AS description, cat.color')->from(MAUTIC_TABLE_PREFIX . 'email_stats', 'es')->leftJoin('es', MAUTIC_TABLE_PREFIX . 'emails', 'e', 'es.email_id = e.id')->leftJoin('e', MAUTIC_TABLE_PREFIX . 'categories', 'cat', 'cat.id = e.category_id AND cat.bundle="email"')->where($query->expr()->andX($query->expr()->gte('es.date_sent', ':start'), $query->expr()->lte('es.date_sent', ':end')))->groupBy('e.id, es.email_id, e.subject, es.date_sent, e.plain_text, cat.color')->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(15);
$results = $query->execute()->fetchAll();
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
$date = new DateTimeHelper($object['start']);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
$object['url'] = $router->generate('mautic_email_action', array('objectAction' => 'view', 'objectId' => $object['email_id']), true);
$object['attr'] = 'data-toggle="ajax"';
$object['description'] = html_entity_decode($object['description']);
$object['title'] = $this->translator->trans('mautic.email.event.sent', array('%email%' => $object['title'], '%x%' => $object['quantity']));
}
$event->addEvents($results);
}
示例14: onCalendarGenerate
/**
* Adds events to the calendar
*
* @param CalendarGeneratorEvent $event
*
* @return void
*/
public function onCalendarGenerate(CalendarGeneratorEvent $event)
{
$dates = $event->getDates();
$router = $this->factory->getRouter();
// Lead Notes
$query = $this->factory->getEntityManager()->getConnection()->createQueryBuilder();
$query->select('ln.lead_id, l.firstname, l.lastname, ln.date_time AS start, ln.text AS description, ln.type')->from(MAUTIC_TABLE_PREFIX . 'lead_notes', 'ln')->leftJoin('ln', MAUTIC_TABLE_PREFIX . 'leads', 'l', 'ln.lead_id = l.id')->where($query->expr()->andX($query->expr()->gte('ln.date_time', ':start'), $query->expr()->lte('ln.date_time', ':end')))->setParameter('start', $dates['start_date'])->setParameter('end', $dates['end_date'])->setFirstResult(0)->setMaxResults(100);
$results = $query->execute()->fetchAll();
// We need to convert the date to a ISO8601 compliant string
foreach ($results as &$object) {
if ($object['firstname'] || $object['lastname']) {
$leadName = $object['firstname'] . ' ' . $object['lastname'];
} else {
$leadName = $this->translator->trans('mautic.lead.lead.anonymous');
}
$date = new DateTimeHelper($object['start']);
$object['start'] = $date->toLocalString(\DateTime::ISO8601);
$object['url'] = $router->generate('mautic_contact_action', array('objectAction' => 'view', 'objectId' => $object['lead_id']), true);
$object['attr'] = 'data-toggle="ajax"';
$object['description'] = strip_tags(html_entity_decode($object['description']));
switch ($object['type']) {
default:
case 'general':
$icon = 'fa-file-text';
break;
case 'email':
$icon = 'fa-send';
break;
case 'call':
$icon = 'fa-phone';
break;
case 'meeting':
$icon = 'fa-group';
break;
}
$object['iconClass'] = 'fa fa-fw ' . $icon;
$object['title'] = $leadName;
//$object['title'] .= ' (' . $this->translator->trans('mautic.lead.note.type.' . $object['type']) . ')';
}
$event->addEvents($results);
}
示例15: getDeviceStats
/**
* @param $emailIds
* @param \DateTime $fromDate
*
* @return array
*/
public function getDeviceStats($emailIds, \DateTime $fromDate = null, \DateTime $toDate = null)
{
$qb = $this->getEntityManager()->getConnection()->createQueryBuilder();
$qb->select('count(es.id) as count, d.device as device, es.list_id')->from(MAUTIC_TABLE_PREFIX . 'email_stats_devices', 'ed')->join('ed', MAUTIC_TABLE_PREFIX . 'lead_devices', 'd', 'd.id = ed.device_id')->join('ed', MAUTIC_TABLE_PREFIX . 'email_stats', 'es', 'es.id = ed.stat_id');
if ($emailIds != null) {
if (!is_array($emailIds)) {
$emailIds = [(int) $emailIds];
}
$qb->where($qb->expr()->in('es.email_id', $emailIds));
}
$qb->groupBy('es.list_id, d.device');
if ($fromDate !== null) {
//make sure the date is UTC
$dt = new DateTimeHelper($fromDate);
$qb->andWhere($qb->expr()->gte('es.date_read', $qb->expr()->literal($dt->toUtcString())));
}
if ($toDate !== null) {
//make sure the date is UTC
$dt = new DateTimeHelper($toDate);
$qb->andWhere($qb->expr()->lte('es.date_read', $qb->expr()->literal($dt->toUtcString())));
}
return $qb->execute()->fetchAll();
}