MODULE = 'bx_resources'; parent::__construct($aInfo, $oTemplate); } public function setContextId($iContextId) { $this->_iContextId = $iContextId; } public function getCode($bDynamicMode = false) { $this->_replaceMarkersInControls('controls_edit'); return parent::getCode($bDynamicMode); } public function initChecker ($aValues = array (), $aSpecificValues = array()) { $CNF = &$this->_oModule->_oConfig->CNF; $bValues = $aValues && !empty($aValues['id']); $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false; if(!empty($aContentInfo) && is_array($aContentInfo)) $this->setContextId(abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']])); if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden'))) unset($this->aInputs[$CNF['FIELD_PUBLISHED']]); if(($sKey = 'FIELD_COVER') && isset($CNF[$sKey], $this->aInputs[$CNF[$sKey]])) { if($bValues) $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id']; $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo)); } parent::initChecker ($aValues, $aSpecificValues); } public function insert ($aValsToAdd = array(), $isIgnore = false) { $CNF = &$this->_oModule->_oConfig->CNF; if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) { $iAdded = 0; if(isset($this->aInputs[$CNF['FIELD_ADDED']])) $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']); if(empty($iAdded)) $iAdded = time(); $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded; } if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) { $iPublished = 0; if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']); if(empty($iPublished)) $iPublished = time(); $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished; } $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? 'awaiting' : 'active'; $iContentId = parent::insert ($aValsToAdd, $isIgnore); if(!empty($iContentId)) $this->processFiles($CNF['FIELD_COVER'], $iContentId, true); return $iContentId; } public function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) { $CNF = &$this->_oModule->_oConfig->CNF; if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) { $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']); if(empty($iPublished)) $iPublished = time(); $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished; } $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId); $aValsToAdd[$CNF['FIELD_ALLOW_VIEW_TO']] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]; $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges); $this->processFiles($CNF['FIELD_COVER'], $iContentId, false); return $iResult; } protected function _getCoverGhostTmplVars($aContentInfo = []) { $CNF = &$this->_oModule->_oConfig->CNF; return [ 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'], 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'], 'editor_id' => $CNF['FIELD_TEXT_ID'] ?? '', 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0, 'name_thumb' => $CNF['FIELD_THUMB'] ?? '' ]; } } /** @} */