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

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