Skip to content

Commit

Permalink
#3393 Help Tours module initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
rednaxal committed May 31, 2021
1 parent 8b23182 commit 5bf151e
Show file tree
Hide file tree
Showing 21 changed files with 1,409 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/boonex/help_tours/classes/BxHelpToursConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup Help Tours Help Tours
* @ingroup UnaModules
*
* @{
*/

class BxHelpToursConfig extends BxBaseModGeneralConfig
{
public function __construct($aModule)
{
parent::__construct($aModule);
}
}

/** @} */
150 changes: 150 additions & 0 deletions modules/boonex/help_tours/classes/BxHelpToursDb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup Help Tours Help Tours
* @ingroup UnaModules
*
* @{
*/

class BxHelpToursDb extends BxDolModuleDb
{
private $_sTourBlockTemplate = 'a:3:{s:6:"module";s:13:"bx_help_tours";s:6:"method";s:13:"get_help_tour";s:6:"params";a:1:{i:0;i:__tour_id__;}}';
private $_sBlockSelectorTemplate = '#bx-page-block-__block_id__ > div';

public function __construct(&$oConfig)
{
parent::__construct($oConfig);
}

public function getTourDetails($iTourId) {
return $this->getRow("SELECT * FROM `bx_help_tours` WHERE `id` = :id", ['id' => $iTourId]);
}

public function getTourPageUrl($iTourId) {
$aTour = $this->getTourDetails($iTourId);
if (!$aTour) return false;

if ($aTour['page'] == 'sys_home') return '/';

return $this->getOne("SELECT `url` FROM `sys_objects_page` WHERE `object` = :page", ['page' => $aTour['page']]);
}

public function getSitePages() {
$aPages = $this->getAll("SELECT `object`, `module`, `title_system` AS `name` FROM `sys_objects_page` WHERE `title_system` <> '' ORDER BY `title_system` ASC");
$aPagesByModules = [];
foreach ($aPages as $aPage) {
$aPagesByModules[$aPage['module']][$aPage['object']] = _t($aPage['name']);
}

$aResult = [];
foreach ($aPagesByModules as $sModule => $aPages) {
$oModule = BxDolModule::getInstance($sModule);
$sTitle = $oModule && isset($oModule->_aModule) ? $oModule->_aModule['title'] : ucfirst($sModule);

$aResult[$sModule.'_start'] = ['type' => 'group_header', 'value' => $sTitle];
$aResult = $aResult + $aPages;
$aResult[$sModule.'_end'] = ['type' => 'group_end'];
}

return $aResult;
}

public function deleteHelpTourItems($iEntry) {
$this->query("DELETE FROM `bx_help_tours_items` WHERE `tour` = :tour", ['tour' => $iEntry]);
}

public function getPageTitleDetails($sPageObject) {
$aData = $this->getRow("SELECT `module`, `title_system` FROM `sys_objects_page` WHERE `object` = :page", ['page' => $sPageObject]);
if (!$aData) return false;

$oModule = BxDolModule::getInstance($aData['module']);
$aData['module_title'] = $oModule && isset($oModule->_aModule) ? $oModule->_aModule['title'] : ucfirst($aData['module']);

return $aData;
}

public function putHelpTourOnPage($iTourId, $sOldPage) {
$aTour = $this->getTourDetails($iTourId);
$sPage = $aTour['page'];

if ($sOldPage != $sPage) {
if (!empty($sOldPage)) {
$this->query("DELETE FROM `sys_pages_blocks` WHERE `object` = :page AND `module` = 'bx_help_tours'", [
'page' => $sOldPage,
]);
}

$iOrder = intval($this->getOne("SELECT MAX(`order`) FROM `sys_pages_blocks` WHERE `object` = :page and `cell_id` = 1", ['page' => $sPage])) + 1;

$this->query("
INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
(:page, 1, 'bx_help_tours', '_bx_help_tours_page_block_caption', 0, 2147483647, 'service', :service_call, 0, 0, :order);
", [
'page' => $sPage,
'service_call' => str_replace('__tour_id__', $iTourId, $this->_sTourBlockTemplate),
'order' => $iOrder,
]);
}
}

function deleteHelpTourBlock($iTourId) {
$aTour = $this->getTourDetails($iTourId);

$this->query("DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_help_tours' AND `object` = :page", [
'page' => $aTour['page'],
]);
}

function getHelpTourItemsCount($iTourId) {
return $this->getOne("SELECT COUNT(*) FROM `bx_help_tours_items` WHERE `tour` = :tour", [
'tour' => $iTourId,
]);
}

public function getHelpTourItems($iTourId) {
return $this->getAll("SELECT * FROM `bx_help_tours_items` WHERE `tour` = :tour ORDER BY `order` ASC", [
'tour' => $iTourId,
]);
}

public function getTourItemDetails($iItemId) {
return $this->getRow("SELECT * FROM `bx_help_tours_items` WHERE `id` = :id", ['id' => $iItemId]);
}

public function getPageBlocksForHelpTour($iTourId) {
$aTour = $this->getTourDetails($iTourId);
if (!$aTour) return [];

$aResult = [];

$aRes = $this->getAll("SELECT `id`, `title_system`, `title` FROM `sys_pages_blocks` WHERE `object` = :page AND `cell_id` > 0 AND `active` AND `module` <> 'bx_help_tours' AND (`title_system` <> '' OR `title` <> '') ORDER BY `cell_id` ASC, `order` ASC", ['page' => $aTour['page']]);
if ($aRes) {
foreach ($aRes as $aRow) {
$aResult[str_replace('__block_id__', $aRow['id'], $this->_sBlockSelectorTemplate)] = !empty($aRow['title_system']) ? _t($aRow['title_system']) : _t($aRow['title']);
}
}

return $aResult;
}

public function getHelpToursOptions() {
return $this->getPairs("SELECT `id`, `page` FROM `bx_help_tours` ORDER BY `order` ASC", 'id', 'page');
}

public function deleteAccountData($iAccount) {
$this->query("DELETE FROM `bx_help_tours_track_views` WHERE `account` = :account", ['account' => $iAccount]);
}

public function trackTourSeen($iAccount, $iTour) {
$this->query("INSERT IGNORE INTO `bx_help_tours_track_views` (`account`, `tour`) VALUES(:account, :tour)", ['account' => $iAccount, 'tour' => $iTour]);
}

public function isHelpTourSeen($iAccount, $iTour) {
return $this->getOne("SELECT COUNT(*) FROM `bx_help_tours_track_views` WHERE `account` = :account AND `tour` = :tour", ['account' => $iAccount, 'tour' => $iTour]);
}
}

/** @} */
Loading

0 comments on commit 5bf151e

Please sign in to comment.