Exemplo n.º 1
0
    /**
     * checks if commission type exists in this campaign
     *
     * @param string $commissionType
     * @return Pap_Db_CommissionType
     */
    public function getCommissionTypeObject($commissionType, $code = '',$countryCode = '') {
        $baseTypeSelect = $this->getCommissionTypeSelect($commissionType, $code, '');
        $commType = new Pap_Db_CommissionType();

        try {
            $baseTypesCollection = $commType->loadCollectionFromRecordset($baseTypeSelect->getAllRows());
        } catch (Gpf_DbEngine_NoRowException $e) {
            throw new Pap_Tracking_Exception("Commission type not found in campaign: " . $e->getMessage());
        }
        if ($baseTypesCollection->getSize()==0) {
            throw new Pap_Tracking_Exception("Commission type not found in campaign");
        }

        $countrySpecificTypeSelect = $this->getCommissionTypeSelect($commissionType, $code, $countryCode);
        try {
            $countryTypesCollection = $commType->loadCollectionFromRecordset($countrySpecificTypeSelect->getAllRows());
        } catch (Gpf_DbEngine_NoRowException $e) {
            return $baseTypesCollection->get(0);
        }
        if ($countryTypesCollection->getSize()==0) {
            return $baseTypesCollection->get(0);
        }
        return $countryTypesCollection->get(0);
    }
Exemplo n.º 2
0
 public function getCommissionType(Pap_Contexts_Action $context) {
     $context->debug("Begin recognizing country specific commission type");
     if(!strlen($context->getTransactionObject()->getCountryCode())) {
         $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty");
         return;
     }
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Pap_Db_Table_CommissionTypes::getInstance());
     $select->from->add(Pap_Db_Table_CommissionTypes::getName());
     $select->where->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', $context->getCommissionTypeObject()->getId());
         
     $compoundContext = new Gpf_Data_Record(array(Pap_Db_Table_RawImpressions::IP, Pap_Db_Table_Impressions::COUNTRYCODE), array($context->getVisit()->getIp(), ''));
     $this->getCountryCode($compoundContext);
     $countryCode = $compoundContext->get(Pap_Db_Table_Impressions::COUNTRYCODE);
     if (!strlen($countryCode)) {
         $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty");
         return;
     }
         
     $select->where->add(Pap_Db_Table_CommissionTypes::COUNTRYCODES, 'LIKE', '%'.$countryCode.'%');
     try {
         $commType = new Pap_Db_CommissionType();
         $collection = $commType->loadCollectionFromRecordset($select->getAllRows());
         $context->setCommissionTypeObject($collection->get(0));
     } catch (Gpf_DbEngine_NoRowException $e) {
         $context->debug("Recognizing country specific commission type eneded - no country secpific commission defined");
         return;
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         $context->debug("STOPPING ecognizing country specific commission type eneded: more than one commision type is defined for country " . $context->getTransactionObject()->getCountryCode());
         return;
     } catch (Gpf_Exception $e) {
         $context->debug("STOPPING recognizing country specific commission type eneded: " . $e->getMessage());
     }
 }