Skip to content

Commit

Permalink
Ticket #4817 - Courses improvements. Core changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Oct 7, 2024
1 parent ab6a3e3 commit 57e3494
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 26 deletions.
15 changes: 6 additions & 9 deletions modules/base/files/classes/BxBaseModFilesFormUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithCont
bx_import('BxDolPrivacy');

// get values form main form to pass it to each file later
$aFormValues = array();
foreach ($this->aInputs as $aInput) {
if(in_array($aInput['name'], array('do_submit', 'profile_id', $CNF['FIELD_PHOTO'])))
continue;

$aFormValues[$aInput['name']] = $this->getCleanValue($aInput['name']);
}
$aFormValues = [];
foreach ($this->aInputs as $aInput)
if(!empty($aInput['db']) && is_array($aInput['db']))
$aFormValues[$aInput['name']] = $this->getCleanValue($aInput['name']);

$aContentIds = array();
$aContentIds = [];
foreach ($aGhostFiles as $aFile) {
if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedAdd())
continue;
Expand All @@ -74,7 +71,7 @@ public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithCont
$iContentId = BxBaseModGeneralFormEntry::insert (array_merge(array(
$CNF['FIELD_FOR_STORING_FILE_ID'] => $aFile['id'],
$CNF['FIELD_TITLE'] => $this->getCleanValue('title-' . $aFile['id']),
$CNF['FIELD_AUTHOR'] => bx_get('profile_id') && $this->_oModule->serviceIsAllowedAddContentToProfile(bx_get('profile_id')) ? bx_get('profile_id') : '',
$CNF['FIELD_AUTHOR'] => bx_get('profile_id') && $this->_oModule->serviceIsAllowedAddContentToContext(bx_get('profile_id')) ? bx_get('profile_id') : '',
$CNF['FIELD_STATUS_ADMIN'] => !$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled() ? BX_BASE_MOD_GENERAL_STATUS_PENDING : BX_BASE_MOD_TEXT_STATUS_ACTIVE
), $aFormValues));
if (!$iContentId)
Expand Down
24 changes: 24 additions & 0 deletions modules/base/files/classes/BxBaseModFilesFormsEntryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ protected function addDataFormAction ($sDisplay = false, $sCheckFunction = false

return array('need_redirect_after_action' => true, 'content_ids_array' => $aContentIds);
}

protected function getRedirectUrlAfterAdd($mixedContent)
{
$CNF = &$this->_oModule->_oConfig->CNF;

$iProfileId = false;
$sUri = $CNF['URI_AUTHOR_ENTRIES'];

$sKeyIds = 'content_ids_array';
if(!empty($mixedContent[$sKeyIds]) && is_array($mixedContent[$sKeyIds])) {
$aContentInfo = $this->_oModule->_oDb->getContentInfoById(array_pop($mixedContent[$sKeyIds]));

if(($sKey = 'FIELD_AUTHOR') && isset($CNF[$sKey]) && ($iAuthor = (int)$aContentInfo[$CNF[$sKey]])) {
$iProfileId = $iAuthor;
}

if(($sKey = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKey]) && ($iVisibility = (int)$aContentInfo[$CNF[$sKey]]) < 0) {
$iProfileId = abs($iVisibility);
$sUri = $CNF['URI_ENTRIES_BY_CONTEXT'];
}
}

return 'page.php?i=' . $sUri . '&profile_id=' . (($oProfile = BxDolProfile::getInstance($iProfileId)) !== false ? $oProfile->id() : bx_get_logged_profile_id());
}
}

/** @} */
84 changes: 67 additions & 17 deletions modules/base/general/classes/BxBaseModGeneralFormEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ function initChecker ($aValues = array (), $aSpecificValues = array())

parent::initChecker ($aValues, $aSpecificValues);

$this->_processContextBeforeAdd();

foreach($aPrivacyFields as $sField => $sObject)
$this->_validatePrivacyField($sField, $sObject, $aValues);
}
Expand Down Expand Up @@ -509,33 +511,35 @@ public function insert ($aValsToAdd = array(), $isIgnore = false)
$bMulticatEnabled = $this->_isMulticatEnabled();
if ($bMulticatEnabled)
$this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);

$iContentId = parent::insert ($aValsToAdd, $isIgnore);

if(!empty($iContentId)) {
foreach($this->aInputs as $aInput) {
if ($aInput['type'] == 'nested_form') {
if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
foreach ($aInput['ghost_template'] as $oFormNested) {
$iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
if(empty($iContentId))
return $iContentId;

if ($aInput['rateable']) {
BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
}
foreach($this->aInputs as $aInput) {
if ($aInput['type'] == 'nested_form') {
if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
foreach ($aInput['ghost_template'] as $oFormNested) {
$iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));

if ($aInput['rateable']) {
BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
}
}
}
}

if ($bMulticatEnabled)
$this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
}

foreach($this->aInputs as $aInput) {
if (isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form'){
if($bMulticatEnabled)
$this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);

foreach($this->aInputs as $aInput)
if(isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form')
BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName());
}
}

if(($iContextNid = $this->getCleanValue('context_nid')) !== false)
$this->_processContextAfterAdd($iContentId, $iContextNid);

return $iContentId;
}

Expand Down Expand Up @@ -998,6 +1002,52 @@ protected function _validatePrivacyField($sField, $sPrivacyObject, $aValues)
}
}

protected function _processContextBeforeAdd()
{
$CNF = &$this->_oModule->_oConfig->CNF;

$sKey = 'FIELD_ALLOW_VIEW_TO';
if(!isset($CNF[$sKey], $this->aInputs[$CNF[$sKey]]))
return;

if(($iContextId = bx_get('context_pid')) !== false)
$this->aInputs[$CNF[$sKey]] = array_merge($this->aInputs[$CNF[$sKey]], [
'type' => 'hidden',
'value' => -abs((int)$iContextId)
]);

if(($iNodeId = bx_get('context_nid')) !== false && !isset($this->aInputs['context_nid'])) {
$this->aInputs['context_nid'] = [
'name' => 'context_nid',
'type' => 'hidden',
'value' => (int)$iNodeId
];
}
}

protected function _processContextAfterAdd($iContentId, $iContextNid)
{
$CNF = &$this->_oModule->_oConfig->CNF;

$sKey = 'FIELD_ALLOW_VIEW_TO';
if(!isset($CNF[$sKey]))
return;

$aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
if(!is_numeric($aContentInfo[$CNF[$sKey]]) || (int)$aContentInfo[$CNF[$sKey]] > 0)
return;

$iContextPid = abs($aContentInfo[$CNF[$sKey]]);
$oContext = BxDolProfile::getInstance($iContextPid);
if(!$oContext)
return;

$sModule = $oContext->getModule();
$sMethod = 'on_content_added';
if(bx_is_srv($sModule, $sMethod))
bx_srv($sModule, $sMethod, [$this->MODULE, $iContentId, $oContext->getContentId(), $iContextNid]);
}

/**
*
* MultiCategories related methods.
Expand Down
11 changes: 11 additions & 0 deletions modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,17 @@ public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
$oPrivacy->deleteGroupCustomByContentId($iContentId);

$sKey = 'FIELD_ALLOW_VIEW_TO';
if(isset($CNF[$sKey], $aContentInfo[$CNF[$sKey]]) && ($iContextPid = (int)$aContentInfo[$CNF[$sKey]]) < 0) {
$iContextPid = abs($iContextPid);
if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false) {
$sModule = $oContext->getModule();
$sMethod = 'on_content_deleted';
if(bx_is_srv($sModule, $sMethod))
bx_srv($sModule, $sMethod, [$this->_oModule->getName(), $iContentId, $oContext->getContentId()]);
}
}

bx_audit(
$iContentId,
$this->_oModule->getName(),
Expand Down
11 changes: 11 additions & 0 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,17 @@ protected function _prepareBrowsingFiltersParamsGet($mParams = false)
}

// ====== SERVICE METHODS
public function serviceIsAllowedAddContentToContext($iContextPid)
{
$oContext = false;
if(!$iContextPid || !($oContext = BxDolProfile::getInstance((int)$iContextPid)))
return false;

if($iContextPid == bx_get_logged_profile_id())
return true;

return bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $this->getName()]) === CHECK_ACTION_RESULT_ALLOWED;
}

public function serviceIsBadgesAvaliable()
{
Expand Down

0 comments on commit 57e3494

Please sign in to comment.