本文整理汇总了PHP中Connection::deepQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::deepQuery方法的具体用法?PHP Connection::deepQuery怎么用?PHP Connection::deepQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::deepQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: droppedAction
public function droppedAction()
{
// do not allow empty calls
if (empty($_POST)) {
die("EMPTY CALL");
}
// get the params from post
$email = $_POST['recipient'];
$domain = $_POST['domain'];
$reason = $_POST['reason'];
$code = isset($_POST['code']) ? $_POST['code'] : "";
$desc = isset($_POST['description']) ? str_replace("'", "", $_POST['description']) : "";
// do not save Spam as hardfail
if (stripos($desc, 'spam') !== false) {
$reason = "spam";
}
// mark as bounced if the email is part of the latest campaign
$connection = new Connection();
$campaign = $connection->deepQuery("\n\t\t\tSELECT campaign, email FROM (\n\t\t\t\tSELECT * FROM `campaign_sent`\n\t\t\t\tWHERE campaign = (SELECT id FROM campaign WHERE status='SENT' ORDER BY sending_date DESC LIMIT 1)\n\t\t\t) A WHERE email = '{$email}'");
if (count($campaign) > 0) {
// increase the bounce number for the campaign
$campaign = $campaign[0];
$connection->deepQuery("\n\t\t\t\tUPDATE campaign SET\tbounced=bounced+1 WHERE id={$campaign->campaign};\n\t\t\t\tUPDATE campaign_sent SET status='BOUNCED', date_opened=CURRENT_TIMESTAMP WHERE id={$campaign->campaign} AND email='{$email}'");
// unsubscribe from the list
$utils = new Utils();
$utils->unsubscribeFromEmailList($email);
}
// save into the database
$sql = "INSERT INTO delivery_dropped(email,sender,reason,code,description) VALUES ('{$email}','{$domain}','{$reason}','{$code}','{$desc}')";
$connection->deepQuery($sql);
// echo completion message
echo "FINISHED";
}
示例2: 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'");
}
示例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 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'");
}
示例4: payment
/**
* Function executed when a payment is finalized
* Add new tickets to the database when the user pays
*
* @author salvipascual
* */
public function payment(Payment $payment)
{
// get the number of times the loop has to iterate
$numberTickets = null;
if ($payment->code == "1TICKET") {
$numberTickets = 1;
}
if ($payment->code == "5TICKETS") {
$numberTickets = 5;
}
if ($payment->code == "10TICKETS") {
$numberTickets = 10;
}
// do not give tickets for wrong codes
if (empty($numberTickets)) {
return false;
}
// create as many tickets as necesary
$query = "INSERT INTO ticket(email,origin) VALUES ";
for ($i = 0; $i < $numberTickets; $i++) {
$query .= "('{$payment->buyer}','PURCHASE')";
$query .= $i < $numberTickets - 1 ? "," : ";";
}
// save the tickets in the database
$connection = new Connection();
$transfer = $connection->deepQuery($query);
}
示例5: _main
/**
* Function executed when the service is called
*
* @param Request
* @return Response
* */
public function _main($request)
{
// get list of services
$connection = new Connection();
$result = $connection->deepQuery("SELECT name, description, category FROM service WHERE listed=1");
$services = array();
$others = array();
// to keep the categoty "others" at the end
// create array of arrays
foreach ($result as $res) {
// to keep the categoty "others" at the end
if ($res->category == "otros") {
$others[] = $res;
continue;
}
// group all other categories in a big array
if (!isset($services[$res->category])) {
$services[$res->category] = array();
}
array_push($services[$res->category], $res);
}
// sort by category alphabetically and merge to "other"
ksort($services);
$services = array_merge($services, array("otros" => $others));
// get variables to send to the template
$responseContent = array("services" => $services, "serviceNum" => count($result));
// create response
$response = new Response();
$response->setResponseSubject("Lista de servicios de Apretaste");
$response->createFromTemplate("basic.tpl", $responseContent);
// return
return $response;
}
示例6: 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();
}
示例7: getPerson
/**
* Get a person's profile
*
* @author salvipascual
* @return Array or false
* */
public function getPerson($email)
{
// get the person
$connection = new Connection();
$person = $connection->deepQuery("SELECT * FROM person WHERE email = '{$email}'");
// return false if there is no person with that email
if (count($person) == 0) {
return false;
} else {
$person = $person[0];
}
// get number of tickets for the raffle adquired by the user
$tickets = $connection->deepQuery("SELECT count(*) as tickets FROM ticket WHERE raffle_id is NULL AND email = '{$email}'");
$tickets = $tickets[0]->tickets;
// get the person's full name
$fullName = "{$person->first_name} {$person->middle_name} {$person->last_name} {$person->mother_name}";
$fullName = trim(preg_replace("/\\s+/", " ", $fullName));
// get the image of the person
$image = NULL;
$thumbnail = NULL;
if ($person->picture) {
$di = \Phalcon\DI\FactoryDefault::getDefault();
$wwwroot = $di->get('path')['root'];
if (file_exists("{$wwwroot}/public/profile/{$email}.jpg")) {
$image = "{$wwwroot}/public/profile/{$email}.jpg";
}
if (file_exists("{$wwwroot}/public/profile/thumbnail/{$email}.jpg")) {
$thumbnail = "{$wwwroot}/public/profile/thumbnail/{$email}.jpg";
}
}
// get the interests as an array
$person->interests = preg_split('@,@', $person->interests, NULL, PREG_SPLIT_NO_EMPTY);
// remove all whitespaces at the begining and ending
foreach ($person as $key => $value) {
if (!is_array($value)) {
$person->{$key} = trim($value);
}
}
// add elements to the response
$person->full_name = $fullName;
$person->picture = $image;
$person->thumbnail = $thumbnail;
$person->raffle_tickets = $tickets;
return $person;
}
示例8: 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'");
}
示例9: mainAction
public function mainAction()
{
// inicialize supporting classes
$timeStart = time();
$utils = new Utils();
$connection = new Connection();
$sender = new Email();
// get the first campaign created that is waiting to be sent
$campaign = $connection->deepQuery("\n\t\t\tSELECT id, subject, content\n\t\t\tFROM campaign\n\t\t\tWHERE sending_date < CURRENT_TIMESTAMP\n\t\t\tAND status = 'WAITING'\n\t\t\tGROUP BY sending_date ASC\n\t\t\tLIMIT 1");
// check if there are not campaigns
if (empty($campaign)) {
return;
} else {
$campaign = $campaign[0];
}
// check campaign as SENDING
$connection->deepQuery("UPDATE campaign SET status='SENDING' WHERE id = {$campaign->id}");
// get the list of people in the list who hsa not receive this campaign yet
// so in case the campaign fails when it tries again starts from the same place
$people = $connection->deepQuery("\n\t\t\tSELECT email FROM person\n\t\t\tWHERE mail_list=1 AND active=1\n\t\t\tAND email NOT IN (SELECT email FROM campaign_sent WHERE campaign={$campaign->id})");
// show initial message
$total = count($people);
echo "\nSTARTING COUNT: {$total}\n";
// email people one by one
$counter = 1;
foreach ($people as $person) {
// show message
echo "{$counter}/{$total} - {$person->email}\n";
$counter++;
// replace the template variables
$content = $utils->campaignReplaceTemplateVariables($person->email, $campaign->content, $campaign->id);
// send test email
$sender->trackCampaign = $campaign->id;
$result = $sender->sendEmail($person->email, $campaign->subject, $content);
// add to bounced and unsubscribe if there are issues sending
$bounced = "";
$status = "SENT";
if (!$result) {
$utils->unsubscribeFromEmailList($person->email);
$bounced = "bounced=bounced+1,";
$status = "BOUNCED";
}
// save status before moving to the next email
$connection->deepQuery("\n\t\t\t\tINSERT INTO campaign_sent (email, campaign, status) VALUES ('{$person->email}', '{$campaign->id}', '{$status}');\n\t\t\t\tUPDATE campaign SET {$bounced} sent=sent+1 WHERE id='{$campaign->id}'");
}
// set the campaign as SENT
$connection->deepQuery("UPDATE campaign SET status='SENT' WHERE id='{$campaign->id}'");
// get final delay
$timeEnd = time();
$timeDiff = $timeEnd - $timeStart;
// saving the log
$wwwroot = $this->di->get('path')['root'];
$logger = new \Phalcon\Logger\Adapter\File("{$wwwroot}/logs/campaigns.log");
$logger->log("ID: {$campaign->id}, RUNTIME: {$timeDiff}, SUBJECT: {$campaign->subject}");
$logger->close();
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP, delay='{$timeDiff}' WHERE task='campaign'");
}
示例10: mainAction
/**
* Get the content from outside sources and post it in Pizarra
*
* @author kuma
* */
public function mainAction()
{
$connection = new Connection();
// create a twitter handler
$twitter = new TwitterOAuth($this->KEY, $this->KEY_SECRET, $this->TOKEN, $this->TOKEN_SECRET);
// loop all sources and get their content
foreach ($this->sources as $email => $query) {
// get the last
$listOfTweets = $twitter->get("search/tweets", array("q" => $query, "count" => 50));
// pick the newest, unpicked tweet form the list
$total = count($listOfTweets->statuses);
for ($i = 0; $i < $total; $i++) {
// get the original post
if (isset($listOfTweets->statuses[$i]->retweeted_status->text)) {
$note = $listOfTweets->statuses[$i]->retweeted_status->text;
} else {
$note = $listOfTweets->statuses[$i]->text;
}
// trim, escape and format text
$note = str_replace("'", "", $note);
$note = str_replace("@", "", $note);
$note = str_replace("“", '"', $note);
$note = str_replace("”", '"', $note);
$note = $this->removeAccents($note);
$note = substr($note, 0, 140);
// check if that nota already exist
$notescount = $connection->deepQuery("SELECT COUNT(*) as total FROM _pizarra_notes WHERE text='{$note}'");
if ($notescount[0]->total > 0) {
continue;
}
// save note into the database
$connection->deepQuery("INSERT INTO _pizarra_notes (email,text,auto) VALUES ('{$email}', '{$note}',1)");
break;
}
}
// save the status in the database
$connection->deepQuery("UPDATE task_status SET executed=CURRENT_TIMESTAMP WHERE task='pizarra'");
}
示例11: 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"));
}
示例12: getServicesRelatedArray
/**
* Get up to five services related and return an array with them
*
* @author salvipascual
* @param String $serviceName, name of the service
* @return Array
*/
private function getServicesRelatedArray($serviceName)
{
// get last 5 services inserted with the same category
$query = "SELECT name FROM service \n\t\t\tWHERE category = (SELECT category FROM service WHERE name='{$serviceName}')\n\t\t\tAND name <> '{$serviceName}'\n\t\t\tORDER BY insertion_date\n\t\t\tLIMIT 5";
$connection = new Connection();
$result = $connection->deepQuery($query);
// create returning array
$servicesRelates = array();
foreach ($result as $res) {
$servicesRelates[] = $res->name;
}
// return the array
return $servicesRelates;
}
示例13: indexAction
public function indexAction()
{
// START visitors
$connection = new Connection();
$visits = $connection->deepQuery("\n\t\t\tSELECT\n\t\t\t\tcount(*) as received, \n\t\t\t\tDATE_FORMAT(request_time,'%Y-%m') as inserted \n\t\t\tFROM utilization\n\t\t\tGROUP BY DATE_FORMAT(request_time,'%Y-%m')\n\t\t\tHAVING inserted <> DATE_FORMAT(curdate(), '%Y-%m')\n\t\t\tORDER BY inserted DESC \n\t\t\tLIMIT 5");
$visitors = array();
$visitorsPerMonth = 0;
foreach ($visits as $visit) {
if ($visit->received > $visitorsPerMonth) {
$visitorsPerMonth = $visit->received;
}
$visitors[] = ["date" => date("M Y", strtotime($visit->inserted)), "emails" => $visit->received];
}
$visitors = array_reverse($visitors);
// END visitors
$this->view->visitors = $visitors;
$this->view->visitorsPerMonth = $visitorsPerMonth;
$this->view->wwwhttp = $this->di->get('path')['http'];
$this->view->wwwroot = $this->di->get('path')['root'];
$this->view->stripePushibleKey = $this->di->get('config')['stripe']['pushible'];
$this->view->pick("index/bienvenido");
}
示例14: getMarketProductAction
public function getMarketProductAction()
{
$utils = new Utils();
$code = $this->request->getPost('code');
$code = $utils->clearStr($code, "1234567890");
$connection = new Connection();
$product = $connection->deepQuery("SELECT * FROM _tienda_products WHERE code = '{$code}';");
$wwwroot = $this->di->get('path')['root'];
if (is_array($product)) {
$product = $product[0];
$product->image = false;
if (file_exists("{$wwwroot}/public/products/{$code}")) {
$product->image = true;
}
$product->price_friendly = '$' . number_format($product->price, 2);
$product->shipping_price_friendly = '$' . number_format($product->shipping_price, 2);
$product->credits_friendly = '$' . number_format($product->credits, 2);
echo "{product:" . json_encode($product) . "}";
} else {
echo "{product: false}";
}
$this->view->disable();
}
示例15: addService
/**
* Add a new service to the filesystem, database and create the specific service tables
*
* @author salvipascual
* @author kuma
* @param Service
* @param String , the path to the location of the zip
* @param String , the path to the location of the files
* @paran Boolean , if service are updating
* */
public function addService($service, $pathToZip, $pathToService, $updating = false)
{
$utils = $this->getUtils();
// get the path
$di = \Phalcon\DI\FactoryDefault::getDefault();
$wwwroot = $di->get('path')['root'];
// create a new connection
$connection = new Connection();
// save the new service in the database
$insertUserQuery = "\n\t\t\tINSERT INTO service (name,description,usage_text,creator_email,category,listed,ads) \n\t\t\tVALUES ('{$service['serviceName']}','{$service['serviceDescription']}','{$service['serviceUsage']}','{$service['creatorEmail']}','{$service['serviceCategory']}','{$service['listed']}','{$service['showAds']}')";
$connection->deepQuery($insertUserQuery);
// clear old alias
$sqlClear = "DELETE FROM service_alias WHERE alias <> '";
$sqlClear .= implode("' AND alias <> '", $service['serviceAlias']);
$sqlClear .= "' AND service = '{$service['serviceName']}' ;";
$connection->deepQuery($sqlClear);
// insert new alias
foreach ($service['serviceAlias'] as $alias) {
$connection->deepQuery("INSERT IGNORE INTO service_alias (service, alias) VALUES ('{$service['serviceName']}','{$alias}');");
}
// clear old ads
$connection->deepQuery("DELETE FROM ads WHERE related_service = '{$service['serviceName']}';");
// create the owner of ad
$sql = "INSERT IGNORE INTO person (email, username, credit) VALUES ('soporte@apretaste.com', 'soporteap', 1000000);";
$sql .= "UPDATE person SET credit = 1000000 WHERE email = 'soporte@apretaste.com';";
$connection->deepQuery($sql);
$serviceName = strtoupper($service['serviceName']);
$serviceDesc = $connection->escape($service['serviceDescription']);
$toaddress = $utils->getValidEmailAddress();
// create an Ad for new service
$body = "<p>Hola,<br/><br/>Nos alegra decir que tenemos un servicio nuevo en Apretatse. El servicio es {$serviceName} y {$serviceDesc}. ";
$body .= "Espero que le sea de su agrado, y si quiere saber mas al respecto, el enlace a continuacion le explicará como se usa y detallará más sobre el mismo.";
$body .= '<center><a href="mailto:' . $toaddress . '?subject=AYUDA ' . $serviceName . '">Conocer más sobre este servicio</a></center>';
$body .= "<br/><br/>Gracias por usar Apretaste.<p>";
if ($updating) {
$body = "<p>Hola,<br/><br/>Tenemos una actualización al servicio {$serviceName} en Apretaste!";
$body .= "Con las actualizaciones vienen mejoras, nuevas funciones y soluciones a problemas antiguos. Espero que le sea de su agrado, y si quiere saber mas al respecto, el enlace a continuacion le explicará como se usa y detallará más sobre el mismo.";
$body .= '<center><a href="mailto:' . $toaddress . '?subject=AYUDA ' . $serviceName . '">Conocer más sobre este servicio</a></center>';
$body .= "<br/><br/>Gracias por usar Apretaste.<p>";
}
$title = 'Presentando el servicio ' . $serviceName . ' a nuestros usuarios de Apretaste';
if ($updating) {
$title = 'Buenas noticias! Hemos realizado mejoras al servicio ' . $serviceName;
}
$sql = "INSERT INTO ads (title,description,owner,expiration_date,related_service) \n\t\t\t VALUES ('{$title}', '{$body}','soporte@apretaste.com', DATE_ADD(CURRENT_DATE, INTERVAL 1 WEEK), '{$service['serviceName']}');";
$connection->deepQuery($sql);
// copy files to the service folder and remove temp files
rename($pathToService, "{$wwwroot}/services/{$service['serviceName']}");
unlink($pathToZip);
}