diff --git a/modules/boonex/ads/classes/BxAdsConfig.php b/modules/boonex/ads/classes/BxAdsConfig.php
index 90d5b94ecf..401592d4ab 100644
--- a/modules/boonex/ads/classes/BxAdsConfig.php
+++ b/modules/boonex/ads/classes/BxAdsConfig.php
@@ -13,6 +13,12 @@
class BxAdsConfig extends BxBaseModTextConfig
{
+ protected $_oDb;
+
+ protected $_aCurrency;
+
+ protected $_bAuction;
+
function __construct($aModule)
{
parent::__construct($aModule);
@@ -33,6 +39,9 @@ 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',
@@ -40,13 +49,17 @@ function __construct($aModule)
'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',
@@ -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',
@@ -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',
@@ -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',
@@ -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
@@ -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
@@ -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 (
@@ -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',
@@ -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(
@@ -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']);
+ }
}
/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsDb.php b/modules/boonex/ads/classes/BxAdsDb.php
index 54c8771807..05a579c41e 100644
--- a/modules/boonex/ads/classes/BxAdsDb.php
+++ b/modules/boonex/ads/classes/BxAdsDb.php
@@ -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;
@@ -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;
+ }
}
/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsFormEntry.php b/modules/boonex/ads/classes/BxAdsFormEntry.php
index 3cd4424171..d89315a2bb 100644
--- a/modules/boonex/ads/classes/BxAdsFormEntry.php
+++ b/modules/boonex/ads/classes/BxAdsFormEntry.php
@@ -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'];
@@ -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())
@@ -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);
@@ -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;
diff --git a/modules/boonex/ads/classes/BxAdsFormOffer.php b/modules/boonex/ads/classes/BxAdsFormOffer.php
new file mode 100644
index 0000000000..a749288404
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsFormOffer.php
@@ -0,0 +1,49 @@
+_sModule = 'bx_ads';
+ $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+ parent::__construct($aInfo, $oTemplate);
+ }
+
+ public function insert ($aValsToAdd = array(), $isIgnore = false)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if(!isset($aValsToAdd[$CNF['FIELD_OFR_AUTHOR']]))
+ $aValsToAdd[$CNF['FIELD_OFR_AUTHOR']] = bx_get_logged_profile_id();
+
+ if(!isset($aValsToAdd[$CNF['FIELD_OFR_ADDED']]))
+ $aValsToAdd[$CNF['FIELD_OFR_ADDED']] = time();
+
+ return parent::insert ($aValsToAdd, $isIgnore);
+ }
+
+ public function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if(!isset($aValsToAdd[$CNF['FIELD_OFR_CHANGED']]))
+ $aValsToAdd[$CNF['FIELD_OFR_CHANGED']] = time();
+
+ return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsGridAdministration.php b/modules/boonex/ads/classes/BxAdsGridAdministration.php
index 8f1cbd4b16..5c9a555f74 100644
--- a/modules/boonex/ads/classes/BxAdsGridAdministration.php
+++ b/modules/boonex/ads/classes/BxAdsGridAdministration.php
@@ -16,6 +16,10 @@ public function __construct ($aOptions, $oTemplate = false)
$this->MODULE = 'bx_ads';
parent::__construct ($aOptions, $oTemplate);
+
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ $this->_aFilter1Values[BX_ADS_STATUS_PENDING] = $CNF['T']['filter_item_' . BX_ADS_STATUS_PENDING];
}
}
diff --git a/modules/boonex/ads/classes/BxAdsGridCommon.php b/modules/boonex/ads/classes/BxAdsGridCommon.php
index de345ddb48..75ba24ee7a 100644
--- a/modules/boonex/ads/classes/BxAdsGridCommon.php
+++ b/modules/boonex/ads/classes/BxAdsGridCommon.php
@@ -17,6 +17,41 @@ public function __construct ($aOptions, $oTemplate = false)
parent::__construct ($aOptions, $oTemplate);
}
+
+ protected function _getCellStatusAdmin($mixedValue, $sKey, $aField, $aRow)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if(!empty($CNF['T']['filter_item_' . $mixedValue]))
+ $mixedValue = $CNF['T']['filter_item_' . $mixedValue];
+ else
+ $mixedValue = '_undefined';
+
+ return parent::_getCellDefault(_t($mixedValue), $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
+ {
+ if(!$this->_switcherState2Checked($aRow['status_admin']))
+ return parent::_getCellDefault('', $sKey, $aField, $aRow);
+
+ return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
+ }
+
+ protected function _isRowDisabled($aRow)
+ {
+ if(parent::_isRowDisabled($aRow))
+ return true;
+
+ return !$this->_switcherState2Checked($aRow['status_admin']);
+ }
+
+ protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+ {
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `author`=?", bx_get_logged_profile_id());
+
+ return $this->__getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+ }
}
/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsGridLicenses.php b/modules/boonex/ads/classes/BxAdsGridLicenses.php
new file mode 100644
index 0000000000..9b0a6bb739
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsGridLicenses.php
@@ -0,0 +1,32 @@
+_aQueryAppend['profile_id']))
+ return array();
+
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tl`.`profile_id`=?", $this->_aQueryAppend['profile_id']);
+
+ return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsGridLicensesAdministration.php b/modules/boonex/ads/classes/BxAdsGridLicensesAdministration.php
new file mode 100644
index 0000000000..564a5db00d
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsGridLicensesAdministration.php
@@ -0,0 +1,57 @@
+_sModule = 'bx_ads';
+ $this->_oModule = BxDolModule::getInstance($this->_sModule);
+ if(!$oTemplate)
+ $oTemplate = $this->_oModule->_oTemplate;
+
+ parent::__construct ($aOptions, $oTemplate);
+
+ $this->_sDefaultSortingOrder = 'DESC';
+ $this->_aQueryReset = array($this->_aOptions['order_get_field'], $this->_aOptions['order_get_dir'], $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
+
+ $iProfileId = bx_get_logged_profile_id();
+ if($iProfileId !== false)
+ $this->_aQueryAppend['profile_id'] = (int)$iProfileId;
+ }
+
+ protected function _getCellProfileId($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault($this->_oModule->_oTemplate->getProfileLink($mixedValue), $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellEntry($mixedValue, $sKey, $aField, $aRow)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ $mixedValue = $this->_oModule->_oTemplate->getEntryLink(array(
+ $CNF['FIELD_ID'] => $aRow['entry_id'],
+ $CNF['FIELD_TITLE'] => $mixedValue,
+ ));
+
+ return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsGridOffers.php b/modules/boonex/ads/classes/BxAdsGridOffers.php
new file mode 100644
index 0000000000..fe7fd89a18
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsGridOffers.php
@@ -0,0 +1,130 @@
+_sModule = 'bx_ads';
+ $this->_oModule = BxDolModule::getInstance($this->_sModule);
+ if(!$oTemplate)
+ $oTemplate = $this->_oModule->_oTemplate;
+
+ parent::__construct ($aOptions, $oTemplate);
+
+ if(($iContentId = bx_get('content_id')) !== false)
+ $this->setContentId($iContentId);
+ }
+
+ public function setContentId($iContentId)
+ {
+ $this->_aQueryAppend['content_id'] = (int)$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);
+ }
+ 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);
+ }
+ else
+ $aResult = array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
+
+ echoJson($aResult);
+ }
+
+ protected function _getCellAuthorId($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault($this->_oModule->_oTemplate->getProfileLink($mixedValue), $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault(_t_format_currency($mixedValue), $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
+ }
+
+ protected function _getCellStatus($mixedValue, $sKey, $aField, $aRow)
+ {
+ return parent::_getCellDefault(_t('_bx_ads_txt_offer_status_' . $mixedValue), $sKey, $aField, $aRow);
+ }
+
+ protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if($aRow[$CNF['FIELD_OFR_STATUS']] != BX_ADS_OFFER_STATUS_AWAITING)
+ return '';
+
+ return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+ }
+
+ protected function _getActionDecline ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if($aRow[$CNF['FIELD_OFR_STATUS']] != BX_ADS_OFFER_STATUS_AWAITING)
+ return '';
+
+ return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+ }
+
+ protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+ {
+ if(empty($this->_aQueryAppend['content_id']))
+ return array();
+
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `content_id`=?", $this->_aQueryAppend['content_id']);
+
+ return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+ }
+
+ protected function _getId()
+ {
+ $aIds = bx_get('ids');
+ if(!empty($aIds) && is_array($aIds))
+ return array_shift($aIds);
+
+ if(($iId = bx_get('id')) !== false)
+ return (int)$iId;
+
+ return false;
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsGridOffersAll.php b/modules/boonex/ads/classes/BxAdsGridOffersAll.php
new file mode 100644
index 0000000000..34c1b05974
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsGridOffersAll.php
@@ -0,0 +1,82 @@
+_sModule = 'bx_ads';
+ $this->_oModule = BxDolModule::getInstance($this->_sModule);
+ if(!$oTemplate)
+ $oTemplate = $this->_oModule->_oTemplate;
+
+ $this->_iProfileId = bx_get_logged_profile_id();
+
+ parent::__construct ($aOptions, $oTemplate);
+ }
+
+ protected function _getCellContentId($mixedValue, $sKey, $aField, $aRow)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ $mixedValue = $this->_oModule->_oTemplate->getEntryLink(array(
+ $CNF['FIELD_ID'] => $aRow['content_id'],
+ $CNF['FIELD_TITLE'] => $aRow['content_title'],
+ ));
+
+ return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
+ }
+
+ protected function _getActionView($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY_OFFERS'], array('id' => $aRow['content_id']));
+
+ $a['attr'] = array_merge($a['attr'], array(
+ "onclick" => "window.open('" . $sUrl . "','_self');"
+ ));
+ unset($a['attr']['bx_grid_action_single']);
+
+ return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
+ }
+
+ protected function _getDataSqlOrderClause ($sOrderByFilter, $sOrderField, $sOrderDir, $bFieldsOnly = false)
+ {
+ return " GROUP BY `to`.`content_id` " . parent::_getDataSqlOrderClause ($sOrderByFilter, $sOrderField, $sOrderDir, $bFieldsOnly);
+ }
+
+ protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+ {
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `te`.`author`=?", $this->_iProfileId);
+
+ return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+ }
+
+ protected function _getId()
+ {
+ $aIds = bx_get('ids');
+ if(!empty($aIds) && is_array($aIds))
+ return array_shift($aIds);
+
+ if(($iId = bx_get('id')) !== false)
+ return (int)$iId;
+
+ return false;
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsMenuView.php b/modules/boonex/ads/classes/BxAdsMenuView.php
index ae09073201..13f582d793 100644
--- a/modules/boonex/ads/classes/BxAdsMenuView.php
+++ b/modules/boonex/ads/classes/BxAdsMenuView.php
@@ -14,18 +14,89 @@
*/
class BxAdsMenuView extends BxBaseModTextMenuView
{
+ /**
+ * Array with check_sum => JS_code pairs of all JS codes
+ * which should be added to the page.
+ */
+ protected $_aJsCodes;
+
public function __construct($aObject, $oTemplate = false)
{
$this->MODULE = 'bx_ads';
parent::__construct($aObject, $oTemplate);
+
+ $this->_aJsCodes = array();
+
+ $this->addMarkers(array(
+ 'js_object' => $this->_oModule->_oConfig->getJsObject('entry')
+ ));
+ }
+
+ public function getCode ()
+ {
+ return parent::getCode() . $this->getJsCode();
}
- public function setContentId($iContentId)
+ public function getJsCode()
{
- parent::setContentId($iContentId);
+ if(empty($this->_aJsCodes) || !is_array($this->_aJsCodes))
+ return '';
+
+ return implode('', $this->_aJsCodes);
+ }
+
+ protected function _isVisible ($a)
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ if(!parent::_isVisible($a))
+ return false;
+
+ $oPayment = BxDolPayments::getInstance();
+
+ $bResult = false;
+ switch ($a['name']) {
+ case 'add-to-cart':
+ if((float)$this->_aContentInfo[$CNF['FIELD_PRICE']] == 0 || (int)$this->_aContentInfo[$CNF['FIELD_QUANTITY']] <= 0)
+ break;
+
+ $aJs = $oPayment->getAddToCartJs($this->_aContentInfo[$CNF['FIELD_AUTHOR']], $this->MODULE, $this->_aContentInfo[$CNF['FIELD_ID']], 1, true);
+ if(empty($aJs) || !is_array($aJs))
+ break;
+
+ list($sJsCode, $sJsMethod) = $aJs;
+
+ $sJsCodeCheckSum = md5($sJsCode);
+ if(!isset($this->_aJsCodes[$sJsCodeCheckSum]))
+ $this->_aJsCodes[$sJsCodeCheckSum] = $sJsCode;
+
+ $aCurrency = $this->_oModule->_oConfig->getCurrency();
+
+ $bResult = true;
+ $this->addMarkers(array(
+ 'add_to_cart_title' => _t('_bx_market_menu_item_title_add_to_cart', $aCurrency['sign'], $this->_aContentInfo[$CNF['FIELD_PRICE']]),
+ 'add_to_cart_onclick' => $sJsMethod
+ ));
+ break;
+
+ case 'interested':
+ $bResult = $this->_aContentInfo[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id();
+ break;
+
+ case 'make-offer':
+ $bResult = $this->_oModule->isAllowedMakeOffer($this->_aContentInfo);
+ break;
+
+ case 'view-offers':
+ $bResult = $this->_oModule->isAllowedViewOffers($this->_aContentInfo);
+ break;
+
+ default:
+ $bResult = true;
+ }
- $this->addMarkers(array('js_object' => $this->_oModule->_oConfig->getJsObject('entry')));
+ return $bResult;
}
}
diff --git a/modules/boonex/ads/classes/BxAdsMenuViewActions.php b/modules/boonex/ads/classes/BxAdsMenuViewActions.php
index 11630f78bc..8dff96fb32 100644
--- a/modules/boonex/ads/classes/BxAdsMenuViewActions.php
+++ b/modules/boonex/ads/classes/BxAdsMenuViewActions.php
@@ -21,11 +21,36 @@ public function __construct($aObject, $oTemplate = false)
parent::__construct($aObject, $oTemplate);
}
+ public function getCode ()
+ {
+ $sCode = parent::getCode();
+
+ if(!empty($this->_oMenuActions))
+ $sCode .= $this->_oMenuActions->getJsCode();
+
+ return $sCode;
+ }
+
protected function _getMenuItemInterested($aItem)
{
return $this->_getMenuItemByNameActions($aItem);
}
-
+
+ protected function _getMenuItemAddToCart($aItem)
+ {
+ return $this->_getMenuItemByNameActions($aItem);
+ }
+
+ protected function _getMenuItemMakeOffer($aItem)
+ {
+ return $this->_getMenuItemByNameActions($aItem);
+ }
+
+ protected function _getMenuItemViewOffers($aItem)
+ {
+ return $this->_getMenuItemByNameActions($aItem);
+ }
+
protected function _getMenuItemEditAd($aItem)
{
return $this->_getMenuItemByNameActions($aItem);
@@ -35,6 +60,7 @@ protected function _getMenuItemDeleteAd($aItem)
{
return $this->_getMenuItemByNameActions($aItem);
}
+
protected function _getMenuItemReview($aItem, $aParams = array())
{
$CNF = &$this->_oModule->_oConfig->CNF;
diff --git a/modules/boonex/ads/classes/BxAdsModule.php b/modules/boonex/ads/classes/BxAdsModule.php
index fd2ae1520e..aee9b34374 100644
--- a/modules/boonex/ads/classes/BxAdsModule.php
+++ b/modules/boonex/ads/classes/BxAdsModule.php
@@ -9,21 +9,39 @@
* @{
*/
+define('BX_ADS_STATUS_ACTIVE', 'active');
+define('BX_ADS_STATUS_HIDDEN', 'hidden');
+define('BX_ADS_STATUS_PENDING', 'pending');
+
+define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
+define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
+define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
+
/**
* Ads module
*/
class BxAdsModule extends BxBaseModTextModule
{
+ protected $_aOfferStatuses;
+
function __construct(&$aModule)
{
parent::__construct($aModule);
+ $this->_oConfig->init($this->_oDb);
+
$CNF = &$this->_oConfig->CNF;
$this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
$CNF['FIELD_CATEGORY_VIEW'],
$CNF['FIELD_CATEGORY_SELECT']
));
+
+ $this->_aOfferStatuses = array(
+ BX_ADS_OFFER_STATUS_ACCEPTED,
+ BX_ADS_OFFER_STATUS_AWAITING,
+ BX_ADS_OFFER_STATUS_DECLINED
+ );
}
public function actionGetCategoryForm()
@@ -39,6 +57,29 @@ public function actionGetCategoryForm()
));
}
+ public function actionCheckName()
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $sName = '';
+
+ $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
+ if(empty($sTitle))
+ return echoJson(array());
+
+ $iId = (int)bx_get($CNF['FIELD_ID']);
+ if(!empty($iId)) {
+ $aEntry = $this->_oDb->getContentInfoById($iId);
+ if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
+ $sName = $sTitle;
+ }
+
+ echoJson(array(
+ 'title' => $sTitle,
+ 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
+ ));
+ }
+
public function actionInterested()
{
$CNF = &$this->_oConfig->CNF;
@@ -86,6 +127,64 @@ public function actionInterested()
return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
}
+ public function actionMakeOffer()
+ {
+ $CNF = &$this->_oConfig->CNF;
+ $sJsObject = $this->_oConfig->getJsObject('entry');
+
+ $iAuthorId = bx_get_logged_profile_id();
+ $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+
+ $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+ if(empty($aContentInfo) || !is_array($aContentInfo))
+ return echoJson(array());
+
+ $aOffer = $this->_oDb->getOffersBy(array(
+ 'type' => 'content_and_author_ids',
+ 'content_id' => $iContentId,
+ 'author_id' => $iAuthorId,
+ 'status' => BX_ADS_OFFER_STATUS_AWAITING
+ ));
+
+ if(!empty($aOffer) && is_array($aOffer))
+ return echoJson(array('code' => 1, 'msg' => _t('_bx_ads_txt_err_duplicate')));
+
+ $aOffer = $this->_oDb->getOffersBy(array(
+ 'type' => 'content_and_author_ids',
+ 'content_id' => $iContentId,
+ 'author_id' => $iAuthorId,
+ 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
+ ));
+
+ if(!empty($aOffer) && is_array($aOffer))
+ return echoJson(array('code' => 1, 'msg' => _t('_bx_ads_txt_err_offer_accepted')));
+
+ $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
+ $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', array('id' => $iContentId));
+ $oForm->initChecker();
+
+ if($oForm->isSubmittedAndValid()) {
+ $aValToAdd = array('content_id' => $iContentId, 'author_id' => $iAuthorId);
+
+ $iId = (int)$oForm->insert($aValToAdd);
+ if($iId != 0)
+ $aResult = array('code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId);
+ else
+ $aResult = array('code' => 2, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
+
+ $this->onOfferAdded($iId);
+
+ return echoJson($aResult);
+ }
+
+ $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
+ 'form_id' => $oForm->getId(),
+ 'form' => $oForm->getCode(true)
+ )));
+
+ return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
+ }
+
public function serviceGetSafeServices()
{
$a = parent::serviceGetSafeServices();
@@ -127,6 +226,7 @@ public function serviceGetSearchableFields($aInputsAdd = array())
$CNF = &$this->_oConfig->CNF;
$aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
+ unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
@@ -350,6 +450,698 @@ public function serviceGetNotificationsInterest($aEvent)
);
}
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-page_blocks Page Blocks
+ * @subsubsection bx_ads-block_licenses block_licenses
+ *
+ * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
+ *
+ * Get page block with a list of licenses purchased by currently logged member.
+ *
+ * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
+ *
+ * @see BxAdsModule::serviceBlockLicenses
+ */
+ /**
+ * @ref bx_ads-block_licenses "block_licenses"
+ */
+ public function serviceBlockLicenses()
+ {
+ return $this->_getBlockLicenses();
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-page_blocks Page Blocks
+ * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
+ *
+ * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
+ *
+ * Get page block with a list of all licenses. It's needed for moderators/administrators.
+ *
+ * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
+ *
+ * @see BxAdsModule::serviceBlockLicensesAdministration
+ */
+ /**
+ * @ref bx_ads-block_licenses "block_licenses"
+ */
+ public function serviceBlockLicensesAdministration()
+ {
+ return $this->_getBlockLicenses('administration');
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-page_blocks Page Blocks
+ * @subsubsection bx_ads-block_licenses_note block_licenses_note
+ *
+ * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
+ *
+ * Get page block with a notice for licenses usage.
+ *
+ * @return HTML string with block content to display on the site.
+ *
+ * @see BxAdsModule::serviceBlockLicensesNote
+ */
+ /**
+ * @ref bx_ads-block_licenses_note "block_licenses_note"
+ */
+ public function serviceBlockLicensesNote()
+ {
+ return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-get_payment_data get_payment_data
+ *
+ * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
+ *
+ * Get an array with module's description. Is needed for payments processing module.
+ *
+ * @return an array with module's description.
+ *
+ * @see BxAdsModule::serviceGetPaymentData
+ */
+ /**
+ * @ref bx_ads-get_payment_data "get_payment_data"
+ */
+ public function serviceGetPaymentData()
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $oPermalink = BxDolPermalinks::getInstance();
+
+ $aResult = $this->_aModule;
+ $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
+ $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
+
+ return $aResult;
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-get_cart_item get_cart_item
+ *
+ * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
+ *
+ * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
+ *
+ * @param $mixedItemId product's ID or Unique Name.
+ * @return an array with prodict's description. Empty array is returned if something is wrong.
+ *
+ * @see BxAdsModule::serviceGetCartItem
+ */
+ /**
+ * @ref bx_ads-get_cart_item "get_cart_item"
+ */
+ public function serviceGetCartItem($mixedItemId)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ if(!$mixedItemId)
+ return array();
+
+ if(is_numeric($mixedItemId))
+ $aItem = $this->_oDb->getContentInfoById((int)$mixedItemId);
+ else
+ $aItem = $this->_oDb->getContentInfoByName($mixedItemId);
+
+ if(empty($aItem) || !is_array($aItem))
+ return array();
+
+ $iItemId = (int)$aItem[$CNF['FIELD_ID']];
+ $fItemPrice = (float)$aItem[$CNF['FIELD_PRICE']];
+
+ if($this->isAuction($aItem)) {
+ $iUserId = bx_get_logged_profile_id();
+
+ $aOffer = $this->_oDb->getOffersBy(array(
+ 'type' => 'content_and_author_ids',
+ 'content_id' => $iItemId,
+ 'author_id' => $iUserId,
+ 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
+ ));
+
+ if(!empty($aOffer) && is_array($aOffer))
+ $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
+ }
+
+ return array (
+ 'id' => $iItemId,
+ 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
+ 'name' => $aItem[$CNF['FIELD_NAME']],
+ 'title' => $aItem[$CNF['FIELD_TITLE']],
+ 'description' => $aItem[$CNF['FIELD_TEXT']],
+ 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
+ 'price_single' => $fItemPrice,
+ 'price_recurring' => '',
+ 'period_recurring' => 0,
+ 'period_unit_recurring' => '',
+ 'trial_recurring' => ''
+ );
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-get_cart_items get_cart_items
+ *
+ * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
+ *
+ * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
+ *
+ * @param $iSellerId seller ID.
+ * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
+ *
+ * @see BxAdsModule::serviceGetCartItems
+ */
+ /**
+ * @ref bx_ads-get_cart_items "get_cart_items"
+ */
+ public function serviceGetCartItems($iSellerId)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $iSellerId = (int)$iSellerId;
+ if(empty($iSellerId))
+ return array();
+
+ $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
+
+ $aResult = array();
+ foreach($aItems as $aItem)
+ $aResult[] = array(
+ 'id' => $aItem[$CNF['FIELD_ID']],
+ 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
+ 'name' => $aItem[$CNF['FIELD_NAME']],
+ 'title' => $aItem[$CNF['FIELD_TITLE']],
+ 'description' => $aItem[$CNF['FIELD_TEXT']],
+ 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
+ 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
+ 'price_recurring' => '',
+ 'period_recurring' => 0,
+ 'period_unit_recurring' => '',
+ 'trial_recurring' => ''
+ );
+
+ return $aResult;
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-register_cart_item register_cart_item
+ *
+ * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
+ *
+ * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemId item ID.
+ * @param $iItemCount the number of purchased items.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @param $sLicense license number genereted with payment processing module for internal usage
+ * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
+ *
+ * @see BxAdsModule::serviceRegisterCartItem
+ */
+ /**
+ * @ref bx_ads-register_cart_item "register_cart_item"
+ */
+ public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $aItem = $this->serviceGetCartItem($iItemId);
+ if(empty($aItem) || !is_array($aItem))
+ return array();
+
+ $aEntry = $this->_oDb->getContentInfoById($iItemId);
+ if(empty($aEntry) || !is_array($aEntry) || (int)$aEntry[$CNF['FIELD_QUANTITY']] <= 0)
+ return array();
+
+ if(!$this->_oDb->registerLicense($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
+ return array();
+
+ $this->_oDb->updateEntriesBy(array($CNF['FIELD_QUANTITY'] => (int)$aEntry[$CNF['FIELD_QUANTITY']] - $iItemCount), array($CNF['FIELD_ID'] => $iItemId));
+
+ bx_alert($this->getName(), 'license_register', 0, false, array(
+ 'product_id' => $iItemId,
+ 'profile_id' => $iClientId,
+ 'order' => $sOrder,
+ 'license' => $sLicense,
+ 'count' => $iItemCount
+ ));
+
+ $oClient = BxDolProfile::getInstanceMagic($iClientId);
+ $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
+ $sSellerUrl = $oSeller->getUrl();
+ $sSellerName = $oSeller->getDisplayName();
+
+ $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
+ if(empty($sNote))
+ $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
+
+ sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
+ 'client_name' => $oClient->getDisplayName(),
+ 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
+ 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aEntry[$CNF['FIELD_ID']])),
+ 'vendor_url' => $sSellerUrl,
+ 'vendor_name' => $sSellerName,
+ 'count' => (int)$iItemCount,
+ 'license' => $sLicense,
+ 'notes' => $sNote,
+ ));
+
+ return $aItem;
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-register_subscription_item register_subscription_item
+ *
+ * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
+ *
+ * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemId item ID.
+ * @param $iItemCount the number of purchased items.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @param $sLicense license number genereted with payment processing module for internal usage
+ * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
+ *
+ * @see BxAdsModule::serviceRegisterSubscriptionItem
+ */
+ /**
+ * @ref bx_ads-register_subscription_item "register_subscription_item"
+ */
+ public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
+ {
+ return array();
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
+ *
+ * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
+ *
+ * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemIdOld old item ID.
+ * @param $iItemIdNew new item ID.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
+ *
+ * @see BxAdsModule::serviceReregisterCartItem
+ */
+ /**
+ * @ref bx_ads-reregister_cart_item "reregister_cart_item"
+ */
+ public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
+ {
+ return array();
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
+ *
+ * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
+ *
+ * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemIdOld old item ID.
+ * @param $iItemIdNew new item ID.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
+ *
+ * @see BxAdsModule::serviceReregisterSubscriptionItem
+ */
+ /**
+ * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
+ */
+ public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
+ {
+ return array();
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
+ *
+ * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
+ *
+ * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemId item ID.
+ * @param $iItemCount the number of purchased items.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @param $sLicense license number genereted with payment processing module for internal usage
+ * @return boolean value determining where the payment was unregistered or not.
+ *
+ * @see BxAdsModule::serviceUnregisterCartItem
+ */
+ /**
+ * @ref bx_ads-unregister_cart_item "unregister_cart_item"
+ */
+ public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
+ {
+ if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense))
+ return false;
+
+ bx_alert($this->getName(), 'license_unregister', 0, false, array(
+ 'product_id' => $iItemId,
+ 'profile_id' => $iClientId,
+ 'order' => $sOrder,
+ 'license' => $sLicense,
+ 'count' => $iItemCount
+ ));
+
+ return true;;
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
+ *
+ * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
+ *
+ * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemId item ID.
+ * @param $iItemCount the number of purchased items.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @param $sLicense license number genereted with payment processing module for internal usage
+ * @return boolean value determining where the subscription was unregistered or not.
+ *
+ * @see BxAdsModule::serviceUnregisterSubscriptionItem
+ */
+ /**
+ * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
+ */
+ public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
+ {
+ return true;
+ }
+
+ /**
+ * @page service Service Calls
+ * @section bx_ads Ads
+ * @subsection bx_ads-payments Payments
+ * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
+ *
+ * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
+ *
+ * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
+ *
+ * @param $iClientId client ID.
+ * @param $iSellerId seller ID
+ * @param $iItemId item ID.
+ * @param $iItemCount the number of purchased items.
+ * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
+ * @return boolean value determining where the subscription was canceled or not.
+ *
+ * @see BxAdsModule::serviceCancelSubscriptionItem
+ */
+ /**
+ * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
+ */
+ public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
+ {
+ return true;
+ }
+
+ public function serviceGetOffersCount($sStatus = '')
+ {
+ if(!$this->_oConfig->isAuction())
+ return 0;
+
+ if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
+ $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
+
+ $iUserId = bx_get_logged_profile_id();
+ return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
+ }
+
+ public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
+ {
+ if(!in_array($sStatus, $this->_aOfferStatuses))
+ return false;
+
+ $iUserId = bx_get_logged_profile_id();
+ $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
+ if($iCountNew == $iCount)
+ return false;
+
+ return array(
+ 'count' => $iCountNew, // required
+ 'method' => 'bx_menu_show_live_update(oData)', // required
+ 'data' => array(
+ 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
+ 'content' => '{count}'
+ )),
+ 'mi_parent' => $aMenuItemParent,
+ 'mi_child' => $aMenuItemChild
+ ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
+ );
+ }
+
+ public function serviceOffers()
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ if(!$this->_oConfig->isAuction())
+ return '';
+
+ $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
+ if(!$oGrid)
+ return '';
+
+ return $oGrid->getCode();
+ }
+
+ public function serviceEntityOffers($iContentId = 0)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ if(!$this->_oConfig->isAuction())
+ return '';
+
+ $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
+ if(!$oGrid)
+ return '';
+
+ if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
+ $iContentId = (int)$_iContentId;
+
+ $oGrid->setContentId($iContentId);
+ return $oGrid->getCode();
+ }
+
+ public function serviceEntityOfferAccepted($iContentId = 0)
+ {
+ if(!$this->_oConfig->isAuction())
+ return '';
+
+ $iUserId = bx_get_logged_profile_id();
+
+ if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
+ $iContentId = (int)$_iContentId;
+
+ $aContent = $this->_oDb->getContentInfoById($iContentId);
+ if(empty($aContent) || !is_array($aContent))
+ return '';
+
+ $aOffer = $this->_oDb->getOffersBy(array(
+ 'type' => 'content_and_author_ids',
+ 'content_id' => $iContentId,
+ 'author_id' => $iUserId,
+ 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
+ ));
+
+ if(empty($aOffer) || !is_array($aOffer))
+ return '';
+
+ return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
+ }
+
+ public function isAuction($aContentInfo)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
+ }
+
+ public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
+ {
+ return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
+ }
+
+ public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ if(!is_array($mixedContent))
+ $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
+
+ if(!$this->isAuction($mixedContent))
+ return _t('_sys_txt_access_denied');
+
+ if(!empty($mixedContent) && is_array($mixedContent) && $mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
+ return CHECK_ACTION_RESULT_ALLOWED;
+
+ return _t('_sys_txt_access_denied');
+ }
+
+ public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
+ {
+ return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
+ }
+
+ public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ if(!is_array($mixedContent))
+ $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
+
+ if(!$this->isAuction($mixedContent))
+ return _t('_sys_txt_access_denied');
+
+ if($this->checkAllowedEditAnyEntry($isPerformAction) === CHECK_ACTION_RESULT_ALLOWED)
+ return CHECK_ACTION_RESULT_ALLOWED;
+
+ if(!empty($mixedContent) && is_array($mixedContent) && $mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
+ return CHECK_ACTION_RESULT_ALLOWED;
+
+ return _t('_sys_txt_access_denied');
+ }
+
+ public function onOfferAdded($iOfferId)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
+ if(empty($aOfferInfo) || !is_array($aOfferInfo))
+ return;
+
+ $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
+ $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+ if(empty($aContentInfo) || !is_array($aContentInfo))
+ return;
+
+ $iViewer = bx_get_logged_profile_id();
+ $oViewer = BxDolProfile::getInstanceMagic($iViewer);
+
+ sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
+ 'viewer_name' => $oViewer->getDisplayName(),
+ 'viewer_url' => $oViewer->getUrl(),
+ 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
+ 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
+ 'i' => $CNF['URI_VIEW_ENTRY'],
+ $CNF['FIELD_ID'] => $iContentId
+ ))
+ ));
+
+ $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
+ bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
+ }
+
+ public function onOfferAccepted($iOfferId)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
+ if(empty($aOfferInfo) || !is_array($aOfferInfo))
+ return;
+
+ $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
+ $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+ if(empty($aContentInfo) || !is_array($aContentInfo))
+ return;
+
+ $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
+ $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
+
+ sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
+ 'offerer_name' => $oOfferer->getDisplayName(),
+ 'offerer_url' => $oOfferer->getUrl(),
+ 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
+ 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
+ 'i' => $CNF['URI_VIEW_ENTRY'],
+ $CNF['FIELD_ID'] => $iContentId
+ ))
+ ));
+
+ $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
+ bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
+ }
+
+ public function onOfferDeclined($iOfferId)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
+ if(empty($aOfferInfo) || !is_array($aOfferInfo))
+ return;
+
+ $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
+ $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+ if(empty($aContentInfo) || !is_array($aContentInfo))
+ return;
+
+ $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
+ $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
+
+ sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
+ 'offerer_name' => $oOfferer->getDisplayName(),
+ 'offerer_url' => $oOfferer->getUrl(),
+ 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
+ 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
+ 'i' => $CNF['URI_VIEW_ENTRY'],
+ $CNF['FIELD_ID'] => $iContentId
+ ))
+ ));
+
+ $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
+ bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
+ }
+
+
/**
* Common methods.
*/
@@ -500,6 +1292,41 @@ protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowsePa
return $aResult;
}
+
+ protected function _getBlockLicenses($sType = '')
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
+ $oGrid = BxDolGrid::getObjectInstance($sGrid);
+ if(!$oGrid)
+ return '';
+
+ $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
+
+ $this->_oTemplate->addJs(array('licenses.js'));
+ return array(
+ 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
+ 'menu' => $CNF['OBJECT_MENU_LICENSES']
+ );
+ }
+
+ protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $aParams = array(
+ 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
+ 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
+
+ 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
+ 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
+ );
+ if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
+ $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
+
+ return $aParams;
+ }
}
/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsPageEntry.php b/modules/boonex/ads/classes/BxAdsPageEntry.php
index de00e721f9..21b40d97de 100644
--- a/modules/boonex/ads/classes/BxAdsPageEntry.php
+++ b/modules/boonex/ads/classes/BxAdsPageEntry.php
@@ -21,6 +21,24 @@ public function __construct($aObject, $oTemplate = false)
parent::__construct($aObject, $oTemplate);
}
+ public function getCode ()
+ {
+ $CNF = &$this->_oModule->_oConfig->CNF;
+
+ $iEntryAuthor = (int)$this->_aContentInfo[$CNF['FIELD_AUTHOR']];
+ $sEntryStatus = $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
+ if(($iEntryAuthor == bx_get_logged_profile_id() || $this->_oModule->_isModerator()) && $sEntryStatus != BX_ADS_STATUS_ACTIVE)
+ BxDolInformer::getInstance($this->_oModule->_oTemplate)->add('bx-ads-entry-' . $sEntryStatus, _t('_bx_ads_txt_msg_status_' . $sEntryStatus), BX_INFORMER_ALERT);
+
+ $sResult = parent::getCode();
+ if(!empty($sResult))
+ $sResult .= $this->_oModule->_oTemplate->getJsCode('entry');
+
+ $this->_oModule->_oTemplate->addCss(array('entry.css'));
+ $this->_oModule->_oTemplate->addJs(array('entry.js'));
+ return $sResult;
+ }
+
protected function _setSubmenu($aParams)
{
parent::_setSubmenu(array_merge($aParams, array(
diff --git a/modules/boonex/ads/classes/BxAdsPageLicenses.php b/modules/boonex/ads/classes/BxAdsPageLicenses.php
new file mode 100644
index 0000000000..0cc0ff386c
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsPageLicenses.php
@@ -0,0 +1,32 @@
+MODULE = 'bx_ads';
+
+ parent::__construct($aObject, $oTemplate);
+
+ $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
+ if($oMenuSubmenu) {
+ $sMenuSubmenu = 'sys_account_dashboard';
+ $oMenuSubmenu->setObjectSubmenu($sMenuSubmenu, array('title' => _t('_sys_menu_item_title_account_dashboard'), 'link' => '', 'icon' => ''));
+
+ BxDolMenu::getObjectInstance($sMenuSubmenu)->setSelected($this->MODULE, 'dashboard-ads-licenses');
+ }
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsPageOffers.php b/modules/boonex/ads/classes/BxAdsPageOffers.php
new file mode 100644
index 0000000000..4408531b81
--- /dev/null
+++ b/modules/boonex/ads/classes/BxAdsPageOffers.php
@@ -0,0 +1,22 @@
+MODULE = 'bx_ads';
+
+ parent::__construct($aObject, $oTemplate);
+ }
+}
+
+/** @} */
diff --git a/modules/boonex/ads/classes/BxAdsTemplate.php b/modules/boonex/ads/classes/BxAdsTemplate.php
index e33a325fc7..d14c751578 100644
--- a/modules/boonex/ads/classes/BxAdsTemplate.php
+++ b/modules/boonex/ads/classes/BxAdsTemplate.php
@@ -23,6 +23,28 @@ function __construct(&$oConfig, &$oDb)
$this->aMethodsToCallAddJsCss[] = 'categories';
}
+ public function entryOfferAccepted($iUserId, $aContent, $aOffer)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ $sJsCode = $sJsMethod = '';
+ $aJs = BxDolPayments::getInstance()->getAddToCartJs($aContent[$CNF['FIELD_AUTHOR']], $this->MODULE, $aContent[$CNF['FIELD_ID']], $aOffer[$CNF['FIELD_OFR_QUANTITY']], true);
+ if(!empty($aJs) && is_array($aJs))
+ list($sJsCode, $sJsMethod) = $aJs;
+
+ return $this->parseHtmlByName('entry-offer-accepted.html', array(
+ 'amount' => _t_format_currency($aOffer['amount']),
+ 'quantity' => _t('_bx_ads_txt_n_items', $aOffer['quantity']),
+ 'bx_if:show_pay' => array(
+ 'condition' => !empty($sJsMethod),
+ 'content' => array(
+ 'js_method' => $sJsMethod,
+ )
+ ),
+ 'js_code' => $sJsCode
+ ));
+ }
+
public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
{
$CNF = &$this->_oConfig->CNF;
@@ -55,6 +77,19 @@ public function categoriesList($aParams = array())
return $sResult;
}
+ public function getEntryLink($aEntry)
+ {
+ $CNF = &$this->_oConfig->CNF;
+
+ return $this->getLink('entry-link', array(
+ 'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array(
+ 'id' => $aEntry[$CNF['FIELD_ID']]
+ )),
+ 'title' => bx_html_attribute($aEntry[$CNF['FIELD_TITLE']]),
+ 'content' => $aEntry[$CNF['FIELD_TITLE']]
+ ));
+ }
+
/**
* Use Gallery image for both because currently there is no Unit types with small thumbnails.
*/
diff --git a/modules/boonex/ads/install/installer.php b/modules/boonex/ads/install/installer.php
index d5ed43ac36..53f11f2dfc 100644
--- a/modules/boonex/ads/install/installer.php
+++ b/modules/boonex/ads/install/installer.php
@@ -11,10 +11,27 @@
class BxAdsInstaller extends BxBaseModTextInstaller
{
- function __construct($aConfig)
+ public function __construct($aConfig)
{
parent::__construct($aConfig);
}
+
+ public function enable($aParams)
+ {
+ $aResult = parent::enable($aParams);
+
+ if($aResult['result'])
+ BxDolPayments::getInstance()->updateDependentModules($this->_aConfig['name'], true);
+
+ return $aResult;
+ }
+
+ public function disable($aParams)
+ {
+ BxDolPayments::getInstance()->updateDependentModules($this->_aConfig['name'], false);
+
+ return parent::disable($aParams);
+ }
}
/** @} */
diff --git a/modules/boonex/ads/install/langs/en.xml b/modules/boonex/ads/install/langs/en.xml
index f06b253a8f..a9611a87db 100644
--- a/modules/boonex/ads/install/langs/en.xml
+++ b/modules/boonex/ads/install/langs/en.xml
@@ -4,6 +4,7 @@
{viewer_name} is interested in your ad {ad_name}.
+{email_footer}]]> + +You've purchased {entry_name} ad ({count} item(s)) from {vendor_name}.
Your license is {license}.
{notes}
+{email_footer}]]>{viewer_name} added an offer for your ad {ad_name}.
+{email_footer}]]>Your offer for {ad_name} ad was accepted.
+{email_footer}]]>Your offer for {ad_name} ad was declined.
{email_footer}]]>Здравствуйте, {client_name}.
Вы оплатили {entry_name} объявление ({count} шт.), размещенное {vendor_name}.
Ваша лицензия - {license}.
{notes}
+{email_footer}]]> + +{viewer_name} сделал предложение по вашему объявлению {ad_name}.
+{email_footer}]]>Ваше предложение по {ad_name} объявлению было принято.
+{email_footer}]]>Ваше предложение по {ad_name} объявлению было отклонено.
{email_footer}]]>