article_extend_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_extend_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxcategories', 1, 1, 0),
00016         array('oxdesc', 'oxcategories', 1, 1, 0),
00017         array('oxid', 'oxcategories', 0, 0, 0),
00018         array('oxid', 'oxcategories', 0, 0, 1)
00019     ),
00020                                  'container2' => array(
00021                                      array('oxtitle', 'oxcategories', 1, 1, 0),
00022                                      array('oxdesc', 'oxcategories', 1, 1, 0),
00023                                      array('oxid', 'oxcategories', 0, 0, 0),
00024                                      array('oxid', 'oxobject2category', 0, 0, 1),
00025                                      array('oxtime', 'oxobject2category', 0, 0, 1),
00026                                      array('oxid', 'oxcategories', 0, 0, 1)
00027                                  ),
00028     );
00029 
00035     protected function _getQuery()
00036     {
00037         $sCategoriesTable = $this->_getViewName('oxcategories');
00038         $sO2CView = $this->_getViewName('oxobject2category');
00039         $oDb = oxDb::getDb();
00040 
00041         $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
00042         $sSynchOxid = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00043 
00044         if ($sOxid) {
00045             // all categories article is in
00046             $sQAdd = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00047             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote($sOxid)
00048                       . " and $sCategoriesTable.oxid is not null ";
00049         } else {
00050             $sQAdd = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
00051             $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView "
00052                       . "left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
00053             $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote($sSynchOxid)
00054                       . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
00055         }
00056 
00057         return $sQAdd;
00058     }
00059 
00067     protected function _getDataFields($sQ)
00068     {
00069         $aDataFields = parent::_getDataFields($sQ);
00070         if (oxRegistry::getConfig()->getRequestParameter('oxid') && is_array($aDataFields) && count($aDataFields)) {
00071 
00072             // looking for smallest time value to mark record as main category ..
00073             $iMinPos = null;
00074             $iMinVal = null;
00075             reset($aDataFields);
00076             while (list($iPos, $aField) = each($aDataFields)) {
00077 
00078                 // already set ?
00079                 if ($aField['_3'] == '0') {
00080                     $iMinPos = null;
00081                     break;
00082                 }
00083 
00084                 if (!$iMinVal) {
00085                     $iMinVal = $aField['_3'];
00086                     $iMinPos = $iPos;
00087                 } elseif ($iMinVal > $aField['_3']) {
00088                     $iMinPos = $iPos;
00089                 }
00090             }
00091 
00092             // setting primary category
00093             if (isset($iMinPos)) {
00094                 $aDataFields[$iMinPos]['_3'] = '0';
00095             }
00096         }
00097 
00098         return $aDataFields;
00099     }
00100 
00104     public function removeCat()
00105     {
00106         $myConfig = $this->getConfig();
00107         $aRemoveCat = $this->_getActionIds('oxcategories.oxid');
00108 
00109         $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
00110         $sShopID = $myConfig->getShopId();
00111         $oDb = oxDb::getDb();
00112 
00113         // adding
00114         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00115             $sCategoriesTable = $this->_getViewName('oxcategories');
00116             $aRemoveCat = $this->_getAll($this->_addFilter("select {$sCategoriesTable}.oxid " . $this->_getQuery()));
00117         }
00118 
00119         // removing all
00120         if (is_array($aRemoveCat) && count($aRemoveCat)) {
00121 
00122             $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= "
00123                   . oxDb::getDb()->quote($soxId) . " and ";
00124             $sQ .= " oxcatnid in (" . implode(', ', oxDb::getInstance()->quoteArray($aRemoveCat)) . ')';
00125             $oDb->Execute($sQ);
00126 
00127             // updating oxtime values
00128             $this->_updateOxTime($soxId);
00129         }
00130 
00131         $this->resetArtSeoUrl($soxId, $aRemoveCat);
00132         $this->resetContentCache();
00133 
00134     }
00135 
00139     public function addCat()
00140     {
00141         $myConfig = $this->getConfig();
00142         $oDb = oxDb::getDb();
00143         $aAddCat = $this->_getActionIds('oxcategories.oxid');
00144         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00145         $sShopID = $myConfig->getShopId();
00146         $sO2CView = $this->_getViewName('oxobject2category');
00147 
00148         // adding
00149         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00150             $sCategoriesTable = $this->_getViewName('oxcategories');
00151             $aAddCat = $this->_getAll($this->_addFilter("select $sCategoriesTable.oxid " . $this->_getQuery()));
00152         }
00153 
00154         if (isset($aAddCat) && is_array($aAddCat)) {
00155 
00156             $oDb = oxDb::getDb();
00157 
00158             $oNew = oxNew('oxobject2category');
00159             $myUtilsObj = oxUtilsObject::getInstance();
00160 
00161             foreach ($aAddCat as $sAdd) {
00162                 // check, if it's already in, then don't add it again
00163                 $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= "
00164                            . $oDb->quote($sAdd) . " and oxobject2category.oxobjectid = " . $oDb->quote($soxId) . " ";
00165                 if ($oDb->getOne($sSelect, false, false)) {
00166                     continue;
00167                 }
00168 
00169                 $oNew->setId(md5($soxId . $sAdd . $sShopID));
00170                 $oNew->oxobject2category__oxobjectid = new oxField($soxId);
00171                 $oNew->oxobject2category__oxcatnid = new oxField($sAdd);
00172                 $oNew->oxobject2category__oxtime = new oxField(time());
00173 
00174                 $oNew->save();
00175             }
00176 
00177             $this->_updateOxTime($soxId);
00178 
00179             $this->resetArtSeoUrl($soxId);
00180             $this->resetContentCache();
00181 
00182         }
00183     }
00184 
00190     protected function _updateOxTime($soxId)
00191     {
00192         $oDb = oxDb::getDb();
00193         $sO2CView = $this->_getViewName('oxobject2category');
00194         $soxId = $oDb->quote($soxId);
00195         $sSqlShopFilter = "";
00196         // updating oxtime values
00197         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} {$sSqlShopFilter} and oxid = (
00198                     select oxid from (
00199                         select oxid from {$sO2CView} where oxobjectid = {$soxId} {$sSqlShopFilter}
00200                         order by oxtime limit 1
00201                     ) as _tmp
00202                 )";
00203         $oDb->execute($sQ);
00204     }
00205 
00209     public function setAsDefault()
00210     {
00211         $sDefCat = oxRegistry::getConfig()->getRequestParameter("defcat");
00212         $soxId = oxRegistry::getConfig()->getRequestParameter("oxid");
00213         $oDb = oxDb::getDb();
00214 
00215         $sQuotedOxId = $oDb->quote($soxId);
00216         $sQuotedDefCat = $oDb->quote($sDefCat);
00217 
00218         $sSqlShopFilter = "";
00219 
00220         // #0003650: increment all product references independent to active shop
00221         $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = {$sQuotedOxId} {$sSqlShopFilter}";
00222         oxDb::getInstance()->getDb()->Execute($sQ);
00223 
00224         // set main category for active shop
00225         $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$sQuotedOxId} " .
00226               "and oxcatnid = {$sQuotedDefCat} {$sSqlShopFilter}";
00227         oxDb::getInstance()->getDb()->Execute($sQ);
00228         //echo "\n$sQ\n";
00229 
00230         // #0003366: invalidate article SEO for all shops
00231         oxRegistry::get("oxSeoEncoder")->markAsExpired($soxId, null, 1, null, "oxtype='oxarticle'");
00232         $this->resetContentCache();
00233     }
00234 }