7272 */
7373class Table implements Stringable
7474{
75- /**
76- * UI preferences properties
77- */
78- public const PROP_SORTED_COLUMN = 'sorted_col ' ;
79- public const PROP_COLUMN_ORDER = 'col_order ' ;
80- public const PROP_COLUMN_VISIB = 'col_visib ' ;
81-
8275 /** @var mixed[] UI preferences */
8376 public array $ uiprefs = [];
8477
@@ -1677,28 +1670,22 @@ protected function loadUiPrefs(): void
16771670 /**
16781671 * Get a property from UI preferences.
16791672 * Return false if the property is not found.
1680- * Available property:
1681- * - PROP_SORTED_COLUMN
1682- * - PROP_COLUMN_ORDER
1683- * - PROP_COLUMN_VISIB
1684- *
1685- * @param string $property property
16861673 */
1687- public function getUiProp (string $ property ): mixed
1674+ public function getUiProp (UiProperty $ property ): mixed
16881675 {
16891676 if ($ this ->uiprefs === []) {
16901677 $ this ->loadUiPrefs ();
16911678 }
16921679
16931680 // do checking based on property
1694- if ($ property === self :: PROP_SORTED_COLUMN ) {
1695- if (! isset ($ this ->uiprefs [$ property ])) {
1681+ if ($ property === UiProperty::SortedColumn ) {
1682+ if (! isset ($ this ->uiprefs [$ property-> value ])) {
16961683 return false ;
16971684 }
16981685
16991686 if (! isset ($ _POST ['discard_remembered_sort ' ])) {
17001687 // check if the column name exists in this table
1701- $ tmp = explode (' ' , $ this ->uiprefs [$ property ]);
1688+ $ tmp = explode (' ' , $ this ->uiprefs [$ property-> value ]);
17021689 $ colname = $ tmp [0 ];
17031690 //remove backquoting from colname
17041691 $ colname = str_replace ('` ' , '' , $ colname );
@@ -1708,7 +1695,7 @@ public function getUiProp(string $property): mixed
17081695 foreach ($ availColumns as $ eachCol ) {
17091696 // check if $each_col ends with $colname
17101697 if (substr_compare ($ eachCol , $ colname , mb_strlen ($ eachCol ) - mb_strlen ($ colname )) === 0 ) {
1711- return $ this ->uiprefs [$ property ];
1698+ return $ this ->uiprefs [$ property-> value ];
17121699 }
17131700 }
17141701 }
@@ -1719,47 +1706,43 @@ public function getUiProp(string $property): mixed
17191706 return false ;
17201707 }
17211708
1722- if ($ property === self ::PROP_COLUMN_ORDER || $ property === self ::PROP_COLUMN_VISIB ) {
1723- if ($ this ->isView () || ! isset ($ this ->uiprefs [$ property ])) {
1724- return false ;
1725- }
1726-
1727- // check if the table has not been modified
1728- if ($ this ->getStatusInfo ('Create_time ' ) == $ this ->uiprefs ['CREATE_TIME ' ]) {
1729- return array_map (intval (...), $ this ->uiprefs [$ property ]);
1730- }
1731-
1732- // remove the property, since the table has been modified
1733- $ this ->removeUiProp ($ property );
1734-
1709+ if ($ this ->isView () || ! isset ($ this ->uiprefs [$ property ->value ])) {
17351710 return false ;
17361711 }
17371712
1738- // default behaviour for other property:
1739- return $ this ->uiprefs [$ property ] ?? false ;
1713+ // check if the table has not been modified
1714+ if ($ this ->getStatusInfo ('Create_time ' ) == $ this ->uiprefs ['CREATE_TIME ' ]) {
1715+ return array_map (intval (...), $ this ->uiprefs [$ property ->value ]);
1716+ }
1717+
1718+ // remove the property, since the table has been modified
1719+ $ this ->removeUiProp ($ property );
1720+
1721+ return false ;
17401722 }
17411723
17421724 /**
17431725 * Set a property from UI preferences.
17441726 * If pmadb and table_uiprefs is set, it will save the UI preferences to
17451727 * phpMyAdmin database.
1746- * Available property:
1747- * - PROP_SORTED_COLUMN
1748- * - PROP_COLUMN_ORDER
1749- * - PROP_COLUMN_VISIB
1750- *
1751- * @param string $property Property
1752- * @param mixed $value Value for the property
1753- * @param string|null $tableCreateTime Needed for PROP_COLUMN_ORDER and PROP_COLUMN_VISIB
1728+ *
1729+ * @param int[]|string $value Value for the property
1730+ * @param string|null $tableCreateTime Needed for PROP_COLUMN_ORDER and PROP_COLUMN_VISIB
17541731 */
1755- public function setUiProp (string $ property , mixed $ value , string |null $ tableCreateTime = null ): bool |Message
1756- {
1732+ public function setUiProp (
1733+ UiProperty $ property ,
1734+ array |string $ value ,
1735+ string |null $ tableCreateTime = null ,
1736+ ): bool |Message {
17571737 if ($ this ->uiprefs === []) {
17581738 $ this ->loadUiPrefs ();
17591739 }
17601740
17611741 // we want to save the create time if the property is PROP_COLUMN_ORDER
1762- if (! $ this ->isView () && ($ property === self ::PROP_COLUMN_ORDER || $ property === self ::PROP_COLUMN_VISIB )) {
1742+ if (
1743+ ! $ this ->isView ()
1744+ && ($ property === UiProperty::ColumnOrder || $ property === UiProperty::ColumnVisibility)
1745+ ) {
17631746 $ currCreateTime = $ this ->getStatusInfo ('CREATE_TIME ' );
17641747 if ($ tableCreateTime === null || $ tableCreateTime != $ currCreateTime ) {
17651748 // there is no $table_create_time, or
@@ -1772,7 +1755,7 @@ public function setUiProp(string $property, mixed $value, string|null $tableCrea
17721755 'not be persistent after you refresh this page. ' .
17731756 'Please check if the table structure has been changed. ' ,
17741757 ),
1775- $ property ,
1758+ $ property-> value ,
17761759 ),
17771760 );
17781761 }
@@ -1781,7 +1764,7 @@ public function setUiProp(string $property, mixed $value, string|null $tableCrea
17811764 }
17821765
17831766 // save the value
1784- $ this ->uiprefs [$ property ] = $ value ;
1767+ $ this ->uiprefs [$ property-> value ] = $ value ;
17851768
17861769 // check if pmadb is set
17871770 $ uiPreferencesFeature = $ this ->relation ->getRelationParameters ()->uiPreferencesFeature ;
@@ -1795,18 +1778,16 @@ public function setUiProp(string $property, mixed $value, string|null $tableCrea
17951778 /**
17961779 * Remove a property from UI preferences.
17971780 *
1798- * @param string $property the property
1799- *
18001781 * @return true|Message
18011782 */
1802- public function removeUiProp (string $ property ): bool |Message
1783+ public function removeUiProp (UiProperty $ property ): bool |Message
18031784 {
18041785 if ($ this ->uiprefs === []) {
18051786 $ this ->loadUiPrefs ();
18061787 }
18071788
1808- if (isset ($ this ->uiprefs [$ property ])) {
1809- unset($ this ->uiprefs [$ property ]);
1789+ if (isset ($ this ->uiprefs [$ property-> value ])) {
1790+ unset($ this ->uiprefs [$ property-> value ]);
18101791
18111792 // check if pmadb is set
18121793 $ uiPreferencesFeature = $ this ->relation ->getRelationParameters ()->uiPreferencesFeature ;
0 commit comments