@@ -1754,116 +1754,34 @@ private function getTableBody(
17541754
17551755 // 1. Prepares the row
17561756
1757- // In print view these variable needs to be initialized
1758- $ deleteUrl = null ;
1759- $ deleteString = null ;
1760- $ editString = null ;
1761- $ jsConf = null ;
1762- $ copyUrl = null ;
1763- $ copyString = null ;
1764- $ editUrl = null ;
1765- $ editCopyUrlParams = [];
1766- $ delUrlParams = null ;
1767-
17681757 // 1.2 Defines the URLs for the modify/delete link(s)
17691758
17701759 if (
17711760 $ displayParts ->hasEditLink
17721761 || $ displayParts ->deleteLink !== DeleteLinkEnum::NO_DELETE
17731762 ) {
1774- $ expressions = [];
1775-
1776- if ($ statementInfo ->statement instanceof SelectStatement) {
1777- $ expressions = $ statementInfo ->statement ->expr ;
1778- }
1779-
1780- // Results from a "SELECT" statement -> builds the
1781- // WHERE clause to use in links (a unique key if possible)
1782- /**
1783- * @todo $where_clause could be empty, for example a table
1784- * with only one field and it's a BLOB; in this case,
1785- * avoid to display the delete and edit links
1786- */
1787- $ uniqueCondition = new UniqueCondition (
1788- $ this ->fieldsMeta ,
1789- self ::$ row ,
1790- false ,
1791- $ this ->table ,
1792- $ expressions ,
1793- );
1794- $ whereClause = $ uniqueCondition ->getWhereClause ();
1795- $ clauseIsUnique = $ uniqueCondition ->isClauseUnique ();
1796- $ conditionArray = $ uniqueCondition ->getConditionArray ();
1797- $ this ->whereClauseMap [$ rowNumber ][$ this ->table ] = $ whereClause ;
1798-
1799- // 1.2.1 Modify link(s) - update row case
1800- if ($ displayParts ->hasEditLink ) {
1801- $ editCopyUrlParams = $ this ->getUrlParams ($ whereClause , $ clauseIsUnique , $ urlSqlQuery );
1802- $ editUrl = Url::getFromRoute ('/table/change ' );
1803- $ copyUrl = Url::getFromRoute ('/table/change ' );
1804- $ editString = $ this ->getActionLinkContent ('b_edit ' , __ ('Edit ' ));
1805- $ copyString = $ this ->getActionLinkContent ('b_insrow ' , __ ('Copy ' ));
1806- }
1807-
1808- // 1.2.2 Delete/Kill link(s)
1809- [$ deleteUrl , $ deleteString , $ jsConf , $ delUrlParams ] = $ this ->getDeleteAndKillLinks (
1810- $ whereClause ,
1811- $ clauseIsUnique ,
1812- $ urlSqlQuery ,
1813- $ displayParts ->deleteLink ,
1814- self ::$ row [0 ],
1815- );
1816-
18171763 // 1.3 Displays the links at left if required
18181764 if (
18191765 $ this ->config ->settings ['RowActionLinks ' ] === self ::POSITION_LEFT
18201766 || $ this ->config ->settings ['RowActionLinks ' ] === self ::POSITION_BOTH
18211767 ) {
1822- $ tableBodyHtml .= $ this ->template ->render ('display/results/checkbox_and_links ' , [
1823- 'position ' => self ::POSITION_LEFT ,
1824- 'has_checkbox ' => $ deleteUrl && $ displayParts ->deleteLink !== DeleteLinkEnum::KILL_PROCESS ,
1825- 'edit ' => [
1826- 'url ' => $ editUrl ,
1827- 'params ' => $ editCopyUrlParams + ['default_action ' => 'update ' ],
1828- 'string ' => $ editString ,
1829- 'clause_is_unique ' => $ clauseIsUnique ,
1830- ],
1831- 'copy ' => [
1832- 'url ' => $ copyUrl ,
1833- 'params ' => $ editCopyUrlParams + ['default_action ' => 'insert ' ],
1834- 'string ' => $ copyString ,
1835- ],
1836- 'delete ' => ['url ' => $ deleteUrl , 'params ' => $ delUrlParams , 'string ' => $ deleteString ],
1837- 'row_number ' => $ rowNumber ,
1838- 'where_clause ' => $ whereClause ,
1839- 'condition ' => json_encode ($ conditionArray ),
1840- 'is_ajax ' => ResponseRenderer::getInstance ()->isAjax (),
1841- 'js_conf ' => $ jsConf ?? '' ,
1842- 'grid_edit_config ' => $ gridEditConfig ,
1843- ]);
1768+ $ tableBodyHtml .= $ this ->getLinksHtml (
1769+ self ::POSITION_LEFT ,
1770+ $ displayParts ,
1771+ $ rowNumber ,
1772+ $ statementInfo ,
1773+ $ gridEditConfig ,
1774+ $ urlSqlQuery ,
1775+ );
18441776 } elseif ($ this ->config ->settings ['RowActionLinks ' ] === self ::POSITION_NONE ) {
1845- $ tableBodyHtml .= $ this ->template ->render ('display/results/checkbox_and_links ' , [
1846- 'position ' => self ::POSITION_NONE ,
1847- 'has_checkbox ' => $ deleteUrl && $ displayParts ->deleteLink !== DeleteLinkEnum::KILL_PROCESS ,
1848- 'edit ' => [
1849- 'url ' => $ editUrl ,
1850- 'params ' => $ editCopyUrlParams + ['default_action ' => 'update ' ],
1851- 'string ' => $ editString ,
1852- 'clause_is_unique ' => $ clauseIsUnique ,
1853- ],
1854- 'copy ' => [
1855- 'url ' => $ copyUrl ,
1856- 'params ' => $ editCopyUrlParams + ['default_action ' => 'insert ' ],
1857- 'string ' => $ copyString ,
1858- ],
1859- 'delete ' => ['url ' => $ deleteUrl , 'params ' => $ delUrlParams , 'string ' => $ deleteString ],
1860- 'row_number ' => $ rowNumber ,
1861- 'where_clause ' => $ whereClause ,
1862- 'condition ' => json_encode ($ conditionArray ),
1863- 'is_ajax ' => ResponseRenderer::getInstance ()->isAjax (),
1864- 'js_conf ' => $ jsConf ?? '' ,
1865- 'grid_edit_config ' => $ gridEditConfig ,
1866- ]);
1777+ $ tableBodyHtml .= $ this ->getLinksHtml (
1778+ self ::POSITION_NONE ,
1779+ $ displayParts ,
1780+ $ rowNumber ,
1781+ $ statementInfo ,
1782+ $ gridEditConfig ,
1783+ $ urlSqlQuery ,
1784+ );
18671785 }
18681786 }
18691787
@@ -1890,28 +1808,14 @@ private function getTableBody(
18901808 && ($ this ->config ->settings ['RowActionLinks ' ] === self ::POSITION_RIGHT
18911809 || $ this ->config ->settings ['RowActionLinks ' ] === self ::POSITION_BOTH )
18921810 ) {
1893- $ tableBodyHtml .= $ this ->template ->render ('display/results/checkbox_and_links ' , [
1894- 'position ' => self ::POSITION_RIGHT ,
1895- 'has_checkbox ' => $ deleteUrl && $ displayParts ->deleteLink !== DeleteLinkEnum::KILL_PROCESS ,
1896- 'edit ' => [
1897- 'url ' => $ editUrl ,
1898- 'params ' => $ editCopyUrlParams + ['default_action ' => 'update ' ],
1899- 'string ' => $ editString ,
1900- 'clause_is_unique ' => $ clauseIsUnique ?? true ,
1901- ],
1902- 'copy ' => [
1903- 'url ' => $ copyUrl ,
1904- 'params ' => $ editCopyUrlParams + ['default_action ' => 'insert ' ],
1905- 'string ' => $ copyString ,
1906- ],
1907- 'delete ' => ['url ' => $ deleteUrl , 'params ' => $ delUrlParams , 'string ' => $ deleteString ],
1908- 'row_number ' => $ rowNumber ,
1909- 'where_clause ' => $ whereClause ?? '' ,
1910- 'condition ' => json_encode ($ conditionArray ?? []),
1911- 'is_ajax ' => ResponseRenderer::getInstance ()->isAjax (),
1912- 'js_conf ' => $ jsConf ?? '' ,
1913- 'grid_edit_config ' => $ gridEditConfig ,
1914- ]);
1811+ $ tableBodyHtml .= $ this ->getLinksHtml (
1812+ self ::POSITION_RIGHT ,
1813+ $ displayParts ,
1814+ $ rowNumber ,
1815+ $ statementInfo ,
1816+ $ gridEditConfig ,
1817+ $ urlSqlQuery ,
1818+ );
19151819 }
19161820
19171821 $ tableBodyHtml .= '</tr> ' ;
@@ -1922,6 +1826,87 @@ private function getTableBody(
19221826 return $ tableBodyHtml ;
19231827 }
19241828
1829+ private function getUniqueCondition (StatementInfo $ statementInfo ): UniqueCondition
1830+ {
1831+ $ expressions = [];
1832+
1833+ if ($ statementInfo ->statement instanceof SelectStatement) {
1834+ $ expressions = $ statementInfo ->statement ->expr ;
1835+ }
1836+
1837+ // Results from a "SELECT" statement -> builds the
1838+ // WHERE clause to use in links (a unique key if possible)
1839+
1840+ /**
1841+ * @todo $where_clause could be empty, for example a table
1842+ * with only one field and it's a BLOB; in this case,
1843+ * avoid to display the delete and edit links
1844+ */
1845+ return new UniqueCondition ($ this ->fieldsMeta , self ::$ row , false , $ this ->table , $ expressions );
1846+ }
1847+
1848+ private function getLinksHtml (
1849+ string $ position ,
1850+ DisplayParts $ displayParts ,
1851+ int $ rowNumber ,
1852+ StatementInfo $ statementInfo ,
1853+ string $ gridEditConfig ,
1854+ string $ urlSqlQuery ,
1855+ ): string {
1856+ $ uniqueCondition = $ this ->getUniqueCondition ($ statementInfo );
1857+ $ whereClause = $ uniqueCondition ->getWhereClause ();
1858+ $ clauseIsUnique = $ uniqueCondition ->isClauseUnique ();
1859+ $ conditionArray = $ uniqueCondition ->getConditionArray ();
1860+ $ this ->whereClauseMap [$ rowNumber ][$ this ->table ] = $ whereClause ;
1861+
1862+ $ editString = null ;
1863+ $ copyUrl = null ;
1864+ $ copyString = null ;
1865+ $ editUrl = null ;
1866+ $ editCopyUrlParams = [];
1867+ if ($ displayParts ->hasEditLink ) {
1868+ $ editCopyUrlParams = $ this ->getUrlParams ($ whereClause , $ clauseIsUnique , $ urlSqlQuery );
1869+ $ editUrl = Url::getFromRoute ('/table/change ' );
1870+ $ copyUrl = Url::getFromRoute ('/table/change ' );
1871+ $ editString = $ this ->getActionLinkContent ('b_edit ' , __ ('Edit ' ));
1872+ $ copyString = $ this ->getActionLinkContent ('b_insrow ' , __ ('Copy ' ));
1873+ }
1874+
1875+ $ deleteString = $ jsConf = '' ;
1876+ $ delUrlParams = [];
1877+ if ($ displayParts ->deleteLink !== DeleteLinkEnum::NO_DELETE ) {
1878+ [$ deleteString , $ jsConf , $ delUrlParams ] = $ this ->getDeleteAndKillLinks (
1879+ $ whereClause ,
1880+ $ clauseIsUnique ,
1881+ $ urlSqlQuery ,
1882+ $ displayParts ->deleteLink ,
1883+ );
1884+ }
1885+
1886+ return $ this ->template ->render ('display/results/checkbox_and_links ' , [
1887+ 'position ' => $ position ,
1888+ 'has_checkbox ' => $ displayParts ->deleteLink === DeleteLinkEnum::DELETE_ROW ,
1889+ 'edit ' => [
1890+ 'url ' => $ editUrl ,
1891+ 'params ' => $ editCopyUrlParams + ['default_action ' => 'update ' ],
1892+ 'string ' => $ editString ,
1893+ 'clause_is_unique ' => $ clauseIsUnique ,
1894+ ],
1895+ 'copy ' => [
1896+ 'url ' => $ copyUrl ,
1897+ 'params ' => $ editCopyUrlParams + ['default_action ' => 'insert ' ],
1898+ 'string ' => $ copyString ,
1899+ ],
1900+ 'delete ' => ['url ' => Url::getFromRoute ('/sql ' ), 'params ' => $ delUrlParams , 'string ' => $ deleteString ],
1901+ 'row_number ' => $ rowNumber ,
1902+ 'where_clause ' => $ whereClause ,
1903+ 'condition ' => json_encode ($ conditionArray ),
1904+ 'is_ajax ' => ResponseRenderer::getInstance ()->isAjax (),
1905+ 'js_conf ' => $ jsConf ,
1906+ 'grid_edit_config ' => $ gridEditConfig ,
1907+ ]);
1908+ }
1909+
19251910 /**
19261911 * Sets the MIME details of the columns in the results set
19271912 */
@@ -2381,19 +2366,17 @@ private function getUrlParams(string $whereClause, bool $clauseIsUnique, string
23812366 *
23822367 * @see getTableBody()
23832368 *
2384- * @param string $whereClause the where clause of the sql
2385- * @param bool $clauseIsUnique the unique condition of clause
2386- * @param string $urlSqlQuery the analyzed sql query
2387- * @param string|null $processId Process ID
2369+ * @param string $whereClause the where clause of the sql
2370+ * @param bool $clauseIsUnique the unique condition of clause
2371+ * @param string $urlSqlQuery the analyzed sql query
23882372 *
2389- * @return array{? string, ? string, ? string, string[]|null }
2373+ * @return array{string, string, string[] }
23902374 */
23912375 private function getDeleteAndKillLinks (
23922376 string $ whereClause ,
23932377 bool $ clauseIsUnique ,
23942378 string $ urlSqlQuery ,
23952379 DeleteLinkEnum $ deleteLink ,
2396- string |null $ processId ,
23972380 ): array {
23982381 if ($ deleteLink === DeleteLinkEnum::DELETE_ROW ) { // delete row case
23992382 $ urlParams = [
@@ -2418,14 +2401,13 @@ private function getDeleteAndKillLinks(
24182401 'message_to_show ' => __ ('The row has been deleted. ' ),
24192402 'goto ' => $ linkGoto ,
24202403 ];
2421- $ deleteUrl = Url::getFromRoute ('/sql ' );
24222404
24232405 $ jsConf = 'DELETE FROM ' . $ this ->table
24242406 . ' WHERE ' . $ whereClause
24252407 . ($ clauseIsUnique ? '' : ' LIMIT 1 ' );
24262408
24272409 $ deleteString = $ this ->getActionLinkContent ('b_drop ' , __ ('Delete ' ));
2428- } elseif ( $ deleteLink === DeleteLinkEnum:: KILL_PROCESS ) { // kill process case
2410+ } else { // kill process case
24292411 $ urlParams = [
24302412 'db ' => $ this ->db ,
24312413 'table ' => $ this ->table ,
@@ -2435,21 +2417,18 @@ private function getDeleteAndKillLinks(
24352417
24362418 $ linkGoto = Url::getFromRoute ('/sql ' , $ urlParams );
24372419
2438- $ kill = $ this ->dbi ->getKillQuery ((int ) $ processId );
2420+ $ kill = $ this ->dbi ->getKillQuery ((int ) self :: $ row [ 0 ] );
24392421
24402422 $ urlParams = ['db ' => 'mysql ' , 'sql_query ' => $ kill , 'goto ' => $ linkGoto ];
24412423
2442- $ deleteUrl = Url::getFromRoute ('/sql ' );
24432424 $ jsConf = $ kill ;
24442425 $ deleteString = Generator::getIcon (
24452426 'b_drop ' ,
24462427 __ ('Kill ' ),
24472428 );
2448- } else {
2449- $ deleteUrl = $ deleteString = $ jsConf = $ urlParams = null ;
24502429 }
24512430
2452- return [$ deleteUrl , $ deleteString , $ jsConf , $ urlParams ];
2431+ return [$ deleteString , $ jsConf , $ urlParams ];
24532432 }
24542433
24552434 /**
0 commit comments