Skip to content

Commit

Permalink
Ticket #3265
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Mar 16, 2021
1 parent 36de296 commit 47edd31
Show file tree
Hide file tree
Showing 31 changed files with 2,332 additions and 101 deletions.
78 changes: 76 additions & 2 deletions modules/boonex/ads/classes/BxAdsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

class BxAdsConfig extends BxBaseModTextConfig
{
protected $_oDb;

protected $_aCurrency;

protected $_bAuction;

function __construct($aModule)
{
parent::__construct($aModule);
Expand All @@ -33,20 +39,27 @@ function __construct($aModule)
'TABLE_CATEGORIES' => $aModule['db_prefix'] . 'categories',
'TABLE_CATEGORIES_TYPES' => $aModule['db_prefix'] . 'categories_types',
'TABLE_INTERESTED_TRACK' => $aModule['db_prefix'] . 'interested_track',
'TABLE_LICENSES' => $aModule['db_prefix'] . 'licenses',
'TABLE_LICENSES_DELETED' => $aModule['db_prefix'] . 'licenses_deleted',
'TABLE_OFFERS' => $aModule['db_prefix'] . 'offers',

// database fields
'FIELD_ID' => 'id',
'FIELD_AUTHOR' => 'author',
'FIELD_ADDED' => 'added',
'FIELD_CHANGED' => 'changed',
'FIELD_TITLE' => 'title',
'FIELD_NAME' => 'name',
'FIELD_TEXT' => 'text',
'FIELD_TEXT_ID' => 'ad-text',
'FIELD_CATEGORY' => 'category',
'FIELD_CATEGORY_VIEW' => 'category_view',
'FIELD_CATEGORY_SELECT' => 'category_select',
'FIELD_PRICE' => 'price',
'FIELD_AUCTION' => 'auction',
'FIELD_QUANTITY' => 'quantity',
'FIELD_YEAR' => 'year',
'FIELD_NOTES_PURCHASED' => 'notes_purchased',
'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
'FIELD_COVER' => 'covers',
'FIELD_PHOTO' => 'pictures',
Expand All @@ -66,8 +79,18 @@ function __construct($aModule)
'FIELDS_WITH_KEYWORDS' => 'auto', // can be 'auto', array of fields or comma separated string of field names, works only when OBJECT_METATAGS is specified
'FIELDS_DELAYED_PROCESSING' => 'videos', // can be array of fields or comma separated string of field names

'FIELD_OFR_ID' => 'id',
'FIELD_OFR_CONTENT' => 'content_id',
'FIELD_OFR_AUTHOR' => 'author_id',
'FIELD_OFR_ADDED' => 'added',
'FIELD_OFR_CHANGED' => 'changed',
'FIELD_OFR_AMOUNT' => 'amount',
'FIELD_OFR_QUANTITY' => 'quantity',
'FIELD_OFR_STATUS' => 'status',

// page URIs
'URI_VIEW_ENTRY' => 'view-ad',
'URI_VIEW_ENTRY_OFFERS' => 'view-ad-offers',
'URI_AUTHOR_ENTRIES' => 'ads-author',
'URI_ENTRIES_BY_CONTEXT' => 'ads-context',
'URI_ADD_ENTRY' => 'create-ad',
Expand All @@ -80,10 +103,13 @@ function __construct($aModule)
'URL_CATEGORIES' => 'page.php?i=ads-categories',
'URL_MANAGE_COMMON' => 'page.php?i=ads-manage',
'URL_MANAGE_ADMINISTRATION' => 'page.php?i=ads-administration',
'URL_LICENSES_COMMON' => 'page.php?i=ads-licenses',
'URL_LICENSES_ADMINISTRATION' => 'page.php?i=ads-licenses-administration',

'GET_PARAM_CATEGORY' => 'category',

// some params
'PARAM_AUTO_APPROVE' => 'bx_ads_enable_auto_approve',
'PARAM_CHARS_SUMMARY' => 'bx_ads_summary_chars',
'PARAM_CHARS_SUMMARY_PLAIN' => 'bx_ads_plain_summary_chars',
'PARAM_NUM_RSS' => 'bx_ads_rss_num',
Expand All @@ -92,6 +118,7 @@ function __construct($aModule)
'PARAM_LIFETIME' => 'bx_ads_lifetime',
'PARAM_USE_IIN' => 'bx_ads_internal_interested_notification',
'PARAM_CATEGORY_LEVEL_MAX' => 1,
'PARAM_USE_AUCTION' => 'bx_ads_enable_auction',

// objects
'OBJECT_STORAGE' => 'bx_ads_covers',
Expand Down Expand Up @@ -135,6 +162,8 @@ function __construct($aModule)
'OBJECT_FORM_ENTRY_DISPLAY_DELETE' => 'bx_ads_entry_delete',
'OBJECT_FORM_POLL' => 'bx_ads_poll',
'OBJECT_FORM_POLL_DISPLAY_ADD' => 'bx_ads_poll_add',
'OBJECT_FORM_OFFER' => 'bx_ads_offer',
'OBJECT_FORM_OFFER_DISPLAY_ADD' => 'bx_ads_offer_add',
'OBJECT_MENU_ENTRY_ATTACHMENTS' => 'bx_ads_entry_attachments', // attachments menu in create/edit forms
'OBJECT_MENU_ACTIONS_VIEW_ENTRY' => 'bx_ads_view', // actions menu on view entry page
'OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL' => 'bx_ads_view_actions', // all actions menu on view entry page
Expand All @@ -144,9 +173,14 @@ function __construct($aModule)
'OBJECT_MENU_SUBMENU_VIEW_ENTRY_MAIN_SELECTION' => 'ads-home', // first item in view entry submenu from main module submenu
'OBJECT_MENU_SNIPPET_META' => 'bx_ads_snippet_meta', // menu for snippet meta info
'OBJECT_MENU_MANAGE_TOOLS' => 'bx_ads_menu_manage_tools', //manage menu in content administration tools
'OBJECT_MENU_LICENSES' => 'bx_ads_licenses_submenu',
'OBJECT_GRID_CATEGORIES' => 'bx_ads_categories',
'OBJECT_GRID_ADMINISTRATION' => 'bx_ads_administration',
'OBJECT_GRID_COMMON' => 'bx_ads_common',
'OBJECT_GRID_LICENSES_ADMINISTRATION' => 'bx_ads_licenses_administration',
'OBJECT_GRID_LICENSES' => 'bx_ads_licenses',
'OBJECT_GRID_OFFERS' => 'bx_ads_offers',
'OBJECT_GRID_OFFERS_ALL' => 'bx_ads_offers_all',
'OBJECT_UPLOADERS' => array('bx_ads_simple', 'bx_ads_html5'),

// menu items which visibility depends on custom visibility checking
Expand All @@ -170,6 +204,10 @@ function __construct($aModule)

// email templates
'ETEMPLATE_INTERESTED' => 'bx_ads_interested',
'ETEMPLATE_PURCHASED' => 'bx_ads_purchased',
'ETEMPLATE_OFFER_ADDED' => 'bx_ads_offer_added',
'ETEMPLATE_OFFER_ACCEPTED' => 'bx_ads_offer_accepted',
'ETEMPLATE_OFFER_DECLINED' => 'bx_ads_offer_declined',

// some language keys
'T' => array (
Expand All @@ -186,6 +224,7 @@ function __construct($aModule)
'grid_txt_account_manager' => '_bx_ads_grid_txt_account_manager',
'filter_item_active' => '_bx_ads_grid_filter_item_title_adm_active',
'filter_item_hidden' => '_bx_ads_grid_filter_item_title_adm_hidden',
'filter_item_pending' => '_bx_ads_grid_filter_item_title_adm_pending',
'filter_item_select_one_filter1' => '_bx_ads_grid_filter_item_title_adm_select_one_filter1',
'menu_item_manage_my' => '_bx_ads_menu_item_title_manage_my',
'menu_item_manage_all' => '_bx_ads_menu_item_title_manage_all',
Expand All @@ -209,13 +248,15 @@ function __construct($aModule)
$this->_aJsClasses = array_merge($this->_aJsClasses, array(
'manage_tools' => 'BxAdsManageTools',
'studio' => 'BxAdsStudio',
'entry' => 'BxAdsEntry'
'entry' => 'BxAdsEntry',
'form' => 'BxAdsForm',
));

$this->_aJsObjects = array_merge($this->_aJsObjects, array(
'manage_tools' => 'oBxAdsManageTools',
'studio' => 'oBxAdsStudio',
'entry' => 'oBxAdsEntry'
'entry' => 'oBxAdsEntry',
'form' => 'oBxAdsForm',
));

$this->_aGridObjects = array(
Expand All @@ -224,8 +265,41 @@ function __construct($aModule)
'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
);

$sPrefix = str_replace('_', '-', $this->_sName);
$this->_aHtmlIds = array(
'offer_popup' => $sPrefix . '-offer-popup',
);

$oPayments = BxDolPayments::getInstance();
$this->_aCurrency = array(
'code' => $oPayments->getOption('default_currency_code'),
'sign' => $oPayments->getOption('default_currency_sign')
);

$this->_bAttachmentsInTimeline = true;
}

public function init(&$oDb)
{
$this->_oDb = &$oDb;

$this->_bAuction = getParam($this->CNF['PARAM_USE_AUCTION']) == 'on';
}

public function isAuction()
{
return $this->_bAuction;
}

public function getCurrency()
{
return $this->_aCurrency;
}

public function getEntryName($sName)
{
return uriGenerate($sName, $this->CNF['TABLE_ENTRIES'], $this->CNF['FIELD_NAME']);
}
}

/** @} */
121 changes: 121 additions & 0 deletions modules/boonex/ads/classes/BxAdsDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,48 @@ public function insertInterested($aParamsSet)
return (int)$this->lastId();
}

public function registerLicense($iProfileId, $iEntryId, $iCount, $sOrder, $sLicense)
{
$CNF = &$this->_oConfig->CNF;

$aQueryParams = array(
'profile_id' => $iProfileId,
'entry_id' => $iEntryId,
'count' => $iCount,
'order' => $sOrder,
'license' => $sLicense
);

return (int)$this->query("INSERT INTO `" . $CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aQueryParams) . ", `added`=UNIX_TIMESTAMP()") > 0;
}

public function unregisterLicense($iProfileId, $iEntryId, $sOrder, $sLicense)
{
$CNF = &$this->_oConfig->CNF;

$sWhereClause = "`profile_id`=:profile_id AND `entry_id`=:entry_id AND `order`=:order AND `license`=:license";
$aWhereBindings = array(
'profile_id' => $iProfileId,
'entry_id' => $iEntryId,
'order' => $sOrder,
'license' => $sLicense
);

//--- Move to deleted licenses table with 'refund' as reason.
$sQuery = "INSERT IGNORE INTO `" . $CNF['TABLE_LICENSES_DELETED'] . "` SELECT *, 'refund' AS `reason`, UNIX_TIMESTAMP() AS `deleted` FROM `" . $CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
$this->query($sQuery, $aWhereBindings);

$sQuery = "DELETE FROM `" . $CNF['TABLE_LICENSES'] . "` WHERE " . $sWhereClause;
return $this->query($sQuery, $aWhereBindings) !== false;
}

public function updateLicense($aSet, $aWhere)
{
$CNF = &$this->_oConfig->CNF;

return (int)$this->query("UPDATE `" . $CNF['TABLE_LICENSES'] . "` SET " . $this->arrayToSQL($aSet) . " WHERE " . (!empty($aWhere) ? $this->arrayToSQL($aWhere, ' AND ') : "1")) > 0;
}

protected function _getEntriesBySearchIds($aParams, &$aMethod, &$sSelectClause, &$sJoinClause, &$sWhereClause, &$sOrderClause, &$sLimitClause)
{
$CNF = &$this->_oConfig->CNF;
Expand Down Expand Up @@ -334,6 +376,85 @@ protected function _getEntriesBySearchIds($aParams, &$aMethod, &$sSelectClause,

parent::_getEntriesBySearchIds($aParams, $aMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause);
}

public function getOffersBy($aParams = array())
{
$CNF = &$this->_oConfig->CNF;

$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query', 1 => array()));
$sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";

$sSelectClause = "`to`.*";

if(!empty($aParams['type']))
switch($aParams['type']) {
case 'id':
$aMethod['name'] = 'getRow';
$aMethod['params'][1]['id'] = (int)$aParams['id'];

$sWhereClause = " AND `to`.`id`=:id";
break;

case 'content_author_id':
$aMethod['params'][1]['author_id'] = (int)$aParams['author_id'];

$sJoinClause = "LEFT JOIN `" . $CNF['TABLE_ENTRIES'] . "` AS `te` ON `to`.`content_id`=`te`.`id`";
$sWhereClause = " AND `te`.`author`=:author_id";

if(!empty($aParams['status'])) {
$aMethod['params'][1]['status'] = $aParams['status'];

$sWhereClause .= " AND `to`.`status`=:status";
}

if(isset($aParams['count']) && $aParams['count'] === true) {
$aMethod['name'] = 'getOne';

$sSelectClause = "COUNT(`to`.`id`)";
}
break;

case 'content_and_author_ids':
if(!isset($aParams['all']) || $aParams['all'] !== true)
$aMethod['name'] = 'getRow';

$aMethod['params'][1]['content_id'] = (int)$aParams['content_id'];
$aMethod['params'][1]['author_id'] = (int)$aParams['author_id'];

$sWhereClause = " AND `to`.`content_id`=:content_id AND `to`.`author_id`=:author_id";

if(!empty($aParams['status'])) {
$aMethod['params'][1]['status'] = $aParams['status'];

$sWhereClause .= " AND `to`.`status`=:status";
}

$sOrderClause = "`to`.`added` DESC";
break;
}

if(!empty($sGroupClause))
$sGroupClause = ' GROUP BY ' . $sGroupClause;

if(!empty($sOrderClause))
$sOrderClause = ' ORDER BY ' . $sOrderClause;

if(!empty($sLimitClause))
$sLimitClause = ' LIMIT ' . $sLimitClause;

$aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `" . $CNF['TABLE_OFFERS'] . "` AS `to` " . $sJoinClause . " WHERE 1 " . $sWhereClause . $sGroupClause . $sOrderClause . $sLimitClause;
return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
}

public function updateOffer($aSet, $aWhere)
{
$CNF = &$this->_oConfig->CNF;

if(!isset($aSet[$CNF['FIELD_OFR_CHANGED']]))
$aSet[$CNF['FIELD_OFR_CHANGED']] = time();

return (int)$this->query("UPDATE `" . $CNF['TABLE_OFFERS'] . "` SET " . $this->arrayToSQL($aSet) . " WHERE " . (!empty($aWhere) ? $this->arrayToSQL($aWhere, ' AND ') : "1")) > 0;
}
}

/** @} */
37 changes: 35 additions & 2 deletions modules/boonex/ads/classes/BxAdsFormEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ public function __construct($aInfo, $oTemplate = false)

$this->_initCategoryFields();

if(isset($this->aInputs[$CNF['FIELD_TITLE']], $this->aInputs[$CNF['FIELD_NAME']])) {
$sJsObject = $this->_oModule->_oConfig->getJsObject('form');

$aMask = array('mask' => "javascript:%s.checkName('%s', '%s');", $sJsObject, $CNF['FIELD_TITLE'], $CNF['FIELD_NAME']);
if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && bx_get('id') !== false) {
$aMask['mask'] = "javascript:%s.checkName('%s', '%s', %d);";
$aMask[] = (int)bx_get('id');
}

$sOnBlur = call_user_func_array('sprintf', array_values($aMask));
$this->aInputs[$CNF['FIELD_TITLE']]['attrs']['onblur'] = $sOnBlur;
$this->aInputs[$CNF['FIELD_NAME']]['attrs']['onblur'] = $sOnBlur;
}

if(isset($CNF['FIELD_AUCTION']) && isset($this->aInputs[$CNF['FIELD_AUCTION']]) && !$this->_oModule->_oConfig->isAuction())
unset($this->aInputs[$CNF['FIELD_AUCTION']]);

if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
if($this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) {
$this->aInputs[$CNF['FIELD_COVER']]['storage_object'] = $CNF['OBJECT_STORAGE'];
Expand Down Expand Up @@ -84,8 +101,16 @@ public function __construct($aInfo, $oTemplate = false)

function getCode($bDynamicMode = false)
{
$sInclude = $this->_oModule->_oTemplate->addJs(array('entry.js'), $bDynamicMode);
return ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('entry') . parent::getCode($bDynamicMode);
$sJs = $this->_oModule->_oTemplate->addJs(array('form.js'), $bDynamicMode);

$sCode = '';
if($bDynamicMode)
$sCode .= $sJs;

$sCode .= $this->_oModule->_oTemplate->getJsCode('form');
$sCode .= parent::getCode($bDynamicMode);

return $sCode;
}

function initChecker ($aValues = array (), $aSpecificValues = array())
Expand Down Expand Up @@ -114,6 +139,9 @@ public function insert ($aValsToAdd = array(), $isIgnore = false)
{
$CNF = &$this->_oModule->_oConfig->CNF;

if(!$this->_oModule->_isModerator() && getParam($CNF['PARAM_AUTO_APPROVE']) != 'on')
$aValsToAdd[$CNF['FIELD_STATUS_ADMIN']] = BX_ADS_STATUS_PENDING;

$iContentId = parent::insert ($aValsToAdd, $isIgnore);
if(!empty($iContentId))
$this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
Expand Down Expand Up @@ -165,6 +193,11 @@ protected function genCustomViewRowValuePrice(&$aInput)
return isset($aInput['value']) && $aInput['value'] !== '' ? getParam('currency_sign') . bx_process_output($aInput['value']) : null;
}

protected function genCustomViewRowValueQuantity(&$aInput)
{
return (int)$aInput['value'] > 0 ? (int)$aInput['value'] : 0;
}

protected function _getCoverGhostTmplVars($aContentInfo = array())
{
$CNF = &$this->_oModule->_oConfig->CNF;
Expand Down
Loading

0 comments on commit 47edd31

Please sign in to comment.