Source of file VaryingPersonalisationScheme.php
Size: 2,959 Bytes - Last Modified: 2021-12-23T10:33:31+00:00
/var/www/docs.ssmods.com/process/src/code/VaryingPersonalisationScheme.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | <?php class VaryingPersonalisationScheme extends PersonalisationScheme { public static $db = array( "ContextProviderClass" => "Varchar(255)", "SelectionProviderClass" => "Varchar(255)" ); public static $has_many = array( "Variations" => "PersonalisationVariation" ); public static $is_abstract = true; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName("ContextProviderClass"); $fields->removeByName("SelectionProviderClass"); return $fields; } public function personalise(Controller $controller = null) { $cp = $this->getContextProvider(); $sp = $this->getSelectionProvider(); $var = $sp->getVariation($cp, $this); if (is_numeric($var)) { // if we got a number, we're going to treat it as a personalisation variation ID $var = PersonalisationVariation::get()->filter("ID", $var)->First(); } elseif (is_string($var)) { // if we got a name, we're going to treat it as a personalation variation Name $var = PersonalisationVariation::get()->filter("Name", $var)->First(); } if ($var instanceof PersonalisationVariation) { if ($var->ParentID != $this->ID) { $var = null; } // we got a variation but it is not for this scheme. } if ($var === null) { // if we can't determine a variation that is within this scheme, use the default for the scheme, or first. $var = $this->Variations()->First(); if (!$var) { return ""; } // bah, give up. if the user can't be bothered configuring it, they can't expect magic. } $this->trackRender($var); return $var->render($cp); } public function getContextProvider() { if ($this->ContextProviderClass) { $c = $this->ContextProviderClass; return new $c(); } return new DefaultContextProvider(); } public function getSelectionProvider() { if ($this->SelectionProviderClass) { $c = $this->SelectionProviderClass; return new $c(); } return new BasicSelectionProvider(); } public function canCreate($member = null) { return false; } public function getRenderProperty() { return "personalisation.measure." . $this->ID . ".render"; } /** * If measurement is enabled for this scheme, then we need to track that this was rendered for the current * identity. * @return void */ protected function trackRender($var) { if (!$this->MeasurementEnabled) { return; } if (!$var) { return; } $prop = $this->getRenderProperty(); Tracker::track(array($prop => $var->ID)); } } |