当前位置: 首页>>代码示例>>PHP>>正文


PHP Render::renderJSON方法代码示例

本文整理汇总了PHP中Render::renderJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP Render::renderJSON方法的具体用法?PHP Render::renderJSON怎么用?PHP Render::renderJSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Render的用法示例。


在下文中一共展示了Render::renderJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderResponse


//.........这里部分代码省略.........
     $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;
     }
     // echo the json on the screen
     if ($format == "json") {
         return $render->renderJSON($response);
     }
     // false if no action could be taken
     return false;
 }
开发者ID:Apretaste,项目名称:Sandbox,代码行数:101,代码来源:RunController.php

示例2: renderResponse


//.........这里部分代码省略.........
                 $connection->deepQuery($sql);
                 // add notification to user
                 $utils->addNotification($rs->email, "GAME", "Haz ganado 10 tickets para Rifa por utilizar Apretaste durante 5 d&iacute;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");
             if (count($invites) > 0) {
                 // check how this user came to know Apretaste, for stadistics
                 $inviteSource = $invites[0]->source;
                 // give prizes to the invitations via service invitar
                 // if more than one person invites X, they all get prizes
                 foreach ($invites as $invite) {
                     switch ($invite->source) {
                         case "internal":
                             // assign tickets and credits
                             $sql .= "INSERT INTO ticket (email, origin) VALUES ('{$invite->email_inviter}', 'RAFFLE');";
                             $sql .= "UPDATE person SET credit=credit+0.25 WHERE email='{$invite->email_inviter}';";
                             // email the invitor
                             $newTicket = new Response();
                             $newTicket->setResponseEmail($invite->email_inviter);
                             $newTicket->setEmailLayout("email_simple.tpl");
开发者ID:Apretaste,项目名称:Core,代码行数:67,代码来源:RunController.php

示例3: 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);
//.........这里部分代码省略.........
开发者ID:ChrisClement,项目名称:Core,代码行数:101,代码来源:RunController.php


注:本文中的Render::renderJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。