PHP Classes

File: zray/Panels/codingstandard.phtml

Recommend this page to a friend!
  Classes of Simo   CodeIgniter Plugin for Z-Ray   zray/Panels/codingstandard.phtml   Download  
File: zray/Panels/codingstandard.phtml
Role: Example script
Content type: text/plain
Description: Example script
Class: CodeIgniter Plugin for Z-Ray
Show CodeIgniter application information in Z-Ray
Author: By
Last change:
Date: 2 years ago
Size: 4,254 bytes
 

Contents

Class file image Download
<?php
$tableParams
= array(
       
'tableId' => 'codeigniter-coding-table',
       
'tableWidth' => '3',
       
'summaryTableId' => 'codeigniter-coding-summary-table',
       
'summaryTableWidth' => '1',
);
?>

<?php echo $this->zrayTable($tableParams) ?>

<script type="text/javascript">
    (function() {
        var storage = zray.getStorage('CodeIgniterCodingStandard');

        // create main table
        var maintable = zray.createTable(storage, jQuery('#<?php echo $tableParams['tableId']; ?>'));
        maintable.setColumns([
            {
                "label": "Filename",
                "propertyName": "filename",
                "sortable": true,
                "width": '35%',
                getHtml: function(val, rec) {
                    var titleText = rec.filepath + ':' + rec.line;
                    var url = (window.location != window.parent.location)
                        ? document.referrer
                        : document.location;
                    var showInIDEParams = rec.filepath ? { filePath: rec.filepath, line: rec.line, fullUrl: url } : false;

                    return zendDevBar.getFileActions(val, val, titleText, showInIDEParams);
                }
            },
            {
                "label": "Severity",
                "propertyName": "severity",
                "sortable": true,
                "width": '10%'
            },
            {
                "label": "Line number",
                "propertyName": "line",
                "sortable": true,
                "width": '10%'
            },
            {
                "label": "Message",
                "propertyName": "message",
                "sortable": false
            }
        ]);
        // create main table - end

        // create the summary table
        var summaryTable = zray.createSummaryTable(storage, jQuery('#<?php echo $tableParams['summaryTableId']; ?>'));

        // set the columns structure
        summaryTable.setColumns([
            {
                label: 'Files',
                propertyName: 'filename',
                getHtml: function(val, rec) {
                    return summaryTable.createCheckboxColumn(val, rec, summaryTable);
                }
            },
            {
                label: 'Filename',
                propertyName: 'filename',
                width: '80%'
            },
            {
                label: 'Errors',
                propertyName: 'error',
                width: '10%',
                attributes: {'class': 'zdb-numerical'},
                getHtml: function(val) {
                    return '(' + val + ')';
                }
            },
            {
                label: 'Warnings',
                propertyName: 'warning',
                width: '10%',
                attributes: {'class': 'zdb-numerical'},
                getHtml: function(val) {
                    return '(' + val + ')';
                }
            }

        ]);

        // set by which column the user choice will filter
        summaryTable.setFilterColumn('filename');

        // set callback function to create the table rows from all the data
        // return an array of rows, with columns that match to setColumns
        summaryTable.setUpdateCallback(function (data) {
            if (! data) return [];

            var aggregated = {};
            $zendDevBar.each(data, function(key, observer){
                var key = (observer.severity).toLowerCase();
                if (aggregated[observer.filename]) {
                    aggregated[observer.filename][key]++;
                } else {
                    aggregated[observer.filename] = {'error' : 0, 'warning' : 0, 'filepath' : observer.filepath };
                    aggregated[observer.filename][key] = 1;
                }
            });

            if (Object.keys(aggregated).length == 0) {
                return [];
            }

            var normalized = [];
            normalized.push({
                'filename': 'All',
                'error': jQuery.map(aggregated, function(v, k){return v.error}).reduce(function(acc, item){ return acc += item}),
                'warning': jQuery.map(aggregated, function(v, k){return v.warning}).reduce(function(acc, item){ return acc += item}),
            });

            return normalized.concat($zendDevBar.map(aggregated, function(item, filename){
                return {'filename': filename, 'error': item.error, 'warning': item.warning, 'filepath': item.filepath};
            }));
        });
        // create summary table - end

        // create pager and search
        zray.createPager(storage, jQuery('#<?php echo $params['pagerId']; ?>'));
        zray.createSearch(storage, jQuery('#<?php echo $params['searchId']; ?>'), maintable);

        zray.registerDataHandler('CodeIgniter', 'codingstandard', function(extensionData, requestData) {
            storage.setData(extensionData);
        });
    })();
</script>