diff --git a/classes/tl_catalog.php b/classes/tl_catalog.php index 5b3ebae6..85b980c0 100644 --- a/classes/tl_catalog.php +++ b/classes/tl_catalog.php @@ -2,60 +2,66 @@ namespace CatalogManager; -class tl_catalog extends \Backend { +class tl_catalog extends \Backend +{ - public function checkPermission() { + public function checkPermission() + { $objDcPermission = new DcPermission(); - $objDcPermission->checkPermission( 'tl_catalog' , 'catalog', 'catalogp' ); + $objDcPermission->checkPermission('tl_catalog', 'catalog', 'catalogp'); } - public function setCoreTableData( \DataContainer $dc ) { + public function setCoreTableData(\DataContainer $dc) + { - if ( Toolkit::isCoreTable( $dc->activeRecord->tablename ) && \Input::post( 'tl_loadDataContainer' ) ) { + if (Toolkit::isCoreTable($dc->activeRecord->tablename) && \Input::post('tl_loadDataContainer')) { $objDCAExtractor = new CatalogDcExtractor(); - $objDCAExtractor->initialize( $dc->activeRecord->tablename ); + $objDCAExtractor->initialize($dc->activeRecord->tablename); $arrContainerData = $objDCAExtractor->convertDataContainerToCatalog(); - if ( !empty( $arrContainerData ) ) $this->Database->prepare( 'UPDATE tl_catalog %s WHERE id = ?' )->set( $arrContainerData )->execute( $dc->activeRecord->id ); + if (!empty($arrContainerData)) $this->Database->prepare('UPDATE tl_catalog %s WHERE id = ?')->set($arrContainerData)->execute($dc->activeRecord->id); } } - public function checkEditMask( \DataContainer $dc ) { + public function checkEditMask(\DataContainer $dc) + { - if ( Toolkit::isEmpty( $dc->id ) ) return null; + if (Toolkit::isEmpty($dc->id)) return null; - $objCatalog = $this->Database->prepare( 'SELECT * FROM tl_catalog WHERE `id` = ?' )->limit(1)->execute( $dc->id ); + $objCatalog = $this->Database->prepare('SELECT * FROM tl_catalog WHERE `id` = ?')->limit(1)->execute($dc->id); - if ( $objCatalog->type == 'modifier') { + if ($objCatalog->type == 'modifier') { $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['inputType'] = 'select'; $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['eval']['chosen'] = true; $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['eval']['tl_class'] = 'w50 wizard'; - $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['options_callback'] = [ 'CatalogManager\tl_catalog', 'getCoreTables' ]; - $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['wizard'][] = [ 'CatalogManager\DcCallbacks', 'getCoreTableLoaderButton' ]; + $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['options_callback'] = ['CatalogManager\tl_catalog', 'getCoreTables']; + $GLOBALS['TL_DCA']['tl_catalog']['fields']['tablename']['wizard'][] = ['CatalogManager\DcCallbacks', 'getCoreTableLoaderButton']; } } - - public function getCoreTables() { + + public function getCoreTables() + { return $this->getTables(); } - protected function getTables( $arrExclude = [] ) { + protected function getTables($arrExclude = []) + { $arrReturn = []; $arrTables = $this->Database->listTables(); - foreach ( $arrTables as $strTable ) { + foreach ($arrTables as $strTable) { - if ( Toolkit::isCoreTable( $strTable ) && !in_array( $strTable, $arrExclude ) ) { + if (Toolkit::isCoreTable($strTable) && !in_array($strTable, $arrExclude)) { $arrReturn[] = $strTable; } @@ -65,16 +71,17 @@ protected function getTables( $arrExclude = [] ) { } - public function createTableOnSubmit( \DataContainer $dc ) { + public function createTableOnSubmit(\DataContainer $dc) + { $strTablename = $dc->activeRecord->tablename; - if ( !$strTablename ) return null; + if (!$strTablename) return null; $objDatabaseBuilder = new CatalogDatabaseBuilder(); - $objDatabaseBuilder->initialize( $strTablename, $dc->activeRecord->row() ); + $objDatabaseBuilder->initialize($strTablename, $dc->activeRecord->row()); - if ( $this->Database->tableExists( $strTablename ) ) { + if ($this->Database->tableExists($strTablename)) { $objDatabaseBuilder->tableCheck(); @@ -85,39 +92,43 @@ public function createTableOnSubmit( \DataContainer $dc ) { } - public function renameTable( $varValue, \DataContainer $dc ) { + public function renameTable($varValue, \DataContainer $dc) + { - if ( !$varValue || !$dc->activeRecord->tablename || $dc->activeRecord->tablename == $varValue ) { + if (!$varValue || !$dc->activeRecord->tablename || $dc->activeRecord->tablename == $varValue) { return $varValue; } - if ( !$this->Database->tableExists( $varValue ) ) { + if (!$this->Database->tableExists($varValue)) { $objDatabaseBuilder = new CatalogDatabaseBuilder(); - $objDatabaseBuilder->initialize( $dc->activeRecord->tablename, $dc->activeRecord->row() ); - $objDatabaseBuilder->renameTable( $varValue ); + $objDatabaseBuilder->initialize($dc->activeRecord->tablename, $dc->activeRecord->row()); + $objDatabaseBuilder->renameTable($varValue); } return $varValue; } - public function dropTableOnDelete( \DataContainer $dc ) { + public function dropTableOnDelete(\DataContainer $dc) + { $objDatabaseBuilder = new CatalogDatabaseBuilder(); - $objDatabaseBuilder->initialize( $dc->activeRecord->tablename, $dc->activeRecord->row() ); + $objDatabaseBuilder->initialize($dc->activeRecord->tablename, $dc->activeRecord->row()); $objDatabaseBuilder->dropTable(); } - public function getPanelLayouts() { + public function getPanelLayouts() + { - return [ 'filter', 'sort', 'search', 'limit' ]; + return ['filter', 'sort', 'search', 'limit']; } - public function getOperations( \DataContainer $dc ) { + public function getOperations(\DataContainer $dc) + { $arrOperations = Toolkit::$arrOperators; @@ -133,107 +144,112 @@ public function getOperations( \DataContainer $dc ) { } - public function getModeTypes ( \DataContainer $dc ) { + public function getModeTypes(\DataContainer $dc) + { $blnDynamicPtable = false; $strTablename = $dc->activeRecord->tablename; - $blnCoreTable = Toolkit::isCoreTable( $strTablename ); + $blnCoreTable = Toolkit::isCoreTable($strTablename); - if ( $blnCoreTable ) { + if ($blnCoreTable) { - \Controller::loadDataContainer( $strTablename ); + \Controller::loadDataContainer($strTablename); - $blnDynamicPtable = $GLOBALS['TL_DCA'][ $strTablename ]['config']['dynamicPtable'] ?: false; + $blnDynamicPtable = $GLOBALS['TL_DCA'][$strTablename]['config']['dynamicPtable'] ?: false; } - if ( $dc->activeRecord->pTable || $blnDynamicPtable ) { + if ($dc->activeRecord->pTable || $blnDynamicPtable) { - if ( $blnCoreTable ) { + if ($blnCoreTable) { - return [ '3', '4' ]; + return ['3', '4']; } - if ( $dc->activeRecord->mode == '3' ) { // backwards compatibility + if ($dc->activeRecord->mode == '3') { // backwards compatibility - return [ '3', '4' ]; + return ['3', '4']; } - return [ '4' ]; + return ['4']; } $arrModes = Toolkit::$arrModeTypes; - unset( $arrModes[3] ); - unset( $arrModes[4] ); + unset($arrModes[3]); + unset($arrModes[4]); return $arrModes; } - public function getFlagTypes() { + public function getFlagTypes() + { - return [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ]; + return ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; } - public function checkTablename( $varValue, \DataContainer $dc ) { + public function checkTablename($varValue, \DataContainer $dc) + { - $strTablename = Toolkit::parseConformSQLValue( $varValue ); - $strValidname = Toolkit::slug( $strTablename, [ 'delimiter' => '_' ] ); + $strTablename = Toolkit::parseConformSQLValue($varValue); + $strValidname = Toolkit::slug($strTablename, ['delimiter' => '_']); - if ( $strValidname != $strTablename && Toolkit::strictMode() ) { + if ($strValidname != $strTablename && Toolkit::strictMode()) { - throw new \Exception( sprintf( 'invalid tablename. Please try with "%s"', $strValidname ) ); + throw new \Exception(sprintf('invalid tablename. Please try with "%s"', $strValidname)); } - if ( !$this->Database->isUniqueValue( 'tl_catalog', 'tablename', $strTablename, $dc->activeRecord->id ) ) { + if (!$this->Database->isUniqueValue('tl_catalog', 'tablename', $strTablename, $dc->activeRecord->id)) { - throw new \Exception( sprintf( 'table "%s" already exists in catalog manager.', $strTablename ) ); + throw new \Exception(sprintf('table "%s" already exists in catalog manager.', $strTablename)); } - if ( $dc->activeRecord->type == 'default' && Toolkit::isCoreTable( $strTablename ) ) { + if ($dc->activeRecord->type == 'default' && Toolkit::isCoreTable($strTablename)) { - throw new \Exception( '"tl_" prefix is not allowed.' ); + throw new \Exception('"tl_" prefix is not allowed.'); } - if ( Toolkit::isCoreTable( $strTablename ) && !$this->Database->tableExists( $strTablename ) ) { + if (Toolkit::isCoreTable($strTablename) && !$this->Database->tableExists($strTablename)) { - throw new \Exception( sprintf( 'table "%s" do not exist.', $strTablename ) ); + throw new \Exception(sprintf('table "%s" do not exist.', $strTablename)); } return $strTablename; } - public function parseModulename( $varValue, \DataContainer $dc ) { + public function parseModulename($varValue, \DataContainer $dc) + { - if ( Toolkit::isEmpty( $varValue ) && $dc->activeRecord->isBackendModule ) { + if (Toolkit::isEmpty($varValue) && $dc->activeRecord->isBackendModule) { $varValue = $dc->activeRecord->name; } - if ( Toolkit::isEmpty( $varValue ) ) { + if (Toolkit::isEmpty($varValue)) { return ''; } - return Toolkit::slug( $varValue, [ 'delimiter' => '_' ] ); + return Toolkit::slug($varValue, ['delimiter' => '_']); } - public function checkModeTypeRequirements( $varValue, \DataContainer $dc ) { + public function checkModeTypeRequirements($varValue, \DataContainer $dc) + { $blnDynamicPtable = false; $strTablename = $dc->activeRecord->tablename; - if ( Toolkit::isCoreTable( $strTablename ) ) { + if (Toolkit::isCoreTable($strTablename)) { - \Controller::loadDataContainer( $strTablename ); + \Controller::loadDataContainer($strTablename); - $blnDynamicPtable = $GLOBALS['TL_DCA'][ $strTablename ]['config']['dynamicPtable'] ?: false; + $blnDynamicPtable = $GLOBALS['TL_DCA'][$strTablename]['config']['dynamicPtable'] ?: false; } - if ( in_array( $varValue, [ '3', '4', '6' ] ) && ( Toolkit::isEmpty( $dc->activeRecord->pTable ) && !$blnDynamicPtable ) ) { + if (in_array($varValue, ['3', '4', '6']) && (Toolkit::isEmpty($dc->activeRecord->pTable) && !$blnDynamicPtable)) { throw new \Exception('this mode required parent table.'); } @@ -242,29 +258,31 @@ public function checkModeTypeRequirements( $varValue, \DataContainer $dc ) { } - public function getParentDataContainerFields( \DataContainer $dc ) { + public function getParentDataContainerFields(\DataContainer $dc) + { $arrReturn = []; $strTablename = $dc->activeRecord->pTable; - if ( Toolkit::isEmpty( $strTablename ) ) return $arrReturn; + if (Toolkit::isEmpty($strTablename)) return $arrReturn; $objFieldBuilder = new CatalogFieldBuilder(); - $objFieldBuilder->initialize( $strTablename ); - $arrFields = $objFieldBuilder->getCatalogFields( true, null ); + $objFieldBuilder->initialize($strTablename); + $arrFields = $objFieldBuilder->getCatalogFields(true, null); - foreach ( $arrFields as $strFieldname => $arrField ) { + foreach ($arrFields as $strFieldname => $arrField) { - if ( !Toolkit::isDcConformField( $arrField ) ) continue; + if (!Toolkit::isDcConformField($arrField)) continue; - $arrReturn[ $strFieldname ] = Toolkit::getLabelValue( $arrField['_dcFormat']['label'], $strFieldname ); + $arrReturn[$strFieldname] = Toolkit::getLabelValue($arrField['_dcFormat']['label'], $strFieldname); } return $arrReturn; } - public function getDataContainerFields(\DataContainer $dc) { + public function getDataContainerFields(\DataContainer $dc) + { $arrReturn = []; $strTablename = $dc->activeRecord->tablename; @@ -303,15 +321,16 @@ public function getDataContainerFields(\DataContainer $dc) { } - public function getSystemTables( \DataContainer $dc ) { + public function getSystemTables(\DataContainer $dc) + { $blnCore = $dc->activeRecord->type === 'modifier'; - $arrReturn = $blnCore ? $this->getTables( [ 'tl_content' ] ) : []; - $objCatalogTables = $this->Database->prepare( 'SELECT `id`, `name`, `tablename` FROM tl_catalog WHERE `tablename` != ?' )->execute( $dc->activeRecord->tablename ); + $arrReturn = $blnCore ? $this->getTables(['tl_content']) : []; + $objCatalogTables = $this->Database->prepare('SELECT `id`, `name`, `tablename` FROM tl_catalog WHERE `tablename` != ?')->execute($dc->activeRecord->tablename); - while ( $objCatalogTables->next() ) { + while ($objCatalogTables->next()) { - if ( !in_array( $objCatalogTables->tablename, $arrReturn ) ) { + if (!in_array($objCatalogTables->tablename, $arrReturn)) { $arrReturn[] = $objCatalogTables->tablename; } @@ -319,11 +338,12 @@ public function getSystemTables( \DataContainer $dc ) { return $arrReturn; } - - public function checkModeTypeForFormat( $varValue, \DataContainer $dc ) { - if ( $varValue && $dc->activeRecord->mode == '4' ) { + public function checkModeTypeForFormat($varValue, \DataContainer $dc) + { + + if ($varValue && $dc->activeRecord->mode == '4') { return ''; } @@ -332,9 +352,10 @@ public function checkModeTypeForFormat( $varValue, \DataContainer $dc ) { } - public function checkModeTypeForPTableAndModes( $varValue, \DataContainer $dc ) { + public function checkModeTypeForPTableAndModes($varValue, \DataContainer $dc) + { - if ( $varValue && $dc->activeRecord->pTable ) { + if ($varValue && $dc->activeRecord->pTable) { throw new \Exception('you can not generate backend module with parent table.'); } @@ -343,9 +364,10 @@ public function checkModeTypeForPTableAndModes( $varValue, \DataContainer $dc ) } - public function checkModeTypeForBackendModule( $varValue, \DataContainer $dc ) { + public function checkModeTypeForBackendModule($varValue, \DataContainer $dc) + { - if ( $varValue && $dc->activeRecord->isBackendModule ) { + if ($varValue && $dc->activeRecord->isBackendModule) { throw new \Exception('you can not use parent table for backend module.'); } @@ -354,42 +376,45 @@ public function checkModeTypeForBackendModule( $varValue, \DataContainer $dc ) { } - public function getNavigationAreas() { + public function getNavigationAreas() + { $arrReturn = []; $arrModules = $GLOBALS['BE_MOD'] ? $GLOBALS['BE_MOD'] : []; - if ( !is_array( $arrModules ) ) return []; + if (!is_array($arrModules)) return []; - foreach ( $arrModules as $strName => $arrModule ) { + foreach ($arrModules as $strName => $arrModule) { - $arrLabel = $GLOBALS['TL_LANG']['MOD'][ $strName ]; + $arrLabel = $GLOBALS['TL_LANG']['MOD'][$strName]; $strModuleName = $strName; - if ( $arrLabel && is_array( $arrLabel ) ) $strModuleName = $arrLabel[0]; - if ( is_string( $arrLabel ) ) $strModuleName = $arrLabel; + if ($arrLabel && is_array($arrLabel)) $strModuleName = $arrLabel[0]; + if (is_string($arrLabel)) $strModuleName = $arrLabel; - $arrReturn[ $strName ] = $strModuleName; + $arrReturn[$strName] = $strModuleName; } return $arrReturn; } - - public function getNavigationPosition() { - return [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]; + public function getNavigationPosition() + { + + return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; } - - public function getChangeLanguageColumns( \DataContainer $dc ) { + + public function getChangeLanguageColumns(\DataContainer $dc) + { $strTable = ''; $arrReturn = []; - if ( !$dc->activeRecord->languageEntitySource ) return $arrReturn; + if (!$dc->activeRecord->languageEntitySource) return $arrReturn; - switch ( $dc->activeRecord->languageEntitySource ) { + switch ($dc->activeRecord->languageEntitySource) { case 'parentTable': @@ -404,19 +429,17 @@ public function getChangeLanguageColumns( \DataContainer $dc ) { break; } - if ( !$strTable ) return $arrReturn; + if (!$strTable) return $arrReturn; - if ( $this->Database->tableExists( $strTable ) ) { + if ($this->Database->tableExists($strTable)) { $objFieldBuilder = new CatalogFieldBuilder(); - $objFieldBuilder->initialize( $strTable ); - $arrFields = $objFieldBuilder->getCatalogFields( false, null ); - - foreach ( $arrFields as $strFieldname => $arrField ) { - - if ( !is_numeric( $strFieldname ) ) { + $objFieldBuilder->initialize($strTable); + $arrFields = $objFieldBuilder->getCatalogFields(false, null); - $arrReturn[ $strFieldname ] = $arrField['title'] ?: $strFieldname; + foreach ($arrFields as $strFieldname => $arrField) { + if (!is_numeric($strFieldname)) { + $arrReturn[$strFieldname] = $arrField['title'] ?? $strFieldname; } } } @@ -425,65 +448,70 @@ public function getChangeLanguageColumns( \DataContainer $dc ) { } - public function getInternalCatalogFields() { + public function getInternalCatalogFields() + { $arrReturn = []; $strID = \Input::get('id'); - $objCatalogFields = $this->Database->prepare( 'SELECT * FROM tl_catalog_fields WHERE `pid` = ? AND `pagePicker` = ?' )->execute( $strID, '1' ); + $objCatalogFields = $this->Database->prepare('SELECT * FROM tl_catalog_fields WHERE `pid` = ? AND `pagePicker` = ?')->execute($strID, '1'); - if ( !$objCatalogFields->numRows ) return $arrReturn; + if (!$objCatalogFields->numRows) return $arrReturn; - while ( $objCatalogFields->next() ) { + while ($objCatalogFields->next()) { - if ( !$objCatalogFields->fieldname ) continue; + if (!$objCatalogFields->fieldname) continue; - $arrReturn[ $objCatalogFields->fieldname ] = $objCatalogFields->title ? $objCatalogFields->title : $objCatalogFields->fieldname; + $arrReturn[$objCatalogFields->fieldname] = $objCatalogFields->title ? $objCatalogFields->title : $objCatalogFields->fieldname; } return $arrReturn; } - public function getExternalCatalogFields() { + public function getExternalCatalogFields() + { $arrReturn = []; $strID = \Input::get('id'); - $objCatalogFields = $this->Database->prepare( 'SELECT * FROM tl_catalog_fields WHERE `pid` = ? AND `rgxp` = ?' )->execute( $strID, 'url' ); + $objCatalogFields = $this->Database->prepare('SELECT * FROM tl_catalog_fields WHERE `pid` = ? AND `rgxp` = ?')->execute($strID, 'url'); - if ( !$objCatalogFields->numRows ) return $arrReturn; + if (!$objCatalogFields->numRows) return $arrReturn; - while ( $objCatalogFields->next() ) { + while ($objCatalogFields->next()) { - if ( !$objCatalogFields->fieldname ) continue; + if (!$objCatalogFields->fieldname) continue; - $arrReturn[ $objCatalogFields->fieldname ] = $objCatalogFields->title ? $objCatalogFields->title : $objCatalogFields->fieldname; + $arrReturn[$objCatalogFields->fieldname] = $objCatalogFields->title ? $objCatalogFields->title : $objCatalogFields->fieldname; } return $arrReturn; } - public function getPermissionTypes() { + public function getPermissionTypes() + { - return [ 'default', 'extended' ]; + return ['default', 'extended']; } - public function getSystemLanguages( \DataContainer $dc ) { + public function getSystemLanguages(\DataContainer $dc) + { $strFallback = $dc->activeRecord->fallbackLanguage; $arrLanguages = \System::getLanguages(); - if ( $strFallback ) { + if ($strFallback) { - unset( $arrLanguages[ $strFallback ] ); + unset($arrLanguages[$strFallback]); } return $arrLanguages; } - public function getFallbackLanguages() { + public function getFallbackLanguages() + { return \System::getLanguages(); } diff --git a/config/config.php b/config/config.php index b477f91c..80eb8a71 100644 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,6 @@ [ 'name' => 'support', - 'callback' => CatalogManager\SupportPage::class, + 'callback' => \CatalogManager\SupportPage::class, 'stylesheet' => 'system/modules/catalog-manager/assets/support.css', 'icon' => 'system/modules/catalog-manager/assets/icons/support-icon.svg' ], diff --git a/library/alnv/CatalogFieldBuilder.php b/library/alnv/CatalogFieldBuilder.php index 22d03847..b2fc63fc 100644 --- a/library/alnv/CatalogFieldBuilder.php +++ b/library/alnv/CatalogFieldBuilder.php @@ -324,9 +324,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) { $arrFields = [ - 'id' => [ - 'type' => '', 'sort' => '1', 'search' => '1', @@ -337,9 +335,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['id'][0], 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['id'][0] ], - 'tstamp' => [ - 'flag' => 6, 'type' => '', 'sort' => '1', @@ -351,9 +347,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['tstamp'][0], 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['tstamp'][0] ], - 'pid' => [ - 'type' => '', 'invisible' => '', 'disableFEE' => true, @@ -361,9 +355,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'fieldname' => 'pid', 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['pid'][0] ], - 'sorting' => [ - 'type' => '', 'invisible' => '', 'statement' => 'i10', @@ -371,9 +363,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'fieldname' => 'sorting', 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['sorting'][0] ], - 'title' => [ - 'sort' => '1', 'search' => '1', 'type' => 'text', @@ -390,9 +380,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['title'][0], 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['title'][0] ], - 'alias' => [ - 'search' => '1', 'unique' => '1', 'type' => 'text', @@ -409,9 +397,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['alias'][0], 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['alias'][0] ], - 'invisible' => [ - 'exclude' => '1', 'multiple' => '', 'invisible' => '', @@ -423,9 +409,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'cssID' => serialize(['', 'invisible']), 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['invisible'][0], ], - 'start' => [ - 'flag' => 6, 'sort' => '1', 'type' => 'date', @@ -441,9 +425,7 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) 'title' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['start'][0], 'placeholder' => &$GLOBALS['TL_LANG']['catalog_manager']['fields']['start'][0] ], - 'stop' => [ - 'flag' => 6, 'sort' => '1', 'type' => 'date', @@ -475,13 +457,11 @@ protected function getDefaultCatalogFields($arrIncludeOnly = []) } if (!in_array($this->arrCatalog['mode'], Toolkit::$arrRequireSortingModes) && !in_array('cut', $this->arrCatalog['operations'])) { - unset($arrFields['sorting']); } } if (isset($this->arrCatalog['type']) && $this->arrCatalog['type'] == 'modifier') { - unset($arrFields['id']); unset($arrFields['pid']); unset($arrFields['stop']); @@ -499,28 +479,24 @@ protected function prepareDefaultFields($arrField, $strFieldname, $blnCoreTable { if ($blnCoreTable) { - return $arrField; } switch ($strFieldname) { - case 'tstamp' : case 'id' : $arrField['_dcFormat'] = [ 'sorting' => $arrField['_dcFormat']['sorting'] ?? false, 'search' => $arrField['_dcFormat']['search'] ?? false, - 'label' => $arrField['_dcFormat']['label'] ?? '', + 'label' => $arrField['_dcFormat']['label'] ?? [], 'flag' => $arrField['_dcFormat']['flag'] ?? null, 'sql' => $arrField['_dcFormat']['sql'] ?? '' ]; - return $arrField; - case 'pid' : if ($this->arrCatalog['pTable']) { $arrField['_dcFormat'] = [ - 'label' => $arrField['_dcFormat']['label'], + 'label' => ($arrField['_dcFormat']['label']??[]), 'sql' => "int(10) unsigned NOT NULL default '0'", 'foreignKey' => sprintf('%s.id', $this->arrCatalog['pTable']), 'relation' => [ @@ -534,29 +510,20 @@ protected function prepareDefaultFields($arrField, $strFieldname, $blnCoreTable break; case 'sorting' : - if (in_array($this->arrCatalog['mode'], Toolkit::$arrRequireSortingModes)) { - $arrField['_dcFormat'] = [ - - 'label' => $arrField['_dcFormat']['label'], + 'label' => ($arrField['_dcFormat']['label']??[]), 'sql' => "int(10) unsigned NOT NULL default '0'" ]; - return $arrField; } break; - case 'alias': - if (TL_MODE == 'FE') return $arrField; - $arrField['_dcFormat']['save_callback'] = [function ($varValue, \DataContainer $dc) { - $objDcCallbacks = new DcCallbacks(); - return $objDcCallbacks->generateAlias($varValue, $dc, 'title', $this->strTable); }]; @@ -586,7 +553,6 @@ protected function getCoreFields($blnDcFormat) $strType = Toolkit::setCatalogConformInputType($arrField); $arrReturn[$strFieldname] = [ - '_core' => true, 'type' => $strType, 'fieldname' => $strFieldname, diff --git a/library/alnv/CatalogView.php b/library/alnv/CatalogView.php index 15070bc4..be026895 100644 --- a/library/alnv/CatalogView.php +++ b/library/alnv/CatalogView.php @@ -3,7 +3,8 @@ namespace CatalogManager; -class CatalogView extends CatalogController { +class CatalogView extends CatalogController +{ public $strMode; @@ -36,23 +37,25 @@ class CatalogView extends CatalogController { protected $arrCatalogMapViewOptions = []; - public function __construct() { + public function __construct() + { parent::__construct(); - $this->import( 'IconGetter' ); - $this->import( 'CatalogInput' ); - $this->import( 'CatalogEvents' ); - $this->import( 'TemplateHelper' ); - $this->import( 'SQLQueryHelper' ); - $this->import( 'SQLQueryBuilder' ); - $this->import( 'CatalogFieldBuilder' ); - $this->import( 'I18nCatalogTranslator' ); - $this->import( 'FrontendEditingPermission' ); + $this->import('IconGetter'); + $this->import('CatalogInput'); + $this->import('CatalogEvents'); + $this->import('TemplateHelper'); + $this->import('SQLQueryHelper'); + $this->import('SQLQueryBuilder'); + $this->import('CatalogFieldBuilder'); + $this->import('I18nCatalogTranslator'); + $this->import('FrontendEditingPermission'); } - public function initialize() { + public function initialize() + { $this->objMainTemplate = $this->objMainTemplate ?? new \stdClass(); @@ -66,30 +69,30 @@ public function initialize() { $this->I18nCatalogTranslator->initialize(); - if ( !$this->catalogTablename ) return null; + if (!$this->catalogTablename) return null; - $this->CatalogFieldBuilder->initialize( $this->catalogTablename ); + $this->CatalogFieldBuilder->initialize($this->catalogTablename); $this->arrCatalog = $this->CatalogFieldBuilder->getCatalog(); - $this->arrCatalogFields = $this->CatalogFieldBuilder->getCatalogFields( false, $this ); + $this->arrCatalogFields = $this->CatalogFieldBuilder->getCatalogFields(false, $this); - if ( !empty( $this->arrCatalogFields ) && is_array( $this->arrCatalogFields ) ) { + if (!empty($this->arrCatalogFields) && is_array($this->arrCatalogFields)) { - foreach ( $this->arrCatalogFields as $strID => $arrField ) { + foreach ($this->arrCatalogFields as $strID => $arrField) { - if ( !$arrField['fieldname'] || !$arrField['type'] ) continue; + if (!$arrField['fieldname'] || !$arrField['type']) continue; - $arrFieldLabels = $this->I18nCatalogTranslator->get( 'field', $arrField['fieldname'], [ 'table' => $this->catalogTablename, 'title' => $arrField['title'], 'description' => $arrField['description']??'' ] ); + $arrFieldLabels = $this->I18nCatalogTranslator->get('field', $arrField['fieldname'], ['table' => $this->catalogTablename, 'title' => $arrField['title'], 'description' => $arrField['description'] ?? '']); - $this->arrCatalogFields[ $strID ][ 'title' ] = $arrFieldLabels[0]; - $this->arrCatalogFields[ $strID ][ 'description' ] = $arrFieldLabels[1]; + $this->arrCatalogFields[$strID]['title'] = $arrFieldLabels[0]; + $this->arrCatalogFields[$strID]['description'] = $arrFieldLabels[1]; - if ( in_array( $arrField['type'], [ 'map', 'message' ] ) ) { + if (in_array($arrField['type'], ['map', 'message'])) { $this->arrCatalogStaticFields[] = $strID; } - $this->setPreviewEntityFields( $arrField['fieldname'], $this->arrCatalogFields[ $strID ] ); + $this->setPreviewEntityFields($arrField['fieldname'], $this->arrCatalogFields[$strID]); } } @@ -99,23 +102,23 @@ public function initialize() { $this->arrMasterPage = $this->arrPage; $this->arrFrontendEditingPage = $this->arrPage; - if ( $this->catalogUseViewPage && $this->catalogViewPage !== '0' ) { + if ($this->catalogUseViewPage && $this->catalogViewPage !== '0') { - $this->arrViewPage = $this->getPageModel( $this->catalogViewPage ); + $this->arrViewPage = $this->getPageModel($this->catalogViewPage); } - if ( $this->catalogUseMasterPage && $this->catalogMasterPage !== '0' ) { + if ($this->catalogUseMasterPage && $this->catalogMasterPage !== '0') { - $this->arrMasterPage = $this->getPageModel( $this->catalogMasterPage ); + $this->arrMasterPage = $this->getPageModel($this->catalogMasterPage); } - if ( $this->catalogUseFrontendEditingViewPage && $this->catalogFrontendEditingViewPage !== '0' ) { + if ($this->catalogUseFrontendEditingViewPage && $this->catalogFrontendEditingViewPage !== '0') { - $this->arrFrontendEditingPage = $this->getPageModel( $this->catalogFrontendEditingViewPage ); + $this->arrFrontendEditingPage = $this->getPageModel($this->catalogFrontendEditingViewPage); } - if ( $this->catalogUseMap && $this->strMode == 'view' ) { - + if ($this->catalogUseMap && $this->strMode == 'view') { + $this->arrCatalogMapViewOptions = Map::getMapViewOptions([ 'id' => 'map_' . $this->id, @@ -134,44 +137,44 @@ public function initialize() { $this->strTemplate = $this->catalogMapTemplate; } - $this->catalogOrderBy = Toolkit::deserialize( $this->catalogOrderBy ); - $this->catalogDownloads = Toolkit::deserialize( $this->catalogDownloads ); - $this->catalogTaxonomies = Toolkit::deserialize( $this->catalogTaxonomies ); - $this->catalogJoinFields = Toolkit::parseStringToArray( $this->catalogJoinFields ); - $this->catalogItemOperations = Toolkit::deserialize( $this->catalogItemOperations ); - $this->catalogJoinCTables = Toolkit::parseStringToArray( $this->catalogJoinCTables ); - $this->catalogRelatedChildTables = Toolkit::deserialize( $this->catalogRelatedChildTables ); - $this->catalogExcludeArrayOptions = Toolkit::deserialize( $this->catalogExcludeArrayOptions ); - $this->catalogPreventFieldFromFastMode = Toolkit::deserialize( $this->catalogPreventFieldFromFastMode ); + $this->catalogOrderBy = Toolkit::deserialize($this->catalogOrderBy); + $this->catalogDownloads = Toolkit::deserialize($this->catalogDownloads); + $this->catalogTaxonomies = Toolkit::deserialize($this->catalogTaxonomies); + $this->catalogJoinFields = Toolkit::parseStringToArray($this->catalogJoinFields); + $this->catalogItemOperations = Toolkit::deserialize($this->catalogItemOperations); + $this->catalogJoinCTables = Toolkit::parseStringToArray($this->catalogJoinCTables); + $this->catalogRelatedChildTables = Toolkit::deserialize($this->catalogRelatedChildTables); + $this->catalogExcludeArrayOptions = Toolkit::deserialize($this->catalogExcludeArrayOptions); + $this->catalogPreventFieldFromFastMode = Toolkit::deserialize($this->catalogPreventFieldFromFastMode); $this->setRelatedTables(); - if ( $objPage->catalogRoutingTable && $objPage->catalogRoutingTable !== $this->catalogTablename ) { + if ($objPage->catalogRoutingTable && $objPage->catalogRoutingTable !== $this->catalogTablename) { $objPage->catalogUseRouting = ''; } - if ( $objPage->catalogUseRouting && $objPage->catalogRouting && !\Config::get('CTLG_IGNORE_LIST_ROUTING') ) { + if ($objPage->catalogUseRouting && $objPage->catalogRouting && !\Config::get('CTLG_IGNORE_LIST_ROUTING')) { - $this->arrRoutingParameter = Toolkit::getRoutingParameter( $objPage->catalogRouting ); + $this->arrRoutingParameter = Toolkit::getRoutingParameter($objPage->catalogRouting); } - if ( empty( $this->arrRoutingParameter ) && $this->catalogUseMasterPage ) { + if (empty($this->arrRoutingParameter) && $this->catalogUseMasterPage) { - if ( $this->arrMasterPage['catalogUseRouting'] ) { + if ($this->arrMasterPage['catalogUseRouting']) { - $this->arrRoutingParameter = Toolkit::getRoutingParameter( $this->arrMasterPage['catalogRouting'] ); + $this->arrRoutingParameter = Toolkit::getRoutingParameter($this->arrMasterPage['catalogRouting']); } } - if ( $this->enableTableView && $this->strMode == 'view' ) { + if ($this->enableTableView && $this->strMode == 'view') { $this->strTemplate = $this->catalogTableBodyViewTemplate; $this->catalogActiveTableColumns = $this->setActiveTableColumns(); $this->objMainTemplate->activeTableColumns = $this->catalogActiveTableColumns ?: []; - $this->objMainTemplate->hasRelations = (bool) $this->catalogUseRelation; - $this->objMainTemplate->hasDownloads = (bool) $this->catalogUseDownloads; + $this->objMainTemplate->hasRelations = (bool)$this->catalogUseRelation; + $this->objMainTemplate->hasDownloads = (bool)$this->catalogUseDownloads; $this->objMainTemplate->readMoreColumnTitle = $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['detailLink']; $this->objMainTemplate->sharingButtonsColumnTitle = $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['sharing']; $this->objMainTemplate->downloadsColumnTitle = $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['downloadLinks']; @@ -188,41 +191,41 @@ public function initialize() { $this->objMainTemplate->catalogEntityFields = $this->arrEntityFields; $this->objMainTemplate->mapProtected = \Config::get('catalogMapProtected'); - $this->objMainTemplate->mapPrivacyText = \Controller::replaceInsertTags( \Config::get('catalogMapPrivacyText') ); - $this->objMainTemplate->mapPrivacyButtonText = \Controller::replaceInsertTags( ( \Config::get('catalogMapPrivacyButtonText') ?: $GLOBALS['TL_LANG']['MSC']['googleMapPrivacyAcceptText'] ) ); + $this->objMainTemplate->mapPrivacyText = \Controller::replaceInsertTags(\Config::get('catalogMapPrivacyText')); + $this->objMainTemplate->mapPrivacyButtonText = \Controller::replaceInsertTags((\Config::get('catalogMapPrivacyButtonText') ?: $GLOBALS['TL_LANG']['MSC']['googleMapPrivacyAcceptText'])); $this->FrontendEditingPermission->blnDisablePermissions = $this->catalogEnableFrontendPermission ? false : true; - if ( !$this->FrontendEditingPermission->blnDisablePermissions ) { + if (!$this->FrontendEditingPermission->blnDisablePermissions) { $this->FrontendEditingPermission->initialize(); } - if ( $this->catalogUseSocialSharingButtons ) { + if ($this->catalogUseSocialSharingButtons) { - $this->import( 'SocialSharingButtons' ); + $this->import('SocialSharingButtons'); $blnDefaultTheme = $this->catalogDisableSocialSharingCSS ? false : true; - $arrSocialSharingButtons = Toolkit::deserialize( $this->catalogSocialSharingButtons ); - $this->SocialSharingButtons->initialize( $arrSocialSharingButtons, $this->catalogSocialSharingTemplate, $blnDefaultTheme, [ + $arrSocialSharingButtons = Toolkit::deserialize($this->catalogSocialSharingButtons); + $this->SocialSharingButtons->initialize($arrSocialSharingButtons, $this->catalogSocialSharingTemplate, $blnDefaultTheme, [ 'catalogSocialSharingCssID' => $this->catalogSocialSharingCssID, 'catalogSocialSharingHeadline' => $this->catalogSocialSharingHeadline ]); } - if ( \Input::get( 'toggleVisibility' . $this->id ) ) { + if (\Input::get('toggleVisibility' . $this->id)) { $this->toggleVisibility(); } - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerInitializeView'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerInitializeView'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerInitializeView']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerInitializeView'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerInitializeView'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerInitializeView'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $this->{$arrCallback[0]}->{$arrCallback[1]}( $this ); + $this->import($arrCallback[0]); + $this->{$arrCallback[0]}->{$arrCallback[1]}($this); } } } @@ -231,13 +234,14 @@ public function initialize() { } - protected function toggleVisibility() { + protected function toggleVisibility() + { - $strId = \Input::get( 'toggleVisibility' . $this->id ); + $strId = \Input::get('toggleVisibility' . $this->id); - if ( $this->catalogTablename && $this->SQLQueryHelper->SQLQueryBuilder->Database->fieldExists( 'invisible', $this->catalogTablename ) ) { + if ($this->catalogTablename && $this->SQLQueryHelper->SQLQueryBuilder->Database->fieldExists('invisible', $this->catalogTablename)) { - $objEntity = $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare( 'SELECT invisible FROM '. $this->catalogTablename .' WHERE id = ?' )->limit(1)->execute( $strId ); + $objEntity = $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare('SELECT invisible FROM ' . $this->catalogTablename . ' WHERE id = ?')->limit(1)->execute($strId); $strValue = $objEntity->invisible ? '' : '1'; $dteTime = \Date::floorToMinute(); @@ -249,7 +253,7 @@ protected function toggleVisibility() { ]; - $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare( 'UPDATE '. $this->catalogTablename .' %s WHERE id = ?' )->set( $arrValues )->execute( $strId ); + $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare('UPDATE ' . $this->catalogTablename . ' %s WHERE id = ?')->set($arrValues)->execute($strId); $arrData = [ @@ -258,24 +262,27 @@ protected function toggleVisibility() { 'table' => $this->catalogTablename, ]; - $this->CatalogEvents->addEventListener( 'update', $arrData, $this ); + $this->CatalogEvents->addEventListener('update', $arrData, $this); } } - public function showAsGroup() { + public function showAsGroup() + { return $this->blnShowAsGroup; } - public function getHasOperationFlag() { + public function getHasOperationFlag() + { return $this->blnHasOperations; } - public function setActiveTableColumns() { + public function setActiveTableColumns() + { $this->catalogActiveTableColumns = Toolkit::deserialize($this->catalogActiveTableColumns, true); @@ -296,68 +303,72 @@ public function setActiveTableColumns() { } - protected function setPreviewEntityFields( $strFieldname, $arrField ) { + protected function setPreviewEntityFields($strFieldname, $arrField) + { - if ( in_array( $strFieldname, [ 'title', 'alias', 'id', 'pid', 'sorting', 'tstamp' ] ) ) { + if (in_array($strFieldname, ['title', 'alias', 'id', 'pid', 'sorting', 'tstamp'])) { return null; } - if ( $arrField['type'] == 'dbColumn' ) { + if ($arrField['type'] == 'dbColumn') { return null; } - if ( $arrField['type'] == 'upload' && $arrField['useArrayFormat'] ) { + if ($arrField['type'] == 'upload' && $arrField['useArrayFormat']) { return null; } - $this->arrEntityFields[ $strFieldname ] = $arrField; + $this->arrEntityFields[$strFieldname] = $arrField; } - protected function rebuildCatalogFieldIndexes() { + protected function rebuildCatalogFieldIndexes() + { $arrReturn = []; - if ( !empty( $this->arrCatalogFields ) && is_array( $this->arrCatalogFields ) ) { + if (!empty($this->arrCatalogFields) && is_array($this->arrCatalogFields)) { - foreach ( $this->arrCatalogFields as $arrCatalogField ) { + foreach ($this->arrCatalogFields as $arrCatalogField) { - if ( !$arrCatalogField['fieldname'] ) continue; + if (!$arrCatalogField['fieldname']) continue; - $arrReturn[ $arrCatalogField['fieldname'] ] = $arrCatalogField; - } + $arrReturn[$arrCatalogField['fieldname']] = $arrCatalogField; + } } $this->arrCatalogFields = $arrReturn; } - public function getMapViewOptions() { + public function getMapViewOptions() + { return $this->arrCatalogMapViewOptions; } - public function getCatalogView( $arrQuery ) { + public function getCatalogView($arrQuery) + { global $objPage; - $this->catalogOffset = (int) $this->catalogOffset; + $this->catalogOffset = (int)$this->catalogOffset; $blnActive = $this->catalogActiveParameters ? false : true; $intOffset = $this->catalogOffset; $strPageID = 'page_e' . $this->id; - $intPerPage = intval( $this->catalogPerPage ); - $intPagination = intval( \Input::get( $strPageID ) ); + $intPerPage = intval($this->catalogPerPage); + $intPagination = intval(\Input::get($strPageID)); $arrQuery['table'] = $this->catalogTablename; $arrQuery['joins'] = []; - $arrTaxonomies = []; + $arrTaxonomies = []; - if ( !$this->catalogTablename || !$this->SQLQueryBuilder->tableExist( $this->catalogTablename ) ) return ''; + if (!$this->catalogTablename || !$this->SQLQueryBuilder->tableExist($this->catalogTablename)) return ''; if (!empty($this->catalogJoinFields) || is_array($this->catalogJoinFields)) { $this->prepareJoinData($arrQuery['joins']); @@ -368,14 +379,13 @@ public function getCatalogView( $arrQuery ) { $this->preparePTableJoinData($arrQuery['joins']); } - if ( in_array( $this->strMode, [ 'view', 'master' ] ) && !empty( $this->catalogTaxonomies['query'] ) && is_array( $this->catalogTaxonomies['query'] ) && $this->catalogUseTaxonomies ) { - - $arrTaxonomies = Toolkit::parseQueries( $this->catalogTaxonomies['query'] ); + if (in_array($this->strMode, ['view', 'master']) && !empty($this->catalogTaxonomies['query']) && is_array($this->catalogTaxonomies['query']) && $this->catalogUseTaxonomies) { + $arrTaxonomies = Toolkit::parseQueries($this->catalogTaxonomies['query']); } - array_insert( $arrQuery['where'], 0, $arrTaxonomies ); + array_insert($arrQuery['where'], 0, $arrTaxonomies); - if ( $this->hasVisibility() ) { + if ($this->hasVisibility()) { $dteTime = \Date::floorToMinute(); @@ -423,47 +433,44 @@ public function getCatalogView( $arrQuery ) { 'value' => '1' ]; } - - if ( $this->catalogUseRadiusSearch && $this->strMode == 'view' ) { + + if ($this->catalogUseRadiusSearch && $this->strMode == 'view') { $arrRSValues = []; - $strDistance = $this->CatalogInput->getActiveValue( 'rs_dstnc' ); - $arrRSAttributes = [ 'rs_cty', 'rs_strt', 'rs_pstl', 'rs_cntry', 'rs_strtn' ]; + $strDistance = $this->CatalogInput->getActiveValue('rs_dstnc'); + $arrRSAttributes = ['rs_cty', 'rs_strt', 'rs_pstl', 'rs_cntry', 'rs_strtn']; - if ( Toolkit::isEmpty( $strDistance ) || is_array( $strDistance ) ) { + if (Toolkit::isEmpty($strDistance) || is_array($strDistance)) { $strDistance = '50'; } - foreach ( $arrRSAttributes as $strSRAttribute ) { + foreach ($arrRSAttributes as $strSRAttribute) { - $strValue = $this->CatalogInput->getActiveValue( $strSRAttribute ); + $strValue = $this->CatalogInput->getActiveValue($strSRAttribute); - if ( !Toolkit::isEmpty( $strValue ) && is_string( $strValue ) ) { + if (!Toolkit::isEmpty($strValue) && is_string($strValue)) { - $arrRSValues[ $strSRAttribute ] = $strValue; + $arrRSValues[$strSRAttribute] = $strValue; } } - if ( !empty( $arrRSValues ) && is_array( $arrRSValues ) ) { - - if ( !$arrRSValues['rs_cntry'] && $this->catalogRadioSearchCountry ) { + if (!empty($arrRSValues) && is_array($arrRSValues)) { + if (!$arrRSValues['rs_cntry'] && $this->catalogRadioSearchCountry) { $arrRSValues['rs_cntry'] = $this->catalogRadioSearchCountry; } - - $objGeoCoding = new GeoCoding(); - $objGeoCoding->setCity( $arrRSValues['rs_cty'] ); - $objGeoCoding->setStreet( $arrRSValues['rs_strt'] ); - $objGeoCoding->setPostal( $arrRSValues['rs_pstl'] ); - $objGeoCoding->setCountry( $arrRSValues['rs_cntry'] ); - $objGeoCoding->setStreetNumber( $arrRSValues['rs_strtn'] ); - $arrCords = $objGeoCoding->getCords( '', 'en', true ); - - if ( $arrCords['lat'] && $arrCords['lng'] ) { + $objGeoCoding = new GeoCoding(); + $objGeoCoding->setCity($arrRSValues['rs_cty']); + $objGeoCoding->setStreet($arrRSValues['rs_strt']); + $objGeoCoding->setPostal($arrRSValues['rs_pstl']); + $objGeoCoding->setCountry($arrRSValues['rs_cntry']); + $objGeoCoding->setStreetNumber($arrRSValues['rs_strtn']); + $arrCords = $objGeoCoding->getCords('', 'en', true); + + if ($arrCords['lat'] && $arrCords['lng']) { $arrQuery['distance'] = [ - 'value' => $strDistance, 'latCord' => $arrCords['lat'], 'lngCord' => $arrCords['lng'], @@ -476,31 +483,24 @@ public function getCatalogView( $arrQuery ) { } } - if ( !isset( $arrQuery['distance'] ) && $this->CatalogInput->getActiveValue( '_latitude' ) && $this->CatalogInput->getActiveValue( '_longitude' ) ) { + if (!isset($arrQuery['distance']) && $this->CatalogInput->getActiveValue('_latitude') && $this->CatalogInput->getActiveValue('_longitude')) { $arrQuery['distance'] = [ - 'value' => $strDistance, - 'latCord' => $this->CatalogInput->getActiveValue( '_latitude' ), - 'lngCord' => $this->CatalogInput->getActiveValue( '_longitude' ), + 'latCord' => $this->CatalogInput->getActiveValue('_latitude'), + 'lngCord' => $this->CatalogInput->getActiveValue('_longitude'), 'latField' => $this->catalogFieldLat, 'lngField' => $this->catalogFieldLng ]; } } - if ( is_array( $this->catalogOrderBy ) ) { - + if (is_array($this->catalogOrderBy)) { $this->setOrderByParameters(); - - if ( !empty( $this->catalogOrderBy ) ) { - - foreach ( $this->catalogOrderBy as $arrOrderBy ) { - - if ( $arrOrderBy['key'] && $arrOrderBy['value'] ) { - + if (!empty($this->catalogOrderBy)) { + foreach ($this->catalogOrderBy as $arrOrderBy) { + if ($arrOrderBy['key'] && $arrOrderBy['value']) { $arrQuery['orderBy'][] = [ - 'field' => $arrOrderBy['key'], 'order' => $arrOrderBy['value'] ]; @@ -509,38 +509,37 @@ public function getCatalogView( $arrQuery ) { } } - if ( $this->catalogEnableParentFilter ) { + if ($this->catalogEnableParentFilter) { - if ( \Input::get( 'pid' ) ) { + if (\Input::get('pid')) { $arrQuery['where'][] = [ - 'field' => 'pid', 'operator' => 'equal', - 'value' => \Input::get( 'pid' ) + 'value' => \Input::get('pid') ]; } } - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerViewQuery'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerViewQuery'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerViewQuery']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerViewQuery'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerViewQuery'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerViewQuery'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $arrQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}( $arrQuery, $this ); + $this->import($arrCallback[0]); + $arrQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}($arrQuery, $this); } } } - if ( $this->catalogActiveParameters ) { + if ($this->catalogActiveParameters) { - $arrActiveParameterFields = explode( ',', $this->catalogActiveParameters ); + $arrActiveParameterFields = explode(',', $this->catalogActiveParameters); - foreach ( $arrActiveParameterFields as $strFieldname ) { + foreach ($arrActiveParameterFields as $strFieldname) { - if ( $this->CatalogInput->getActiveValue( $strFieldname ) !== '' && $this->CatalogInput->getActiveValue( $strFieldname ) !== null ) { + if ($this->CatalogInput->getActiveValue($strFieldname) !== '' && $this->CatalogInput->getActiveValue($strFieldname) !== null) { $blnActive = true; @@ -549,14 +548,14 @@ public function getCatalogView( $arrQuery ) { } } - if ( !$blnActive ) { + if (!$blnActive) { - if ( $this->blnGoogleMapScript ) { + if ($this->blnGoogleMapScript) { $GLOBALS['TL_HEAD']['CatalogManagerGoogleMaps'] = Map::generateGoogleMapJSInitializer(); } - if ( $this->catalogUseArray || $this->blnShowAsGroup ) { + if ($this->catalogUseArray || $this->blnShowAsGroup) { return []; } @@ -564,9 +563,9 @@ public function getCatalogView( $arrQuery ) { return ''; } - $intTotal = $this->SQLQueryBuilder->execute( $arrQuery )->count(); + $intTotal = $this->SQLQueryBuilder->execute($arrQuery)->count(); - if ( $this->strMode == 'view' ) { + if ($this->strMode == 'view') { $arrQuery['pagination'] = [ @@ -575,18 +574,18 @@ public function getCatalogView( $arrQuery ) { ]; } - if ( $this->catalogOffset ) $intTotal -= $intOffset; + if ($this->catalogOffset) $intTotal -= $intOffset; - if ( \Input::get( $strPageID ) && $this->catalogAddPagination ) { + if (\Input::get($strPageID) && $this->catalogAddPagination) { $intOffset = $intPagination; - if ( $intPerPage > 0 && $this->catalogOffset ) { + if ($intPerPage > 0 && $this->catalogOffset) { - $intOffset += round( $this->catalogOffset / $intPerPage ); + $intOffset += round($this->catalogOffset / $intPerPage); } - $arrQuery['pagination']['offset'] = ( $intOffset - 1 ) * $intPerPage; + $arrQuery['pagination']['offset'] = ($intOffset - 1) * $intPerPage; } $arrCatalogs = []; @@ -594,9 +593,9 @@ public function getCatalogView( $arrQuery ) { $objEntities = $this->SQLQueryBuilder->execute($arrQuery); $intNumRows = $objEntities->numRows; - if ( $this->strMode == 'view' ) $this->objMainTemplate->entityIndex = [ $intNumRows, $intTotal ]; + if ($this->strMode == 'view') $this->objMainTemplate->entityIndex = [$intNumRows, $intTotal]; - while ( $objEntities->next() ) { + while ($objEntities->next()) { $arrCatalog = $objEntities->row(); $intCurrentEntity++; @@ -604,114 +603,114 @@ public function getCatalogView( $arrQuery ) { $arrCatalog['useSocialSharingButtons'] = $this->catalogUseSocialSharingButtons ? true : false; $arrCatalog['origin'] = $arrCatalog; - if ( $this->strMode === 'master' ) { + if ($this->strMode === 'master') { $this->strMasterID = $arrCatalog['id']; } - $arrCatalog['masterUrl'] = $this->getMasterRedirect( $arrCatalog, $arrCatalog['alias'] ); + $arrCatalog['masterUrl'] = $this->getMasterRedirect($arrCatalog, $arrCatalog['alias']); $arrCatalog['hasGoBackLink'] = $this->catalogUseViewPage && $this->catalogViewPage !== '0'; - if ( !empty( $this->arrViewPage ) ) { + if (!empty($this->arrViewPage)) { - $arrCatalog['goBackLink'] = $this->generateUrl( $this->arrViewPage, '' ); + $arrCatalog['goBackLink'] = $this->generateUrl($this->arrViewPage, ''); $arrCatalog['goBackLabel'] = $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['back']; } - if ( $this->catalogEnableFrontendEditing ) { + if ($this->catalogEnableFrontendEditing) { - $arrCatalog['operations'] = $this->generateOperations( $arrCatalog['id'], $arrCatalog['alias'], $arrCatalog ); + $arrCatalog['operations'] = $this->generateOperations($arrCatalog['id'], $arrCatalog['alias'], $arrCatalog); } - if ( $this->catalogUseDownloads ) { + if ($this->catalogUseDownloads) { - $arrCatalog['downloads'] = $this->generateDownloads( $arrCatalog['id'], $arrCatalog['alias'] ); + $arrCatalog['downloads'] = $this->generateDownloads($arrCatalog['id'], $arrCatalog['alias']); } - if ( !empty( $arrCatalog ) && is_array( $arrCatalog ) ) { + if (!empty($arrCatalog) && is_array($arrCatalog)) { - if ( $arrCatalog['id'] && !empty( $this->catalogJoinCTables ) ) { + if ($arrCatalog['id'] && !empty($this->catalogJoinCTables)) { - foreach ( $this->catalogJoinCTables as $strTable ) { + foreach ($this->catalogJoinCTables as $strTable) { - $arrCatalog[ $strTable ] = $this->getChildrenByIdAndTable( $arrCatalog['id'], $strTable ); + $arrCatalog[$strTable] = $this->getChildrenByIdAndTable($arrCatalog['id'], $strTable); } } - foreach ( $arrCatalog as $strFieldname => $varValue ) { + foreach ($arrCatalog as $strFieldname => $varValue) { - if ( isset( $this->arrParseAsArray[ $strFieldname ] ) ) { + if (isset($this->arrParseAsArray[$strFieldname])) { - $arrCatalog[ $strFieldname ] = $this->getJoinedEntities( $varValue, $strFieldname ); + $arrCatalog[$strFieldname] = $this->getJoinedEntities($varValue, $strFieldname); continue; } - $arrCatalog[ $strFieldname ] = $this->parseCatalogValues( $varValue, $strFieldname, $arrCatalog ); + $arrCatalog[$strFieldname] = $this->parseCatalogValues($varValue, $strFieldname, $arrCatalog); } } - if ( $this->catalogUseRelation ) { + if ($this->catalogUseRelation) { - $arrCatalog['relations'] = $this->setRelatedTableLinks( $arrCatalog['id'] ); + $arrCatalog['relations'] = $this->setRelatedTableLinks($arrCatalog['id']); } $arrCatalog['contentElements'] = ''; - if ( ( $this->strMode === 'master' || $this->catalogAddContentElements ) && $this->arrCatalog['addContentElements'] ) { + if (($this->strMode === 'master' || $this->catalogAddContentElements) && $this->arrCatalog['addContentElements']) { - $objContent = \ContentModel::findPublishedByPidAndTable( $arrCatalog['id'] , $this->catalogTablename ); + $objContent = \ContentModel::findPublishedByPidAndTable($arrCatalog['id'], $this->catalogTablename); - if ( $objContent !== null ) { + if ($objContent !== null) { - while ( $objContent->next() ) { + while ($objContent->next()) { - $arrCatalog['contentElements'] .= $this->getContentElement( $objContent->current() ); + $arrCatalog['contentElements'] .= $this->getContentElement($objContent->current()); } } } - if ( !empty( $this->arrCatalogStaticFields ) && is_array( $this->arrCatalogStaticFields ) && !$this->blnMapViewMode ) { + if (!empty($this->arrCatalogStaticFields) && is_array($this->arrCatalogStaticFields) && !$this->blnMapViewMode) { - foreach ( $this->arrCatalogStaticFields as $strID ) { + foreach ($this->arrCatalogStaticFields as $strID) { - $arrField = $this->arrCatalogFields[ $strID ]; + $arrField = $this->arrCatalogFields[$strID]; - switch ( $arrField['type'] ) { + switch ($arrField['type']) { case 'map': - if ( !$this->blnGoogleMapScript ) $this->blnGoogleMapScript = true; + if (!$this->blnGoogleMapScript) $this->blnGoogleMapScript = true; - $arrCatalog[ $strID ] = Map::parseValue( '', $arrField, $arrCatalog ); + $arrCatalog[$strID] = Map::parseValue('', $arrField, $arrCatalog); break; case 'message': - $arrCatalog[ $strID ] = MessageInput::parseValue( '', $arrField, $arrCatalog ); + $arrCatalog[$strID] = MessageInput::parseValue('', $arrField, $arrCatalog); break; } } } - if ( $this->blnMapViewMode ) { + if ($this->blnMapViewMode) { - $this->arrCatalogMapViewOptions['mapInfoBoxContent'] = Map::parseInfoBoxContent( $this->catalogMapInfoBoxContent, $arrCatalog ); - $this->arrCatalogMapViewOptions['locationLat'] = $arrCatalog[ $this->catalogFieldLat ]; - $this->arrCatalogMapViewOptions['locationLng'] = $arrCatalog[ $this->catalogFieldLng ]; + $this->arrCatalogMapViewOptions['mapInfoBoxContent'] = Map::parseInfoBoxContent($this->catalogMapInfoBoxContent, $arrCatalog); + $this->arrCatalogMapViewOptions['locationLat'] = $arrCatalog[$this->catalogFieldLat]; + $this->arrCatalogMapViewOptions['locationLng'] = $arrCatalog[$this->catalogFieldLng]; $arrCatalog['map'] = $this->arrCatalogMapViewOptions; } if ($this->strMode == 'master') { if ($this->catalogSEOTitle) { - $arrCatalog[$this->catalogSEOTitle] ?? ''; + $arrCatalog[$this->catalogSEOTitle] ?? ''; $objPage->pageTitle = $arrCatalog[$this->catalogSEOTitle] ? strip_tags($arrCatalog[$this->catalogSEOTitle]) : $objPage->pageTitle; } if ($this->catalogSEODescription) { - $arrCatalog[$this->catalogSEODescription] ?? ''; + $arrCatalog[$this->catalogSEODescription] ?? ''; $objPage->description = $arrCatalog[$this->catalogSEODescription] ? strip_tags($arrCatalog[$this->catalogSEODescription]) : $objPage->description; } } @@ -725,34 +724,34 @@ public function getCatalogView( $arrQuery ) { $arrCatalog['catalogEntityFields'] = $this->arrEntityFields; $arrCatalog['readMore'] = $GLOBALS['TL_LANG']['MSC']['more']; - if ( $this->strMode == 'view' ) { + if ($this->strMode == 'view') { $intPageNumber = $intPagination - 1; $intPageOffset = !$this->catalogOffset ? $intPerPage : $this->catalogOffset; $intMultiplicator = $intPageNumber > 0 ? $intPageOffset * $intPageNumber : 0; - $arrCatalog['entityIndex'] = [ $intCurrentEntity + $intMultiplicator, $intTotal ]; + $arrCatalog['entityIndex'] = [$intCurrentEntity + $intMultiplicator, $intTotal]; } - if ( $this->enableTableView && $this->strMode == 'view' ) { + if ($this->enableTableView && $this->strMode == 'view') { $arrCatalog['activeTableColumns'] = $this->catalogActiveTableColumns; } - if ( $this->blnShowAsGroup && !$this->enableTableView ) { + if ($this->blnShowAsGroup && !$this->enableTableView) { - $this->createGroups( $arrCatalog[ $this->catalogGroupBy ] ); + $this->createGroups($arrCatalog[$this->catalogGroupBy]); } - if ( $arrCatalog['useSocialSharingButtons'] ) { + if ($arrCatalog['useSocialSharingButtons']) { - $arrCatalog['socialSharingButtons'] = $this->SocialSharingButtons->render( $arrCatalog, $this->catalogSEOTitle, $this->catalogSEODescription ); + $arrCatalog['socialSharingButtons'] = $this->SocialSharingButtons->render($arrCatalog, $this->catalogSEOTitle, $this->catalogSEODescription); } - if ( isset($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog'])) { - foreach ($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { - $this->import( $arrCallback[0] ); - $this->{$arrCallback[0]}->{$arrCallback[1]}( $arrCatalog, $this->catalogTablename, $this); + if (isset($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog'])) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerRenderCatalog'] as $arrCallback) { + if (is_array($arrCallback)) { + $this->import($arrCallback[0]); + $this->{$arrCallback[0]}->{$arrCallback[1]}($arrCatalog, $this->catalogTablename, $this); } } if (empty($arrCatalog)) { @@ -760,61 +759,63 @@ public function getCatalogView( $arrQuery ) { } } - if ( $this->catalogUseArray ) { + if ($this->catalogUseArray) { - if ( in_array( 'origin', $this->catalogExcludeArrayOptions ) ) unset( $arrCatalog['origin'] ); - if ( in_array( 'catalogFields', $this->catalogExcludeArrayOptions ) ) unset( $arrCatalog['catalogFields'] ); - if ( in_array( 'catalogEntityFields', $this->catalogExcludeArrayOptions ) ) unset( $arrCatalog['catalogEntityFields'] ); + if (in_array('origin', $this->catalogExcludeArrayOptions)) unset($arrCatalog['origin']); + if (in_array('catalogFields', $this->catalogExcludeArrayOptions)) unset($arrCatalog['catalogFields']); + if (in_array('catalogEntityFields', $this->catalogExcludeArrayOptions)) unset($arrCatalog['catalogEntityFields']); } $arrCatalogs[] = $arrCatalog; } - - if ( $intPerPage > 0 && $this->catalogAddPagination && $this->strMode == 'view' ) { - $this->objMainTemplate->pagination = $this->TemplateHelper->addPagination( $intTotal, $intPerPage, $strPageID, ($this->arrViewPage['id']??'') ); + if ($intPerPage > 0 && $this->catalogAddPagination && $this->strMode == 'view') { + + $this->objMainTemplate->pagination = $this->TemplateHelper->addPagination($intTotal, $intPerPage, $strPageID, ($this->arrViewPage['id'] ?? '')); } - if ( $this->blnGoogleMapScript ) { + if ($this->blnGoogleMapScript) { $GLOBALS['TL_HEAD']['CatalogManagerGoogleMaps'] = Map::generateGoogleMapJSInitializer(); } - if ( $this->catalogRandomSorting ) shuffle( $arrCatalogs ); - if ( $this->catalogUseArray ) return $this->getArrayValue( $arrCatalogs, $intNumRows ); - if ( $this->blnShowAsGroup && !$this->enableTableView ) return $this->getGroupedValue( $arrCatalogs ); + if ($this->catalogRandomSorting) shuffle($arrCatalogs); + if ($this->catalogUseArray) return $this->getArrayValue($arrCatalogs, $intNumRows); + if ($this->blnShowAsGroup && !$this->enableTableView) return $this->getGroupedValue($arrCatalogs); - return $this->getTemplateValue( $arrCatalogs, $intNumRows ); + return $this->getTemplateValue($arrCatalogs, $intNumRows); } - protected function setHasOperationsFlag() { + protected function setHasOperationsFlag() + { - if ( !$this->catalogEnableFrontendEditing || empty( $this->catalogItemOperations ) ) { + if (!$this->catalogEnableFrontendEditing || empty($this->catalogItemOperations)) { $this->blnHasOperations = false; return null; } - if ( isset( $this->catalogItemOperations[0] ) && !Toolkit::isEmpty( $this->catalogItemOperations[0] ) ) { + if (isset($this->catalogItemOperations[0]) && !Toolkit::isEmpty($this->catalogItemOperations[0])) { $this->blnHasOperations = true; } - if ( count( $this->catalogItemOperations ) === 1 && in_array( 'create', $this->catalogItemOperations ) ) { + if (count($this->catalogItemOperations) === 1 && in_array('create', $this->catalogItemOperations)) { $this->blnHasOperations = false; } } - protected function getJoinedEntities( $strValue, $strFieldname ) { + protected function getJoinedEntities($strValue, $strFieldname) + { $arrReturn = []; - $strTable = $this->arrParseAsArray[ $strFieldname ]['onTable']; - $strField = $this->arrParseAsArray[ $strFieldname ]['onField']; - $arrOrderBy= Toolkit::parseStringToArray( $this->arrCatalogFields[ $strFieldname ]['dbOrderBy'] ); + $strTable = $this->arrParseAsArray[$strFieldname]['onTable']; + $strField = $this->arrParseAsArray[$strFieldname]['onField']; + $arrOrderBy = Toolkit::parseStringToArray($this->arrCatalogFields[$strFieldname]['dbOrderBy']); $arrQuery = [ @@ -824,15 +825,15 @@ protected function getJoinedEntities( $strValue, $strFieldname ) { [ 'field' => $strField, 'operator' => 'findInSet', - 'value' => explode( ',', $strValue ) + 'value' => explode(',', $strValue) ] ], 'orderBy' => [] ]; - if ( is_array( $arrOrderBy ) && !empty( $arrOrderBy ) ) { + if (is_array($arrOrderBy) && !empty($arrOrderBy)) { - foreach ( $arrOrderBy as $arrOrder ) { + foreach ($arrOrderBy as $arrOrder) { $arrQuery['orderBy'][] = [ @@ -842,7 +843,7 @@ protected function getJoinedEntities( $strValue, $strFieldname ) { } } - if ( $this->arrParseAsArray[ $strFieldname ]['hasVisibility'] ) { + if ($this->arrParseAsArray[$strFieldname]['hasVisibility']) { $dteTime = \Date::floorToMinute(); @@ -891,20 +892,21 @@ protected function getJoinedEntities( $strValue, $strFieldname ) { ]; } - $objEntities = $this->SQLQueryBuilder->execute( $arrQuery ); + $objEntities = $this->SQLQueryBuilder->execute($arrQuery); - if ( !$objEntities->numRows ) return $arrReturn; + if (!$objEntities->numRows) return $arrReturn; - while ( $objEntities->next() ) { + while ($objEntities->next()) { - $arrReturn[] = Toolkit::parseCatalogValues( $objEntities->row(), $this->arrCatalogFields, false, $strTable ); + $arrReturn[] = Toolkit::parseCatalogValues($objEntities->row(), $this->arrCatalogFields, false, $strTable); } return $arrReturn; } - public function hasVisibility() { + public function hasVisibility() + { if (!$this->SQLQueryHelper->SQLQueryBuilder->Database->fieldExists('invisible', $this->catalogTablename)) { return false; @@ -930,88 +932,92 @@ public function hasVisibility() { } - protected function createGroups( $varGroupName ) { + protected function createGroups($varGroupName) + { - if ( is_array( $varGroupName ) ) { + if (is_array($varGroupName)) { - foreach ( $varGroupName as $strGroup ) { + foreach ($varGroupName as $strGroup) { - if ( is_array( $strGroup ) ) { + if (is_array($strGroup)) { - $strKeyname = $this->arrCatalogFields[ $this->catalogGroupBy ]['dbTableValue'] ?: 'title'; - $strGroup = $strGroup[ $strKeyname ]; + $strKeyname = $this->arrCatalogFields[$this->catalogGroupBy]['dbTableValue'] ?: 'title'; + $strGroup = $strGroup[$strKeyname]; } - $this->createGroups( $strGroup ); + $this->createGroups($strGroup); } } - if ( $varGroupName && is_string( $varGroupName ) && !isset( $this->arrGroups[ $varGroupName ] ) ) { + if ($varGroupName && is_string($varGroupName) && !isset($this->arrGroups[$varGroupName])) { - $this->arrGroups[ $varGroupName ] = []; + $this->arrGroups[$varGroupName] = []; } } - protected function getGroupedValue( $arrCatalogs ) { + protected function getGroupedValue($arrCatalogs) + { $arrIndexes = []; - foreach ( $arrCatalogs as $arrCatalog ) { + foreach ($arrCatalogs as $arrCatalog) { - $varGroupName = $arrCatalog[ $this->catalogGroupBy ]; - $this->groupByValue( $varGroupName, $arrCatalog, $arrIndexes ); + $varGroupName = $arrCatalog[$this->catalogGroupBy]; + $this->groupByValue($varGroupName, $arrCatalog, $arrIndexes); } return $this->arrGroups; } - protected function groupByValue( $varGroupName, $arrCatalog, &$arrIndexes ) { + protected function groupByValue($varGroupName, $arrCatalog, &$arrIndexes) + { - if ( is_array( $varGroupName ) ) { + if (is_array($varGroupName)) { - foreach ( $varGroupName as $strGroupName ) { + foreach ($varGroupName as $strGroupName) { - if ( is_array( $strGroupName ) ) { + if (is_array($strGroupName)) { - $strKeyname = $this->arrCatalogFields[ $this->catalogGroupBy ]['dbTableValue'] ?: 'title'; - $strGroupName = $strGroupName[ $strKeyname ]; + $strKeyname = $this->arrCatalogFields[$this->catalogGroupBy]['dbTableValue'] ?: 'title'; + $strGroupName = $strGroupName[$strKeyname]; } - $this->groupByValue( $strGroupName, $arrCatalog, $arrIndexes ); + $this->groupByValue($strGroupName, $arrCatalog, $arrIndexes); } } - if ( $varGroupName && is_string( $varGroupName ) ) { + if ($varGroupName && is_string($varGroupName)) { - $objTemplate = new \FrontendTemplate( $this->strTemplate ); + $objTemplate = new \FrontendTemplate($this->strTemplate); - if ( !$this->arrGroups[ $varGroupName ] ) $arrIndexes[ $varGroupName ] = 0; + if (!$this->arrGroups[$varGroupName]) $arrIndexes[$varGroupName] = 0; - $arrCatalog['cssClass'] = $arrIndexes[ $varGroupName ] % 2 ? ' even' : ' odd'; + $arrCatalog['cssClass'] = $arrIndexes[$varGroupName] % 2 ? ' even' : ' odd'; $arrCatalog['_mainGroup'] = $varGroupName; $objTemplate->setData($arrCatalog); - $this->arrGroups[ $varGroupName ][] = $objTemplate->parse(); - $arrIndexes[ $varGroupName ]++; + $this->arrGroups[$varGroupName][] = $objTemplate->parse(); + $arrIndexes[$varGroupName]++; } } - protected function getTemplateValue( $arrCatalogs, $intNumRows ) { + protected function getTemplateValue($arrCatalogs, $intNumRows) + { $strContent = ''; - $objTemplate = new \FrontendTemplate( $this->strTemplate ); + $objTemplate = new \FrontendTemplate($this->strTemplate); - foreach ( $arrCatalogs as $intIndex => $arrCatalog ) { + foreach ($arrCatalogs as $intIndex => $arrCatalog) { $arrCatalog['cssClass'] = $intIndex % 2 ? ' even' : ' odd'; - if ( !$intIndex ) $arrCatalog['cssClass'] .= ' first'; - if ( $intIndex == ( $intNumRows - 1 ) ) $arrCatalog['cssClass'] .= ' last'; + if (!$intIndex) $arrCatalog['cssClass'] .= ' first'; + if ($intIndex == ($intNumRows - 1)) $arrCatalog['cssClass'] .= ' last'; - $objTemplate->setData( $arrCatalog ); + $objTemplate->setData($arrCatalog); $strContent .= $objTemplate->parse(); } @@ -1020,60 +1026,54 @@ protected function getTemplateValue( $arrCatalogs, $intNumRows ) { } - protected function getArrayValue( $arrCatalogs, $intNumRows ) { + protected function getArrayValue($arrCatalogs, $intNumRows) + { - for ( $intIndex = 0; $intIndex < count( $arrCatalogs ); $intIndex++ ) { + for ($intIndex = 0; $intIndex < count($arrCatalogs); $intIndex++) { - $arrCatalogs[ $intIndex ]['cssClass'] = $intIndex % 2 ? ' even' : ' odd'; + $arrCatalogs[$intIndex]['cssClass'] = $intIndex % 2 ? ' even' : ' odd'; - if ( !$intIndex ) $arrCatalogs[ $intIndex ]['cssClass'] .= ' first'; - if ( $intIndex == ( $intNumRows - 1 ) ) $arrCatalogs[ $intIndex ]['cssClass'] .= ' last'; + if (!$intIndex) $arrCatalogs[$intIndex]['cssClass'] .= ' first'; + if ($intIndex == ($intNumRows - 1)) $arrCatalogs[$intIndex]['cssClass'] .= ' last'; } return $arrCatalogs; } - protected function getActiveFieldsHeadline( $strTemplate ) { + protected function getActiveFieldsHeadline($strTemplate) + { - return sprintf( $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['activeFieldsHeadline'], $strTemplate ); + return sprintf($GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['activeFieldsHeadline'], $strTemplate); } - protected function setOrderByParameters() { - - $strSort = $this->CatalogInput->getActiveValue( 'sortID' . $this->id ); - $strOrder = $this->CatalogInput->getActiveValue( 'orderID' . $this->id ); + protected function setOrderByParameters() + { - if ( Toolkit::isEmpty( $strSort ) || is_array( $strSort ) ) { + $strSort = $this->CatalogInput->getActiveValue('sortID' . $this->id); + $strOrder = $this->CatalogInput->getActiveValue('orderID' . $this->id); + if (Toolkit::isEmpty($strSort) || is_array($strSort)) { $strSort = ''; } - if ( Toolkit::isEmpty( $strOrder ) || is_array( $strOrder ) ) { - + if (Toolkit::isEmpty($strOrder) || is_array($strOrder)) { $strOrder = 'DESC'; } else { - - mb_strtoupper( $strOrder, 'UTF-8' ); + mb_strtoupper($strOrder, 'UTF-8'); } - if ( !in_array( $strOrder, [ 'ASC','DESC' ] ) ) { - - if ( $strOrder == 'RAND' ) { - + if (!in_array($strOrder, ['ASC', 'DESC'])) { + if ($strOrder == 'RAND') { $this->catalogRandomSorting = '1'; - } - - else { - + } else { $strOrder = 'DESC'; } }; - if ( $strSort && $this->SQLQueryHelper->SQLQueryBuilder->Database->fieldExists( $strSort, $this->catalogTablename ) ) { - + if ($strSort && $this->SQLQueryHelper->SQLQueryBuilder->Database->fieldExists($strSort, $this->catalogTablename)) { $this->catalogOrderBy = [[ 'key' => $strSort, @@ -1083,48 +1083,46 @@ protected function setOrderByParameters() { } - protected function getMasterRedirect( $arrCatalog = [], $strAlias = '' ) { - - if ( $this->catalogDisableMasterLink ) return ''; - - if ( $this->arrCatalog['useRedirect'] && $this->arrCatalog['internalUrlColumn'] ) { + protected function getMasterRedirect($arrCatalog = [], $strAlias = '') + { - if ( $arrCatalog[ $this->arrCatalog['internalUrlColumn'] ] ) { + if ($this->catalogDisableMasterLink) return ''; - return \Controller::replaceInsertTags( $arrCatalog[ $this->arrCatalog['internalUrlColumn'] ] ); + if ($this->arrCatalog['useRedirect'] && $this->arrCatalog['internalUrlColumn']) { + if ($arrCatalog[$this->arrCatalog['internalUrlColumn']]) { + return \Controller::replaceInsertTags($arrCatalog[$this->arrCatalog['internalUrlColumn']]); } } - if ( $this->arrCatalog['useRedirect'] && $this->arrCatalog['externalUrlColumn'] ) { - - if ( $arrCatalog[ $this->arrCatalog['externalUrlColumn'] ] ) { - - return $arrCatalog[ $this->arrCatalog['externalUrlColumn'] ]; + if ($this->arrCatalog['useRedirect'] && $this->arrCatalog['externalUrlColumn']) { + if ($arrCatalog[$this->arrCatalog['externalUrlColumn']]) { + return $arrCatalog[$this->arrCatalog['externalUrlColumn']]; } } - $strAlias = $this->getAliasWithParameters( $strAlias, $arrCatalog ); + $strAlias = $this->getAliasWithParameters($strAlias, $arrCatalog); - return $this->generateUrl( $this->arrMasterPage, $strAlias ); + return $this->generateUrl($this->arrMasterPage, $strAlias); } - protected function getAliasWithParameters( $strAlias, $arrCatalog = [] ) { + protected function getAliasWithParameters($strAlias, $arrCatalog = []) + { - if ( !empty( $this->arrRoutingParameter ) && is_array( $this->arrRoutingParameter ) ) { - - return Toolkit::generateAliasWithRouting( $strAlias, $this->arrRoutingParameter, $arrCatalog ); + if (!empty($this->arrRoutingParameter) && is_array($this->arrRoutingParameter)) { + return Toolkit::generateAliasWithRouting($strAlias, $this->arrRoutingParameter, $arrCatalog); } return $strAlias; } - protected function isFastMode( $strType = '', $strFieldname = '' ) { + protected function isFastMode($strType = '', $strFieldname = '') + { - if ( $this->catalogFastMode && $this->strMode == 'view' && in_array( $strType, Toolkit::$arrDoNotRenderInFastMode ) ) { + if ($this->catalogFastMode && $this->strMode == 'view' && in_array($strType, Toolkit::$arrDoNotRenderInFastMode)) { - if ( $strFieldname && is_array( $this->catalogPreventFieldFromFastMode ) && in_array( $strFieldname, $this->catalogPreventFieldFromFastMode ) ) return false; + if ($strFieldname && is_array($this->catalogPreventFieldFromFastMode) && in_array($strFieldname, $this->catalogPreventFieldFromFastMode)) return false; return true; } @@ -1133,7 +1131,8 @@ protected function isFastMode( $strType = '', $strFieldname = '' ) { } - protected function parseCatalogValues($varValue, $strFieldname, &$arrCatalog) { + protected function parseCatalogValues($varValue, $strFieldname, &$arrCatalog) + { $arrField = $this->arrCatalogFields[$strFieldname] ?? []; if (empty($arrField)) { @@ -1183,14 +1182,15 @@ protected function parseCatalogValues($varValue, $strFieldname, &$arrCatalog) { } - public function getCommentForm( $strMasterID ) { + public function getCommentForm($strMasterID) + { - if ( !in_array( 'comments', \ModuleLoader::getActive() ) ) { + if (!in_array('comments', \ModuleLoader::getActive())) { return null; } - if ( !$this->catalogAllowComments ) { + if (!$this->catalogAllowComments) { return null; } @@ -1198,7 +1198,7 @@ public function getCommentForm( $strMasterID ) { $this->TemplateHelper->addComments( $this->objMainTemplate, - + [ 'template' => $this->com_template, 'bbcode' => $this->catalogCommentBBCode, @@ -1211,18 +1211,19 @@ public function getCommentForm( $strMasterID ) { $this->catalogTablename, - ( $strMasterID ? $strMasterID : '0' ), + ($strMasterID ? $strMasterID : '0'), [] ); } - protected function setOptions() { + protected function setOptions() + { - if ( !empty( $this->arrOptions ) && is_array( $this->arrOptions ) ) { + if (!empty($this->arrOptions) && is_array($this->arrOptions)) { - foreach ( $this->arrOptions as $strKey => $varValue ) { + foreach ($this->arrOptions as $strKey => $varValue) { $this->{$strKey} = $varValue; } @@ -1230,7 +1231,8 @@ protected function setOptions() { } - protected function getPageModel( $strID ) { + protected function getPageModel($strID) + { return $this->SQLQueryHelper->SQLQueryBuilder->execute([ @@ -1255,7 +1257,8 @@ protected function getPageModel( $strID ) { } - protected function prepareJoinData(&$arrReturn) { + protected function prepareJoinData(&$arrReturn) + { foreach ($this->catalogJoinFields as $strFieldJoinID) { @@ -1267,15 +1270,15 @@ protected function prepareJoinData(&$arrReturn) { $arrRelatedJoinData['multiple'] = false; $arrRelatedJoinData['table'] = $this->catalogTablename; - $arrRelatedJoinData['field'] = $this->arrCatalogFields[ $strFieldJoinID ]['fieldname']; - $arrRelatedJoinData['onTable'] = $this->arrCatalogFields[ $strFieldJoinID ]['dbTable']; - $arrRelatedJoinData['onField'] = $this->arrCatalogFields[ $strFieldJoinID ]['dbTableKey']; + $arrRelatedJoinData['field'] = $this->arrCatalogFields[$strFieldJoinID]['fieldname']; + $arrRelatedJoinData['onTable'] = $this->arrCatalogFields[$strFieldJoinID]['dbTable']; + $arrRelatedJoinData['onField'] = $this->arrCatalogFields[$strFieldJoinID]['dbTableKey']; - if ($this->arrCatalogFields[ $strFieldJoinID ]['multiple'] || $this->arrCatalogFields[ $strFieldJoinID ]['type'] == 'checkbox') { + if ($this->arrCatalogFields[$strFieldJoinID]['multiple'] || $this->arrCatalogFields[$strFieldJoinID]['type'] == 'checkbox') { $arrRelatedJoinData['multiple'] = true; } - $this->arrCatalogFields = $this->SQLQueryHelper->getCatalogFieldsByCatalogTablename( $arrRelatedJoinData['onTable'], $this->arrCatalogFields, true, $this->arrCatalogStaticFields ); + $this->arrCatalogFields = $this->SQLQueryHelper->getCatalogFieldsByCatalogTablename($arrRelatedJoinData['onTable'], $this->arrCatalogFields, true, $this->arrCatalogStaticFields); if ($arrRelatedJoinData['multiple'] && $this->catalogJoinAsArray) { @@ -1295,14 +1298,15 @@ protected function prepareJoinData(&$arrReturn) { } - protected function getChildrenByIdAndTable( $strId, $strTable ) { + protected function getChildrenByIdAndTable($strId, $strTable) + { $objFieldBuilder = new CatalogFieldBuilder(); - $objFieldBuilder->initialize( $strTable ); + $objFieldBuilder->initialize($strTable); $arrReturn = []; $arrCatalog = $objFieldBuilder->getCatalog(); - $arrFields = $objFieldBuilder->getCatalogFields( true, null ); + $arrFields = $objFieldBuilder->getCatalogFields(true, null); $arrQuery = [ @@ -1316,7 +1320,7 @@ protected function getChildrenByIdAndTable( $strId, $strTable ) { ] ]; - if ( in_array( 'invisible', $arrCatalog['operations'] ) ) { + if (in_array('invisible', $arrCatalog['operations'])) { $dteTime = \Date::floorToMinute(); @@ -1365,64 +1369,66 @@ protected function getChildrenByIdAndTable( $strId, $strTable ) { ]; } - if ( !empty( $arrCatalog['sortingFields'] ) ) { + if (!empty($arrCatalog['sortingFields'])) { - $numFlag = (int) $arrCatalog['flag'] ?: 1; + $numFlag = (int)$arrCatalog['flag'] ?: 1; - foreach ( $arrCatalog['sortingFields'] as $strSortingField ) { + foreach ($arrCatalog['sortingFields'] as $strSortingField) { $arrQuery['orderBy'][] = [ 'field' => $strSortingField, - 'order' => ( $numFlag % 2 == 0 ) ? 'DESC' : 'ASC' + 'order' => ($numFlag % 2 == 0) ? 'DESC' : 'ASC' ]; } } - $objEntities = $this->SQLQueryBuilder->execute( $arrQuery ); + $objEntities = $this->SQLQueryBuilder->execute($arrQuery); - if ( !$objEntities->numRows ) { + if (!$objEntities->numRows) { return $arrReturn; } - while ( $objEntities->next() ) { + while ($objEntities->next()) { - $arrReturn[] = Toolkit::parseCatalogValues( $objEntities->row(), $arrFields ); + $arrReturn[] = Toolkit::parseCatalogValues($objEntities->row(), $arrFields); } return $arrReturn; } - protected function generateUrl( $objPage, $strAlias ) { + protected function generateUrl($objPage, $strAlias) + { - if ( $objPage == null ) return ''; + if ($objPage == null) return ''; - return $this->generateFrontendUrl( $objPage, ( $strAlias ? '/' . $strAlias : '' ) ); + return $this->generateFrontendUrl($objPage, ($strAlias ? '/' . $strAlias : '')); } - protected function generateDownloads( $strID, $strAlias = '' ) { + protected function generateDownloads($strID, $strAlias = '') + { $arrReturn = []; $strConnector = '?'; - $strUrl = ampersand( \Environment::get('indexFreeRequest') ); + $strUrl = ampersand(\Environment::get('indexFreeRequest')); - if ( strpos( $strUrl, $strConnector ) !== false ) { + if (strpos($strUrl, $strConnector) !== false) { $strConnector = '&'; } - if ( !empty( $this->catalogDownloads ) && is_array( $this->catalogDownloads ) ) { + if (!empty($this->catalogDownloads) && is_array($this->catalogDownloads)) { - foreach ( $this->catalogDownloads as $strDownload ) { + foreach ($this->catalogDownloads as $strDownload) { - $arrReturn[ $strDownload ] = [ + $arrReturn[$strDownload] = [ - 'href' => $strUrl . $strConnector . $strDownload . $this->id . '=' . $strID, - 'title' => $GLOBALS['TL_LANG']['tl_module']['reference']['catalogDownloadTitles'][ $strDownload ], - 'image' => \Image::getHtml( Toolkit::getIcon( $strDownload ), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogDownloadTitles'][ $strDownload ] ), + 'href' => $strUrl . $strConnector . $strDownload . $this->id . '=' . $strID, + 'title' => $GLOBALS['TL_LANG']['tl_module']['reference']['catalogDownloadTitles'][$strDownload], + 'image' => \Image::getHtml(Toolkit::getIcon($strDownload), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogDownloadTitles'][$strDownload]), 'attributes' => '', ]; } @@ -1432,91 +1438,93 @@ protected function generateDownloads( $strID, $strAlias = '' ) { } - protected function generateOperations( $strID, $strAlias = '', $arrCatalog = [] ) { + protected function generateOperations($strID, $strAlias = '', $arrCatalog = []) + { $arrReturn = []; - $this->loadLanguageFile( 'tl_module' ); + $this->loadLanguageFile('tl_module'); - if ( !empty( $this->catalogItemOperations ) && is_array( $this->catalogItemOperations ) ) { + if (!empty($this->catalogItemOperations) && is_array($this->catalogItemOperations)) { - $strAlias = $this->getAliasWithParameters( $strAlias, $arrCatalog ); + $strAlias = $this->getAliasWithParameters($strAlias, $arrCatalog); - foreach ( $this->catalogItemOperations as $strOperation ) { + foreach ($this->catalogItemOperations as $strOperation) { - if ( !$strOperation || $strOperation == 'create' ) continue; + if (!$strOperation || $strOperation == 'create') continue; - if ( !$this->FrontendEditingPermission->hasPermission( ( $strOperation === 'copy' ? 'create' : $strOperation ), $this->catalogTablename ) ) { + if (!$this->FrontendEditingPermission->hasPermission(($strOperation === 'copy' ? 'create' : $strOperation), $this->catalogTablename)) { continue; } - $strActFragment = sprintf( '?act%s=%s&id%s=%s', $this->id, $strOperation, $this->id, $strID ); + $strActFragment = sprintf('?act%s=%s&id%s=%s', $this->id, $strOperation, $this->id, $strID); - if ( $this->arrCatalog['pTable'] ) { + if ($this->arrCatalog['pTable']) { - $strActFragment .= sprintf( '&pid=%s', ( \Input::get('pid' ) ? \Input::get('pid' ) : $arrCatalog['pid'] ) ); + $strActFragment .= sprintf('&pid=%s', (\Input::get('pid') ? \Input::get('pid') : $arrCatalog['pid'])); } - $arrReturn[ $strOperation ] = [ + $arrReturn[$strOperation] = [ 'class' => 'act_' . $strOperation, - 'href' => $this->generateUrl( $this->arrFrontendEditingPage, $strAlias ) . $strActFragment, - 'title' => $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations'][ $strOperation ], - 'image' => \Image::getHtml( Toolkit::getIcon( $strOperation ), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations'][ $strOperation ] ), - 'attributes' => $strOperation === 'delete' ? 'onclick="if(!confirm(\'' . sprintf( $GLOBALS['TL_LANG']['MSC']['deleteConfirm'], $strID ) . '\'))return false;"' : '', + 'href' => $this->generateUrl($this->arrFrontendEditingPage, $strAlias) . $strActFragment, + 'title' => $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations'][$strOperation], + 'image' => \Image::getHtml(Toolkit::getIcon($strOperation), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations'][$strOperation]), + 'attributes' => $strOperation === 'delete' ? 'onclick="if(!confirm(\'' . sprintf($GLOBALS['TL_LANG']['MSC']['deleteConfirm'], $strID) . '\'))return false;"' : '', ]; } } - if ( empty( $arrReturn ) ) $this->blnHasOperations = false; + if (empty($arrReturn)) $this->blnHasOperations = false; return $arrReturn; } - public function getCreateOperation() { + public function getCreateOperation() + { $strPTableFragment = ''; - $this->loadLanguageFile( 'tl_module' ); + $this->loadLanguageFile('tl_module'); - if ( !$this->catalogEnableFrontendEditing ) return []; + if (!$this->catalogEnableFrontendEditing) return []; - if ( !$this->FrontendEditingPermission->hasPermission( 'create', $this->catalogTablename ) ) { + if (!$this->FrontendEditingPermission->hasPermission('create', $this->catalogTablename)) { return []; } - if ( empty( $this->catalogItemOperations ) || !in_array( 'create', $this->catalogItemOperations ) ) { + if (empty($this->catalogItemOperations) || !in_array('create', $this->catalogItemOperations)) { return []; } - if ( $this->arrCatalog['pTable'] && !\Input::get('pid' ) ) { + if ($this->arrCatalog['pTable'] && !\Input::get('pid')) { return []; } - if ( $this->arrCatalog['pTable'] ) { + if ($this->arrCatalog['pTable']) { - $strPTableFragment = sprintf( '&pid=%s', \Input::get('pid' ) ); + $strPTableFragment = sprintf('&pid=%s', \Input::get('pid')); } return [ 'attributes' => '', 'title' => $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations']['create'], - 'href' => $this->generateUrl( $this->arrFrontendEditingPage, '' ) . sprintf( '?act%s=create%s', $this->id, $strPTableFragment ), - 'image' => \Image::getHtml( Toolkit::getIcon( 'new' ), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations']['create'] ) + 'href' => $this->generateUrl($this->arrFrontendEditingPage, '') . sprintf('?act%s=create%s', $this->id, $strPTableFragment), + 'image' => \Image::getHtml(Toolkit::getIcon('new'), $GLOBALS['TL_LANG']['tl_module']['reference']['catalogItemOperations']['create']) ]; } - protected function preparePTableJoinData ( &$arrReturn ) { + protected function preparePTableJoinData(&$arrReturn) + { - $this->arrCatalogFields = $this->SQLQueryHelper->getCatalogFieldsByCatalogTablename( $this->arrCatalog['pTable'], $this->arrCatalogFields, true, $this->arrCatalogStaticFields ); + $this->arrCatalogFields = $this->SQLQueryHelper->getCatalogFieldsByCatalogTablename($this->arrCatalog['pTable'], $this->arrCatalogFields, true, $this->arrCatalogStaticFields); $arrReturn[] = [ - 'field' => 'pid', 'onField' => 'id', 'multiple' => false, @@ -1526,68 +1534,74 @@ protected function preparePTableJoinData ( &$arrReturn ) { } - protected function setRelatedTableLinks( $strID ) { + protected function setRelatedTableLinks($strID) + { - foreach ( $this->arrRelatedTables as $strTablename => $arrRelatedTable ) { + foreach ($this->arrRelatedTables as $strTablename => $arrRelatedTable) { - $strUrl = $this->arrRelatedTables[ $strTablename ]['url']; - $strSuffix = sprintf( '?pid=%s', $strID ); + $strUrl = $this->arrRelatedTables[$strTablename]['url']; + $strSuffix = sprintf('?pid=%s', $strID); - $this->arrRelatedTables[ $strTablename ]['href'] = $strUrl . $strSuffix; + $this->arrRelatedTables[$strTablename]['href'] = $strUrl . $strSuffix; } return $this->arrRelatedTables; } - protected function setRelatedTables() { + protected function setRelatedTables() + { - if ( !empty( $this->catalogRelatedChildTables ) && is_array( $this->catalogRelatedChildTables ) ) { + if (!empty($this->catalogRelatedChildTables) && is_array($this->catalogRelatedChildTables)) { - foreach ( $this->catalogRelatedChildTables as $arrRelatedTable ) { + foreach ($this->catalogRelatedChildTables as $arrRelatedTable) { - if ( !is_array( $arrRelatedTable ) ) continue; + if (!is_array($arrRelatedTable)) continue; - if ( Toolkit::isEmpty( $arrRelatedTable['active'] ) ) continue; + if (Toolkit::isEmpty($arrRelatedTable['active'])) continue; $arrTableData = []; - $objCatalog = $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare( 'SELECT * FROM tl_catalog WHERE tablename = ?' )->limit(1)->execute( $arrRelatedTable['table'] ); + $objCatalog = $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare('SELECT * FROM tl_catalog WHERE tablename = ?')->limit(1)->execute($arrRelatedTable['table']); - if ( !$objCatalog->numRows ) continue; + if (!$objCatalog->numRows) continue; $arrCatalog = $objCatalog->row(); - $strTitle = $this->I18nCatalogTranslator->get( 'module', $arrRelatedTable['table'], [ 'titleOnly' => true ] ); + $strTitle = $this->I18nCatalogTranslator->get('module', $arrRelatedTable['table'], ['titleOnly' => true]); $arrTableData['title'] = $strTitle; $arrTableData['info'] = $arrCatalog['info']; $arrTableData['description'] = $arrCatalog['description']; - $arrTableData['url'] = \Controller::replaceInsertTags( $arrRelatedTable['pageURL'] ); - $arrTableData['image'] = \Image::getHtml( $this->IconGetter->setCatalogIcon( $arrRelatedTable['table'] ), $strTitle ); + $arrTableData['url'] = \Controller::replaceInsertTags($arrRelatedTable['pageURL']); + $arrTableData['image'] = \Image::getHtml($this->IconGetter->setCatalogIcon($arrRelatedTable['table']), $strTitle); - $this->arrRelatedTables[ $arrRelatedTable['table'] ] = $arrTableData; + $this->arrRelatedTables[$arrRelatedTable['table']] = $arrTableData; } } } - public function getCatalog() { + public function getCatalog() + { - return is_array( $this->arrCatalog ) && !empty( $this->arrCatalog ) ? $this->arrCatalog : []; + return is_array($this->arrCatalog) && !empty($this->arrCatalog) ? $this->arrCatalog : []; } - public function changeItemOperations( $arrItemOperations ) { + public function changeItemOperations($arrItemOperations) + { $this->catalogItemOperations = $arrItemOperations; } - public function getItemOperations() { + public function getItemOperations() + { return $this->catalogItemOperations; } - public function getCatalogFields() { + public function getCatalogFields() + { return $this->arrCatalogFields; } diff --git a/library/alnv/Inserttags/ActiveInsertTag.php b/library/alnv/Inserttags/ActiveInsertTag.php index ff08f92f..13e74fcf 100644 --- a/library/alnv/Inserttags/ActiveInsertTag.php +++ b/library/alnv/Inserttags/ActiveInsertTag.php @@ -2,41 +2,44 @@ namespace CatalogManager; -class ActiveInsertTag extends \Frontend { +class ActiveInsertTag extends \Frontend +{ - public function __construct() { + public function __construct() + { $this->import('CatalogInput'); } - public function getInsertTagValue( $strTag ) { + public function getInsertTagValue($strTag) + { - $arrTags = explode( '::', $strTag ); + $arrTags = explode('::', $strTag); - if ( is_array( $arrTags ) && $arrTags[0] == 'CTLG_ACTIVE' && isset( $arrTags[1] ) ) { + if (is_array($arrTags) && $arrTags[0] == 'CTLG_ACTIVE' && isset($arrTags[1])) { global $objPage; - $varValue = $this->CatalogInput->getActiveValue( $arrTags[1] ); + $varValue = $this->CatalogInput->getActiveValue($arrTags[1]); - if ( isset( $arrTags[2] ) && strpos( $arrTags[2], '?' ) !== false ) { + if (isset($arrTags[2]) && strpos($arrTags[2], '?') !== false) { - $arrChunks = explode('?', urldecode( $arrTags[2] ), 2 ); - $strSource = \StringUtil::decodeEntities( $arrChunks[1] ); - $strSource = str_replace( '[&]', '&', $strSource ); - $arrParams = explode( '&', $strSource ); + $arrChunks = explode('?', urldecode($arrTags[2]), 2); + $strSource = \StringUtil::decodeEntities($arrChunks[1]); + $strSource = str_replace('[&]', '&', $strSource); + $arrParams = explode('&', $strSource); $blnIsDate = false; $strDateMethod = 'tstamp'; $strDateFormat = $objPage->dateFormat; - foreach ( $arrParams as $strParam ) { - list( $strKey, $strOption ) = explode( '=', $strParam ); + foreach ($arrParams as $strParam) { + list($strKey, $strOption) = explode('=', $strParam); switch ($strKey) { case 'default': - if ( Toolkit::isEmpty( $varValue ) ) $varValue = \Controller::replaceInsertTags($strOption); + if (Toolkit::isEmpty($varValue)) $varValue = \Controller::replaceInsertTags($strOption); break; case 'suffix': case 'prefix': @@ -66,61 +69,54 @@ public function getInsertTagValue( $strTag ) { } } - if ( $blnIsDate && is_array( $varValue ) ) { + if ($blnIsDate && is_array($varValue)) { - foreach ( $varValue as $strK => $strV ) { + foreach ($varValue as $strK => $strV) { - if ( !$strV ) { + if (!$strV) { - unset( $varValue[$strK] ); + unset($varValue[$strK]); continue; }; - if ( \Validator::isDate( $strV ) || \Validator::isDate( $strV ) || \Validator::isTime( $strV ) ) { + if (\Validator::isDate($strV) || \Validator::isDate($strV) || \Validator::isTime($strV)) { - $objDate = new \Date( $strV, $strDateFormat ); + $objDate = new \Date($strV, $strDateFormat); $intTimestamp = $objDate->{$strDateMethod}; - if ( $intTimestamp > 0 ) $varValue[ $strK ] = $objDate->{$strDateMethod}; - } - - else if ( is_numeric( $strV ) ) { + if ($intTimestamp > 0) $varValue[$strK] = $objDate->{$strDateMethod}; + } else if (is_numeric($strV)) { - $objDate = new \Date( $strV ); + $objDate = new \Date($strV); $intTimestamp = $objDate->{$strDateMethod}; - if ( $intTimestamp > 0 ) $varValue[ $strK ] = $objDate->{$strDateMethod}; + if ($intTimestamp > 0) $varValue[$strK] = $objDate->{$strDateMethod}; } } } - if ( $blnIsDate && is_string( $varValue ) && !Toolkit::isEmpty( $varValue ) ) { + if ($blnIsDate && is_string($varValue) && !Toolkit::isEmpty($varValue)) { - if ( \Validator::isDate( $varValue ) || \Validator::isDate( $varValue ) || \Validator::isTime( $varValue ) ) { + if (\Validator::isDate($varValue) || \Validator::isDate($varValue) || \Validator::isTime($varValue)) { - $objDate = new \Date( $varValue, $strDateFormat ); + $objDate = new \Date($varValue, $strDateFormat); $intTimestamp = $objDate->{$strDateMethod}; - if ( $intTimestamp > 0 ) $varValue = $objDate->{$strDateMethod}; - } - - else if ( is_numeric( $varValue ) ){ + if ($intTimestamp > 0) $varValue = $objDate->{$strDateMethod}; + } else if (is_numeric($varValue)) { - $objDate = new \Date( $varValue ); + $objDate = new \Date($varValue); $intTimestamp = $objDate->{$strDateMethod}; - if ( $intTimestamp > 0 ) $varValue = $objDate->{$strDateMethod}; + if ($intTimestamp > 0) $varValue = $objDate->{$strDateMethod}; } } - } - - elseif( Toolkit::isEmpty( $varValue ) ) { - + } elseif (Toolkit::isEmpty($varValue)) { $varValue = $arrTags[2] ?? ''; } - if ( is_array( $varValue ) ) $varValue = implode( ',', $varValue ); + if (is_array($varValue)) $varValue = implode(',', $varValue); return $varValue; } diff --git a/library/alnv/SQLQueryBuilder.php b/library/alnv/SQLQueryBuilder.php index 88ac32e7..c7a497b9 100644 --- a/library/alnv/SQLQueryBuilder.php +++ b/library/alnv/SQLQueryBuilder.php @@ -1 +1 @@ -strJoinType = Config::get('catalogJoinType'); } $this->import('Database'); } public function execute($arrQuery) { $this->getQuery($arrQuery); if (isset($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery'])) { foreach ($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery'] as $arrCallback) { if (is_array($arrCallback)) { $this->import($arrCallback[0]); $this->strQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}($arrQuery, $this->strQuery, $this->arrValues); } } } return $this->Database->prepare($this->strQuery)->execute($this->arrValues); } public function getQuery($arrQuery) { $this->arrValues = []; $this->arrQuery = $arrQuery; $this->strTable = $arrQuery['table']; $this->createSelectQuery(); return $this->strQuery; } protected function createSelectQuery() { $this->strQuery = sprintf('SELECT %s FROM %s%s%s%s%s%s', $this->createSelectionStatement(), $this->strTable, $this->createJoinStatement(), $this->createWhereStatement(), $this->createHavingDistanceStatement(), $this->createOrderByStatement(), $this->createPaginationStatement() ); } protected function createSelectionStatement() { $strSelectionStatement = '*'; if (!isset($this->arrQuery['joins']) || empty($this->arrQuery['joins']) || !is_array($this->arrQuery['joins'])) { return $strSelectionStatement . $this->getDistanceField(); } $arrCount = []; $strSelectionStatement = sprintf('%s.*', $this->strTable); foreach ($this->arrQuery['joins'] as $intIndex => $arrJoin) { if (empty($arrJoin)) continue; if (!$intIndex) $strSelectionStatement .= ','; if (!isset($arrCount[$arrJoin['onTable']])) { $arrCount[$arrJoin['onTable']] = 0; } $arrCount[$arrJoin['onTable']] += 1; $arrColumnAliases = []; $arrForeignColumns = $this->getForeignColumnsByTablename($arrJoin['onTable']); foreach ($arrForeignColumns as $strForeignColumn) { $arrColumnAliases[] = sprintf('%s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s` AS %s', $arrJoin['onTable'], $strForeignColumn, $arrJoin['onTable'] . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . (ucfirst($strForeignColumn))); } $strSelectionStatement .= ($intIndex ? ',' : '') . implode(',', $arrColumnAliases); } return $strSelectionStatement . $this->getDistanceField(); } private function getDistanceField() { if (!isset($this->arrQuery['distance']) || empty($this->arrQuery['distance']) || !is_array($this->arrQuery['distance'])) { return ''; } $this->blnDistance = true; return sprintf( ",3956 * 1.6 * 2 * ASIN(SQRT(POWER(SIN((%s-abs(%s.`%s`)) * pi()/180 / 2),2) + COS(%s * pi()/180) * COS(abs(%s.`%s`) * pi()/180) * POWER( SIN( (%s-%s.`%s`) * pi()/180 / 2 ), 2 ))) AS _distance", $this->arrQuery['distance']['latCord'], $this->strTable, $this->arrQuery['distance']['latField'], $this->arrQuery['distance']['latCord'], $this->strTable, $this->arrQuery['distance']['latField'], $this->arrQuery['distance']['lngCord'], $this->strTable, $this->arrQuery['distance']['lngField'] ); } private function getForeignColumnsByTablename($strTable) { if (!$strTable || !$this->Database->tableExists($strTable)) { return []; } return Toolkit::parseColumns($this->Database->listFields($strTable)); } protected function createJoinStatement() { $strJoinStatement = ''; if (!isset($this->arrQuery['joins']) || empty($this->arrQuery['joins']) || !is_array($this->arrQuery['joins'])) { return $strJoinStatement; } $arrCount = []; foreach ($this->arrQuery['joins'] as $intIndex => $arrJoin) { $strType = isset($arrJoin['type']) && $arrJoin['type'] ? $arrJoin['type'] : $this->strJoinType; if (!isset($arrCount[$arrJoin['onTable']])) { $arrCount[$arrJoin['onTable']] = 0; } $arrCount[$arrJoin['onTable']] += 1; if (!$arrJoin['table'] || !$arrJoin['field'] || !$arrJoin['onTable'] || !$arrJoin['onField']) { continue; } if ($arrJoin['multiple']) { $strJoinStatement .= sprintf(($intIndex ? ' ' : '') . ' %s %s' . ($arrCount[$arrJoin['onTable']] > 1 ? ' AS ' . $arrJoin['onTable'] . $arrCount[$arrJoin['onTable']] : '') . ' ON FIND_IN_SET(%s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s`,%s.`%s`)', $strType, $arrJoin['onTable'], $arrJoin['onTable'], $arrJoin['onField'], $arrJoin['table'], $arrJoin['field']); } else { $strJoinStatement .= sprintf(($intIndex ? ' ' : '') . ' %s %s' . ($arrCount[$arrJoin['onTable']] > 1 ? ' AS ' . $arrJoin['onTable'] . $arrCount[$arrJoin['onTable']] : '') . ' ON %s.`%s` = %s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s`', $strType, $arrJoin['onTable'], $arrJoin['table'], $arrJoin['field'], $arrJoin['onTable'], $arrJoin['onField']); } } return $strJoinStatement; } protected function createWhereStatement() { $strStatement = ''; if (!$this->arrQuery['where'] || empty($this->arrQuery['where']) || !is_array($this->arrQuery['where'])) { return $strStatement; } $strStatement .= ' WHERE'; foreach ($this->arrQuery['where'] as $intLevel1 => $arrQuery) { if (!Toolkit::isAssoc($arrQuery)) { $intLevel2 = 0; if ($intLevel1) $strStatement .= ' AND '; if (!$intLevel2 && count($arrQuery) > 1) $strStatement .= ' ( '; foreach ($arrQuery as $arrOrQuery) { if ($intLevel2) $strStatement .= strpos($arrOrQuery['operator'], 'Exact') !== false ? ' AND ' : ' OR '; $this->createMultipleValueQueries($strStatement, $arrOrQuery, $intLevel1); $intLevel2++; } if ($intLevel2 && $intLevel2 == count($arrQuery) && count($arrQuery) > 1) $strStatement .= ' ) '; } else { if ($intLevel1) $strStatement .= ' AND '; $this->createMultipleValueQueries($strStatement, $arrQuery, $intLevel1); } } return $strStatement; } protected function createMultipleValueQueries(&$strQuery, $arrQuery, $intLevel) { $this->setValue($arrQuery['value'], $arrQuery['field'], $intLevel, $arrQuery['operator']); if (is_array($arrQuery['value']) && !empty($arrQuery['value']) && !in_array($arrQuery['operator'], ['between', 'contain', 'notContain'])) { $strQuery .= ' ( '; foreach ($arrQuery['value'] as $intIndex => $strValue) { if ($intIndex) $strQuery .= strpos($arrQuery['operator'], 'Exact') !== false ? ' AND ' : ' OR '; $strQuery .= ' ' . call_user_func_array(['SQLQueryBuilder', $arrQuery['operator']], [$arrQuery['field'], $intLevel]); } $strQuery .= ' ) '; } else { $strQuery .= ' ' . call_user_func_array(['SQLQueryBuilder', $arrQuery['operator']], [$arrQuery['field'], $intLevel]); } } private function setValue($varValue, $strFieldname = '', $intLevel = 0, $strOperator = '') { if (is_array($varValue)) { foreach ($varValue as $strValue) { if (is_string($strValue) && $strValue != '') { $strValue = trim($strValue); } $this->arrValues[] = $this->replaceEvilChars($strValue, $strOperator); } $this->arrMultipleValues[$strFieldname . '::' . $intLevel] = count($varValue); } else { $this->arrValues[] = $this->replaceEvilChars($varValue, $strOperator); } } protected function replaceEvilChars($strValue, $strOperator = '') { if (!is_string($strValue) || empty($strValue)) { return $strValue; } if ((strpos($strValue, '(') !== false || strpos($strValue, ')') !== false) && $strOperator != 'equal') { $strValue = str_replace($strValue, '(', '\('); $strValue = str_replace($strValue, ')', '\)'); } return $strValue; } protected function createHavingDistanceStatement() { if (!isset($this->arrQuery['distance']) || empty($this->arrQuery['distance']) || !is_array($this->arrQuery['distance'])) return ''; return sprintf(' HAVING _distance < %s', $this->arrQuery['distance']['value']); } protected function createOrderByStatement() { $arrOrderByStatements = []; $arrAllowedModes = ['DESC', 'ASC']; if (!isset($this->arrQuery['orderBy']) || empty($this->arrQuery['orderBy']) || !is_array($this->arrQuery['orderBy'])) { return ''; } foreach ($this->arrQuery['orderBy'] as $intIndex => $arrOrderBy) { if (!$arrOrderBy['order']) $arrOrderBy['order'] = 'DESC'; if (!$arrOrderBy['field'] || !in_array($arrOrderBy['order'], $arrAllowedModes)) continue; if ($arrOrderBy['field'] == '_distance' && !$this->blnDistance) { continue; } $arrOrderByStatements[] = sprintf('%s`%s` %s', ($this->blnDistance ? '' : $this->strTable . '.'), $arrOrderBy['field'], $arrOrderBy['order']); } if (empty($arrOrderByStatements)) { return ''; } return ' ORDER BY ' . implode(',', $arrOrderByStatements); } protected function createPaginationStatement() { if (!isset($this->arrQuery['pagination']) || empty($this->arrQuery['pagination']) || !is_array($this->arrQuery['pagination'])) { return ''; } $strOffset = isset($this->arrQuery['pagination']['offset']) && $this->arrQuery['pagination']['offset'] ? intval($this->arrQuery['pagination']['offset']) : 0; $strLimit = isset($this->arrQuery['pagination']['limit']) && $this->arrQuery['pagination']['limit'] ? intval($this->arrQuery['pagination']['limit']) : 1000; return sprintf(' LIMIT %s, %s', $strOffset, $strLimit); } public function tableExist($strTable) { if (!$strTable || !$this->Database->tableExists($strTable)) { return false; } return true; } public function getWhereQuery($arrQuery) { $this->arrValues = []; $this->arrQuery = $arrQuery; $this->strTable = $arrQuery['table']; return $this->createWhereStatement(); } public function getValues() { return $this->arrValues; } protected function equal($strField, $intLevel = 0) { return sprintf('%s.`%s` = ?', $this->strTable, $strField); } protected function not($strField, $intLevel = 0) { return sprintf('%s.`%s` != ?', $this->strTable, $strField); } protected function multiSelectRegexp($strField, $intLevel = 0) { return $this->regexp($strField, $intLevel); } protected function regexp($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS CHAR)) REGEXP LOWER(?)', $this->strTable, $strField); } protected function regexpExact($strField, $intLevel = 0) { return $this->regexp($strField); } protected function regexpNoSpace($strField, $intLevel = 0) { return $this->regexp($strField); } protected function multiSelectFindInSet($strField, $intLevel = 0) { return $this->findInSet($strField, $intLevel); } protected function findInSet($strField, $intLevel = 0) { return sprintf('FIND_IN_SET(?,LOWER(CAST(%s.`%s` AS CHAR)))', $this->strTable, $strField); } protected function findInSetExact($strField, $intLevel = 0) { return $this->findInSet($strField, $intLevel); } protected function gt($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS SIGNED)) > ?', $this->strTable, $strField); } protected function gte($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS SIGNED)) >= ?', $this->strTable, $strField); } protected function lt($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS SIGNED)) < ?', $this->strTable, $strField); } protected function lte($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS SIGNED)) <= ?', $this->strTable, $strField); } protected function notContain($strField, $intLevel = 0) { $strPlaceholder = $this->arrMultipleValues[$strField . '::' . $intLevel] ? implode(',', array_fill(0, $this->arrMultipleValues[$strField . '::' . $intLevel], '?')) : '?'; return sprintf('LOWER(%s.`%s`) NOT IN (' . $strPlaceholder . ')', $this->strTable, $strField); } protected function containExact($strField, $intLevel = 0) { return $this->contain($strField, $intLevel); } protected function contain($strField, $intLevel = 0) { $strPlaceholder = $this->arrMultipleValues[$strField . '::' . $intLevel] ? implode(',', array_fill(0, $this->arrMultipleValues[$strField . '::' . $intLevel], '?')) : '?'; return sprintf('LOWER(%s.`%s`) IN (' . $strPlaceholder . ')', $this->strTable, $strField); } protected function between($strField, $intLevel = 0) { return sprintf('LOWER(%s.`%s`) BETWEEN ? AND ?', $this->strTable, $strField); } protected function isEmpty($strField, $intLevel = 0) { return sprintf("(%s.%s IS NULL OR %s.%s = ?)", $this->strTable, $strField, $this->strTable, $strField); } protected function isNotEmpty($strField, $intLevel = 0) { return sprintf("%s.%s != ?", $this->strTable, $strField); } } \ No newline at end of file +strJoinType = Config::get('catalogJoinType'); } $this->import('Database'); } public function execute($arrQuery) { $this->getQuery($arrQuery); if (isset($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery'])) { foreach ($GLOBALS['TL_HOOKS']['catalogManagerOverwriteQuery'] as $arrCallback) { if (is_array($arrCallback)) { $this->import($arrCallback[0]); $this->strQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}($arrQuery, $this->strQuery, $this->arrValues); } } } return $this->Database->prepare($this->strQuery)->execute($this->arrValues); } public function getQuery($arrQuery) { $this->arrValues = []; $this->arrQuery = $arrQuery; $this->strTable = $arrQuery['table']; $this->createSelectQuery(); return $this->strQuery; } protected function createSelectQuery() { $this->strQuery = sprintf('SELECT %s FROM %s%s%s%s%s%s', $this->createSelectionStatement(), $this->strTable, $this->createJoinStatement(), $this->createWhereStatement(), $this->createHavingDistanceStatement(), $this->createOrderByStatement(), $this->createPaginationStatement() ); } protected function createSelectionStatement() { $strSelectionStatement = '*'; if (!isset($this->arrQuery['joins']) || empty($this->arrQuery['joins']) || !is_array($this->arrQuery['joins'])) { return $strSelectionStatement . $this->getDistanceField(); } $arrCount = []; $strSelectionStatement = sprintf('%s.*', $this->strTable); foreach ($this->arrQuery['joins'] as $intIndex => $arrJoin) { if (empty($arrJoin)) continue; if (!$intIndex) $strSelectionStatement .= ','; if (!isset($arrCount[$arrJoin['onTable']])) { $arrCount[$arrJoin['onTable']] = 0; } $arrCount[$arrJoin['onTable']] += 1; $arrColumnAliases = []; $arrForeignColumns = $this->getForeignColumnsByTablename($arrJoin['onTable']); foreach ($arrForeignColumns as $strForeignColumn) { $arrColumnAliases[] = sprintf('%s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s` AS %s', $arrJoin['onTable'], $strForeignColumn, $arrJoin['onTable'] . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . (ucfirst($strForeignColumn))); } $strSelectionStatement .= ($intIndex ? ',' : '') . implode(',', $arrColumnAliases); } return $strSelectionStatement . $this->getDistanceField(); } private function getDistanceField() { if (!isset($this->arrQuery['distance']) || empty($this->arrQuery['distance']) || !is_array($this->arrQuery['distance'])) { return ''; } $this->blnDistance = true; return sprintf( ",3956 * 1.6 * 2 * ASIN(SQRT(POWER(SIN((%s-abs(%s.`%s`)) * pi()/180 / 2),2) + COS(%s * pi()/180) * COS(abs(%s.`%s`) * pi()/180) * POWER( SIN( (%s-%s.`%s`) * pi()/180 / 2 ), 2 ))) AS _distance", $this->arrQuery['distance']['latCord'], $this->strTable, $this->arrQuery['distance']['latField'], $this->arrQuery['distance']['latCord'], $this->strTable, $this->arrQuery['distance']['latField'], $this->arrQuery['distance']['lngCord'], $this->strTable, $this->arrQuery['distance']['lngField'] ); } private function getForeignColumnsByTablename($strTable) { if (!$strTable || !$this->Database->tableExists($strTable)) { return []; } return Toolkit::parseColumns($this->Database->listFields($strTable)); } protected function createJoinStatement() { $strJoinStatement = ''; if (!isset($this->arrQuery['joins']) || empty($this->arrQuery['joins']) || !is_array($this->arrQuery['joins'])) { return $strJoinStatement; } $arrCount = []; foreach ($this->arrQuery['joins'] as $intIndex => $arrJoin) { $strType = isset($arrJoin['type']) && $arrJoin['type'] ? $arrJoin['type'] : $this->strJoinType; if (!isset($arrCount[$arrJoin['onTable']])) { $arrCount[$arrJoin['onTable']] = 0; } $arrCount[$arrJoin['onTable']] += 1; if (!$arrJoin['table'] || !$arrJoin['field'] || !$arrJoin['onTable'] || !$arrJoin['onField']) { continue; } if ($arrJoin['multiple']) { $strJoinStatement .= sprintf(($intIndex ? ' ' : '') . ' %s %s' . ($arrCount[$arrJoin['onTable']] > 1 ? ' AS ' . $arrJoin['onTable'] . $arrCount[$arrJoin['onTable']] : '') . ' ON FIND_IN_SET(%s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s`,%s.`%s`)', $strType, $arrJoin['onTable'], $arrJoin['onTable'], $arrJoin['onField'], $arrJoin['table'], $arrJoin['field']); } else { $strJoinStatement .= sprintf(($intIndex ? ' ' : '') . ' %s %s' . ($arrCount[$arrJoin['onTable']] > 1 ? ' AS ' . $arrJoin['onTable'] . $arrCount[$arrJoin['onTable']] : '') . ' ON %s.`%s` = %s' . ($arrCount[$arrJoin['onTable']] > 1 ? $arrCount[$arrJoin['onTable']] : '') . '.`%s`', $strType, $arrJoin['onTable'], $arrJoin['table'], $arrJoin['field'], $arrJoin['onTable'], $arrJoin['onField']); } } return $strJoinStatement; } protected function createWhereStatement() { $strStatement = ''; if (!$this->arrQuery['where'] || empty($this->arrQuery['where']) || !is_array($this->arrQuery['where'])) { return $strStatement; } $strStatement .= ' WHERE'; foreach ($this->arrQuery['where'] as $intLevel1 => $arrQuery) { if (!Toolkit::isAssoc($arrQuery)) { $intLevel2 = 0; if ($intLevel1) $strStatement .= ' AND '; if (!$intLevel2 && count($arrQuery) > 1) $strStatement .= ' ( '; foreach ($arrQuery as $arrOrQuery) { if ($intLevel2) $strStatement .= strpos($arrOrQuery['operator'], 'Exact') !== false ? ' AND ' : ' OR '; $this->createMultipleValueQueries($strStatement, $arrOrQuery, $intLevel1); $intLevel2++; } if ($intLevel2 && $intLevel2 == count($arrQuery) && count($arrQuery) > 1) $strStatement .= ' ) '; } else { if ($intLevel1) $strStatement .= ' AND '; $this->createMultipleValueQueries($strStatement, $arrQuery, $intLevel1); } } return $strStatement; } protected function createMultipleValueQueries(&$strQuery, $arrQuery, $intLevel) { $this->setValue($arrQuery['value'], $arrQuery['field'], $intLevel, $arrQuery['operator']); if (is_array($arrQuery['value']) && !empty($arrQuery['value']) && !in_array($arrQuery['operator'], ['between', 'contain', 'notContain'])) { $strQuery .= ' ( '; foreach ($arrQuery['value'] as $intIndex => $strValue) { if ($intIndex) $strQuery .= strpos($arrQuery['operator'], 'Exact') !== false ? ' AND ' : ' OR '; $strQuery .= ' ' . call_user_func_array(['SQLQueryBuilder', $arrQuery['operator']], [$arrQuery['field'], $intLevel]); } $strQuery .= ' ) '; } else { $strQuery .= ' ' . call_user_func_array(['SQLQueryBuilder', $arrQuery['operator']], [$arrQuery['field'], $intLevel]); } } private function setValue($varValue, $strFieldname = '', $intLevel = 0, $strOperator = '') { if (is_array($varValue)) { foreach ($varValue as $strValue) { if (is_string($strValue) && $strValue != '') { $strValue = trim($strValue); } $this->arrValues[] = $this->replaceEvilChars($strValue, $strOperator); } $this->arrMultipleValues[$strFieldname . '::' . $intLevel] = count($varValue); } else { $this->arrValues[] = $this->replaceEvilChars($varValue, $strOperator); } } protected function replaceEvilChars($strValue, $strOperator = '') { if (!is_string($strValue) || empty($strValue)) { return $strValue; } if ((strpos($strValue, '(') !== false || strpos($strValue, ')') !== false) && $strOperator != 'equal') { $strValue = str_replace($strValue, '(', '\('); $strValue = str_replace($strValue, ')', '\)'); } return $strValue; } protected function createHavingDistanceStatement() { if (!isset($this->arrQuery['distance']) || empty($this->arrQuery['distance']) || !is_array($this->arrQuery['distance'])) return ''; return sprintf(' HAVING _distance < %s', $this->arrQuery['distance']['value']); } protected function createOrderByStatement() { $arrOrderByStatements = []; $arrAllowedModes = ['DESC', 'ASC']; if (!isset($this->arrQuery['orderBy']) || empty($this->arrQuery['orderBy']) || !is_array($this->arrQuery['orderBy'])) { return ''; } foreach ($this->arrQuery['orderBy'] as $intIndex => $arrOrderBy) { if (!$arrOrderBy['order']) $arrOrderBy['order'] = 'DESC'; if (!$arrOrderBy['field'] || !in_array($arrOrderBy['order'], $arrAllowedModes)) continue; if ($arrOrderBy['field'] == '_distance' && !$this->blnDistance) { continue; } $arrOrderByStatements[] = sprintf('%s`%s` %s', ($this->blnDistance ? '' : $this->strTable . '.'), $arrOrderBy['field'], $arrOrderBy['order']); } if (empty($arrOrderByStatements)) { return ''; } return ' ORDER BY ' . implode(',', $arrOrderByStatements); } protected function createPaginationStatement() { if (!isset($this->arrQuery['pagination']) || empty($this->arrQuery['pagination']) || !is_array($this->arrQuery['pagination'])) { return ''; } $strOffset = isset($this->arrQuery['pagination']['offset']) && $this->arrQuery['pagination']['offset'] ? intval($this->arrQuery['pagination']['offset']) : 0; $strLimit = isset($this->arrQuery['pagination']['limit']) && $this->arrQuery['pagination']['limit'] ? intval($this->arrQuery['pagination']['limit']) : 1000; return sprintf(' LIMIT %s, %s', $strOffset, $strLimit); } public function tableExist($strTable) { if (!$strTable || !$this->Database->tableExists($strTable)) { return false; } return true; } public function getWhereQuery($arrQuery) { $this->arrValues = []; $this->arrQuery = $arrQuery; $this->strTable = $arrQuery['table']; return $this->createWhereStatement(); } public function getValues() { return $this->arrValues; } protected function equal($strField, $intLevel = 0) { return sprintf('%s.`%s` = ?', $this->strTable, $strField); } protected function not($strField, $intLevel = 0) { return sprintf('%s.`%s` != ?', $this->strTable, $strField); } protected function multiSelectRegexp($strField, $intLevel = 0) { return $this->regexp($strField, $intLevel); } protected function regexp($strField, $intLevel = 0) { return sprintf('LOWER(CAST(%s.`%s` AS CHAR)) REGEXP LOWER(?)', $this->strTable, $strField); } protected function regexpExact($strField, $intLevel = 0) { return $this->regexp($strField); } protected function regexpNoSpace($strField, $intLevel = 0) { return $this->regexp($strField); } protected function multiSelectFindInSet($strField, $intLevel = 0) { return $this->findInSet($strField, $intLevel); } protected function findInSet($strField, $intLevel = 0) { return sprintf('FIND_IN_SET(?,LOWER(CAST(%s.`%s` AS CHAR)))', $this->strTable, $strField); } protected function findInSetExact($strField, $intLevel = 0) { return $this->findInSet($strField, $intLevel); } protected function gt($strField, $intLevel = 0) { return sprintf('CAST(%s.`%s` AS SIGNED) > ?', $this->strTable, $strField); } protected function gte($strField, $intLevel = 0) { return sprintf('CAST(%s.`%s` AS SIGNED) >= ?', $this->strTable, $strField); } protected function lt($strField, $intLevel = 0) { return sprintf('CAST(%s.`%s` AS SIGNED) < ?', $this->strTable, $strField); } protected function lte($strField, $intLevel = 0) { return sprintf('CAST(%s.`%s` AS SIGNED) <= ?', $this->strTable, $strField); } protected function notContain($strField, $intLevel = 0) { $strPlaceholder = $this->arrMultipleValues[$strField . '::' . $intLevel] ? implode(',', array_fill(0, $this->arrMultipleValues[$strField . '::' . $intLevel], '?')) : '?'; return sprintf('LOWER(%s.`%s`) NOT IN (' . $strPlaceholder . ')', $this->strTable, $strField); } protected function containExact($strField, $intLevel = 0) { return $this->contain($strField, $intLevel); } protected function contain($strField, $intLevel = 0) { $strPlaceholder = $this->arrMultipleValues[$strField . '::' . $intLevel] ? implode(',', array_fill(0, $this->arrMultipleValues[$strField . '::' . $intLevel], '?')) : '?'; return sprintf('LOWER(%s.`%s`) IN (' . $strPlaceholder . ')', $this->strTable, $strField); } protected function between($strField, $intLevel = 0) { return sprintf('LOWER(%s.`%s`) BETWEEN ? AND ?', $this->strTable, $strField); } protected function isEmpty($strField, $intLevel = 0) { return sprintf("(%s.%s IS NULL OR %s.%s = ?)", $this->strTable, $strField, $this->strTable, $strField); } protected function isNotEmpty($strField, $intLevel = 0) { return sprintf("%s.%s != ?", $this->strTable, $strField); } } \ No newline at end of file diff --git a/library/alnv/Toolkit.php b/library/alnv/Toolkit.php index f8cedcd3..01fa0ce0 100644 --- a/library/alnv/Toolkit.php +++ b/library/alnv/Toolkit.php @@ -476,7 +476,6 @@ public static function parseQueries($arrQueries, $fnCallback = null) $arrSubQueries = self::parseQueries($arrQuery['subQueries']); array_insert($arrSubQueries, 0, [[ - 'field' => $arrQuery['field'], 'value' => $arrQuery['value'], 'operator' => $arrQuery['operator'], @@ -536,31 +535,31 @@ public static function parseQuery($arrQuery) } if (is_string($arrQuery['value']) && $arrQuery['operator'] == 'regexp') { - if (strpos($arrQuery['value'], ' ')) { - $arrQuery['value'] = explode(' ', $arrQuery['value']); } } } if (isset($arrQuery['value']) && is_array($arrQuery['value']) && !in_array($arrQuery['operator'], ['contain', 'notContain', 'between'])) { - $arrQuery['multiple'] = true; } if ((!isset($arrQuery['value']) || $arrQuery['value'] === '') && !$blnAllowEmptyValue) { - return null; } if ((is_array($arrQuery['value']) && empty($arrQuery['value'])) && !$blnAllowEmptyValue) { - return null; } + if (is_numeric($arrQuery['value']) && in_array($arrQuery['operator'], ['lte', 'lt', 'gt', 'gte'])) { - $arrQuery['value'] = floatval($arrQuery['value']); + if (strpos((string)$arrQuery['value'], '.') !== false) { + $arrQuery['value'] = floatval($arrQuery['value']); + } else { + $arrQuery['value'] = (int)$arrQuery['value']; + } } $arrQuery['value'] = self::prepareValueForQuery($arrQuery['value']);