Returns the very first visit for the given visitorId

@internal

@param $idSite
@param $visitorId

@return DataTable
341134
public function getFirstVisitForVisitorId($idSite, $visitorId)
    {
        Piwik::checkUserHasSomeViewAccess();

        if (empty($visitorId)) {
            return new DataTable();
        }

        $model = new Model();
        $data = $model->queryLogVisits($idSite, false, false, false, 0, 1, $visitorId, false, 'ASC');
        $dataTable = $this->makeVisitorTableFromArray($data);
        $this->addFilterToCleanVisitors($dataTable, $idSite, false, true);

        return $dataTable;
    }
700489
public function addVisitor(VisitorInterface $visitor, $priority = 0)
    {
        $this->sortedVisitors = null;

        $this->visitors[spl_object_hash($visitor)] = array(
            'priority' => $priority,
            'visitor' => $visitor
        );

        return $this;
    }
401800
private function first(int $id = null)
    {
        $this->firstIsSelected = true;  // utile pour active record

        if ($id) {
            $this->where('id', '=', $id);
        }

        $this->query->setStartSelect();

        $this->limit(1);

        $this->query->prepare()->bindWhere()->bindLimit()->execute();

        return $this->query->fetch();
    }
1226021
public function create(array $visitorRawData = array())
    {
        $visitor = null;

        /**
         * Triggered while visit is filtering in live plugin. Subscribers to this
         * event can force the use of a custom visitor object that extends from
         * {@link Piwik\Plugins\Live\VisitorInterface}.
         *
         * @param \Piwik\Plugins\Live\VisitorInterface &$visitor Initialized to null, but can be set to
         *                                              a new visitor object. If it isn't modified
         *                                              Piwik uses the default class.
         * @param array $visitorRawData Raw data using in Visitor object constructor.
         */
        Piwik::postEvent('Live.makeNewVisitorObject', array(&$visitor, $visitorRawData));

        if (is_null($visitor)) {
            $visitor = new Visitor($visitorRawData);
        } elseif (!($visitor instanceof VisitorInterface)) {
            throw new Exception("The Visitor object set in the plugin must implement VisitorInterface");
        }

        return $visitor;
    }
902682
public function first($id = null) {
        if ($id) {
            $this->where($this->connection->getPrimaryKey(), $id);
        }
        $data = $this->get();

        return $data ? $data[0] : [];
    }
1157546
public function getEntryPageTitles($idSite, $period, $date, $segment = false, $expanded = false,
                                       $idSubtable = false, $flat = false)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $dataTable = $this->getPageTitles($idSite, $period, $date, $segment, $expanded, $idSubtable, $flat);
        $this->filterNonEntryActions($dataTable);
        return $dataTable;
    }
436569
public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
    {
        $className = $this->manager->getClass();

        if ($data instanceof $className) {
            return $visitor->visitInteger($data->getId(), $type, $context);
        }
    }
1062799
public function getSiteById($idSite, $env, $includeSite404Table = false)
	{
        // Retrieve cache version if front mode to avoid multiple calls
	    $cacheKey = get_class($this) . '_getSiteById_' . $idSite . '_' . $env . '_' . $includeSite404Table;
        $cacheConfig = 'engine_page_services';
        $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem');
        $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
        if (!empty($results)) return $results;
	    
		$select = $this->tableGateway->getSql()->select();
		
		$select->columns(array('*'));
	
		$siteDomainjoin = new Expression('melis_cms_site_domain.sdom_site_id = melis_cms_site.site_id AND sdom_env =\''.$env.'\'');
		
		if($includeSite404Table) {
		    
		    $site404join = new Expression('melis_cms_site_domain.sdom_site_id = melis_cms_site.site_id');
		    
		    $select->join('melis_cms_site_domain', $siteDomainjoin, array('*'), $select::JOIN_LEFT)
		           ->join('melis_cms_site_404', $site404join, array('*'), $select::JOIN_LEFT);
		}
		else {
		    $select->join('melis_cms_site_domain', $siteDomainjoin, array('*'), $select::JOIN_LEFT);
		}
		
		$select->where('site_id ='.$idSite);
	
		$resultSet = $this->tableGateway->selectWith($select);

		$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $resultSet);
		
		return $resultSet;
	}
219026
public function deleteFromLogTable($tableName, $visitIds)
    {
        $sql = "DELETE FROM `" . Common::prefixTable($tableName) . "` WHERE idvisit IN "
             . $this->getInFieldExpressionWithInts($visitIds);

        $statement = Db::query($sql);
        return $statement->rowCount();
    }
307927
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('ObjectState');
        $visitor->setHeader('Content-Type', $generator->getMediaType('ObjectState'));
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('ObjectStateUpdate'));

        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_loadObjectState',
                array('objectStateGroupId' => $data->groupId, 'objectStateId' => $data->objectState->id)
            )
        );
        $generator->endAttribute('href');

        $generator->startValueElement('id', $data->objectState->id);
        $generator->endValueElement('id');

        $generator->startValueElement('identifier', $data->objectState->identifier);
        $generator->endValueElement('identifier');

        $generator->startValueElement('priority', $data->objectState->priority);
        $generator->endValueElement('priority');

        $generator->startObjectElement('ObjectStateGroup');

        $generator->startAttribute(
            'href',
            $this->router->generate('ezpublish_rest_loadObjectStateGroup', array('objectStateGroupId' => $data->groupId))
        );
        $generator->endAttribute('href');

        $generator->endObjectElement('ObjectStateGroup');

        $generator->startValueElement('defaultLanguageCode', $data->objectState->defaultLanguageCode);
        $generator->endValueElement('defaultLanguageCode');

        $generator->startValueElement('languageCodes', implode(',', $data->objectState->languageCodes));
        $generator->endValueElement('languageCodes');

        $this->visitNamesList($generator, $data->objectState->getNames());
        $this->visitDescriptionsList($generator, $data->objectState->getDescriptions());

        $generator->endObjectElement('ObjectState');
    }
294741
protected function getOtherMonth($VisitorsID)
	{
	    $StartMonth = date('Y-m-d',mktime(0, 0, 0, date("m")-11, 1, date("Y"))); // aktueller Monat -11
	    $EndMonth   = date('Y-m-d',mktime(0, 0, 0, date("m")-1 , 0, date("Y"))); // letzter Tag des vorletzten Monats
		if ($VisitorsID) 
		{
			//Total je Monat (aktueller und letzter)
            $objVisitorsToMo = \Database::getInstance()
			        ->prepare('SELECT 
                                    EXTRACT( YEAR FROM visitors_date ) AS Y, 
                                    EXTRACT( MONTH FROM visitors_date ) AS M, 
                                    SUM( visitors_visit ) AS SUMV, 
                                    SUM( visitors_hit ) AS SUMH 
                                 FROM 
                                    tl_visitors_counter 
                                 WHERE 
                                    vid=? AND visitors_date BETWEEN ? AND ?
                                 GROUP BY Y, M
                                 ORDER BY Y DESC, M DESC')
                    ->execute($VisitorsID,$StartMonth,$EndMonth);
			$intRows = $objVisitorsToMo->numRows;
			$arrOtherMonth = array();
			if ($intRows>0) 
			{ 
				while ($objVisitorsToMo->next()) 
				{
					$arrOtherMonth[] = array($objVisitorsToMo->Y,
					                         $GLOBALS['TL_LANG']['MONTHS'][($objVisitorsToMo->M - 1)],
					                         $this->getFormattedNumber($objVisitorsToMo->SUMV,0),
					                         $this->getFormattedNumber($objVisitorsToMo->SUMH,0)
					                        );
				}
			}
		}
		return $arrOtherMonth;
	}
887893
public function serializeDateInterval(SerializationVisitorInterface $visitor, \DateInterval $date, array $type, SerializationContext $context)
    {
        $iso8601DateIntervalString = $this->format($date);

        if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
            return $visitor->visitSimpleString($iso8601DateIntervalString, $type);
        }

        return $visitor->visitString($iso8601DateIntervalString, $type);
    }
1240
public function generateNewsVisitHitTop($VisitorsID, $limit = 10, $parse = true)
    {
        $arrNewsStatCount = false;
        
        //News Tables exists?
        if (true === $this->getNewstableexists())
        {
            $objNewsStatCount = \Database::getInstance()
                            ->prepare("SELECT 
                                            visitors_page_id,
                                            visitors_page_lang,
                                            SUM(visitors_page_visit) AS visitors_page_visits,
                                            SUM(visitors_page_hit)   AS visitors_page_hits
                                        FROM
                                            tl_visitors_pages
                                        WHERE
                                            vid = ?
                                        AND visitors_page_type = ?
                                        GROUP BY 
                                            visitors_page_id, 
                                            visitors_page_lang
                                        ORDER BY 
                                            visitors_page_visits DESC,
                                            visitors_page_hits DESC,
                                            visitors_page_id,
                                            visitors_page_lang
                                    ")
                            ->limit($limit)
                            ->execute($VisitorsID, self::PAGE_TYPE_NEWS);
            
            while ($objNewsStatCount->next())
            {
        	    $alias   = false;
        	    $aliases = $this->getNewsAliases($objNewsStatCount->visitors_page_id);
        	    if (false !== $aliases['PageAlias'])
        	    {
        	       $alias = $aliases['PageAlias'] .'/'. $aliases['NewsAlias'];
        	    }
                
                if (false !== $alias) 
                {
                    $arrNewsStatCount[] = array
                    (
                        'title'         => $aliases['NewsArchivTitle'],
                        'alias'         => $alias,
                        'lang'          => $objNewsStatCount->visitors_page_lang,
                        'visits'        => $objNewsStatCount->visitors_page_visits,
                        'hits'          => $objNewsStatCount->visitors_page_hits
                    );
                }
            }
            if ($parse === true)
            {
                /* @var $TemplatePartial Template */
                $TemplatePartial = new \BackendTemplate('mod_visitors_be_stat_partial_newsvisithittop');
                $TemplatePartial->NewsVisitHitTop = $arrNewsStatCount;
                return $TemplatePartial->parse();
            }
            return $arrNewsStatCount;
        }
        return false;
    }
538898
public function getGoal($idSite, $idGoal)
    {
        Piwik::checkUserHasViewAccess($idSite);
        
        $goal = $this->getModel()->getActiveGoal($idSite, $idGoal);

        if (!empty($goal)) {
            return $this->formatGoal($goal);
        }
    }
123382
public function getWidgetMetadata($idSite)
    {
        Piwik::checkUserHasViewAccess($idSite);

        $widgetsList  = WidgetsList::get();
        $categoryList = CategoryList::get();
        $metadata     = new WidgetMetadata();

        return $metadata->getWidgetMetadata($categoryList, $widgetsList);
    }
1309376
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('UrlAliasList');
        $visitor->setHeader('Content-Type', $generator->getMediaType('UrlAliasList'));

        $generator->startAttribute('href', $data->path);
        $generator->endAttribute('href');

        $generator->startList('UrlAlias');
        foreach ($data->urlAliases as $urlAlias) {
            $visitor->visitValueObject($urlAlias);
        }
        $generator->endList('UrlAlias');

        $generator->endObjectElement('UrlAliasList');
    }
338756
public function findCacheById(int $id, int $siteId = null)
    {

        // Resolve siteId
        $siteId = SiteHelper::resolveSiteId($siteId);

        // Check if already in addToCache
        if ($this->isCachedById($id, $siteId)) {
            return $this->cacheById[$siteId][$id];
        }

        return null;
    }