/**
     * @param Pap_Db_VisitorAffiliate
     * @return Pap_Db_VisitorAffiliate
     */
    public function recognizeAffiliate(Pap_Db_VisitorAffiliate $visitorAffiliate) {
        $user = $this->getUserById($visitorAffiliate->getUserId());

        if ($user == null) {
            $this->isValid = false;
            return;
        }
        
        $this->context->setUserObject($user);

        $campaign = $this->getCampaignById($visitorAffiliate->getCampaignId());
        if ($campaign != null && $this->context->getCampaignObject() == null) {
            $this->context->setCampaignObject($campaign);
        }

        $banner = $this->getBannerById($visitorAffiliate->getBannerId());
        if ($banner != null && $this->context->getBannerObject() == null) {
            $this->context->setBannerObject($banner);
        }

        $channel = $this->getChannelById($visitorAffiliate->getChannelId());
        if ($channel != null) {
            $this->context->setChannelObject($channel);
        }
        $this->context->setVisitorAffiliate($visitorAffiliate);

        $this->isValid = true;
    }
 private function isSameVisitorAffiliates(Pap_Db_VisitorAffiliate $saleVisitorAffiliate, Pap_Db_VisitorAffiliate $clickVisitorAffilaite) {
     return ($saleVisitorAffiliate->getUserId() == $clickVisitorAffilaite->getUserId() &&
     $saleVisitorAffiliate->getCampaignId() == $clickVisitorAffilaite->getCampaignId() &&
     $saleVisitorAffiliate->getChannelId() == $clickVisitorAffilaite->getChannelId());
 }
    private function checkTwoVisitorAffiliateAreSameAndRemove($index1, $index2, Pap_Tracking_Common_VisitorAffiliateCollection $rows,
    Pap_Db_VisitorAffiliate $firstClickVisitorAffiliate, Pap_Tracking_Visit_VisitorAffiliateCache $cache) {
        if ($rows->getValid($index1)->getUserId() != $rows->getValid($index2)->getUserId()) {
            return false;
        }

        if ($rows->getValid($index1)->getUserId() == $firstClickVisitorAffiliate->getUserId()) {
            return false;
        }

        $cache->removeVisitorAffiliate($rows->getValid($index2)->getId());
        $rows->remove($index2);
        $rows->correctIndexes();
        
        $this->cloneVisitorAffiliate($firstClickVisitorAffiliate, $rows, false);
        return true;
    }