category_rights_buyable.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,  visible, multilanguage, ident
00004                                         array( 'oxtitle', 'oxgroups', 1, 0, 0 ),
00005                                         array( 'oxid',    'oxgroups', 0, 0, 0 ),
00006                                         array( 'oxrrid',  'oxgroups', 0, 0, 1 ),
00007                                         ),
00008                      'container2' => array(
00009                                         array( 'oxtitle', 'oxgroups', 1, 0, 0 ),
00010                                         array( 'oxid',    'oxgroups', 0, 0, 0 ),
00011                                         array( 'oxrrid',  'oxgroups', 0, 0, 1 ),
00012                                         )
00013                     );
00017 class ajaxComponent extends ajaxListComponent
00018 {
00024     protected function _getQuery()
00025     {
00026         // looking for table/view
00027         $sGroupTable = getViewName('oxgroups');
00028         $iAction = 2;
00029 
00030         $sArtId      = oxConfig::getParameter( 'oxid' );
00031         $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
00032 
00033         // category selected or not ?
00034         if ( !$sArtId) {
00035             $sQAdd  = " from $sGroupTable where 1 ";
00036         } else {
00037             // fetching article RR view index
00038             $sQAdd   = " from $sGroupTable, oxobjectrights where ";
00039             $sQAdd  .= " oxobjectrights.oxobjectid = '$sArtId' and ";
00040             $sQAdd  .= " oxobjectrights.oxoffset = ( $sGroupTable.oxrrid div 31 ) and ";
00041             $sQAdd  .= " oxobjectrights.oxgroupidx & ( 1 << ( $sGroupTable.oxrrid mod 31 ) ) and oxobjectrights.oxaction = $iAction ";
00042         }
00043 
00044         if ( $sSynchArtId && $sSynchArtId != $sArtId ) {
00045             $sQAdd   = " from $sGroupTable left join oxobjectrights on ";
00046             $sQAdd  .= " oxobjectrights.oxoffset = ($sGroupTable.oxrrid div 31) and ";
00047             $sQAdd  .= " oxobjectrights.oxgroupidx & ( 1 << ( $sGroupTable.oxrrid mod 31 ) ) and oxobjectrights.oxobjectid='$sSynchArtId' and oxobjectrights.oxaction = $iAction ";
00048             $sQAdd  .= " where oxobjectrights.oxobjectid != '$sSynchArtId' or ( oxobjectid is null )";
00049         }
00050 
00051         return $sQAdd;
00052     }
00053 
00059     public function removegroupfromcatbuy()
00060     {
00061         $myConfig = $this->getConfig();
00062 
00063         $aGroups = $this->_getActionIds( 'oxgroups.oxrrid' );
00064         $soxId   = oxConfig::getParameter( 'oxid');
00065 
00066         $iRange  = oxConfig::getParameter( 'oxrrapplyrange');
00067         $iAction = 2;
00068 
00069         // removing all
00070         if ( oxConfig::getParameter( 'all' ) ) {
00071             $sGroupTable = getViewName('oxgroups');
00072             $aGroups = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxrrid ".$this->_getQuery() ) );
00073         }
00074 
00075         if ( $soxId != "-1" && isset( $soxId) && count($aGroups)) {
00076             $aIndexes = array();
00077             foreach ($aGroups as $iRRIdx) {
00078                 $iOffset = ( int ) ( $iRRIdx / 31 );
00079                 $iBitMap = 1 << ( $iRRIdx % 31 );
00080 
00081                 // summing indexes
00082                 if ( !isset( $aIndexes[ $iOffset ] ) )
00083                     $aIndexes[ $iOffset ] = $iBitMap;
00084                 else
00085                     $aIndexes[ $iOffset ] = $aIndexes [ $iOffset ] | $iBitMap;
00086             }
00087 
00088             $oCat = oxNew( "oxcategory" );
00089             $oCat->load( $soxId);
00090 
00091             $sShopID  = $myConfig->getShopID();
00092 
00093             $iShopBit = oxUtils::getInstance()->getShopBit($sShopID);
00094             $sO2CView = getViewName('oxobject2category');
00095 
00096             // iterating through indexes and applying to (sub)categories R&R
00097             foreach ( $aIndexes as $iOffset => $sIdx ) {
00098                 // processing category
00099                 $sQ  = "update oxobjectrights set oxgroupidx = oxgroupidx & ~$sIdx where oxobjectid = '$soxId' and oxoffset = $iOffset and oxaction = $iAction ";
00100                 oxDb::getDb()->Execute( $sQ );
00101 
00102                 // processing articles
00103                 $sQ  = "update oxobjectrights set oxgroupidx = oxgroupidx & ~$sIdx where oxaction = $iAction and oxoffset = $iOffset and oxobjectid in ( ";
00104                 $sQ .= "select oxobject2category.oxobjectid from  $sO2CView as oxobject2category where oxobject2category.oxcatnid='$soxId' ) ";
00105                 oxDb::getDb()->Execute( $sQ );
00106 
00107                 if ($iRange) {
00108                     // processing subcategories
00109                     $sQ  = "update oxobjectrights, oxcategories set oxobjectrights.oxgroupidx = oxobjectrights.oxgroupidx & ~$sIdx where oxobjectrights.oxoffset = $iOffset and oxobjectrights.oxaction = $iAction ";
00110                     $sQ .= "and oxobjectrights.oxobjectid = oxcategories.oxid and ";
00111                     $sQ .= "( ( oxcategories.oxshopincl & $iShopBit ) > 0 and ( oxcategories.oxshopexcl & $iShopBit ) = 0 ) and ";
00112                     $sQ .= "oxcategories.oxleft > ".$oCat->oxcategories__oxleft->value." and oxcategories.oxright < ".$oCat->oxcategories__oxright->value." and ";
00113                     $sQ .= "oxcategories.oxrootid='".$oCat->oxcategories__oxrootid->value."' ";
00114                     oxDb::getDb()->Execute( $sQ );
00115 
00116                     // processing articles
00117                     $sQ  = "update oxobjectrights set oxobjectrights.oxgroupidx = oxobjectrights.oxgroupidx & ~$sIdx ";
00118                     $sQ .= "where oxobjectrights.oxaction = $iAction and oxobjectrights.oxobjectid in ( ";
00119                     $sQ .= "select oxobject2category.oxobjectid from $sO2CView as oxobject2category ";
00120                     $sQ .= "left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
00121                     $sQ .= "where ( ( oxcategories.oxshopincl & $iShopBit ) > 0 and ( oxcategories.oxshopexcl & $iShopBit ) = 0 ) and ";
00122                     $sQ .= "oxcategories.oxrootid = '".$oCat->oxcategories__oxrootid->value."' and ";
00123                     $sQ .= "oxcategories.oxleft > ".$oCat->oxcategories__oxleft->value." and ";
00124                     $sQ .= "oxcategories.oxright < ".$oCat->oxcategories__oxright->value." ) ";
00125                     oxDb::getDb()->Execute( $sQ );
00126                 }
00127             }
00128 
00129             // removing cleared
00130             $sQ = "delete from oxobjectrights where oxgroupidx = 0";
00131             oxDb::getDb()->Execute( $sQ );
00132         }
00133     }
00134 
00140     public function addgrouptocatbuy()
00141     {
00142         $myConfig = $this->getConfig();
00143 
00144         $aGroups = $this->_getActionIds( 'oxgroups.oxrrid' );
00145         $soxId   = oxConfig::getParameter( 'synchoxid');
00146 
00147         $iRange  = oxConfig::getParameter( 'oxrrapplyrange');
00148         $iAction = 2;
00149 
00150         // adding
00151         if ( oxConfig::getParameter( 'all' ) ) {
00152             $sGroupTable = getViewName('oxgroups');
00153             $aGroups = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxrrid ".$this->_getQuery() ) );
00154         }
00155 
00156         if ( $soxId != "-1" && isset( $soxId) && count($aGroups)) {
00157             $aIndexes = array();
00158             foreach ($aGroups as $iRRIdx) {
00159                 $iOffset = ( int ) ( $iRRIdx / 31 );
00160                 $iBitMap = 1 << ( $iRRIdx % 31 );
00161 
00162                 // summing indexes
00163                 if ( !isset( $aIndexes[ $iOffset ] ) )
00164                     $aIndexes[ $iOffset ] = $iBitMap;
00165                 else
00166                     $aIndexes[ $iOffset ] = $aIndexes [ $iOffset ] | $iBitMap;
00167             }
00168 
00169             $oCat = oxNew( "oxcategory" );
00170             $oCat->load( $soxId);
00171 
00172             $sShopID  = $myConfig->getShopID();
00173             //$iShopBit = pow( 2, ( $sShopID - 1 ) );
00174             $iShopBit = oxUtils::getInstance()->getShopBit($sShopID);
00175             $sO2CView = getViewName('oxobject2category');
00176 
00177             // iterating through indexes and applying to (sub)categories R&R
00178             foreach ( $aIndexes as $iOffset => $sIdx ) {
00179                 // processing category
00180                 $sQ  = "insert into oxobjectrights (oxid, oxobjectid, oxgroupidx, oxoffset, oxaction) ";
00181                 $sQ .= "values ('".oxUtilsObject::getInstance()->generateUID()."', '$soxId', $sIdx, $iOffset,  $iAction ) on duplicate key update oxgroupidx = (oxgroupidx | $sIdx ) ";
00182                 oxDb::getDb()->Execute( $sQ );
00183 
00184                 // processing articles
00185                 $sQ  = "insert into oxobjectrights (oxid, oxobjectid, oxgroupidx, oxoffset, oxaction) ";
00186                 $sQ .= "select md5( concat( a.oxobjectid, oxobject2category.oxid) ), oxobject2category.oxobjectid, a.oxgroupidx, a.oxoffset, a.oxaction ";
00187                 $sQ .= "from $sO2CView as oxobject2category left join oxobjectrights a on oxobject2category.oxcatnid=a.oxobjectid where oxobject2category.oxcatnid='$soxId' and a.oxaction = $iAction ";
00188                 $sQ .= "on duplicate key update oxobjectrights.oxgroupidx = (oxobjectrights.oxgroupidx | a.oxgroupidx ) ";
00189                 oxDb::getDb()->Execute( $sQ );
00190 
00191                 if ( $iRange ) {
00192                     // processing subcategories
00193                     $sQ  = "insert into oxobjectrights (oxid, oxobjectid, oxgroupidx, oxoffset, oxaction) ";
00194                     $sQ .= "select '".oxUtilsObject::getInstance()->generateUID()."', oxcategories.oxid, $sIdx, $iOffset, $iAction from oxcategories ";
00195                     $sQ .= "where ( ( oxcategories.oxshopincl & $iShopBit ) > 0 and ( oxcategories.oxshopexcl & $iShopBit ) = 0 ) and ";
00196                     $sQ .= "oxcategories.oxleft > ".$oCat->oxcategories__oxleft->value." and oxcategories.oxright < ".$oCat->oxcategories__oxright->value." and ";
00197                     $sQ .= "oxcategories.oxrootid='".$oCat->oxcategories__oxrootid->value."' ";
00198                     $sQ .= "on duplicate key update oxgroupidx = (oxgroupidx | $sIdx ) ";
00199                     oxDb::getDb()->Execute( $sQ );
00200 
00201                     // processing articles
00202                     $sQ  = "insert into oxobjectrights (oxid, oxobjectid, oxgroupidx, oxoffset, oxaction) ";
00203                     $sQ .= "select md5( concat( a.oxobjectid, oxobject2category.oxid, a.oxaction, a.oxoffset) ), oxobject2category.oxobjectid, a.oxgroupidx, a.oxoffset, a.oxaction ";
00204                     $sQ .= "from $sO2CView oxobject2category ";
00205                     $sQ .= "left join oxcategories on oxcategories.oxid = oxobject2category.oxcatnid ";
00206                     $sQ .= "left join oxobjectrights a on a.oxobjectid = '$soxId' ";
00207                     $sQ .= "where oxcategories.oxrootid = '".$oCat->oxcategories__oxrootid->value."' and ";
00208                     $sQ .= "oxcategories.oxleft > ".$oCat->oxcategories__oxleft->value." and  ";
00209                     $sQ .= "oxcategories.oxright < ".$oCat->oxcategories__oxright->value." and a.oxaction = $iAction ";
00210                     $sQ .= "on duplicate key update oxobjectrights.oxgroupidx = (oxobjectrights.oxgroupidx | a.oxgroupidx )";
00211                     oxDb::getDb()->Execute( $sQ );
00212                 }
00213             }
00214         }
00215     }
00216 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5