repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.evaluateDay | public function evaluateDay($returnHours = false, $date = null)
{
$hours = $this->getScheduleHours();
if (!$date) {
$date = clone $this->now;
}
if ($hours) {
$day = intval($date->format('N')) - 1;
if (isset($hours[$day])) {
if (
isset($hours[$day]->isActive)
&& !$hours[$day]->isActive
) {
throw new ContactClientException(
'This contact client does not allow contacts on a '.$date->format('l').'.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
} elseif ($returnHours) {
return $hours[$day];
}
}
}
return $this;
} | php | public function evaluateDay($returnHours = false, $date = null)
{
$hours = $this->getScheduleHours();
if (!$date) {
$date = clone $this->now;
}
if ($hours) {
$day = intval($date->format('N')) - 1;
if (isset($hours[$day])) {
if (
isset($hours[$day]->isActive)
&& !$hours[$day]->isActive
) {
throw new ContactClientException(
'This contact client does not allow contacts on a '.$date->format('l').'.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
} elseif ($returnHours) {
return $hours[$day];
}
}
}
return $this;
} | [
"public",
"function",
"evaluateDay",
"(",
"$",
"returnHours",
"=",
"false",
",",
"$",
"date",
"=",
"null",
")",
"{",
"$",
"hours",
"=",
"$",
"this",
"->",
"getScheduleHours",
"(",
")",
";",
"if",
"(",
"!",
"$",
"date",
")",
"{",
"$",
"date",
"=",
"clone",
"$",
"this",
"->",
"now",
";",
"}",
"if",
"(",
"$",
"hours",
")",
"{",
"$",
"day",
"=",
"intval",
"(",
"$",
"date",
"->",
"format",
"(",
"'N'",
")",
")",
"-",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"isActive",
")",
"&&",
"!",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"isActive",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'This contact client does not allow contacts on a '",
".",
"$",
"date",
"->",
"format",
"(",
"'l'",
")",
".",
"'.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"elseif",
"(",
"$",
"returnHours",
")",
"{",
"return",
"$",
"hours",
"[",
"$",
"day",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | \
@param bool $returnHours
@param null|\DateTime $date
@return $this|mixed
@throws ContactClientException | [
"\\",
"@param",
"bool",
"$returnHours",
"@param",
"null|",
"\\",
"DateTime",
"$date"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L202-L230 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.getScheduleHours | private function getScheduleHours()
{
if (!$this->scheduleHours) {
$jsonHelper = new JSONHelper();
$hoursString = $this->contactClient->getScheduleHours();
$this->scheduleHours = $jsonHelper->decodeArray($hoursString, 'ScheduleHours');
}
return $this->scheduleHours;
} | php | private function getScheduleHours()
{
if (!$this->scheduleHours) {
$jsonHelper = new JSONHelper();
$hoursString = $this->contactClient->getScheduleHours();
$this->scheduleHours = $jsonHelper->decodeArray($hoursString, 'ScheduleHours');
}
return $this->scheduleHours;
} | [
"private",
"function",
"getScheduleHours",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scheduleHours",
")",
"{",
"$",
"jsonHelper",
"=",
"new",
"JSONHelper",
"(",
")",
";",
"$",
"hoursString",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getScheduleHours",
"(",
")",
";",
"$",
"this",
"->",
"scheduleHours",
"=",
"$",
"jsonHelper",
"->",
"decodeArray",
"(",
"$",
"hoursString",
",",
"'ScheduleHours'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"scheduleHours",
";",
"}"
] | @return array|mixed
@throws \Exception | [
"@return",
"array|mixed"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L237-L246 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.evaluateExclusions | public function evaluateExclusions($date = null)
{
if (!$date) {
$date = clone $this->now;
}
// Check dates of exclusion (if there are any).
$jsonHelper = new JSONHelper();
$exclusionsString = $this->contactClient->getScheduleExclusions();
$exclusions = $jsonHelper->decodeArray($exclusionsString, 'ScheduleExclusions');
if ($exclusions) {
// Fastest way to compare dates is by string.
$todaysDateString = $date->format('Y-m-d');
foreach ($exclusions as $exclusion) {
if (!empty($exclusion->value)) {
$dateString = trim(str_ireplace('yyyy-', '', $exclusion->value));
$segments = explode('-', $dateString);
$segmentCount = count($segments);
if (3 == $segmentCount) {
$year = !empty($segments[0]) ? str_pad(
$segments[0],
4,
'0',
STR_PAD_LEFT
) : $date->format(
'Y'
);
$month = !empty($segments[1]) ? str_pad(
$segments[1],
2,
'0',
STR_PAD_LEFT
) : $date->format('m');
$day = !empty($segments[2]) ? str_pad(
$segments[2],
2,
'0',
STR_PAD_LEFT
) : $date->format('d');
} elseif (2 == $segmentCount) {
$year = $date->format('Y');
$month = !empty($segments[0]) ? str_pad(
$segments[0],
2,
'0',
STR_PAD_LEFT
) : $date->format('m');
$day = !empty($segments[1]) ? str_pad(
$segments[1],
2,
'0',
STR_PAD_LEFT
) : $date->format('d');
} else {
continue;
}
$dateString = $year.'-'.$month.'-'.$day;
if ($dateString == $todaysDateString) {
throw new ContactClientException(
'This contact client does not allow contacts on the date '.$dateString.'.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
}
}
}
return $this;
} | php | public function evaluateExclusions($date = null)
{
if (!$date) {
$date = clone $this->now;
}
// Check dates of exclusion (if there are any).
$jsonHelper = new JSONHelper();
$exclusionsString = $this->contactClient->getScheduleExclusions();
$exclusions = $jsonHelper->decodeArray($exclusionsString, 'ScheduleExclusions');
if ($exclusions) {
// Fastest way to compare dates is by string.
$todaysDateString = $date->format('Y-m-d');
foreach ($exclusions as $exclusion) {
if (!empty($exclusion->value)) {
$dateString = trim(str_ireplace('yyyy-', '', $exclusion->value));
$segments = explode('-', $dateString);
$segmentCount = count($segments);
if (3 == $segmentCount) {
$year = !empty($segments[0]) ? str_pad(
$segments[0],
4,
'0',
STR_PAD_LEFT
) : $date->format(
'Y'
);
$month = !empty($segments[1]) ? str_pad(
$segments[1],
2,
'0',
STR_PAD_LEFT
) : $date->format('m');
$day = !empty($segments[2]) ? str_pad(
$segments[2],
2,
'0',
STR_PAD_LEFT
) : $date->format('d');
} elseif (2 == $segmentCount) {
$year = $date->format('Y');
$month = !empty($segments[0]) ? str_pad(
$segments[0],
2,
'0',
STR_PAD_LEFT
) : $date->format('m');
$day = !empty($segments[1]) ? str_pad(
$segments[1],
2,
'0',
STR_PAD_LEFT
) : $date->format('d');
} else {
continue;
}
$dateString = $year.'-'.$month.'-'.$day;
if ($dateString == $todaysDateString) {
throw new ContactClientException(
'This contact client does not allow contacts on the date '.$dateString.'.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
}
}
}
return $this;
} | [
"public",
"function",
"evaluateExclusions",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"date",
")",
"{",
"$",
"date",
"=",
"clone",
"$",
"this",
"->",
"now",
";",
"}",
"// Check dates of exclusion (if there are any).",
"$",
"jsonHelper",
"=",
"new",
"JSONHelper",
"(",
")",
";",
"$",
"exclusionsString",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getScheduleExclusions",
"(",
")",
";",
"$",
"exclusions",
"=",
"$",
"jsonHelper",
"->",
"decodeArray",
"(",
"$",
"exclusionsString",
",",
"'ScheduleExclusions'",
")",
";",
"if",
"(",
"$",
"exclusions",
")",
"{",
"// Fastest way to compare dates is by string.",
"$",
"todaysDateString",
"=",
"$",
"date",
"->",
"format",
"(",
"'Y-m-d'",
")",
";",
"foreach",
"(",
"$",
"exclusions",
"as",
"$",
"exclusion",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"exclusion",
"->",
"value",
")",
")",
"{",
"$",
"dateString",
"=",
"trim",
"(",
"str_ireplace",
"(",
"'yyyy-'",
",",
"''",
",",
"$",
"exclusion",
"->",
"value",
")",
")",
";",
"$",
"segments",
"=",
"explode",
"(",
"'-'",
",",
"$",
"dateString",
")",
";",
"$",
"segmentCount",
"=",
"count",
"(",
"$",
"segments",
")",
";",
"if",
"(",
"3",
"==",
"$",
"segmentCount",
")",
"{",
"$",
"year",
"=",
"!",
"empty",
"(",
"$",
"segments",
"[",
"0",
"]",
")",
"?",
"str_pad",
"(",
"$",
"segments",
"[",
"0",
"]",
",",
"4",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
":",
"$",
"date",
"->",
"format",
"(",
"'Y'",
")",
";",
"$",
"month",
"=",
"!",
"empty",
"(",
"$",
"segments",
"[",
"1",
"]",
")",
"?",
"str_pad",
"(",
"$",
"segments",
"[",
"1",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
":",
"$",
"date",
"->",
"format",
"(",
"'m'",
")",
";",
"$",
"day",
"=",
"!",
"empty",
"(",
"$",
"segments",
"[",
"2",
"]",
")",
"?",
"str_pad",
"(",
"$",
"segments",
"[",
"2",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
":",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
";",
"}",
"elseif",
"(",
"2",
"==",
"$",
"segmentCount",
")",
"{",
"$",
"year",
"=",
"$",
"date",
"->",
"format",
"(",
"'Y'",
")",
";",
"$",
"month",
"=",
"!",
"empty",
"(",
"$",
"segments",
"[",
"0",
"]",
")",
"?",
"str_pad",
"(",
"$",
"segments",
"[",
"0",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
":",
"$",
"date",
"->",
"format",
"(",
"'m'",
")",
";",
"$",
"day",
"=",
"!",
"empty",
"(",
"$",
"segments",
"[",
"1",
"]",
")",
"?",
"str_pad",
"(",
"$",
"segments",
"[",
"1",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
":",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"$",
"dateString",
"=",
"$",
"year",
".",
"'-'",
".",
"$",
"month",
".",
"'-'",
".",
"$",
"day",
";",
"if",
"(",
"$",
"dateString",
"==",
"$",
"todaysDateString",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'This contact client does not allow contacts on the date '",
".",
"$",
"dateString",
".",
"'.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | @param null|\DateTime $date
@return $this
@throws ContactClientException | [
"@param",
"null|",
"\\",
"DateTime",
"$date"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L255-L325 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.evaluateFileRate | private function evaluateFileRate($fileRate = 1, $date = null)
{
if (!$date) {
$date = clone $this->now;
}
$date->setTimezone($this->timezone);
$repo = $this->getFileRepository();
$fileCount = $repo->getCountByDate($date, $this->contactClient->getId());
if ($fileCount >= $fileRate) {
throw new ContactClientException(
'This client has reached the maximum number of files they can receive per day.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
return $fileCount;
} | php | private function evaluateFileRate($fileRate = 1, $date = null)
{
if (!$date) {
$date = clone $this->now;
}
$date->setTimezone($this->timezone);
$repo = $this->getFileRepository();
$fileCount = $repo->getCountByDate($date, $this->contactClient->getId());
if ($fileCount >= $fileRate) {
throw new ContactClientException(
'This client has reached the maximum number of files they can receive per day.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
return $fileCount;
} | [
"private",
"function",
"evaluateFileRate",
"(",
"$",
"fileRate",
"=",
"1",
",",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"date",
")",
"{",
"$",
"date",
"=",
"clone",
"$",
"this",
"->",
"now",
";",
"}",
"$",
"date",
"->",
"setTimezone",
"(",
"$",
"this",
"->",
"timezone",
")",
";",
"$",
"repo",
"=",
"$",
"this",
"->",
"getFileRepository",
"(",
")",
";",
"$",
"fileCount",
"=",
"$",
"repo",
"->",
"getCountByDate",
"(",
"$",
"date",
",",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"$",
"fileCount",
">=",
"$",
"fileRate",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'This client has reached the maximum number of files they can receive per day.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"return",
"$",
"fileCount",
";",
"}"
] | Test if we can send/build another file for the day in question.
@param int $fileRate
@param null|\DateTime $date
@return int
@throws ContactClientException | [
"Test",
"if",
"we",
"can",
"send",
"/",
"build",
"another",
"file",
"for",
"the",
"day",
"in",
"question",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L337-L357 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.evaluateTime | public function evaluateTime($returnRange = false)
{
$hours = $this->getScheduleHours();
if ($hours) {
$day = intval($this->now->format('N')) - 1;
if (isset($hours[$day])) {
if (
isset($hours[$day]->isActive)
&& !$hours[$day]->isActive
) {
// No need to trigger an exception because we are only evaluating the time.
} else {
$timeFrom = !empty($hours[$day]->timeFrom) ? $hours[$day]->timeFrom : '00:00';
$timeTill = !empty($hours[$day]->timeTill) ? $hours[$day]->timeTill : '23:59';
$startDate = \DateTime::createFromFormat('H:i', $timeFrom, $this->timezone);
$endDate = \DateTime::createFromFormat('H:i', $timeTill, $this->timezone);
if (
!($this->now > $startDate && $this->now < $endDate)
&& !('00:00' == $timeFrom && '23:59' == $timeTill)
) {
throw new ContactClientException(
'This contact client does not allow contacts during this time of day.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
if ($returnRange) {
return [$startDate, $endDate];
}
}
}
}
return $this;
} | php | public function evaluateTime($returnRange = false)
{
$hours = $this->getScheduleHours();
if ($hours) {
$day = intval($this->now->format('N')) - 1;
if (isset($hours[$day])) {
if (
isset($hours[$day]->isActive)
&& !$hours[$day]->isActive
) {
// No need to trigger an exception because we are only evaluating the time.
} else {
$timeFrom = !empty($hours[$day]->timeFrom) ? $hours[$day]->timeFrom : '00:00';
$timeTill = !empty($hours[$day]->timeTill) ? $hours[$day]->timeTill : '23:59';
$startDate = \DateTime::createFromFormat('H:i', $timeFrom, $this->timezone);
$endDate = \DateTime::createFromFormat('H:i', $timeTill, $this->timezone);
if (
!($this->now > $startDate && $this->now < $endDate)
&& !('00:00' == $timeFrom && '23:59' == $timeTill)
) {
throw new ContactClientException(
'This contact client does not allow contacts during this time of day.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
if ($returnRange) {
return [$startDate, $endDate];
}
}
}
}
return $this;
} | [
"public",
"function",
"evaluateTime",
"(",
"$",
"returnRange",
"=",
"false",
")",
"{",
"$",
"hours",
"=",
"$",
"this",
"->",
"getScheduleHours",
"(",
")",
";",
"if",
"(",
"$",
"hours",
")",
"{",
"$",
"day",
"=",
"intval",
"(",
"$",
"this",
"->",
"now",
"->",
"format",
"(",
"'N'",
")",
")",
"-",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"isActive",
")",
"&&",
"!",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"isActive",
")",
"{",
"// No need to trigger an exception because we are only evaluating the time.",
"}",
"else",
"{",
"$",
"timeFrom",
"=",
"!",
"empty",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"timeFrom",
")",
"?",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"timeFrom",
":",
"'00:00'",
";",
"$",
"timeTill",
"=",
"!",
"empty",
"(",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"timeTill",
")",
"?",
"$",
"hours",
"[",
"$",
"day",
"]",
"->",
"timeTill",
":",
"'23:59'",
";",
"$",
"startDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'H:i'",
",",
"$",
"timeFrom",
",",
"$",
"this",
"->",
"timezone",
")",
";",
"$",
"endDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'H:i'",
",",
"$",
"timeTill",
",",
"$",
"this",
"->",
"timezone",
")",
";",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"now",
">",
"$",
"startDate",
"&&",
"$",
"this",
"->",
"now",
"<",
"$",
"endDate",
")",
"&&",
"!",
"(",
"'00:00'",
"==",
"$",
"timeFrom",
"&&",
"'23:59'",
"==",
"$",
"timeTill",
")",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'This contact client does not allow contacts during this time of day.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"if",
"(",
"$",
"returnRange",
")",
"{",
"return",
"[",
"$",
"startDate",
",",
"$",
"endDate",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | @param bool $returnRange
@return $this|array
@throws ContactClientException | [
"@param",
"bool",
"$returnRange"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L374-L410 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.setNow | public function setNow(\DateTime $now = null)
{
if (!$now) {
$now = new \DateTime();
}
$this->now = $now;
return $this;
} | php | public function setNow(\DateTime $now = null)
{
if (!$now) {
$now = new \DateTime();
}
$this->now = $now;
return $this;
} | [
"public",
"function",
"setNow",
"(",
"\\",
"DateTime",
"$",
"now",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"now",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"$",
"this",
"->",
"now",
"=",
"$",
"now",
";",
"return",
"$",
"this",
";",
"}"
] | @param \DateTime|null $now
@return $this
@throws \Exception | [
"@param",
"\\",
"DateTime|null",
"$now"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L427-L436 |
TheDMSGroup/mautic-contact-client | Model/Schedule.php | Schedule.setTimezone | public function setTimezone(\DateTimeZone $timezone = null)
{
if (!$timezone) {
$timezone = $this->contactClient->getScheduleTimezone();
if (!$timezone) {
$timezone = $this->coreParametersHelper->getParameter(
'default_timezone'
);
$timezone = !empty($timezone) ? $timezone : date_default_timezone_get();
}
$timezone = new \DateTimeZone($timezone);
}
$this->timezone = $timezone;
$this->now->setTimezone($timezone);
return $this;
} | php | public function setTimezone(\DateTimeZone $timezone = null)
{
if (!$timezone) {
$timezone = $this->contactClient->getScheduleTimezone();
if (!$timezone) {
$timezone = $this->coreParametersHelper->getParameter(
'default_timezone'
);
$timezone = !empty($timezone) ? $timezone : date_default_timezone_get();
}
$timezone = new \DateTimeZone($timezone);
}
$this->timezone = $timezone;
$this->now->setTimezone($timezone);
return $this;
} | [
"public",
"function",
"setTimezone",
"(",
"\\",
"DateTimeZone",
"$",
"timezone",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"timezone",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getScheduleTimezone",
"(",
")",
";",
"if",
"(",
"!",
"$",
"timezone",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"coreParametersHelper",
"->",
"getParameter",
"(",
"'default_timezone'",
")",
";",
"$",
"timezone",
"=",
"!",
"empty",
"(",
"$",
"timezone",
")",
"?",
"$",
"timezone",
":",
"date_default_timezone_get",
"(",
")",
";",
"}",
"$",
"timezone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"}",
"$",
"this",
"->",
"timezone",
"=",
"$",
"timezone",
";",
"$",
"this",
"->",
"now",
"->",
"setTimezone",
"(",
"$",
"timezone",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set Client timezone, defaulting to Mautic or System as is relevant.
@param \DateTimeZone $timezone
@return $this | [
"Set",
"Client",
"timezone",
"defaulting",
"to",
"Mautic",
"or",
"System",
"as",
"is",
"relevant",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Schedule.php#L453-L469 |
TheDMSGroup/mautic-contact-client | Entity/Queue.php | Queue.setCampaignEvent | public function setCampaignEvent($campaignEvent)
{
if ($campaignEvent instanceof CampaignEvent) {
$campaignEvent = $campaignEvent->getId();
}
$this->campaignEvent = $campaignEvent;
return $this;
} | php | public function setCampaignEvent($campaignEvent)
{
if ($campaignEvent instanceof CampaignEvent) {
$campaignEvent = $campaignEvent->getId();
}
$this->campaignEvent = $campaignEvent;
return $this;
} | [
"public",
"function",
"setCampaignEvent",
"(",
"$",
"campaignEvent",
")",
"{",
"if",
"(",
"$",
"campaignEvent",
"instanceof",
"CampaignEvent",
")",
"{",
"$",
"campaignEvent",
"=",
"$",
"campaignEvent",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"campaignEvent",
"=",
"$",
"campaignEvent",
";",
"return",
"$",
"this",
";",
"}"
] | @param $campaignEvent
@return $this | [
"@param",
"$campaignEvent"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/Queue.php#L114-L122 |
TheDMSGroup/mautic-contact-client | Entity/Queue.php | Queue.setCampaign | public function setCampaign($campaign)
{
if ($campaign instanceof Campaign) {
$campaign = $campaign->getId();
}
$this->campaign = $campaign;
return $this;
} | php | public function setCampaign($campaign)
{
if ($campaign instanceof Campaign) {
$campaign = $campaign->getId();
}
$this->campaign = $campaign;
return $this;
} | [
"public",
"function",
"setCampaign",
"(",
"$",
"campaign",
")",
"{",
"if",
"(",
"$",
"campaign",
"instanceof",
"Campaign",
")",
"{",
"$",
"campaign",
"=",
"$",
"campaign",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"campaign",
"=",
"$",
"campaign",
";",
"return",
"$",
"this",
";",
"}"
] | @param $campaign
@return $this | [
"@param",
"$campaign"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/Queue.php#L137-L145 |
TheDMSGroup/mautic-contact-client | Entity/Queue.php | Queue.setContact | public function setContact($contact)
{
if ($contact instanceof Contact) {
$contact = $contact->getId();
}
$this->contact = $contact;
return $this;
} | php | public function setContact($contact)
{
if ($contact instanceof Contact) {
$contact = $contact->getId();
}
$this->contact = $contact;
return $this;
} | [
"public",
"function",
"setContact",
"(",
"$",
"contact",
")",
"{",
"if",
"(",
"$",
"contact",
"instanceof",
"Contact",
")",
"{",
"$",
"contact",
"=",
"$",
"contact",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"this",
"->",
"contact",
"=",
"$",
"contact",
";",
"return",
"$",
"this",
";",
"}"
] | @param Contact|int $contact
@return $this | [
"@param",
"Contact|int",
"$contact"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/Queue.php#L208-L217 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.create | public function create()
{
$entities = [];
$exclusive = $this->getExclusiveRules();
if (count($exclusive)) {
// Create an entry for *each* exclusivity rule as they will end up with different dates of exclusivity
// expiration. Any of these entries will suffice for duplicate checking and limit checking.
foreach ($exclusive as $rule) {
if (!isset($entity)) {
$entity = $this->createEntity();
} else {
// No need to re-run all the getters and setters.
$entity = clone $entity;
}
// Each entry may have different exclusion expiration.
$expireDate = $this->getRepository()->oldestDateAdded(
$rule['duration'],
$this->getTimezone(),
$this->dateSend
);
$entity->setExclusiveExpireDate($expireDate);
$entity->setExclusivePattern($rule['matching']);
$entity->setExclusiveScope($rule['scope']);
$entities[] = $entity;
}
} else {
// A single entry will suffice for all duplicate checking and limit checking.
$entities[] = $this->createEntity();
}
if (count($entities)) {
$this->getRepository()->saveEntities($entities);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Cache');
}
} | php | public function create()
{
$entities = [];
$exclusive = $this->getExclusiveRules();
if (count($exclusive)) {
// Create an entry for *each* exclusivity rule as they will end up with different dates of exclusivity
// expiration. Any of these entries will suffice for duplicate checking and limit checking.
foreach ($exclusive as $rule) {
if (!isset($entity)) {
$entity = $this->createEntity();
} else {
// No need to re-run all the getters and setters.
$entity = clone $entity;
}
// Each entry may have different exclusion expiration.
$expireDate = $this->getRepository()->oldestDateAdded(
$rule['duration'],
$this->getTimezone(),
$this->dateSend
);
$entity->setExclusiveExpireDate($expireDate);
$entity->setExclusivePattern($rule['matching']);
$entity->setExclusiveScope($rule['scope']);
$entities[] = $entity;
}
} else {
// A single entry will suffice for all duplicate checking and limit checking.
$entities[] = $this->createEntity();
}
if (count($entities)) {
$this->getRepository()->saveEntities($entities);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Cache');
}
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"entities",
"=",
"[",
"]",
";",
"$",
"exclusive",
"=",
"$",
"this",
"->",
"getExclusiveRules",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"exclusive",
")",
")",
"{",
"// Create an entry for *each* exclusivity rule as they will end up with different dates of exclusivity",
"// expiration. Any of these entries will suffice for duplicate checking and limit checking.",
"foreach",
"(",
"$",
"exclusive",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"createEntity",
"(",
")",
";",
"}",
"else",
"{",
"// No need to re-run all the getters and setters.",
"$",
"entity",
"=",
"clone",
"$",
"entity",
";",
"}",
"// Each entry may have different exclusion expiration.",
"$",
"expireDate",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"oldestDateAdded",
"(",
"$",
"rule",
"[",
"'duration'",
"]",
",",
"$",
"this",
"->",
"getTimezone",
"(",
")",
",",
"$",
"this",
"->",
"dateSend",
")",
";",
"$",
"entity",
"->",
"setExclusiveExpireDate",
"(",
"$",
"expireDate",
")",
";",
"$",
"entity",
"->",
"setExclusivePattern",
"(",
"$",
"rule",
"[",
"'matching'",
"]",
")",
";",
"$",
"entity",
"->",
"setExclusiveScope",
"(",
"$",
"rule",
"[",
"'scope'",
"]",
")",
";",
"$",
"entities",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"else",
"{",
"// A single entry will suffice for all duplicate checking and limit checking.",
"$",
"entities",
"[",
"]",
"=",
"$",
"this",
"->",
"createEntity",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"entities",
")",
")",
"{",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"saveEntities",
"(",
"$",
"entities",
")",
";",
"$",
"this",
"->",
"em",
"->",
"clear",
"(",
"'MauticPlugin\\MauticContactClientBundle\\Entity\\Cache'",
")",
";",
"}",
"}"
] | Create all necessary cache entities for the given Contact and Contact Client.
@throws \Exception | [
"Create",
"all",
"necessary",
"cache",
"entities",
"for",
"the",
"given",
"Contact",
"and",
"Contact",
"Client",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L56-L89 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.getExclusiveRules | public function getExclusiveRules()
{
$jsonHelper = new JSONHelper();
$exclusive = $jsonHelper->decodeObject($this->contactClient->getExclusive(), 'Exclusive');
$this->excludeIrrelevantRules($exclusive);
return $this->mergeRules($exclusive);
} | php | public function getExclusiveRules()
{
$jsonHelper = new JSONHelper();
$exclusive = $jsonHelper->decodeObject($this->contactClient->getExclusive(), 'Exclusive');
$this->excludeIrrelevantRules($exclusive);
return $this->mergeRules($exclusive);
} | [
"public",
"function",
"getExclusiveRules",
"(",
")",
"{",
"$",
"jsonHelper",
"=",
"new",
"JSONHelper",
"(",
")",
";",
"$",
"exclusive",
"=",
"$",
"jsonHelper",
"->",
"decodeObject",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getExclusive",
"(",
")",
",",
"'Exclusive'",
")",
";",
"$",
"this",
"->",
"excludeIrrelevantRules",
"(",
"$",
"exclusive",
")",
";",
"return",
"$",
"this",
"->",
"mergeRules",
"(",
"$",
"exclusive",
")",
";",
"}"
] | Given the Contact and Contact Client, discern which exclusivity entries need to be cached.
@throws \Exception | [
"Given",
"the",
"Contact",
"and",
"Contact",
"Client",
"discern",
"which",
"exclusivity",
"entries",
"need",
"to",
"be",
"cached",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L96-L104 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.getUtmSource | private function getUtmSource()
{
if (!$this->utmSource) {
$utmHelper = $this->getContainer()->get('mautic.contactclient.helper.utmsource');
$this->utmSource = $utmHelper->getFirstUtmSource($this->contact);
$this->em->clear('Mautic\LeadBundle\Entity\UtmTag');
}
return $this->utmSource;
} | php | private function getUtmSource()
{
if (!$this->utmSource) {
$utmHelper = $this->getContainer()->get('mautic.contactclient.helper.utmsource');
$this->utmSource = $utmHelper->getFirstUtmSource($this->contact);
$this->em->clear('Mautic\LeadBundle\Entity\UtmTag');
}
return $this->utmSource;
} | [
"private",
"function",
"getUtmSource",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"utmSource",
")",
"{",
"$",
"utmHelper",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.contactclient.helper.utmsource'",
")",
";",
"$",
"this",
"->",
"utmSource",
"=",
"$",
"utmHelper",
"->",
"getFirstUtmSource",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"em",
"->",
"clear",
"(",
"'Mautic\\LeadBundle\\Entity\\UtmTag'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"utmSource",
";",
"}"
] | Get the original / first utm source code for contact.
@return string
@throws \Exception | [
"Get",
"the",
"original",
"/",
"first",
"utm",
"source",
"code",
"for",
"contact",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L148-L157 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.mergeRules | private function mergeRules($rules, $requireMatching = true)
{
$newRules = [];
if (isset($rules->rules) && is_array($rules->rules)) {
foreach ($rules->rules as $rule) {
// Exclusivity and Duplicates have matching, Limits may not.
if (
(!$requireMatching || !empty($rule->matching))
&& !empty($rule->scope)
&& !empty($rule->duration)
) {
$duration = $rule->duration;
$scope = intval($rule->scope);
$value = isset($rule->value) ? strval($rule->value) : '';
$key = $duration.'-'.$scope.'-'.$value;
if (!isset($newRules[$key])) {
$newRules[$key] = [];
if (!empty($rule->matching)) {
$newRules[$key]['matching'] = intval($rule->matching);
}
$newRules[$key]['scope'] = $scope;
$newRules[$key]['duration'] = $duration;
$newRules[$key]['value'] = $value;
} elseif (!empty($rule->matching)) {
$newRules[$key]['matching'] += intval($rule->matching);
}
if (isset($rule->quantity)) {
if (!isset($newRules[$key]['quantity'])) {
$newRules[$key]['quantity'] = intval($rule->quantity);
} else {
$newRules[$key]['quantity'] = min($newRules[$key]['quantity'], intval($rule->quantity));
}
}
}
}
}
krsort($newRules);
return $newRules;
} | php | private function mergeRules($rules, $requireMatching = true)
{
$newRules = [];
if (isset($rules->rules) && is_array($rules->rules)) {
foreach ($rules->rules as $rule) {
// Exclusivity and Duplicates have matching, Limits may not.
if (
(!$requireMatching || !empty($rule->matching))
&& !empty($rule->scope)
&& !empty($rule->duration)
) {
$duration = $rule->duration;
$scope = intval($rule->scope);
$value = isset($rule->value) ? strval($rule->value) : '';
$key = $duration.'-'.$scope.'-'.$value;
if (!isset($newRules[$key])) {
$newRules[$key] = [];
if (!empty($rule->matching)) {
$newRules[$key]['matching'] = intval($rule->matching);
}
$newRules[$key]['scope'] = $scope;
$newRules[$key]['duration'] = $duration;
$newRules[$key]['value'] = $value;
} elseif (!empty($rule->matching)) {
$newRules[$key]['matching'] += intval($rule->matching);
}
if (isset($rule->quantity)) {
if (!isset($newRules[$key]['quantity'])) {
$newRules[$key]['quantity'] = intval($rule->quantity);
} else {
$newRules[$key]['quantity'] = min($newRules[$key]['quantity'], intval($rule->quantity));
}
}
}
}
}
krsort($newRules);
return $newRules;
} | [
"private",
"function",
"mergeRules",
"(",
"$",
"rules",
",",
"$",
"requireMatching",
"=",
"true",
")",
"{",
"$",
"newRules",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"rules",
"->",
"rules",
")",
"&&",
"is_array",
"(",
"$",
"rules",
"->",
"rules",
")",
")",
"{",
"foreach",
"(",
"$",
"rules",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"// Exclusivity and Duplicates have matching, Limits may not.",
"if",
"(",
"(",
"!",
"$",
"requireMatching",
"||",
"!",
"empty",
"(",
"$",
"rule",
"->",
"matching",
")",
")",
"&&",
"!",
"empty",
"(",
"$",
"rule",
"->",
"scope",
")",
"&&",
"!",
"empty",
"(",
"$",
"rule",
"->",
"duration",
")",
")",
"{",
"$",
"duration",
"=",
"$",
"rule",
"->",
"duration",
";",
"$",
"scope",
"=",
"intval",
"(",
"$",
"rule",
"->",
"scope",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"rule",
"->",
"value",
")",
"?",
"strval",
"(",
"$",
"rule",
"->",
"value",
")",
":",
"''",
";",
"$",
"key",
"=",
"$",
"duration",
".",
"'-'",
".",
"$",
"scope",
".",
"'-'",
".",
"$",
"value",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"newRules",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"newRules",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"rule",
"->",
"matching",
")",
")",
"{",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'matching'",
"]",
"=",
"intval",
"(",
"$",
"rule",
"->",
"matching",
")",
";",
"}",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'scope'",
"]",
"=",
"$",
"scope",
";",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'duration'",
"]",
"=",
"$",
"duration",
";",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"rule",
"->",
"matching",
")",
")",
"{",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'matching'",
"]",
"+=",
"intval",
"(",
"$",
"rule",
"->",
"matching",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"rule",
"->",
"quantity",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'quantity'",
"]",
")",
")",
"{",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'quantity'",
"]",
"=",
"intval",
"(",
"$",
"rule",
"->",
"quantity",
")",
";",
"}",
"else",
"{",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'quantity'",
"]",
"=",
"min",
"(",
"$",
"newRules",
"[",
"$",
"key",
"]",
"[",
"'quantity'",
"]",
",",
"intval",
"(",
"$",
"rule",
"->",
"quantity",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
"krsort",
"(",
"$",
"newRules",
")",
";",
"return",
"$",
"newRules",
";",
"}"
] | Validate and merge the rules object (exclusivity/duplicate/limits).
@param $rules
@param bool $requireMatching
@return array | [
"Validate",
"and",
"merge",
"the",
"rules",
"object",
"(",
"exclusivity",
"/",
"duplicate",
"/",
"limits",
")",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L179-L218 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.createEntity | private function createEntity()
{
$entity = new CacheEntity();
$entity->setAddress1(trim(ucwords($this->contact->getAddress1())));
$entity->setAddress2(trim(ucwords($this->contact->getAddress2())));
$category = $this->contactClient->getCategory();
if ($category) {
$entity->setCategory($category->getId());
}
$entity->setCity(trim(ucwords($this->contact->getCity())));
$entity->setContact($this->contact->getId());
$entity->setContactClient($this->contactClient->getId());
$entity->setState(trim(ucwords($this->contact->getStage())));
$entity->setCountry(trim(ucwords($this->contact->getCountry())));
$entity->setZipcode(trim($this->contact->getZipcode()));
$entity->setEmail(trim($this->contact->getEmail()));
$phone = $this->phoneValidate($this->contact->getPhone());
if (!empty($phone)) {
$entity->setPhone($phone);
}
$mobile = $this->phoneValidate($this->contact->getMobile());
if (!empty($mobile)) {
$entity->setMobile($mobile);
}
$utmSource = $this->getUtmSource();
if (!empty($utmSource)) {
$entity->setUtmSource($utmSource);
}
if ($this->dateSend) {
$entity->setDateAdded($this->dateSend);
}
return $entity;
} | php | private function createEntity()
{
$entity = new CacheEntity();
$entity->setAddress1(trim(ucwords($this->contact->getAddress1())));
$entity->setAddress2(trim(ucwords($this->contact->getAddress2())));
$category = $this->contactClient->getCategory();
if ($category) {
$entity->setCategory($category->getId());
}
$entity->setCity(trim(ucwords($this->contact->getCity())));
$entity->setContact($this->contact->getId());
$entity->setContactClient($this->contactClient->getId());
$entity->setState(trim(ucwords($this->contact->getStage())));
$entity->setCountry(trim(ucwords($this->contact->getCountry())));
$entity->setZipcode(trim($this->contact->getZipcode()));
$entity->setEmail(trim($this->contact->getEmail()));
$phone = $this->phoneValidate($this->contact->getPhone());
if (!empty($phone)) {
$entity->setPhone($phone);
}
$mobile = $this->phoneValidate($this->contact->getMobile());
if (!empty($mobile)) {
$entity->setMobile($mobile);
}
$utmSource = $this->getUtmSource();
if (!empty($utmSource)) {
$entity->setUtmSource($utmSource);
}
if ($this->dateSend) {
$entity->setDateAdded($this->dateSend);
}
return $entity;
} | [
"private",
"function",
"createEntity",
"(",
")",
"{",
"$",
"entity",
"=",
"new",
"CacheEntity",
"(",
")",
";",
"$",
"entity",
"->",
"setAddress1",
"(",
"trim",
"(",
"ucwords",
"(",
"$",
"this",
"->",
"contact",
"->",
"getAddress1",
"(",
")",
")",
")",
")",
";",
"$",
"entity",
"->",
"setAddress2",
"(",
"trim",
"(",
"ucwords",
"(",
"$",
"this",
"->",
"contact",
"->",
"getAddress2",
"(",
")",
")",
")",
")",
";",
"$",
"category",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getCategory",
"(",
")",
";",
"if",
"(",
"$",
"category",
")",
"{",
"$",
"entity",
"->",
"setCategory",
"(",
"$",
"category",
"->",
"getId",
"(",
")",
")",
";",
"}",
"$",
"entity",
"->",
"setCity",
"(",
"trim",
"(",
"ucwords",
"(",
"$",
"this",
"->",
"contact",
"->",
"getCity",
"(",
")",
")",
")",
")",
";",
"$",
"entity",
"->",
"setContact",
"(",
"$",
"this",
"->",
"contact",
"->",
"getId",
"(",
")",
")",
";",
"$",
"entity",
"->",
"setContactClient",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
")",
";",
"$",
"entity",
"->",
"setState",
"(",
"trim",
"(",
"ucwords",
"(",
"$",
"this",
"->",
"contact",
"->",
"getStage",
"(",
")",
")",
")",
")",
";",
"$",
"entity",
"->",
"setCountry",
"(",
"trim",
"(",
"ucwords",
"(",
"$",
"this",
"->",
"contact",
"->",
"getCountry",
"(",
")",
")",
")",
")",
";",
"$",
"entity",
"->",
"setZipcode",
"(",
"trim",
"(",
"$",
"this",
"->",
"contact",
"->",
"getZipcode",
"(",
")",
")",
")",
";",
"$",
"entity",
"->",
"setEmail",
"(",
"trim",
"(",
"$",
"this",
"->",
"contact",
"->",
"getEmail",
"(",
")",
")",
")",
";",
"$",
"phone",
"=",
"$",
"this",
"->",
"phoneValidate",
"(",
"$",
"this",
"->",
"contact",
"->",
"getPhone",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"phone",
")",
")",
"{",
"$",
"entity",
"->",
"setPhone",
"(",
"$",
"phone",
")",
";",
"}",
"$",
"mobile",
"=",
"$",
"this",
"->",
"phoneValidate",
"(",
"$",
"this",
"->",
"contact",
"->",
"getMobile",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"mobile",
")",
")",
"{",
"$",
"entity",
"->",
"setMobile",
"(",
"$",
"mobile",
")",
";",
"}",
"$",
"utmSource",
"=",
"$",
"this",
"->",
"getUtmSource",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"utmSource",
")",
")",
"{",
"$",
"entity",
"->",
"setUtmSource",
"(",
"$",
"utmSource",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dateSend",
")",
"{",
"$",
"entity",
"->",
"setDateAdded",
"(",
"$",
"this",
"->",
"dateSend",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Create a new cache entity with the existing Contact and contactClient.
Normalize the fields as much as possible to aid in exclusive/duplicate/limit correlation.
@return CacheEntity
@throws \Exception | [
"Create",
"a",
"new",
"cache",
"entity",
"with",
"the",
"existing",
"Contact",
"and",
"contactClient",
".",
"Normalize",
"the",
"fields",
"as",
"much",
"as",
"possible",
"to",
"aid",
"in",
"exclusive",
"/",
"duplicate",
"/",
"limit",
"correlation",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L228-L261 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.getTimezone | private function getTimezone()
{
if (!$this->timezone) {
$this->timezone = $this->getContainer()->get('mautic.helper.core_parameters')->getParameter(
'default_timezone'
);
}
return $this->timezone;
} | php | private function getTimezone()
{
if (!$this->timezone) {
$this->timezone = $this->getContainer()->get('mautic.helper.core_parameters')->getParameter(
'default_timezone'
);
}
return $this->timezone;
} | [
"private",
"function",
"getTimezone",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"timezone",
")",
"{",
"$",
"this",
"->",
"timezone",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.helper.core_parameters'",
")",
"->",
"getParameter",
"(",
"'default_timezone'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"timezone",
";",
"}"
] | Get the global timezone setting.
@return mixed
@throws \Exception | [
"Get",
"the",
"global",
"timezone",
"setting",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L303-L312 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.evaluateExclusive | public function evaluateExclusive()
{
if (!$this->contactClient->getExclusiveIgnore()) {
$exclusive = $this->getRepository()->findExclusive(
$this->contact,
$this->contactClient,
$this->dateSend
);
if ($exclusive) {
throw new ContactClientException(
'Skipping exclusive Contact.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_EXCLUSIVE,
false,
null,
$exclusive
);
}
}
} | php | public function evaluateExclusive()
{
if (!$this->contactClient->getExclusiveIgnore()) {
$exclusive = $this->getRepository()->findExclusive(
$this->contact,
$this->contactClient,
$this->dateSend
);
if ($exclusive) {
throw new ContactClientException(
'Skipping exclusive Contact.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_EXCLUSIVE,
false,
null,
$exclusive
);
}
}
} | [
"public",
"function",
"evaluateExclusive",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"contactClient",
"->",
"getExclusiveIgnore",
"(",
")",
")",
"{",
"$",
"exclusive",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findExclusive",
"(",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"dateSend",
")",
";",
"if",
"(",
"$",
"exclusive",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Skipping exclusive Contact.'",
",",
"Codes",
"::",
"HTTP_CONFLICT",
",",
"null",
",",
"Stat",
"::",
"TYPE_EXCLUSIVE",
",",
"false",
",",
"null",
",",
"$",
"exclusive",
")",
";",
"}",
"}",
"}"
] | Given a contact, evaluate exclusivity rules of all cache entries against it.
@throws ContactClientException
@throws \Exception | [
"Given",
"a",
"contact",
"evaluate",
"exclusivity",
"rules",
"of",
"all",
"cache",
"entries",
"against",
"it",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L320-L340 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.evaluateDuplicate | public function evaluateDuplicate()
{
$duplicate = $this->getRepository()->findDuplicate(
$this->contact,
$this->contactClient,
$this->getDuplicateRules(),
$this->getUtmSource(),
$this->getTimezone(),
$this->dateSend
);
if ($duplicate) {
throw new ContactClientException(
'Skipping duplicate Contact.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_DUPLICATE,
false,
null,
$duplicate
);
}
} | php | public function evaluateDuplicate()
{
$duplicate = $this->getRepository()->findDuplicate(
$this->contact,
$this->contactClient,
$this->getDuplicateRules(),
$this->getUtmSource(),
$this->getTimezone(),
$this->dateSend
);
if ($duplicate) {
throw new ContactClientException(
'Skipping duplicate Contact.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_DUPLICATE,
false,
null,
$duplicate
);
}
} | [
"public",
"function",
"evaluateDuplicate",
"(",
")",
"{",
"$",
"duplicate",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findDuplicate",
"(",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"getDuplicateRules",
"(",
")",
",",
"$",
"this",
"->",
"getUtmSource",
"(",
")",
",",
"$",
"this",
"->",
"getTimezone",
"(",
")",
",",
"$",
"this",
"->",
"dateSend",
")",
";",
"if",
"(",
"$",
"duplicate",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Skipping duplicate Contact.'",
",",
"Codes",
"::",
"HTTP_CONFLICT",
",",
"null",
",",
"Stat",
"::",
"TYPE_DUPLICATE",
",",
"false",
",",
"null",
",",
"$",
"duplicate",
")",
";",
"}",
"}"
] | Using the duplicate rules, evaluate if the current contact matches any entry in the cache.
@throws ContactClientException
@throws \Exception | [
"Using",
"the",
"duplicate",
"rules",
"evaluate",
"if",
"the",
"current",
"contact",
"matches",
"any",
"entry",
"in",
"the",
"cache",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L348-L369 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.evaluateLimits | public function evaluateLimits()
{
$limits = $this->getRepository()->findLimit(
$this->contactClient,
$this->getLimitRules(),
$this->getTimezone(),
$this->dateSend
);
if ($limits) {
throw new ContactClientException(
'Not able to send contact to client due to an exceeded budget.',
Codes::HTTP_TOO_MANY_REQUESTS,
null,
Stat::TYPE_LIMITS,
false,
null,
$limits
);
}
} | php | public function evaluateLimits()
{
$limits = $this->getRepository()->findLimit(
$this->contactClient,
$this->getLimitRules(),
$this->getTimezone(),
$this->dateSend
);
if ($limits) {
throw new ContactClientException(
'Not able to send contact to client due to an exceeded budget.',
Codes::HTTP_TOO_MANY_REQUESTS,
null,
Stat::TYPE_LIMITS,
false,
null,
$limits
);
}
} | [
"public",
"function",
"evaluateLimits",
"(",
")",
"{",
"$",
"limits",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findLimit",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"getLimitRules",
"(",
")",
",",
"$",
"this",
"->",
"getTimezone",
"(",
")",
",",
"$",
"this",
"->",
"dateSend",
")",
";",
"if",
"(",
"$",
"limits",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Not able to send contact to client due to an exceeded budget.'",
",",
"Codes",
"::",
"HTTP_TOO_MANY_REQUESTS",
",",
"null",
",",
"Stat",
"::",
"TYPE_LIMITS",
",",
"false",
",",
"null",
",",
"$",
"limits",
")",
";",
"}",
"}"
] | Using the duplicate rules, evaluate if the current contact matches any entry in the cache.
@throws ContactClientException
@throws \Exception | [
"Using",
"the",
"duplicate",
"rules",
"evaluate",
"if",
"the",
"current",
"contact",
"matches",
"any",
"entry",
"in",
"the",
"cache",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L390-L409 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.getLimitRules | public function getLimitRules()
{
$jsonHelper = new JSONHelper();
$limits = $jsonHelper->decodeObject($this->contactClient->getLimits(), 'Limits');
$this->excludeIrrelevantRules($limits);
return $this->mergeRules($limits, false);
} | php | public function getLimitRules()
{
$jsonHelper = new JSONHelper();
$limits = $jsonHelper->decodeObject($this->contactClient->getLimits(), 'Limits');
$this->excludeIrrelevantRules($limits);
return $this->mergeRules($limits, false);
} | [
"public",
"function",
"getLimitRules",
"(",
")",
"{",
"$",
"jsonHelper",
"=",
"new",
"JSONHelper",
"(",
")",
";",
"$",
"limits",
"=",
"$",
"jsonHelper",
"->",
"decodeObject",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getLimits",
"(",
")",
",",
"'Limits'",
")",
";",
"$",
"this",
"->",
"excludeIrrelevantRules",
"(",
"$",
"limits",
")",
";",
"return",
"$",
"this",
"->",
"mergeRules",
"(",
"$",
"limits",
",",
"false",
")",
";",
"}"
] | Given the Contact and Contact Client, get the rules used to evaluate limits.
@throws \Exception | [
"Given",
"the",
"Contact",
"and",
"Contact",
"Client",
"get",
"the",
"rules",
"used",
"to",
"evaluate",
"limits",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L416-L424 |
TheDMSGroup/mautic-contact-client | Model/Cache.php | Cache.setDateSend | public function setDateSend($dateSend = null)
{
if (!$dateSend) {
$this->dateSend = new \DateTime();
} else {
$this->dateSend = $dateSend;
}
return $this;
} | php | public function setDateSend($dateSend = null)
{
if (!$dateSend) {
$this->dateSend = new \DateTime();
} else {
$this->dateSend = $dateSend;
}
return $this;
} | [
"public",
"function",
"setDateSend",
"(",
"$",
"dateSend",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"dateSend",
")",
"{",
"$",
"this",
"->",
"dateSend",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dateSend",
"=",
"$",
"dateSend",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param $dateSend
@return $this | [
"@param",
"$dateSend"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/Cache.php#L451-L460 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setAttribution | public function setAttribution($attribution)
{
if ($this->queue) {
$this->queue->setAttribution($attribution);
$this->getQueueRepository()->saveEntity($this->queue);
}
} | php | public function setAttribution($attribution)
{
if ($this->queue) {
$this->queue->setAttribution($attribution);
$this->getQueueRepository()->saveEntity($this->queue);
}
} | [
"public",
"function",
"setAttribution",
"(",
"$",
"attribution",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"queue",
")",
"{",
"$",
"this",
"->",
"queue",
"->",
"setAttribution",
"(",
"$",
"attribution",
")",
";",
"$",
"this",
"->",
"getQueueRepository",
"(",
")",
"->",
"saveEntity",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"}",
"}"
] | Append the current queue entity with attribution.
@param $attribution | [
"Append",
"the",
"current",
"queue",
"entity",
"with",
"attribution",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L229-L235 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.reset | public function reset(
$exclusions = [
'contactClientModel',
'tokenHelper',
'em',
'formModel',
'eventModel',
'contactModel',
'pathsHelper',
'coreParametersHelper',
'filesystemLocal',
'mailHelper',
'scheduleModel',
'utmSourceHelper',
]
) {
foreach (array_diff_key(
get_class_vars(get_class($this)),
array_flip($exclusions)
) as $name => $default) {
$this->$name = $default;
}
return $this;
} | php | public function reset(
$exclusions = [
'contactClientModel',
'tokenHelper',
'em',
'formModel',
'eventModel',
'contactModel',
'pathsHelper',
'coreParametersHelper',
'filesystemLocal',
'mailHelper',
'scheduleModel',
'utmSourceHelper',
]
) {
foreach (array_diff_key(
get_class_vars(get_class($this)),
array_flip($exclusions)
) as $name => $default) {
$this->$name = $default;
}
return $this;
} | [
"public",
"function",
"reset",
"(",
"$",
"exclusions",
"=",
"[",
"'contactClientModel'",
",",
"'tokenHelper'",
",",
"'em'",
",",
"'formModel'",
",",
"'eventModel'",
",",
"'contactModel'",
",",
"'pathsHelper'",
",",
"'coreParametersHelper'",
",",
"'filesystemLocal'",
",",
"'mailHelper'",
",",
"'scheduleModel'",
",",
"'utmSourceHelper'",
",",
"]",
")",
"{",
"foreach",
"(",
"array_diff_key",
"(",
"get_class_vars",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
",",
"array_flip",
"(",
"$",
"exclusions",
")",
")",
"as",
"$",
"name",
"=>",
"$",
"default",
")",
"{",
"$",
"this",
"->",
"$",
"name",
"=",
"$",
"default",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Reset local class variables.
@param array $exclusions optional array of local variables to keep current values
@return $this | [
"Reset",
"local",
"class",
"variables",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L252-L276 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setContactClient | public function setContactClient(ContactClient $contactClient)
{
$this->contactClient = $contactClient;
$this->setPayload($this->contactClient->getFilePayload());
return $this;
} | php | public function setContactClient(ContactClient $contactClient)
{
$this->contactClient = $contactClient;
$this->setPayload($this->contactClient->getFilePayload());
return $this;
} | [
"public",
"function",
"setContactClient",
"(",
"ContactClient",
"$",
"contactClient",
")",
"{",
"$",
"this",
"->",
"contactClient",
"=",
"$",
"contactClient",
";",
"$",
"this",
"->",
"setPayload",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getFilePayload",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param ContactClient $contactClient
@return $this
@throws ContactClientException | [
"@param",
"ContactClient",
"$contactClient"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L313-L319 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setSettings | private function setSettings($settings)
{
if ($settings) {
foreach ($this->settings as $key => &$value) {
if (!empty($settings->{$key}) && $settings->{$key}) {
if (is_object($settings->{$key})) {
$value = array_merge(
$value,
json_decode(json_encode($settings->{$key}, JSON_FORCE_OBJECT), true)
);
} else {
$value = $settings->{$key};
}
}
}
}
} | php | private function setSettings($settings)
{
if ($settings) {
foreach ($this->settings as $key => &$value) {
if (!empty($settings->{$key}) && $settings->{$key}) {
if (is_object($settings->{$key})) {
$value = array_merge(
$value,
json_decode(json_encode($settings->{$key}, JSON_FORCE_OBJECT), true)
);
} else {
$value = $settings->{$key};
}
}
}
}
} | [
"private",
"function",
"setSettings",
"(",
"$",
"settings",
")",
"{",
"if",
"(",
"$",
"settings",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"settings",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"settings",
"->",
"{",
"$",
"key",
"}",
")",
"&&",
"$",
"settings",
"->",
"{",
"$",
"key",
"}",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"settings",
"->",
"{",
"$",
"key",
"}",
")",
")",
"{",
"$",
"value",
"=",
"array_merge",
"(",
"$",
"value",
",",
"json_decode",
"(",
"json_encode",
"(",
"$",
"settings",
"->",
"{",
"$",
"key",
"}",
",",
"JSON_FORCE_OBJECT",
")",
",",
"true",
")",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"settings",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"}",
"}",
"}",
"}"
] | Retrieve File settings from the payload to override our defaults.
@param object $settings | [
"Retrieve",
"File",
"settings",
"from",
"the",
"payload",
"to",
"override",
"our",
"defaults",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L371-L387 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.run | public function run($step = 'add')
{
$this->setLogs($step, 'step');
switch ($step) {
// Step 1: Validate and add a contact to a queue for the next file for the client.
case 'add':
$this->getFieldValues();
$this->fileEntitySelect(true);
$this->fileEntityRefreshSettings();
$this->addContactToQueue();
break;
// Step 3: Build the file (if a good time), performing a second validation on each contact.
case 'build':
if ($this->test) {
$this->getFieldValues();
}
$this->fileEntitySelect();
$this->evaluateSchedule(true);
$this->fileEntityRefreshSettings();
$this->fileBuild();
break;
// Step 4: Perform file send operations, if any are configured.
case 'send':
$this->fileEntitySelect(false, File::STATUS_READY);
$this->evaluateSchedule(true);
$this->fileSend();
break;
}
return $this;
} | php | public function run($step = 'add')
{
$this->setLogs($step, 'step');
switch ($step) {
// Step 1: Validate and add a contact to a queue for the next file for the client.
case 'add':
$this->getFieldValues();
$this->fileEntitySelect(true);
$this->fileEntityRefreshSettings();
$this->addContactToQueue();
break;
// Step 3: Build the file (if a good time), performing a second validation on each contact.
case 'build':
if ($this->test) {
$this->getFieldValues();
}
$this->fileEntitySelect();
$this->evaluateSchedule(true);
$this->fileEntityRefreshSettings();
$this->fileBuild();
break;
// Step 4: Perform file send operations, if any are configured.
case 'send':
$this->fileEntitySelect(false, File::STATUS_READY);
$this->evaluateSchedule(true);
$this->fileSend();
break;
}
return $this;
} | [
"public",
"function",
"run",
"(",
"$",
"step",
"=",
"'add'",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"step",
",",
"'step'",
")",
";",
"switch",
"(",
"$",
"step",
")",
"{",
"// Step 1: Validate and add a contact to a queue for the next file for the client.",
"case",
"'add'",
":",
"$",
"this",
"->",
"getFieldValues",
"(",
")",
";",
"$",
"this",
"->",
"fileEntitySelect",
"(",
"true",
")",
";",
"$",
"this",
"->",
"fileEntityRefreshSettings",
"(",
")",
";",
"$",
"this",
"->",
"addContactToQueue",
"(",
")",
";",
"break",
";",
"// Step 3: Build the file (if a good time), performing a second validation on each contact.",
"case",
"'build'",
":",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"getFieldValues",
"(",
")",
";",
"}",
"$",
"this",
"->",
"fileEntitySelect",
"(",
")",
";",
"$",
"this",
"->",
"evaluateSchedule",
"(",
"true",
")",
";",
"$",
"this",
"->",
"fileEntityRefreshSettings",
"(",
")",
";",
"$",
"this",
"->",
"fileBuild",
"(",
")",
";",
"break",
";",
"// Step 4: Perform file send operations, if any are configured.",
"case",
"'send'",
":",
"$",
"this",
"->",
"fileEntitySelect",
"(",
"false",
",",
"File",
"::",
"STATUS_READY",
")",
";",
"$",
"this",
"->",
"evaluateSchedule",
"(",
"true",
")",
";",
"$",
"this",
"->",
"fileSend",
"(",
")",
";",
"break",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | These steps can occur in different sessions.
@param string $step
@return $this
@throws ContactClientException | [
"These",
"steps",
"can",
"occur",
"in",
"different",
"sessions",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L426-L458 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.getFieldValues | private function getFieldValues()
{
$requestFields = [];
if (!empty($this->payload->body) && !is_string($this->payload->body)) {
$this->tokenHelper->newSession(
$this->contactClient,
$this->contact,
$this->payload,
$this->campaign,
$this->event
);
$requestFields = $this->fieldValues($this->payload->body);
if ($this->file) {
$nullCsv = $this->file->getCsvNull();
if (!empty($nullCsv)) {
foreach ($requestFields as $field => &$value) {
if (empty($value) && false !== $value) {
$value = $nullCsv;
}
}
}
// Filter out exclusion characters.
$exclusions = $this->file->getExclusions();
if (!empty($exclusions)) {
$exclusionArray = array_unique(str_split($exclusions));
foreach ($requestFields as $field => &$value) {
$value = str_replace($exclusionArray, ' ', $value);
}
}
}
}
return $requestFields;
} | php | private function getFieldValues()
{
$requestFields = [];
if (!empty($this->payload->body) && !is_string($this->payload->body)) {
$this->tokenHelper->newSession(
$this->contactClient,
$this->contact,
$this->payload,
$this->campaign,
$this->event
);
$requestFields = $this->fieldValues($this->payload->body);
if ($this->file) {
$nullCsv = $this->file->getCsvNull();
if (!empty($nullCsv)) {
foreach ($requestFields as $field => &$value) {
if (empty($value) && false !== $value) {
$value = $nullCsv;
}
}
}
// Filter out exclusion characters.
$exclusions = $this->file->getExclusions();
if (!empty($exclusions)) {
$exclusionArray = array_unique(str_split($exclusions));
foreach ($requestFields as $field => &$value) {
$value = str_replace($exclusionArray, ' ', $value);
}
}
}
}
return $requestFields;
} | [
"private",
"function",
"getFieldValues",
"(",
")",
"{",
"$",
"requestFields",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
")",
"&&",
"!",
"is_string",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
")",
")",
"{",
"$",
"this",
"->",
"tokenHelper",
"->",
"newSession",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"payload",
",",
"$",
"this",
"->",
"campaign",
",",
"$",
"this",
"->",
"event",
")",
";",
"$",
"requestFields",
"=",
"$",
"this",
"->",
"fieldValues",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
")",
";",
"if",
"(",
"$",
"this",
"->",
"file",
")",
"{",
"$",
"nullCsv",
"=",
"$",
"this",
"->",
"file",
"->",
"getCsvNull",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"nullCsv",
")",
")",
"{",
"foreach",
"(",
"$",
"requestFields",
"as",
"$",
"field",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"false",
"!==",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"nullCsv",
";",
"}",
"}",
"}",
"// Filter out exclusion characters.",
"$",
"exclusions",
"=",
"$",
"this",
"->",
"file",
"->",
"getExclusions",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"exclusions",
")",
")",
"{",
"$",
"exclusionArray",
"=",
"array_unique",
"(",
"str_split",
"(",
"$",
"exclusions",
")",
")",
";",
"foreach",
"(",
"$",
"requestFields",
"as",
"$",
"field",
"=>",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"$",
"exclusionArray",
",",
"' '",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"requestFields",
";",
"}"
] | Gets the token rendered field values (evaluating required fields in the process).
@throws ContactClientException | [
"Gets",
"the",
"token",
"rendered",
"field",
"values",
"(",
"evaluating",
"required",
"fields",
"in",
"the",
"process",
")",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L465-L498 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fieldValues | private function fieldValues($fields)
{
$result = [];
foreach ($fields as $field) {
if (!$this->test && (isset($field->test_only) ? $field->test_only : false)) {
// Skip this field as it is for test mode only.
continue;
}
$key = isset($field->key) ? trim($field->key) : '';
if ('' === $key) {
// Skip if we have an empty key.
continue;
}
// Loop through value sources till a non-empty tokenized result is found.
$valueSources = ['value', 'default_value'];
if ($this->test) {
$valueSources = ['test_value', 'value', 'default_value'];
}
$value = null;
foreach ($valueSources as $valueSource) {
if (isset($field->{$valueSource}) && null !== $field->{$valueSource} && '' !== $field->{$valueSource}) {
$value = $this->tokenHelper->render($field->{$valueSource});
if (null !== $value && '' !== $value) {
break;
}
}
}
if (null === $value || '' === $value) {
// The field value is empty and not 0/false.
if (true === (isset($field->required) ? $field->required : false)) {
// The field is required. Abort.
throw new ContactClientException(
'A required Client file field "'.$field->key.'" is empty based on "'.$field->value.'"',
0,
null,
Stat::TYPE_FIELDS,
false,
$field->key
);
}
}
$result[$key] = $value;
}
return $result;
} | php | private function fieldValues($fields)
{
$result = [];
foreach ($fields as $field) {
if (!$this->test && (isset($field->test_only) ? $field->test_only : false)) {
// Skip this field as it is for test mode only.
continue;
}
$key = isset($field->key) ? trim($field->key) : '';
if ('' === $key) {
// Skip if we have an empty key.
continue;
}
// Loop through value sources till a non-empty tokenized result is found.
$valueSources = ['value', 'default_value'];
if ($this->test) {
$valueSources = ['test_value', 'value', 'default_value'];
}
$value = null;
foreach ($valueSources as $valueSource) {
if (isset($field->{$valueSource}) && null !== $field->{$valueSource} && '' !== $field->{$valueSource}) {
$value = $this->tokenHelper->render($field->{$valueSource});
if (null !== $value && '' !== $value) {
break;
}
}
}
if (null === $value || '' === $value) {
// The field value is empty and not 0/false.
if (true === (isset($field->required) ? $field->required : false)) {
// The field is required. Abort.
throw new ContactClientException(
'A required Client file field "'.$field->key.'" is empty based on "'.$field->value.'"',
0,
null,
Stat::TYPE_FIELDS,
false,
$field->key
);
}
}
$result[$key] = $value;
}
return $result;
} | [
"private",
"function",
"fieldValues",
"(",
"$",
"fields",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
"&&",
"(",
"isset",
"(",
"$",
"field",
"->",
"test_only",
")",
"?",
"$",
"field",
"->",
"test_only",
":",
"false",
")",
")",
"{",
"// Skip this field as it is for test mode only.",
"continue",
";",
"}",
"$",
"key",
"=",
"isset",
"(",
"$",
"field",
"->",
"key",
")",
"?",
"trim",
"(",
"$",
"field",
"->",
"key",
")",
":",
"''",
";",
"if",
"(",
"''",
"===",
"$",
"key",
")",
"{",
"// Skip if we have an empty key.",
"continue",
";",
"}",
"// Loop through value sources till a non-empty tokenized result is found.",
"$",
"valueSources",
"=",
"[",
"'value'",
",",
"'default_value'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"valueSources",
"=",
"[",
"'test_value'",
",",
"'value'",
",",
"'default_value'",
"]",
";",
"}",
"$",
"value",
"=",
"null",
";",
"foreach",
"(",
"$",
"valueSources",
"as",
"$",
"valueSource",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"->",
"{",
"$",
"valueSource",
"}",
")",
"&&",
"null",
"!==",
"$",
"field",
"->",
"{",
"$",
"valueSource",
"}",
"&&",
"''",
"!==",
"$",
"field",
"->",
"{",
"$",
"valueSource",
"}",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"tokenHelper",
"->",
"render",
"(",
"$",
"field",
"->",
"{",
"$",
"valueSource",
"}",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"value",
"&&",
"''",
"!==",
"$",
"value",
")",
"{",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"null",
"===",
"$",
"value",
"||",
"''",
"===",
"$",
"value",
")",
"{",
"// The field value is empty and not 0/false.",
"if",
"(",
"true",
"===",
"(",
"isset",
"(",
"$",
"field",
"->",
"required",
")",
"?",
"$",
"field",
"->",
"required",
":",
"false",
")",
")",
"{",
"// The field is required. Abort.",
"throw",
"new",
"ContactClientException",
"(",
"'A required Client file field \"'",
".",
"$",
"field",
"->",
"key",
".",
"'\" is empty based on \"'",
".",
"$",
"field",
"->",
"value",
".",
"'\"'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_FIELDS",
",",
"false",
",",
"$",
"field",
"->",
"key",
")",
";",
"}",
"}",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Tokenize/parse fields from the file Payload for transit.
@param $fields
@return array
@throws ContactClientException
@todo - This method also exists in the other payload type with a minor difference | [
"Tokenize",
"/",
"parse",
"fields",
"from",
"the",
"file",
"Payload",
"for",
"transit",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L511-L556 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileEntitySelect | private function fileEntitySelect($create = false, $status = null)
{
if (!$this->file && $this->contactClient) {
$file = null;
// Discern the next file entity to use.
if (!$status) {
$status = File::STATUS_QUEUEING;
}
if (!$this->test) {
$file = $this->getFileRepository()->findOneBy(
['contactClient' => $this->contactClient, 'status' => $status, 'test' => $this->test],
['dateAdded' => 'desc']
);
}
if (!$file && ($create || $this->test)) {
// There isn't currently a file being built, let's create one.
$file = new File();
$file->setContactClient($this->contactClient);
$file->setIsPublished(true);
$file->setTest($this->test);
if (!$this->test) {
$this->em->persist($file);
}
}
if ($file) {
$this->file = $file;
$this->setLogs($this->file->getId(), 'fileId');
$this->setLogs($this->file->getStatus(), 'fileStatus');
}
}
if (!$this->file) {
throw new ContactClientException(
'Nothing queued up for this client yet.',
0,
null,
Stat::TYPE_INVALID,
false
);
}
return $this;
} | php | private function fileEntitySelect($create = false, $status = null)
{
if (!$this->file && $this->contactClient) {
$file = null;
// Discern the next file entity to use.
if (!$status) {
$status = File::STATUS_QUEUEING;
}
if (!$this->test) {
$file = $this->getFileRepository()->findOneBy(
['contactClient' => $this->contactClient, 'status' => $status, 'test' => $this->test],
['dateAdded' => 'desc']
);
}
if (!$file && ($create || $this->test)) {
// There isn't currently a file being built, let's create one.
$file = new File();
$file->setContactClient($this->contactClient);
$file->setIsPublished(true);
$file->setTest($this->test);
if (!$this->test) {
$this->em->persist($file);
}
}
if ($file) {
$this->file = $file;
$this->setLogs($this->file->getId(), 'fileId');
$this->setLogs($this->file->getStatus(), 'fileStatus');
}
}
if (!$this->file) {
throw new ContactClientException(
'Nothing queued up for this client yet.',
0,
null,
Stat::TYPE_INVALID,
false
);
}
return $this;
} | [
"private",
"function",
"fileEntitySelect",
"(",
"$",
"create",
"=",
"false",
",",
"$",
"status",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"&&",
"$",
"this",
"->",
"contactClient",
")",
"{",
"$",
"file",
"=",
"null",
";",
"// Discern the next file entity to use.",
"if",
"(",
"!",
"$",
"status",
")",
"{",
"$",
"status",
"=",
"File",
"::",
"STATUS_QUEUEING",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileRepository",
"(",
")",
"->",
"findOneBy",
"(",
"[",
"'contactClient'",
"=>",
"$",
"this",
"->",
"contactClient",
",",
"'status'",
"=>",
"$",
"status",
",",
"'test'",
"=>",
"$",
"this",
"->",
"test",
"]",
",",
"[",
"'dateAdded'",
"=>",
"'desc'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"file",
"&&",
"(",
"$",
"create",
"||",
"$",
"this",
"->",
"test",
")",
")",
"{",
"// There isn't currently a file being built, let's create one.",
"$",
"file",
"=",
"new",
"File",
"(",
")",
";",
"$",
"file",
"->",
"setContactClient",
"(",
"$",
"this",
"->",
"contactClient",
")",
";",
"$",
"file",
"->",
"setIsPublished",
"(",
"true",
")",
";",
"$",
"file",
"->",
"setTest",
"(",
"$",
"this",
"->",
"test",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"file",
")",
";",
"}",
"}",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getId",
"(",
")",
",",
"'fileId'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getStatus",
"(",
")",
",",
"'fileStatus'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Nothing queued up for this client yet.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_INVALID",
",",
"false",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param bool $create
@param null $status
@return $this
@throws ContactClientException | [
"@param",
"bool",
"$create",
"@param",
"null",
"$status"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L566-L609 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileEntityRefreshSettings | private function fileEntityRefreshSettings()
{
if ($this->file) {
// Update settings from the Contact Client entity.
if (!empty($this->settings['name']) && !$this->file->getLocation()) {
// Preliminary name containing tokens.
$this->file->setName($this->settings['name']);
}
if (!empty($this->settings['type'])) {
if (!empty($this->settings['type']['key'])) {
$this->file->setType($this->settings['type']['key']);
}
if (!empty($this->settings['type']['delimiter'])) {
$this->file->setCsvDelimiter($this->settings['type']['delimiter']);
}
if (!empty($this->settings['type']['enclosure'])) {
$this->file->setCsvEnclosure($this->settings['type']['enclosure']);
}
if (!empty($this->settings['type']['escape'])) {
$this->file->setCsvEscape($this->settings['type']['escape']);
}
if (!empty($this->settings['type']['terminate'])) {
$this->file->setCsvTerminate($this->settings['type']['terminate']);
}
if (!empty($this->settings['type']['null'])) {
$this->file->setCsvNull($this->settings['type']['null']);
}
}
if (isset($this->settings['compression'])) {
$this->file->setCompression($this->settings['compression']);
}
if (isset($this->settings['exclusions'])) {
$this->file->setExclusions($this->settings['exclusions']);
}
if (!empty($this->settings['headers'])) {
$this->file->setHeaders((bool) $this->settings['headers']);
}
if ($this->count) {
$this->file->setCount($this->count);
$this->setLogs($this->count, 'count');
}
if ($this->scheduleStart) {
$this->file->setDateAdded($this->scheduleStart);
}
}
return $this;
} | php | private function fileEntityRefreshSettings()
{
if ($this->file) {
// Update settings from the Contact Client entity.
if (!empty($this->settings['name']) && !$this->file->getLocation()) {
// Preliminary name containing tokens.
$this->file->setName($this->settings['name']);
}
if (!empty($this->settings['type'])) {
if (!empty($this->settings['type']['key'])) {
$this->file->setType($this->settings['type']['key']);
}
if (!empty($this->settings['type']['delimiter'])) {
$this->file->setCsvDelimiter($this->settings['type']['delimiter']);
}
if (!empty($this->settings['type']['enclosure'])) {
$this->file->setCsvEnclosure($this->settings['type']['enclosure']);
}
if (!empty($this->settings['type']['escape'])) {
$this->file->setCsvEscape($this->settings['type']['escape']);
}
if (!empty($this->settings['type']['terminate'])) {
$this->file->setCsvTerminate($this->settings['type']['terminate']);
}
if (!empty($this->settings['type']['null'])) {
$this->file->setCsvNull($this->settings['type']['null']);
}
}
if (isset($this->settings['compression'])) {
$this->file->setCompression($this->settings['compression']);
}
if (isset($this->settings['exclusions'])) {
$this->file->setExclusions($this->settings['exclusions']);
}
if (!empty($this->settings['headers'])) {
$this->file->setHeaders((bool) $this->settings['headers']);
}
if ($this->count) {
$this->file->setCount($this->count);
$this->setLogs($this->count, 'count');
}
if ($this->scheduleStart) {
$this->file->setDateAdded($this->scheduleStart);
}
}
return $this;
} | [
"private",
"function",
"fileEntityRefreshSettings",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"file",
")",
"{",
"// Update settings from the Contact Client entity.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'name'",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
")",
"{",
"// Preliminary name containing tokens.",
"$",
"this",
"->",
"file",
"->",
"setName",
"(",
"$",
"this",
"->",
"settings",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'key'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setType",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'key'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'delimiter'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCsvDelimiter",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'delimiter'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'enclosure'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCsvEnclosure",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'enclosure'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'escape'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCsvEscape",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'escape'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'terminate'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCsvTerminate",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'terminate'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'null'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCsvNull",
"(",
"$",
"this",
"->",
"settings",
"[",
"'type'",
"]",
"[",
"'null'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"'compression'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCompression",
"(",
"$",
"this",
"->",
"settings",
"[",
"'compression'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"'exclusions'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setExclusions",
"(",
"$",
"this",
"->",
"settings",
"[",
"'exclusions'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"[",
"'headers'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setHeaders",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"settings",
"[",
"'headers'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"count",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setCount",
"(",
"$",
"this",
"->",
"count",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"count",
",",
"'count'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"scheduleStart",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setDateAdded",
"(",
"$",
"this",
"->",
"scheduleStart",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Update fields on the file entity based on latest data.
@return $this | [
"Update",
"fields",
"on",
"the",
"file",
"entity",
"based",
"on",
"latest",
"data",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L624-L671 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.addContactToQueue | private function addContactToQueue()
{
if (
!$this->queue
&& $this->file
&& $this->contactClient
&& $this->contact
) {
// Check for a pre-existing instance of this contact queued for this file.
$queue = $this->getQueueRepository()->findOneBy(
[
'contactClient' => $this->contactClient,
'file' => $this->file,
'contact' => (int) $this->contact->getId(),
]
);
if ($queue) {
throw new ContactClientException(
'Skipping duplicate Contact. Already queued for file delivery.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_DUPLICATE,
false,
$queue
);
} else {
/** @var Queue $queue */
$queue = new Queue();
$queue->setContactClient($this->contactClient);
$queue->setContact($this->contact);
$queue->setFile($this->file);
if (!empty($this->event['id'])) {
$queue->setCampaignEvent($this->event['id']);
}
if ($this->campaign) {
$queue->setCampaign($this->campaign);
}
if ($queue) {
$this->queue = $queue;
$this->getQueueRepository()->saveEntity($this->queue);
$this->valid = true;
$this->setLogs($this->queue->getId(), 'queueId');
}
}
}
if (!$this->queue) {
throw new ContactClientException(
'Could not append this contact to the queue.',
Codes::HTTP_INTERNAL_SERVER_ERROR,
isset($e) ? $e : null,
Stat::TYPE_ERROR,
false
);
}
return $this->queue;
} | php | private function addContactToQueue()
{
if (
!$this->queue
&& $this->file
&& $this->contactClient
&& $this->contact
) {
// Check for a pre-existing instance of this contact queued for this file.
$queue = $this->getQueueRepository()->findOneBy(
[
'contactClient' => $this->contactClient,
'file' => $this->file,
'contact' => (int) $this->contact->getId(),
]
);
if ($queue) {
throw new ContactClientException(
'Skipping duplicate Contact. Already queued for file delivery.',
Codes::HTTP_CONFLICT,
null,
Stat::TYPE_DUPLICATE,
false,
$queue
);
} else {
/** @var Queue $queue */
$queue = new Queue();
$queue->setContactClient($this->contactClient);
$queue->setContact($this->contact);
$queue->setFile($this->file);
if (!empty($this->event['id'])) {
$queue->setCampaignEvent($this->event['id']);
}
if ($this->campaign) {
$queue->setCampaign($this->campaign);
}
if ($queue) {
$this->queue = $queue;
$this->getQueueRepository()->saveEntity($this->queue);
$this->valid = true;
$this->setLogs($this->queue->getId(), 'queueId');
}
}
}
if (!$this->queue) {
throw new ContactClientException(
'Could not append this contact to the queue.',
Codes::HTTP_INTERNAL_SERVER_ERROR,
isset($e) ? $e : null,
Stat::TYPE_ERROR,
false
);
}
return $this->queue;
} | [
"private",
"function",
"addContactToQueue",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
"&&",
"$",
"this",
"->",
"file",
"&&",
"$",
"this",
"->",
"contactClient",
"&&",
"$",
"this",
"->",
"contact",
")",
"{",
"// Check for a pre-existing instance of this contact queued for this file.",
"$",
"queue",
"=",
"$",
"this",
"->",
"getQueueRepository",
"(",
")",
"->",
"findOneBy",
"(",
"[",
"'contactClient'",
"=>",
"$",
"this",
"->",
"contactClient",
",",
"'file'",
"=>",
"$",
"this",
"->",
"file",
",",
"'contact'",
"=>",
"(",
"int",
")",
"$",
"this",
"->",
"contact",
"->",
"getId",
"(",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"queue",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Skipping duplicate Contact. Already queued for file delivery.'",
",",
"Codes",
"::",
"HTTP_CONFLICT",
",",
"null",
",",
"Stat",
"::",
"TYPE_DUPLICATE",
",",
"false",
",",
"$",
"queue",
")",
";",
"}",
"else",
"{",
"/** @var Queue $queue */",
"$",
"queue",
"=",
"new",
"Queue",
"(",
")",
";",
"$",
"queue",
"->",
"setContactClient",
"(",
"$",
"this",
"->",
"contactClient",
")",
";",
"$",
"queue",
"->",
"setContact",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"queue",
"->",
"setFile",
"(",
"$",
"this",
"->",
"file",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"queue",
"->",
"setCampaignEvent",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"campaign",
")",
"{",
"$",
"queue",
"->",
"setCampaign",
"(",
"$",
"this",
"->",
"campaign",
")",
";",
"}",
"if",
"(",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"$",
"queue",
";",
"$",
"this",
"->",
"getQueueRepository",
"(",
")",
"->",
"saveEntity",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"$",
"this",
"->",
"valid",
"=",
"true",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"queue",
"->",
"getId",
"(",
")",
",",
"'queueId'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"queue",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Could not append this contact to the queue.'",
",",
"Codes",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
",",
"isset",
"(",
"$",
"e",
")",
"?",
"$",
"e",
":",
"null",
",",
"Stat",
"::",
"TYPE_ERROR",
",",
"false",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queue",
";",
"}"
] | @return Queue|null|object
@throws ContactClientException | [
"@return",
"Queue|null|object"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L678-L736 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.evaluateSchedule | public function evaluateSchedule($prepFile = false)
{
if (!$this->scheduleStart && !$this->test) {
$rate = max(1, (int) $this->settings['rate']);
$endDay = 30;
$this->scheduleModel
->reset()
->setContactClient($this->contactClient)
->setTimezone();
$openings = $this->scheduleModel->findOpening(0, $endDay, $rate);
if (!$openings) {
throw new ContactClientException(
'Could not find an open time slot to send in the next '.$endDay.' days',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
$opening = reset($openings);
list($start, $end) = $opening;
// More stringent schedule check to discern if now is a good time to prepare a file for build/send.
if ($prepFile) {
$now = new \DateTime();
$prepStart = clone $start;
$prepEnd = clone $end;
$prepStart->modify('-'.self::FILE_PREP_BEFORE_TIME);
$prepEnd->modify('+'.self::FILE_PREP_AFTER_TIME);
if ($now < $prepStart || $now > $prepEnd) {
throw new ContactClientException(
'It is not yet time to prepare the next file for this client.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
}
$this->scheduleStart = $start;
}
return $this->scheduleStart;
} | php | public function evaluateSchedule($prepFile = false)
{
if (!$this->scheduleStart && !$this->test) {
$rate = max(1, (int) $this->settings['rate']);
$endDay = 30;
$this->scheduleModel
->reset()
->setContactClient($this->contactClient)
->setTimezone();
$openings = $this->scheduleModel->findOpening(0, $endDay, $rate);
if (!$openings) {
throw new ContactClientException(
'Could not find an open time slot to send in the next '.$endDay.' days',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
$opening = reset($openings);
list($start, $end) = $opening;
// More stringent schedule check to discern if now is a good time to prepare a file for build/send.
if ($prepFile) {
$now = new \DateTime();
$prepStart = clone $start;
$prepEnd = clone $end;
$prepStart->modify('-'.self::FILE_PREP_BEFORE_TIME);
$prepEnd->modify('+'.self::FILE_PREP_AFTER_TIME);
if ($now < $prepStart || $now > $prepEnd) {
throw new ContactClientException(
'It is not yet time to prepare the next file for this client.',
0,
null,
Stat::TYPE_SCHEDULE,
false
);
}
}
$this->scheduleStart = $start;
}
return $this->scheduleStart;
} | [
"public",
"function",
"evaluateSchedule",
"(",
"$",
"prepFile",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scheduleStart",
"&&",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"rate",
"=",
"max",
"(",
"1",
",",
"(",
"int",
")",
"$",
"this",
"->",
"settings",
"[",
"'rate'",
"]",
")",
";",
"$",
"endDay",
"=",
"30",
";",
"$",
"this",
"->",
"scheduleModel",
"->",
"reset",
"(",
")",
"->",
"setContactClient",
"(",
"$",
"this",
"->",
"contactClient",
")",
"->",
"setTimezone",
"(",
")",
";",
"$",
"openings",
"=",
"$",
"this",
"->",
"scheduleModel",
"->",
"findOpening",
"(",
"0",
",",
"$",
"endDay",
",",
"$",
"rate",
")",
";",
"if",
"(",
"!",
"$",
"openings",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Could not find an open time slot to send in the next '",
".",
"$",
"endDay",
".",
"' days'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"$",
"opening",
"=",
"reset",
"(",
"$",
"openings",
")",
";",
"list",
"(",
"$",
"start",
",",
"$",
"end",
")",
"=",
"$",
"opening",
";",
"// More stringent schedule check to discern if now is a good time to prepare a file for build/send.",
"if",
"(",
"$",
"prepFile",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"prepStart",
"=",
"clone",
"$",
"start",
";",
"$",
"prepEnd",
"=",
"clone",
"$",
"end",
";",
"$",
"prepStart",
"->",
"modify",
"(",
"'-'",
".",
"self",
"::",
"FILE_PREP_BEFORE_TIME",
")",
";",
"$",
"prepEnd",
"->",
"modify",
"(",
"'+'",
".",
"self",
"::",
"FILE_PREP_AFTER_TIME",
")",
";",
"if",
"(",
"$",
"now",
"<",
"$",
"prepStart",
"||",
"$",
"now",
">",
"$",
"prepEnd",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'It is not yet time to prepare the next file for this client.'",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_SCHEDULE",
",",
"false",
")",
";",
"}",
"}",
"$",
"this",
"->",
"scheduleStart",
"=",
"$",
"start",
";",
"}",
"return",
"$",
"this",
"->",
"scheduleStart",
";",
"}"
] | Assuming we have a file entity ready to go
Throws an exception if an open slot is not available.
@param bool $prepFile
@return \DateTime|null
@throws ContactClientException | [
"Assuming",
"we",
"have",
"a",
"file",
"entity",
"ready",
"to",
"go",
"Throws",
"an",
"exception",
"if",
"an",
"open",
"slot",
"is",
"not",
"available",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L748-L793 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileBuild | private function fileBuild()
{
if (!$this->contactClient || !$this->file) {
return $this;
}
if ($this->test) {
return $this->fileBuildTest();
}
$filter = [];
$filter['force'][] = [
'column' => 'q.contactClient',
'expr' => 'eq',
'value' => (int) $this->contactClient->getId(),
];
$filter['force'][] = [
'column' => 'q.file',
'expr' => 'eq',
'value' => (int) $this->file->getId(),
];
$queues = $this->getQueueRepository()->getEntities(
[
'filter' => $filter,
'iterator_mode' => true,
],
['id' => 'ASC']
);
$this->count = 0;
$queueEntriesProcessed = [];
while (false !== ($queue = $queues->next())) {
/** @var Queue $queueEntry */
$queue = reset($queue);
$this->contact = null;
try {
// Get the full Contact entity.
$contactId = $queue->getContact();
if ($contactId) {
$this->contact = $this->contactModel->getEntity($contactId);
}
if (!$this->contact) {
throw new ContactClientException(
'This contact appears to have been deleted: '.$contactId,
Codes::HTTP_GONE,
null,
Stat::TYPE_REJECT,
false
);
}
// Apply the event for configuration/overrides.
$eventId = $queue->getCampaignEvent();
if ($eventId) {
$event = $this->eventModel->getEntity((int) $eventId);
if ($event) {
$event = $event->getProperties();
// This will apply overrides.
$this->setEvent($event);
}
}
// Get tokenized field values (will include overrides).
$fieldValues = $this->getFieldValues();
$this->fileAddRow($fieldValues);
$queueEntriesProcessed[] = $queue->getId();
} catch (\Exception $e) {
// Cancel this contact and any attribution applied to it.
$this->setLogs($e->getMessage(), 'error');
$attribution = $queue->getAttribution();
if (!empty($attribution)) {
$attributionChange = $attribution * -1;
$originalAttribution = $this->contact->getAttribution();
$newAttribution = $originalAttribution + $attributionChange;
$this->contact->addUpdatedField('attribution', $newAttribution, $originalAttribution);
$this->setLogs($attributionChange, 'attributionCancelled');
try {
$utmSource = $this->utmSourceHelper->getFirstUtmSource($this->contact);
} catch (\Exception $e) {
$utmSource = null;
}
$this->contactClientModel->addStat(
$this->contactClient,
Stat::TYPE_CANCELLED,
$this->contact,
$attributionChange,
$utmSource
);
}
}
if ($this->contact) {
$this->em->detach($this->contact);
}
$this->em->detach($queue);
unset($queue, $contact);
}
unset($queues);
$this->fileClose();
if ($this->count) {
$this->fileCompress();
$this->fileMove();
$this->fileEntityRefreshSettings();
$this->fileEntityAddLogs();
$this->fileEntitySave();
$this->getQueueRepository()->deleteEntitiesById($queueEntriesProcessed);
} else {
$this->setLogs('No applicable contacts were found, so no file was generated.', 'notice');
}
return $this;
} | php | private function fileBuild()
{
if (!$this->contactClient || !$this->file) {
return $this;
}
if ($this->test) {
return $this->fileBuildTest();
}
$filter = [];
$filter['force'][] = [
'column' => 'q.contactClient',
'expr' => 'eq',
'value' => (int) $this->contactClient->getId(),
];
$filter['force'][] = [
'column' => 'q.file',
'expr' => 'eq',
'value' => (int) $this->file->getId(),
];
$queues = $this->getQueueRepository()->getEntities(
[
'filter' => $filter,
'iterator_mode' => true,
],
['id' => 'ASC']
);
$this->count = 0;
$queueEntriesProcessed = [];
while (false !== ($queue = $queues->next())) {
/** @var Queue $queueEntry */
$queue = reset($queue);
$this->contact = null;
try {
// Get the full Contact entity.
$contactId = $queue->getContact();
if ($contactId) {
$this->contact = $this->contactModel->getEntity($contactId);
}
if (!$this->contact) {
throw new ContactClientException(
'This contact appears to have been deleted: '.$contactId,
Codes::HTTP_GONE,
null,
Stat::TYPE_REJECT,
false
);
}
// Apply the event for configuration/overrides.
$eventId = $queue->getCampaignEvent();
if ($eventId) {
$event = $this->eventModel->getEntity((int) $eventId);
if ($event) {
$event = $event->getProperties();
// This will apply overrides.
$this->setEvent($event);
}
}
// Get tokenized field values (will include overrides).
$fieldValues = $this->getFieldValues();
$this->fileAddRow($fieldValues);
$queueEntriesProcessed[] = $queue->getId();
} catch (\Exception $e) {
// Cancel this contact and any attribution applied to it.
$this->setLogs($e->getMessage(), 'error');
$attribution = $queue->getAttribution();
if (!empty($attribution)) {
$attributionChange = $attribution * -1;
$originalAttribution = $this->contact->getAttribution();
$newAttribution = $originalAttribution + $attributionChange;
$this->contact->addUpdatedField('attribution', $newAttribution, $originalAttribution);
$this->setLogs($attributionChange, 'attributionCancelled');
try {
$utmSource = $this->utmSourceHelper->getFirstUtmSource($this->contact);
} catch (\Exception $e) {
$utmSource = null;
}
$this->contactClientModel->addStat(
$this->contactClient,
Stat::TYPE_CANCELLED,
$this->contact,
$attributionChange,
$utmSource
);
}
}
if ($this->contact) {
$this->em->detach($this->contact);
}
$this->em->detach($queue);
unset($queue, $contact);
}
unset($queues);
$this->fileClose();
if ($this->count) {
$this->fileCompress();
$this->fileMove();
$this->fileEntityRefreshSettings();
$this->fileEntityAddLogs();
$this->fileEntitySave();
$this->getQueueRepository()->deleteEntitiesById($queueEntriesProcessed);
} else {
$this->setLogs('No applicable contacts were found, so no file was generated.', 'notice');
}
return $this;
} | [
"private",
"function",
"fileBuild",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"contactClient",
"||",
"!",
"$",
"this",
"->",
"file",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"return",
"$",
"this",
"->",
"fileBuildTest",
"(",
")",
";",
"}",
"$",
"filter",
"=",
"[",
"]",
";",
"$",
"filter",
"[",
"'force'",
"]",
"[",
"]",
"=",
"[",
"'column'",
"=>",
"'q.contactClient'",
",",
"'expr'",
"=>",
"'eq'",
",",
"'value'",
"=>",
"(",
"int",
")",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
",",
"]",
";",
"$",
"filter",
"[",
"'force'",
"]",
"[",
"]",
"=",
"[",
"'column'",
"=>",
"'q.file'",
",",
"'expr'",
"=>",
"'eq'",
",",
"'value'",
"=>",
"(",
"int",
")",
"$",
"this",
"->",
"file",
"->",
"getId",
"(",
")",
",",
"]",
";",
"$",
"queues",
"=",
"$",
"this",
"->",
"getQueueRepository",
"(",
")",
"->",
"getEntities",
"(",
"[",
"'filter'",
"=>",
"$",
"filter",
",",
"'iterator_mode'",
"=>",
"true",
",",
"]",
",",
"[",
"'id'",
"=>",
"'ASC'",
"]",
")",
";",
"$",
"this",
"->",
"count",
"=",
"0",
";",
"$",
"queueEntriesProcessed",
"=",
"[",
"]",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"queue",
"=",
"$",
"queues",
"->",
"next",
"(",
")",
")",
")",
"{",
"/** @var Queue $queueEntry */",
"$",
"queue",
"=",
"reset",
"(",
"$",
"queue",
")",
";",
"$",
"this",
"->",
"contact",
"=",
"null",
";",
"try",
"{",
"// Get the full Contact entity.",
"$",
"contactId",
"=",
"$",
"queue",
"->",
"getContact",
"(",
")",
";",
"if",
"(",
"$",
"contactId",
")",
"{",
"$",
"this",
"->",
"contact",
"=",
"$",
"this",
"->",
"contactModel",
"->",
"getEntity",
"(",
"$",
"contactId",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"contact",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'This contact appears to have been deleted: '",
".",
"$",
"contactId",
",",
"Codes",
"::",
"HTTP_GONE",
",",
"null",
",",
"Stat",
"::",
"TYPE_REJECT",
",",
"false",
")",
";",
"}",
"// Apply the event for configuration/overrides.",
"$",
"eventId",
"=",
"$",
"queue",
"->",
"getCampaignEvent",
"(",
")",
";",
"if",
"(",
"$",
"eventId",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"eventModel",
"->",
"getEntity",
"(",
"(",
"int",
")",
"$",
"eventId",
")",
";",
"if",
"(",
"$",
"event",
")",
"{",
"$",
"event",
"=",
"$",
"event",
"->",
"getProperties",
"(",
")",
";",
"// This will apply overrides.",
"$",
"this",
"->",
"setEvent",
"(",
"$",
"event",
")",
";",
"}",
"}",
"// Get tokenized field values (will include overrides).",
"$",
"fieldValues",
"=",
"$",
"this",
"->",
"getFieldValues",
"(",
")",
";",
"$",
"this",
"->",
"fileAddRow",
"(",
"$",
"fieldValues",
")",
";",
"$",
"queueEntriesProcessed",
"[",
"]",
"=",
"$",
"queue",
"->",
"getId",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Cancel this contact and any attribution applied to it.",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'error'",
")",
";",
"$",
"attribution",
"=",
"$",
"queue",
"->",
"getAttribution",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attribution",
")",
")",
"{",
"$",
"attributionChange",
"=",
"$",
"attribution",
"*",
"-",
"1",
";",
"$",
"originalAttribution",
"=",
"$",
"this",
"->",
"contact",
"->",
"getAttribution",
"(",
")",
";",
"$",
"newAttribution",
"=",
"$",
"originalAttribution",
"+",
"$",
"attributionChange",
";",
"$",
"this",
"->",
"contact",
"->",
"addUpdatedField",
"(",
"'attribution'",
",",
"$",
"newAttribution",
",",
"$",
"originalAttribution",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"attributionChange",
",",
"'attributionCancelled'",
")",
";",
"try",
"{",
"$",
"utmSource",
"=",
"$",
"this",
"->",
"utmSourceHelper",
"->",
"getFirstUtmSource",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"utmSource",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"contactClientModel",
"->",
"addStat",
"(",
"$",
"this",
"->",
"contactClient",
",",
"Stat",
"::",
"TYPE_CANCELLED",
",",
"$",
"this",
"->",
"contact",
",",
"$",
"attributionChange",
",",
"$",
"utmSource",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"contact",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"detach",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"detach",
"(",
"$",
"queue",
")",
";",
"unset",
"(",
"$",
"queue",
",",
"$",
"contact",
")",
";",
"}",
"unset",
"(",
"$",
"queues",
")",
";",
"$",
"this",
"->",
"fileClose",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"count",
")",
"{",
"$",
"this",
"->",
"fileCompress",
"(",
")",
";",
"$",
"this",
"->",
"fileMove",
"(",
")",
";",
"$",
"this",
"->",
"fileEntityRefreshSettings",
"(",
")",
";",
"$",
"this",
"->",
"fileEntityAddLogs",
"(",
")",
";",
"$",
"this",
"->",
"fileEntitySave",
"(",
")",
";",
"$",
"this",
"->",
"getQueueRepository",
"(",
")",
"->",
"deleteEntitiesById",
"(",
"$",
"queueEntriesProcessed",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'No applicable contacts were found, so no file was generated.'",
",",
"'notice'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Build out the original temp file.
@return $this
@throws ContactClientException | [
"Build",
"out",
"the",
"original",
"temp",
"file",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L802-L916 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileAddRow | private function fileAddRow($fieldValues = [])
{
if ($fieldValues) {
$this->getFileWriter()->write($fieldValues);
if (0 === $this->count) {
// Indicate to other processes that this file is being compiled.
$this->file->setStatus(File::STATUS_BUILDING);
$this->fileEntitySave();
}
++$this->count;
}
return $this;
} | php | private function fileAddRow($fieldValues = [])
{
if ($fieldValues) {
$this->getFileWriter()->write($fieldValues);
if (0 === $this->count) {
// Indicate to other processes that this file is being compiled.
$this->file->setStatus(File::STATUS_BUILDING);
$this->fileEntitySave();
}
++$this->count;
}
return $this;
} | [
"private",
"function",
"fileAddRow",
"(",
"$",
"fieldValues",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"fieldValues",
")",
"{",
"$",
"this",
"->",
"getFileWriter",
"(",
")",
"->",
"write",
"(",
"$",
"fieldValues",
")",
";",
"if",
"(",
"0",
"===",
"$",
"this",
"->",
"count",
")",
"{",
"// Indicate to other processes that this file is being compiled.",
"$",
"this",
"->",
"file",
"->",
"setStatus",
"(",
"File",
"::",
"STATUS_BUILDING",
")",
";",
"$",
"this",
"->",
"fileEntitySave",
"(",
")",
";",
"}",
"++",
"$",
"this",
"->",
"count",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param array $fieldValues
@return $this | [
"@param",
"array",
"$fieldValues"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L964-L977 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileGenerateTmp | private function fileGenerateTmp($compression = null)
{
$fileTmp = null;
$compression = 'none' == $compression ? null : $compression;
while (true) {
$fileTmpName = uniqid($this->getFileName($compression), true);
$fileTmp = sys_get_temp_dir().'/'.$fileTmpName;
if (!file_exists($fileTmp)) {
if (!$compression) {
$this->file->setTmp($fileTmp);
$this->setLogs($fileTmp, 'fileTmp');
}
break;
}
}
return $fileTmp;
} | php | private function fileGenerateTmp($compression = null)
{
$fileTmp = null;
$compression = 'none' == $compression ? null : $compression;
while (true) {
$fileTmpName = uniqid($this->getFileName($compression), true);
$fileTmp = sys_get_temp_dir().'/'.$fileTmpName;
if (!file_exists($fileTmp)) {
if (!$compression) {
$this->file->setTmp($fileTmp);
$this->setLogs($fileTmp, 'fileTmp');
}
break;
}
}
return $fileTmp;
} | [
"private",
"function",
"fileGenerateTmp",
"(",
"$",
"compression",
"=",
"null",
")",
"{",
"$",
"fileTmp",
"=",
"null",
";",
"$",
"compression",
"=",
"'none'",
"==",
"$",
"compression",
"?",
"null",
":",
"$",
"compression",
";",
"while",
"(",
"true",
")",
"{",
"$",
"fileTmpName",
"=",
"uniqid",
"(",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"compression",
")",
",",
"true",
")",
";",
"$",
"fileTmp",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/'",
".",
"$",
"fileTmpName",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileTmp",
")",
")",
"{",
"if",
"(",
"!",
"$",
"compression",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setTmp",
"(",
"$",
"fileTmp",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"fileTmp",
",",
"'fileTmp'",
")",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"fileTmp",
";",
"}"
] | Generates a temporary path for file generation.
@param string $compression
@return null|string | [
"Generates",
"a",
"temporary",
"path",
"for",
"file",
"generation",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1046-L1063 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.getFileName | private function getFileName($compression = null)
{
$compression = 'none' == $compression ? null : $compression;
$this->tokenHelper->newSession(
$this->contactClient,
$this->contact, // Context of the first/last client in the file will be used if available
$this->payload,
$this->campaign,
$this->event
);
$type = $this->file->getType();
$type = str_ireplace('custom', '', $type);
$extension = $type.($compression ? '.'.$compression : '');
// Prevent BC break for old token values here.
$this->settings['name'] = str_replace(
[
'{{count}}',
'{{test}}',
'{{date}}',
'{{time}}',
'{{type}}',
'{{compression}}',
'{{extension}}',
],
[
'{{file_count}}',
'{{file_test}}',
'{{file_date|date.yyyy-mm-dd}}',
'{{file_date|date.hh-mm-ss}}',
'{{file_type}}',
'{{file_compression}}',
'{{file_extension}}',
],
$this->settings['name']
);
$this->tokenHelper->addContext(
[
'file_count' => ($this->count ? $this->count : 0),
'file_test' => $this->test ? '.test' : '',
'file_date' => $this->tokenHelper->getDateFormatHelper()->format(new \DateTime()),
'file_type' => $type,
'file_compression' => $compression,
'file_extension' => $extension,
]
);
// Update the name of the output file to represent latest token data.
$result = $this->tokenHelper->render($this->settings['name']);
return trim($result);
} | php | private function getFileName($compression = null)
{
$compression = 'none' == $compression ? null : $compression;
$this->tokenHelper->newSession(
$this->contactClient,
$this->contact, // Context of the first/last client in the file will be used if available
$this->payload,
$this->campaign,
$this->event
);
$type = $this->file->getType();
$type = str_ireplace('custom', '', $type);
$extension = $type.($compression ? '.'.$compression : '');
// Prevent BC break for old token values here.
$this->settings['name'] = str_replace(
[
'{{count}}',
'{{test}}',
'{{date}}',
'{{time}}',
'{{type}}',
'{{compression}}',
'{{extension}}',
],
[
'{{file_count}}',
'{{file_test}}',
'{{file_date|date.yyyy-mm-dd}}',
'{{file_date|date.hh-mm-ss}}',
'{{file_type}}',
'{{file_compression}}',
'{{file_extension}}',
],
$this->settings['name']
);
$this->tokenHelper->addContext(
[
'file_count' => ($this->count ? $this->count : 0),
'file_test' => $this->test ? '.test' : '',
'file_date' => $this->tokenHelper->getDateFormatHelper()->format(new \DateTime()),
'file_type' => $type,
'file_compression' => $compression,
'file_extension' => $extension,
]
);
// Update the name of the output file to represent latest token data.
$result = $this->tokenHelper->render($this->settings['name']);
return trim($result);
} | [
"private",
"function",
"getFileName",
"(",
"$",
"compression",
"=",
"null",
")",
"{",
"$",
"compression",
"=",
"'none'",
"==",
"$",
"compression",
"?",
"null",
":",
"$",
"compression",
";",
"$",
"this",
"->",
"tokenHelper",
"->",
"newSession",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"contact",
",",
"// Context of the first/last client in the file will be used if available",
"$",
"this",
"->",
"payload",
",",
"$",
"this",
"->",
"campaign",
",",
"$",
"this",
"->",
"event",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"file",
"->",
"getType",
"(",
")",
";",
"$",
"type",
"=",
"str_ireplace",
"(",
"'custom'",
",",
"''",
",",
"$",
"type",
")",
";",
"$",
"extension",
"=",
"$",
"type",
".",
"(",
"$",
"compression",
"?",
"'.'",
".",
"$",
"compression",
":",
"''",
")",
";",
"// Prevent BC break for old token values here.",
"$",
"this",
"->",
"settings",
"[",
"'name'",
"]",
"=",
"str_replace",
"(",
"[",
"'{{count}}'",
",",
"'{{test}}'",
",",
"'{{date}}'",
",",
"'{{time}}'",
",",
"'{{type}}'",
",",
"'{{compression}}'",
",",
"'{{extension}}'",
",",
"]",
",",
"[",
"'{{file_count}}'",
",",
"'{{file_test}}'",
",",
"'{{file_date|date.yyyy-mm-dd}}'",
",",
"'{{file_date|date.hh-mm-ss}}'",
",",
"'{{file_type}}'",
",",
"'{{file_compression}}'",
",",
"'{{file_extension}}'",
",",
"]",
",",
"$",
"this",
"->",
"settings",
"[",
"'name'",
"]",
")",
";",
"$",
"this",
"->",
"tokenHelper",
"->",
"addContext",
"(",
"[",
"'file_count'",
"=>",
"(",
"$",
"this",
"->",
"count",
"?",
"$",
"this",
"->",
"count",
":",
"0",
")",
",",
"'file_test'",
"=>",
"$",
"this",
"->",
"test",
"?",
"'.test'",
":",
"''",
",",
"'file_date'",
"=>",
"$",
"this",
"->",
"tokenHelper",
"->",
"getDateFormatHelper",
"(",
")",
"->",
"format",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
",",
"'file_type'",
"=>",
"$",
"type",
",",
"'file_compression'",
"=>",
"$",
"compression",
",",
"'file_extension'",
"=>",
"$",
"extension",
",",
"]",
")",
";",
"// Update the name of the output file to represent latest token data.",
"$",
"result",
"=",
"$",
"this",
"->",
"tokenHelper",
"->",
"render",
"(",
"$",
"this",
"->",
"settings",
"[",
"'name'",
"]",
")",
";",
"return",
"trim",
"(",
"$",
"result",
")",
";",
"}"
] | Discern the desired output file name for a new file.
@param null $compression
@return string
@throws \Exception | [
"Discern",
"the",
"desired",
"output",
"file",
"name",
"for",
"a",
"new",
"file",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1074-L1124 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileEntitySave | private function fileEntitySave()
{
if (!$this->file) {
return;
}
if ($this->file->isNew() || $this->file->getChanges()) {
if ($this->contactClient->getId()) {
$this->formModel->saveEntity($this->file, true);
}
}
} | php | private function fileEntitySave()
{
if (!$this->file) {
return;
}
if ($this->file->isNew() || $this->file->getChanges()) {
if ($this->contactClient->getId()) {
$this->formModel->saveEntity($this->file, true);
}
}
} | [
"private",
"function",
"fileEntitySave",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"file",
"->",
"isNew",
"(",
")",
"||",
"$",
"this",
"->",
"file",
"->",
"getChanges",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"formModel",
"->",
"saveEntity",
"(",
"$",
"this",
"->",
"file",
",",
"true",
")",
";",
"}",
"}",
"}"
] | Save any file changes using the form model. | [
"Save",
"any",
"file",
"changes",
"using",
"the",
"form",
"model",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1129-L1139 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileCompress | private function fileCompress()
{
if ($this->file && $this->file->getTmp()) {
$compression = $this->file->getCompression();
if ($compression && in_array($compression, ['tar.gz', 'tar.bz2', 'zip'])) {
// Discern new tmp file name (with compression applied).
$target = $this->fileGenerateTmp($compression);
$fileName = $this->getFileName();
try {
switch ($compression) {
case 'tar.gz':
$phar = new \PharData($target);
$phar->addFile($this->file->getTmp(), $fileName);
$phar->compress(\Phar::GZ, $compression);
$target = $phar->getRealPath();
break;
case 'tar.bz2':
$phar = new \PharData($target);
$phar->addFile($this->file->getTmp(), $fileName);
$phar->compress(\Phar::BZ2, $compression);
$target = $phar->getRealPath();
break;
default:
case 'zip':
$zip = new \ZipArchive();
if (true !== $zip->open($target, \ZipArchive::CREATE)) {
throw new ContactClientException(
'Cound not open zip '.$target,
Codes::HTTP_INTERNAL_SERVER_ERROR,
null,
Stat::TYPE_ERROR,
false
);
}
$zip->addFile($this->file->getTmp(), $fileName);
$zip->close();
break;
}
$this->file->setTmp($target);
$this->setLogs($target, 'fileCompressed');
} catch (\Exception $e) {
throw new ContactClientException(
'Could not create compressed file '.$target,
Codes::HTTP_INTERNAL_SERVER_ERROR,
$e,
Stat::TYPE_ERROR,
false
);
}
} else {
$this->setLogs(false, 'fileCompressed');
}
}
return $this;
} | php | private function fileCompress()
{
if ($this->file && $this->file->getTmp()) {
$compression = $this->file->getCompression();
if ($compression && in_array($compression, ['tar.gz', 'tar.bz2', 'zip'])) {
// Discern new tmp file name (with compression applied).
$target = $this->fileGenerateTmp($compression);
$fileName = $this->getFileName();
try {
switch ($compression) {
case 'tar.gz':
$phar = new \PharData($target);
$phar->addFile($this->file->getTmp(), $fileName);
$phar->compress(\Phar::GZ, $compression);
$target = $phar->getRealPath();
break;
case 'tar.bz2':
$phar = new \PharData($target);
$phar->addFile($this->file->getTmp(), $fileName);
$phar->compress(\Phar::BZ2, $compression);
$target = $phar->getRealPath();
break;
default:
case 'zip':
$zip = new \ZipArchive();
if (true !== $zip->open($target, \ZipArchive::CREATE)) {
throw new ContactClientException(
'Cound not open zip '.$target,
Codes::HTTP_INTERNAL_SERVER_ERROR,
null,
Stat::TYPE_ERROR,
false
);
}
$zip->addFile($this->file->getTmp(), $fileName);
$zip->close();
break;
}
$this->file->setTmp($target);
$this->setLogs($target, 'fileCompressed');
} catch (\Exception $e) {
throw new ContactClientException(
'Could not create compressed file '.$target,
Codes::HTTP_INTERNAL_SERVER_ERROR,
$e,
Stat::TYPE_ERROR,
false
);
}
} else {
$this->setLogs(false, 'fileCompressed');
}
}
return $this;
} | [
"private",
"function",
"fileCompress",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"file",
"&&",
"$",
"this",
"->",
"file",
"->",
"getTmp",
"(",
")",
")",
"{",
"$",
"compression",
"=",
"$",
"this",
"->",
"file",
"->",
"getCompression",
"(",
")",
";",
"if",
"(",
"$",
"compression",
"&&",
"in_array",
"(",
"$",
"compression",
",",
"[",
"'tar.gz'",
",",
"'tar.bz2'",
",",
"'zip'",
"]",
")",
")",
"{",
"// Discern new tmp file name (with compression applied).",
"$",
"target",
"=",
"$",
"this",
"->",
"fileGenerateTmp",
"(",
"$",
"compression",
")",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getFileName",
"(",
")",
";",
"try",
"{",
"switch",
"(",
"$",
"compression",
")",
"{",
"case",
"'tar.gz'",
":",
"$",
"phar",
"=",
"new",
"\\",
"PharData",
"(",
"$",
"target",
")",
";",
"$",
"phar",
"->",
"addFile",
"(",
"$",
"this",
"->",
"file",
"->",
"getTmp",
"(",
")",
",",
"$",
"fileName",
")",
";",
"$",
"phar",
"->",
"compress",
"(",
"\\",
"Phar",
"::",
"GZ",
",",
"$",
"compression",
")",
";",
"$",
"target",
"=",
"$",
"phar",
"->",
"getRealPath",
"(",
")",
";",
"break",
";",
"case",
"'tar.bz2'",
":",
"$",
"phar",
"=",
"new",
"\\",
"PharData",
"(",
"$",
"target",
")",
";",
"$",
"phar",
"->",
"addFile",
"(",
"$",
"this",
"->",
"file",
"->",
"getTmp",
"(",
")",
",",
"$",
"fileName",
")",
";",
"$",
"phar",
"->",
"compress",
"(",
"\\",
"Phar",
"::",
"BZ2",
",",
"$",
"compression",
")",
";",
"$",
"target",
"=",
"$",
"phar",
"->",
"getRealPath",
"(",
")",
";",
"break",
";",
"default",
":",
"case",
"'zip'",
":",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"zip",
"->",
"open",
"(",
"$",
"target",
",",
"\\",
"ZipArchive",
"::",
"CREATE",
")",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Cound not open zip '",
".",
"$",
"target",
",",
"Codes",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
",",
"null",
",",
"Stat",
"::",
"TYPE_ERROR",
",",
"false",
")",
";",
"}",
"$",
"zip",
"->",
"addFile",
"(",
"$",
"this",
"->",
"file",
"->",
"getTmp",
"(",
")",
",",
"$",
"fileName",
")",
";",
"$",
"zip",
"->",
"close",
"(",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"file",
"->",
"setTmp",
"(",
"$",
"target",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"target",
",",
"'fileCompressed'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Could not create compressed file '",
".",
"$",
"target",
",",
"Codes",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
",",
"$",
"e",
",",
"Stat",
"::",
"TYPE_ERROR",
",",
"false",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"false",
",",
"'fileCompressed'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Perform compression on the temp file.
@return $this
@throws ContactClientException | [
"Perform",
"compression",
"on",
"the",
"temp",
"file",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1160-L1217 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileMove | private function fileMove($overwrite = true)
{
if (!$this->file->getLocation() || $overwrite) {
$origin = $this->file->getTmp();
// This will typically be /media/files
$uploadDir = realpath($this->coreParametersHelper->getParameter('upload_dir'));
$fileName = $this->getFileName(
$this->file->getCompression()
);
$target = $uploadDir.'/client_payloads/'.$this->contactClient->getId().'/'.$fileName;
if ($origin && (!file_exists($target) || $overwrite)) {
$this->filesystemLocal->copy($origin, $target, $overwrite);
if (file_exists($target)) {
// Final file name as it will be seen by the client.
$this->file->setName($fileName);
$this->setLogs($fileName, 'fileName');
$this->file->setDateAdded(new \DateTime());
$this->file->setLocation($target);
$this->setLogs($target, 'fileLocation');
$crc32 = hash_file('crc32b', $target);
$this->file->setCrc32($crc32);
$this->setLogs($crc32, 'crc32');
$md5 = hash_file('md5', $target);
$this->file->setMd5($md5);
$this->setLogs($md5, 'md5');
$sha1 = hash_file('sha1', $target);
$this->file->setSha1($sha1);
$this->setLogs($sha1, 'sha1');
$this->setLogs(filesize($target), 'fileSize');
$this->filesystemLocal->remove($origin);
$this->file->setStatus(File::STATUS_READY);
$this->setLogs($this->file->getStatus(), 'fileStatus');
} else {
throw new ContactClientException(
'Could not move file to local location.',
Codes::HTTP_INTERNAL_SERVER_ERROR,
null,
Stat::TYPE_ERROR,
false
);
}
}
}
return $this;
} | php | private function fileMove($overwrite = true)
{
if (!$this->file->getLocation() || $overwrite) {
$origin = $this->file->getTmp();
// This will typically be /media/files
$uploadDir = realpath($this->coreParametersHelper->getParameter('upload_dir'));
$fileName = $this->getFileName(
$this->file->getCompression()
);
$target = $uploadDir.'/client_payloads/'.$this->contactClient->getId().'/'.$fileName;
if ($origin && (!file_exists($target) || $overwrite)) {
$this->filesystemLocal->copy($origin, $target, $overwrite);
if (file_exists($target)) {
// Final file name as it will be seen by the client.
$this->file->setName($fileName);
$this->setLogs($fileName, 'fileName');
$this->file->setDateAdded(new \DateTime());
$this->file->setLocation($target);
$this->setLogs($target, 'fileLocation');
$crc32 = hash_file('crc32b', $target);
$this->file->setCrc32($crc32);
$this->setLogs($crc32, 'crc32');
$md5 = hash_file('md5', $target);
$this->file->setMd5($md5);
$this->setLogs($md5, 'md5');
$sha1 = hash_file('sha1', $target);
$this->file->setSha1($sha1);
$this->setLogs($sha1, 'sha1');
$this->setLogs(filesize($target), 'fileSize');
$this->filesystemLocal->remove($origin);
$this->file->setStatus(File::STATUS_READY);
$this->setLogs($this->file->getStatus(), 'fileStatus');
} else {
throw new ContactClientException(
'Could not move file to local location.',
Codes::HTTP_INTERNAL_SERVER_ERROR,
null,
Stat::TYPE_ERROR,
false
);
}
}
}
return $this;
} | [
"private",
"function",
"fileMove",
"(",
"$",
"overwrite",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
"||",
"$",
"overwrite",
")",
"{",
"$",
"origin",
"=",
"$",
"this",
"->",
"file",
"->",
"getTmp",
"(",
")",
";",
"// This will typically be /media/files",
"$",
"uploadDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"coreParametersHelper",
"->",
"getParameter",
"(",
"'upload_dir'",
")",
")",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"this",
"->",
"file",
"->",
"getCompression",
"(",
")",
")",
";",
"$",
"target",
"=",
"$",
"uploadDir",
".",
"'/client_payloads/'",
".",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'/'",
".",
"$",
"fileName",
";",
"if",
"(",
"$",
"origin",
"&&",
"(",
"!",
"file_exists",
"(",
"$",
"target",
")",
"||",
"$",
"overwrite",
")",
")",
"{",
"$",
"this",
"->",
"filesystemLocal",
"->",
"copy",
"(",
"$",
"origin",
",",
"$",
"target",
",",
"$",
"overwrite",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"target",
")",
")",
"{",
"// Final file name as it will be seen by the client.",
"$",
"this",
"->",
"file",
"->",
"setName",
"(",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"fileName",
",",
"'fileName'",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setDateAdded",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setLocation",
"(",
"$",
"target",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"target",
",",
"'fileLocation'",
")",
";",
"$",
"crc32",
"=",
"hash_file",
"(",
"'crc32b'",
",",
"$",
"target",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setCrc32",
"(",
"$",
"crc32",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"crc32",
",",
"'crc32'",
")",
";",
"$",
"md5",
"=",
"hash_file",
"(",
"'md5'",
",",
"$",
"target",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setMd5",
"(",
"$",
"md5",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"md5",
",",
"'md5'",
")",
";",
"$",
"sha1",
"=",
"hash_file",
"(",
"'sha1'",
",",
"$",
"target",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setSha1",
"(",
"$",
"sha1",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"sha1",
",",
"'sha1'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"filesize",
"(",
"$",
"target",
")",
",",
"'fileSize'",
")",
";",
"$",
"this",
"->",
"filesystemLocal",
"->",
"remove",
"(",
"$",
"origin",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setStatus",
"(",
"File",
"::",
"STATUS_READY",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getStatus",
"(",
")",
",",
"'fileStatus'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Could not move file to local location.'",
",",
"Codes",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
",",
"null",
",",
"Stat",
"::",
"TYPE_ERROR",
",",
"false",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Moves the file out of temp, and locks the hashes.
@param bool $overwrite
@return $this
@throws ContactClientException | [
"Moves",
"the",
"file",
"out",
"of",
"temp",
"and",
"locks",
"the",
"hashes",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1228-L1282 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setEvent | public function setEvent($event = [])
{
if (!empty($event['id'])) {
$this->setLogs($event['id'], 'campaignEventId');
}
$overrides = [];
if (!empty($event['config']['contactclient_overrides'])) {
// Flatten overrides to key-value pairs.
$jsonHelper = new JSONHelper();
$array = $jsonHelper->decodeArray($event['config']['contactclient_overrides'], 'Overrides');
if ($array) {
foreach ($array as $field) {
if (!empty($field->key) && !empty($field->value) && (empty($field->enabled) || true === $field->enabled)) {
$overrides[$field->key] = $field->value;
}
}
}
if ($overrides) {
$this->setOverrides($overrides);
}
}
$this->event = $event;
return $this;
} | php | public function setEvent($event = [])
{
if (!empty($event['id'])) {
$this->setLogs($event['id'], 'campaignEventId');
}
$overrides = [];
if (!empty($event['config']['contactclient_overrides'])) {
// Flatten overrides to key-value pairs.
$jsonHelper = new JSONHelper();
$array = $jsonHelper->decodeArray($event['config']['contactclient_overrides'], 'Overrides');
if ($array) {
foreach ($array as $field) {
if (!empty($field->key) && !empty($field->value) && (empty($field->enabled) || true === $field->enabled)) {
$overrides[$field->key] = $field->value;
}
}
}
if ($overrides) {
$this->setOverrides($overrides);
}
}
$this->event = $event;
return $this;
} | [
"public",
"function",
"setEvent",
"(",
"$",
"event",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"event",
"[",
"'id'",
"]",
",",
"'campaignEventId'",
")",
";",
"}",
"$",
"overrides",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
"[",
"'config'",
"]",
"[",
"'contactclient_overrides'",
"]",
")",
")",
"{",
"// Flatten overrides to key-value pairs.",
"$",
"jsonHelper",
"=",
"new",
"JSONHelper",
"(",
")",
";",
"$",
"array",
"=",
"$",
"jsonHelper",
"->",
"decodeArray",
"(",
"$",
"event",
"[",
"'config'",
"]",
"[",
"'contactclient_overrides'",
"]",
",",
"'Overrides'",
")",
";",
"if",
"(",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"->",
"key",
")",
"&&",
"!",
"empty",
"(",
"$",
"field",
"->",
"value",
")",
"&&",
"(",
"empty",
"(",
"$",
"field",
"->",
"enabled",
")",
"||",
"true",
"===",
"$",
"field",
"->",
"enabled",
")",
")",
"{",
"$",
"overrides",
"[",
"$",
"field",
"->",
"key",
"]",
"=",
"$",
"field",
"->",
"value",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"overrides",
")",
"{",
"$",
"this",
"->",
"setOverrides",
"(",
"$",
"overrides",
")",
";",
"}",
"}",
"$",
"this",
"->",
"event",
"=",
"$",
"event",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $event
@return $this
@throws \Exception | [
"@param",
"array",
"$event"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1309-L1333 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setOverrides | public function setOverrides($overrides)
{
$fieldsOverridden = [];
if (isset($this->payload->body)) {
foreach ($this->payload->body as &$field) {
if (
isset($field->overridable)
&& true === $field->overridable
&& isset($field->key)
&& isset($overrides[$field->key])
&& null !== $overrides[$field->key]
) {
$field->value = $overrides[$field->key];
$fieldsOverridden[$field->key] = $overrides[$field->key];
}
}
}
if ($fieldsOverridden) {
$this->setLogs($fieldsOverridden, 'fieldsOverridden');
}
return $this;
} | php | public function setOverrides($overrides)
{
$fieldsOverridden = [];
if (isset($this->payload->body)) {
foreach ($this->payload->body as &$field) {
if (
isset($field->overridable)
&& true === $field->overridable
&& isset($field->key)
&& isset($overrides[$field->key])
&& null !== $overrides[$field->key]
) {
$field->value = $overrides[$field->key];
$fieldsOverridden[$field->key] = $overrides[$field->key];
}
}
}
if ($fieldsOverridden) {
$this->setLogs($fieldsOverridden, 'fieldsOverridden');
}
return $this;
} | [
"public",
"function",
"setOverrides",
"(",
"$",
"overrides",
")",
"{",
"$",
"fieldsOverridden",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
"as",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"->",
"overridable",
")",
"&&",
"true",
"===",
"$",
"field",
"->",
"overridable",
"&&",
"isset",
"(",
"$",
"field",
"->",
"key",
")",
"&&",
"isset",
"(",
"$",
"overrides",
"[",
"$",
"field",
"->",
"key",
"]",
")",
"&&",
"null",
"!==",
"$",
"overrides",
"[",
"$",
"field",
"->",
"key",
"]",
")",
"{",
"$",
"field",
"->",
"value",
"=",
"$",
"overrides",
"[",
"$",
"field",
"->",
"key",
"]",
";",
"$",
"fieldsOverridden",
"[",
"$",
"field",
"->",
"key",
"]",
"=",
"$",
"overrides",
"[",
"$",
"field",
"->",
"key",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"fieldsOverridden",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"fieldsOverridden",
",",
"'fieldsOverridden'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Override the default field values, if allowed.
@param $overrides
@return $this | [
"Override",
"the",
"default",
"field",
"values",
"if",
"allowed",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1342-L1364 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.fileSend | private function fileSend()
{
$attemptCount = 0;
$successCount = 0;
if (isset($this->payload->operations)) {
foreach ($this->payload->operations as $type => $operation) {
if (is_object($operation)) {
++$attemptCount;
$result = false;
$now = new \DateTime();
$this->setLogs($now->format(\DateTime::ISO8601), $type.'started');
try {
switch ($type) {
case 'email':
$result = $this->operationEmail($operation);
break;
case 'ftp':
$result = $this->operationFtp($operation);
break;
case 'sftp':
$result = $this->operationSftp($operation);
break;
case 's3':
$result = $this->operationS3($operation);
break;
}
} catch (\Exception $e) {
$message = 'Unable to send file to '.$type.': '.$e->getMessage();
$this->setLogs($message, $type.'error');
}
if ($result) {
++$successCount;
}
}
}
}
if (!$attemptCount) {
$this->setLogs(
'No file send operations are enabled. Please add a file send operation to be tested',
'error'
);
} elseif ($successCount === $attemptCount) {
$this->file->setStatus(File::STATUS_SENT);
$this->valid = true;
} elseif ($successCount < $attemptCount) {
$this->file->setStatus(File::STATUS_ERROR);
$this->valid = false;
}
$this->setLogs($this->file->getStatus(), 'fileStatus');
$this->setLogs($this->valid, 'valid');
$this->fileEntityAddLogs();
$this->fileEntitySave();
return $this;
} | php | private function fileSend()
{
$attemptCount = 0;
$successCount = 0;
if (isset($this->payload->operations)) {
foreach ($this->payload->operations as $type => $operation) {
if (is_object($operation)) {
++$attemptCount;
$result = false;
$now = new \DateTime();
$this->setLogs($now->format(\DateTime::ISO8601), $type.'started');
try {
switch ($type) {
case 'email':
$result = $this->operationEmail($operation);
break;
case 'ftp':
$result = $this->operationFtp($operation);
break;
case 'sftp':
$result = $this->operationSftp($operation);
break;
case 's3':
$result = $this->operationS3($operation);
break;
}
} catch (\Exception $e) {
$message = 'Unable to send file to '.$type.': '.$e->getMessage();
$this->setLogs($message, $type.'error');
}
if ($result) {
++$successCount;
}
}
}
}
if (!$attemptCount) {
$this->setLogs(
'No file send operations are enabled. Please add a file send operation to be tested',
'error'
);
} elseif ($successCount === $attemptCount) {
$this->file->setStatus(File::STATUS_SENT);
$this->valid = true;
} elseif ($successCount < $attemptCount) {
$this->file->setStatus(File::STATUS_ERROR);
$this->valid = false;
}
$this->setLogs($this->file->getStatus(), 'fileStatus');
$this->setLogs($this->valid, 'valid');
$this->fileEntityAddLogs();
$this->fileEntitySave();
return $this;
} | [
"private",
"function",
"fileSend",
"(",
")",
"{",
"$",
"attemptCount",
"=",
"0",
";",
"$",
"successCount",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"->",
"operations",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"payload",
"->",
"operations",
"as",
"$",
"type",
"=>",
"$",
"operation",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"operation",
")",
")",
"{",
"++",
"$",
"attemptCount",
";",
"$",
"result",
"=",
"false",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"now",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"ISO8601",
")",
",",
"$",
"type",
".",
"'started'",
")",
";",
"try",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'email'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"operationEmail",
"(",
"$",
"operation",
")",
";",
"break",
";",
"case",
"'ftp'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"operationFtp",
"(",
"$",
"operation",
")",
";",
"break",
";",
"case",
"'sftp'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"operationSftp",
"(",
"$",
"operation",
")",
";",
"break",
";",
"case",
"'s3'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"operationS3",
"(",
"$",
"operation",
")",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"'Unable to send file to '",
".",
"$",
"type",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"message",
",",
"$",
"type",
".",
"'error'",
")",
";",
"}",
"if",
"(",
"$",
"result",
")",
"{",
"++",
"$",
"successCount",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"attemptCount",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'No file send operations are enabled. Please add a file send operation to be tested'",
",",
"'error'",
")",
";",
"}",
"elseif",
"(",
"$",
"successCount",
"===",
"$",
"attemptCount",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setStatus",
"(",
"File",
"::",
"STATUS_SENT",
")",
";",
"$",
"this",
"->",
"valid",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"successCount",
"<",
"$",
"attemptCount",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setStatus",
"(",
"File",
"::",
"STATUS_ERROR",
")",
";",
"$",
"this",
"->",
"valid",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getStatus",
"(",
")",
",",
"'fileStatus'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"valid",
",",
"'valid'",
")",
";",
"$",
"this",
"->",
"fileEntityAddLogs",
"(",
")",
";",
"$",
"this",
"->",
"fileEntitySave",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | By cron/cli send appropriate files for this time. | [
"By",
"cron",
"/",
"cli",
"send",
"appropriate",
"files",
"for",
"this",
"time",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1369-L1426 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.operationEmail | private function operationEmail($operation)
{
if ($this->test) {
$to = !empty($operation->test) ? $operation->test : (!empty($operation->to) ? $operation->to : '');
} else {
$to = !empty($operation->to) ? $operation->to : '';
}
if (!$to) {
$this->setLogs('Email to address is invalid. No email will be sent.', 'error');
return false;
}
$from = (isset($operation->from) && !empty(trim($operation->from)))
? $operation->from : $this->getIntegrationSetting('email_from');
$email = new Email();
$email->setSessionId('new_'.hash('sha1', uniqid(mt_rand())));
$email->setReplyToAddress($from);
$email->setFromAddress($from);
$subject = (isset($operation->subject) && !empty(trim($operation->subject)))
? $operation->subject : $this->file->getName();
$email->setSubject($subject);
if ($this->file->getCount()) {
$body = (isset($operation->successMessage) && !empty(trim($operation->successMessage)))
? $operation->successMessage : $this->getIntegrationSetting('success_message');
} else {
$body = (isset($operation->emptyMessage) && !empty(trim($operation->emptyMessage)))
? $operation->emptyMessage : $this->getIntegrationSetting('empty_message');
}
$body .= PHP_EOL.PHP_EOL.((isset($operation->footer) && !empty(trim($operation->footer)))
? $operation->footer : $this->getIntegrationSetting('footer'));
$email->setContent($body);
$email->setCustomHtml(htmlentities($body));
/** @var MailHelper $mailer */
$mailer = $this->mailHelper->getMailer();
$mailer->setLead(null, true);
$mailer->setTokens([]);
$to = (!empty($to)) ? array_fill_keys(array_map('trim', explode(',', $to)), null) : [];
$mailer->setTo($to);
$mailer->setFrom($from);
$mailer->setEmail($email);
$mailer->attachFile($this->file->getLocation(), $this->file->getName());
$this->setLogs($to, 'emailTo');
$this->setLogs($from, 'emailFrom');
$this->setLogs($subject, 'emailSubject');
$this->setLogs($body, 'emailbody');
// $mailer->setBody($email);
// $mailer->setEmail($to, false, $emailSettings[$emailId]['slots'], $assetAttachments, (!$saveStat));
// $mailer->setCc($cc);
// $mailer->setBcc($bcc);
// [ENG-683] start/stop transport as suggested by http://www.prowebdev.us/2013/06/swiftmailersymfony2-expected-response.html and
// https://github.com/php-pm/php-pm-httpkernel/issues/62#issuecomment-410667217
$repeatSend = true;
$sendTry = 1;
while ($repeatSend || $sendTry < 4) {
if (!$mailer->getTransport()->isStarted()) {
$mailer->getTransport()->start();
}
$mailResult = $mailer->send(false, false);
if ($errors = $mailer->getErrors()) {
$this->setLogs($errors, 'sendError');
} else {
$repeatSend = false;
}
++$sendTry;
$mailer->getTransport()->stop();
}
return $mailResult;
} | php | private function operationEmail($operation)
{
if ($this->test) {
$to = !empty($operation->test) ? $operation->test : (!empty($operation->to) ? $operation->to : '');
} else {
$to = !empty($operation->to) ? $operation->to : '';
}
if (!$to) {
$this->setLogs('Email to address is invalid. No email will be sent.', 'error');
return false;
}
$from = (isset($operation->from) && !empty(trim($operation->from)))
? $operation->from : $this->getIntegrationSetting('email_from');
$email = new Email();
$email->setSessionId('new_'.hash('sha1', uniqid(mt_rand())));
$email->setReplyToAddress($from);
$email->setFromAddress($from);
$subject = (isset($operation->subject) && !empty(trim($operation->subject)))
? $operation->subject : $this->file->getName();
$email->setSubject($subject);
if ($this->file->getCount()) {
$body = (isset($operation->successMessage) && !empty(trim($operation->successMessage)))
? $operation->successMessage : $this->getIntegrationSetting('success_message');
} else {
$body = (isset($operation->emptyMessage) && !empty(trim($operation->emptyMessage)))
? $operation->emptyMessage : $this->getIntegrationSetting('empty_message');
}
$body .= PHP_EOL.PHP_EOL.((isset($operation->footer) && !empty(trim($operation->footer)))
? $operation->footer : $this->getIntegrationSetting('footer'));
$email->setContent($body);
$email->setCustomHtml(htmlentities($body));
/** @var MailHelper $mailer */
$mailer = $this->mailHelper->getMailer();
$mailer->setLead(null, true);
$mailer->setTokens([]);
$to = (!empty($to)) ? array_fill_keys(array_map('trim', explode(',', $to)), null) : [];
$mailer->setTo($to);
$mailer->setFrom($from);
$mailer->setEmail($email);
$mailer->attachFile($this->file->getLocation(), $this->file->getName());
$this->setLogs($to, 'emailTo');
$this->setLogs($from, 'emailFrom');
$this->setLogs($subject, 'emailSubject');
$this->setLogs($body, 'emailbody');
// $mailer->setBody($email);
// $mailer->setEmail($to, false, $emailSettings[$emailId]['slots'], $assetAttachments, (!$saveStat));
// $mailer->setCc($cc);
// $mailer->setBcc($bcc);
// [ENG-683] start/stop transport as suggested by http://www.prowebdev.us/2013/06/swiftmailersymfony2-expected-response.html and
// https://github.com/php-pm/php-pm-httpkernel/issues/62#issuecomment-410667217
$repeatSend = true;
$sendTry = 1;
while ($repeatSend || $sendTry < 4) {
if (!$mailer->getTransport()->isStarted()) {
$mailer->getTransport()->start();
}
$mailResult = $mailer->send(false, false);
if ($errors = $mailer->getErrors()) {
$this->setLogs($errors, 'sendError');
} else {
$repeatSend = false;
}
++$sendTry;
$mailer->getTransport()->stop();
}
return $mailResult;
} | [
"private",
"function",
"operationEmail",
"(",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"to",
"=",
"!",
"empty",
"(",
"$",
"operation",
"->",
"test",
")",
"?",
"$",
"operation",
"->",
"test",
":",
"(",
"!",
"empty",
"(",
"$",
"operation",
"->",
"to",
")",
"?",
"$",
"operation",
"->",
"to",
":",
"''",
")",
";",
"}",
"else",
"{",
"$",
"to",
"=",
"!",
"empty",
"(",
"$",
"operation",
"->",
"to",
")",
"?",
"$",
"operation",
"->",
"to",
":",
"''",
";",
"}",
"if",
"(",
"!",
"$",
"to",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Email to address is invalid. No email will be sent.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"$",
"from",
"=",
"(",
"isset",
"(",
"$",
"operation",
"->",
"from",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"operation",
"->",
"from",
")",
")",
")",
"?",
"$",
"operation",
"->",
"from",
":",
"$",
"this",
"->",
"getIntegrationSetting",
"(",
"'email_from'",
")",
";",
"$",
"email",
"=",
"new",
"Email",
"(",
")",
";",
"$",
"email",
"->",
"setSessionId",
"(",
"'new_'",
".",
"hash",
"(",
"'sha1'",
",",
"uniqid",
"(",
"mt_rand",
"(",
")",
")",
")",
")",
";",
"$",
"email",
"->",
"setReplyToAddress",
"(",
"$",
"from",
")",
";",
"$",
"email",
"->",
"setFromAddress",
"(",
"$",
"from",
")",
";",
"$",
"subject",
"=",
"(",
"isset",
"(",
"$",
"operation",
"->",
"subject",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"operation",
"->",
"subject",
")",
")",
")",
"?",
"$",
"operation",
"->",
"subject",
":",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
";",
"$",
"email",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"if",
"(",
"$",
"this",
"->",
"file",
"->",
"getCount",
"(",
")",
")",
"{",
"$",
"body",
"=",
"(",
"isset",
"(",
"$",
"operation",
"->",
"successMessage",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"operation",
"->",
"successMessage",
")",
")",
")",
"?",
"$",
"operation",
"->",
"successMessage",
":",
"$",
"this",
"->",
"getIntegrationSetting",
"(",
"'success_message'",
")",
";",
"}",
"else",
"{",
"$",
"body",
"=",
"(",
"isset",
"(",
"$",
"operation",
"->",
"emptyMessage",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"operation",
"->",
"emptyMessage",
")",
")",
")",
"?",
"$",
"operation",
"->",
"emptyMessage",
":",
"$",
"this",
"->",
"getIntegrationSetting",
"(",
"'empty_message'",
")",
";",
"}",
"$",
"body",
".=",
"PHP_EOL",
".",
"PHP_EOL",
".",
"(",
"(",
"isset",
"(",
"$",
"operation",
"->",
"footer",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"operation",
"->",
"footer",
")",
")",
")",
"?",
"$",
"operation",
"->",
"footer",
":",
"$",
"this",
"->",
"getIntegrationSetting",
"(",
"'footer'",
")",
")",
";",
"$",
"email",
"->",
"setContent",
"(",
"$",
"body",
")",
";",
"$",
"email",
"->",
"setCustomHtml",
"(",
"htmlentities",
"(",
"$",
"body",
")",
")",
";",
"/** @var MailHelper $mailer */",
"$",
"mailer",
"=",
"$",
"this",
"->",
"mailHelper",
"->",
"getMailer",
"(",
")",
";",
"$",
"mailer",
"->",
"setLead",
"(",
"null",
",",
"true",
")",
";",
"$",
"mailer",
"->",
"setTokens",
"(",
"[",
"]",
")",
";",
"$",
"to",
"=",
"(",
"!",
"empty",
"(",
"$",
"to",
")",
")",
"?",
"array_fill_keys",
"(",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"to",
")",
")",
",",
"null",
")",
":",
"[",
"]",
";",
"$",
"mailer",
"->",
"setTo",
"(",
"$",
"to",
")",
";",
"$",
"mailer",
"->",
"setFrom",
"(",
"$",
"from",
")",
";",
"$",
"mailer",
"->",
"setEmail",
"(",
"$",
"email",
")",
";",
"$",
"mailer",
"->",
"attachFile",
"(",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
",",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"to",
",",
"'emailTo'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"from",
",",
"'emailFrom'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"subject",
",",
"'emailSubject'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"body",
",",
"'emailbody'",
")",
";",
"// $mailer->setBody($email);",
"// $mailer->setEmail($to, false, $emailSettings[$emailId]['slots'], $assetAttachments, (!$saveStat));",
"// $mailer->setCc($cc);",
"// $mailer->setBcc($bcc);",
"// [ENG-683] start/stop transport as suggested by http://www.prowebdev.us/2013/06/swiftmailersymfony2-expected-response.html and",
"// https://github.com/php-pm/php-pm-httpkernel/issues/62#issuecomment-410667217",
"$",
"repeatSend",
"=",
"true",
";",
"$",
"sendTry",
"=",
"1",
";",
"while",
"(",
"$",
"repeatSend",
"||",
"$",
"sendTry",
"<",
"4",
")",
"{",
"if",
"(",
"!",
"$",
"mailer",
"->",
"getTransport",
"(",
")",
"->",
"isStarted",
"(",
")",
")",
"{",
"$",
"mailer",
"->",
"getTransport",
"(",
")",
"->",
"start",
"(",
")",
";",
"}",
"$",
"mailResult",
"=",
"$",
"mailer",
"->",
"send",
"(",
"false",
",",
"false",
")",
";",
"if",
"(",
"$",
"errors",
"=",
"$",
"mailer",
"->",
"getErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"errors",
",",
"'sendError'",
")",
";",
"}",
"else",
"{",
"$",
"repeatSend",
"=",
"false",
";",
"}",
"++",
"$",
"sendTry",
";",
"$",
"mailer",
"->",
"getTransport",
"(",
")",
"->",
"stop",
"(",
")",
";",
"}",
"return",
"$",
"mailResult",
";",
"}"
] | Send an email containing the file to the current client by Email.
@param $operation
@return bool | [
"Send",
"an",
"email",
"containing",
"the",
"file",
"to",
"the",
"current",
"client",
"by",
"Email",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1435-L1508 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.operationFtpConfig | private function operationFtpConfig($operation)
{
$config = [];
$config['host'] = isset($operation->host) ? trim($operation->host) : null;
if (!$config['host']) {
$this->setLogs('Host is required.', 'error');
return false;
} else {
// Remove schema/port/etc from the host.
$host = parse_url($config['host'], PHP_URL_HOST);
if ($host) {
$config['host'] = $host;
}
$this->setLogs($config['host'], 'host');
}
$config['username'] = isset($operation->user) ? trim($operation->user) : null;
if (!$config['username']) {
$this->setLogs('User is required.', 'error');
return false;
} else {
$this->setLogs($config['username'], 'user');
}
$config['password'] = isset($operation->pass) ? trim($operation->pass) : null;
if (!$config['password']) {
unset($config['password']);
$this->setLogs('Password is blank. Assuming anonymous access.', 'warning');
} else {
$this->setLogs(str_repeat('*', strlen($config['password'])), 'password');
}
$config['privateKey'] = isset($operation->privateKey) ? trim($operation->privateKey) : null;
if (!$config['privateKey']) {
unset($config['privateKey']);
} else {
$this->setLogs(true, 'privateKey');
}
$config['port'] = isset($operation->port) ? (int) $operation->port : null;
if (!$config['port']) {
unset($config['port']);
} else {
$this->setLogs($config['port'], 'port');
}
if ($this->test && isset($operation->rootTest)) {
$config['root'] = isset($operation->rootTest) ? trim($operation->rootTest) : null;
}
if (empty($config['root'])) {
$config['root'] = isset($operation->root) ? trim($operation->root) : null;
}
if (!$config['root']) {
unset($config['root']);
} else {
$this->setLogs($config['root'], 'root');
}
$config['passive'] = isset($operation->passive) ? (bool) $operation->passive : true;
$this->setLogs($config['passive'], 'passive');
$config['timeout'] = isset($operation->timeout) ? (int) $operation->timeout : 90;
$this->setLogs($config['timeout'], 'timeout');
$config['ssl'] = isset($operation->ssl) ? (bool) $operation->ssl : false;
$this->setLogs($config['ssl'], 'ssl');
return $config;
} | php | private function operationFtpConfig($operation)
{
$config = [];
$config['host'] = isset($operation->host) ? trim($operation->host) : null;
if (!$config['host']) {
$this->setLogs('Host is required.', 'error');
return false;
} else {
// Remove schema/port/etc from the host.
$host = parse_url($config['host'], PHP_URL_HOST);
if ($host) {
$config['host'] = $host;
}
$this->setLogs($config['host'], 'host');
}
$config['username'] = isset($operation->user) ? trim($operation->user) : null;
if (!$config['username']) {
$this->setLogs('User is required.', 'error');
return false;
} else {
$this->setLogs($config['username'], 'user');
}
$config['password'] = isset($operation->pass) ? trim($operation->pass) : null;
if (!$config['password']) {
unset($config['password']);
$this->setLogs('Password is blank. Assuming anonymous access.', 'warning');
} else {
$this->setLogs(str_repeat('*', strlen($config['password'])), 'password');
}
$config['privateKey'] = isset($operation->privateKey) ? trim($operation->privateKey) : null;
if (!$config['privateKey']) {
unset($config['privateKey']);
} else {
$this->setLogs(true, 'privateKey');
}
$config['port'] = isset($operation->port) ? (int) $operation->port : null;
if (!$config['port']) {
unset($config['port']);
} else {
$this->setLogs($config['port'], 'port');
}
if ($this->test && isset($operation->rootTest)) {
$config['root'] = isset($operation->rootTest) ? trim($operation->rootTest) : null;
}
if (empty($config['root'])) {
$config['root'] = isset($operation->root) ? trim($operation->root) : null;
}
if (!$config['root']) {
unset($config['root']);
} else {
$this->setLogs($config['root'], 'root');
}
$config['passive'] = isset($operation->passive) ? (bool) $operation->passive : true;
$this->setLogs($config['passive'], 'passive');
$config['timeout'] = isset($operation->timeout) ? (int) $operation->timeout : 90;
$this->setLogs($config['timeout'], 'timeout');
$config['ssl'] = isset($operation->ssl) ? (bool) $operation->ssl : false;
$this->setLogs($config['ssl'], 'ssl');
return $config;
} | [
"private",
"function",
"operationFtpConfig",
"(",
"$",
"operation",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"$",
"config",
"[",
"'host'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"host",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"host",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'host'",
"]",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Host is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"// Remove schema/port/etc from the host.",
"$",
"host",
"=",
"parse_url",
"(",
"$",
"config",
"[",
"'host'",
"]",
",",
"PHP_URL_HOST",
")",
";",
"if",
"(",
"$",
"host",
")",
"{",
"$",
"config",
"[",
"'host'",
"]",
"=",
"$",
"host",
";",
"}",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'host'",
"]",
",",
"'host'",
")",
";",
"}",
"$",
"config",
"[",
"'username'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"user",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"user",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'username'",
"]",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'User is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'username'",
"]",
",",
"'user'",
")",
";",
"}",
"$",
"config",
"[",
"'password'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"pass",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"pass",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'password'",
"]",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"'password'",
"]",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"'Password is blank. Assuming anonymous access.'",
",",
"'warning'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"str_repeat",
"(",
"'*'",
",",
"strlen",
"(",
"$",
"config",
"[",
"'password'",
"]",
")",
")",
",",
"'password'",
")",
";",
"}",
"$",
"config",
"[",
"'privateKey'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"privateKey",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"privateKey",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'privateKey'",
"]",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"'privateKey'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"true",
",",
"'privateKey'",
")",
";",
"}",
"$",
"config",
"[",
"'port'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"port",
")",
"?",
"(",
"int",
")",
"$",
"operation",
"->",
"port",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'port'",
"]",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"'port'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'port'",
"]",
",",
"'port'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"test",
"&&",
"isset",
"(",
"$",
"operation",
"->",
"rootTest",
")",
")",
"{",
"$",
"config",
"[",
"'root'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"rootTest",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"rootTest",
")",
":",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'root'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'root'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"root",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"root",
")",
":",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"config",
"[",
"'root'",
"]",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"'root'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'root'",
"]",
",",
"'root'",
")",
";",
"}",
"$",
"config",
"[",
"'passive'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"passive",
")",
"?",
"(",
"bool",
")",
"$",
"operation",
"->",
"passive",
":",
"true",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'passive'",
"]",
",",
"'passive'",
")",
";",
"$",
"config",
"[",
"'timeout'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"timeout",
")",
"?",
"(",
"int",
")",
"$",
"operation",
"->",
"timeout",
":",
"90",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'timeout'",
"]",
",",
"'timeout'",
")",
";",
"$",
"config",
"[",
"'ssl'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"ssl",
")",
"?",
"(",
"bool",
")",
"$",
"operation",
"->",
"ssl",
":",
"false",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'ssl'",
"]",
",",
"'ssl'",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Given the operation array, construct configuration array for a FTP/SFTP adaptor.
@param $operation
@return array|bool | [
"Given",
"the",
"operation",
"array",
"construct",
"configuration",
"array",
"for",
"a",
"FTP",
"/",
"SFTP",
"adaptor",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1574-L1642 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.operationSftp | private function operationSftp($operation)
{
$config = $this->operationFtpConfig($operation);
$adapter = new SftpAdapter($config);
$filesystem = new Filesystem($adapter);
$written = false;
if ($stream = fopen($this->file->getLocation(), 'r+')) {
$this->setLogs($this->file->getLocation(), 'sftpUploading');
$written = $filesystem->writeStream($this->file->getName(), $stream);
if (is_resource($stream)) {
fclose($stream);
}
$this->setLogs($written, 'sftpConfirmed');
if (!$written) {
$this->setLogs('Could not confirm file upload via SFTP', 'error');
} else {
$this->setLogs($filesystem->has($this->file->getName()), 'sftpConfirmed2');
}
} else {
$this->setLogs('Unable to open file for upload via SFTP.', 'error');
}
return $written;
} | php | private function operationSftp($operation)
{
$config = $this->operationFtpConfig($operation);
$adapter = new SftpAdapter($config);
$filesystem = new Filesystem($adapter);
$written = false;
if ($stream = fopen($this->file->getLocation(), 'r+')) {
$this->setLogs($this->file->getLocation(), 'sftpUploading');
$written = $filesystem->writeStream($this->file->getName(), $stream);
if (is_resource($stream)) {
fclose($stream);
}
$this->setLogs($written, 'sftpConfirmed');
if (!$written) {
$this->setLogs('Could not confirm file upload via SFTP', 'error');
} else {
$this->setLogs($filesystem->has($this->file->getName()), 'sftpConfirmed2');
}
} else {
$this->setLogs('Unable to open file for upload via SFTP.', 'error');
}
return $written;
} | [
"private",
"function",
"operationSftp",
"(",
"$",
"operation",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"operationFtpConfig",
"(",
"$",
"operation",
")",
";",
"$",
"adapter",
"=",
"new",
"SftpAdapter",
"(",
"$",
"config",
")",
";",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
"$",
"adapter",
")",
";",
"$",
"written",
"=",
"false",
";",
"if",
"(",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
",",
"'r+'",
")",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
",",
"'sftpUploading'",
")",
";",
"$",
"written",
"=",
"$",
"filesystem",
"->",
"writeStream",
"(",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
",",
"$",
"stream",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"stream",
")",
")",
"{",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"written",
",",
"'sftpConfirmed'",
")",
";",
"if",
"(",
"!",
"$",
"written",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Could not confirm file upload via SFTP'",
",",
"'error'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"filesystem",
"->",
"has",
"(",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
")",
",",
"'sftpConfirmed2'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Unable to open file for upload via SFTP.'",
",",
"'error'",
")",
";",
"}",
"return",
"$",
"written",
";",
"}"
] | Upload the current client file by sFTP.
@param $operation
@return bool | [
"Upload",
"the",
"current",
"client",
"file",
"by",
"sFTP",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1651-L1676 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.operationS3 | private function operationS3($operation)
{
$config = [];
$config['key'] = isset($operation->key) ? trim($operation->key) : null;
if (!$config['key']) {
$this->setLogs('Key is required.', 'error');
return false;
} else {
$this->setLogs($config['key'], 'key');
}
$config['secret'] = isset($operation->secret) ? trim($operation->secret) : null;
if (!$config['secret']) {
$this->setLogs('Secret is required.', 'error');
return false;
} else {
$this->setLogs(true, 'secret');
}
$config['region'] = isset($operation->region) ? trim($operation->region) : null;
if (!$config['region']) {
$this->setLogs('Region is required.', 'error');
return false;
} else {
$this->setLogs($config['region'], 'region');
}
$bucketName = isset($operation->bucket) ? trim($operation->bucket) : null;
if (!$bucketName) {
$this->setLogs('Bucket name is required.', 'error');
return false;
} else {
$this->setLogs($bucketName, 'bucket');
}
if ($this->test && isset($operation->rootTest)) {
$root = isset($operation->rootTest) ? trim($operation->rootTest) : null;
}
if (empty($root)) {
$root = isset($operation->root) ? trim($operation->root) : null;
}
if ($root) {
$this->setLogs($root, 'root');
}
$client = S3Client::factory($config);
$adapter = new AwsS3Adapter($client, $bucketName, $root);
$filesystem = new Filesystem($adapter);
$written = false;
if ($stream = fopen($this->file->getLocation(), 'r+')) {
$this->setLogs($this->file->getLocation(), 's3Uploading');
$written = $filesystem->writeStream($this->file->getName(), $stream);
if (is_resource($stream)) {
fclose($stream);
}
// $written = $written ? $filesystem->has($this->file->getName()) : false;
$this->setLogs($written, 's3Confirmed');
if (!$written) {
$this->setLogs('Could not confirm file upload via S3', 'error');
}
} else {
$this->setLogs('Unable to open file for upload via S3.', 'error');
}
return $written;
} | php | private function operationS3($operation)
{
$config = [];
$config['key'] = isset($operation->key) ? trim($operation->key) : null;
if (!$config['key']) {
$this->setLogs('Key is required.', 'error');
return false;
} else {
$this->setLogs($config['key'], 'key');
}
$config['secret'] = isset($operation->secret) ? trim($operation->secret) : null;
if (!$config['secret']) {
$this->setLogs('Secret is required.', 'error');
return false;
} else {
$this->setLogs(true, 'secret');
}
$config['region'] = isset($operation->region) ? trim($operation->region) : null;
if (!$config['region']) {
$this->setLogs('Region is required.', 'error');
return false;
} else {
$this->setLogs($config['region'], 'region');
}
$bucketName = isset($operation->bucket) ? trim($operation->bucket) : null;
if (!$bucketName) {
$this->setLogs('Bucket name is required.', 'error');
return false;
} else {
$this->setLogs($bucketName, 'bucket');
}
if ($this->test && isset($operation->rootTest)) {
$root = isset($operation->rootTest) ? trim($operation->rootTest) : null;
}
if (empty($root)) {
$root = isset($operation->root) ? trim($operation->root) : null;
}
if ($root) {
$this->setLogs($root, 'root');
}
$client = S3Client::factory($config);
$adapter = new AwsS3Adapter($client, $bucketName, $root);
$filesystem = new Filesystem($adapter);
$written = false;
if ($stream = fopen($this->file->getLocation(), 'r+')) {
$this->setLogs($this->file->getLocation(), 's3Uploading');
$written = $filesystem->writeStream($this->file->getName(), $stream);
if (is_resource($stream)) {
fclose($stream);
}
// $written = $written ? $filesystem->has($this->file->getName()) : false;
$this->setLogs($written, 's3Confirmed');
if (!$written) {
$this->setLogs('Could not confirm file upload via S3', 'error');
}
} else {
$this->setLogs('Unable to open file for upload via S3.', 'error');
}
return $written;
} | [
"private",
"function",
"operationS3",
"(",
"$",
"operation",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"$",
"config",
"[",
"'key'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"key",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"key",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'key'",
"]",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Key is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'key'",
"]",
",",
"'key'",
")",
";",
"}",
"$",
"config",
"[",
"'secret'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"secret",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"secret",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'secret'",
"]",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Secret is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"true",
",",
"'secret'",
")",
";",
"}",
"$",
"config",
"[",
"'region'",
"]",
"=",
"isset",
"(",
"$",
"operation",
"->",
"region",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"region",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'region'",
"]",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Region is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"config",
"[",
"'region'",
"]",
",",
"'region'",
")",
";",
"}",
"$",
"bucketName",
"=",
"isset",
"(",
"$",
"operation",
"->",
"bucket",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"bucket",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"bucketName",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Bucket name is required.'",
",",
"'error'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"bucketName",
",",
"'bucket'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"test",
"&&",
"isset",
"(",
"$",
"operation",
"->",
"rootTest",
")",
")",
"{",
"$",
"root",
"=",
"isset",
"(",
"$",
"operation",
"->",
"rootTest",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"rootTest",
")",
":",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"root",
")",
")",
"{",
"$",
"root",
"=",
"isset",
"(",
"$",
"operation",
"->",
"root",
")",
"?",
"trim",
"(",
"$",
"operation",
"->",
"root",
")",
":",
"null",
";",
"}",
"if",
"(",
"$",
"root",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"root",
",",
"'root'",
")",
";",
"}",
"$",
"client",
"=",
"S3Client",
"::",
"factory",
"(",
"$",
"config",
")",
";",
"$",
"adapter",
"=",
"new",
"AwsS3Adapter",
"(",
"$",
"client",
",",
"$",
"bucketName",
",",
"$",
"root",
")",
";",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
"$",
"adapter",
")",
";",
"$",
"written",
"=",
"false",
";",
"if",
"(",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
",",
"'r+'",
")",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"file",
"->",
"getLocation",
"(",
")",
",",
"'s3Uploading'",
")",
";",
"$",
"written",
"=",
"$",
"filesystem",
"->",
"writeStream",
"(",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
",",
"$",
"stream",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"stream",
")",
")",
"{",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"// $written = $written ? $filesystem->has($this->file->getName()) : false;",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"written",
",",
"'s3Confirmed'",
")",
";",
"if",
"(",
"!",
"$",
"written",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Could not confirm file upload via S3'",
",",
"'error'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Unable to open file for upload via S3.'",
",",
"'error'",
")",
";",
"}",
"return",
"$",
"written",
";",
"}"
] | @param $operation
@return bool | [
"@param",
"$operation"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1683-L1753 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.setCampaign | public function setCampaign(Campaign $campaign = null)
{
if ($campaign) {
$this->setLogs($campaign->getId(), 'campaignId');
$this->campaign = $campaign;
}
return $this;
} | php | public function setCampaign(Campaign $campaign = null)
{
if ($campaign) {
$this->setLogs($campaign->getId(), 'campaignId');
$this->campaign = $campaign;
}
return $this;
} | [
"public",
"function",
"setCampaign",
"(",
"Campaign",
"$",
"campaign",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"campaign",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"campaign",
"->",
"getId",
"(",
")",
",",
"'campaignId'",
")",
";",
"$",
"this",
"->",
"campaign",
"=",
"$",
"campaign",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Campaign|null $campaign
@return $this | [
"@param",
"Campaign|null",
"$campaign"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1788-L1796 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.getOverrides | public function getOverrides()
{
$result = [];
if (isset($this->payload->body)) {
foreach ($this->payload->body as $field) {
if (isset($field->overridable) && true === $field->overridable) {
// Remove irrelevant data, since this result will need to be light-weight.
unset($field->default_value);
unset($field->test_value);
unset($field->test_only);
unset($field->overridable);
unset($field->required);
$result[(string) $field->key] = $field;
}
}
}
ksort($result);
return array_values($result);
} | php | public function getOverrides()
{
$result = [];
if (isset($this->payload->body)) {
foreach ($this->payload->body as $field) {
if (isset($field->overridable) && true === $field->overridable) {
// Remove irrelevant data, since this result will need to be light-weight.
unset($field->default_value);
unset($field->test_value);
unset($field->test_only);
unset($field->overridable);
unset($field->required);
$result[(string) $field->key] = $field;
}
}
}
ksort($result);
return array_values($result);
} | [
"public",
"function",
"getOverrides",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"payload",
"->",
"body",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"field",
"->",
"overridable",
")",
"&&",
"true",
"===",
"$",
"field",
"->",
"overridable",
")",
"{",
"// Remove irrelevant data, since this result will need to be light-weight.",
"unset",
"(",
"$",
"field",
"->",
"default_value",
")",
";",
"unset",
"(",
"$",
"field",
"->",
"test_value",
")",
";",
"unset",
"(",
"$",
"field",
"->",
"test_only",
")",
";",
"unset",
"(",
"$",
"field",
"->",
"overridable",
")",
";",
"unset",
"(",
"$",
"field",
"->",
"required",
")",
";",
"$",
"result",
"[",
"(",
"string",
")",
"$",
"field",
"->",
"key",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"}",
"ksort",
"(",
"$",
"result",
")",
";",
"return",
"array_values",
"(",
"$",
"result",
")",
";",
"}"
] | Retrieve from the payload all outgoing fields that are set to overridable.
@return array | [
"Retrieve",
"from",
"the",
"payload",
"all",
"outgoing",
"fields",
"that",
"are",
"set",
"to",
"overridable",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1803-L1822 |
TheDMSGroup/mautic-contact-client | Model/FilePayload.php | FilePayload.getExternalId | public function getExternalId()
{
if ($this->file && $this->file->getCrc32()) {
return $this->file->getName().' ('.$this->file->getCrc32().')';
}
return null;
} | php | public function getExternalId()
{
if ($this->file && $this->file->getCrc32()) {
return $this->file->getName().' ('.$this->file->getCrc32().')';
}
return null;
} | [
"public",
"function",
"getExternalId",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"file",
"&&",
"$",
"this",
"->",
"file",
"->",
"getCrc32",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
".",
"' ('",
".",
"$",
"this",
"->",
"file",
"->",
"getCrc32",
"(",
")",
".",
"')'",
";",
"}",
"return",
"null",
";",
"}"
] | Since there is no external ID when sending files, we'll include the file name and CRC check at creation.
@return null|string | [
"Since",
"there",
"is",
"no",
"external",
"ID",
"when",
"sending",
"files",
"we",
"ll",
"include",
"the",
"file",
"name",
"and",
"CRC",
"check",
"at",
"creation",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Model/FilePayload.php#L1829-L1836 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.pushLead | public function pushLead($contact, $event = [])
{
$this->reset();
$this->getEvent($event);
if (empty($this->event['config']['contactclient'])) {
return false;
}
/** @var Contact $contactModel */
$clientModel = $this->getContactClientModel();
$client = $clientModel->getEntity($this->event['config']['contactclient']);
$this->sendContact($client, $contact, false);
// Returning false will typically cause a retry.
// If an error occurred and we do not wish to retry we should return true.
return $this->valid ? $this->valid : !$this->retry;
} | php | public function pushLead($contact, $event = [])
{
$this->reset();
$this->getEvent($event);
if (empty($this->event['config']['contactclient'])) {
return false;
}
/** @var Contact $contactModel */
$clientModel = $this->getContactClientModel();
$client = $clientModel->getEntity($this->event['config']['contactclient']);
$this->sendContact($client, $contact, false);
// Returning false will typically cause a retry.
// If an error occurred and we do not wish to retry we should return true.
return $this->valid ? $this->valid : !$this->retry;
} | [
"public",
"function",
"pushLead",
"(",
"$",
"contact",
",",
"$",
"event",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"this",
"->",
"getEvent",
"(",
"$",
"event",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"event",
"[",
"'config'",
"]",
"[",
"'contactclient'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"/** @var Contact $contactModel */",
"$",
"clientModel",
"=",
"$",
"this",
"->",
"getContactClientModel",
"(",
")",
";",
"$",
"client",
"=",
"$",
"clientModel",
"->",
"getEntity",
"(",
"$",
"this",
"->",
"event",
"[",
"'config'",
"]",
"[",
"'contactclient'",
"]",
")",
";",
"$",
"this",
"->",
"sendContact",
"(",
"$",
"client",
",",
"$",
"contact",
",",
"false",
")",
";",
"// Returning false will typically cause a retry.",
"// If an error occurred and we do not wish to retry we should return true.",
"return",
"$",
"this",
"->",
"valid",
"?",
"$",
"this",
"->",
"valid",
":",
"!",
"$",
"this",
"->",
"retry",
";",
"}"
] | Push a contact to a preconfigured Contact Client.
@param Contact $contact
@param array $event
@return bool
@throws Exception | [
"Push",
"a",
"contact",
"to",
"a",
"preconfigured",
"Contact",
"Client",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L147-L165 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getEvent | public function getEvent($event = [])
{
if (!$this->event) {
$this->event = $event;
if (isset($event['config'])
&& (empty($event['integration'])
|| (
!empty($event['integration'])
&& $event['integration'] == $this->getName()
)
)
) {
$this->event['config'] = array_merge($this->settings->getFeatureSettings(), $event['config']);
}
if (isset($this->event['campaignEvent']) && !empty($this->event['campaignEvent'])) {
$campaignEvent = $this->event['campaignEvent'];
$this->event['id'] = $campaignEvent['id'];
$this->event['campaignId'] = $campaignEvent['campaign']['id'];
}
// If the campaign event ID is missing, backfill it.
if (!isset($this->event['id']) || !is_numeric($this->event['id'])) {
try {
$identityMap = $this->em->getUnitOfWork()->getIdentityMap();
if (isset($identityMap['Mautic\CampaignBundle\Entity\Event'])) {
if (isset($identityMap['Mautic\CampaignBundle\Entity\Campaign']) && !empty($identityMap['Mautic\CampaignBundle\Entity\Campaign'])) {
$memoryCampaign = end($identityMap['Mautic\CampaignBundle\Entity\Campaign']);
$campaignId = $memoryCampaign->getId();
/** @var \Mautic\CampaignBundle\Entity\Event $leadEvent */
foreach ($identityMap['Mautic\CampaignBundle\Entity\Event'] as $leadEvent) {
$properties = $leadEvent->getProperties();
$campaign = $leadEvent->getCampaign();
if (
$properties['_token'] === $this->event['_token']
&& $campaignId == $campaign->getId()
) {
$this->event['id'] = $leadEvent->getId();
$this->event['name'] = $leadEvent->getName();
$this->event['campaignId'] = $campaign->getId();
break;
}
}
}
}
} catch (\Exception $e) {
}
}
}
return $this->event;
} | php | public function getEvent($event = [])
{
if (!$this->event) {
$this->event = $event;
if (isset($event['config'])
&& (empty($event['integration'])
|| (
!empty($event['integration'])
&& $event['integration'] == $this->getName()
)
)
) {
$this->event['config'] = array_merge($this->settings->getFeatureSettings(), $event['config']);
}
if (isset($this->event['campaignEvent']) && !empty($this->event['campaignEvent'])) {
$campaignEvent = $this->event['campaignEvent'];
$this->event['id'] = $campaignEvent['id'];
$this->event['campaignId'] = $campaignEvent['campaign']['id'];
}
// If the campaign event ID is missing, backfill it.
if (!isset($this->event['id']) || !is_numeric($this->event['id'])) {
try {
$identityMap = $this->em->getUnitOfWork()->getIdentityMap();
if (isset($identityMap['Mautic\CampaignBundle\Entity\Event'])) {
if (isset($identityMap['Mautic\CampaignBundle\Entity\Campaign']) && !empty($identityMap['Mautic\CampaignBundle\Entity\Campaign'])) {
$memoryCampaign = end($identityMap['Mautic\CampaignBundle\Entity\Campaign']);
$campaignId = $memoryCampaign->getId();
/** @var \Mautic\CampaignBundle\Entity\Event $leadEvent */
foreach ($identityMap['Mautic\CampaignBundle\Entity\Event'] as $leadEvent) {
$properties = $leadEvent->getProperties();
$campaign = $leadEvent->getCampaign();
if (
$properties['_token'] === $this->event['_token']
&& $campaignId == $campaign->getId()
) {
$this->event['id'] = $leadEvent->getId();
$this->event['name'] = $leadEvent->getName();
$this->event['campaignId'] = $campaign->getId();
break;
}
}
}
}
} catch (\Exception $e) {
}
}
}
return $this->event;
} | [
"public",
"function",
"getEvent",
"(",
"$",
"event",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"event",
")",
"{",
"$",
"this",
"->",
"event",
"=",
"$",
"event",
";",
"if",
"(",
"isset",
"(",
"$",
"event",
"[",
"'config'",
"]",
")",
"&&",
"(",
"empty",
"(",
"$",
"event",
"[",
"'integration'",
"]",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"event",
"[",
"'integration'",
"]",
")",
"&&",
"$",
"event",
"[",
"'integration'",
"]",
"==",
"$",
"this",
"->",
"getName",
"(",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"event",
"[",
"'config'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"settings",
"->",
"getFeatureSettings",
"(",
")",
",",
"$",
"event",
"[",
"'config'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignEvent'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignEvent'",
"]",
")",
")",
"{",
"$",
"campaignEvent",
"=",
"$",
"this",
"->",
"event",
"[",
"'campaignEvent'",
"]",
";",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
"=",
"$",
"campaignEvent",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
"=",
"$",
"campaignEvent",
"[",
"'campaign'",
"]",
"[",
"'id'",
"]",
";",
"}",
"// If the campaign event ID is missing, backfill it.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
")",
"{",
"try",
"{",
"$",
"identityMap",
"=",
"$",
"this",
"->",
"em",
"->",
"getUnitOfWork",
"(",
")",
"->",
"getIdentityMap",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Event'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
")",
"{",
"$",
"memoryCampaign",
"=",
"end",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
";",
"$",
"campaignId",
"=",
"$",
"memoryCampaign",
"->",
"getId",
"(",
")",
";",
"/** @var \\Mautic\\CampaignBundle\\Entity\\Event $leadEvent */",
"foreach",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Event'",
"]",
"as",
"$",
"leadEvent",
")",
"{",
"$",
"properties",
"=",
"$",
"leadEvent",
"->",
"getProperties",
"(",
")",
";",
"$",
"campaign",
"=",
"$",
"leadEvent",
"->",
"getCampaign",
"(",
")",
";",
"if",
"(",
"$",
"properties",
"[",
"'_token'",
"]",
"===",
"$",
"this",
"->",
"event",
"[",
"'_token'",
"]",
"&&",
"$",
"campaignId",
"==",
"$",
"campaign",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
"=",
"$",
"leadEvent",
"->",
"getId",
"(",
")",
";",
"$",
"this",
"->",
"event",
"[",
"'name'",
"]",
"=",
"$",
"leadEvent",
"->",
"getName",
"(",
")",
";",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
"=",
"$",
"campaign",
"->",
"getId",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"event",
";",
"}"
] | Merges a config from integration_list with feature settings.
@param array $event to merge configuration
@return array|mixed | [
"Merges",
"a",
"config",
"from",
"integration_list",
"with",
"feature",
"settings",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L194-L246 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getContactClientModel | private function getContactClientModel()
{
if (!$this->contactClientModel) {
/* @var ContactClientModel $contactClientModel */
$this->contactClientModel = $this->getContainer()->get('mautic.contactclient.model.contactclient');
}
return $this->contactClientModel;
} | php | private function getContactClientModel()
{
if (!$this->contactClientModel) {
/* @var ContactClientModel $contactClientModel */
$this->contactClientModel = $this->getContainer()->get('mautic.contactclient.model.contactclient');
}
return $this->contactClientModel;
} | [
"private",
"function",
"getContactClientModel",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"contactClientModel",
")",
"{",
"/* @var ContactClientModel $contactClientModel */",
"$",
"this",
"->",
"contactClientModel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.contactclient.model.contactclient'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"contactClientModel",
";",
"}"
] | @return ContactClientModel|object
@throws Exception | [
"@return",
"ContactClientModel|object"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L263-L271 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.sendContact | public function sendContact(
ContactClient $client = null,
Contact $contact = null,
$test = false,
$force = false
) {
if (!$this->translator) {
$this->translator = $this->getContainer()->get('translator');
}
$this->contactClient = $client;
$this->contact = $contact;
$this->test = $test;
try {
$this->validateClient($client, $force);
$this->addTrace('contactClient', $this->contactClient->getName());
$this->addTrace('contactClientId', $this->contactClient->getId());
$this->validateContact();
// Check all rules that may preclude sending this contact, in order of performance cost.
// Schedule - Check schedule rules to ensure we can send a contact now, do not retry if outside of window.
$this->evaluateSchedule();
// Filter - Check filter rules to ensure this contact is applicable.
$this->evaluateFilter();
// DNC - Check Do Not Contact channels for an entry for this contact that is not permitted for this client.
$this->evaluateDnc();
// Limits - Check limit rules to ensure we have not sent too many contacts in our window.
if (!$this->test) {
$this->getCacheModel()->evaluateLimits();
}
// Duplicates - Check duplicate cache to ensure we have not already sent this contact.
if (!$this->test) {
$this->getCacheModel()->evaluateDuplicate();
}
// Exclusivity - Check exclusivity rules on the cache to ensure this contact hasn't been sent to a disallowed competitor.
if (!$this->test) {
$this->getCacheModel()->evaluateExclusive();
}
/* @var ApiPayload|FilePayload $model */
$this->getPayloadModel($this->contactClient)
->setCampaign($this->getCampaign())
->setEvent($this->event);
// Send all operations (API) or queue the contact (file).
$this->payloadModel->run();
$this->valid = $this->payloadModel->getValid();
if ($this->valid) {
$this->statType = Stat::TYPE_CONVERTED;
}
} catch (\Exception $e) {
$this->handleException($e);
}
if ($this->payloadModel) {
$operationLogs = $this->payloadModel->getLogs();
if ($operationLogs) {
$this->setLogs($operationLogs, 'operations');
}
}
$this->updateContact();
$this->createCache();
$this->logResults();
return $this;
} | php | public function sendContact(
ContactClient $client = null,
Contact $contact = null,
$test = false,
$force = false
) {
if (!$this->translator) {
$this->translator = $this->getContainer()->get('translator');
}
$this->contactClient = $client;
$this->contact = $contact;
$this->test = $test;
try {
$this->validateClient($client, $force);
$this->addTrace('contactClient', $this->contactClient->getName());
$this->addTrace('contactClientId', $this->contactClient->getId());
$this->validateContact();
// Check all rules that may preclude sending this contact, in order of performance cost.
// Schedule - Check schedule rules to ensure we can send a contact now, do not retry if outside of window.
$this->evaluateSchedule();
// Filter - Check filter rules to ensure this contact is applicable.
$this->evaluateFilter();
// DNC - Check Do Not Contact channels for an entry for this contact that is not permitted for this client.
$this->evaluateDnc();
// Limits - Check limit rules to ensure we have not sent too many contacts in our window.
if (!$this->test) {
$this->getCacheModel()->evaluateLimits();
}
// Duplicates - Check duplicate cache to ensure we have not already sent this contact.
if (!$this->test) {
$this->getCacheModel()->evaluateDuplicate();
}
// Exclusivity - Check exclusivity rules on the cache to ensure this contact hasn't been sent to a disallowed competitor.
if (!$this->test) {
$this->getCacheModel()->evaluateExclusive();
}
/* @var ApiPayload|FilePayload $model */
$this->getPayloadModel($this->contactClient)
->setCampaign($this->getCampaign())
->setEvent($this->event);
// Send all operations (API) or queue the contact (file).
$this->payloadModel->run();
$this->valid = $this->payloadModel->getValid();
if ($this->valid) {
$this->statType = Stat::TYPE_CONVERTED;
}
} catch (\Exception $e) {
$this->handleException($e);
}
if ($this->payloadModel) {
$operationLogs = $this->payloadModel->getLogs();
if ($operationLogs) {
$this->setLogs($operationLogs, 'operations');
}
}
$this->updateContact();
$this->createCache();
$this->logResults();
return $this;
} | [
"public",
"function",
"sendContact",
"(",
"ContactClient",
"$",
"client",
"=",
"null",
",",
"Contact",
"$",
"contact",
"=",
"null",
",",
"$",
"test",
"=",
"false",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"translator",
")",
"{",
"$",
"this",
"->",
"translator",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"}",
"$",
"this",
"->",
"contactClient",
"=",
"$",
"client",
";",
"$",
"this",
"->",
"contact",
"=",
"$",
"contact",
";",
"$",
"this",
"->",
"test",
"=",
"$",
"test",
";",
"try",
"{",
"$",
"this",
"->",
"validateClient",
"(",
"$",
"client",
",",
"$",
"force",
")",
";",
"$",
"this",
"->",
"addTrace",
"(",
"'contactClient'",
",",
"$",
"this",
"->",
"contactClient",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"addTrace",
"(",
"'contactClientId'",
",",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateContact",
"(",
")",
";",
"// Check all rules that may preclude sending this contact, in order of performance cost.",
"// Schedule - Check schedule rules to ensure we can send a contact now, do not retry if outside of window.",
"$",
"this",
"->",
"evaluateSchedule",
"(",
")",
";",
"// Filter - Check filter rules to ensure this contact is applicable.",
"$",
"this",
"->",
"evaluateFilter",
"(",
")",
";",
"// DNC - Check Do Not Contact channels for an entry for this contact that is not permitted for this client.",
"$",
"this",
"->",
"evaluateDnc",
"(",
")",
";",
"// Limits - Check limit rules to ensure we have not sent too many contacts in our window.",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"getCacheModel",
"(",
")",
"->",
"evaluateLimits",
"(",
")",
";",
"}",
"// Duplicates - Check duplicate cache to ensure we have not already sent this contact.",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"getCacheModel",
"(",
")",
"->",
"evaluateDuplicate",
"(",
")",
";",
"}",
"// Exclusivity - Check exclusivity rules on the cache to ensure this contact hasn't been sent to a disallowed competitor.",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"$",
"this",
"->",
"getCacheModel",
"(",
")",
"->",
"evaluateExclusive",
"(",
")",
";",
"}",
"/* @var ApiPayload|FilePayload $model */",
"$",
"this",
"->",
"getPayloadModel",
"(",
"$",
"this",
"->",
"contactClient",
")",
"->",
"setCampaign",
"(",
"$",
"this",
"->",
"getCampaign",
"(",
")",
")",
"->",
"setEvent",
"(",
"$",
"this",
"->",
"event",
")",
";",
"// Send all operations (API) or queue the contact (file).",
"$",
"this",
"->",
"payloadModel",
"->",
"run",
"(",
")",
";",
"$",
"this",
"->",
"valid",
"=",
"$",
"this",
"->",
"payloadModel",
"->",
"getValid",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"valid",
")",
"{",
"$",
"this",
"->",
"statType",
"=",
"Stat",
"::",
"TYPE_CONVERTED",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleException",
"(",
"$",
"e",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"payloadModel",
")",
"{",
"$",
"operationLogs",
"=",
"$",
"this",
"->",
"payloadModel",
"->",
"getLogs",
"(",
")",
";",
"if",
"(",
"$",
"operationLogs",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"operationLogs",
",",
"'operations'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"updateContact",
"(",
")",
";",
"$",
"this",
"->",
"createCache",
"(",
")",
";",
"$",
"this",
"->",
"logResults",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Given the JSON API API instructions payload instruction set.
Send the lead/contact to the API by following the steps.
@param ContactClient|null $client
@param Contact|null $contact
@param bool $test
@param bool $force
@return $this
@throws Exception | [
"Given",
"the",
"JSON",
"API",
"API",
"instructions",
"payload",
"instruction",
"set",
".",
"Send",
"the",
"lead",
"/",
"contact",
"to",
"the",
"API",
"by",
"following",
"the",
"steps",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L298-L375 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.validateClient | private function validateClient(ContactClient $client = null, $force = false)
{
if (!$client && !$this->test) {
throw new ContactClientException(
$this->translator->trans('mautic.contactclient.sendcontact.error.client.load'),
0,
null,
Stat::TYPE_INVALID,
false
);
}
if (!$force && !$this->test && !$client->getIsPublished()) {
throw new ContactClientException(
$this->translator->trans('mautic.contactclient.sendcontact.error.client.publish'),
0,
null,
Stat::TYPE_UNPUBLISHED,
false
);
}
} | php | private function validateClient(ContactClient $client = null, $force = false)
{
if (!$client && !$this->test) {
throw new ContactClientException(
$this->translator->trans('mautic.contactclient.sendcontact.error.client.load'),
0,
null,
Stat::TYPE_INVALID,
false
);
}
if (!$force && !$this->test && !$client->getIsPublished()) {
throw new ContactClientException(
$this->translator->trans('mautic.contactclient.sendcontact.error.client.publish'),
0,
null,
Stat::TYPE_UNPUBLISHED,
false
);
}
} | [
"private",
"function",
"validateClient",
"(",
"ContactClient",
"$",
"client",
"=",
"null",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"client",
"&&",
"!",
"$",
"this",
"->",
"test",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.sendcontact.error.client.load'",
")",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_INVALID",
",",
"false",
")",
";",
"}",
"if",
"(",
"!",
"$",
"force",
"&&",
"!",
"$",
"this",
"->",
"test",
"&&",
"!",
"$",
"client",
"->",
"getIsPublished",
"(",
")",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.sendcontact.error.client.publish'",
")",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_UNPUBLISHED",
",",
"false",
")",
";",
"}",
"}"
] | @param ContactClient|null $client
@param bool $force
@throws ContactClientException | [
"@param",
"ContactClient|null",
"$client",
"@param",
"bool",
"$force"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L383-L403 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getPayloadModel | private function getPayloadModel(ContactClient $contactClient = null)
{
if (!$this->payloadModel || $contactClient) {
$contactClient = $contactClient ? $contactClient : $this->contactClient;
$clientType = $contactClient->getType();
if ('api' == $clientType) {
$model = $this->getApiPayloadModel();
} elseif ('file' == $clientType) {
$model = $this->getFilePayloadModel();
} else {
throw new \InvalidArgumentException('Client type is invalid.');
}
$model->reset();
$model->setTest($this->test);
$model->setContactClient($contactClient);
if ($this->contact) {
$model->setContact($this->contact);
}
$this->payloadModel = $model;
}
return $this->payloadModel;
} | php | private function getPayloadModel(ContactClient $contactClient = null)
{
if (!$this->payloadModel || $contactClient) {
$contactClient = $contactClient ? $contactClient : $this->contactClient;
$clientType = $contactClient->getType();
if ('api' == $clientType) {
$model = $this->getApiPayloadModel();
} elseif ('file' == $clientType) {
$model = $this->getFilePayloadModel();
} else {
throw new \InvalidArgumentException('Client type is invalid.');
}
$model->reset();
$model->setTest($this->test);
$model->setContactClient($contactClient);
if ($this->contact) {
$model->setContact($this->contact);
}
$this->payloadModel = $model;
}
return $this->payloadModel;
} | [
"private",
"function",
"getPayloadModel",
"(",
"ContactClient",
"$",
"contactClient",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"payloadModel",
"||",
"$",
"contactClient",
")",
"{",
"$",
"contactClient",
"=",
"$",
"contactClient",
"?",
"$",
"contactClient",
":",
"$",
"this",
"->",
"contactClient",
";",
"$",
"clientType",
"=",
"$",
"contactClient",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"'api'",
"==",
"$",
"clientType",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getApiPayloadModel",
"(",
")",
";",
"}",
"elseif",
"(",
"'file'",
"==",
"$",
"clientType",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getFilePayloadModel",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Client type is invalid.'",
")",
";",
"}",
"$",
"model",
"->",
"reset",
"(",
")",
";",
"$",
"model",
"->",
"setTest",
"(",
"$",
"this",
"->",
"test",
")",
";",
"$",
"model",
"->",
"setContactClient",
"(",
"$",
"contactClient",
")",
";",
"if",
"(",
"$",
"this",
"->",
"contact",
")",
"{",
"$",
"model",
"->",
"setContact",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"$",
"this",
"->",
"payloadModel",
"=",
"$",
"model",
";",
"}",
"return",
"$",
"this",
"->",
"payloadModel",
";",
"}"
] | Get the current Payload model, or the model of a particular client.
@param ContactClient|null $contactClient
@return ApiPayload|FilePayload|object
@throws ContactClientException | [
"Get",
"the",
"current",
"Payload",
"model",
"or",
"the",
"model",
"of",
"a",
"particular",
"client",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L459-L481 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getApiPayloadModel | private function getApiPayloadModel()
{
if (!$this->apiPayloadModel) {
/* @var ApiPayload apiPayloadModel */
$this->apiPayloadModel = $this->getContainer()->get('mautic.contactclient.model.apipayload');
}
return $this->apiPayloadModel;
} | php | private function getApiPayloadModel()
{
if (!$this->apiPayloadModel) {
/* @var ApiPayload apiPayloadModel */
$this->apiPayloadModel = $this->getContainer()->get('mautic.contactclient.model.apipayload');
}
return $this->apiPayloadModel;
} | [
"private",
"function",
"getApiPayloadModel",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"apiPayloadModel",
")",
"{",
"/* @var ApiPayload apiPayloadModel */",
"$",
"this",
"->",
"apiPayloadModel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.contactclient.model.apipayload'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"apiPayloadModel",
";",
"}"
] | @return ApiPayload|object
@throws Exception | [
"@return",
"ApiPayload|object"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L488-L496 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getFilePayloadModel | private function getFilePayloadModel()
{
if (!$this->filePayloadModel) {
/* @var FilePayload filePayloadModel */
$this->filePayloadModel = $this->getContainer()->get('mautic.contactclient.model.filepayload');
}
return $this->filePayloadModel;
} | php | private function getFilePayloadModel()
{
if (!$this->filePayloadModel) {
/* @var FilePayload filePayloadModel */
$this->filePayloadModel = $this->getContainer()->get('mautic.contactclient.model.filepayload');
}
return $this->filePayloadModel;
} | [
"private",
"function",
"getFilePayloadModel",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filePayloadModel",
")",
"{",
"/* @var FilePayload filePayloadModel */",
"$",
"this",
"->",
"filePayloadModel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.contactclient.model.filepayload'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filePayloadModel",
";",
"}"
] | @return FilePayload|object
@throws Exception | [
"@return",
"FilePayload|object"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L503-L511 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.evaluateFilter | private function evaluateFilter()
{
if ($this->test) {
return $this;
}
$definition = $this->contactClient->getFilter();
if ($definition) {
// Succeed by default should there be no rules.
$filterResult = true;
$filter = new FilterHelper();
$context = $this->getPayloadModel()
->getTokenHelper()
->newSession($this->contactClient, $this->contact)
->getContext(true);
try {
$filterResult = $filter->filter($definition, $context);
} catch (\Exception $e) {
throw new ContactClientException(
'Error in filter: '.$e->getMessage(),
0,
$e,
Stat::TYPE_FILTER,
false,
null,
$filter->getErrors()
);
}
if (!$filterResult) {
throw new ContactClientException(
'Contact filtered: '.implode(', ', $filter->getErrors()),
0,
null,
Stat::TYPE_FILTER,
false,
null,
$filter->getErrors()
);
}
}
return $this;
} | php | private function evaluateFilter()
{
if ($this->test) {
return $this;
}
$definition = $this->contactClient->getFilter();
if ($definition) {
// Succeed by default should there be no rules.
$filterResult = true;
$filter = new FilterHelper();
$context = $this->getPayloadModel()
->getTokenHelper()
->newSession($this->contactClient, $this->contact)
->getContext(true);
try {
$filterResult = $filter->filter($definition, $context);
} catch (\Exception $e) {
throw new ContactClientException(
'Error in filter: '.$e->getMessage(),
0,
$e,
Stat::TYPE_FILTER,
false,
null,
$filter->getErrors()
);
}
if (!$filterResult) {
throw new ContactClientException(
'Contact filtered: '.implode(', ', $filter->getErrors()),
0,
null,
Stat::TYPE_FILTER,
false,
null,
$filter->getErrors()
);
}
}
return $this;
} | [
"private",
"function",
"evaluateFilter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"definition",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getFilter",
"(",
")",
";",
"if",
"(",
"$",
"definition",
")",
"{",
"// Succeed by default should there be no rules.",
"$",
"filterResult",
"=",
"true",
";",
"$",
"filter",
"=",
"new",
"FilterHelper",
"(",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"getPayloadModel",
"(",
")",
"->",
"getTokenHelper",
"(",
")",
"->",
"newSession",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"contact",
")",
"->",
"getContext",
"(",
"true",
")",
";",
"try",
"{",
"$",
"filterResult",
"=",
"$",
"filter",
"->",
"filter",
"(",
"$",
"definition",
",",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Error in filter: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"e",
",",
"Stat",
"::",
"TYPE_FILTER",
",",
"false",
",",
"null",
",",
"$",
"filter",
"->",
"getErrors",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"filterResult",
")",
"{",
"throw",
"new",
"ContactClientException",
"(",
"'Contact filtered: '",
".",
"implode",
"(",
"', '",
",",
"$",
"filter",
"->",
"getErrors",
"(",
")",
")",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_FILTER",
",",
"false",
",",
"null",
",",
"$",
"filter",
"->",
"getErrors",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | @return $this
@throws ContactClientException | [
"@return",
"$this"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L518-L559 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.evaluateDnc | private function evaluateDnc()
{
if ($this->test) {
return $this;
}
$channels = explode(',', $this->contactClient->getDncChecks());
if ($channels) {
foreach ($channels as $channel) {
$dncRepo = $this->getDncRepo();
$dncRepo->setDispatcher($this->dispatcher);
$dncEntries = $dncRepo->getEntriesByLeadAndChannel(
$this->contact,
$channel
);
// @todo - Support external DNC checking should it be needed in the future.
// if (empty($dncEntries)) {
// $event = new ContactDncCheckEvent($this->contact, $channels, $dncEntries);
// $this->dispatcher->dispatch(ContactClientEvents::EXTERNAL_DNC_CHECK, $event);
// }
if (!empty($dncEntries)) {
foreach ($dncEntries as $dnc) {
$comments = !in_array($dnc->getComments(), ['user', 'system']) ? $dnc->getComments() : '';
throw new ContactClientException(
trim(
$this->translator->trans(
'mautic.contactclient.sendcontact.error.dnc',
[
'%channel%' => $this->getDncChannelName($channel),
'%date%' => $dnc->getDateAdded()->format('Y-m-d H:i:s e'),
'%comments%' => $comments,
]
)
),
0,
null,
Stat::TYPE_DNC,
false
);
}
}
}
}
return $this;
} | php | private function evaluateDnc()
{
if ($this->test) {
return $this;
}
$channels = explode(',', $this->contactClient->getDncChecks());
if ($channels) {
foreach ($channels as $channel) {
$dncRepo = $this->getDncRepo();
$dncRepo->setDispatcher($this->dispatcher);
$dncEntries = $dncRepo->getEntriesByLeadAndChannel(
$this->contact,
$channel
);
// @todo - Support external DNC checking should it be needed in the future.
// if (empty($dncEntries)) {
// $event = new ContactDncCheckEvent($this->contact, $channels, $dncEntries);
// $this->dispatcher->dispatch(ContactClientEvents::EXTERNAL_DNC_CHECK, $event);
// }
if (!empty($dncEntries)) {
foreach ($dncEntries as $dnc) {
$comments = !in_array($dnc->getComments(), ['user', 'system']) ? $dnc->getComments() : '';
throw new ContactClientException(
trim(
$this->translator->trans(
'mautic.contactclient.sendcontact.error.dnc',
[
'%channel%' => $this->getDncChannelName($channel),
'%date%' => $dnc->getDateAdded()->format('Y-m-d H:i:s e'),
'%comments%' => $comments,
]
)
),
0,
null,
Stat::TYPE_DNC,
false
);
}
}
}
}
return $this;
} | [
"private",
"function",
"evaluateDnc",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"channels",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"contactClient",
"->",
"getDncChecks",
"(",
")",
")",
";",
"if",
"(",
"$",
"channels",
")",
"{",
"foreach",
"(",
"$",
"channels",
"as",
"$",
"channel",
")",
"{",
"$",
"dncRepo",
"=",
"$",
"this",
"->",
"getDncRepo",
"(",
")",
";",
"$",
"dncRepo",
"->",
"setDispatcher",
"(",
"$",
"this",
"->",
"dispatcher",
")",
";",
"$",
"dncEntries",
"=",
"$",
"dncRepo",
"->",
"getEntriesByLeadAndChannel",
"(",
"$",
"this",
"->",
"contact",
",",
"$",
"channel",
")",
";",
"// @todo - Support external DNC checking should it be needed in the future.",
"// if (empty($dncEntries)) {",
"// $event = new ContactDncCheckEvent($this->contact, $channels, $dncEntries);",
"// $this->dispatcher->dispatch(ContactClientEvents::EXTERNAL_DNC_CHECK, $event);",
"// }",
"if",
"(",
"!",
"empty",
"(",
"$",
"dncEntries",
")",
")",
"{",
"foreach",
"(",
"$",
"dncEntries",
"as",
"$",
"dnc",
")",
"{",
"$",
"comments",
"=",
"!",
"in_array",
"(",
"$",
"dnc",
"->",
"getComments",
"(",
")",
",",
"[",
"'user'",
",",
"'system'",
"]",
")",
"?",
"$",
"dnc",
"->",
"getComments",
"(",
")",
":",
"''",
";",
"throw",
"new",
"ContactClientException",
"(",
"trim",
"(",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.sendcontact.error.dnc'",
",",
"[",
"'%channel%'",
"=>",
"$",
"this",
"->",
"getDncChannelName",
"(",
"$",
"channel",
")",
",",
"'%date%'",
"=>",
"$",
"dnc",
"->",
"getDateAdded",
"(",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s e'",
")",
",",
"'%comments%'",
"=>",
"$",
"comments",
",",
"]",
")",
")",
",",
"0",
",",
"null",
",",
"Stat",
"::",
"TYPE_DNC",
",",
"false",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Evaluates the DNC entries for the Contact against the Client settings.
@return $this
@throws ContactClientException | [
"Evaluates",
"the",
"DNC",
"entries",
"for",
"the",
"Contact",
"against",
"the",
"Client",
"settings",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L568-L614 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getDncChannelName | private function getDncChannelName($key)
{
if (!$this->dncChannels) {
$this->dncChannels = $this->getContactModel()->getPreferenceChannels();
}
if ($key) {
if (isset($this->dncChannels[$key])) {
return $this->dncChannels[$key];
} else {
return ucwords($key);
}
}
return '';
} | php | private function getDncChannelName($key)
{
if (!$this->dncChannels) {
$this->dncChannels = $this->getContactModel()->getPreferenceChannels();
}
if ($key) {
if (isset($this->dncChannels[$key])) {
return $this->dncChannels[$key];
} else {
return ucwords($key);
}
}
return '';
} | [
"private",
"function",
"getDncChannelName",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dncChannels",
")",
"{",
"$",
"this",
"->",
"dncChannels",
"=",
"$",
"this",
"->",
"getContactModel",
"(",
")",
"->",
"getPreferenceChannels",
"(",
")",
";",
"}",
"if",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dncChannels",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dncChannels",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"ucwords",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Get all DNC Channels, or one by key.
@param $key
@return array|mixed | [
"Get",
"all",
"DNC",
"Channels",
"or",
"one",
"by",
"key",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L635-L649 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getCacheModel | private function getCacheModel()
{
if (!$this->cacheModel) {
/* @var \MauticPlugin\MauticContactClientBundle\Model\Cache $cacheModel */
$this->cacheModel = $this->getContainer()->get('mautic.contactclient.model.cache');
$this->cacheModel->setContact($this->contact);
$this->cacheModel->setContactClient($this->contactClient);
$this->cacheModel->setDateSend($this->dateSend);
}
return $this->cacheModel;
} | php | private function getCacheModel()
{
if (!$this->cacheModel) {
/* @var \MauticPlugin\MauticContactClientBundle\Model\Cache $cacheModel */
$this->cacheModel = $this->getContainer()->get('mautic.contactclient.model.cache');
$this->cacheModel->setContact($this->contact);
$this->cacheModel->setContactClient($this->contactClient);
$this->cacheModel->setDateSend($this->dateSend);
}
return $this->cacheModel;
} | [
"private",
"function",
"getCacheModel",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cacheModel",
")",
"{",
"/* @var \\MauticPlugin\\MauticContactClientBundle\\Model\\Cache $cacheModel */",
"$",
"this",
"->",
"cacheModel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.contactclient.model.cache'",
")",
";",
"$",
"this",
"->",
"cacheModel",
"->",
"setContact",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"cacheModel",
"->",
"setContactClient",
"(",
"$",
"this",
"->",
"contactClient",
")",
";",
"$",
"this",
"->",
"cacheModel",
"->",
"setDateSend",
"(",
"$",
"this",
"->",
"dateSend",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cacheModel",
";",
"}"
] | Get the Cache model for duplicate/exclusive/limit checking.
@return \MauticPlugin\MauticContactClientBundle\Model\Cache
@throws Exception | [
"Get",
"the",
"Cache",
"model",
"for",
"duplicate",
"/",
"exclusive",
"/",
"limit",
"checking",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L670-L681 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getCampaign | private function getCampaign()
{
if (!$this->campaign && $this->event) {
// Sometimes we have a campaignId as an integer ID.
if (!empty($this->event['campaignId']) && is_integer($this->event['campaignId'])) {
/** @var CampaignModel $campaignModel */
$campaignModel = $this->getContainer()->get('mautic.campaign.model.campaign');
$this->campaign = $campaignModel->getEntity($this->event['campaignId']);
}
// Sometimes we have a campaignId as a hash.
if (!$this->campaign) {
try {
$identityMap = $this->em->getUnitOfWork()->getIdentityMap();
if (isset($identityMap['Mautic\CampaignBundle\Entity\Campaign']) && !empty($identityMap['Mautic\CampaignBundle\Entity\Campaign'])) {
$this->campaign = end($identityMap['Mautic\CampaignBundle\Entity\Campaign']);
}
} catch (\Exception $e) {
}
}
if ($this->campaign) {
$this->addTrace('campaign', $this->campaign->getName());
$this->addTrace('campaignId', $this->campaign->getId());
}
}
return $this->campaign;
} | php | private function getCampaign()
{
if (!$this->campaign && $this->event) {
// Sometimes we have a campaignId as an integer ID.
if (!empty($this->event['campaignId']) && is_integer($this->event['campaignId'])) {
/** @var CampaignModel $campaignModel */
$campaignModel = $this->getContainer()->get('mautic.campaign.model.campaign');
$this->campaign = $campaignModel->getEntity($this->event['campaignId']);
}
// Sometimes we have a campaignId as a hash.
if (!$this->campaign) {
try {
$identityMap = $this->em->getUnitOfWork()->getIdentityMap();
if (isset($identityMap['Mautic\CampaignBundle\Entity\Campaign']) && !empty($identityMap['Mautic\CampaignBundle\Entity\Campaign'])) {
$this->campaign = end($identityMap['Mautic\CampaignBundle\Entity\Campaign']);
}
} catch (\Exception $e) {
}
}
if ($this->campaign) {
$this->addTrace('campaign', $this->campaign->getName());
$this->addTrace('campaignId', $this->campaign->getId());
}
}
return $this->campaign;
} | [
"private",
"function",
"getCampaign",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"campaign",
"&&",
"$",
"this",
"->",
"event",
")",
"{",
"// Sometimes we have a campaignId as an integer ID.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
")",
"&&",
"is_integer",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
")",
")",
"{",
"/** @var CampaignModel $campaignModel */",
"$",
"campaignModel",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mautic.campaign.model.campaign'",
")",
";",
"$",
"this",
"->",
"campaign",
"=",
"$",
"campaignModel",
"->",
"getEntity",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
")",
";",
"}",
"// Sometimes we have a campaignId as a hash.",
"if",
"(",
"!",
"$",
"this",
"->",
"campaign",
")",
"{",
"try",
"{",
"$",
"identityMap",
"=",
"$",
"this",
"->",
"em",
"->",
"getUnitOfWork",
"(",
")",
"->",
"getIdentityMap",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"campaign",
"=",
"end",
"(",
"$",
"identityMap",
"[",
"'Mautic\\CampaignBundle\\Entity\\Campaign'",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"campaign",
")",
"{",
"$",
"this",
"->",
"addTrace",
"(",
"'campaign'",
",",
"$",
"this",
"->",
"campaign",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"addTrace",
"(",
"'campaignId'",
",",
"$",
"this",
"->",
"campaign",
"->",
"getId",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"campaign",
";",
"}"
] | Attempt to discern if we are being triggered by/within a campaign.
@return \Mautic\CampaignBundle\Entity\Campaign|mixed|null
@throws Exception | [
"Attempt",
"to",
"discern",
"if",
"we",
"are",
"being",
"triggered",
"by",
"/",
"within",
"a",
"campaign",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L690-L716 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.handleException | private function handleException(\Exception $exception)
{
// Any exception means the client send has failed.
$this->valid = false;
if ($exception instanceof ContactClientException) {
// A known exception within the Client handling.
if ($this->contact) {
$exception->setContact($this->contact);
}
// Handle retryable / queue exceptions.
if (
Stat::TYPE_SCHEDULE == $exception->getStatType()
&& $this->contactClient
&& 'api' == $this->contactClient->getType()
&& $this->contactClient->getScheduleQueue()
) {
// API request during a closed hour/day but the queue is enabled for this.
// Attempt to reschedule given the spread setting and scheduling.
$maxDay = $this->contactClient->getScheduleQueueSpread();
$startTime = new \DateTime('+1 hour');
if ($this->addRescheduleItemToSession(0, $maxDay, $startTime, $exception->getMessage())) {
// Requeue the contact to be sent at a later time per API Schedule Queue setting,
$this->retry = true;
$exception->setStatType(Stat::TYPE_SCHEDULE_QUEUE);
$exception->setMessage($exception->getMessage().' Queued for a later.');
}
} elseif (
Stat::TYPE_LIMITS == $exception->getStatType()
&& $this->contactClient
&& $this->contactClient->getLimitsQueue()
) {
// Rate limits were exceed but the queue is enabled for this.
// Attempt to reschedule given the spread setting and scheduling.
$maxDay = $this->contactClient->getLimitsQueueSpread();
if ($this->addRescheduleItemToSession(1, $maxDay, null, $exception->getMessage())) {
// Requeue the contact to be sent at a later time per Limits Queue setting,
$this->retry = true;
$exception->setStatType(Stat::TYPE_LIMITS_QUEUE);
$exception->setMessage($exception->getMessage().' Queued for a later.');
}
} elseif (
$exception->getRetry()
&& $this->contactClient
&& 'api' === $this->contactClient->getType()
&& ($payloadModel = $this->getPayloadModel())
&& ($settings = $payloadModel->getSettings())
&& isset($settings['autoRetry'])
&& true === boolval($settings['autoRetry'])
) {
// API based client had a retryable exception and has autoRetry enabled, so we should retry if possible.
// Attempt to reschedule to the next open slot by global campaign setting up to 1 day in the future.
// This will avoid retries on closed hours if at-all possible.
/** @var string $intervalString */
$intervalString = $this->getParameterHelper()->getParameter(
'campaign_time_wait_on_event_false'
);
if ($intervalString) {
try {
$interval = new \DateInterval($intervalString);
$startTime = new \DateTime();
$startTime->add($interval);
} catch (\Exception $e) {
// If no interval is set default to a few hours in the future
$startTime = new \DateTime('+6 hours');
}
// Add randomized drift of up to 30 minutes to reduce likelihood of stampedes.
$startTime->modify('+'.rand(0, 1800).' seconds');
if ($this->addRescheduleItemToSession(0, 1, $startTime, $exception->getMessage())) {
$this->retry = true;
}
}
}
// We will persist exception information to logs/stats.
if ($exception->getStatType()) {
$this->statType = $exception->getStatType();
$this->setLogs($this->statType, 'status');
}
$errorData = $exception->getData();
if ($errorData) {
$this->setLogs($errorData, $exception->getStatType());
}
} elseif ($exception instanceof ConnectException) {
if (function_exists('newrelic_notice_error')) {
call_user_func(
'newrelic_notice_error',
'ContactClient Connection Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
$exception
);
}
} else {
if (function_exists('newrelic_notice_error')) {
call_user_func(
'newrelic_notice_error',
'ContactClient Integration Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
$exception
);
}
// Unexpected issue with the Client plugin.
$this->logIntegrationError($exception, $this->contact);
}
$this->setLogs($exception->getMessage(), 'error');
$this->setLogs($this->retry, 'retry');
} | php | private function handleException(\Exception $exception)
{
// Any exception means the client send has failed.
$this->valid = false;
if ($exception instanceof ContactClientException) {
// A known exception within the Client handling.
if ($this->contact) {
$exception->setContact($this->contact);
}
// Handle retryable / queue exceptions.
if (
Stat::TYPE_SCHEDULE == $exception->getStatType()
&& $this->contactClient
&& 'api' == $this->contactClient->getType()
&& $this->contactClient->getScheduleQueue()
) {
// API request during a closed hour/day but the queue is enabled for this.
// Attempt to reschedule given the spread setting and scheduling.
$maxDay = $this->contactClient->getScheduleQueueSpread();
$startTime = new \DateTime('+1 hour');
if ($this->addRescheduleItemToSession(0, $maxDay, $startTime, $exception->getMessage())) {
// Requeue the contact to be sent at a later time per API Schedule Queue setting,
$this->retry = true;
$exception->setStatType(Stat::TYPE_SCHEDULE_QUEUE);
$exception->setMessage($exception->getMessage().' Queued for a later.');
}
} elseif (
Stat::TYPE_LIMITS == $exception->getStatType()
&& $this->contactClient
&& $this->contactClient->getLimitsQueue()
) {
// Rate limits were exceed but the queue is enabled for this.
// Attempt to reschedule given the spread setting and scheduling.
$maxDay = $this->contactClient->getLimitsQueueSpread();
if ($this->addRescheduleItemToSession(1, $maxDay, null, $exception->getMessage())) {
// Requeue the contact to be sent at a later time per Limits Queue setting,
$this->retry = true;
$exception->setStatType(Stat::TYPE_LIMITS_QUEUE);
$exception->setMessage($exception->getMessage().' Queued for a later.');
}
} elseif (
$exception->getRetry()
&& $this->contactClient
&& 'api' === $this->contactClient->getType()
&& ($payloadModel = $this->getPayloadModel())
&& ($settings = $payloadModel->getSettings())
&& isset($settings['autoRetry'])
&& true === boolval($settings['autoRetry'])
) {
// API based client had a retryable exception and has autoRetry enabled, so we should retry if possible.
// Attempt to reschedule to the next open slot by global campaign setting up to 1 day in the future.
// This will avoid retries on closed hours if at-all possible.
/** @var string $intervalString */
$intervalString = $this->getParameterHelper()->getParameter(
'campaign_time_wait_on_event_false'
);
if ($intervalString) {
try {
$interval = new \DateInterval($intervalString);
$startTime = new \DateTime();
$startTime->add($interval);
} catch (\Exception $e) {
// If no interval is set default to a few hours in the future
$startTime = new \DateTime('+6 hours');
}
// Add randomized drift of up to 30 minutes to reduce likelihood of stampedes.
$startTime->modify('+'.rand(0, 1800).' seconds');
if ($this->addRescheduleItemToSession(0, 1, $startTime, $exception->getMessage())) {
$this->retry = true;
}
}
}
// We will persist exception information to logs/stats.
if ($exception->getStatType()) {
$this->statType = $exception->getStatType();
$this->setLogs($this->statType, 'status');
}
$errorData = $exception->getData();
if ($errorData) {
$this->setLogs($errorData, $exception->getStatType());
}
} elseif ($exception instanceof ConnectException) {
if (function_exists('newrelic_notice_error')) {
call_user_func(
'newrelic_notice_error',
'ContactClient Connection Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
$exception
);
}
} else {
if (function_exists('newrelic_notice_error')) {
call_user_func(
'newrelic_notice_error',
'ContactClient Integration Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
$exception
);
}
// Unexpected issue with the Client plugin.
$this->logIntegrationError($exception, $this->contact);
}
$this->setLogs($exception->getMessage(), 'error');
$this->setLogs($this->retry, 'retry');
} | [
"private",
"function",
"handleException",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"// Any exception means the client send has failed.",
"$",
"this",
"->",
"valid",
"=",
"false",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"ContactClientException",
")",
"{",
"// A known exception within the Client handling.",
"if",
"(",
"$",
"this",
"->",
"contact",
")",
"{",
"$",
"exception",
"->",
"setContact",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"// Handle retryable / queue exceptions.",
"if",
"(",
"Stat",
"::",
"TYPE_SCHEDULE",
"==",
"$",
"exception",
"->",
"getStatType",
"(",
")",
"&&",
"$",
"this",
"->",
"contactClient",
"&&",
"'api'",
"==",
"$",
"this",
"->",
"contactClient",
"->",
"getType",
"(",
")",
"&&",
"$",
"this",
"->",
"contactClient",
"->",
"getScheduleQueue",
"(",
")",
")",
"{",
"// API request during a closed hour/day but the queue is enabled for this.",
"// Attempt to reschedule given the spread setting and scheduling.",
"$",
"maxDay",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getScheduleQueueSpread",
"(",
")",
";",
"$",
"startTime",
"=",
"new",
"\\",
"DateTime",
"(",
"'+1 hour'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"addRescheduleItemToSession",
"(",
"0",
",",
"$",
"maxDay",
",",
"$",
"startTime",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
")",
"{",
"// Requeue the contact to be sent at a later time per API Schedule Queue setting,",
"$",
"this",
"->",
"retry",
"=",
"true",
";",
"$",
"exception",
"->",
"setStatType",
"(",
"Stat",
"::",
"TYPE_SCHEDULE_QUEUE",
")",
";",
"$",
"exception",
"->",
"setMessage",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"' Queued for a later.'",
")",
";",
"}",
"}",
"elseif",
"(",
"Stat",
"::",
"TYPE_LIMITS",
"==",
"$",
"exception",
"->",
"getStatType",
"(",
")",
"&&",
"$",
"this",
"->",
"contactClient",
"&&",
"$",
"this",
"->",
"contactClient",
"->",
"getLimitsQueue",
"(",
")",
")",
"{",
"// Rate limits were exceed but the queue is enabled for this.",
"// Attempt to reschedule given the spread setting and scheduling.",
"$",
"maxDay",
"=",
"$",
"this",
"->",
"contactClient",
"->",
"getLimitsQueueSpread",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"addRescheduleItemToSession",
"(",
"1",
",",
"$",
"maxDay",
",",
"null",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
")",
"{",
"// Requeue the contact to be sent at a later time per Limits Queue setting,",
"$",
"this",
"->",
"retry",
"=",
"true",
";",
"$",
"exception",
"->",
"setStatType",
"(",
"Stat",
"::",
"TYPE_LIMITS_QUEUE",
")",
";",
"$",
"exception",
"->",
"setMessage",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"' Queued for a later.'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"exception",
"->",
"getRetry",
"(",
")",
"&&",
"$",
"this",
"->",
"contactClient",
"&&",
"'api'",
"===",
"$",
"this",
"->",
"contactClient",
"->",
"getType",
"(",
")",
"&&",
"(",
"$",
"payloadModel",
"=",
"$",
"this",
"->",
"getPayloadModel",
"(",
")",
")",
"&&",
"(",
"$",
"settings",
"=",
"$",
"payloadModel",
"->",
"getSettings",
"(",
")",
")",
"&&",
"isset",
"(",
"$",
"settings",
"[",
"'autoRetry'",
"]",
")",
"&&",
"true",
"===",
"boolval",
"(",
"$",
"settings",
"[",
"'autoRetry'",
"]",
")",
")",
"{",
"// API based client had a retryable exception and has autoRetry enabled, so we should retry if possible.",
"// Attempt to reschedule to the next open slot by global campaign setting up to 1 day in the future.",
"// This will avoid retries on closed hours if at-all possible.",
"/** @var string $intervalString */",
"$",
"intervalString",
"=",
"$",
"this",
"->",
"getParameterHelper",
"(",
")",
"->",
"getParameter",
"(",
"'campaign_time_wait_on_event_false'",
")",
";",
"if",
"(",
"$",
"intervalString",
")",
"{",
"try",
"{",
"$",
"interval",
"=",
"new",
"\\",
"DateInterval",
"(",
"$",
"intervalString",
")",
";",
"$",
"startTime",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"startTime",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// If no interval is set default to a few hours in the future",
"$",
"startTime",
"=",
"new",
"\\",
"DateTime",
"(",
"'+6 hours'",
")",
";",
"}",
"// Add randomized drift of up to 30 minutes to reduce likelihood of stampedes.",
"$",
"startTime",
"->",
"modify",
"(",
"'+'",
".",
"rand",
"(",
"0",
",",
"1800",
")",
".",
"' seconds'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"addRescheduleItemToSession",
"(",
"0",
",",
"1",
",",
"$",
"startTime",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"retry",
"=",
"true",
";",
"}",
"}",
"}",
"// We will persist exception information to logs/stats.",
"if",
"(",
"$",
"exception",
"->",
"getStatType",
"(",
")",
")",
"{",
"$",
"this",
"->",
"statType",
"=",
"$",
"exception",
"->",
"getStatType",
"(",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"statType",
",",
"'status'",
")",
";",
"}",
"$",
"errorData",
"=",
"$",
"exception",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"errorData",
")",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"errorData",
",",
"$",
"exception",
"->",
"getStatType",
"(",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"exception",
"instanceof",
"ConnectException",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'newrelic_notice_error'",
")",
")",
"{",
"call_user_func",
"(",
"'newrelic_notice_error'",
",",
"'ContactClient Connection Error '",
".",
"(",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
":",
"'NA'",
")",
",",
"$",
"exception",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"function_exists",
"(",
"'newrelic_notice_error'",
")",
")",
"{",
"call_user_func",
"(",
"'newrelic_notice_error'",
",",
"'ContactClient Integration Error '",
".",
"(",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
":",
"'NA'",
")",
",",
"$",
"exception",
")",
";",
"}",
"// Unexpected issue with the Client plugin.",
"$",
"this",
"->",
"logIntegrationError",
"(",
"$",
"exception",
",",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'error'",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"$",
"this",
"->",
"retry",
",",
"'retry'",
")",
";",
"}"
] | @param Exception $exception
@throws ContactClientException | [
"@param",
"Exception",
"$exception"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L723-L828 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.addRescheduleItemToSession | public function addRescheduleItemToSession($startDay = 1, $endDay = 7, \DateTime $startTime = null, $reason = null)
{
$result = false;
if (isset($this->getEvent()['leadEventLog'])) {
// To randomly disperse API requests we must get all openings within the date range first.
$all = 'api' === $this->contactClient->getType();
// Get all openings if API, otherwise just get the first available.
$openings = $this->payloadModel->getScheduleModel()->findOpening($startDay, $endDay, 1, $all, $startTime);
if ($openings) {
// Select an opening.
if ($all) {
$opening = $openings[rand(0, count($openings) - 1)];
} else {
$opening = reset($openings);
}
/**
* @var \DateTime
* @var $end \DateTime
*/
list($start, $end) = $opening;
// Randomly disperse within this range of time if needed.
if ($all) {
// How many seconds are there in this range, minus a minute for margin of error at the end of day?
$rangeSeconds = max(0, ($end->format('U') - $start->format('U') - 60));
$randSeconds = rand(0, $rangeSeconds);
$start->modify('+'.$randSeconds.' seconds');
}
// Add leadEventLog id instance to global session array for later processing in reschedule() dispatch.
$eventLogId = $this->getEvent()['leadEventLog']->getId();
$events = $this->getSession()->get('contact.client.reschedule.event', []);
$events[$eventLogId] = [
'triggerDate' => $start,
'reason' => $reason,
];
$this->getSession()->set('contact.client.reschedule.event', $events);
$result = true;
}
}
return $result;
} | php | public function addRescheduleItemToSession($startDay = 1, $endDay = 7, \DateTime $startTime = null, $reason = null)
{
$result = false;
if (isset($this->getEvent()['leadEventLog'])) {
// To randomly disperse API requests we must get all openings within the date range first.
$all = 'api' === $this->contactClient->getType();
// Get all openings if API, otherwise just get the first available.
$openings = $this->payloadModel->getScheduleModel()->findOpening($startDay, $endDay, 1, $all, $startTime);
if ($openings) {
// Select an opening.
if ($all) {
$opening = $openings[rand(0, count($openings) - 1)];
} else {
$opening = reset($openings);
}
/**
* @var \DateTime
* @var $end \DateTime
*/
list($start, $end) = $opening;
// Randomly disperse within this range of time if needed.
if ($all) {
// How many seconds are there in this range, minus a minute for margin of error at the end of day?
$rangeSeconds = max(0, ($end->format('U') - $start->format('U') - 60));
$randSeconds = rand(0, $rangeSeconds);
$start->modify('+'.$randSeconds.' seconds');
}
// Add leadEventLog id instance to global session array for later processing in reschedule() dispatch.
$eventLogId = $this->getEvent()['leadEventLog']->getId();
$events = $this->getSession()->get('contact.client.reschedule.event', []);
$events[$eventLogId] = [
'triggerDate' => $start,
'reason' => $reason,
];
$this->getSession()->set('contact.client.reschedule.event', $events);
$result = true;
}
}
return $result;
} | [
"public",
"function",
"addRescheduleItemToSession",
"(",
"$",
"startDay",
"=",
"1",
",",
"$",
"endDay",
"=",
"7",
",",
"\\",
"DateTime",
"$",
"startTime",
"=",
"null",
",",
"$",
"reason",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"getEvent",
"(",
")",
"[",
"'leadEventLog'",
"]",
")",
")",
"{",
"// To randomly disperse API requests we must get all openings within the date range first.",
"$",
"all",
"=",
"'api'",
"===",
"$",
"this",
"->",
"contactClient",
"->",
"getType",
"(",
")",
";",
"// Get all openings if API, otherwise just get the first available.",
"$",
"openings",
"=",
"$",
"this",
"->",
"payloadModel",
"->",
"getScheduleModel",
"(",
")",
"->",
"findOpening",
"(",
"$",
"startDay",
",",
"$",
"endDay",
",",
"1",
",",
"$",
"all",
",",
"$",
"startTime",
")",
";",
"if",
"(",
"$",
"openings",
")",
"{",
"// Select an opening.",
"if",
"(",
"$",
"all",
")",
"{",
"$",
"opening",
"=",
"$",
"openings",
"[",
"rand",
"(",
"0",
",",
"count",
"(",
"$",
"openings",
")",
"-",
"1",
")",
"]",
";",
"}",
"else",
"{",
"$",
"opening",
"=",
"reset",
"(",
"$",
"openings",
")",
";",
"}",
"/**\n * @var \\DateTime\n * @var $end \\DateTime\n */",
"list",
"(",
"$",
"start",
",",
"$",
"end",
")",
"=",
"$",
"opening",
";",
"// Randomly disperse within this range of time if needed.",
"if",
"(",
"$",
"all",
")",
"{",
"// How many seconds are there in this range, minus a minute for margin of error at the end of day?",
"$",
"rangeSeconds",
"=",
"max",
"(",
"0",
",",
"(",
"$",
"end",
"->",
"format",
"(",
"'U'",
")",
"-",
"$",
"start",
"->",
"format",
"(",
"'U'",
")",
"-",
"60",
")",
")",
";",
"$",
"randSeconds",
"=",
"rand",
"(",
"0",
",",
"$",
"rangeSeconds",
")",
";",
"$",
"start",
"->",
"modify",
"(",
"'+'",
".",
"$",
"randSeconds",
".",
"' seconds'",
")",
";",
"}",
"// Add leadEventLog id instance to global session array for later processing in reschedule() dispatch.",
"$",
"eventLogId",
"=",
"$",
"this",
"->",
"getEvent",
"(",
")",
"[",
"'leadEventLog'",
"]",
"->",
"getId",
"(",
")",
";",
"$",
"events",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"'contact.client.reschedule.event'",
",",
"[",
"]",
")",
";",
"$",
"events",
"[",
"$",
"eventLogId",
"]",
"=",
"[",
"'triggerDate'",
"=>",
"$",
"start",
",",
"'reason'",
"=>",
"$",
"reason",
",",
"]",
";",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"set",
"(",
"'contact.client.reschedule.event'",
",",
"$",
"events",
")",
";",
"$",
"result",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | @param int $startDay
@param int $endDay
@param \DateTime|null $startTime
@param string|null $reason
@return bool
@throws Exception | [
"@param",
"int",
"$startDay",
"@param",
"int",
"$endDay",
"@param",
"\\",
"DateTime|null",
"$startTime",
"@param",
"string|null",
"$reason"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L840-L883 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.updateContact | private function updateContact()
{
// Assume no attribution till calculated.
$this->attribution = 0;
// Do not update contacts for test runs.
if ($this->test || !$this->payloadModel) {
return;
}
// Only update contacts if success definitions are met.
if (!$this->valid) {
return;
}
try {
$this->dispatchContextCreate();
// Only API model currently has a map to update contacts based on the response.
$updatedFields = false;
if (method_exists($this->payloadModel, 'applyResponseMap')) {
/** @var bool $updatedFields */
$updatedFields = $this->payloadModel->applyResponseMap();
if ($updatedFields) {
$this->contact = $this->payloadModel->getContact();
}
}
/** @var Attribution $attribution */
$attribution = new Attribution($this->contactClient, $this->contact, $this->payloadModel);
/** @var bool $updatedAttribution */
$updatedAttribution = $attribution->applyAttribution();
if ($updatedAttribution) {
$this->attribution = $attribution->getAttributionChange();
$this->setLogs(strval(round($this->attribution, 4)), 'attribution');
if ($this->attribution && method_exists($this->payloadModel, 'setAttribution')) {
$this->payloadModel->setAttribution($this->attribution);
}
} else {
$this->setLogs('0', 'attribution');
}
$this->setLogs(strval(round($this->contact->getAttribution(), 4)), 'attributionTotal');
// If any fields were updated, save the Contact entity.
if ($updatedFields || $updatedAttribution) {
$this->getContactModel()->saveEntity($this->contact);
$this->setLogs('Operation successful. The contact was updated.', 'updated');
} else {
$this->setLogs('Operation successful, but no fields on the contact needed updating.', 'info');
}
if (!$updatedAttribution) {
// Fields may have updated, but not attribution, so the ledger needs an event to capture conversions.
$this->dispatchContextCapture();
}
} catch (\Exception $e) {
$this->valid = false;
$this->setLogs('Operation completed, but we failed to update our Contact. '.$e->getMessage(), 'error');
$this->logIntegrationError($e, $this->contact);
$this->retry = false;
}
} | php | private function updateContact()
{
// Assume no attribution till calculated.
$this->attribution = 0;
// Do not update contacts for test runs.
if ($this->test || !$this->payloadModel) {
return;
}
// Only update contacts if success definitions are met.
if (!$this->valid) {
return;
}
try {
$this->dispatchContextCreate();
// Only API model currently has a map to update contacts based on the response.
$updatedFields = false;
if (method_exists($this->payloadModel, 'applyResponseMap')) {
/** @var bool $updatedFields */
$updatedFields = $this->payloadModel->applyResponseMap();
if ($updatedFields) {
$this->contact = $this->payloadModel->getContact();
}
}
/** @var Attribution $attribution */
$attribution = new Attribution($this->contactClient, $this->contact, $this->payloadModel);
/** @var bool $updatedAttribution */
$updatedAttribution = $attribution->applyAttribution();
if ($updatedAttribution) {
$this->attribution = $attribution->getAttributionChange();
$this->setLogs(strval(round($this->attribution, 4)), 'attribution');
if ($this->attribution && method_exists($this->payloadModel, 'setAttribution')) {
$this->payloadModel->setAttribution($this->attribution);
}
} else {
$this->setLogs('0', 'attribution');
}
$this->setLogs(strval(round($this->contact->getAttribution(), 4)), 'attributionTotal');
// If any fields were updated, save the Contact entity.
if ($updatedFields || $updatedAttribution) {
$this->getContactModel()->saveEntity($this->contact);
$this->setLogs('Operation successful. The contact was updated.', 'updated');
} else {
$this->setLogs('Operation successful, but no fields on the contact needed updating.', 'info');
}
if (!$updatedAttribution) {
// Fields may have updated, but not attribution, so the ledger needs an event to capture conversions.
$this->dispatchContextCapture();
}
} catch (\Exception $e) {
$this->valid = false;
$this->setLogs('Operation completed, but we failed to update our Contact. '.$e->getMessage(), 'error');
$this->logIntegrationError($e, $this->contact);
$this->retry = false;
}
} | [
"private",
"function",
"updateContact",
"(",
")",
"{",
"// Assume no attribution till calculated.",
"$",
"this",
"->",
"attribution",
"=",
"0",
";",
"// Do not update contacts for test runs.",
"if",
"(",
"$",
"this",
"->",
"test",
"||",
"!",
"$",
"this",
"->",
"payloadModel",
")",
"{",
"return",
";",
"}",
"// Only update contacts if success definitions are met.",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"dispatchContextCreate",
"(",
")",
";",
"// Only API model currently has a map to update contacts based on the response.",
"$",
"updatedFields",
"=",
"false",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"payloadModel",
",",
"'applyResponseMap'",
")",
")",
"{",
"/** @var bool $updatedFields */",
"$",
"updatedFields",
"=",
"$",
"this",
"->",
"payloadModel",
"->",
"applyResponseMap",
"(",
")",
";",
"if",
"(",
"$",
"updatedFields",
")",
"{",
"$",
"this",
"->",
"contact",
"=",
"$",
"this",
"->",
"payloadModel",
"->",
"getContact",
"(",
")",
";",
"}",
"}",
"/** @var Attribution $attribution */",
"$",
"attribution",
"=",
"new",
"Attribution",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"payloadModel",
")",
";",
"/** @var bool $updatedAttribution */",
"$",
"updatedAttribution",
"=",
"$",
"attribution",
"->",
"applyAttribution",
"(",
")",
";",
"if",
"(",
"$",
"updatedAttribution",
")",
"{",
"$",
"this",
"->",
"attribution",
"=",
"$",
"attribution",
"->",
"getAttributionChange",
"(",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"strval",
"(",
"round",
"(",
"$",
"this",
"->",
"attribution",
",",
"4",
")",
")",
",",
"'attribution'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"attribution",
"&&",
"method_exists",
"(",
"$",
"this",
"->",
"payloadModel",
",",
"'setAttribution'",
")",
")",
"{",
"$",
"this",
"->",
"payloadModel",
"->",
"setAttribution",
"(",
"$",
"this",
"->",
"attribution",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'0'",
",",
"'attribution'",
")",
";",
"}",
"$",
"this",
"->",
"setLogs",
"(",
"strval",
"(",
"round",
"(",
"$",
"this",
"->",
"contact",
"->",
"getAttribution",
"(",
")",
",",
"4",
")",
")",
",",
"'attributionTotal'",
")",
";",
"// If any fields were updated, save the Contact entity.",
"if",
"(",
"$",
"updatedFields",
"||",
"$",
"updatedAttribution",
")",
"{",
"$",
"this",
"->",
"getContactModel",
"(",
")",
"->",
"saveEntity",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"setLogs",
"(",
"'Operation successful. The contact was updated.'",
",",
"'updated'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLogs",
"(",
"'Operation successful, but no fields on the contact needed updating.'",
",",
"'info'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"updatedAttribution",
")",
"{",
"// Fields may have updated, but not attribution, so the ledger needs an event to capture conversions.",
"$",
"this",
"->",
"dispatchContextCapture",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"valid",
"=",
"false",
";",
"$",
"this",
"->",
"setLogs",
"(",
"'Operation completed, but we failed to update our Contact. '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'error'",
")",
";",
"$",
"this",
"->",
"logIntegrationError",
"(",
"$",
"e",
",",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"retry",
"=",
"false",
";",
"}",
"}"
] | Loop through the API Operation responses and find valid field mappings.
Set the new values to the contact and log the changes thereof. | [
"Loop",
"through",
"the",
"API",
"Operation",
"responses",
"and",
"find",
"valid",
"field",
"mappings",
".",
"Set",
"the",
"new",
"values",
"to",
"the",
"contact",
"and",
"log",
"the",
"changes",
"thereof",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L914-L974 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.dispatchContextCreate | private function dispatchContextCreate()
{
if ($this->test || !$this->payloadModel) {
return;
}
$campaign = $this->getCampaign();
$event = new ContactLedgerContextEvent(
$campaign, $this->contactClient, $this->statType, '0 Revenue conversion', $this->contact
);
$this->dispatcher->dispatch(
'mautic.contactledger.context_create',
$event
);
} | php | private function dispatchContextCreate()
{
if ($this->test || !$this->payloadModel) {
return;
}
$campaign = $this->getCampaign();
$event = new ContactLedgerContextEvent(
$campaign, $this->contactClient, $this->statType, '0 Revenue conversion', $this->contact
);
$this->dispatcher->dispatch(
'mautic.contactledger.context_create',
$event
);
} | [
"private",
"function",
"dispatchContextCreate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"||",
"!",
"$",
"this",
"->",
"payloadModel",
")",
"{",
"return",
";",
"}",
"$",
"campaign",
"=",
"$",
"this",
"->",
"getCampaign",
"(",
")",
";",
"$",
"event",
"=",
"new",
"ContactLedgerContextEvent",
"(",
"$",
"campaign",
",",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"statType",
",",
"'0 Revenue conversion'",
",",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'mautic.contactledger.context_create'",
",",
"$",
"event",
")",
";",
"}"
] | Provide context to Ledger plugin (or others) about this contact for save events. | [
"Provide",
"context",
"to",
"Ledger",
"plugin",
"(",
"or",
"others",
")",
"about",
"this",
"contact",
"for",
"save",
"events",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L979-L993 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.dispatchContextCapture | private function dispatchContextCapture()
{
if ($this->test || !$this->valid || !$this->payloadModel || Stat::TYPE_CONVERTED !== $this->statType) {
return;
}
$campaign = $this->getCampaign();
$event = new ContactLedgerContextEvent(
$campaign, $this->contactClient, $this->statType, null, $this->contact
);
$this->dispatcher->dispatch(
'mautic.contactledger.context_capture',
$event
);
} | php | private function dispatchContextCapture()
{
if ($this->test || !$this->valid || !$this->payloadModel || Stat::TYPE_CONVERTED !== $this->statType) {
return;
}
$campaign = $this->getCampaign();
$event = new ContactLedgerContextEvent(
$campaign, $this->contactClient, $this->statType, null, $this->contact
);
$this->dispatcher->dispatch(
'mautic.contactledger.context_capture',
$event
);
} | [
"private",
"function",
"dispatchContextCapture",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"test",
"||",
"!",
"$",
"this",
"->",
"valid",
"||",
"!",
"$",
"this",
"->",
"payloadModel",
"||",
"Stat",
"::",
"TYPE_CONVERTED",
"!==",
"$",
"this",
"->",
"statType",
")",
"{",
"return",
";",
"}",
"$",
"campaign",
"=",
"$",
"this",
"->",
"getCampaign",
"(",
")",
";",
"$",
"event",
"=",
"new",
"ContactLedgerContextEvent",
"(",
"$",
"campaign",
",",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"statType",
",",
"null",
",",
"$",
"this",
"->",
"contact",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'mautic.contactledger.context_capture'",
",",
"$",
"event",
")",
";",
"}"
] | For situations where there is no entity saved, but we still need to log a conversion. | [
"For",
"situations",
"where",
"there",
"is",
"no",
"entity",
"saved",
"but",
"we",
"still",
"need",
"to",
"log",
"a",
"conversion",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L998-L1012 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.createCache | private function createCache()
{
if (!$this->test && $this->valid) {
try {
$this->getCacheModel()->create();
} catch (Exception $e) {
// Do not log this as an error, because the contact was sent successfully.
$this->setLogs(
'Caching issue which may impact duplicates/exclusivity/limits: '.$e->getMessage(),
'warning'
);
}
}
} | php | private function createCache()
{
if (!$this->test && $this->valid) {
try {
$this->getCacheModel()->create();
} catch (Exception $e) {
// Do not log this as an error, because the contact was sent successfully.
$this->setLogs(
'Caching issue which may impact duplicates/exclusivity/limits: '.$e->getMessage(),
'warning'
);
}
}
} | [
"private",
"function",
"createCache",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"test",
"&&",
"$",
"this",
"->",
"valid",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getCacheModel",
"(",
")",
"->",
"create",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Do not log this as an error, because the contact was sent successfully.",
"$",
"this",
"->",
"setLogs",
"(",
"'Caching issue which may impact duplicates/exclusivity/limits: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'warning'",
")",
";",
"}",
"}",
"}"
] | If all went well, and a contact was sent, create a cache entity for later correlation on exclusive/duplicate/
limit rules. | [
"If",
"all",
"went",
"well",
"and",
"a",
"contact",
"was",
"sent",
"create",
"a",
"cache",
"entity",
"for",
"later",
"correlation",
"on",
"exclusive",
"/",
"duplicate",
"/",
"limit",
"rules",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L1018-L1031 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.logResults | private function logResults()
{
// Do not log the results of a test?
if ($this->test) {
return;
}
$integrationEntityId = !empty($this->payloadModel) ? $this->payloadModel->getExternalId() : null;
/** @var contactClientModel $clientModel */
$clientModel = $this->getContactClientModel();
// Stats - contactclient_stats
$errors = $this->getLogs('error');
$this->statType = !empty($this->statType) ? $this->statType : Stat::TYPE_ERROR;
$this->addTrace('contactClientStatType', $this->statType);
$message = '';
if ($this->valid) {
$statLevel = 'INFO';
switch ($this->contactClient->getType()) {
case 'api':
$message = 'Contact was sent successfully.';
break;
case 'file':
$message = 'Contact queued for the next file payload.';
break;
}
} else {
$statLevel = 'ERROR';
$message = $errors ? implode(PHP_EOL, $errors) : 'An unexpected issue occurred.';
}
// Session storage for external plugins (should probably be dispatcher instead).
$events = $this->getSession()->get('mautic.contactClient.events', []);
$events[] = [
'id' => isset($this->event['id']) ? $this->event['id'] : 'NA',
'name' => isset($this->event['name']) ? $this->event['name'] : null,
'valid' => $this->valid,
'statType' => $this->statType,
'errors' => $errors,
'contactId' => $this->contact ? $this->contact->getId() : null,
'contactClientId' => $this->contactClient ? $this->contactClient->getId() : null,
'contactClientName' => $this->contactClient ? $this->contactClient->getName() : null,
];
$this->getSession()->set('mautic.contactClient.events', $events);
// get the original / first utm source code for contact
$utmSource = null;
if ($this->contact) {
try {
/** @var \MauticPlugin\MauticContactClientBundle\Helper\UtmSourceHelper $utmHelper */
$utmHelper = $this->container->get('mautic.contactclient.helper.utmsource');
$utmSource = $utmHelper->getFirstUtmSource($this->contact);
} catch (\Exception $e) {
}
}
// Add log entry for statistics / charts.
$eventId = (isset($this->event['id']) && $this->event['id']) ? $this->event['id'] : 0;
$campaignId = (isset($this->event['campaignId']) && $this->event['campaignId']) ? $this->event['campaignId'] : 0;
$clientModel->addStat(
$this->contactClient,
$this->statType,
$this->contact,
$this->attribution,
$utmSource,
$campaignId,
$eventId
);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Stat');
// Add transactional event for deep dive into logs.
if ($this->contact && $this->contactClient) {
$clientModel->addEvent(
$this->contactClient,
$this->statType,
$this->contact,
$this->getLogsJSON(),
$message,
$integrationEntityId
);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Event');
}
// Lead event log (lead_event_log) I've decided to leave this out for now because it's not very useful.
//$contactModel = $this->getContainer()->get('mautic.lead.model.lead');
//$eventLogRepo = $contactModel->getEventLogRepository();
//$eventLog = new LeadEventLog();
//$eventLog
// ->setUserId($this->contactClient->getCreatedBy())
// ->setUserName($this->contactClient->getCreatedByUser())
// ->setBundle('lead')
// ->setObject('import')
// ->setObjectId($this->contactClient->getId())
// ->setLead($this->contact)
// ->setAction('updated')
// ->setProperties($this->logs);
//$eventLogRepo->saveEntity($eventLog);
// $this->dispatchIntegrationKeyEvent()
// Integration entity creation (shows up under Integrations in a Contact).
if ($this->valid) {
$integrationEntities = [
$this->saveSyncedData(
'Client',
'ContactClient',
$this->contactClient ? $this->contactClient->getId() : null,
$this->contact
),
];
if (!empty($integrationEntities)) {
$this->em->getRepository('MauticPluginBundle:IntegrationEntity')->saveEntities($integrationEntities);
$this->em->clear('Mautic\PluginBundle\Entity\IntegrationEntity');
}
}
// File-based logging.
$this->getLogger()->log(
$statLevel,
'Contact Client '.($this->contactClient ? $this->contactClient->getId() : 'NA').': '.$message
);
} | php | private function logResults()
{
// Do not log the results of a test?
if ($this->test) {
return;
}
$integrationEntityId = !empty($this->payloadModel) ? $this->payloadModel->getExternalId() : null;
/** @var contactClientModel $clientModel */
$clientModel = $this->getContactClientModel();
// Stats - contactclient_stats
$errors = $this->getLogs('error');
$this->statType = !empty($this->statType) ? $this->statType : Stat::TYPE_ERROR;
$this->addTrace('contactClientStatType', $this->statType);
$message = '';
if ($this->valid) {
$statLevel = 'INFO';
switch ($this->contactClient->getType()) {
case 'api':
$message = 'Contact was sent successfully.';
break;
case 'file':
$message = 'Contact queued for the next file payload.';
break;
}
} else {
$statLevel = 'ERROR';
$message = $errors ? implode(PHP_EOL, $errors) : 'An unexpected issue occurred.';
}
// Session storage for external plugins (should probably be dispatcher instead).
$events = $this->getSession()->get('mautic.contactClient.events', []);
$events[] = [
'id' => isset($this->event['id']) ? $this->event['id'] : 'NA',
'name' => isset($this->event['name']) ? $this->event['name'] : null,
'valid' => $this->valid,
'statType' => $this->statType,
'errors' => $errors,
'contactId' => $this->contact ? $this->contact->getId() : null,
'contactClientId' => $this->contactClient ? $this->contactClient->getId() : null,
'contactClientName' => $this->contactClient ? $this->contactClient->getName() : null,
];
$this->getSession()->set('mautic.contactClient.events', $events);
// get the original / first utm source code for contact
$utmSource = null;
if ($this->contact) {
try {
/** @var \MauticPlugin\MauticContactClientBundle\Helper\UtmSourceHelper $utmHelper */
$utmHelper = $this->container->get('mautic.contactclient.helper.utmsource');
$utmSource = $utmHelper->getFirstUtmSource($this->contact);
} catch (\Exception $e) {
}
}
// Add log entry for statistics / charts.
$eventId = (isset($this->event['id']) && $this->event['id']) ? $this->event['id'] : 0;
$campaignId = (isset($this->event['campaignId']) && $this->event['campaignId']) ? $this->event['campaignId'] : 0;
$clientModel->addStat(
$this->contactClient,
$this->statType,
$this->contact,
$this->attribution,
$utmSource,
$campaignId,
$eventId
);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Stat');
// Add transactional event for deep dive into logs.
if ($this->contact && $this->contactClient) {
$clientModel->addEvent(
$this->contactClient,
$this->statType,
$this->contact,
$this->getLogsJSON(),
$message,
$integrationEntityId
);
$this->em->clear('MauticPlugin\MauticContactClientBundle\Entity\Event');
}
// Lead event log (lead_event_log) I've decided to leave this out for now because it's not very useful.
//$contactModel = $this->getContainer()->get('mautic.lead.model.lead');
//$eventLogRepo = $contactModel->getEventLogRepository();
//$eventLog = new LeadEventLog();
//$eventLog
// ->setUserId($this->contactClient->getCreatedBy())
// ->setUserName($this->contactClient->getCreatedByUser())
// ->setBundle('lead')
// ->setObject('import')
// ->setObjectId($this->contactClient->getId())
// ->setLead($this->contact)
// ->setAction('updated')
// ->setProperties($this->logs);
//$eventLogRepo->saveEntity($eventLog);
// $this->dispatchIntegrationKeyEvent()
// Integration entity creation (shows up under Integrations in a Contact).
if ($this->valid) {
$integrationEntities = [
$this->saveSyncedData(
'Client',
'ContactClient',
$this->contactClient ? $this->contactClient->getId() : null,
$this->contact
),
];
if (!empty($integrationEntities)) {
$this->em->getRepository('MauticPluginBundle:IntegrationEntity')->saveEntities($integrationEntities);
$this->em->clear('Mautic\PluginBundle\Entity\IntegrationEntity');
}
}
// File-based logging.
$this->getLogger()->log(
$statLevel,
'Contact Client '.($this->contactClient ? $this->contactClient->getId() : 'NA').': '.$message
);
} | [
"private",
"function",
"logResults",
"(",
")",
"{",
"// Do not log the results of a test?",
"if",
"(",
"$",
"this",
"->",
"test",
")",
"{",
"return",
";",
"}",
"$",
"integrationEntityId",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"payloadModel",
")",
"?",
"$",
"this",
"->",
"payloadModel",
"->",
"getExternalId",
"(",
")",
":",
"null",
";",
"/** @var contactClientModel $clientModel */",
"$",
"clientModel",
"=",
"$",
"this",
"->",
"getContactClientModel",
"(",
")",
";",
"// Stats - contactclient_stats",
"$",
"errors",
"=",
"$",
"this",
"->",
"getLogs",
"(",
"'error'",
")",
";",
"$",
"this",
"->",
"statType",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"statType",
")",
"?",
"$",
"this",
"->",
"statType",
":",
"Stat",
"::",
"TYPE_ERROR",
";",
"$",
"this",
"->",
"addTrace",
"(",
"'contactClientStatType'",
",",
"$",
"this",
"->",
"statType",
")",
";",
"$",
"message",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"valid",
")",
"{",
"$",
"statLevel",
"=",
"'INFO'",
";",
"switch",
"(",
"$",
"this",
"->",
"contactClient",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'api'",
":",
"$",
"message",
"=",
"'Contact was sent successfully.'",
";",
"break",
";",
"case",
"'file'",
":",
"$",
"message",
"=",
"'Contact queued for the next file payload.'",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"statLevel",
"=",
"'ERROR'",
";",
"$",
"message",
"=",
"$",
"errors",
"?",
"implode",
"(",
"PHP_EOL",
",",
"$",
"errors",
")",
":",
"'An unexpected issue occurred.'",
";",
"}",
"// Session storage for external plugins (should probably be dispatcher instead).",
"$",
"events",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"'mautic.contactClient.events'",
",",
"[",
"]",
")",
";",
"$",
"events",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
"?",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
":",
"'NA'",
",",
"'name'",
"=>",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'name'",
"]",
")",
"?",
"$",
"this",
"->",
"event",
"[",
"'name'",
"]",
":",
"null",
",",
"'valid'",
"=>",
"$",
"this",
"->",
"valid",
",",
"'statType'",
"=>",
"$",
"this",
"->",
"statType",
",",
"'errors'",
"=>",
"$",
"errors",
",",
"'contactId'",
"=>",
"$",
"this",
"->",
"contact",
"?",
"$",
"this",
"->",
"contact",
"->",
"getId",
"(",
")",
":",
"null",
",",
"'contactClientId'",
"=>",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
":",
"null",
",",
"'contactClientName'",
"=>",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getName",
"(",
")",
":",
"null",
",",
"]",
";",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"set",
"(",
"'mautic.contactClient.events'",
",",
"$",
"events",
")",
";",
"// get the original / first utm source code for contact",
"$",
"utmSource",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"contact",
")",
"{",
"try",
"{",
"/** @var \\MauticPlugin\\MauticContactClientBundle\\Helper\\UtmSourceHelper $utmHelper */",
"$",
"utmHelper",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mautic.contactclient.helper.utmsource'",
")",
";",
"$",
"utmSource",
"=",
"$",
"utmHelper",
"->",
"getFirstUtmSource",
"(",
"$",
"this",
"->",
"contact",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"// Add log entry for statistics / charts.",
"$",
"eventId",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
"&&",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
")",
"?",
"$",
"this",
"->",
"event",
"[",
"'id'",
"]",
":",
"0",
";",
"$",
"campaignId",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
")",
"&&",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
")",
"?",
"$",
"this",
"->",
"event",
"[",
"'campaignId'",
"]",
":",
"0",
";",
"$",
"clientModel",
"->",
"addStat",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"statType",
",",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"attribution",
",",
"$",
"utmSource",
",",
"$",
"campaignId",
",",
"$",
"eventId",
")",
";",
"$",
"this",
"->",
"em",
"->",
"clear",
"(",
"'MauticPlugin\\MauticContactClientBundle\\Entity\\Stat'",
")",
";",
"// Add transactional event for deep dive into logs.",
"if",
"(",
"$",
"this",
"->",
"contact",
"&&",
"$",
"this",
"->",
"contactClient",
")",
"{",
"$",
"clientModel",
"->",
"addEvent",
"(",
"$",
"this",
"->",
"contactClient",
",",
"$",
"this",
"->",
"statType",
",",
"$",
"this",
"->",
"contact",
",",
"$",
"this",
"->",
"getLogsJSON",
"(",
")",
",",
"$",
"message",
",",
"$",
"integrationEntityId",
")",
";",
"$",
"this",
"->",
"em",
"->",
"clear",
"(",
"'MauticPlugin\\MauticContactClientBundle\\Entity\\Event'",
")",
";",
"}",
"// Lead event log (lead_event_log) I've decided to leave this out for now because it's not very useful.",
"//$contactModel = $this->getContainer()->get('mautic.lead.model.lead');",
"//$eventLogRepo = $contactModel->getEventLogRepository();",
"//$eventLog = new LeadEventLog();",
"//$eventLog",
"// ->setUserId($this->contactClient->getCreatedBy())",
"// ->setUserName($this->contactClient->getCreatedByUser())",
"// ->setBundle('lead')",
"// ->setObject('import')",
"// ->setObjectId($this->contactClient->getId())",
"// ->setLead($this->contact)",
"// ->setAction('updated')",
"// ->setProperties($this->logs);",
"//$eventLogRepo->saveEntity($eventLog);",
"// $this->dispatchIntegrationKeyEvent()",
"// Integration entity creation (shows up under Integrations in a Contact).",
"if",
"(",
"$",
"this",
"->",
"valid",
")",
"{",
"$",
"integrationEntities",
"=",
"[",
"$",
"this",
"->",
"saveSyncedData",
"(",
"'Client'",
",",
"'ContactClient'",
",",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
":",
"null",
",",
"$",
"this",
"->",
"contact",
")",
",",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"integrationEntities",
")",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'MauticPluginBundle:IntegrationEntity'",
")",
"->",
"saveEntities",
"(",
"$",
"integrationEntities",
")",
";",
"$",
"this",
"->",
"em",
"->",
"clear",
"(",
"'Mautic\\PluginBundle\\Entity\\IntegrationEntity'",
")",
";",
"}",
"}",
"// File-based logging.",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"statLevel",
",",
"'Contact Client '",
".",
"(",
"$",
"this",
"->",
"contactClient",
"?",
"$",
"this",
"->",
"contactClient",
"->",
"getId",
"(",
")",
":",
"'NA'",
")",
".",
"': '",
".",
"$",
"message",
")",
";",
"}"
] | Log to:
contactclient_stats
contactclient_events
integration_entity. | [
"Log",
"to",
":",
"contactclient_stats",
"contactclient_events",
"integration_entity",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L1039-L1161 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.getLogs | public function getLogs($key = '')
{
if ($key) {
if (isset($this->logs[$key])) {
if (!is_array($this->logs[$key])) {
return [$this->logs[$key]];
} else {
return $this->logs[$key];
}
} else {
return null;
}
}
return $this->logs;
} | php | public function getLogs($key = '')
{
if ($key) {
if (isset($this->logs[$key])) {
if (!is_array($this->logs[$key])) {
return [$this->logs[$key]];
} else {
return $this->logs[$key];
}
} else {
return null;
}
}
return $this->logs;
} | [
"public",
"function",
"getLogs",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"logs",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"logs",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"[",
"$",
"this",
"->",
"logs",
"[",
"$",
"key",
"]",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"logs",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"logs",
";",
"}"
] | @param string $key
@return array|mixed|null | [
"@param",
"string",
"$key"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L1168-L1183 |
TheDMSGroup/mautic-contact-client | Integration/ClientIntegration.php | ClientIntegration.appendToForm | public function appendToForm(&$builder, $data, $formArea)
{
if ('integration' == $formArea) {
if ($this->isAuthorized()) {
/** @var contactClientModel $clientModel */
$clientModel = $this->getContactClientModel();
/** @var contactClientRepository $contactClientRepo */
$contactClientRepo = $clientModel->getRepository();
$contactClientEntities = $contactClientRepo->getEntities();
$clients = ['' => ''];
$overrides = [];
foreach ($contactClientEntities as $contactClientEntity) {
if ($contactClientEntity->getIsPublished()) {
$id = $contactClientEntity->getId();
$clients[$id] = $contactClientEntity->getName();
// Get overridable fields from the payload of the type needed.
try {
$overrides[$id] = $this->getPayloadModel($contactClientEntity)
->getOverrides();
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->error($e->getMessage());
}
$clients[$id] .= ' ('.$e->getMessage().')';
}
}
}
if (1 === count($clients)) {
$clients = ['', '-- No Clients have been created and published --'];
}
$builder->add(
'contactclient',
'choice',
[
'choices' => $clients,
'expanded' => false,
'label_attr' => ['class' => 'control-label'],
'multiple' => false,
'label' => 'mautic.contactclient.integration.client',
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.contactclient.integration.client.tooltip',
// Auto-set the integration name based on the client.
'onchange' => "var client = mQuery('#campaignevent_properties_config_contactclient:first'),".
" eventName = mQuery('#campaignevent_name');".
'if (client.length && client.val() && eventName.length) {'.
' eventName.val(client.find("option:selected:first").text().trim());'.
'}',
],
'required' => true,
'constraints' => [
new NotBlank(
['message' => 'mautic.core.value.required']
),
],
'choice_attr' => function ($val, $key, $index) use ($overrides) {
$results = [];
// adds a class like attending_yes, attending_no, etc
if ($val && isset($overrides[$val])) {
$results['class'] = 'contact-client-'.$val;
// Change format to match json schema.
$results['data-overridable-fields'] = json_encode($overrides[$val]);
}
return $results;
},
]
);
$builder->add(
'contactclient_overrides_button',
'button',
[
'label' => 'mautic.contactclient.integration.overrides',
'attr' => [
'class' => 'btn btn-default',
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
// Shim to get our javascript over the border and into Integration land.
'onclick' => "if (typeof Mautic.contactclientIntegrationPre === 'undefined') {".
" mQuery.getScript(mauticBasePath + '/' + mauticAssetPrefix + 'plugins/MauticContactClientBundle/Assets/build/contactclient.min.js', function(){".
' Mautic.contactclientIntegrationPre();'.
' });'.
'} else {'.
' Mautic.contactclientIntegrationPre();'.
'}',
'icon' => 'fa fa-wrench',
],
]
);
$builder->add(
'contactclient_overrides',
'textarea',
[
'label' => 'mautic.contactclient.integration.overrides',
'label_attr' => ['class' => 'control-label hide'],
'attr' => [
'class' => 'form-control hide',
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
],
'required' => false,
]
);
}
}
if ('features' == $formArea) {
$builder->add(
'email_from',
'text',
[
'label' => $this->translator->trans('mautic.contactclient.email.from'),
'data' => !isset($data['email_from']) ? '' : $data['email_from'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.from.tooltip'),
],
'required' => false,
]
);
$builder->add(
'success_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.success_message'),
'data' => !isset($data['success_message']) ? '' : $data['success_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.success_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'empty_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.empty_message'),
'data' => !isset($data['empty_message']) ? '' : $data['empty_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.empty_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'empty_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.empty_message'),
'data' => !isset($data['empty_message']) ? '' : $data['empty_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.empty_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'footer',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.footer'),
'data' => !isset($data['footer']) ? '' : $data['footer'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.footer.tooltip'),
],
'required' => false,
]
);
}
} | php | public function appendToForm(&$builder, $data, $formArea)
{
if ('integration' == $formArea) {
if ($this->isAuthorized()) {
/** @var contactClientModel $clientModel */
$clientModel = $this->getContactClientModel();
/** @var contactClientRepository $contactClientRepo */
$contactClientRepo = $clientModel->getRepository();
$contactClientEntities = $contactClientRepo->getEntities();
$clients = ['' => ''];
$overrides = [];
foreach ($contactClientEntities as $contactClientEntity) {
if ($contactClientEntity->getIsPublished()) {
$id = $contactClientEntity->getId();
$clients[$id] = $contactClientEntity->getName();
// Get overridable fields from the payload of the type needed.
try {
$overrides[$id] = $this->getPayloadModel($contactClientEntity)
->getOverrides();
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->error($e->getMessage());
}
$clients[$id] .= ' ('.$e->getMessage().')';
}
}
}
if (1 === count($clients)) {
$clients = ['', '-- No Clients have been created and published --'];
}
$builder->add(
'contactclient',
'choice',
[
'choices' => $clients,
'expanded' => false,
'label_attr' => ['class' => 'control-label'],
'multiple' => false,
'label' => 'mautic.contactclient.integration.client',
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.contactclient.integration.client.tooltip',
// Auto-set the integration name based on the client.
'onchange' => "var client = mQuery('#campaignevent_properties_config_contactclient:first'),".
" eventName = mQuery('#campaignevent_name');".
'if (client.length && client.val() && eventName.length) {'.
' eventName.val(client.find("option:selected:first").text().trim());'.
'}',
],
'required' => true,
'constraints' => [
new NotBlank(
['message' => 'mautic.core.value.required']
),
],
'choice_attr' => function ($val, $key, $index) use ($overrides) {
$results = [];
// adds a class like attending_yes, attending_no, etc
if ($val && isset($overrides[$val])) {
$results['class'] = 'contact-client-'.$val;
// Change format to match json schema.
$results['data-overridable-fields'] = json_encode($overrides[$val]);
}
return $results;
},
]
);
$builder->add(
'contactclient_overrides_button',
'button',
[
'label' => 'mautic.contactclient.integration.overrides',
'attr' => [
'class' => 'btn btn-default',
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
// Shim to get our javascript over the border and into Integration land.
'onclick' => "if (typeof Mautic.contactclientIntegrationPre === 'undefined') {".
" mQuery.getScript(mauticBasePath + '/' + mauticAssetPrefix + 'plugins/MauticContactClientBundle/Assets/build/contactclient.min.js', function(){".
' Mautic.contactclientIntegrationPre();'.
' });'.
'} else {'.
' Mautic.contactclientIntegrationPre();'.
'}',
'icon' => 'fa fa-wrench',
],
]
);
$builder->add(
'contactclient_overrides',
'textarea',
[
'label' => 'mautic.contactclient.integration.overrides',
'label_attr' => ['class' => 'control-label hide'],
'attr' => [
'class' => 'form-control hide',
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
],
'required' => false,
]
);
}
}
if ('features' == $formArea) {
$builder->add(
'email_from',
'text',
[
'label' => $this->translator->trans('mautic.contactclient.email.from'),
'data' => !isset($data['email_from']) ? '' : $data['email_from'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.from.tooltip'),
],
'required' => false,
]
);
$builder->add(
'success_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.success_message'),
'data' => !isset($data['success_message']) ? '' : $data['success_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.success_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'empty_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.empty_message'),
'data' => !isset($data['empty_message']) ? '' : $data['empty_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.empty_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'empty_message',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.empty_message'),
'data' => !isset($data['empty_message']) ? '' : $data['empty_message'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.empty_message.tooltip'),
],
'required' => false,
]
);
$builder->add(
'footer',
'textarea',
[
'label' => $this->translator->trans('mautic.contactclient.email.footer'),
'data' => !isset($data['footer']) ? '' : $data['footer'],
'attr' => [
'tooltip' => $this->translator->trans('mautic.contactclient.email.footer.tooltip'),
],
'required' => false,
]
);
}
} | [
"public",
"function",
"appendToForm",
"(",
"&",
"$",
"builder",
",",
"$",
"data",
",",
"$",
"formArea",
")",
"{",
"if",
"(",
"'integration'",
"==",
"$",
"formArea",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAuthorized",
"(",
")",
")",
"{",
"/** @var contactClientModel $clientModel */",
"$",
"clientModel",
"=",
"$",
"this",
"->",
"getContactClientModel",
"(",
")",
";",
"/** @var contactClientRepository $contactClientRepo */",
"$",
"contactClientRepo",
"=",
"$",
"clientModel",
"->",
"getRepository",
"(",
")",
";",
"$",
"contactClientEntities",
"=",
"$",
"contactClientRepo",
"->",
"getEntities",
"(",
")",
";",
"$",
"clients",
"=",
"[",
"''",
"=>",
"''",
"]",
";",
"$",
"overrides",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contactClientEntities",
"as",
"$",
"contactClientEntity",
")",
"{",
"if",
"(",
"$",
"contactClientEntity",
"->",
"getIsPublished",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"contactClientEntity",
"->",
"getId",
"(",
")",
";",
"$",
"clients",
"[",
"$",
"id",
"]",
"=",
"$",
"contactClientEntity",
"->",
"getName",
"(",
")",
";",
"// Get overridable fields from the payload of the type needed.",
"try",
"{",
"$",
"overrides",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"getPayloadModel",
"(",
"$",
"contactClientEntity",
")",
"->",
"getOverrides",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"clients",
"[",
"$",
"id",
"]",
".=",
"' ('",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"')'",
";",
"}",
"}",
"}",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"clients",
")",
")",
"{",
"$",
"clients",
"=",
"[",
"''",
",",
"'-- No Clients have been created and published --'",
"]",
";",
"}",
"$",
"builder",
"->",
"add",
"(",
"'contactclient'",
",",
"'choice'",
",",
"[",
"'choices'",
"=>",
"$",
"clients",
",",
"'expanded'",
"=>",
"false",
",",
"'label_attr'",
"=>",
"[",
"'class'",
"=>",
"'control-label'",
"]",
",",
"'multiple'",
"=>",
"false",
",",
"'label'",
"=>",
"'mautic.contactclient.integration.client'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'form-control'",
",",
"'tooltip'",
"=>",
"'mautic.contactclient.integration.client.tooltip'",
",",
"// Auto-set the integration name based on the client.",
"'onchange'",
"=>",
"\"var client = mQuery('#campaignevent_properties_config_contactclient:first'),\"",
".",
"\" eventName = mQuery('#campaignevent_name');\"",
".",
"'if (client.length && client.val() && eventName.length) {'",
".",
"' eventName.val(client.find(\"option:selected:first\").text().trim());'",
".",
"'}'",
",",
"]",
",",
"'required'",
"=>",
"true",
",",
"'constraints'",
"=>",
"[",
"new",
"NotBlank",
"(",
"[",
"'message'",
"=>",
"'mautic.core.value.required'",
"]",
")",
",",
"]",
",",
"'choice_attr'",
"=>",
"function",
"(",
"$",
"val",
",",
"$",
"key",
",",
"$",
"index",
")",
"use",
"(",
"$",
"overrides",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"// adds a class like attending_yes, attending_no, etc",
"if",
"(",
"$",
"val",
"&&",
"isset",
"(",
"$",
"overrides",
"[",
"$",
"val",
"]",
")",
")",
"{",
"$",
"results",
"[",
"'class'",
"]",
"=",
"'contact-client-'",
".",
"$",
"val",
";",
"// Change format to match json schema.",
"$",
"results",
"[",
"'data-overridable-fields'",
"]",
"=",
"json_encode",
"(",
"$",
"overrides",
"[",
"$",
"val",
"]",
")",
";",
"}",
"return",
"$",
"results",
";",
"}",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'contactclient_overrides_button'",
",",
"'button'",
",",
"[",
"'label'",
"=>",
"'mautic.contactclient.integration.overrides'",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'btn btn-default'",
",",
"'tooltip'",
"=>",
"'mautic.contactclient.integration.overrides.tooltip'",
",",
"// Shim to get our javascript over the border and into Integration land.",
"'onclick'",
"=>",
"\"if (typeof Mautic.contactclientIntegrationPre === 'undefined') {\"",
".",
"\" mQuery.getScript(mauticBasePath + '/' + mauticAssetPrefix + 'plugins/MauticContactClientBundle/Assets/build/contactclient.min.js', function(){\"",
".",
"' Mautic.contactclientIntegrationPre();'",
".",
"' });'",
".",
"'} else {'",
".",
"' Mautic.contactclientIntegrationPre();'",
".",
"'}'",
",",
"'icon'",
"=>",
"'fa fa-wrench'",
",",
"]",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'contactclient_overrides'",
",",
"'textarea'",
",",
"[",
"'label'",
"=>",
"'mautic.contactclient.integration.overrides'",
",",
"'label_attr'",
"=>",
"[",
"'class'",
"=>",
"'control-label hide'",
"]",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'form-control hide'",
",",
"'tooltip'",
"=>",
"'mautic.contactclient.integration.overrides.tooltip'",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"}",
"}",
"if",
"(",
"'features'",
"==",
"$",
"formArea",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"'email_from'",
",",
"'text'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.from'",
")",
",",
"'data'",
"=>",
"!",
"isset",
"(",
"$",
"data",
"[",
"'email_from'",
"]",
")",
"?",
"''",
":",
"$",
"data",
"[",
"'email_from'",
"]",
",",
"'attr'",
"=>",
"[",
"'tooltip'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.from.tooltip'",
")",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'success_message'",
",",
"'textarea'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.success_message'",
")",
",",
"'data'",
"=>",
"!",
"isset",
"(",
"$",
"data",
"[",
"'success_message'",
"]",
")",
"?",
"''",
":",
"$",
"data",
"[",
"'success_message'",
"]",
",",
"'attr'",
"=>",
"[",
"'tooltip'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.success_message.tooltip'",
")",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'empty_message'",
",",
"'textarea'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.empty_message'",
")",
",",
"'data'",
"=>",
"!",
"isset",
"(",
"$",
"data",
"[",
"'empty_message'",
"]",
")",
"?",
"''",
":",
"$",
"data",
"[",
"'empty_message'",
"]",
",",
"'attr'",
"=>",
"[",
"'tooltip'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.empty_message.tooltip'",
")",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'empty_message'",
",",
"'textarea'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.empty_message'",
")",
",",
"'data'",
"=>",
"!",
"isset",
"(",
"$",
"data",
"[",
"'empty_message'",
"]",
")",
"?",
"''",
":",
"$",
"data",
"[",
"'empty_message'",
"]",
",",
"'attr'",
"=>",
"[",
"'tooltip'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.empty_message.tooltip'",
")",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'footer'",
",",
"'textarea'",
",",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.footer'",
")",
",",
"'data'",
"=>",
"!",
"isset",
"(",
"$",
"data",
"[",
"'footer'",
"]",
")",
"?",
"''",
":",
"$",
"data",
"[",
"'footer'",
"]",
",",
"'attr'",
"=>",
"[",
"'tooltip'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.email.footer.tooltip'",
")",
",",
"]",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"}",
"}"
] | @param \Symfony\Component\Form\FormBuilder $builder
@param array $data
@param string $formArea
@throws Exception | [
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Form",
"\\",
"FormBuilder",
"$builder",
"@param",
"array",
"$data",
"@param",
"string",
"$formArea"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Integration/ClientIntegration.php#L1267-L1442 |
TheDMSGroup/mautic-contact-client | Helper/JSONHelper.php | JSONHelper.decodeArray | public function decodeArray($string, $fieldName = null, $assoc = false)
{
if (empty($string)) {
return [];
}
$array = self::decode($string, $fieldName, $assoc);
if (is_string($array)) {
$array = self::decode($array, $fieldName, $assoc);
}
if (!is_array($array)) {
throw new \Exception('The field '.$fieldName.' is not a JSON array as expected.');
}
return $array;
} | php | public function decodeArray($string, $fieldName = null, $assoc = false)
{
if (empty($string)) {
return [];
}
$array = self::decode($string, $fieldName, $assoc);
if (is_string($array)) {
$array = self::decode($array, $fieldName, $assoc);
}
if (!is_array($array)) {
throw new \Exception('The field '.$fieldName.' is not a JSON array as expected.');
}
return $array;
} | [
"public",
"function",
"decodeArray",
"(",
"$",
"string",
",",
"$",
"fieldName",
"=",
"null",
",",
"$",
"assoc",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"array",
"=",
"self",
"::",
"decode",
"(",
"$",
"string",
",",
"$",
"fieldName",
",",
"$",
"assoc",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"array",
")",
")",
"{",
"$",
"array",
"=",
"self",
"::",
"decode",
"(",
"$",
"array",
",",
"$",
"fieldName",
",",
"$",
"assoc",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'The field '",
".",
"$",
"fieldName",
".",
"' is not a JSON array as expected.'",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | @param $string
@param string $fieldName
@param bool $assoc
@return mixed
@throws \Exception | [
"@param",
"$string",
"@param",
"string",
"$fieldName",
"@param",
"bool",
"$assoc"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/JSONHelper.php#L28-L42 |
TheDMSGroup/mautic-contact-client | Helper/JSONHelper.php | JSONHelper.decode | private function decode($string, $fieldName, $assoc = false)
{
$jsonError = false;
$result = json_decode($string, $assoc);
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$jsonError = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$jsonError = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$jsonError = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$jsonError = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
$jsonError = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$jsonError = 'Unknown error';
break;
}
if ($jsonError) {
throw new \Exception('JSON is invalid in field '.$fieldName.' JSON error: '.$jsonError);
}
return $result;
} | php | private function decode($string, $fieldName, $assoc = false)
{
$jsonError = false;
$result = json_decode($string, $assoc);
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$jsonError = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$jsonError = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$jsonError = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$jsonError = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
$jsonError = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$jsonError = 'Unknown error';
break;
}
if ($jsonError) {
throw new \Exception('JSON is invalid in field '.$fieldName.' JSON error: '.$jsonError);
}
return $result;
} | [
"private",
"function",
"decode",
"(",
"$",
"string",
",",
"$",
"fieldName",
",",
"$",
"assoc",
"=",
"false",
")",
"{",
"$",
"jsonError",
"=",
"false",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"string",
",",
"$",
"assoc",
")",
";",
"switch",
"(",
"json_last_error",
"(",
")",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"break",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"$",
"jsonError",
"=",
"'Maximum stack depth exceeded'",
";",
"break",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"$",
"jsonError",
"=",
"'Underflow or the modes mismatch'",
";",
"break",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"$",
"jsonError",
"=",
"'Unexpected control character found'",
";",
"break",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"$",
"jsonError",
"=",
"'Syntax error, malformed JSON'",
";",
"break",
";",
"case",
"JSON_ERROR_UTF8",
":",
"$",
"jsonError",
"=",
"'Malformed UTF-8 characters, possibly incorrectly encoded'",
";",
"break",
";",
"default",
":",
"$",
"jsonError",
"=",
"'Unknown error'",
";",
"break",
";",
"}",
"if",
"(",
"$",
"jsonError",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'JSON is invalid in field '",
".",
"$",
"fieldName",
".",
"' JSON error: '",
".",
"$",
"jsonError",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | @param $string
@param $fieldName
@param bool $assoc
@return mixed
@throws \Exception | [
"@param",
"$string",
"@param",
"$fieldName",
"@param",
"bool",
"$assoc"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/JSONHelper.php#L53-L84 |
TheDMSGroup/mautic-contact-client | Helper/JSONHelper.php | JSONHelper.decodeObject | public function decodeObject($string, $fieldName = null)
{
if (empty($string)) {
return new \stdClass();
}
$object = self::decode($string, $fieldName);
if (is_string($object)) {
$object = self::decode($object, $fieldName);
}
if (!is_object($object)) {
throw new \Exception('The field '.$fieldName.' is not a JSON object as expected.');
}
return $object;
} | php | public function decodeObject($string, $fieldName = null)
{
if (empty($string)) {
return new \stdClass();
}
$object = self::decode($string, $fieldName);
if (is_string($object)) {
$object = self::decode($object, $fieldName);
}
if (!is_object($object)) {
throw new \Exception('The field '.$fieldName.' is not a JSON object as expected.');
}
return $object;
} | [
"public",
"function",
"decodeObject",
"(",
"$",
"string",
",",
"$",
"fieldName",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"$",
"object",
"=",
"self",
"::",
"decode",
"(",
"$",
"string",
",",
"$",
"fieldName",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"object",
")",
")",
"{",
"$",
"object",
"=",
"self",
"::",
"decode",
"(",
"$",
"object",
",",
"$",
"fieldName",
")",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'The field '",
".",
"$",
"fieldName",
".",
"' is not a JSON object as expected.'",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | @param $string
@param string $fieldName
@return mixed
@throws \Exception | [
"@param",
"$string",
"@param",
"string",
"$fieldName"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/JSONHelper.php#L94-L108 |
TheDMSGroup/mautic-contact-client | Helper/JSONHelper.php | JSONHelper.encode | public function encode($mixed, $fieldName)
{
$jsonError = false;
self::utf8_encode($mixed);
$result = json_encode(
$mixed,
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRETTY_PRINT
);
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$jsonError = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$jsonError = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$jsonError = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$jsonError = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
$jsonError = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$jsonError = 'Unknown error';
break;
}
if ($jsonError) {
throw new \Exception('JSON encoding failed for field '.$fieldName.' JSON error: '.$jsonError);
}
return $result;
} | php | public function encode($mixed, $fieldName)
{
$jsonError = false;
self::utf8_encode($mixed);
$result = json_encode(
$mixed,
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRETTY_PRINT
);
switch (json_last_error()) {
case JSON_ERROR_NONE:
break;
case JSON_ERROR_DEPTH:
$jsonError = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$jsonError = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$jsonError = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
$jsonError = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
$jsonError = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$jsonError = 'Unknown error';
break;
}
if ($jsonError) {
throw new \Exception('JSON encoding failed for field '.$fieldName.' JSON error: '.$jsonError);
}
return $result;
} | [
"public",
"function",
"encode",
"(",
"$",
"mixed",
",",
"$",
"fieldName",
")",
"{",
"$",
"jsonError",
"=",
"false",
";",
"self",
"::",
"utf8_encode",
"(",
"$",
"mixed",
")",
";",
"$",
"result",
"=",
"json_encode",
"(",
"$",
"mixed",
",",
"JSON_HEX_TAG",
"|",
"JSON_HEX_APOS",
"|",
"JSON_HEX_AMP",
"|",
"JSON_HEX_QUOT",
"|",
"JSON_PRETTY_PRINT",
")",
";",
"switch",
"(",
"json_last_error",
"(",
")",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"break",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"$",
"jsonError",
"=",
"'Maximum stack depth exceeded'",
";",
"break",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"$",
"jsonError",
"=",
"'Underflow or the modes mismatch'",
";",
"break",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"$",
"jsonError",
"=",
"'Unexpected control character found'",
";",
"break",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"$",
"jsonError",
"=",
"'Syntax error, malformed JSON'",
";",
"break",
";",
"case",
"JSON_ERROR_UTF8",
":",
"$",
"jsonError",
"=",
"'Malformed UTF-8 characters, possibly incorrectly encoded'",
";",
"break",
";",
"default",
":",
"$",
"jsonError",
"=",
"'Unknown error'",
";",
"break",
";",
"}",
"if",
"(",
"$",
"jsonError",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'JSON encoding failed for field '",
".",
"$",
"fieldName",
".",
"' JSON error: '",
".",
"$",
"jsonError",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | @param $mixed
@param $fieldName
@return false|string
@throws \Exception | [
"@param",
"$mixed",
"@param",
"$fieldName"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/JSONHelper.php#L118-L153 |
TheDMSGroup/mautic-contact-client | Helper/JSONHelper.php | JSONHelper.utf8_encode | private static function utf8_encode(&$mixed)
{
if (is_array($mixed) || is_object($mixed)) {
foreach ($mixed as &$value) {
self::utf8_encode($value);
}
} else {
if (is_string($mixed)) {
$mixed = utf8_encode($mixed);
}
}
} | php | private static function utf8_encode(&$mixed)
{
if (is_array($mixed) || is_object($mixed)) {
foreach ($mixed as &$value) {
self::utf8_encode($value);
}
} else {
if (is_string($mixed)) {
$mixed = utf8_encode($mixed);
}
}
} | [
"private",
"static",
"function",
"utf8_encode",
"(",
"&",
"$",
"mixed",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mixed",
")",
"||",
"is_object",
"(",
"$",
"mixed",
")",
")",
"{",
"foreach",
"(",
"$",
"mixed",
"as",
"&",
"$",
"value",
")",
"{",
"self",
"::",
"utf8_encode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
")",
"{",
"$",
"mixed",
"=",
"utf8_encode",
"(",
"$",
"mixed",
")",
";",
"}",
"}",
"}"
] | Recursively encode via UTF8.
@param $mixed | [
"Recursively",
"encode",
"via",
"UTF8",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/JSONHelper.php#L160-L171 |
TheDMSGroup/mautic-contact-client | Entity/AuthRepository.php | AuthRepository.getPreviousPayloadAuthTokensByContactClient | public function getPreviousPayloadAuthTokensByContactClient($contactClientId, $operationId = null, $test = false)
{
$result = [];
$q = $this->getEntityManager()->getConnection()->createQueryBuilder();
$q->select('a.operation, a.type, a.field, a.val')
->from(MAUTIC_TABLE_PREFIX.'contactclient_auth', 'a')
->where(
$q->expr()->eq('a.contactclient_id', (int) $contactClientId),
$q->expr()->eq('a.test', (int) $test)
);
if ($operationId) {
$q->andWhere(
$q->expr()->eq('a.operation', (int) $operationId)
);
}
foreach ($q->execute()->fetchAll() as $row) {
$token = 'payload.operations.'.$row['operation'].'.response.'.$row['type'].'.'.$row['field'];
$result[$token] = $row['val'];
}
return $result;
} | php | public function getPreviousPayloadAuthTokensByContactClient($contactClientId, $operationId = null, $test = false)
{
$result = [];
$q = $this->getEntityManager()->getConnection()->createQueryBuilder();
$q->select('a.operation, a.type, a.field, a.val')
->from(MAUTIC_TABLE_PREFIX.'contactclient_auth', 'a')
->where(
$q->expr()->eq('a.contactclient_id', (int) $contactClientId),
$q->expr()->eq('a.test', (int) $test)
);
if ($operationId) {
$q->andWhere(
$q->expr()->eq('a.operation', (int) $operationId)
);
}
foreach ($q->execute()->fetchAll() as $row) {
$token = 'payload.operations.'.$row['operation'].'.response.'.$row['type'].'.'.$row['field'];
$result[$token] = $row['val'];
}
return $result;
} | [
"public",
"function",
"getPreviousPayloadAuthTokensByContactClient",
"(",
"$",
"contactClientId",
",",
"$",
"operationId",
"=",
"null",
",",
"$",
"test",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"q",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"q",
"->",
"select",
"(",
"'a.operation, a.type, a.field, a.val'",
")",
"->",
"from",
"(",
"MAUTIC_TABLE_PREFIX",
".",
"'contactclient_auth'",
",",
"'a'",
")",
"->",
"where",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.contactclient_id'",
",",
"(",
"int",
")",
"$",
"contactClientId",
")",
",",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.test'",
",",
"(",
"int",
")",
"$",
"test",
")",
")",
";",
"if",
"(",
"$",
"operationId",
")",
"{",
"$",
"q",
"->",
"andWhere",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.operation'",
",",
"(",
"int",
")",
"$",
"operationId",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"q",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"token",
"=",
"'payload.operations.'",
".",
"$",
"row",
"[",
"'operation'",
"]",
".",
"'.response.'",
".",
"$",
"row",
"[",
"'type'",
"]",
".",
"'.'",
".",
"$",
"row",
"[",
"'field'",
"]",
";",
"$",
"result",
"[",
"$",
"token",
"]",
"=",
"$",
"row",
"[",
"'val'",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Gets all token key-value pairs for a contactClient that were previously captured by succesful
auth requests and persisted for re-use.
@param $contactClientId
@param $operationId
@param bool $test
@return array | [
"Gets",
"all",
"token",
"key",
"-",
"value",
"pairs",
"for",
"a",
"contactClient",
"that",
"were",
"previously",
"captured",
"by",
"succesful",
"auth",
"requests",
"and",
"persisted",
"for",
"re",
"-",
"use",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/AuthRepository.php#L31-L54 |
TheDMSGroup/mautic-contact-client | Entity/AuthRepository.php | AuthRepository.flushPreviousAuthTokens | public function flushPreviousAuthTokens($contactClientId, $operationId, $test)
{
$q = $this->createQueryBuilder('a');
$q->delete()
->where(
$q->expr()->eq('a.contactClient', (int) $contactClientId),
$q->expr()->eq('a.operation', (int) $operationId),
$q->expr()->eq('a.test', (int) $test)
);
return $q->getQuery()->getArrayResult();
} | php | public function flushPreviousAuthTokens($contactClientId, $operationId, $test)
{
$q = $this->createQueryBuilder('a');
$q->delete()
->where(
$q->expr()->eq('a.contactClient', (int) $contactClientId),
$q->expr()->eq('a.operation', (int) $operationId),
$q->expr()->eq('a.test', (int) $test)
);
return $q->getQuery()->getArrayResult();
} | [
"public",
"function",
"flushPreviousAuthTokens",
"(",
"$",
"contactClientId",
",",
"$",
"operationId",
",",
"$",
"test",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'a'",
")",
";",
"$",
"q",
"->",
"delete",
"(",
")",
"->",
"where",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.contactClient'",
",",
"(",
"int",
")",
"$",
"contactClientId",
")",
",",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.operation'",
",",
"(",
"int",
")",
"$",
"operationId",
")",
",",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.test'",
",",
"(",
"int",
")",
"$",
"test",
")",
")",
";",
"return",
"$",
"q",
"->",
"getQuery",
"(",
")",
"->",
"getArrayResult",
"(",
")",
";",
"}"
] | @param $contactClientId
@param $operationId
@param bool $test
@return array | [
"@param",
"$contactClientId",
"@param",
"$operationId",
"@param",
"bool",
"$test"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/AuthRepository.php#L63-L74 |
TheDMSGroup/mautic-contact-client | Controller/AjaxController.php | AjaxController.transactionsAction | public function transactionsAction(Request $request)
{
$dataArray = [
'html' => '',
'success' => 0,
];
$filters = null;
// filters means the transaction table had a column sort or filter submission or pagination, otherwise its a fresh page load
if ($request->request->has('filters')) {
foreach ($request->request->get('filters') as $filter) {
if (in_array($filter['name'], ['dateTo', 'dateFrom']) && !empty($filter['value'])) {
$filter['value'] = new \DateTime($filter['value']);
list($hour, $min, $sec) = 'dateTo' == $filter['name'] ? [23, 59, 59] : [00, 00, 00];
$filter['value']->setTime($hour, $min, $sec);
}
if (!empty($filter['value'])) {
$filters[$filter['name']] = $filter['value'];
}
}
}
$page = isset($filters['page']) && !empty($filters['page']) ? $filters['page'] : 1;
$objectId = InputHelper::clean($request->request->get('objectId'));
if (empty($objectId)) {
return $this->sendJsonResponse($dataArray);
}
$contactClient = $this->checkContactClientAccess($objectId, 'view');
if ($contactClient instanceof Response) {
return $this->sendJsonResponse($dataArray);
}
$order = [
'date_added',
'DESC',
];
if (isset($filters['orderby']) && !empty($filters['orderby'])) {
$order[0] = $filters['orderby'];
}
if (isset($filters['orderbydir']) && !empty($filters['orderbydir'])) {
$order[1] = $filters['orderbydir'];
}
$transactions = $this->getEngagements($contactClient, $filters, $order, $page);
$dataArray['html'] = $this->renderView(
'MauticContactClientBundle:Transactions:list.html.php',
[
'page' => $page,
'contactClient' => $contactClient,
'transactions' => $transactions,
'order' => $order,
]
);
$dataArray['success'] = 1;
$dataArray['total'] = $transactions['total'];
return $this->sendJsonResponse($dataArray);
} | php | public function transactionsAction(Request $request)
{
$dataArray = [
'html' => '',
'success' => 0,
];
$filters = null;
// filters means the transaction table had a column sort or filter submission or pagination, otherwise its a fresh page load
if ($request->request->has('filters')) {
foreach ($request->request->get('filters') as $filter) {
if (in_array($filter['name'], ['dateTo', 'dateFrom']) && !empty($filter['value'])) {
$filter['value'] = new \DateTime($filter['value']);
list($hour, $min, $sec) = 'dateTo' == $filter['name'] ? [23, 59, 59] : [00, 00, 00];
$filter['value']->setTime($hour, $min, $sec);
}
if (!empty($filter['value'])) {
$filters[$filter['name']] = $filter['value'];
}
}
}
$page = isset($filters['page']) && !empty($filters['page']) ? $filters['page'] : 1;
$objectId = InputHelper::clean($request->request->get('objectId'));
if (empty($objectId)) {
return $this->sendJsonResponse($dataArray);
}
$contactClient = $this->checkContactClientAccess($objectId, 'view');
if ($contactClient instanceof Response) {
return $this->sendJsonResponse($dataArray);
}
$order = [
'date_added',
'DESC',
];
if (isset($filters['orderby']) && !empty($filters['orderby'])) {
$order[0] = $filters['orderby'];
}
if (isset($filters['orderbydir']) && !empty($filters['orderbydir'])) {
$order[1] = $filters['orderbydir'];
}
$transactions = $this->getEngagements($contactClient, $filters, $order, $page);
$dataArray['html'] = $this->renderView(
'MauticContactClientBundle:Transactions:list.html.php',
[
'page' => $page,
'contactClient' => $contactClient,
'transactions' => $transactions,
'order' => $order,
]
);
$dataArray['success'] = 1;
$dataArray['total'] = $transactions['total'];
return $this->sendJsonResponse($dataArray);
} | [
"public",
"function",
"transactionsAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"dataArray",
"=",
"[",
"'html'",
"=>",
"''",
",",
"'success'",
"=>",
"0",
",",
"]",
";",
"$",
"filters",
"=",
"null",
";",
"// filters means the transaction table had a column sort or filter submission or pagination, otherwise its a fresh page load",
"if",
"(",
"$",
"request",
"->",
"request",
"->",
"has",
"(",
"'filters'",
")",
")",
"{",
"foreach",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'filters'",
")",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"filter",
"[",
"'name'",
"]",
",",
"[",
"'dateTo'",
",",
"'dateFrom'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"filter",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"filter",
"[",
"'value'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"filter",
"[",
"'value'",
"]",
")",
";",
"list",
"(",
"$",
"hour",
",",
"$",
"min",
",",
"$",
"sec",
")",
"=",
"'dateTo'",
"==",
"$",
"filter",
"[",
"'name'",
"]",
"?",
"[",
"23",
",",
"59",
",",
"59",
"]",
":",
"[",
"00",
",",
"00",
",",
"00",
"]",
";",
"$",
"filter",
"[",
"'value'",
"]",
"->",
"setTime",
"(",
"$",
"hour",
",",
"$",
"min",
",",
"$",
"sec",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"filter",
"[",
"'name'",
"]",
"]",
"=",
"$",
"filter",
"[",
"'value'",
"]",
";",
"}",
"}",
"}",
"$",
"page",
"=",
"isset",
"(",
"$",
"filters",
"[",
"'page'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"filters",
"[",
"'page'",
"]",
")",
"?",
"$",
"filters",
"[",
"'page'",
"]",
":",
"1",
";",
"$",
"objectId",
"=",
"InputHelper",
"::",
"clean",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'objectId'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"objectId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sendJsonResponse",
"(",
"$",
"dataArray",
")",
";",
"}",
"$",
"contactClient",
"=",
"$",
"this",
"->",
"checkContactClientAccess",
"(",
"$",
"objectId",
",",
"'view'",
")",
";",
"if",
"(",
"$",
"contactClient",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"this",
"->",
"sendJsonResponse",
"(",
"$",
"dataArray",
")",
";",
"}",
"$",
"order",
"=",
"[",
"'date_added'",
",",
"'DESC'",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"'orderby'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"filters",
"[",
"'orderby'",
"]",
")",
")",
"{",
"$",
"order",
"[",
"0",
"]",
"=",
"$",
"filters",
"[",
"'orderby'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"'orderbydir'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"filters",
"[",
"'orderbydir'",
"]",
")",
")",
"{",
"$",
"order",
"[",
"1",
"]",
"=",
"$",
"filters",
"[",
"'orderbydir'",
"]",
";",
"}",
"$",
"transactions",
"=",
"$",
"this",
"->",
"getEngagements",
"(",
"$",
"contactClient",
",",
"$",
"filters",
",",
"$",
"order",
",",
"$",
"page",
")",
";",
"$",
"dataArray",
"[",
"'html'",
"]",
"=",
"$",
"this",
"->",
"renderView",
"(",
"'MauticContactClientBundle:Transactions:list.html.php'",
",",
"[",
"'page'",
"=>",
"$",
"page",
",",
"'contactClient'",
"=>",
"$",
"contactClient",
",",
"'transactions'",
"=>",
"$",
"transactions",
",",
"'order'",
"=>",
"$",
"order",
",",
"]",
")",
";",
"$",
"dataArray",
"[",
"'success'",
"]",
"=",
"1",
";",
"$",
"dataArray",
"[",
"'total'",
"]",
"=",
"$",
"transactions",
"[",
"'total'",
"]",
";",
"return",
"$",
"this",
"->",
"sendJsonResponse",
"(",
"$",
"dataArray",
")",
";",
"}"
] | @param Request $request
@return \Symfony\Component\HttpFoundation\JsonResponse
@throws \Exception | [
"@param",
"Request",
"$request"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/AjaxController.php#L42-L101 |
TheDMSGroup/mautic-contact-client | Controller/AjaxController.php | AjaxController.getTokensAction | protected function getTokensAction(Request $request)
{
// Get an array representation of the current payload (of last save) for context.
// No longer needs filePayload.
$payload = html_entity_decode(InputHelper::clean($request->request->get('apiPayload')));
$defaultFile = __DIR__.ContactClient::API_PAYLOAD_DEFAULT_FILE;
if (
$payload
&& file_exists($defaultFile)
&& $payload == file_get_contents($defaultFile)
) {
$cacheKey = 'tokenCacheDefault';
$cacheTtl = 3600;
} else {
$cacheKey = 'tokenCache'.md5($payload);
$cacheTtl = 300;
}
$payload = json_decode($payload, true);
$payload = is_array($payload) ? $payload : [];
$cache = new CacheStorageHelper(
CacheStorageHelper::ADAPTOR_FILESYSTEM,
'ContactClient',
null,
$this->coreParametersHelper->getParameter(
'cached_data_dir',
$this->get('mautic.helper.paths')->getSystemPath('cache', true)
),
300
);
$dataArray = $cache->get($cacheKey, $cacheTtl);
if (!$dataArray) {
$dataArray = [
'tokens' => [],
'types' => [],
'formats' => [],
'success' => 0,
];
/** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
$fieldModel = $this->get('mautic.lead.model.field');
// Exclude company fields as they are not currently used by the token helper.
$fields = $fieldModel->getEntities(
[
'filter' => [
'force' => [
[
'column' => 'f.isPublished',
'expr' => 'eq',
'value' => true,
],
[
'column' => 'f.object',
'expr' => 'notLike',
'value' => 'company',
],
],
],
'hydration_mode' => 'HYDRATE_ARRAY',
]
);
$contact = new Contact();
$fieldGroups = [];
foreach ($fields as $field) {
$fieldGroups[$field['group']][$field['alias']] = [
'value' => $field['label'],
'type' => $field['type'],
'label' => $field['label'],
];
}
$contact->setFields($fieldGroups);
/** @var TokenHelper $tokenHelper */
$tokenHelper = $this->get('mautic.contactclient.helper.token');
$tokenHelper->newSession(null, $contact, $payload);
$tokens = $tokenHelper->getContextLabeled();
if ($tokens) {
$dataArray['success'] = true;
$dataArray['tokens'] = $tokens;
$dataArray['types'] = $tokenHelper->getContextTypes();
$dataArray['formats'] = $tokenHelper->getFormats();
}
$cache->set($cacheKey, $dataArray, $cacheTtl);
}
return $this->sendJsonResponse($dataArray);
} | php | protected function getTokensAction(Request $request)
{
// Get an array representation of the current payload (of last save) for context.
// No longer needs filePayload.
$payload = html_entity_decode(InputHelper::clean($request->request->get('apiPayload')));
$defaultFile = __DIR__.ContactClient::API_PAYLOAD_DEFAULT_FILE;
if (
$payload
&& file_exists($defaultFile)
&& $payload == file_get_contents($defaultFile)
) {
$cacheKey = 'tokenCacheDefault';
$cacheTtl = 3600;
} else {
$cacheKey = 'tokenCache'.md5($payload);
$cacheTtl = 300;
}
$payload = json_decode($payload, true);
$payload = is_array($payload) ? $payload : [];
$cache = new CacheStorageHelper(
CacheStorageHelper::ADAPTOR_FILESYSTEM,
'ContactClient',
null,
$this->coreParametersHelper->getParameter(
'cached_data_dir',
$this->get('mautic.helper.paths')->getSystemPath('cache', true)
),
300
);
$dataArray = $cache->get($cacheKey, $cacheTtl);
if (!$dataArray) {
$dataArray = [
'tokens' => [],
'types' => [],
'formats' => [],
'success' => 0,
];
/** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
$fieldModel = $this->get('mautic.lead.model.field');
// Exclude company fields as they are not currently used by the token helper.
$fields = $fieldModel->getEntities(
[
'filter' => [
'force' => [
[
'column' => 'f.isPublished',
'expr' => 'eq',
'value' => true,
],
[
'column' => 'f.object',
'expr' => 'notLike',
'value' => 'company',
],
],
],
'hydration_mode' => 'HYDRATE_ARRAY',
]
);
$contact = new Contact();
$fieldGroups = [];
foreach ($fields as $field) {
$fieldGroups[$field['group']][$field['alias']] = [
'value' => $field['label'],
'type' => $field['type'],
'label' => $field['label'],
];
}
$contact->setFields($fieldGroups);
/** @var TokenHelper $tokenHelper */
$tokenHelper = $this->get('mautic.contactclient.helper.token');
$tokenHelper->newSession(null, $contact, $payload);
$tokens = $tokenHelper->getContextLabeled();
if ($tokens) {
$dataArray['success'] = true;
$dataArray['tokens'] = $tokens;
$dataArray['types'] = $tokenHelper->getContextTypes();
$dataArray['formats'] = $tokenHelper->getFormats();
}
$cache->set($cacheKey, $dataArray, $cacheTtl);
}
return $this->sendJsonResponse($dataArray);
} | [
"protected",
"function",
"getTokensAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// Get an array representation of the current payload (of last save) for context.",
"// No longer needs filePayload.",
"$",
"payload",
"=",
"html_entity_decode",
"(",
"InputHelper",
"::",
"clean",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'apiPayload'",
")",
")",
")",
";",
"$",
"defaultFile",
"=",
"__DIR__",
".",
"ContactClient",
"::",
"API_PAYLOAD_DEFAULT_FILE",
";",
"if",
"(",
"$",
"payload",
"&&",
"file_exists",
"(",
"$",
"defaultFile",
")",
"&&",
"$",
"payload",
"==",
"file_get_contents",
"(",
"$",
"defaultFile",
")",
")",
"{",
"$",
"cacheKey",
"=",
"'tokenCacheDefault'",
";",
"$",
"cacheTtl",
"=",
"3600",
";",
"}",
"else",
"{",
"$",
"cacheKey",
"=",
"'tokenCache'",
".",
"md5",
"(",
"$",
"payload",
")",
";",
"$",
"cacheTtl",
"=",
"300",
";",
"}",
"$",
"payload",
"=",
"json_decode",
"(",
"$",
"payload",
",",
"true",
")",
";",
"$",
"payload",
"=",
"is_array",
"(",
"$",
"payload",
")",
"?",
"$",
"payload",
":",
"[",
"]",
";",
"$",
"cache",
"=",
"new",
"CacheStorageHelper",
"(",
"CacheStorageHelper",
"::",
"ADAPTOR_FILESYSTEM",
",",
"'ContactClient'",
",",
"null",
",",
"$",
"this",
"->",
"coreParametersHelper",
"->",
"getParameter",
"(",
"'cached_data_dir'",
",",
"$",
"this",
"->",
"get",
"(",
"'mautic.helper.paths'",
")",
"->",
"getSystemPath",
"(",
"'cache'",
",",
"true",
")",
")",
",",
"300",
")",
";",
"$",
"dataArray",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"cacheKey",
",",
"$",
"cacheTtl",
")",
";",
"if",
"(",
"!",
"$",
"dataArray",
")",
"{",
"$",
"dataArray",
"=",
"[",
"'tokens'",
"=>",
"[",
"]",
",",
"'types'",
"=>",
"[",
"]",
",",
"'formats'",
"=>",
"[",
"]",
",",
"'success'",
"=>",
"0",
",",
"]",
";",
"/** @var \\Mautic\\LeadBundle\\Model\\FieldModel $fieldModel */",
"$",
"fieldModel",
"=",
"$",
"this",
"->",
"get",
"(",
"'mautic.lead.model.field'",
")",
";",
"// Exclude company fields as they are not currently used by the token helper.",
"$",
"fields",
"=",
"$",
"fieldModel",
"->",
"getEntities",
"(",
"[",
"'filter'",
"=>",
"[",
"'force'",
"=>",
"[",
"[",
"'column'",
"=>",
"'f.isPublished'",
",",
"'expr'",
"=>",
"'eq'",
",",
"'value'",
"=>",
"true",
",",
"]",
",",
"[",
"'column'",
"=>",
"'f.object'",
",",
"'expr'",
"=>",
"'notLike'",
",",
"'value'",
"=>",
"'company'",
",",
"]",
",",
"]",
",",
"]",
",",
"'hydration_mode'",
"=>",
"'HYDRATE_ARRAY'",
",",
"]",
")",
";",
"$",
"contact",
"=",
"new",
"Contact",
"(",
")",
";",
"$",
"fieldGroups",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"fieldGroups",
"[",
"$",
"field",
"[",
"'group'",
"]",
"]",
"[",
"$",
"field",
"[",
"'alias'",
"]",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"field",
"[",
"'label'",
"]",
",",
"'type'",
"=>",
"$",
"field",
"[",
"'type'",
"]",
",",
"'label'",
"=>",
"$",
"field",
"[",
"'label'",
"]",
",",
"]",
";",
"}",
"$",
"contact",
"->",
"setFields",
"(",
"$",
"fieldGroups",
")",
";",
"/** @var TokenHelper $tokenHelper */",
"$",
"tokenHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'mautic.contactclient.helper.token'",
")",
";",
"$",
"tokenHelper",
"->",
"newSession",
"(",
"null",
",",
"$",
"contact",
",",
"$",
"payload",
")",
";",
"$",
"tokens",
"=",
"$",
"tokenHelper",
"->",
"getContextLabeled",
"(",
")",
";",
"if",
"(",
"$",
"tokens",
")",
"{",
"$",
"dataArray",
"[",
"'success'",
"]",
"=",
"true",
";",
"$",
"dataArray",
"[",
"'tokens'",
"]",
"=",
"$",
"tokens",
";",
"$",
"dataArray",
"[",
"'types'",
"]",
"=",
"$",
"tokenHelper",
"->",
"getContextTypes",
"(",
")",
";",
"$",
"dataArray",
"[",
"'formats'",
"]",
"=",
"$",
"tokenHelper",
"->",
"getFormats",
"(",
")",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"$",
"cacheKey",
",",
"$",
"dataArray",
",",
"$",
"cacheTtl",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sendJsonResponse",
"(",
"$",
"dataArray",
")",
";",
"}"
] | @param Request $request
@return \Symfony\Component\HttpFoundation\JsonResponse
@throws \Exception | [
"@param",
"Request",
"$request"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/AjaxController.php#L212-L299 |
TheDMSGroup/mautic-contact-client | Services/Transport.php | Transport.setSettings | public function setSettings($settings = [])
{
$original = $this->settings;
$this->mergeSettings($settings, $this->settings);
if ($this->settings != $original) {
// @todo - Log Curl equivalent during test mode (adds overhead and risk so only do it during test)
// if (!isset($this->settings['handler']) && class_exists(
// '\Namshi\Cuzzle\Middleware\CurlFormatterMiddleware'
// )) {
// $this->logger = new Logger('guzzle.to.curl'); //initialize the logger
// $this->testHandler = new TestHandler(); //test logger handler
// $this->logger->pushHandler($this->testHandler);
//
// $this->handler = HandlerStack::create();
// $this->handler->after('cookies', new \Namshi\Cuzzle\Middleware\CurlFormatterMiddleware($this->logger));
// $this->settings['handler'] = $this->handler;
// }
$this->client = new Client($this->settings);
}
} | php | public function setSettings($settings = [])
{
$original = $this->settings;
$this->mergeSettings($settings, $this->settings);
if ($this->settings != $original) {
// @todo - Log Curl equivalent during test mode (adds overhead and risk so only do it during test)
// if (!isset($this->settings['handler']) && class_exists(
// '\Namshi\Cuzzle\Middleware\CurlFormatterMiddleware'
// )) {
// $this->logger = new Logger('guzzle.to.curl'); //initialize the logger
// $this->testHandler = new TestHandler(); //test logger handler
// $this->logger->pushHandler($this->testHandler);
//
// $this->handler = HandlerStack::create();
// $this->handler->after('cookies', new \Namshi\Cuzzle\Middleware\CurlFormatterMiddleware($this->logger));
// $this->settings['handler'] = $this->handler;
// }
$this->client = new Client($this->settings);
}
} | [
"public",
"function",
"setSettings",
"(",
"$",
"settings",
"=",
"[",
"]",
")",
"{",
"$",
"original",
"=",
"$",
"this",
"->",
"settings",
";",
"$",
"this",
"->",
"mergeSettings",
"(",
"$",
"settings",
",",
"$",
"this",
"->",
"settings",
")",
";",
"if",
"(",
"$",
"this",
"->",
"settings",
"!=",
"$",
"original",
")",
"{",
"// @todo - Log Curl equivalent during test mode (adds overhead and risk so only do it during test)",
"// if (!isset($this->settings['handler']) && class_exists(",
"// '\\Namshi\\Cuzzle\\Middleware\\CurlFormatterMiddleware'",
"// )) {",
"// $this->logger = new Logger('guzzle.to.curl'); //initialize the logger",
"// $this->testHandler = new TestHandler(); //test logger handler",
"// $this->logger->pushHandler($this->testHandler);",
"//",
"// $this->handler = HandlerStack::create();",
"// $this->handler->after('cookies', new \\Namshi\\Cuzzle\\Middleware\\CurlFormatterMiddleware($this->logger));",
"// $this->settings['handler'] = $this->handler;",
"// }",
"$",
"this",
"->",
"client",
"=",
"new",
"Client",
"(",
"$",
"this",
"->",
"settings",
")",
";",
"}",
"}"
] | Establish a new Transport with the options provided if needed.
Only options that match the keys of our defaults are to be supported.
@param array $settings | [
"Establish",
"a",
"new",
"Transport",
"with",
"the",
"options",
"provided",
"if",
"needed",
".",
"Only",
"options",
"that",
"match",
"the",
"keys",
"of",
"our",
"defaults",
"are",
"to",
"be",
"supported",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Services/Transport.php#L86-L105 |
TheDMSGroup/mautic-contact-client | Services/Transport.php | Transport.mergeSettings | private function mergeSettings($settingsa, &$settingsb)
{
foreach ($settingsb as $key => &$value) {
if (isset($settingsa[$key])) {
if (is_array($value)) {
$this->mergeSettings($settingsa[$key], $value);
} else {
$value = $settingsa[$key];
}
}
}
} | php | private function mergeSettings($settingsa, &$settingsb)
{
foreach ($settingsb as $key => &$value) {
if (isset($settingsa[$key])) {
if (is_array($value)) {
$this->mergeSettings($settingsa[$key], $value);
} else {
$value = $settingsa[$key];
}
}
}
} | [
"private",
"function",
"mergeSettings",
"(",
"$",
"settingsa",
",",
"&",
"$",
"settingsb",
")",
"{",
"foreach",
"(",
"$",
"settingsb",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"settingsa",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"mergeSettings",
"(",
"$",
"settingsa",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"settingsa",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"}"
] | Merge settings from an external source overriding internals by a nested array.
@param array $settingsa
@param array $settingsb | [
"Merge",
"settings",
"from",
"an",
"external",
"source",
"overriding",
"internals",
"by",
"a",
"nested",
"array",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Services/Transport.php#L113-L124 |
TheDMSGroup/mautic-contact-client | MauticContactClientBundle.php | MauticContactClientBundle.onPluginUpdate | public static function onPluginUpdate(
Plugin $plugin,
MauticFactory $factory,
$metadata = null,
Schema $installedSchema = null
) {
// By default this is disabled, but for this plugin doctrine updates the schema faithfully.
self::updatePluginSchema($metadata, $installedSchema, $factory);
} | php | public static function onPluginUpdate(
Plugin $plugin,
MauticFactory $factory,
$metadata = null,
Schema $installedSchema = null
) {
// By default this is disabled, but for this plugin doctrine updates the schema faithfully.
self::updatePluginSchema($metadata, $installedSchema, $factory);
} | [
"public",
"static",
"function",
"onPluginUpdate",
"(",
"Plugin",
"$",
"plugin",
",",
"MauticFactory",
"$",
"factory",
",",
"$",
"metadata",
"=",
"null",
",",
"Schema",
"$",
"installedSchema",
"=",
"null",
")",
"{",
"// By default this is disabled, but for this plugin doctrine updates the schema faithfully.",
"self",
"::",
"updatePluginSchema",
"(",
"$",
"metadata",
",",
"$",
"installedSchema",
",",
"$",
"factory",
")",
";",
"}"
] | Called by PluginController::reloadAction when the addon version does not match what's installed.
@param Plugin $plugin
@param MauticFactory $factory
@param null $metadata
@param Schema $installedSchema
@throws \Exception | [
"Called",
"by",
"PluginController",
"::",
"reloadAction",
"when",
"the",
"addon",
"version",
"does",
"not",
"match",
"what",
"s",
"installed",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/MauticContactClientBundle.php#L31-L39 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.sanitizeEventFilter | public function sanitizeEventFilter($filters)
{
if (!is_array($filters)) {
throw new \InvalidArgumentException('filters parameter must be an array');
}
if (!isset($filters['search'])) {
$filters['search'] = '';
}
if (!isset($filters['includeEvents'])) {
$filters['includeEvents'] = [];
}
if (!isset($filters['excludeEvents'])) {
$filters['excludeEvents'] = [];
}
return $filters;
} | php | public function sanitizeEventFilter($filters)
{
if (!is_array($filters)) {
throw new \InvalidArgumentException('filters parameter must be an array');
}
if (!isset($filters['search'])) {
$filters['search'] = '';
}
if (!isset($filters['includeEvents'])) {
$filters['includeEvents'] = [];
}
if (!isset($filters['excludeEvents'])) {
$filters['excludeEvents'] = [];
}
return $filters;
} | [
"public",
"function",
"sanitizeEventFilter",
"(",
"$",
"filters",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"filters",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'filters parameter must be an array'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'search'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"'search'",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'includeEvents'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"'includeEvents'",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'excludeEvents'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"'excludeEvents'",
"]",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"filters",
";",
"}"
] | Makes sure that the event filter array is in the right format.
@param mixed $filters
@return array
@throws \InvalidArgumentException if not an array | [
"Makes",
"sure",
"that",
"the",
"event",
"filter",
"array",
"is",
"in",
"the",
"right",
"format",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L36-L55 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getEngagements | public function getEngagements(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25,
$forTimeline = true
) {
$session = $this->get('session');
$chartFilters = $session->get('mautic.contactclient.'.$contactClient->getId().'.chartfilter');
if (!isset($filters['dateFrom'])) {
$dateFrom = new \DateTime($chartFilters['date_from']);
$dateFrom->setTime(00, 00, 00); // set to beginning of day, Timezone should be OK.
$filters['dateFrom'] = $dateFrom;
}
if (!isset($filters['dateTo'])) {
$dateTo = new \DateTime($chartFilters['date_to']);
$dateTo->setTime(23, 59, 59);
$filters['dateTo'] = $dateTo;
}
if (
!isset($filters['type'])
&& !empty($chartFilters['type'])
) {
$filters['type'] = $chartFilters['type'];
}
if (
!isset($filters['campaignId'])
&& !empty($chartFilters['campaign'])
) {
$filters['campaignId'] = $chartFilters['campaign'];
}
/** @var \MauticPlugin\MauticContactClientBundle\Event\ContactClientTimelineEvent $engagements */
$engagements = $this->getModel('contactclient')->getEngagements(
$contactClient,
$filters,
$orderBy,
$page,
$limit
);
$payload = [
'events' => $engagements->getEvents(),
'chartfilter' => [
'date_from' => $filters['dateFrom']->format('M j, Y'),
'date_to' => $filters['dateTo']->format('M j, Y'),
'type' => isset($filters['type']) ? $filters['type'] : null,
],
'filters' => $filters,
'order' => $orderBy,
'types' => $engagements->getEventTypes(),
'total' => $engagements->getQueryTotal(),
'page' => $page,
'limit' => $limit,
'maxPages' => $engagements->getMaxPage(),
];
return ($forTimeline)
? $payload
: [$payload, $engagements->getSerializerGroups()];
} | php | public function getEngagements(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25,
$forTimeline = true
) {
$session = $this->get('session');
$chartFilters = $session->get('mautic.contactclient.'.$contactClient->getId().'.chartfilter');
if (!isset($filters['dateFrom'])) {
$dateFrom = new \DateTime($chartFilters['date_from']);
$dateFrom->setTime(00, 00, 00); // set to beginning of day, Timezone should be OK.
$filters['dateFrom'] = $dateFrom;
}
if (!isset($filters['dateTo'])) {
$dateTo = new \DateTime($chartFilters['date_to']);
$dateTo->setTime(23, 59, 59);
$filters['dateTo'] = $dateTo;
}
if (
!isset($filters['type'])
&& !empty($chartFilters['type'])
) {
$filters['type'] = $chartFilters['type'];
}
if (
!isset($filters['campaignId'])
&& !empty($chartFilters['campaign'])
) {
$filters['campaignId'] = $chartFilters['campaign'];
}
/** @var \MauticPlugin\MauticContactClientBundle\Event\ContactClientTimelineEvent $engagements */
$engagements = $this->getModel('contactclient')->getEngagements(
$contactClient,
$filters,
$orderBy,
$page,
$limit
);
$payload = [
'events' => $engagements->getEvents(),
'chartfilter' => [
'date_from' => $filters['dateFrom']->format('M j, Y'),
'date_to' => $filters['dateTo']->format('M j, Y'),
'type' => isset($filters['type']) ? $filters['type'] : null,
],
'filters' => $filters,
'order' => $orderBy,
'types' => $engagements->getEventTypes(),
'total' => $engagements->getQueryTotal(),
'page' => $page,
'limit' => $limit,
'maxPages' => $engagements->getMaxPage(),
];
return ($forTimeline)
? $payload
: [$payload, $engagements->getSerializerGroups()];
} | [
"public",
"function",
"getEngagements",
"(",
"ContactClient",
"$",
"contactClient",
",",
"array",
"$",
"filters",
"=",
"null",
",",
"array",
"$",
"orderBy",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"limit",
"=",
"25",
",",
"$",
"forTimeline",
"=",
"true",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
";",
"$",
"chartFilters",
"=",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.chartfilter'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'dateFrom'",
"]",
")",
")",
"{",
"$",
"dateFrom",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"chartFilters",
"[",
"'date_from'",
"]",
")",
";",
"$",
"dateFrom",
"->",
"setTime",
"(",
"00",
",",
"00",
",",
"00",
")",
";",
"// set to beginning of day, Timezone should be OK.",
"$",
"filters",
"[",
"'dateFrom'",
"]",
"=",
"$",
"dateFrom",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'dateTo'",
"]",
")",
")",
"{",
"$",
"dateTo",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"chartFilters",
"[",
"'date_to'",
"]",
")",
";",
"$",
"dateTo",
"->",
"setTime",
"(",
"23",
",",
"59",
",",
"59",
")",
";",
"$",
"filters",
"[",
"'dateTo'",
"]",
"=",
"$",
"dateTo",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'type'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"chartFilters",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"'type'",
"]",
"=",
"$",
"chartFilters",
"[",
"'type'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"filters",
"[",
"'campaignId'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"chartFilters",
"[",
"'campaign'",
"]",
")",
")",
"{",
"$",
"filters",
"[",
"'campaignId'",
"]",
"=",
"$",
"chartFilters",
"[",
"'campaign'",
"]",
";",
"}",
"/** @var \\MauticPlugin\\MauticContactClientBundle\\Event\\ContactClientTimelineEvent $engagements */",
"$",
"engagements",
"=",
"$",
"this",
"->",
"getModel",
"(",
"'contactclient'",
")",
"->",
"getEngagements",
"(",
"$",
"contactClient",
",",
"$",
"filters",
",",
"$",
"orderBy",
",",
"$",
"page",
",",
"$",
"limit",
")",
";",
"$",
"payload",
"=",
"[",
"'events'",
"=>",
"$",
"engagements",
"->",
"getEvents",
"(",
")",
",",
"'chartfilter'",
"=>",
"[",
"'date_from'",
"=>",
"$",
"filters",
"[",
"'dateFrom'",
"]",
"->",
"format",
"(",
"'M j, Y'",
")",
",",
"'date_to'",
"=>",
"$",
"filters",
"[",
"'dateTo'",
"]",
"->",
"format",
"(",
"'M j, Y'",
")",
",",
"'type'",
"=>",
"isset",
"(",
"$",
"filters",
"[",
"'type'",
"]",
")",
"?",
"$",
"filters",
"[",
"'type'",
"]",
":",
"null",
",",
"]",
",",
"'filters'",
"=>",
"$",
"filters",
",",
"'order'",
"=>",
"$",
"orderBy",
",",
"'types'",
"=>",
"$",
"engagements",
"->",
"getEventTypes",
"(",
")",
",",
"'total'",
"=>",
"$",
"engagements",
"->",
"getQueryTotal",
"(",
")",
",",
"'page'",
"=>",
"$",
"page",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'maxPages'",
"=>",
"$",
"engagements",
"->",
"getMaxPage",
"(",
")",
",",
"]",
";",
"return",
"(",
"$",
"forTimeline",
")",
"?",
"$",
"payload",
":",
"[",
"$",
"payload",
",",
"$",
"engagements",
"->",
"getSerializerGroups",
"(",
")",
"]",
";",
"}"
] | @param ContactClient $contactClient
@param array|null $filters
@param array|null $orderBy
@param int $page
@param int $limit
@param bool $forTimeline
@return array | [
"@param",
"ContactClient",
"$contactClient",
"@param",
"array|null",
"$filters",
"@param",
"array|null",
"$orderBy",
"@param",
"int",
"$page",
"@param",
"int",
"$limit",
"@param",
"bool",
"$forTimeline"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L67-L133 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getAllEngagements | protected function getAllEngagements(
array $contactClients,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
if (null === $filters) {
$chartfilters = $session->get(
'mautic.contactclient.plugin.transactions.chartfilter',
[
'date_from' => $this->get('mautic.helper.core_parameters')->getParameter(
'default_daterange_filter',
'-1 month'
),
'date_to' => null,
'type' => 'All Events',
]
);
$session->set('mautic.contactclient.plugin.transactions.chartfilter');
$search = $session->get('mautic.contactclient.plugin.transactions.search', '');
$session->set('mautic.contactclient.plugin.transactions.search', '');
}
$filters = InputHelper::cleanArray(array_merge($chartfilters, ['search' => $search]));
if (null == $orderBy) {
if (!$session->has('mautic.contactclient.plugin.transactions.orderby')) {
$session->set('mautic.contactclient.plugin.transactions.orderby', 'date_added');
$session->set('mautic.contactclient.plugin.transactions.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.plugin.transactions.orderby'),
$session->get('mautic.contactclient.plugin.transactions.orderbydir'),
];
}
// prepare result object
$result = [
'events' => [],
'chartfilter' => $chartfilters,
'search' => $search,
'order' => $orderBy,
'types' => [],
'total' => 0,
'page' => $page,
'limit' => $limit,
'maxPages' => 0,
];
// get events for each contact
foreach ($contactClients as $contactClient) {
// if (!$contactClient->getEmail()) continue; // discard contacts without email
/** @var ContactClientModel $model */
$model = $this->getModel('contactClient');
$engagements = $model->getEngagements($contactClient, $filters, $orderBy, $page, $limit);
$events = $engagements['events'];
$types = $engagements['types'];
// inject contactClient into events
foreach ($events as &$event) {
$event['contactClientId'] = $contactClient->getId();
$event['contactClientEmail'] = $contactClient->getEmail();
$event['contactClientName'] = $contactClient->getName() ? $contactClient->getName(
) : $contactClient->getEmail();
}
$result['events'] = array_merge($result['events'], $events);
$result['types'] = array_merge($result['types'], $types);
$result['total'] += $engagements['total'];
}
$result['maxPages'] = ($limit <= 0) ? 1 : round(ceil($result['total'] / $limit));
usort($result['events'], [$this, 'cmp']); // sort events by
// now all events are merged, let's limit to $limit
array_splice($result['events'], $limit);
$result['total'] = count($result['events']);
return $result;
} | php | protected function getAllEngagements(
array $contactClients,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
if (null === $filters) {
$chartfilters = $session->get(
'mautic.contactclient.plugin.transactions.chartfilter',
[
'date_from' => $this->get('mautic.helper.core_parameters')->getParameter(
'default_daterange_filter',
'-1 month'
),
'date_to' => null,
'type' => 'All Events',
]
);
$session->set('mautic.contactclient.plugin.transactions.chartfilter');
$search = $session->get('mautic.contactclient.plugin.transactions.search', '');
$session->set('mautic.contactclient.plugin.transactions.search', '');
}
$filters = InputHelper::cleanArray(array_merge($chartfilters, ['search' => $search]));
if (null == $orderBy) {
if (!$session->has('mautic.contactclient.plugin.transactions.orderby')) {
$session->set('mautic.contactclient.plugin.transactions.orderby', 'date_added');
$session->set('mautic.contactclient.plugin.transactions.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.plugin.transactions.orderby'),
$session->get('mautic.contactclient.plugin.transactions.orderbydir'),
];
}
// prepare result object
$result = [
'events' => [],
'chartfilter' => $chartfilters,
'search' => $search,
'order' => $orderBy,
'types' => [],
'total' => 0,
'page' => $page,
'limit' => $limit,
'maxPages' => 0,
];
// get events for each contact
foreach ($contactClients as $contactClient) {
// if (!$contactClient->getEmail()) continue; // discard contacts without email
/** @var ContactClientModel $model */
$model = $this->getModel('contactClient');
$engagements = $model->getEngagements($contactClient, $filters, $orderBy, $page, $limit);
$events = $engagements['events'];
$types = $engagements['types'];
// inject contactClient into events
foreach ($events as &$event) {
$event['contactClientId'] = $contactClient->getId();
$event['contactClientEmail'] = $contactClient->getEmail();
$event['contactClientName'] = $contactClient->getName() ? $contactClient->getName(
) : $contactClient->getEmail();
}
$result['events'] = array_merge($result['events'], $events);
$result['types'] = array_merge($result['types'], $types);
$result['total'] += $engagements['total'];
}
$result['maxPages'] = ($limit <= 0) ? 1 : round(ceil($result['total'] / $limit));
usort($result['events'], [$this, 'cmp']); // sort events by
// now all events are merged, let's limit to $limit
array_splice($result['events'], $limit);
$result['total'] = count($result['events']);
return $result;
} | [
"protected",
"function",
"getAllEngagements",
"(",
"array",
"$",
"contactClients",
",",
"array",
"$",
"filters",
"=",
"null",
",",
"array",
"$",
"orderBy",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"limit",
"=",
"25",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"filters",
")",
"{",
"$",
"chartfilters",
"=",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.plugin.transactions.chartfilter'",
",",
"[",
"'date_from'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'mautic.helper.core_parameters'",
")",
"->",
"getParameter",
"(",
"'default_daterange_filter'",
",",
"'-1 month'",
")",
",",
"'date_to'",
"=>",
"null",
",",
"'type'",
"=>",
"'All Events'",
",",
"]",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.plugin.transactions.chartfilter'",
")",
";",
"$",
"search",
"=",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.plugin.transactions.search'",
",",
"''",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.plugin.transactions.search'",
",",
"''",
")",
";",
"}",
"$",
"filters",
"=",
"InputHelper",
"::",
"cleanArray",
"(",
"array_merge",
"(",
"$",
"chartfilters",
",",
"[",
"'search'",
"=>",
"$",
"search",
"]",
")",
")",
";",
"if",
"(",
"null",
"==",
"$",
"orderBy",
")",
"{",
"if",
"(",
"!",
"$",
"session",
"->",
"has",
"(",
"'mautic.contactclient.plugin.transactions.orderby'",
")",
")",
"{",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.plugin.transactions.orderby'",
",",
"'date_added'",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.plugin.transactions.orderbydir'",
",",
"'DESC'",
")",
";",
"}",
"$",
"orderBy",
"=",
"[",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.plugin.transactions.orderby'",
")",
",",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.plugin.transactions.orderbydir'",
")",
",",
"]",
";",
"}",
"// prepare result object",
"$",
"result",
"=",
"[",
"'events'",
"=>",
"[",
"]",
",",
"'chartfilter'",
"=>",
"$",
"chartfilters",
",",
"'search'",
"=>",
"$",
"search",
",",
"'order'",
"=>",
"$",
"orderBy",
",",
"'types'",
"=>",
"[",
"]",
",",
"'total'",
"=>",
"0",
",",
"'page'",
"=>",
"$",
"page",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'maxPages'",
"=>",
"0",
",",
"]",
";",
"// get events for each contact",
"foreach",
"(",
"$",
"contactClients",
"as",
"$",
"contactClient",
")",
"{",
"// if (!$contactClient->getEmail()) continue; // discard contacts without email",
"/** @var ContactClientModel $model */",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
"'contactClient'",
")",
";",
"$",
"engagements",
"=",
"$",
"model",
"->",
"getEngagements",
"(",
"$",
"contactClient",
",",
"$",
"filters",
",",
"$",
"orderBy",
",",
"$",
"page",
",",
"$",
"limit",
")",
";",
"$",
"events",
"=",
"$",
"engagements",
"[",
"'events'",
"]",
";",
"$",
"types",
"=",
"$",
"engagements",
"[",
"'types'",
"]",
";",
"// inject contactClient into events",
"foreach",
"(",
"$",
"events",
"as",
"&",
"$",
"event",
")",
"{",
"$",
"event",
"[",
"'contactClientId'",
"]",
"=",
"$",
"contactClient",
"->",
"getId",
"(",
")",
";",
"$",
"event",
"[",
"'contactClientEmail'",
"]",
"=",
"$",
"contactClient",
"->",
"getEmail",
"(",
")",
";",
"$",
"event",
"[",
"'contactClientName'",
"]",
"=",
"$",
"contactClient",
"->",
"getName",
"(",
")",
"?",
"$",
"contactClient",
"->",
"getName",
"(",
")",
":",
"$",
"contactClient",
"->",
"getEmail",
"(",
")",
";",
"}",
"$",
"result",
"[",
"'events'",
"]",
"=",
"array_merge",
"(",
"$",
"result",
"[",
"'events'",
"]",
",",
"$",
"events",
")",
";",
"$",
"result",
"[",
"'types'",
"]",
"=",
"array_merge",
"(",
"$",
"result",
"[",
"'types'",
"]",
",",
"$",
"types",
")",
";",
"$",
"result",
"[",
"'total'",
"]",
"+=",
"$",
"engagements",
"[",
"'total'",
"]",
";",
"}",
"$",
"result",
"[",
"'maxPages'",
"]",
"=",
"(",
"$",
"limit",
"<=",
"0",
")",
"?",
"1",
":",
"round",
"(",
"ceil",
"(",
"$",
"result",
"[",
"'total'",
"]",
"/",
"$",
"limit",
")",
")",
";",
"usort",
"(",
"$",
"result",
"[",
"'events'",
"]",
",",
"[",
"$",
"this",
",",
"'cmp'",
"]",
")",
";",
"// sort events by",
"// now all events are merged, let's limit to $limit",
"array_splice",
"(",
"$",
"result",
"[",
"'events'",
"]",
",",
"$",
"limit",
")",
";",
"$",
"result",
"[",
"'total'",
"]",
"=",
"count",
"(",
"$",
"result",
"[",
"'events'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | @param array $contactClients
@param array|null $filters
@param array|null $orderBy
@param int $page
@param int $limit
@return array
@throws InvalidArgumentException | [
"@param",
"array",
"$contactClients",
"@param",
"array|null",
"$filters",
"@param",
"array|null",
"$orderBy",
"@param",
"int",
"$page",
"@param",
"int",
"$limit"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L146-L231 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getPlaces | protected function getPlaces(ContactClient $contactClient)
{
// Get Places from IP addresses
$places = [];
if ($contactClient->getIpAddresses()) {
foreach ($contactClient->getIpAddresses() as $ip) {
if ($details = $ip->getIpDetails()) {
if (!empty($details['latitude']) && !empty($details['longitude'])) {
$name = 'N/A';
if (!empty($details['city'])) {
$name = $details['city'];
} elseif (!empty($details['region'])) {
$name = $details['region'];
}
$place = [
'latLng' => [$details['latitude'], $details['longitude']],
'name' => $name,
];
$places[] = $place;
}
}
}
}
return $places;
} | php | protected function getPlaces(ContactClient $contactClient)
{
// Get Places from IP addresses
$places = [];
if ($contactClient->getIpAddresses()) {
foreach ($contactClient->getIpAddresses() as $ip) {
if ($details = $ip->getIpDetails()) {
if (!empty($details['latitude']) && !empty($details['longitude'])) {
$name = 'N/A';
if (!empty($details['city'])) {
$name = $details['city'];
} elseif (!empty($details['region'])) {
$name = $details['region'];
}
$place = [
'latLng' => [$details['latitude'], $details['longitude']],
'name' => $name,
];
$places[] = $place;
}
}
}
}
return $places;
} | [
"protected",
"function",
"getPlaces",
"(",
"ContactClient",
"$",
"contactClient",
")",
"{",
"// Get Places from IP addresses",
"$",
"places",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"contactClient",
"->",
"getIpAddresses",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"contactClient",
"->",
"getIpAddresses",
"(",
")",
"as",
"$",
"ip",
")",
"{",
"if",
"(",
"$",
"details",
"=",
"$",
"ip",
"->",
"getIpDetails",
"(",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"details",
"[",
"'latitude'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"details",
"[",
"'longitude'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"'N/A'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"details",
"[",
"'city'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"details",
"[",
"'city'",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"details",
"[",
"'region'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"details",
"[",
"'region'",
"]",
";",
"}",
"$",
"place",
"=",
"[",
"'latLng'",
"=>",
"[",
"$",
"details",
"[",
"'latitude'",
"]",
",",
"$",
"details",
"[",
"'longitude'",
"]",
"]",
",",
"'name'",
"=>",
"$",
"name",
",",
"]",
";",
"$",
"places",
"[",
"]",
"=",
"$",
"place",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"places",
";",
"}"
] | Get a list of places for the contactClient based on IP location.
@param ContactClient $contactClient
@return array | [
"Get",
"a",
"list",
"of",
"places",
"for",
"the",
"contactClient",
"based",
"on",
"IP",
"location",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L240-L265 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getAuditlogs | protected function getAuditlogs(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
if (null == $filters) {
$filters = $session->get(
'mautic.contactclient.'.$contactClient->getId().'.auditlog.filters',
[
'search' => '',
'includeEvents' => [],
'excludeEvents' => [],
]
);
}
if (null == $orderBy) {
if (!$session->has('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby')) {
$session->set('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby', 'al.dateAdded');
$session->set('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby'),
$session->get('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderbydir'),
];
}
// Audit Log
/** @var AuditLogModel $auditlogModel */
$auditlogModel = $this->getModel('core.auditLog');
$logs = $auditlogModel->getLogForObject(
'contactclient',
$contactClient->getId(),
$contactClient->getDateAdded()
);
$logCount = count($logs);
$types = [
'delete' => $this->translator->trans('mautic.contactclient.event.delete'),
'create' => $this->translator->trans('mautic.contactclient.event.create'),
'identified' => $this->translator->trans('mautic.contactclient.event.identified'),
'ipadded' => $this->translator->trans('mautic.contactclient.event.ipadded'),
'merge' => $this->translator->trans('mautic.contactclient.event.merge'),
'update' => $this->translator->trans('mautic.contactclient.event.update'),
];
return [
'events' => $logs,
'filters' => $filters,
'order' => $orderBy,
'types' => $types,
'total' => $logCount,
'page' => $page,
'limit' => $limit,
'maxPages' => ceil($logCount / $limit),
];
} | php | protected function getAuditlogs(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
if (null == $filters) {
$filters = $session->get(
'mautic.contactclient.'.$contactClient->getId().'.auditlog.filters',
[
'search' => '',
'includeEvents' => [],
'excludeEvents' => [],
]
);
}
if (null == $orderBy) {
if (!$session->has('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby')) {
$session->set('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby', 'al.dateAdded');
$session->set('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderby'),
$session->get('mautic.contactclient.'.$contactClient->getId().'.auditlog.orderbydir'),
];
}
// Audit Log
/** @var AuditLogModel $auditlogModel */
$auditlogModel = $this->getModel('core.auditLog');
$logs = $auditlogModel->getLogForObject(
'contactclient',
$contactClient->getId(),
$contactClient->getDateAdded()
);
$logCount = count($logs);
$types = [
'delete' => $this->translator->trans('mautic.contactclient.event.delete'),
'create' => $this->translator->trans('mautic.contactclient.event.create'),
'identified' => $this->translator->trans('mautic.contactclient.event.identified'),
'ipadded' => $this->translator->trans('mautic.contactclient.event.ipadded'),
'merge' => $this->translator->trans('mautic.contactclient.event.merge'),
'update' => $this->translator->trans('mautic.contactclient.event.update'),
];
return [
'events' => $logs,
'filters' => $filters,
'order' => $orderBy,
'types' => $types,
'total' => $logCount,
'page' => $page,
'limit' => $limit,
'maxPages' => ceil($logCount / $limit),
];
} | [
"protected",
"function",
"getAuditlogs",
"(",
"ContactClient",
"$",
"contactClient",
",",
"array",
"$",
"filters",
"=",
"null",
",",
"array",
"$",
"orderBy",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"limit",
"=",
"25",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
";",
"if",
"(",
"null",
"==",
"$",
"filters",
")",
"{",
"$",
"filters",
"=",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.filters'",
",",
"[",
"'search'",
"=>",
"''",
",",
"'includeEvents'",
"=>",
"[",
"]",
",",
"'excludeEvents'",
"=>",
"[",
"]",
",",
"]",
")",
";",
"}",
"if",
"(",
"null",
"==",
"$",
"orderBy",
")",
"{",
"if",
"(",
"!",
"$",
"session",
"->",
"has",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.orderby'",
")",
")",
"{",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.orderby'",
",",
"'al.dateAdded'",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.orderbydir'",
",",
"'DESC'",
")",
";",
"}",
"$",
"orderBy",
"=",
"[",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.orderby'",
")",
",",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.auditlog.orderbydir'",
")",
",",
"]",
";",
"}",
"// Audit Log",
"/** @var AuditLogModel $auditlogModel */",
"$",
"auditlogModel",
"=",
"$",
"this",
"->",
"getModel",
"(",
"'core.auditLog'",
")",
";",
"$",
"logs",
"=",
"$",
"auditlogModel",
"->",
"getLogForObject",
"(",
"'contactclient'",
",",
"$",
"contactClient",
"->",
"getId",
"(",
")",
",",
"$",
"contactClient",
"->",
"getDateAdded",
"(",
")",
")",
";",
"$",
"logCount",
"=",
"count",
"(",
"$",
"logs",
")",
";",
"$",
"types",
"=",
"[",
"'delete'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.delete'",
")",
",",
"'create'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.create'",
")",
",",
"'identified'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.identified'",
")",
",",
"'ipadded'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.ipadded'",
")",
",",
"'merge'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.merge'",
")",
",",
"'update'",
"=>",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"'mautic.contactclient.event.update'",
")",
",",
"]",
";",
"return",
"[",
"'events'",
"=>",
"$",
"logs",
",",
"'filters'",
"=>",
"$",
"filters",
",",
"'order'",
"=>",
"$",
"orderBy",
",",
"'types'",
"=>",
"$",
"types",
",",
"'total'",
"=>",
"$",
"logCount",
",",
"'page'",
"=>",
"$",
"page",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'maxPages'",
"=>",
"ceil",
"(",
"$",
"logCount",
"/",
"$",
"limit",
")",
",",
"]",
";",
"}"
] | @param ContactClient $contactClient
@param array|null $filters
@param array|null $orderBy
@param int $page
@param int $limit
@return array | [
"@param",
"ContactClient",
"$contactClient",
"@param",
"array|null",
"$filters",
"@param",
"array|null",
"$orderBy",
"@param",
"int",
"$page",
"@param",
"int",
"$limit"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L319-L381 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getFiles | protected function getFiles(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
$criteria = [];
if (null === $filters) {
$storedFilters = $session->get(
'mautic.contactclient.'.$contactClient->getId().'.chartfilter',
[
'date_from' => $this->get('mautic.helper.core_parameters')->getParameter(
'default_daterange_filter',
'-1 month midnight'
),
'date_to' => null,
'type' => '',
]
);
$session->set('mautic.contactclient.'.$contactClient->getId().'.chartfilter', $storedFilters);
// $filters['fromDate'] = new \DateTime($storedFilters['date_from']);
// $filters['toDate'] = new \DateTime($storedFilters['date_to']);
$filters['type'] = $storedFilters['type'];
}
$filters['contactClient'] = $contactClient->getId();
foreach ($filters as $name => $value) {
switch ($name) {
// case 'fromDate':
// $criteria[] = ['col' => 'dateAdded', 'expr' => 'gte', 'val' => $value];
// break;
// case 'toDate':
// $criteria[] = ['col' => 'dateAdded', 'expr' => 'lt', 'val' => $value];
// break;
default:
if (!empty($value)) {
$criteria[] = ['col' => $name, 'expr' => 'eq', 'val' => $value];
}
}
}
$start = ($page - 1) * $limit;
if (null === $orderBy || null === $orderBy[0]) { //empty array or no fieldname in first index
if (!$session->has('mautic.contactclient.'.$contactClient->getId().'.files.orderby')) {
$session->set('mautic.contactclient.'.$contactClient->getId().'.files.orderby', 'date_added');
$session->set('mautic.contactclient.'.$contactClient->getId().'.files.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.'.$contactClient->getId().'.files.orderby'),
$session->get('mautic.contactclient.'.$contactClient->getId().'.files.orderbydir'),
];
}
/** @var FileRepository $fileRepository */
$fileRepository = $this->getDoctrine()->getManager()->getRepository('MauticContactClientBundle:File');
$files = $fileRepository->getEntities(
[
'filter' => ['where' => $criteria],
'start' => $start,
'limit' => $limit,
'orderBy' => 'f.'.lcfirst(str_replace('_', '', ucwords($orderBy[0], '_'))),
'orderByDir' => $orderBy[1],
]
);
$fileCount = count($files);
return [
'files' => $files,
'filters' => $filters,
'order' => $orderBy,
'total' => $fileCount,
'page' => $page,
'limit' => $limit,
'maxPages' => ceil($fileCount / $limit),
];
} | php | protected function getFiles(
ContactClient $contactClient,
array $filters = null,
array $orderBy = null,
$page = 1,
$limit = 25
) {
$session = $this->get('session');
$criteria = [];
if (null === $filters) {
$storedFilters = $session->get(
'mautic.contactclient.'.$contactClient->getId().'.chartfilter',
[
'date_from' => $this->get('mautic.helper.core_parameters')->getParameter(
'default_daterange_filter',
'-1 month midnight'
),
'date_to' => null,
'type' => '',
]
);
$session->set('mautic.contactclient.'.$contactClient->getId().'.chartfilter', $storedFilters);
// $filters['fromDate'] = new \DateTime($storedFilters['date_from']);
// $filters['toDate'] = new \DateTime($storedFilters['date_to']);
$filters['type'] = $storedFilters['type'];
}
$filters['contactClient'] = $contactClient->getId();
foreach ($filters as $name => $value) {
switch ($name) {
// case 'fromDate':
// $criteria[] = ['col' => 'dateAdded', 'expr' => 'gte', 'val' => $value];
// break;
// case 'toDate':
// $criteria[] = ['col' => 'dateAdded', 'expr' => 'lt', 'val' => $value];
// break;
default:
if (!empty($value)) {
$criteria[] = ['col' => $name, 'expr' => 'eq', 'val' => $value];
}
}
}
$start = ($page - 1) * $limit;
if (null === $orderBy || null === $orderBy[0]) { //empty array or no fieldname in first index
if (!$session->has('mautic.contactclient.'.$contactClient->getId().'.files.orderby')) {
$session->set('mautic.contactclient.'.$contactClient->getId().'.files.orderby', 'date_added');
$session->set('mautic.contactclient.'.$contactClient->getId().'.files.orderbydir', 'DESC');
}
$orderBy = [
$session->get('mautic.contactclient.'.$contactClient->getId().'.files.orderby'),
$session->get('mautic.contactclient.'.$contactClient->getId().'.files.orderbydir'),
];
}
/** @var FileRepository $fileRepository */
$fileRepository = $this->getDoctrine()->getManager()->getRepository('MauticContactClientBundle:File');
$files = $fileRepository->getEntities(
[
'filter' => ['where' => $criteria],
'start' => $start,
'limit' => $limit,
'orderBy' => 'f.'.lcfirst(str_replace('_', '', ucwords($orderBy[0], '_'))),
'orderByDir' => $orderBy[1],
]
);
$fileCount = count($files);
return [
'files' => $files,
'filters' => $filters,
'order' => $orderBy,
'total' => $fileCount,
'page' => $page,
'limit' => $limit,
'maxPages' => ceil($fileCount / $limit),
];
} | [
"protected",
"function",
"getFiles",
"(",
"ContactClient",
"$",
"contactClient",
",",
"array",
"$",
"filters",
"=",
"null",
",",
"array",
"$",
"orderBy",
"=",
"null",
",",
"$",
"page",
"=",
"1",
",",
"$",
"limit",
"=",
"25",
")",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
";",
"$",
"criteria",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"===",
"$",
"filters",
")",
"{",
"$",
"storedFilters",
"=",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.chartfilter'",
",",
"[",
"'date_from'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'mautic.helper.core_parameters'",
")",
"->",
"getParameter",
"(",
"'default_daterange_filter'",
",",
"'-1 month midnight'",
")",
",",
"'date_to'",
"=>",
"null",
",",
"'type'",
"=>",
"''",
",",
"]",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.chartfilter'",
",",
"$",
"storedFilters",
")",
";",
"// $filters['fromDate'] = new \\DateTime($storedFilters['date_from']);",
"// $filters['toDate'] = new \\DateTime($storedFilters['date_to']);",
"$",
"filters",
"[",
"'type'",
"]",
"=",
"$",
"storedFilters",
"[",
"'type'",
"]",
";",
"}",
"$",
"filters",
"[",
"'contactClient'",
"]",
"=",
"$",
"contactClient",
"->",
"getId",
"(",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"// case 'fromDate':",
"// $criteria[] = ['col' => 'dateAdded', 'expr' => 'gte', 'val' => $value];",
"// break;",
"// case 'toDate':",
"// $criteria[] = ['col' => 'dateAdded', 'expr' => 'lt', 'val' => $value];",
"// break;",
"default",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"criteria",
"[",
"]",
"=",
"[",
"'col'",
"=>",
"$",
"name",
",",
"'expr'",
"=>",
"'eq'",
",",
"'val'",
"=>",
"$",
"value",
"]",
";",
"}",
"}",
"}",
"$",
"start",
"=",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"limit",
";",
"if",
"(",
"null",
"===",
"$",
"orderBy",
"||",
"null",
"===",
"$",
"orderBy",
"[",
"0",
"]",
")",
"{",
"//empty array or no fieldname in first index",
"if",
"(",
"!",
"$",
"session",
"->",
"has",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.files.orderby'",
")",
")",
"{",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.files.orderby'",
",",
"'date_added'",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.files.orderbydir'",
",",
"'DESC'",
")",
";",
"}",
"$",
"orderBy",
"=",
"[",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.files.orderby'",
")",
",",
"$",
"session",
"->",
"get",
"(",
"'mautic.contactclient.'",
".",
"$",
"contactClient",
"->",
"getId",
"(",
")",
".",
"'.files.orderbydir'",
")",
",",
"]",
";",
"}",
"/** @var FileRepository $fileRepository */",
"$",
"fileRepository",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"getRepository",
"(",
"'MauticContactClientBundle:File'",
")",
";",
"$",
"files",
"=",
"$",
"fileRepository",
"->",
"getEntities",
"(",
"[",
"'filter'",
"=>",
"[",
"'where'",
"=>",
"$",
"criteria",
"]",
",",
"'start'",
"=>",
"$",
"start",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'orderBy'",
"=>",
"'f.'",
".",
"lcfirst",
"(",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"ucwords",
"(",
"$",
"orderBy",
"[",
"0",
"]",
",",
"'_'",
")",
")",
")",
",",
"'orderByDir'",
"=>",
"$",
"orderBy",
"[",
"1",
"]",
",",
"]",
")",
";",
"$",
"fileCount",
"=",
"count",
"(",
"$",
"files",
")",
";",
"return",
"[",
"'files'",
"=>",
"$",
"files",
",",
"'filters'",
"=>",
"$",
"filters",
",",
"'order'",
"=>",
"$",
"orderBy",
",",
"'total'",
"=>",
"$",
"fileCount",
",",
"'page'",
"=>",
"$",
"page",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'maxPages'",
"=>",
"ceil",
"(",
"$",
"fileCount",
"/",
"$",
"limit",
")",
",",
"]",
";",
"}"
] | @param ContactClient $contactClient
@param array|null $filters
@param array|null $orderBy
@param int $page
@param int $limit
@return array | [
"@param",
"ContactClient",
"$contactClient",
"@param",
"array|null",
"$filters",
"@param",
"array|null",
"$orderBy",
"@param",
"int",
"$page",
"@param",
"int",
"$limit"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L392-L473 |
TheDMSGroup/mautic-contact-client | Controller/ContactClientDetailsTrait.php | ContactClientDetailsTrait.getScheduledCampaignEvents | protected function getScheduledCampaignEvents(ContactClient $contactClient)
{
// Upcoming events from Campaign Bundle
/** @var \Mautic\CampaignBundle\Entity\ContactClientEventLogRepository $contactClientEventLogRepository */
$contactClientEventLogRepository = $this->getDoctrine()->getManager()->getRepository(
'MauticCampaignBundle:ContactClientEventLog'
);
return $contactClientEventLogRepository->getUpcomingEvents(
[
'contactClient' => $contactClient,
'eventType' => ['action', 'condition'],
]
);
} | php | protected function getScheduledCampaignEvents(ContactClient $contactClient)
{
// Upcoming events from Campaign Bundle
/** @var \Mautic\CampaignBundle\Entity\ContactClientEventLogRepository $contactClientEventLogRepository */
$contactClientEventLogRepository = $this->getDoctrine()->getManager()->getRepository(
'MauticCampaignBundle:ContactClientEventLog'
);
return $contactClientEventLogRepository->getUpcomingEvents(
[
'contactClient' => $contactClient,
'eventType' => ['action', 'condition'],
]
);
} | [
"protected",
"function",
"getScheduledCampaignEvents",
"(",
"ContactClient",
"$",
"contactClient",
")",
"{",
"// Upcoming events from Campaign Bundle",
"/** @var \\Mautic\\CampaignBundle\\Entity\\ContactClientEventLogRepository $contactClientEventLogRepository */",
"$",
"contactClientEventLogRepository",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"getRepository",
"(",
"'MauticCampaignBundle:ContactClientEventLog'",
")",
";",
"return",
"$",
"contactClientEventLogRepository",
"->",
"getUpcomingEvents",
"(",
"[",
"'contactClient'",
"=>",
"$",
"contactClient",
",",
"'eventType'",
"=>",
"[",
"'action'",
",",
"'condition'",
"]",
",",
"]",
")",
";",
"}"
] | @param ContactClient $contactClient
@return array | [
"@param",
"ContactClient",
"$contactClient"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Controller/ContactClientDetailsTrait.php#L480-L494 |
TheDMSGroup/mautic-contact-client | Helper/UtmSourceHelper.php | UtmSourceHelper.getFirstUtmSource | public function getFirstUtmSource(Contact $contact)
{
$source = '';
if (!empty($tags = $this->getSortedUtmTags($contact))) {
$tag = reset($tags);
$source = trim($tag->getUtmSource());
}
return $source;
} | php | public function getFirstUtmSource(Contact $contact)
{
$source = '';
if (!empty($tags = $this->getSortedUtmTags($contact))) {
$tag = reset($tags);
$source = trim($tag->getUtmSource());
}
return $source;
} | [
"public",
"function",
"getFirstUtmSource",
"(",
"Contact",
"$",
"contact",
")",
"{",
"$",
"source",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tags",
"=",
"$",
"this",
"->",
"getSortedUtmTags",
"(",
"$",
"contact",
")",
")",
")",
"{",
"$",
"tag",
"=",
"reset",
"(",
"$",
"tags",
")",
";",
"$",
"source",
"=",
"trim",
"(",
"$",
"tag",
"->",
"getUtmSource",
"(",
")",
")",
";",
"}",
"return",
"$",
"source",
";",
"}"
] | @param Contact $contact
@return null|string | [
"@param",
"Contact",
"$contact"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/UtmSourceHelper.php#L27-L36 |
TheDMSGroup/mautic-contact-client | Helper/UtmSourceHelper.php | UtmSourceHelper.getSortedUtmTags | public function getSortedUtmTags(Contact $contact)
{
$tags = [];
if ($contact instanceof Contact) {
$utmTags = $contact->getUtmTags();
if ($utmTags) {
$utmTags = $utmTags instanceof ArrayCollection ? $utmTags->toArray() : $utmTags;
/** @var \Mautic\LeadBundle\Entity\UtmTag $utmTag */
foreach ($utmTags as $utmTag) {
$tags[$utmTag->getDateAdded()->getTimestamp()] = $utmTag;
}
ksort($tags);
}
}
return $tags;
} | php | public function getSortedUtmTags(Contact $contact)
{
$tags = [];
if ($contact instanceof Contact) {
$utmTags = $contact->getUtmTags();
if ($utmTags) {
$utmTags = $utmTags instanceof ArrayCollection ? $utmTags->toArray() : $utmTags;
/** @var \Mautic\LeadBundle\Entity\UtmTag $utmTag */
foreach ($utmTags as $utmTag) {
$tags[$utmTag->getDateAdded()->getTimestamp()] = $utmTag;
}
ksort($tags);
}
}
return $tags;
} | [
"public",
"function",
"getSortedUtmTags",
"(",
"Contact",
"$",
"contact",
")",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"contact",
"instanceof",
"Contact",
")",
"{",
"$",
"utmTags",
"=",
"$",
"contact",
"->",
"getUtmTags",
"(",
")",
";",
"if",
"(",
"$",
"utmTags",
")",
"{",
"$",
"utmTags",
"=",
"$",
"utmTags",
"instanceof",
"ArrayCollection",
"?",
"$",
"utmTags",
"->",
"toArray",
"(",
")",
":",
"$",
"utmTags",
";",
"/** @var \\Mautic\\LeadBundle\\Entity\\UtmTag $utmTag */",
"foreach",
"(",
"$",
"utmTags",
"as",
"$",
"utmTag",
")",
"{",
"$",
"tags",
"[",
"$",
"utmTag",
"->",
"getDateAdded",
"(",
")",
"->",
"getTimestamp",
"(",
")",
"]",
"=",
"$",
"utmTag",
";",
"}",
"ksort",
"(",
"$",
"tags",
")",
";",
"}",
"}",
"return",
"$",
"tags",
";",
"}"
] | @param Contact $contact
@return array | [
"@param",
"Contact",
"$contact"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/UtmSourceHelper.php#L43-L59 |
TheDMSGroup/mautic-contact-client | Helper/UtmSourceHelper.php | UtmSourceHelper.getLastUtmSource | public function getLastUtmSource(Contact $contact)
{
$source = '';
if (!empty($tags = $this->getSortedUtmTags($contact))) {
$tag = end($tags);
$source = trim($tag->getUtmSource());
}
return $source;
} | php | public function getLastUtmSource(Contact $contact)
{
$source = '';
if (!empty($tags = $this->getSortedUtmTags($contact))) {
$tag = end($tags);
$source = trim($tag->getUtmSource());
}
return $source;
} | [
"public",
"function",
"getLastUtmSource",
"(",
"Contact",
"$",
"contact",
")",
"{",
"$",
"source",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tags",
"=",
"$",
"this",
"->",
"getSortedUtmTags",
"(",
"$",
"contact",
")",
")",
")",
"{",
"$",
"tag",
"=",
"end",
"(",
"$",
"tags",
")",
";",
"$",
"source",
"=",
"trim",
"(",
"$",
"tag",
"->",
"getUtmSource",
"(",
")",
")",
";",
"}",
"return",
"$",
"source",
";",
"}"
] | @param Contact $contact
@return string | [
"@param",
"Contact",
"$contact"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Helper/UtmSourceHelper.php#L66-L75 |
TheDMSGroup/mautic-contact-client | EventListener/ContactClientSubscriber.php | ContactClientSubscriber.onContactClientPostSave | public function onContactClientPostSave(ContactClientEvent $event)
{
$entity = $event->getContactClient();
if ($details = $event->getChanges()) {
$log = [
'bundle' => 'contactclient',
'object' => 'contactclient',
'objectId' => $entity->getId(),
'action' => ($event->isNew()) ? 'create' : 'update',
'details' => $details,
'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
];
$this->auditLogModel->writeToLog($log);
}
} | php | public function onContactClientPostSave(ContactClientEvent $event)
{
$entity = $event->getContactClient();
if ($details = $event->getChanges()) {
$log = [
'bundle' => 'contactclient',
'object' => 'contactclient',
'objectId' => $entity->getId(),
'action' => ($event->isNew()) ? 'create' : 'update',
'details' => $details,
'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
];
$this->auditLogModel->writeToLog($log);
}
} | [
"public",
"function",
"onContactClientPostSave",
"(",
"ContactClientEvent",
"$",
"event",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"getContactClient",
"(",
")",
";",
"if",
"(",
"$",
"details",
"=",
"$",
"event",
"->",
"getChanges",
"(",
")",
")",
"{",
"$",
"log",
"=",
"[",
"'bundle'",
"=>",
"'contactclient'",
",",
"'object'",
"=>",
"'contactclient'",
",",
"'objectId'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
",",
"'action'",
"=>",
"(",
"$",
"event",
"->",
"isNew",
"(",
")",
")",
"?",
"'create'",
":",
"'update'",
",",
"'details'",
"=>",
"$",
"details",
",",
"'ipAddress'",
"=>",
"$",
"this",
"->",
"ipHelper",
"->",
"getIpAddressFromRequest",
"(",
")",
",",
"]",
";",
"$",
"this",
"->",
"auditLogModel",
"->",
"writeToLog",
"(",
"$",
"log",
")",
";",
"}",
"}"
] | Add an entry to the audit log.
@param ContactClientEvent $event | [
"Add",
"an",
"entry",
"to",
"the",
"audit",
"log",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/EventListener/ContactClientSubscriber.php#L141-L155 |
TheDMSGroup/mautic-contact-client | EventListener/ContactClientSubscriber.php | ContactClientSubscriber.onContactClientDelete | public function onContactClientDelete(ContactClientEvent $event)
{
$entity = $event->getContactClient();
$log = [
'bundle' => 'contactclient',
'object' => 'contactclient',
'objectId' => $entity->deletedId,
'action' => 'delete',
'details' => ['name' => $entity->getName()],
'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
];
$this->auditLogModel->writeToLog($log);
} | php | public function onContactClientDelete(ContactClientEvent $event)
{
$entity = $event->getContactClient();
$log = [
'bundle' => 'contactclient',
'object' => 'contactclient',
'objectId' => $entity->deletedId,
'action' => 'delete',
'details' => ['name' => $entity->getName()],
'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
];
$this->auditLogModel->writeToLog($log);
} | [
"public",
"function",
"onContactClientDelete",
"(",
"ContactClientEvent",
"$",
"event",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"getContactClient",
"(",
")",
";",
"$",
"log",
"=",
"[",
"'bundle'",
"=>",
"'contactclient'",
",",
"'object'",
"=>",
"'contactclient'",
",",
"'objectId'",
"=>",
"$",
"entity",
"->",
"deletedId",
",",
"'action'",
"=>",
"'delete'",
",",
"'details'",
"=>",
"[",
"'name'",
"=>",
"$",
"entity",
"->",
"getName",
"(",
")",
"]",
",",
"'ipAddress'",
"=>",
"$",
"this",
"->",
"ipHelper",
"->",
"getIpAddressFromRequest",
"(",
")",
",",
"]",
";",
"$",
"this",
"->",
"auditLogModel",
"->",
"writeToLog",
"(",
"$",
"log",
")",
";",
"}"
] | Add a delete entry to the audit log.
@param ContactClientEvent $event | [
"Add",
"a",
"delete",
"entry",
"to",
"the",
"audit",
"log",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/EventListener/ContactClientSubscriber.php#L162-L174 |
TheDMSGroup/mautic-contact-client | EventListener/ContactClientSubscriber.php | ContactClientSubscriber.onTimelineGenerate | public function onTimelineGenerate(ContactClientTimelineEvent $event)
{
/** @var EventRepository $eventRepository */
$eventRepository = $this->em->getRepository('MauticContactClientBundle:Event');
// Set available event types
// $event->addSerializerGroup(['formList', 'submissionEventDetails']);
foreach (Stat::getAllTypes() as $type) {
// TODO: $event->addEventType($type, $this->translator->trans('mautic.contactclient.event.'.$type));
$event->addEventType($type, ucfirst($type));
}
$results = $eventRepository->getEventsForTimeline(
$event->getContactClient()->getId(),
$event->getQueryOptions()
);
$rows = isset($results['results']) ? $results['results'] : $results;
$total = isset($results['total']) ? $results['total'] : count($rows);
foreach ($rows as $row) {
$eventTypeKey = $row['type'];
$eventTypeName = ucwords($eventTypeKey);
// Add total to counter
$event->setQueryTotal($total);
$event->addToCounter($eventTypeKey, 1);
$log = $row['logs'][0] === '{' ? json_encode(json_decode($row['logs']), JSON_PRETTY_PRINT) : $row['logs'];
if (!$event->isEngagementCount()) {
$event->addEvent(
[
'event' => $eventTypeKey,
'eventId' => $eventTypeKey.$row['id'],
'eventLabel' => [
'label' => $eventTypeName,
'href' => $this->router->generate(
'mautic_form_action',
['objectAction' => 'view', 'objectId' => $row['id']]
),
],
'eventType' => $eventTypeName,
'extra' => [
'logs' => strip_tags($log),
'integrationEntityId' => $row['integration_entity_id'],
],
'contentTemplate' => 'MauticContactClientBundle:Transactions:eventdetails.html.php',
'icon' => 'fa-plus-square-o',
'message' => $row['message'],
'contactId' => $row['contact_id'],
'utmSource' => $row['utm_source'],
'timestamp' => $row['date_added'],
]
);
}
}
} | php | public function onTimelineGenerate(ContactClientTimelineEvent $event)
{
/** @var EventRepository $eventRepository */
$eventRepository = $this->em->getRepository('MauticContactClientBundle:Event');
// Set available event types
// $event->addSerializerGroup(['formList', 'submissionEventDetails']);
foreach (Stat::getAllTypes() as $type) {
// TODO: $event->addEventType($type, $this->translator->trans('mautic.contactclient.event.'.$type));
$event->addEventType($type, ucfirst($type));
}
$results = $eventRepository->getEventsForTimeline(
$event->getContactClient()->getId(),
$event->getQueryOptions()
);
$rows = isset($results['results']) ? $results['results'] : $results;
$total = isset($results['total']) ? $results['total'] : count($rows);
foreach ($rows as $row) {
$eventTypeKey = $row['type'];
$eventTypeName = ucwords($eventTypeKey);
// Add total to counter
$event->setQueryTotal($total);
$event->addToCounter($eventTypeKey, 1);
$log = $row['logs'][0] === '{' ? json_encode(json_decode($row['logs']), JSON_PRETTY_PRINT) : $row['logs'];
if (!$event->isEngagementCount()) {
$event->addEvent(
[
'event' => $eventTypeKey,
'eventId' => $eventTypeKey.$row['id'],
'eventLabel' => [
'label' => $eventTypeName,
'href' => $this->router->generate(
'mautic_form_action',
['objectAction' => 'view', 'objectId' => $row['id']]
),
],
'eventType' => $eventTypeName,
'extra' => [
'logs' => strip_tags($log),
'integrationEntityId' => $row['integration_entity_id'],
],
'contentTemplate' => 'MauticContactClientBundle:Transactions:eventdetails.html.php',
'icon' => 'fa-plus-square-o',
'message' => $row['message'],
'contactId' => $row['contact_id'],
'utmSource' => $row['utm_source'],
'timestamp' => $row['date_added'],
]
);
}
}
} | [
"public",
"function",
"onTimelineGenerate",
"(",
"ContactClientTimelineEvent",
"$",
"event",
")",
"{",
"/** @var EventRepository $eventRepository */",
"$",
"eventRepository",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'MauticContactClientBundle:Event'",
")",
";",
"// Set available event types",
"// $event->addSerializerGroup(['formList', 'submissionEventDetails']);",
"foreach",
"(",
"Stat",
"::",
"getAllTypes",
"(",
")",
"as",
"$",
"type",
")",
"{",
"// TODO: $event->addEventType($type, $this->translator->trans('mautic.contactclient.event.'.$type));",
"$",
"event",
"->",
"addEventType",
"(",
"$",
"type",
",",
"ucfirst",
"(",
"$",
"type",
")",
")",
";",
"}",
"$",
"results",
"=",
"$",
"eventRepository",
"->",
"getEventsForTimeline",
"(",
"$",
"event",
"->",
"getContactClient",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"event",
"->",
"getQueryOptions",
"(",
")",
")",
";",
"$",
"rows",
"=",
"isset",
"(",
"$",
"results",
"[",
"'results'",
"]",
")",
"?",
"$",
"results",
"[",
"'results'",
"]",
":",
"$",
"results",
";",
"$",
"total",
"=",
"isset",
"(",
"$",
"results",
"[",
"'total'",
"]",
")",
"?",
"$",
"results",
"[",
"'total'",
"]",
":",
"count",
"(",
"$",
"rows",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"eventTypeKey",
"=",
"$",
"row",
"[",
"'type'",
"]",
";",
"$",
"eventTypeName",
"=",
"ucwords",
"(",
"$",
"eventTypeKey",
")",
";",
"// Add total to counter",
"$",
"event",
"->",
"setQueryTotal",
"(",
"$",
"total",
")",
";",
"$",
"event",
"->",
"addToCounter",
"(",
"$",
"eventTypeKey",
",",
"1",
")",
";",
"$",
"log",
"=",
"$",
"row",
"[",
"'logs'",
"]",
"[",
"0",
"]",
"===",
"'{'",
"?",
"json_encode",
"(",
"json_decode",
"(",
"$",
"row",
"[",
"'logs'",
"]",
")",
",",
"JSON_PRETTY_PRINT",
")",
":",
"$",
"row",
"[",
"'logs'",
"]",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"isEngagementCount",
"(",
")",
")",
"{",
"$",
"event",
"->",
"addEvent",
"(",
"[",
"'event'",
"=>",
"$",
"eventTypeKey",
",",
"'eventId'",
"=>",
"$",
"eventTypeKey",
".",
"$",
"row",
"[",
"'id'",
"]",
",",
"'eventLabel'",
"=>",
"[",
"'label'",
"=>",
"$",
"eventTypeName",
",",
"'href'",
"=>",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'mautic_form_action'",
",",
"[",
"'objectAction'",
"=>",
"'view'",
",",
"'objectId'",
"=>",
"$",
"row",
"[",
"'id'",
"]",
"]",
")",
",",
"]",
",",
"'eventType'",
"=>",
"$",
"eventTypeName",
",",
"'extra'",
"=>",
"[",
"'logs'",
"=>",
"strip_tags",
"(",
"$",
"log",
")",
",",
"'integrationEntityId'",
"=>",
"$",
"row",
"[",
"'integration_entity_id'",
"]",
",",
"]",
",",
"'contentTemplate'",
"=>",
"'MauticContactClientBundle:Transactions:eventdetails.html.php'",
",",
"'icon'",
"=>",
"'fa-plus-square-o'",
",",
"'message'",
"=>",
"$",
"row",
"[",
"'message'",
"]",
",",
"'contactId'",
"=>",
"$",
"row",
"[",
"'contact_id'",
"]",
",",
"'utmSource'",
"=>",
"$",
"row",
"[",
"'utm_source'",
"]",
",",
"'timestamp'",
"=>",
"$",
"row",
"[",
"'date_added'",
"]",
",",
"]",
")",
";",
"}",
"}",
"}"
] | Compile events for the lead timeline.
@param ContactClientTransactionsEvent $event | [
"Compile",
"events",
"for",
"the",
"lead",
"timeline",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/EventListener/ContactClientSubscriber.php#L181-L237 |
TheDMSGroup/mautic-contact-client | Entity/EventRepository.php | EventRepository.getEvents | public function getEvents($contactClientId, $eventType = null, $dateRange = [])
{
$q = $this->getEntityManager()->getConnection()->createQueryBuilder()
->from(MAUTIC_TABLE_PREFIX.'contactclient_events', 'c')
->select('c.*');
$expr = $q->expr()->eq('c.contactclient_id', ':contactClient');
$q->where($expr)
->setParameter('contactClient', (int) $contactClientId);
if (isset($dateRange['dateFrom'])) {
if (!($dateRange['dateFrom'] instanceof \DateTime)) {
try {
$dateRange['datefrom'] = new \DateTime($dateRange['dateFrom']);
$dateRange['dateFrom']->setTime(0, 0, 0);
} catch (\Exception $e) {
$dateRange['datefrom'] = new \DateTime('midnight -1 month');
}
}
$q->andWhere(
$q->expr()->gte('c.date_added', ':dateFrom')
)
->setParameter('dateFrom', $dateRange['dateFrom']->format('Y-m-d H:i:s'));
}
if (isset($dateRange['dateTo'])) {
if (!($dateRange['dateTo'] instanceof \DateTime)) {
try {
$dateRange['datefrom'] = new \DateTime($dateRange['dateTo']);
$dateRange['dateTo']->setTime(0, 0, 0);
} catch (\Exception $e) {
$dateRange['datefrom'] = new \DateTime('midnight');
}
$dateRange['dateTo']->modify('+1 day');
}
$q->andWhere(
$q->expr()->lt('c.date_added', ':dateTo')
)
->setParameter('dateTo', $dateRange['dateTo']->format('Y-m-d H:i:s'));
}
if ($eventType) {
$q->andWhere(
$q->expr()->eq('c.type', ':type')
)
->setParameter('type', $eventType);
}
return $q->execute()->fetchAll();
} | php | public function getEvents($contactClientId, $eventType = null, $dateRange = [])
{
$q = $this->getEntityManager()->getConnection()->createQueryBuilder()
->from(MAUTIC_TABLE_PREFIX.'contactclient_events', 'c')
->select('c.*');
$expr = $q->expr()->eq('c.contactclient_id', ':contactClient');
$q->where($expr)
->setParameter('contactClient', (int) $contactClientId);
if (isset($dateRange['dateFrom'])) {
if (!($dateRange['dateFrom'] instanceof \DateTime)) {
try {
$dateRange['datefrom'] = new \DateTime($dateRange['dateFrom']);
$dateRange['dateFrom']->setTime(0, 0, 0);
} catch (\Exception $e) {
$dateRange['datefrom'] = new \DateTime('midnight -1 month');
}
}
$q->andWhere(
$q->expr()->gte('c.date_added', ':dateFrom')
)
->setParameter('dateFrom', $dateRange['dateFrom']->format('Y-m-d H:i:s'));
}
if (isset($dateRange['dateTo'])) {
if (!($dateRange['dateTo'] instanceof \DateTime)) {
try {
$dateRange['datefrom'] = new \DateTime($dateRange['dateTo']);
$dateRange['dateTo']->setTime(0, 0, 0);
} catch (\Exception $e) {
$dateRange['datefrom'] = new \DateTime('midnight');
}
$dateRange['dateTo']->modify('+1 day');
}
$q->andWhere(
$q->expr()->lt('c.date_added', ':dateTo')
)
->setParameter('dateTo', $dateRange['dateTo']->format('Y-m-d H:i:s'));
}
if ($eventType) {
$q->andWhere(
$q->expr()->eq('c.type', ':type')
)
->setParameter('type', $eventType);
}
return $q->execute()->fetchAll();
} | [
"public",
"function",
"getEvents",
"(",
"$",
"contactClientId",
",",
"$",
"eventType",
"=",
"null",
",",
"$",
"dateRange",
"=",
"[",
"]",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
"->",
"from",
"(",
"MAUTIC_TABLE_PREFIX",
".",
"'contactclient_events'",
",",
"'c'",
")",
"->",
"select",
"(",
"'c.*'",
")",
";",
"$",
"expr",
"=",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'c.contactclient_id'",
",",
"':contactClient'",
")",
";",
"$",
"q",
"->",
"where",
"(",
"$",
"expr",
")",
"->",
"setParameter",
"(",
"'contactClient'",
",",
"(",
"int",
")",
"$",
"contactClientId",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dateRange",
"[",
"'dateFrom'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"dateRange",
"[",
"'dateFrom'",
"]",
"instanceof",
"\\",
"DateTime",
")",
")",
"{",
"try",
"{",
"$",
"dateRange",
"[",
"'datefrom'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"dateRange",
"[",
"'dateFrom'",
"]",
")",
";",
"$",
"dateRange",
"[",
"'dateFrom'",
"]",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"dateRange",
"[",
"'datefrom'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"'midnight -1 month'",
")",
";",
"}",
"}",
"$",
"q",
"->",
"andWhere",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"gte",
"(",
"'c.date_added'",
",",
"':dateFrom'",
")",
")",
"->",
"setParameter",
"(",
"'dateFrom'",
",",
"$",
"dateRange",
"[",
"'dateFrom'",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
"instanceof",
"\\",
"DateTime",
")",
")",
"{",
"try",
"{",
"$",
"dateRange",
"[",
"'datefrom'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
")",
";",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"dateRange",
"[",
"'datefrom'",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"'midnight'",
")",
";",
"}",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
"->",
"modify",
"(",
"'+1 day'",
")",
";",
"}",
"$",
"q",
"->",
"andWhere",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"lt",
"(",
"'c.date_added'",
",",
"':dateTo'",
")",
")",
"->",
"setParameter",
"(",
"'dateTo'",
",",
"$",
"dateRange",
"[",
"'dateTo'",
"]",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
")",
";",
"}",
"if",
"(",
"$",
"eventType",
")",
"{",
"$",
"q",
"->",
"andWhere",
"(",
"$",
"q",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'c.type'",
",",
"':type'",
")",
")",
"->",
"setParameter",
"(",
"'type'",
",",
"$",
"eventType",
")",
";",
"}",
"return",
"$",
"q",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
")",
";",
"}"
] | Fetch the base event data from the database.
@param $contactClientId
@param $eventType
@param array|null $dateRange
@return array | [
"Fetch",
"the",
"base",
"event",
"data",
"from",
"the",
"database",
"."
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/EventRepository.php#L31-L79 |
TheDMSGroup/mautic-contact-client | Entity/EventRepository.php | EventRepository.getEventsForTimeline | public function getEventsForTimeline($contactClientId, array $options = [])
{
$query = $this->getEntityManager()->getConnection()->createQueryBuilder()
->from(MAUTIC_TABLE_PREFIX.'contactclient_events', 'c');
$query->select('c.*, s.utm_source');
$query->leftJoin(
'c',
MAUTIC_TABLE_PREFIX.'contactclient_stats',
's',
'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'
);
$query->where('c.contactclient_id = :contactClientId')
->setParameter('contactClientId', $contactClientId);
if (isset($options['message']) && !empty($options['message'])) {
$query->andWhere('c.message LIKE :message')
->setParameter('message', '%'.trim($options['message']).'%');
}
if (isset($options['contact_id']) && !empty($options['contact_id'])) {
$query->andWhere('c.contact_id = :contact')
->setParameter('contact', trim($options['contact_id']));
}
if (isset($options['type']) && !empty($options['type'])) {
$query->andWhere('c.type = :type')
->setParameter('type', trim($options['type']));
}
if (isset($options['utm_source']) && !empty($options['utm_source'])) {
$query->andWhere('s.utm_source = :utm')
->setParameter('utm', trim($options['utm_source']));
}
if (isset($options['dateFrom'])) {
$query->andWhere('c.date_added >= FROM_UNIXTIME(:dateFrom)')
->setParameter(
'dateFrom',
$options['dateFrom']->getTimestamp()
);
}
if (isset($options['dateTo'])) {
$query->andWhere('c.date_added < FROM_UNIXTIME(:dateTo)')
->setParameter(
'dateTo',
$options['dateTo']->getTimestamp()
);
}
if (isset($options['campaignId']) && !empty($options['campaignId'])) {
$query->andWhere('s.campaign_id = :campaignId')
->setParameter(
'campaignId',
$options['campaignId']
);
}
if (isset($options['order']) && is_array($options['order']) && 2 == count($options['order'])) {
list($orderBy, $orderByDir) = array_values($options['order']);
if ($orderBy && $orderByDir) {
if ('utm_source' !== $orderBy) {
$query->orderBy('c.'.$orderBy, $orderByDir);
} else {
$query->orderBy('s.'.$orderBy, $orderByDir);
}
}
}
if (!empty($options['limit'])) {
$query->setMaxResults($options['limit']);
if (!empty($options['start'])) {
$query->setFirstResult($options['start']);
}
}
$results = $query->execute()->fetchAll();
if (!empty($options['paginated'])) {
// Get a total count along with results
$query->resetQueryParts(['select', 'orderBy', 'join'])
->setFirstResult(null)
->setMaxResults(null)
->select('COUNT(*)');
if (
(isset($options['utm_source']) && !empty($options['utm_source']))
|| (isset($options['campaignId']) && !empty($options['campaignId']))
) {
$query->leftJoin(
'c',
MAUTIC_TABLE_PREFIX.'contactclient_stats',
's',
'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'
);
}
$counter = $query->execute();
$total = $counter->fetchColumn();
return [
'total' => $total,
'results' => $results,
];
}
return $results;
} | php | public function getEventsForTimeline($contactClientId, array $options = [])
{
$query = $this->getEntityManager()->getConnection()->createQueryBuilder()
->from(MAUTIC_TABLE_PREFIX.'contactclient_events', 'c');
$query->select('c.*, s.utm_source');
$query->leftJoin(
'c',
MAUTIC_TABLE_PREFIX.'contactclient_stats',
's',
'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'
);
$query->where('c.contactclient_id = :contactClientId')
->setParameter('contactClientId', $contactClientId);
if (isset($options['message']) && !empty($options['message'])) {
$query->andWhere('c.message LIKE :message')
->setParameter('message', '%'.trim($options['message']).'%');
}
if (isset($options['contact_id']) && !empty($options['contact_id'])) {
$query->andWhere('c.contact_id = :contact')
->setParameter('contact', trim($options['contact_id']));
}
if (isset($options['type']) && !empty($options['type'])) {
$query->andWhere('c.type = :type')
->setParameter('type', trim($options['type']));
}
if (isset($options['utm_source']) && !empty($options['utm_source'])) {
$query->andWhere('s.utm_source = :utm')
->setParameter('utm', trim($options['utm_source']));
}
if (isset($options['dateFrom'])) {
$query->andWhere('c.date_added >= FROM_UNIXTIME(:dateFrom)')
->setParameter(
'dateFrom',
$options['dateFrom']->getTimestamp()
);
}
if (isset($options['dateTo'])) {
$query->andWhere('c.date_added < FROM_UNIXTIME(:dateTo)')
->setParameter(
'dateTo',
$options['dateTo']->getTimestamp()
);
}
if (isset($options['campaignId']) && !empty($options['campaignId'])) {
$query->andWhere('s.campaign_id = :campaignId')
->setParameter(
'campaignId',
$options['campaignId']
);
}
if (isset($options['order']) && is_array($options['order']) && 2 == count($options['order'])) {
list($orderBy, $orderByDir) = array_values($options['order']);
if ($orderBy && $orderByDir) {
if ('utm_source' !== $orderBy) {
$query->orderBy('c.'.$orderBy, $orderByDir);
} else {
$query->orderBy('s.'.$orderBy, $orderByDir);
}
}
}
if (!empty($options['limit'])) {
$query->setMaxResults($options['limit']);
if (!empty($options['start'])) {
$query->setFirstResult($options['start']);
}
}
$results = $query->execute()->fetchAll();
if (!empty($options['paginated'])) {
// Get a total count along with results
$query->resetQueryParts(['select', 'orderBy', 'join'])
->setFirstResult(null)
->setMaxResults(null)
->select('COUNT(*)');
if (
(isset($options['utm_source']) && !empty($options['utm_source']))
|| (isset($options['campaignId']) && !empty($options['campaignId']))
) {
$query->leftJoin(
'c',
MAUTIC_TABLE_PREFIX.'contactclient_stats',
's',
'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'
);
}
$counter = $query->execute();
$total = $counter->fetchColumn();
return [
'total' => $total,
'results' => $results,
];
}
return $results;
} | [
"public",
"function",
"getEventsForTimeline",
"(",
"$",
"contactClientId",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
"->",
"from",
"(",
"MAUTIC_TABLE_PREFIX",
".",
"'contactclient_events'",
",",
"'c'",
")",
";",
"$",
"query",
"->",
"select",
"(",
"'c.*, s.utm_source'",
")",
";",
"$",
"query",
"->",
"leftJoin",
"(",
"'c'",
",",
"MAUTIC_TABLE_PREFIX",
".",
"'contactclient_stats'",
",",
"'s'",
",",
"'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'",
")",
";",
"$",
"query",
"->",
"where",
"(",
"'c.contactclient_id = :contactClientId'",
")",
"->",
"setParameter",
"(",
"'contactClientId'",
",",
"$",
"contactClientId",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'message'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'c.message LIKE :message'",
")",
"->",
"setParameter",
"(",
"'message'",
",",
"'%'",
".",
"trim",
"(",
"$",
"options",
"[",
"'message'",
"]",
")",
".",
"'%'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'contact_id'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'contact_id'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'c.contact_id = :contact'",
")",
"->",
"setParameter",
"(",
"'contact'",
",",
"trim",
"(",
"$",
"options",
"[",
"'contact_id'",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'c.type = :type'",
")",
"->",
"setParameter",
"(",
"'type'",
",",
"trim",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'utm_source'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'utm_source'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'s.utm_source = :utm'",
")",
"->",
"setParameter",
"(",
"'utm'",
",",
"trim",
"(",
"$",
"options",
"[",
"'utm_source'",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dateFrom'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'c.date_added >= FROM_UNIXTIME(:dateFrom)'",
")",
"->",
"setParameter",
"(",
"'dateFrom'",
",",
"$",
"options",
"[",
"'dateFrom'",
"]",
"->",
"getTimestamp",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dateTo'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'c.date_added < FROM_UNIXTIME(:dateTo)'",
")",
"->",
"setParameter",
"(",
"'dateTo'",
",",
"$",
"options",
"[",
"'dateTo'",
"]",
"->",
"getTimestamp",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'campaignId'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'campaignId'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"'s.campaign_id = :campaignId'",
")",
"->",
"setParameter",
"(",
"'campaignId'",
",",
"$",
"options",
"[",
"'campaignId'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'order'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"options",
"[",
"'order'",
"]",
")",
"&&",
"2",
"==",
"count",
"(",
"$",
"options",
"[",
"'order'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"orderBy",
",",
"$",
"orderByDir",
")",
"=",
"array_values",
"(",
"$",
"options",
"[",
"'order'",
"]",
")",
";",
"if",
"(",
"$",
"orderBy",
"&&",
"$",
"orderByDir",
")",
"{",
"if",
"(",
"'utm_source'",
"!==",
"$",
"orderBy",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"'c.'",
".",
"$",
"orderBy",
",",
"$",
"orderByDir",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"'s.'",
".",
"$",
"orderBy",
",",
"$",
"orderByDir",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"setMaxResults",
"(",
"$",
"options",
"[",
"'limit'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'start'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"setFirstResult",
"(",
"$",
"options",
"[",
"'start'",
"]",
")",
";",
"}",
"}",
"$",
"results",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'paginated'",
"]",
")",
")",
"{",
"// Get a total count along with results",
"$",
"query",
"->",
"resetQueryParts",
"(",
"[",
"'select'",
",",
"'orderBy'",
",",
"'join'",
"]",
")",
"->",
"setFirstResult",
"(",
"null",
")",
"->",
"setMaxResults",
"(",
"null",
")",
"->",
"select",
"(",
"'COUNT(*)'",
")",
";",
"if",
"(",
"(",
"isset",
"(",
"$",
"options",
"[",
"'utm_source'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'utm_source'",
"]",
")",
")",
"||",
"(",
"isset",
"(",
"$",
"options",
"[",
"'campaignId'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"options",
"[",
"'campaignId'",
"]",
")",
")",
")",
"{",
"$",
"query",
"->",
"leftJoin",
"(",
"'c'",
",",
"MAUTIC_TABLE_PREFIX",
".",
"'contactclient_stats'",
",",
"'s'",
",",
"'c.contact_id = s.contact_id AND c.contactclient_id = s.contactclient_id'",
")",
";",
"}",
"$",
"counter",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"total",
"=",
"$",
"counter",
"->",
"fetchColumn",
"(",
")",
";",
"return",
"[",
"'total'",
"=>",
"$",
"total",
",",
"'results'",
"=>",
"$",
"results",
",",
"]",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | @param $contactClientId
@param array $options
@param bool $countOnly
@return array | [
"@param",
"$contactClientId",
"@param",
"array",
"$options",
"@param",
"bool",
"$countOnly"
] | train | https://github.com/TheDMSGroup/mautic-contact-client/blob/5874413494d1c73bc18749c0e75c87e7ccc6d65a/Entity/EventRepository.php#L88-L196 |
funkjedi/composer-include-files | src/Composer/AutoloadGenerator.php | AutoloadGenerator.dumpFiles | public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer', $suffix = '', $staticPhpVersion = 70000)
{
$installationManager = $composer->getInstallationManager();
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$mainPackage = $composer->getPackage();
$config = $composer->getConfig();
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
// Do not remove double realpath() calls.
// Fixes failing Windows realpath() implementation.
// See https://bugs.php.net/bug.php?id=72738
$basePath = $filesystem->normalizePath(realpath(realpath(getcwd())));
$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
$targetDir = $vendorPath.'/'.$targetDir;
$filesystem->ensureDirectoryExists($targetDir);
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
// Collect information from all packages.
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
$autoloads = $this->parseAutoloads($packageMap, $mainPackage);
if (!$suffix) {
if (!$config->get('autoloader-suffix') && is_readable($vendorPath.'/autoload.php')) {
$content = file_get_contents($vendorPath.'/autoload.php');
if (preg_match('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
$suffix = $match[1];
}
}
if (!$suffix) {
$suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
}
}
$paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage);
$autoloads['files'] = array_merge($paths, $autoloads['files']);
$includeFilesFilePath = $targetDir.'/autoload_files.php';
if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
file_put_contents($includeFilesFilePath, $includeFilesFileContents);
} elseif (file_exists($includeFilesFilePath)) {
unlink($includeFilesFilePath);
}
file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion));
} | php | public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer', $suffix = '', $staticPhpVersion = 70000)
{
$installationManager = $composer->getInstallationManager();
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$mainPackage = $composer->getPackage();
$config = $composer->getConfig();
$filesystem = new Filesystem();
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
// Do not remove double realpath() calls.
// Fixes failing Windows realpath() implementation.
// See https://bugs.php.net/bug.php?id=72738
$basePath = $filesystem->normalizePath(realpath(realpath(getcwd())));
$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
$targetDir = $vendorPath.'/'.$targetDir;
$filesystem->ensureDirectoryExists($targetDir);
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
// Collect information from all packages.
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
$autoloads = $this->parseAutoloads($packageMap, $mainPackage);
if (!$suffix) {
if (!$config->get('autoloader-suffix') && is_readable($vendorPath.'/autoload.php')) {
$content = file_get_contents($vendorPath.'/autoload.php');
if (preg_match('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
$suffix = $match[1];
}
}
if (!$suffix) {
$suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
}
}
$paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage);
$autoloads['files'] = array_merge($paths, $autoloads['files']);
$includeFilesFilePath = $targetDir.'/autoload_files.php';
if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
file_put_contents($includeFilesFilePath, $includeFilesFileContents);
} elseif (file_exists($includeFilesFilePath)) {
unlink($includeFilesFilePath);
}
file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion));
} | [
"public",
"function",
"dumpFiles",
"(",
"Composer",
"$",
"composer",
",",
"$",
"paths",
",",
"$",
"targetDir",
"=",
"'composer'",
",",
"$",
"suffix",
"=",
"''",
",",
"$",
"staticPhpVersion",
"=",
"70000",
")",
"{",
"$",
"installationManager",
"=",
"$",
"composer",
"->",
"getInstallationManager",
"(",
")",
";",
"$",
"localRepo",
"=",
"$",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
";",
"$",
"mainPackage",
"=",
"$",
"composer",
"->",
"getPackage",
"(",
")",
";",
"$",
"config",
"=",
"$",
"composer",
"->",
"getConfig",
"(",
")",
";",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"filesystem",
"->",
"ensureDirectoryExists",
"(",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
";",
"// Do not remove double realpath() calls.",
"// Fixes failing Windows realpath() implementation.",
"// See https://bugs.php.net/bug.php?id=72738",
"$",
"basePath",
"=",
"$",
"filesystem",
"->",
"normalizePath",
"(",
"realpath",
"(",
"realpath",
"(",
"getcwd",
"(",
")",
")",
")",
")",
";",
"$",
"vendorPath",
"=",
"$",
"filesystem",
"->",
"normalizePath",
"(",
"realpath",
"(",
"realpath",
"(",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
")",
")",
";",
"$",
"targetDir",
"=",
"$",
"vendorPath",
".",
"'/'",
".",
"$",
"targetDir",
";",
"$",
"filesystem",
"->",
"ensureDirectoryExists",
"(",
"$",
"targetDir",
")",
";",
"$",
"vendorPathCode",
"=",
"$",
"filesystem",
"->",
"findShortestPathCode",
"(",
"realpath",
"(",
"$",
"targetDir",
")",
",",
"$",
"vendorPath",
",",
"true",
")",
";",
"$",
"vendorPathCode52",
"=",
"str_replace",
"(",
"'__DIR__'",
",",
"'dirname(__FILE__)'",
",",
"$",
"vendorPathCode",
")",
";",
"$",
"vendorPathToTargetDirCode",
"=",
"$",
"filesystem",
"->",
"findShortestPathCode",
"(",
"$",
"vendorPath",
",",
"realpath",
"(",
"$",
"targetDir",
")",
",",
"true",
")",
";",
"$",
"appBaseDirCode",
"=",
"$",
"filesystem",
"->",
"findShortestPathCode",
"(",
"$",
"vendorPath",
",",
"$",
"basePath",
",",
"true",
")",
";",
"$",
"appBaseDirCode",
"=",
"str_replace",
"(",
"'__DIR__'",
",",
"'$vendorDir'",
",",
"$",
"appBaseDirCode",
")",
";",
"// Collect information from all packages.",
"$",
"packageMap",
"=",
"$",
"this",
"->",
"buildPackageMap",
"(",
"$",
"installationManager",
",",
"$",
"mainPackage",
",",
"$",
"localRepo",
"->",
"getCanonicalPackages",
"(",
")",
")",
";",
"$",
"autoloads",
"=",
"$",
"this",
"->",
"parseAutoloads",
"(",
"$",
"packageMap",
",",
"$",
"mainPackage",
")",
";",
"if",
"(",
"!",
"$",
"suffix",
")",
"{",
"if",
"(",
"!",
"$",
"config",
"->",
"get",
"(",
"'autoloader-suffix'",
")",
"&&",
"is_readable",
"(",
"$",
"vendorPath",
".",
"'/autoload.php'",
")",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"vendorPath",
".",
"'/autoload.php'",
")",
";",
"if",
"(",
"preg_match",
"(",
"'{ComposerAutoloaderInit([^:\\s]+)::}'",
",",
"$",
"content",
",",
"$",
"match",
")",
")",
"{",
"$",
"suffix",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"suffix",
")",
"{",
"$",
"suffix",
"=",
"$",
"config",
"->",
"get",
"(",
"'autoloader-suffix'",
")",
"?",
":",
"md5",
"(",
"uniqid",
"(",
"''",
",",
"true",
")",
")",
";",
"}",
"}",
"$",
"paths",
"=",
"$",
"this",
"->",
"parseAutoloadsTypeFiles",
"(",
"$",
"paths",
",",
"$",
"mainPackage",
")",
";",
"$",
"autoloads",
"[",
"'files'",
"]",
"=",
"array_merge",
"(",
"$",
"paths",
",",
"$",
"autoloads",
"[",
"'files'",
"]",
")",
";",
"$",
"includeFilesFilePath",
"=",
"$",
"targetDir",
".",
"'/autoload_files.php'",
";",
"if",
"(",
"$",
"includeFilesFileContents",
"=",
"$",
"this",
"->",
"getIncludeFilesFile",
"(",
"$",
"autoloads",
"[",
"'files'",
"]",
",",
"$",
"filesystem",
",",
"$",
"basePath",
",",
"$",
"vendorPath",
",",
"$",
"vendorPathCode52",
",",
"$",
"appBaseDirCode",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"includeFilesFilePath",
",",
"$",
"includeFilesFileContents",
")",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"includeFilesFilePath",
")",
")",
"{",
"unlink",
"(",
"$",
"includeFilesFilePath",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"targetDir",
".",
"'/autoload_static.php'",
",",
"$",
"this",
"->",
"getStaticFile",
"(",
"$",
"suffix",
",",
"$",
"targetDir",
",",
"$",
"vendorPath",
",",
"$",
"basePath",
",",
"$",
"staticPhpVersion",
")",
")",
";",
"}"
] | @param \Composer\Composer
@param string
@param string
@see https://github.com/composer/composer/blob/master/src/Composer/Autoload/AutoloadGenerator.php#L115 | [
"@param",
"\\",
"Composer",
"\\",
"Composer",
"@param",
"string",
"@param",
"string"
] | train | https://github.com/funkjedi/composer-include-files/blob/17d155db42578496559769bfa1c05ed790b8e34c/src/Composer/AutoloadGenerator.php#L45-L96 |
funkjedi/composer-include-files | src/Plugin.php | Plugin.activate | public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->generator = new AutoloadGenerator($composer->getEventDispatcher(), $io);
} | php | public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->generator = new AutoloadGenerator($composer->getEventDispatcher(), $io);
} | [
"public",
"function",
"activate",
"(",
"Composer",
"$",
"composer",
",",
"IOInterface",
"$",
"io",
")",
"{",
"$",
"this",
"->",
"composer",
"=",
"$",
"composer",
";",
"$",
"this",
"->",
"generator",
"=",
"new",
"AutoloadGenerator",
"(",
"$",
"composer",
"->",
"getEventDispatcher",
"(",
")",
",",
"$",
"io",
")",
";",
"}"
] | Apply plugin modifications to Composer
@param Composer $composer
@param IOInterface $io | [
"Apply",
"plugin",
"modifications",
"to",
"Composer"
] | train | https://github.com/funkjedi/composer-include-files/blob/17d155db42578496559769bfa1c05ed790b8e34c/src/Plugin.php#L30-L34 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.