/**
  * Puts a JavaScript Variable used in Kwf_js/Statistics.js
  *
  * @return string
  */
 public function getIncludeCode()
 {
     $value = Kwf_Statistics::getDefaultOptValue($this->getData());
     $optInShowBox = $this->getData()->getBaseProperty('statistics.optInShowBox');
     $html = '';
     if ($value == 'out' || $value == 'in' && $optInShowBox) {
         $components = Kwf_Component_Data_Root::getInstance()->getComponentsByClass('Kwc_Statistics_Opt_Component', array('subroot' => $this->getData()));
         $url = isset($components[0]) ? $components[0]->url : null;
         $html = $this->_getOptBoxInnerHtml($url);
         if (!$html) {
             $exception = new Kwf_Exception('To disable optbox please change config.');
             $exception->logOrThrow();
         }
         $html = '<div class="' . self::getRootElementClass($this) . '"><div class="inner">' . $html . '<div></div>';
         $html = str_replace("'", "\\'", $html);
     }
     $ret = '<script type="text/javascript">';
     //TODO commonjs
     /*
     $ret .= "if (typeof Kwf == 'undefined') Kwf = {};";
     $ret .= "if (typeof Kwf.Statistics == 'undefined') Kwf.Statistics = {};";
     $ret .= "Kwf.Statistics.defaultOptValue = '$value';";
     $ret .= "Kwf.Statistics.optBoxHtml = '$html';";
     */
     $ret .= $this->_getJavascriptIncludeCode();
     $ret .= '</script>';
     return $ret;
 }
 public function processOutput($output, $renderer)
 {
     $pos = strpos($output, '{/kwcDefaultOptValue}');
     if ($pos) {
         $defaultOpt = substr($output, 20, $pos - 20);
         if (!Kwf_Statistics::issetUserOptValue() && $defaultOpt == Kwf_Statistics::OPT_IN || Kwf_Statistics::getUserOptValue() == Kwf_Statistics::OPT_IN) {
             return substr($output, $pos + 21);
         }
     }
     return '';
 }
 public function processOutput($output, $renderer)
 {
     $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_componentId);
     $output = '{kwcDefaultOptValue}' . Kwf_Statistics::getDefaultOptValue($component) . '{/kwcDefaultOptValue}' . $output;
     return $output;
 }
 protected function _beforeSave(Kwf_Model_Row_Interface $row)
 {
     $value = $row->opt ? Kwf_Statistics::OPT_IN : Kwf_Statistics::OPT_OUT;
     Kwf_Statistics::setUserOptValue($value);
 }