Example #1
0
 function setBannerTargeting($bannerId, &$aTargeting)
 {
     if ($this->checkIdExistence('banners', $bannerId)) {
         if (!$this->checkPermissions(null, 'banners', $bannerId)) {
             return false;
         }
         foreach ($aTargeting as $executionOrder => $oTargeting) {
             // Prepend "deliveryLimitations:" to any component-identifiers
             // (for 2.6 backwards compatibility)
             if (substr($oTargeting->type, 0, 20) != 'deliveryLimitations:') {
                 $aTargeting[$executionOrder]->type = 'deliveryLimitations:' . $aTargeting[$executionOrder]->type;
             }
             if (!$this->_validateTargeting($oTargeting)) {
                 return false;
             }
         }
         $aTargetingArray = array();
         foreach ($aTargeting as $oTargeting) {
             $aTargetingArray[] = $oTargeting->toArray();
         }
         $res = OX_AclCheckInputsFields($aTargetingArray, false);
         if ($res !== true) {
             $this->raiseError($res[0]);
             return false;
         }
         $doBannerTargeting = OA_Dal::factoryDO('acls');
         $doBannerTargeting->bannerid = $bannerId;
         $doBannerTargeting->find();
         $doBannerTargeting->delete();
         // Create the new targeting options
         $executionOrder = 0;
         $aAcls = array();
         foreach ($aTargetingArray as $bannerTargetingData) {
             $doAcl = OA_Dal::factoryDO('acls');
             $doAcl->setFrom($bannerTargetingData);
             $doAcl->bannerid = $bannerId;
             $doAcl->executionorder = $executionOrder;
             $doAcl->insert();
             $aAcls[$executionOrder] = $doAcl->toArray();
             $executionOrder++;
         }
         // Recompile the banner's compiledlimitations
         $doBanner = OA_Dal::factoryDO('banners');
         $doBanner->get($bannerId);
         $doBanner->compiledlimitation = OA_aclGetSLimitationFromAAcls($aAcls);
         $doBanner->acl_plugins = MAX_AclGetPlugins($aAcls);
         $doBanner->acls_updated = gmdate(OA_DATETIME_FORMAT);
         $doBanner->update();
         return true;
     } else {
         $this->raiseError('Unknown bannerId Error');
         return false;
     }
 }
function MAX_AclSave($acls, $aEntities, $page = false)
{
    //$conf = $GLOBALS['_MAX']['CONF'];
    $oDbh =& OA_DB::singleton();
    if ($page === false) {
        $page = basename($_SERVER['SCRIPT_NAME']);
    }
    switch ($page) {
        case 'banner-acl.php':
        case 'market-campaign-acl.php':
            $table = 'banners';
            $aclsTable = 'acls';
            $fieldId = 'bannerid';
            break;
        case 'channel-acl.php':
            $table = 'channel';
            $aclsTable = 'acls_channel';
            $fieldId = 'channelid';
            break;
        default:
            return false;
    }
    $aclsObjectId = $aEntities[$fieldId];
    $sLimitation = OA_aclGetSLimitationFromAAcls($acls);
    $doTable = OA_Dal::factoryDO($table);
    $doTable->{$fieldId} = $aclsObjectId;
    $found = $doTable->find(true);
    if ($sLimitation == $doTable->compiledlimitation) {
        return true;
        // No changes to the ACL
    }
    $doAcls = OA_Dal::factoryDO($aclsTable);
    $doAcls->whereAdd($fieldId . ' = ' . $aclsObjectId);
    $doAcls->delete(true);
    if (!empty($acls)) {
        foreach ($acls as $acl) {
            $deliveryLimitationPlugin =& OA_aclGetComponentFromRow($acl);
            $doAcls = OA_Dal::factoryDO($aclsTable);
            $doAcls->{$fieldId} = $aclsObjectId;
            $doAcls->logical = $acl['logical'];
            $doAcls->type = $acl['type'];
            $doAcls->comparison = $acl['comparison'];
            $doAcls->data = $deliveryLimitationPlugin->getData();
            $doAcls->executionorder = $acl['executionorder'];
            $id = $doAcls->insert();
            if (!$id) {
                return false;
            }
        }
    }
    $doTable->acl_plugins = MAX_AclGetPlugins($acls);
    $doTable->compiledlimitation = $sLimitation;
    $doTable->acls_updated = OA::getNowUTC();
    $doTable->update();
    // When a channel limitation changes - All banners with this channel must be re-learnt
    if ($page == 'channel-acl.php') {
        $affected_ads = array();
        $table = modifyTableName('acls');
        $query = "\n            SELECT\n                DISTINCT(bannerid)\n            FROM\n                {$table}\n            WHERE\n                type = 'deliveryLimitations:Site:Channel'\n              AND (data = '{$aclsObjectId}' OR data LIKE '%,{$aclsObjectId}' OR data LIKE '%,{$aclsObjectId},%' OR data LIKE '{$aclsObjectId},%')\n        ";
        $res = $oDbh->query($query);
        if (PEAR::isError($res)) {
            return $res;
        }
        while ($row = $res->fetchRow()) {
            $doBanners = OA_Dal::staticGetDO('banners', $row['bannerid']);
            if ($doBanners->bannerid == $row['bannerid']) {
                $doBanners->acls_updated = OA::getNowUTC();
                $doBanners->update();
            }
        }
    }
    return true;
}