本文整理汇总了PHP中Render::renderHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP Render::renderHTML方法的具体用法?PHP Render::renderHTML怎么用?PHP Render::renderHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Render
的用法示例。
在下文中一共展示了Render::renderHTML方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processAction
/**
* Process the page when its submitted
*
* @author kuma, salvipascual
* @version 1.0
* */
public function processAction()
{
// get the values from the post
$captcha = trim($this->request->getPost('captcha'));
$name = trim($this->request->getPost('name'));
$inviter = trim($this->request->getPost('email'));
$guest = trim($this->request->getPost('guest'));
if (!isset($_SESSION['phrase'])) {
$_SESSION['phrase'] = uniqid();
}
// throw a die()
// check all values passed are valid
if (strtoupper($captcha) != strtoupper($_SESSION['phrase']) || $name == "" || !filter_var($inviter, FILTER_VALIDATE_EMAIL) || !filter_var($guest, FILTER_VALIDATE_EMAIL)) {
die("Error procesando, por favor valla atras y comience nuevamente.");
}
// params for the response
$this->view->name = $name;
$this->view->email = $inviter;
// create classes needed
$connection = new Connection();
$email = new Email();
$utils = new Utils();
$render = new Render();
// do not invite people who are already using Apretaste
if ($utils->personExist($guest)) {
$this->view->already = true;
return $this->dispatcher->forward(array("controller" => "invitar", "action" => "index"));
}
// send notification to the inviter
$response = new Response();
$response->setResponseSubject("Gracias por darle internet a un Cubano");
$response->setEmailLayout("email_simple.tpl");
$response->createFromTemplate("invitationThankYou.tpl", array('num_notifications' => 0));
$response->internal = true;
$html = $render->renderHTML(new Service(), $response);
$email->sendEmail($inviter, $response->subject, $html);
// send invitations to the guest
$response = new Response();
$response->setResponseSubject("{$name} le ha invitado a revisar internet desde su email");
$responseContent = array("host" => $name, "guest" => $guest, 'num_notifications' => 0);
$response->createFromTemplate("invitation.tpl", $responseContent);
$response->internal = true;
$html = $render->renderHTML(new Service(), $response);
$email->sendEmail($guest, $response->subject, $html);
// save all the invitations into the database at the same time
$connection->deepQuery("INSERT INTO invitations (email_inviter,email_invited,source) VALUES ('{$inviter}','{$guest}','abroad')");
// redirect to the invite page
$this->view->message = true;
return $this->dispatcher->forward(array("controller" => "invitar", "action" => "index"));
}
示例2: mainAction
public function mainAction()
{
// inicialize supporting classes
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = false;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
// get valid people
$people = $connection->deepQuery("\n\t\t\tSELECT email, username, first_name, last_access\n\t\t\tFROM person\n\t\t\tWHERE active=1\n\t\t\tAND email not in (SELECT DISTINCT email FROM delivery_dropped)\n\t\t\tAND DATE(last_access) > DATE('2016-05-01')\n\t\t\tAND email like '%.cu'\n\t\t\tAND email not like '%@mms.cubacel.cu'");
// send the remarketing
$log = "";
foreach ($people as $person) {
// get the email address
$newEmail = "apretaste+{$person->username}@gmail.com";
// create the variabels to pass to the template
$content = array("newemail" => $newEmail, "name" => $person->first_name);
// create html response
$response->setEmailLayout("email_simple.tpl");
$response->createFromTemplate('newEmail.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send the email
$email->sendEmail($person->email, "Sorteando las dificultades, un email lleno de alegria", $html);
$log .= $person->email . "\n";
}
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/newemail.log");
$logger->log($log);
$logger->close();
}
示例3: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// people who were invited but never used Apretaste
$invitedPeople = $connection->deepQuery("\n\t\t\tSELECT invitation_time, email_inviter, email_invited\n\t\t\tFROM invitations \n\t\t\tWHERE used=0 \n\t\t\tAND DATEDIFF(CURRENT_DATE, invitation_time) > 15 \n\t\t\tAND email_invited NOT IN (SELECT DISTINCT email from delivery_dropped)\n\t\t\tAND email_invited NOT IN (SELECT DISTINCT email from remarketing)\n\t\t\tORDER BY invitation_time DESC\n\t\t\tLIMIT 450");
// send the first remarketing
$log .= "\nINVITATIONS (" . count($invitedPeople) . ")\n";
foreach ($invitedPeople as $person) {
// check number of days since the invitation was sent
$datediff = time() - strtotime($person->invitation_time);
$daysSinceInvitation = floor($datediff / (60 * 60 * 24));
// validate old invitations to avoid bounces
if ($daysSinceInvitation > 60) {
// re-validate the email
$res = $utils->deepValidateEmail($person->email_invited);
// if response not ok or temporal, delete from invitations list
if ($res[0] != "ok" && $res[0] != "temporal") {
$connection->deepQuery("DELETE FROM invitations WHERE email_invited = '{$person->email_invited}'");
$log .= "\t --skiping {$person->email_invited}\n";
continue;
}
}
// send data to the template
$content = array("date" => $person->invitation_time, "inviter" => $person->email_inviter, "invited" => $person->email_invited, "expires" => strtotime('next month'));
// create html response
$response->createFromTemplate('pendinginvitation.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send the invitation email
$subject = "Su amigo {$person->email_inviter} esta esperando por usted!";
$email->sendEmail($person->email_invited, $subject, $html);
// insert into remarketing table
$connection->deepQuery("INSERT INTO remarketing(email, type) VALUES ('{$person->email_invited}', 'INVITE')");
// display notifications
$log .= "\t{$person->email_invited}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/remarketing_invitation.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='invitation'");
}
示例4: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// people in the list to be automatically invited
$people = $connection->deepQuery("\n\t\t\tSELECT * FROM autoinvitations\n\t\t\tWHERE email NOT IN (SELECT email FROM person)\n\t\t\tAND email NOT IN (SELECT DISTINCT email FROM delivery_dropped)\n\t\t\tAND email NOT IN (SELECT DISTINCT email from remarketing)\n\t\t\tAND error=0\n\t\t\tLIMIT 450");
// send the first remarketing
$log .= "\nAUTOMATIC INVITATIONS (" . count($people) . ")\n";
foreach ($people as $person) {
// if response not ok, check the email as error
$res = $utils->deepValidateEmail($person->email);
if ($res[0] != "ok") {
$connection->deepQuery("UPDATE autoinvitations SET error=1, processed=CURRENT_TIMESTAMP WHERE email='{$person->email}'");
$log .= "\t --skiping {$person->email}\n";
continue;
}
// create html response
$content = array("email" => $person->email);
$response->createFromTemplate('autoinvitation.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send invitation email
$subject = "Dos problemas, y una solucion";
$email->sendEmail($person->email, $subject, $html);
// mark as sent
$connection->deepQuery("\n\t\t\t\tSTART TRANSACTION;\n\t\t\t\tDELETE FROM autoinvitations WHERE email='{$person->email}';\n\t\t\t\tINSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'AUTOINVITE');\n\t\t\t\tCOMMIT;");
// display notifications
$log .= "\t{$person->email}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/remarketing_autoinvitation.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='autoinvitation'");
}
示例5: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// get people who did not finish a survey for the last 3 days
$surveys = $connection->deepQuery("\n\t\t\tSELECT A.*, B.title, B.deadline, B.value FROM \n\t\t\t(\n\t\t\t\tSELECT email, survey, \n\t\t\t\tDATEDIFF(CURRENT_DATE, MAX(date_choosen)) as days_since,\n\t\t\t\t(\n\t\t\t\t\tSELECT COUNT(*) \n\t\t\t\t\tFROM _survey_question \n\t\t\t\t\tWHERE _survey_question.survey = _survey_answer_choosen.survey\n\t\t\t\t) as total, \n\t\t\t\tCOUNT(question) as choosen from _survey_answer_choosen GROUP BY email, survey\n\t\t\t) A\n\t\t\tJOIN _survey B\n\t\t\tON A.survey = B.id\n\t\t\tWHERE A.total > A.choosen \n\t\t\tAND A.days_since >= 7\n\t\t\tAND B.active = 1\n\t\t\tAND DATEDIFF(B.deadline, B.date_created) > 0\n\t\t\tAND A.email NOT IN (SELECT DISTINCT email FROM remarketing WHERE type='SURVEY')");
// send emails to users
$log .= "\nSURVEY REMARKETING (" . count($surveys) . ")\n";
foreach ($surveys as $survey) {
$content = array("survey" => $survey->survey, "days" => $survey->days_since, "missing" => $survey->total - $survey->choosen, "title" => $survey->title, "deadline" => $survey->deadline, "value" => $survey->value);
// create html response
$response->setResponseSubject("No queremos que pierda \${$survey->value}");
$response->createFromTemplate('surveyReminder.tpl', $content);
$response->internal = true;
// send email to the person
$html = $render->renderHTML($service, $response);
$email->sendEmail($survey->email, $response->subject, $html);
// add entry to remarketing
$connection->deepQuery("INSERT INTO remarketing(email, type) VALUES ('{$survey->email}', 'SURVEY');");
// display notifications
$log .= "\t{$survey->email} | surveyID: {$survey->survey} \n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/surveyreminder.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='survey'");
}
示例6: recoverAction
/**
* Recovers a pin and create a pin for users with blank pins
*
* @author salvipascual
* @param GET email
* @return JSON
* */
public function recoverAction()
{
$email = trim($this->request->get('email'));
$utils = new Utils();
$connection = new Connection();
// check if the email exist
if (!$utils->personExist($email)) {
die('{"code":"error","message":"invalid user"}');
}
// get pin from the user
$pin = $connection->deepQuery("SELECT pin FROM person WHERE email='{$email}'");
$pin = $pin[0]->pin;
// if pin is blank, create it
if (empty($pin)) {
$pin = mt_rand(1000, 9999);
$connection->deepQuery("UPDATE person SET pin='{$pin}' WHERE email='{$email}'");
}
// create response to email the new code
$subject = "Su codigo de Apretaste";
$response = new Response();
$response->setEmailLayout("email_simple.tpl");
$response->setResponseSubject($subject);
$response->createFromTemplate("pinrecover.tpl", array("pin" => $pin));
$response->internal = true;
// render the template as html
$render = new Render();
$body = $render->renderHTML(new Service(), $response);
// email the code to the user
$emailSender = new Email();
$emailSender->sendEmail($email, $subject, $body);
// return ok response
die('{"code":"ok"}');
}
示例7: renderResponse
//.........这里部分代码省略.........
foreach ($responses as $rs) {
$rs->email = empty($rs->email) ? $email : $rs->email;
// check if is first request of the day
$requestsToday = $utils->getTotalRequestsTodayOf($rs->email);
$stars = 0;
if ($requestsToday == 0) {
// run the tickets's game
// @note: este chequeo se hace despues de verificar si es el primer
// correo del dia, para no preguntar chequear mas veces
// innecesariamente en el resto del dia
$stars = $utils->getRaffleStarsOf($rs->email, false);
if ($stars === 4) {
// insert 10 tickets for user
$sqlValues = "('{$email}', 'GAME')";
$sql = "INSERT INTO ticket(email, origin) VALUES " . str_repeat($sqlValues . ",", 9) . "{$sqlValues};";
$connection->deepQuery($sql);
// add notification to user
$utils->addNotification($rs->email, "GAME", "Haz ganado 10 tickets para Rifa por utilizar Apretaste durante 5 días seguidos", "RIFA", "IMPORTANT");
}
$stars++;
}
$rs->subject = empty($rs->subject) ? "Respuesta del servicio {$serviceName}" : $rs->subject;
$rs->content['num_notifications'] = $utils->getNumberOfNotifications($rs->email);
$rs->content['raffle_stars'] = $stars;
$rs->content['requests_today'] = $requestsToday;
}
// create a new render
$render = new Render();
// render the template and echo on the screen
if ($format == "html") {
$html = "";
for ($i = 0; $i < count($responses); $i++) {
$html .= "<br/><center><small><b>To:</b> " . $responses[$i]->email . ". <b>Subject:</b> " . $responses[$i]->subject . "</small></center><br/>";
$html .= $render->renderHTML($userService, $responses[$i]);
if ($i < count($responses) - 1) {
$html .= "<br/><hr/><br/>";
}
}
$usage = nl2br(str_replace('{APRETASTE_EMAIL}', $utils->getValidEmailAddress(), $serviceUsageText));
$html .= "<br/><hr><center><p><b>XML DEBUG</b></p><small>";
$html .= "<p><b>Owner: </b>{$serviceCreatorEmail}</p>";
$html .= "<p><b>Category: </b>{$serviceCategory}</p>";
$html .= "<p><b>Description: </b>{$serviceDescription}</p>";
$html .= "<p><b>Usage: </b><br/>{$usage}</p></small></center>";
return $html;
}
// echo the json on the screen
if ($format == "json") {
return $render->renderJSON($response);
}
// render the template email it to the user
// only save stadistics for email requests
if ($format == "email") {
// get the person, false if the person does not exist
$person = $utils->getPerson($email);
// if the person exist in Apretaste
if ($person !== false) {
// update last access time to current and make person active
$connection->deepQuery("UPDATE person SET active=1, last_access=CURRENT_TIMESTAMP WHERE email='{$email}'");
} else {
$inviteSource = 'alone';
// alone if the user came by himself, no invitation
$sql = "START TRANSACTION;";
// start the long query
// check if the person was invited to Apretaste
$invites = $connection->deepQuery("SELECT * FROM invitations WHERE email_invited='{$email}' AND used=0 ORDER BY invitation_time DESC");
示例8: renderResponse
/**
* Respond to a request based on the parameters passed
* @author salvipascual
* */
private function renderResponse($email, $subject, $sender = "", $body = "", $attachments = array(), $format = "html")
{
// get the name of the service based on the subject line
$subjectPieces = explode(" ", $subject);
$serviceName = strtolower($subjectPieces[0]);
unset($subjectPieces[0]);
// get path to the service
$utils = new Utils();
$servicePath = $utils->getPathToService($serviceName);
// check the service requested exists in the services folder
if (!$servicePath) {
return "<p>No service \"{$serviceName}\" was found</p>";
}
// include the service code
include_once "{$servicePath}/service.php";
// check if a subservice is been invoked
$subServiceName = "";
if (isset($subjectPieces[1])) {
$serviceClassMethods = get_class_methods($serviceName);
if (@preg_grep("/^_{$subjectPieces[1]}\$/i", $serviceClassMethods)) {
$subServiceName = strtolower($subjectPieces[1]);
unset($subjectPieces[1]);
}
}
// get the service query
$query = implode(" ", $subjectPieces);
// create a new Request object
$request = new Request();
$request->email = $email;
$request->name = $sender;
$request->subject = $subject;
$request->body = $body;
$request->attachments = $attachments;
$request->service = $serviceName;
$request->subservice = trim($subServiceName);
$request->query = trim($query);
// get details of the service from the XML file
$xml = simplexml_load_file("{$servicePath}/config.xml");
$serviceCreatorEmail = trim((string) $xml->creatorEmail);
$serviceDescription = trim((string) $xml->serviceDescription);
$serviceCategory = trim((string) $xml->serviceCategory);
$serviceUsageText = trim((string) $xml->serviceUsage);
$serviceInsertionDate = date("Y/m/d H:m:s");
// check if the email is valid
if (!filter_var($serviceCreatorEmail, FILTER_VALIDATE_EMAIL)) {
die("Invalid email {$serviceCreatorEmail}");
}
// check if the category is valid
$categories = array('negocios', 'ocio', 'academico', 'social', 'comunicaciones', 'informativo', 'adulto', 'otros');
if (!in_array($serviceCategory, $categories)) {
die("Invalid category {$serviceCategory}");
}
// create a new service Object of the user type
$userService = new $serviceName();
$userService->serviceName = $serviceName;
$userService->serviceDescription = $serviceDescription;
$userService->creatorEmail = $serviceCreatorEmail;
$userService->serviceCategory = $serviceCategory;
$userService->serviceUsage = $serviceUsageText;
$userService->insertionDate = $serviceInsertionDate;
$userService->pathToService = $servicePath;
$userService->utils = $utils;
// run the service and get a response
if (empty($subServiceName)) {
$response = $userService->_main($request);
} else {
$subserviceFunction = "_{$subServiceName}";
$response = $userService->{$subserviceFunction}($request);
}
// a service can return an array of Response or only one.
// we always treat the response as an array
$responses = is_array($response) ? $response : array($response);
// clean the empty fields in the response
foreach ($responses as $rs) {
$rs->email = empty($rs->email) ? $email : $rs->email;
$rs->subject = empty($rs->subject) ? "Respuesta del servicio {$serviceName}" : $rs->subject;
}
// create a new render
$render = new Render();
// render the template and echo on the screen
if ($format == "html") {
$html = "";
for ($i = 0; $i < count($responses); $i++) {
$html .= "<br/><center><small><b>Subject:</b> " . $responses[$i]->subject . "</small></center><br/>";
$html .= $render->renderHTML($userService, $responses[$i]);
if ($i < count($responses) - 1) {
$html .= "<br/><hr/><br/>";
}
}
$usage = nl2br(str_replace('{APRETASTE_EMAIL}', $utils->getValidEmailAddress(), $serviceUsageText));
$html .= "<br/><hr><center><p><b>XML DEBUG</b></p><small>";
$html .= "<p><b>Owner: </b>{$serviceCreatorEmail}</p>";
$html .= "<p><b>Category: </b>{$serviceCategory}</p>";
$html .= "<p><b>Description: </b>{$serviceDescription}</p>";
$html .= "<p><b>Usage: </b><br/>{$usage}</p></small></center>";
return $html;
//.........这里部分代码省略.........
示例9: renderResponse
/**
* Respond to a request based on the parameters passed
* @author salvipascual
* */
private function renderResponse($email, $subject, $sender = "", $body = "", $attachments = array(), $format = "html")
{
// get the time when the service started executing
$execStartTime = date("Y-m-d H:i:s");
// get the name of the service based on the subject line
$subjectPieces = explode(" ", $subject);
$serviceName = strtolower($subjectPieces[0]);
unset($subjectPieces[0]);
// check the service requested actually exists
$utils = new Utils();
if (!$utils->serviceExist($serviceName)) {
$serviceName = "ayuda";
}
// include the service code
$wwwroot = $this->di->get('path')['root'];
include "{$wwwroot}/services/{$serviceName}/service.php";
// check if a subservice is been invoked
$subServiceName = "";
if (isset($subjectPieces[1])) {
$serviceClassMethods = get_class_methods($serviceName);
if (preg_grep("/^_{$subjectPieces[1]}\$/i", $serviceClassMethods)) {
$subServiceName = strtolower($subjectPieces[1]);
unset($subjectPieces[1]);
}
}
// get the service query
$query = implode(" ", $subjectPieces);
// create a new Request object
$request = new Request();
$request->email = $email;
$request->name = $sender;
$request->subject = $subject;
$request->body = $body;
$request->attachments = $attachments;
$request->service = $serviceName;
$request->subservice = trim($subServiceName);
$request->query = trim($query);
// get details of the service from the database
$connection = new Connection();
$sql = "SELECT * FROM service WHERE name = '{$serviceName}'";
$result = $connection->deepQuery($sql);
// create a new service Object of the user type
$userService = new $serviceName();
$userService->serviceName = $serviceName;
$userService->serviceDescription = $result[0]->description;
$userService->creatorEmail = $result[0]->creator_email;
$userService->serviceCategory = $result[0]->category;
$userService->serviceUsage = $result[0]->usage_text;
$userService->insertionDate = $result[0]->insertion_date;
$userService->pathToService = $utils->getPathToService($serviceName);
$userService->utils = $utils;
// run the service and get a response
if (empty($subServiceName)) {
$response = $userService->_main($request);
} else {
$subserviceFunction = "_{$subServiceName}";
$response = $userService->{$subserviceFunction}($request);
}
// a service can return an array of Response or only one.
// we always treat the response as an array
$responses = is_array($response) ? $response : array($response);
// clean the empty fields in the response
foreach ($responses as $rs) {
$rs->email = empty($rs->email) ? $email : $rs->email;
$rs->subject = empty($rs->subject) ? "Respuesta del servicio {$serviceName}" : $rs->subject;
}
// create a new render
$render = new Render();
// render the template and echo on the screen
if ($format == "html") {
$html = "";
for ($i = 0; $i < count($responses); $i++) {
$html .= "<br/><center><small><b>To:</b> " . $responses[$i]->email . ". <b>Subject:</b> " . $responses[$i]->subject . "</small></center><br/>";
$html .= $render->renderHTML($userService, $responses[$i]);
if ($i < count($responses) - 1) {
$html .= "<br/><hr/><br/>";
}
}
return $html;
}
// echo the json on the screen
if ($format == "json") {
return $render->renderJSON($response);
}
// render the template email it to the user
// only save stadistics for email requests
if ($format == "email") {
$emailSender = new Email();
// get params for the email and send the response emails
foreach ($responses as $rs) {
if ($rs->render) {
$emailTo = $rs->email;
$subject = $rs->subject;
$images = array_merge($rs->images, $rs->getAds());
$attachments = $rs->attachments;
$body = $render->renderHTML($userService, $rs);
//.........这里部分代码省略.........
示例10: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
// list and total of services
$services = $connection->deepQuery("SELECT name, description FROM service WHERE name <> 'ayuda' AND name <> 'terminos' AND name <> 'excluyeme' AND listed = 1;");
$arr = array();
foreach ($services as $servicex) {
$arr[$servicex->name] = $servicex;
}
$services = $arr;
$total_services = count($services);
// users by service
$sql_users_by_service = "SELECT requestor, service FROM utilization WHERE service <> 'rememberme' GROUP BY requestor, service";
// usage of services
$sql_usage = "SELECT requestor, count(service) as part, {$total_services} as total FROM ({$sql_users_by_service}) subq1 GROUP BY requestor, total";
// filtering by less usage
$sql_less_usage = "SELECT requestor as email, (SELECT sent FROM remarketing WHERE remarketing.email = subq2.requestor ORDER BY sent DESC LIMIT 1) as last_remarketing FROM ({$sql_usage}) subq2 WHERE part/total <= 0.2 ";
// filtering by last remarketing (one by month)
$sql = "SELECT email FROM ({$sql_less_usage}) subq3 WHERE datediff(CURRENT_DATE, last_remarketing) > 30 or datediff(CURRENT_DATE, last_remarketing) is null group by email";
$users = $connection->deepQuery("{$sql};");
// send the remarketing
$log .= "\nLESS USAGE REMARKETING (" . count($users) . ")\n";
foreach ($users as $person) {
// all services
$his_services = $services;
// getting services used by user
$services_of_user = $connection->deepQuery("SELECT service as name FROM ({$sql_users_by_service}) subq1 WHERE requestor = '{$person->email}';");
// remove services used by user from the list
foreach ($services_of_user as $servicex) {
if (isset($his_services[$servicex->name])) {
unset($his_services[$servicex->name]);
}
}
// create the variabels to pass to the template
$content = array("services" => $his_services);
// create html response
$response->createFromTemplate('lessusage.tpl', $content);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// move remarketing to the next state and add $1 to his/her account
$email->sendEmail($person->email, "Lo que te estas perdiendo en Apretaste", $html);
// move remarketing to the next state and add +1 credits
$connection->deepQuery("INSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'LESSUSAGE');");
// display notifications
$log .= "\t{$person->email}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/lessusage.log");
$logger->log($log);
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='lessusage'");
}
示例11: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$connection = new Connection();
$email = new Email();
$service = new Service();
$service->showAds = true;
$render = new Render();
$response = new Response();
$utils = new Utils();
$wwwroot = $this->di->get('path')['root'];
$log = "";
/*
* FIRST REMINDER
* */
// people missed for the last 30 days and with no remarketing emails unopened
$firstReminderPeople = $connection->deepQuery("\n\t\t\tSELECT email, last_access \n\t\t\tFROM person \n\t\t\tWHERE active=1 \n\t\t\tAND IFNULL(DATEDIFF(CURRENT_DATE, last_access),99) > 30 \n\t\t\tAND email not in (SELECT DISTINCT email FROM remarketing WHERE opened IS NULL)\n\t\t\tORDER BY insertion_date ASC\n\t\t\tLIMIT 200");
// send the remarketing
$log .= "\nFIRST REMINDER (" . count($firstReminderPeople) . ")\n";
foreach ($firstReminderPeople as $person) {
// check number of days since the email was last checked
$datediff = time() - strtotime($person->last_access);
$daysSinceLastChecked = floor($datediff / (60 * 60 * 24));
// validate old emails to avoid bounces
if ($daysSinceLastChecked > 60) {
// re-validate the email
$res = $utils->deepValidateEmail($person->email);
// keep it for later if it was temporal
if ($res[0] == "temporal") {
$log .= "\t --skiping {$person->email}\n";
continue;
}
// for other than ok, unsubscribe and do not email
if ($res[0] != "ok") {
$utils->unsubscribeFromEmailList($person->email);
$connection->deepQuery("UPDATE person SET active=0 WHERE email='{$person->email}'");
$log .= "\t --skiping {$person->email}\n";
continue;
}
}
// get services that changed since last time
$sql = "SELECT * FROM service WHERE insertion_date BETWEEN '{$person->last_access}' AND CURRENT_TIMESTAMP AND listed=1";
$services = $connection->deepQuery($sql);
// create the variabels to pass to the template
$content = array("services" => $services);
$images = array("{$wwwroot}/public/images/missyou.jpg");
// create html response
$response->createFromTemplate('remindme1.tpl', $content, $images);
$response->internal = true;
$html = $render->renderHTML($service, $response);
// move remarketing to the next state and add $1 to his/her account
$email->sendEmail($person->email, "Se le extranna por Apretaste", $html, $images);
// move remarketing to the next state and add +1 credits
$connection->deepQuery("\n\t\t\t\tSTART TRANSACTION;\n\t\t\t\tUPDATE person SET credit=credit+1 WHERE email='{$person->email}';\r\n\t\t\t\tINSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'REMINDER1');\n\t\t\t\tCOMMIT;");
// display notifications
$log .= "\t{$person->email}\n";
}
/*
* SECOND REMINDER
* */
// people with REMINDER1 unaswered for the last 30 days, and without REMINDER2 created
$secondReminderPeople = $connection->deepQuery("\n\t\t\tSELECT email\n\t\t\tFROM remarketing A\n\t\t\tWHERE type='REMINDER1'\n\t\t\tAND opened IS NULL\n\t\t\tAND DATEDIFF(CURRENT_DATE, sent) > 30\n\t\t\tAND (SELECT COUNT(email) FROM remarketing WHERE type='REMINDER2' AND opened IS NULL AND email=A.email)=0");
// send the remarketing
$log .= "SECOND REMINDER (" . count($secondReminderPeople) . ")\n";
foreach ($secondReminderPeople as $person) {
// create html response
$response->createFromTemplate('remindme2.tpl', array());
$response->internal = true;
$html = $render->renderHTML($service, $response);
// send email to the $person->email
$email->sendEmail($person->email, "Hace rato no le veo", $html);
// move remarketing to the next state and add +1 credits
$connection->deepQuery("\r\n\t\t\t\tSTART TRANSACTION;\r\n\t\t\t\tUPDATE person SET credit=credit+1 WHERE email='{$person->email}';\n\t\t\t\tINSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'REMINDER2');\r\n\t\t\t\tCOMMIT;");
// display notifications
$log .= "\t{$person->email}\n";
}
/*
* EXCLUDE
* */
// people with REMINDER2 unaswered, sent 30 days ago and not EXCLUDED
$thirdReminderPeople = $connection->deepQuery("\n\t\t\tSELECT email\n\t\t\tFROM remarketing A\n\t\t\tWHERE type='REMINDER2'\n\t\t\tAND opened IS NULL\n\t\t\tAND DATEDIFF(CURRENT_DATE, sent) > 30\n\t\t\tAND (SELECT COUNT(email) from remarketing WHERE type='EXCLUDED' AND opened IS NULL AND email=A.email)=0");
// unsubcribe people
$log .= "UNSUSCRIBING (" . count($thirdReminderPeople) . ")\n";
foreach ($thirdReminderPeople as $person) {
// unsubscribe person
$utils->unsubscribeFromEmailList($person->email);
// move remarketing to the next state and unsubscribe
$connection->deepQuery("\r\n\t\t\t\tSTART TRANSACTION;\r\n\t\t\t\tUPDATE person SET active=0 WHERE email='{$person->email}';\n\t\t\t\tINSERT INTO remarketing(email, type) VALUES ('{$person->email}', 'EXCLUDED');\r\n\t\t\t\tCOMMIT;");
// display notifications
$log .= "\t{$person->email}\n";
}
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// printing log
$log .= "EXECUTION TIME: {$timeDiff} seconds\n\n";
echo $log;
// saving the log
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/remarketing.log");
//.........这里部分代码省略.........