Inheritance: extends Pimcore\Model\AbstractModel
Example #1
0
 /**
  * @param $id
  * @return bool
  */
 public static function isIdActive($id)
 {
     $persona = Model\Tool\Targeting\Persona::getById($id);
     if ($persona) {
         return $persona->getActive();
     }
     return false;
 }
Example #2
0
 /**
  * Loads a list of document-types for the specicifies parameters, returns an array of Document\DocType elements
  *
  * @return array
  */
 public function load()
 {
     $personasData = $this->db->fetchCol("SELECT id FROM targeting_personas" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     $personas = [];
     foreach ($personasData as $personaData) {
         $personas[] = Model\Tool\Targeting\Persona::getById($personaData);
     }
     $this->model->setPersonas($personas);
     return $personas;
 }
Example #3
0
 /**
  *
  */
 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);
     }
 }
Example #4
0
 /**
  * Checks if data is valid for current data field
  *
  * @param mixed $data
  * @param boolean $omitMandatoryCheck
  * @throws \Exception
  */
 public function checkValidity($data, $omitMandatoryCheck = false)
 {
     if (!$omitMandatoryCheck and $this->getMandatory() and empty($data)) {
         throw new \Exception("Empty mandatory field [ " . $this->getName() . " ]");
     }
     if (!empty($data)) {
         $persona = Tool\Targeting\Persona::getById($data);
         if (!$persona instanceof Tool\Targeting\Persona) {
             throw new \Exception("invalid persona reference");
         }
     }
 }
Example #5
0
 public function personaSaveAction()
 {
     $data = \Zend_Json::decode($this->getParam("data"));
     $persona = Targeting\Persona::getById($this->getParam("id"));
     $persona->setValues($data["settings"]);
     $persona->setConditions($data["conditions"]);
     $persona->save();
     $this->_helper->json(["success" => true]);
 }