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


PHP Document::getElements方法代码示例

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


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

示例1: dispatchLoopShutdown

 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         $targets = array();
         $personas = array();
         $dataPush = array("personas" => $this->personas, "method" => strtolower($this->getRequest()->getMethod()));
         if (count($this->events) > 0) {
             $dataPush["events"] = $this->events;
         }
         if ($this->document instanceof Document\Page && !Model\Staticroute::getCurrentRoute()) {
             $dataPush["document"] = $this->document->getId();
             if ($this->document->getPersonas()) {
                 if ($_GET["_ptp"]) {
                     // if a special version is requested only return this id as target group for this page
                     $dataPush["personas"][] = (int) $_GET["_ptp"];
                 } else {
                     $docPersonas = explode(",", trim($this->document->getPersonas(), " ,"));
                     //  cast the values to int
                     array_walk($docPersonas, function (&$value) {
                         $value = (int) trim($value);
                     });
                     $dataPush["personas"] = array_merge($dataPush["personas"], $docPersonas);
                 }
             }
             // check for persona specific variants of this page
             $personaVariants = array();
             foreach ($this->document->getElements() as $key => $tag) {
                 if (preg_match("/^persona_-([0-9]+)-_/", $key, $matches)) {
                     $id = (int) $matches[1];
                     if (Model\Tool\Targeting\Persona::isIdActive($id)) {
                         $personaVariants[] = $id;
                     }
                 }
             }
             if (!empty($personaVariants)) {
                 $personaVariants = array_values(array_unique($personaVariants));
                 $dataPush["personaPageVariants"] = $personaVariants;
             }
         }
         // no duplicates
         $dataPush["personas"] = array_unique($dataPush["personas"]);
         $activePersonas = array();
         foreach ($dataPush["personas"] as $id) {
             if (Model\Tool\Targeting\Persona::isIdActive($id)) {
                 $activePersonas[] = $id;
             }
         }
         $dataPush["personas"] = $activePersonas;
         if ($this->document) {
             // @TODO: cache this
             $list = new Model\Tool\Targeting\Rule\Listing();
             $list->setCondition("active = 1");
             foreach ($list->load() as $target) {
                 $redirectUrl = $target->getActions()->getRedirectUrl();
                 if (is_numeric($redirectUrl)) {
                     $doc = \Document::getById($redirectUrl);
                     if ($doc instanceof \Document) {
                         $target->getActions()->redirectUrl = $doc->getFullPath();
                     }
                 }
                 $targets[] = $target;
             }
             $list = new Model\Tool\Targeting\Persona\Listing();
             $list->setCondition("active = 1");
             foreach ($list->load() as $persona) {
                 $personas[] = $persona;
             }
         }
         $code = '<script type="text/javascript" src="/pimcore/static/js/frontend/geoip.js/"></script>';
         $code .= '<script type="text/javascript">';
         $code .= 'var pimcore = pimcore || {};';
         $code .= 'pimcore["targeting"] = {};';
         $code .= 'pimcore["targeting"]["dataPush"] = ' . \Zend_Json::encode($dataPush) . ';';
         $code .= 'pimcore["targeting"]["targetingRules"] = ' . \Zend_Json::encode($targets) . ';';
         $code .= 'pimcore["targeting"]["personas"] = ' . \Zend_Json::encode($personas) . ';';
         $code .= '</script>';
         $code .= '<script type="text/javascript" src="/pimcore/static/js/frontend/targeting.js"></script>';
         $code .= "\n";
         // analytics
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = stripos($body, "<head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, "<head>\n" . $code, $headEndPosition, 7);
         }
         $this->getResponse()->setBody($body);
     }
 }
开发者ID:quorak,项目名称:pimcore,代码行数:95,代码来源:Targeting.php


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