PHPivot icon indicating copy to clipboard operation
PHPivot copied to clipboard

toHtml bugs

Open paoloflorian opened this issue 6 years ago • 2 comments

HTML tag issues found.

paoloflorian avatar Nov 14 '18 10:11 paoloflorian

//Generates the html code for columns protected function getColHtml(&$colpoint, $row_space, $coldepth = 0, $isLeftmost = true ){ $html = ''; if(is_array($colpoint) && count($this->_columns) - $coldepth > 0){ $new_html = ''; $willBeLeftmost = true; foreach($colpoint as $col_name => $col_value){ if(PHPivot::isSystemField($col_name)) continue; $new_html .= $this->getColHtml($col_value, $row_space, $coldepth + 1, $willBeLeftmost); $willBeLeftmost = false; $html .= '

' . $col_name . ''; } if(count($this->_values) - $coldepth > 0){ $html = str_repeat($html, count($this->_values) - $coldepth); } if($coldepth == 0){ return '' . $row_space . $html . '' . $new_html; }else{ //return ($isLeftmost ? $row_space : '' ) . $html . $new_html; // bug missing and return "" .($isLeftmost ? $row_space : '' ) . $html. "" . $new_html; } }else{ return ''; } }

paoloflorian avatar Nov 14 '18 10:11 paoloflorian

//Figures out where the actual value is and produces html code protected function htmlValues(&$key, &$row, $levels, $type = null){ $levelshtml = '';

    for($i = 0; $i < $levels; $i++){
        $levelshtml .= '<td></td>';
    }
   
    if(!PHPivot::isDataLevel($row)){
        $html = '';
        //fixed bug: missing </tr>  on TYPE_ROW
        if($type == null || strcmp($type, PHPivot::TYPE_ROW) == 0){
            if (strcmp($row['_type'], PHPivot::TYPE_ROW) == 0)
            {
                $html .= '<td>' . $key . '</td></tr>';
            }
            else
            {
                $html .= '<td>' . $key . '</td>';
            }
        } 
        /* original 
        if($type == null || strcmp($type, PHPivot::TYPE_ROW) == 0){
            $html .= '<td>' . $key . '</td>';
        }
        */
        foreach($row as $head => $nest){
            if(PHPivot::isSystemField($head)) continue;
            $t = isset($row['_type']) ?  $row['_type'] : null;
            $new_row = $this->htmlValues($head, $nest, $levels+1, $t);
            $html .=  $new_row;
        }
        ////fixed bug: missing </tr>  on TYPE_ROW
        if($type == null || strcmp($type, PHPivot::TYPE_ROW) == 0 ){
            if (strcmp($row['_type'], PHPivot::TYPE_ROW) == 0)
            {$html = '<tr>' . $levelshtml . $html ;}
            else
            {$html = '<tr>' . $levelshtml . $html .'</tr>';}
        }
        
        
        /* original
        if($type == null || strcmp($type, PHPivot::TYPE_ROW) == 0 ){
            $html = '<tr>' . $levelshtml . $html .'</tr>';
        }
        */
        return $html;
    }else{
        if (isset($row['_type']) && strcmp($row['_type'], PHPivot::TYPE_COMP) == 0){ //Deepest level row, with comparison data
            $c = '<td>';
            for($i = 0; $i < count($row['_val']); $i++){
                $c .=  $row['_val'][$i];
                if($i+1 < count($row['_val'])) $c .= ' &rarr; ';
            }
            $c .= '</td>';
            return $c;
        }
        else if (isset($row['_type']) && strcmp($row['_type'], PHPivot::TYPE_VAL) == 0){ //Deepest level row, with value data
            return '<td>' . $this->getDataValue($row) . '</td>';
        }
        else if($type == PHPivot::TYPE_ROW ){ //Deepest level row
            $html = '<tr>' . $levelshtml . '<td>' . $key . '</td>';
            $html .= '<td style="background:' . $this->getColorOf($row) . ' !important">' . $row . '</td>';
            return $html . '</tr>';
        }else{ //Deepest level column
            if($levels == 0){
                if(PHPivot::isSystemField($key)) return '';
                return '<tr><td>' . $key . '</td><td style="background:' . $this->getColorOf($row) . ' !important">' . $row . '</td></tr>';
            }else{
                $inNest = ($levels - count($this->_columns) - count($this->_rows) + 1 > 0);
                if(!$inNest){
                    return '<td style="background:' . $this->getColorOf($row) . ' !important">' . $row . '</td>';
                }else{
                    return  '<td>' . $key . '</td>' . '<td style="background:' . $this->getColorOf($row) . ' !important">' . $row . '</td>';
                }
            }
        }
    }
}

paoloflorian avatar Nov 14 '18 10:11 paoloflorian