Skip to content

Commit

Permalink
Ticket #3265
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Jun 22, 2021
1 parent 068931f commit 29a329d
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 31 deletions.
5 changes: 5 additions & 0 deletions modules/base/general/classes/BxBaseModGeneralDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function getEntriesBy($aParams = array())
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'])) {
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/ads/classes/BxAdsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function __construct($aModule)
'FIELD_AUTHOR' => 'author',
'FIELD_ADDED' => 'added',
'FIELD_CHANGED' => 'changed',
'FIELD_SOLD' => 'sold',
'FIELD_SHIPPED' => 'shipped',
'FIELD_RECEIVED' => 'received',
'FIELD_TITLE' => 'title',
Expand Down
12 changes: 12 additions & 0 deletions modules/boonex/ads/classes/BxAdsDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,18 @@ public function getOffersBy($aParams = array())
$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'];
Expand Down
20 changes: 5 additions & 15 deletions modules/boonex/ads/classes/BxAdsGridOffers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,20 @@ public function setContentId($iContentId)

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'));

Expand Down
100 changes: 86 additions & 14 deletions modules/boonex/ads/classes/BxAdsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public function actionInterested()
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;
Expand Down Expand Up @@ -175,25 +185,32 @@ public function actionMakeOffer()
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));
}
Expand Down Expand Up @@ -743,7 +760,8 @@ public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItem
$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(
Expand Down Expand Up @@ -1151,7 +1169,7 @@ public function checkAllowedMarkShipped($mixedContent, $isPerformAction = false)

return CHECK_ACTION_RESULT_ALLOWED;
}

public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
{
return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
Expand Down Expand Up @@ -1280,6 +1298,9 @@ public function onOfferCanceled($iOfferId)
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);

Expand Down Expand Up @@ -1361,6 +1382,39 @@ public function onReceived($mixedContent)
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))
Expand Down Expand Up @@ -1444,6 +1498,24 @@ protected function _actionMarkAs($sAction)
);
}

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;
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/ads/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/ads/install/sql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions modules/boonex/ads/js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/russian/data/langs/bx_ads/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions template/scripts/BxBaseMenuAccountDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function __construct ($aObject, $oTemplate)
*/
protected function _isVisible ($a)
{
// default visible settings
if (!BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']))
if(!parent::_isVisible($a))
return false;

switch ($a['name']) {
Expand Down

0 comments on commit 29a329d

Please sign in to comment.