Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 
<?php
namespace Apptus\ESales\Connector\Report;

use Apptus\ESales\Connector\Time\TimeInterval;

/**
 * Report for Search statistics on the site.
 *
 * This report can be seen in the Search Statistics tab on the Reports page in eSales Manager and it is described
 * in the <i>Search statistics</i> section on <a href="http://zone.apptus.com">Apptus Zone</a> (http://zone.apptus.com).
 */
class SearchStatisticsReport extends Report {

    /**
     * Creates an SearchStatisticsReport from an XML document.
     *
     * @param string
     *            A string with the XML document to parse.
     * @param \DateTimeZone
     *            The time zone for this report.
     * @return AdPlacementReport
     *            An AdPlacementReport.
     * @throws FormatException if the XML document does not match the expected format.
     */
    public static function parse($data, \DateTimeZone $tz) {
        $root = new \SimpleXMLElement($data);

        self::checkElem($root, 'function');
        self::checkElem($root->function, 'report');

        $report = $root->function->report;

        self::checkElem($report, 'time_interval');
        self::checkElem($report, 'searches_with_hits');
        self::checkElem($report, 'searches_with_no_hits');
        self::checkElem($report, 'searches_that_boost_conversion');
        self::checkElem($report, 'searches_that_lower_conversion');

        $interval = TimeInterval::parse($report->time_interval);
        $searchesWithHits = $report->searches_with_hits;
        $searchesWithNoHits = $report->searches_with_no_hits;
        $searchesThatBoost = $report->searches_that_boost_conversion;
        $searchesThatLower = $report->searches_that_lower_conversion;

        $searchesWithHitsList = self::parseSearchCounts($searchesWithHits);
        $searchesWithNoHitsList = self::parseSearchCounts($searchesWithNoHits);
        $searchesThatBoostList = self::parseSearchConversion($searchesThatBoost);
        $searchesThatLowerList = self::parseSearchConversion($searchesThatLower);
        return new SearchStatisticsReport($root,
                $interval,
                $searchesWithHitsList->totalRate(),
                $searchesWithHitsList->searches(),
                $searchesWithNoHitsList->totalRate(),
                $searchesWithNoHitsList->searches(),
                $searchesThatBoostList,
                $searchesThatLowerList,
                $tz);
    }

    private static function parseSearchCounts(\SimpleXMLElement $searchesXml) {
        self::checkElem($searchesXml, 'total_rate');
        self::checkElem($searchesXml, 'searches');

        $totalRate = $searchesXml->total_rate;
        $searches = array();

        foreach ($searchesXml->searches->search as $search) {
            self::checkElem($search, 'rank');
            self::checkElem($search, 'phrase');
            self::checkElem($search, 'count');
            self::checkElem($search, 'search_rate');

            $rank = $search->rank;
            $phrase = $search->phrase;
            $count = $search->count;
            $searchRate = $search->search_rate;
            array_push($searches, new SearchCount($phrase, $count, new Rate(self::parseDouble($searchRate[0])), $rank));
        }

        return new SearchCountList(new Rate(self::parseDouble($totalRate[0])), $searches);
    }

    private static function parseSearchConversion(\SimpleXMLElement $searchesXml) {
        self::checkElem($searchesXml, 'searches');
        $searches = array();

        foreach ($searchesXml->searches->search as $search) {
            self::checkElem($search, 'rank');
            self::checkElem($search, 'phrase');
            self::checkElem($search, 'count');
            self::checkElem($search, 'conversion_rate');
            self::checkElem($search, 'impact');

            $rank = $search->rank;
            $phrase = $search->phrase;
            $count = $search->count;
            $convRate = $search->conversion_rate;
            $impact = $search->impact;
            array_push($searches, new SearchConversion($phrase, $count, new Rate(self::parseDouble($convRate[0])), new Rate(self::parseDouble($impact[0])), $rank));
        }

        return $searches;
    }

    private $searchesWithHitsRate;
    private $searchesWithHits;
    private $searchesWithNoHitsRate;
    private $searchesWithNoHits;
    private $searchesThatBoost;
    private $searchesThatLower;

    /**
     * Creates a SearchStatisticsReport.
     *
     * Note that null is illegal for all input parameters.
     *
     * @param \SimpleXMLElement
     *            An XmlTree to be used if the {@see exportToXml()} method is called.
     * @param TimeInterval
     *            The time range for the data in this report.
     * @param Rate
     *            The rate of searches that leads to at least one hit.
     * @param array
     *            List of the most popular search phrases that has resulted in search hits.
     * @param Rate
     *            The rate of searches that does not lead to a no hit.
     * @param array
     *            List of the most popular search phrases that has resulted in no hits.
     * @param array
     *            List of the search phrases that has largest positive impact on the conversion.
     * @param array
     *            List of the search phrases that has largest negative impact on the conversion.
     * @param \DateTimeZone
     *            The time zone for this report.
     */
    public function __construct(\SimpleXMLElement $asXml, TimeInterval $interval, Rate $searchesWithHitsRate,
            array $searchesWithHits, Rate $searchesWithNoHitsRate, array $searchesWithNoHits,
            array $searchesThatBoost, array $searchesThatLower, \DateTimeZone $tz)
    {
        parent::__construct($interval, $asXml, $tz);

        $this->searchesWithHitsRate = $searchesWithHitsRate;
        $this->searchesWithHits = $searchesWithHits;
        $this->searchesWithNoHitsRate = $searchesWithNoHitsRate;
        $this->searchesWithNoHits = $searchesWithNoHits;
        $this->searchesThatBoost = $searchesThatBoost;
        $this->searchesThatLower = $searchesThatLower;
    }

    /**
     * @return array
     *            List of the most popular search phrases that has resulted in search hits.
     */
    public function searchesWithHits() {
        return $this->searchesWithHits;
    }

    /**
     * @return Rate
     *            The rate of searches that leads to at least one hit or Rate::NaN() if the rate can not be calculated.
     */
    public function searchesWithHitsTotalRate() {
        return $this->searchesWithHitsRate;
    }

    /**
     * @return array
     *            List of the most popular search phrases that has resulted in no hits or Rate::NaN() if the rate can not be calculated.
     */
    public function searchesWithNoHits() {
        return $this->searchesWithNoHits;
    }

    /**
     * @return Rate
     *            The rate of searches that does not lead to a no hit.
     */
    public function searchesWithNoHitsTotalRate() {
        return $this->searchesWithNoHitsRate;
    }

    /**
     * @return array
     *            List of the search phrases that has largest positive impact on the conversion.
     */
    public function searchesThatBoostConversion() {
        return $this->searchesThatBoost;
    }

    /**
     * @return array
     *            List of the search phrases that has largest negative impact on the conversion.
     */
    public function searchesThatLowerConversion() {
        return $this->searchesThatLower;
    }

    public function exportToExcel($file) {
        $w = new ExcelWriter($file);

        $w->cell('Search Statistics')->nextRow();
        $w->cell('Time interval');
        $w->cell($this->isoDateTimeFormat($this->timeInterval()->start($this->tz)->toDateTime($this->tz)));
        $w->cell($this->isoDateTimeFormat($this->timeInterval()->end($this->tz)->toDateTime($this->tz)))->nextRow();

        $w->nextRow();
        $w->cell('Searches with Hits')->cell('Total search rate')->cell($this->searchesWithHitsRate)->nextRow();
        $w->cell('Rank')->cell('Phrase')->cell('Count')->cell('Search rate')->nextRow();

        foreach ($this->searchesWithHits as $sc) {
            $w->cell($sc->rank())->cell($sc->phrase())->cell($sc->count())->cell($sc->searchRate())->nextRow();
        }

        $w->nextRow();
        $w->cell('Searches with No Hits')->cell('Total search rate')->cell($this->searchesWithNoHitsRate)->nextRow();
        $w->cell('Rank')->cell('Phrase')->cell('Count')->cell('Search rate')->nextRow();

        foreach ($this->searchesWithNoHits as $sc) {
            $w->cell($sc->rank())->cell($sc->phrase())->cell($sc->count())->cell($sc->searchRate())->nextRow();
        }

        $w->nextRow();
        $w->cell('Searches that Boost Conversion')->nextRow();
        $w->cell('Rank')->cell('Phrase')->cell('Count')->cell('Conversion rate')->cell('Impact')->nextRow();

        foreach ($this->searchesThatBoost as $sc) {
            $impact = is_nan($sc->impact()->value()) ? '' : $sc->impact()->perMille(2);
            $w->cell($sc->rank())->cell($sc->phrase())->cell($sc->count())->cell($sc->conversionRate())->cell($impact)->nextRow();
        }

        $w->nextRow();
        $w->cell('Searches that Lower Conversion')->nextRow();
        $w->cell('Rank')->cell('Phrase')->cell('Count')->cell('Conversion rate')->cell('Impact')->nextRow();

        foreach ($this->searchesThatLower as $sc) {
            $impact = is_nan($sc->impact()->value()) ? '' : $sc->impact()->perMille(2);
            $w->cell($sc->rank())->cell($sc->phrase())->cell($sc->count())->cell($sc->conversionRate())->cell($impact)->nextRow();
        }

        $w->flush();
        $w->close();
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen