示例#1
0
 function delete($useWhere = false, $cascade = true, $parentid = null)
 {
     // Find acls which use this channels
     $dalAcls = OA_Dal::factoryDAL('acls');
     $rsChannel = $dalAcls->getAclsByDataValueType($this->channelid, 'Site:Channel');
     $rsChannel->reset();
     while ($rsChannel->next()) {
         // Get the IDs of the banner that's using this channel
         $bannerId = $rsChannel->get('bannerid');
         // Get the remaining channels the banner will use, if any
         $aChannelIds = explode(',', $rsChannel->get('data'));
         $aChannelIds = array_diff($aChannelIds, array($this->channelid));
         // Prepare to update the banner's limitations in the "acls" table
         $doAcls = DB_DataObject::factory('acls');
         $doAcls->init();
         $doAcls->bannerid = $bannerId;
         $doAcls->executionorder = $rsChannel->get('executionorder');
         if (!empty($aChannelIds)) {
             $doAcls->data = implode(',', $aChannelIds);
             $doAcls->update();
         } else {
             $doAcls->delete();
         }
         // Re-compile the banner's limitations
         $aAcls = array();
         $doAcls = DB_DataObject::factory('acls');
         $doAcls->init();
         $doAcls->bannerid = $bannerId;
         $doAcls->orderBy('executionorder');
         $doAcls->find();
         while ($doAcls->fetch()) {
             $aData = $doAcls->toArray();
             $deliveryLimitationPlugin = OX_Component::factoryByComponentIdentifier('deliveryLimitations:' . $aData['type']);
             if ($deliveryLimitationPlugin) {
                 $deliveryLimitationPlugin->init($aData);
                 if ($deliveryLimitationPlugin->isAllowed($page)) {
                     $aAcls[$aData['executionorder']] = $aData;
                 }
             }
         }
         $sLimitation = MAX_AclGetCompiled($aAcls, $page);
         // TODO: it should be done inside plugins instead, there is no need to slash the data
         $sLimitation = !get_magic_quotes_runtime() ? stripslashes($sLimitation) : $sLimitation;
         $doBanners = OA_Dal::factoryDO('banners');
         $doBanners->bannerid = $bannerId;
         $doBanners->find();
         $doBanners->fetch();
         $doBanners->acl_plugins = MAX_AclGetPlugins($aAcls);
         $doBanners->acls_updated = OA::getNow();
         $doBanners->compiledlimitation = $sLimitation;
         $doBanners->update();
     }
     return parent::delete($useWhere, $cascade, $parentid);
 }
/**
 * A function to test if the delivery limitations stored in the database
 * are valid - that is, have the values stored in the acls or acls_channel
 * tables been correctly compiled into the form required to be stored in
 * the banners or channels table?
 *
 * @param string $page Either "banner-acl.php" if testing a banner limitation,
 *                     or "channel-acl.php" if testing a channel limitation.
 * @param array  $aParams An array, containing either the "bannerid" if testing
 *                        a banner limitation, or the "channelid" if testing a
 *                        channel limitation.
 * @return boolean True if the limitations are correctly compiled, false otherwise.
 */
function MAX_AclValidate($page, $aParams)
{
    $conf =& $GLOBALS['_MAX']['CONF'];
    $oDbh =& OA_DB::singleton();
    if (PEAR::isError($oDbh)) {
        return false;
    }
    switch ($page) {
        case 'banner-acl.php':
        case 'market-campaign-acl.php':
            $doEntityTable = OA_Dal::factoryDO('banners');
            $doEntityTable->bannerid = $aParams['bannerid'];
            $doAclTable = OA_Dal::factoryDO('acls');
            $doAclTable->bannerid = $aParams['bannerid'];
            break;
        case 'channel-acl.php':
            $doEntityTable = OA_Dal::factoryDO('channel');
            $doEntityTable->channelid = $aParams['channelid'];
            $doAclTable = OA_Dal::factoryDO('acls_channel');
            $doAclTable->channelid = $aParams['channelid'];
            break;
    }
    $doEntityTable->find();
    $doEntityTable->fetch();
    $aData = $doEntityTable->toArray();
    $compiledLimitation = $aData['compiledlimitation'];
    $acl_plugins = $aData['acl_plugins'];
    $aAcls = array();
    $doAclTable->orderBy('executionorder');
    $doAclTable->find();
    while ($doAclTable->fetch()) {
        $aData = $doAclTable->toArray();
        $deliveryLimitationPlugin = OA_aclGetComponentFromRow($aData);
        if ($deliveryLimitationPlugin) {
            $deliveryLimitationPlugin->init($aData);
            if ($deliveryLimitationPlugin->isAllowed($page)) {
                $aAcls[$aData['executionorder']] = $aData;
            }
        }
    }
    $newCompiledLimitation = MAX_AclGetCompiled($aAcls);
    $newAclPlugins = MAX_AclGetPlugins($aAcls);
    if ($newCompiledLimitation == $compiledLimitation && $newAclPlugins == $acl_plugins) {
        return true;
    } elseif (($compiledLimitation === 'true' || $compiledLimitation === '') && ($newCompiledLimitation === 'true' && empty($newAclPlugins))) {
        return true;
    } else {
        return false;
    }
}