AntonLV %!s(int64=5) %!d(string=hai) anos
pai
achega
29a329d9dd

+ 5 - 0
modules/base/general/classes/BxBaseModGeneralDb.php

@@ -60,6 +60,11 @@ class BxBaseModGeneralDb extends BxDolModuleDb
                 if(empty($aParams['conditions']))
                     break;
 
+                if(isset($aParams['count']) && $aParams['count'] === true) {
+                    $aMethod['name'] = 'getOne';
+                    $sSelectClause = 'COUNT(`' . $CNF['TABLE_ENTRIES'] . "`.`" . $CNF['FIELD_ID'] . '`)';
+                }
+
                 if(is_array($aParams['conditions']))
                     $sWhereClause .= " AND " . $this->arrayToSQL($aParams['conditions'], ' AND ');
                 else if(is_string($aParams['conditions']) && !empty($aParams['bindings']) && is_array($aParams['bindings'])) {

+ 1 - 0
modules/boonex/ads/classes/BxAdsConfig.php

@@ -48,6 +48,7 @@ class BxAdsConfig extends BxBaseModTextConfig
             'FIELD_AUTHOR' => 'author',
             'FIELD_ADDED' => 'added',
             'FIELD_CHANGED' => 'changed',
+            'FIELD_SOLD' => 'sold',
             'FIELD_SHIPPED' => 'shipped',
             'FIELD_RECEIVED' => 'received',
             'FIELD_TITLE' => 'title',

+ 12 - 0
modules/boonex/ads/classes/BxAdsDb.php

@@ -454,6 +454,18 @@ class BxAdsDb extends BxBaseModTextDb
                     $sWhereClause = " AND `to`.`id`=:id";
                     break;
 
+                case 'content_id':
+                    $aMethod['params'][1]['content_id'] = (int)$aParams['content_id'];
+
+                    $sWhereClause = " AND `to`.`content_id`=:content_id";
+
+                    if(isset($aParams['count']) && $aParams['count'] === true) {
+                        $aMethod['name'] = 'getOne';
+
+                        $sSelectClause = "COUNT(`to`.`id`)";
+                    }
+                    break;
+
                 case 'accepted':
                     $aMethod['name'] = 'getRow';
                     $aMethod['params'][1]['content_id'] = (int)$aParams['content_id'];

+ 5 - 15
modules/boonex/ads/classes/BxAdsGridOffers.php

@@ -34,30 +34,20 @@ class BxAdsGridOffers extends BxTemplGrid
 
     public function performActionAccept()
     {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
         $iId = $this->_getId();
-        if($iId && $this->_oModule->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_ACCEPTED), array($CNF['FIELD_OFR_ID'] => $iId))) {
-            $this->_oModule->onOfferAccepted($iId);
-
-            $aResult = array('grid' => $this->getCode(false),  'blick' => $iId);
-        }
+        if($iId && $this->_oModule->offerAccept($iId))
+            $aResult = array('grid' => $this->getCode(false), 'blick' => $iId);
         else
             $aResult = array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
 
         echoJson($aResult);
     }
-    
+
     public function performActionDecline()
     {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
         $iId = $this->_getId();
-        if($iId && $this->_oModule->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_DECLINED), array($CNF['FIELD_OFR_ID'] => $iId))) {
-            $this->_oModule->onOfferDeclined($iId);
-
-            $aResult = array('grid' => $this->getCode(false),  'blick' => $iId);
-        }
+        if($iId && $this->_oModule->offerDecline($iId))
+            $aResult = array('grid' => $this->getCode(false), 'blick' => $iId);
         else
             $aResult = array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
 

+ 86 - 14
modules/boonex/ads/classes/BxAdsModule.php

@@ -114,6 +114,16 @@ class BxAdsModule extends BxBaseModTextModule
         return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
     }
 
+    public function actionShow()
+    {
+        return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_ACTIVE));
+    }
+
+    public function actionHide()
+    {
+        return echoJson($this->_actionChangeStatus(BX_BASE_MOD_TEXT_STATUS_HIDDEN));
+    }
+
     public function actionMakeOffer()
     {
         $CNF = &$this->_oConfig->CNF;
@@ -175,25 +185,32 @@ class BxAdsModule extends BxBaseModTextModule
         return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
     }
 
-    public function actionCancelOffer()
+    public function actionAcceptOffer()
     {
-        $CNF = &$this->_oConfig->CNF;
+        $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
 
-        $iOfferId = bx_process_input(bx_get('id'), BX_DATA_INT);
-        $aOffer = $this->_oDb->getOffersBy(array(
-            'type' => 'id', 
-            'id' => $iOfferId
-        ));
+        if(!$this->offerAccept($iId))
+            return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
 
-        if(empty($aOffer) || !is_array($aOffer))
-            return echoJson(array());
+        return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_accepted'), 'reload' => 1));
+    }
+
+    public function actionDeclineOffer()
+    {
+        $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
 
-        if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_CANCELED), array($CNF['FIELD_OFR_ID'] => $iOfferId)))
+        if(!$this->offerDecline($iId))
             return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
 
-        $this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $aOffer[$CNF['FIELD_OFR_CONTENT']]));
+        return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_declined'), 'reload' => 1));
+    }
+            
+    public function actionCancelOffer()
+    {
+        $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
 
-        $this->onOfferCanceled($iOfferId);
+        if(!$this->offerCancel($iId))
+            return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));     
 
         return echoJson(array('msg' => _t('_bx_ads_txt_msg_offer_canceled'), 'reload' => 1));
     }
@@ -743,7 +760,8 @@ class BxAdsModule extends BxBaseModTextModule
         $iEntryQnt -= $iItemCount;
         $this->_oDb->updateEntriesBy(array(
             $CNF['FIELD_QUANTITY'] => $iEntryQnt,
-            $CNF['FIELD_STATUS'] => $iEntryQnt == 0 ? BX_ADS_STATUS_SOLD : BX_BASE_MOD_TEXT_STATUS_ACTIVE
+            $CNF['FIELD_STATUS'] => $iEntryQnt == 0 ? BX_ADS_STATUS_SOLD : BX_BASE_MOD_TEXT_STATUS_ACTIVE,
+            $CNF['FIELD_SOLD'] => $iEntryQnt == 0 ? time() : 0,
         ), array($CNF['FIELD_ID'] => $iItemId));
 
         bx_alert($this->getName(), 'license_register', 0, false, array(
@@ -1151,7 +1169,7 @@ class BxAdsModule extends BxBaseModTextModule
 
         return CHECK_ACTION_RESULT_ALLOWED;
     }
-    
+
     public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
     {
         return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
@@ -1280,6 +1298,9 @@ class BxAdsModule extends BxBaseModTextModule
         if(empty($aContentInfo) || !is_array($aContentInfo))
             return;
 
+        if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $iContentId)))
+            return;
+
         $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
         $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
 
@@ -1361,6 +1382,39 @@ class BxAdsModule extends BxBaseModTextModule
         bx_alert($this->getName(), 'received', $iContentId, false, $aParams);
     }
 
+    public function offerAccept($iId) 
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_ACCEPTED), array($CNF['FIELD_OFR_ID'] => $iId)))
+            return false;
+    
+        $this->onOfferAccepted($iId);
+        return true;        
+    }
+
+    public function offerDecline($iId) 
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_DECLINED), array($CNF['FIELD_OFR_ID'] => $iId)))
+            return false;
+    
+        $this->onOfferDeclined($iId);
+        return true;        
+    }
+
+    public function offerCancel($iId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!$this->_oDb->updateOffer(array($CNF['FIELD_OFR_STATUS'] => BX_ADS_OFFER_STATUS_CANCELED), array($CNF['FIELD_OFR_ID'] => $iId)))
+            return false;
+
+        $this->onOfferCanceled($iId);
+        return true;
+    }
+
     public function processMetasAdd($iContentId)
     {
         if(!parent::processMetasAdd($iContentId))
@@ -1444,6 +1498,24 @@ class BxAdsModule extends BxBaseModTextModule
         );
     }
 
+    protected function _actionChangeStatus($sStatus)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+
+        if(($mixedResult = $this->checkAllowedEdit($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
+            return array('msg' => $mixedResult);
+
+        if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => $sStatus), array($CNF['FIELD_ID'] => $iContentId)))
+            return array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
+
+        return array(
+            'reload' => 1
+        );
+    }
+
     protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
     {
         $CNF = &$this->_oConfig->CNF;

+ 2 - 0
modules/boonex/ads/install/langs/en.xml

@@ -541,6 +541,8 @@
     <string name="_bx_ads_txt_msg_auction_sold"><![CDATA[This ad was sold.]]></string>
     <string name="_bx_ads_txt_msg_author_notified"><![CDATA[Advertiser was notified, that you're interested in his ad. Please wait.]]></string>
     <string name="_bx_ads_txt_msg_offer_added"><![CDATA[Your offer was added. Advertiser will be notified about it. Please wait.]]></string>
+    <string name="_bx_ads_txt_msg_offer_accepted"><![CDATA[The offer was accepted.]]></string>
+    <string name="_bx_ads_txt_msg_offer_declined"><![CDATA[The offer was declined.]]></string>
     <string name="_bx_ads_txt_msg_offer_canceled"><![CDATA[The offer was canceled.]]></string>
     <string name="_bx_ads_txt_err_offer_duplicate"><![CDATA[You already made an offer. Please wait for the results.]]></string>
     <string name="_bx_ads_txt_err_offer_accepted"><![CDATA[Your offer was already accepted.]]></string>

+ 1 - 0
modules/boonex/ads/install/sql/install.sql

@@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS `bx_ads_entries` (
   `author` int(11) NOT NULL,
   `added` int(11) NOT NULL,
   `changed` int(11) NOT NULL,
+  `sold` int(11) NOT NULL,
   `shipped` int(11) NOT NULL,
   `received` int(11) NOT NULL,
   `category` int(11) NOT NULL,

+ 24 - 0
modules/boonex/ads/js/entry.js

@@ -22,12 +22,36 @@ BxAdsEntry.prototype.interested = function(oElement, iContentId) {
     this._performAction(oElement, 'interested', iContentId);
 };
 
+BxAdsEntry.prototype.show = function(oElement, iContentId) {
+    this._performAction(oElement, 'show', iContentId);
+};
+
+BxAdsEntry.prototype.hide = function(oElement, iContentId) {
+    this._performAction(oElement, 'hide', iContentId);
+};
+
 BxAdsEntry.prototype.makeOffer = function(oElement, iContentId) {
     this._performAction(oElement, 'make_offer', iContentId);
 };
 
 BxAdsEntry.prototype.onMakeOffer = function(oData) {};
 
+BxAdsEntry.prototype.acceptOffer = function(oElement, iOfferId) {
+    var $this = this;
+
+    bx_confirm('', function() {
+        $this._performAction(oElement, 'accept_offer', iOfferId);
+    });
+};
+
+BxAdsEntry.prototype.declineOffer = function(oElement, iOfferId) {
+    var $this = this;
+
+    bx_confirm('', function() {
+        $this._performAction(oElement, 'decline_offer', iOfferId);
+    });
+};
+
 BxAdsEntry.prototype.cancelOffer = function(oElement, iOfferId) {
     var $this = this;
 

+ 2 - 0
modules/boonex/russian/data/langs/bx_ads/ru.xml

@@ -533,6 +533,8 @@
     <string name="_bx_ads_txt_msg_auction_sold"><![CDATA[Продано.]]></string>
     <string name="_bx_ads_txt_msg_author_notified"><![CDATA[Рекламодатель был оповещен, что Вы заинтересованы в его объявлении. Пожалуйста ждите.]]></string>
     <string name="_bx_ads_txt_msg_offer_added"><![CDATA[Ваше предложение было сохранено. Рекламодатель будет оповещен об этом. Пожалуйста ждите.]]></string>
+    <string name="_bx_ads_txt_msg_offer_accepted"><![CDATA[Предложение было принято.]]></string>
+    <string name="_bx_ads_txt_msg_offer_declined"><![CDATA[Предложение было отклонено.]]></string>
     <string name="_bx_ads_txt_msg_offer_canceled"><![CDATA[Предложение было отменено.]]></string>
     <string name="_bx_ads_txt_err_offer_duplicate"><![CDATA[Вы уже сделали ваше предложение. Пожалуйста ожидайте результатов.]]></string>
     <string name="_bx_ads_txt_err_offer_accepted"><![CDATA[Ваше предложение Your offer was already accepted.]]></string>

+ 1 - 2
template/scripts/BxBaseMenuAccountDashboard.php

@@ -25,8 +25,7 @@ class BxBaseMenuAccountDashboard extends BxTemplMenu
      */
     protected function _isVisible ($a)
     {
-        // default visible settings
-        if (!BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']))
+        if(!parent::_isVisible($a))
             return false;
 
         switch ($a['name']) {