Tuesday, May 22, 2012

Design for the PMA_DisplayResults class of PMA

PMA_DisplayResults class will contain the functions specific to the displaying query results and handling special tables like `PROCESSLIST` which provides informations on current threads running in PMA. At the current code base, these functions are appeared as global functions inside display_tbl.lib.php file. After introducing PMA_DisplayResults class instead of this set of functions, the file will be renamed as DisplayResults.class.php .

Class diagram (not the completed one) for the PMA_DisplayResults class

Following code snippet represent some rough implementation of the PMA_DisplayResults class,
class PMA_DisplayResults {
    const DIRECTION_LEFT = 'left';
    const DIRECTION_VERTICAL = 'vertical';
    private $_db;
    private $_table;
    public function __construct($db, $table) {
        $this->_db = $db;
        $this->_table = $table;
    public function getTable() {
        // Related code for getTable function
        $str .= $this->_getTableHeaders();
        // end of the related code
    private function _getTableHeaders() {
        $msg = PMA_getMessage($this->_db, $this->_table);

As the only outsider accessed Display class, the sql.php file will be use,
// inside sql.php file
$displayResultsObj = new PMA_DisplayResults($GLOBALS['db'], $GLOBALS['table']);
echo $displayResultsObj->getTable();

GSoC 2012 - 2nd Week Progress

       This is my second week of GSoC 2012 project since I have started my coding before the official day. I have started to refactoring the file display_tbl.lib.php in PMA. Last week I remove the HTML rendering inside the functions it selves in this file. Some readability improvements also done.

         In this week, I mainly focused on improving the readability of the code inside display_tbl.lib.php file. There were several function which having more than 200 code lines in this file. I broke those functions into sub functions in a way that each sub function do a specific portion for the bigger function. As well the sub functions were not having very large code blocks and those functions were placed just after the referring function.  The names of these sub functions were little longer sometimes, because of they express valuable details for the developer at the first time.

                 In some places there were used similar code segments again and again even in the same functions. Those similar code segments were moved into new sub functions with the help of some additional parameters to separate out the small differences. (PMA_getOperationLinksForVerticleTable, PMA_getColumnParams etc.)

I have mentioned those larger functions which were broken into sub functions with there names below.

  • PMA_getTableNavigation
    • PMA_getMoveBackwardButtonsForTableNavigation
    • PMA_getShowAllButtonForTableNavigation
    • PMA_getMoveFarwardButtonsForTableNavigation
    • PMA_getAdditionalFieldsForTableNavigation
  • PMA_getTableHeaders
    • PMA_getSortByKeyDropDown
    • PMA_getDataForResettingColumnOrder
    • PMA_getOptionsBlock
    • PMA_getFullOrPartialTextButtonOrLink
    • PMA_getFormForMultiRowOperations
    • PMA_getCommentForRow
    • PMA_isInSorted
    • PMA_getSortingUrlParams
    • PMA_getSortOrderLink
    • PMA_getDraggableClassForSortableColumns
    • PMA_getDraggableClassForNonSortableColumns
  • PMA_getTableBody
    • PMA_getUrlSqlQuery
    • PMA_getColumnParams
    • PMA_getVerticalDisplaySupportSegments
    • PMA_getModifiedLinks
    • PMA_getDeleteAndKillLinks
    • PMA_getPlacedLinks
    • PMA_getResettedClassForInlineEdit
    • PMA_getClassForDateTimeRelatedFields
    • PMA_getDataCellForNumericFeilds
    • PMA_getDataCellForBlobField
    • PMA_getDataCellForGeometryFields
    • PMA_getDataCellForNonNumericAndNonBlobFields
  • PMA_getVerticalTable
    • PMA_getOperationLinksForVerticleTable
    • PMA_getCheckBoxesForMultipleRowOperations
  • PMA_getTable
    • PMA_getOffsets
    • PMA_getSortParams
    • PMA_getSortedColumnMessage
    • PMA_setMessageInformation
    • PMA_getMultiRowOperationLinks

         Apart from this I used some coding conventions for improve the readability. If the function is not too small one, an empty space were kept both after starting bracket of the scope and before ending bracket of the scope. Not only for that, wherever I saw the codes are seems packed and hard to read, I put empty lines between code segments. As well I followed the conventions suggested in my proposal.

                     At next week, I'm going to change my plans by giving the place to most prioritized task at the moment. I am going to make the display_tbl.lib.php file as a PHP class. As well I'm going to reduce the usage of global variables which are used in most of the functions. The strings used inside the functions for comparisons, will be replaced with constants. The design for the class will be discussed with the community on next week.

Monday, May 14, 2012

GSoC 2012 - 1st Week Progress

                            This is my first week of Google Summer of Code project which is Refactoring: Displaying query results under phpMyAdmin organization. Since I have my final examination, I started my work before the official day for start coding(21st May). It was a great experience that working with world wide open source community. That experience will be very helpful for me to manage my work in the upcoming weeks.

       According to my project schedule, I was dealing with, refactoring the file "display_tbl.lib.php" in this week. That is a file with 22 global functions. Some of them are really huge functions. As well, though library files are suppose to provide functions which having logics(calculations, concatenation, manipulation etc), while being in a separate layer (data/model layer), this file have some HTML renderings inside themselves. And the naming convention of some methods were different from the phpMyAdmin (PMA) standards.

           In this week, I modified the all the needed functions in "display_tbl.lib.php" file, to remove the HTML renderings inside themselves. Instead of that, that functions are now returning a string which having relevant HTML content for each function. Since inside some of functions are using the functions in "common.lib.php" file and some of them also had the same issue, I modified them as well. The unit tests for each also modified according to the changes I did in corresponding functions.

            The names of most of the functions were changed due to changing of the behavior of some functions. Those names were changed with adding "get" phrase. I was also looked in to modify the code to keep necessary indentation, since it improve the readability of the code.

         At next week, I'll more look into improve the readability of the code with adding the suggested conventions in my proposal. As well the huge functions will be braked in to several functions. The unit tests also will introduced as possible for those function.