Plugin Directory

Changeset 479087


Ignore:
Timestamp:
12/22/2011 09:28:36 AM (13 years ago)
Author:
AgentsOfValue
Message:
  • Added new function rtp_count_rated_item() to be use to count # of user who rate.
  • Updated aft_plgn_fetch_article_rate() function removed redundant sql select query string on querying list of rated posts/pages.
  • Updated Ratings Report tab on displaying the average rating of the posts/pages rated to include displaying the count of users who rated.
  • Admin settings now using cookies to store the last selected tab.
  • Fixed table sorting not properly sorted from highest to lowest.
  • Fixed table layout on admin settings for Insertion and Reports Tab.
  • Fixed pagination on admin settings for Insertion and Reports Tab.
Location:
rate-this-page-plugin/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • rate-this-page-plugin/trunk/css/rtp-style-admin.css

    r475733 r479087  
    234234    font-size: 12px;
    235235}
     236
     237/*-- Insertion Style --*/
     238#rtp-insertion td.rtp-ins-id {
     239    width: 15%;
     240}
     241
     242#rtp-insertion td.rtp-ins-name {
     243    width: 45%;
     244}
     245
     246#rtp-insertion td.rtp-ins-slug {
     247    width: 35%;
     248}
     249
     250/*-- Pagination Style --*/
     251#rtp-insertion tfoot, #rtp-reporting tfoot {
     252    text-align: center;
     253}
     254
     255#rtp-insertion tfoot td, #rtp-reporting tfoot td {
     256    background-color: #E5E5E5;
     257}
     258
     259#rtp-insertion tfoot td img, #rtp-reporting tfoot td img {
     260    vertical-align: middle;
     261}
     262
     263#rtp-insertion tfoot .pagedisplay, #rtp-reporting tfoot .pagedisplay {
     264    background-color: #E5E5E5;
     265    border: 0;
     266    text-align: center;
     267    vertical-align: top;
     268    width: 40px;
     269}
     270
     271/*-- Reporting Style --*/
     272#rtp-reporting thead th {
     273    text-align: center;
     274    word-wrap: break-word;
     275}
     276
     277#rtp-reporting td.rtp-rpt-name {
     278    width: 36%;
     279}
     280
     281#rtp-reporting td.rtp-rpt-rate {
     282    width: 12%;
     283}
     284
     285#rtp-reporting td.rtp-rpt-average {
     286    font-size: 11px;
     287    width: 10%;
     288}
     289
     290#rtp-reporting td.rtp-rpt-rate {
     291    font-size: 11px;
     292    text-align: left;
     293}
     294
     295table.tablesorter tbody td {
     296    font-size: 12px;
     297}
  • rate-this-page-plugin/trunk/readme.txt

    r476274 r479087  
    7070
    7171== Upgrade Notice ==
    72 = 1.3 =
    73 Fixed jQuery initialization on plugin admin page. It will now load only on its specific page.
     72= 1.4 =
     73SOON.
    7474
    7575== Changelog ==
     76= 1.4 =
     77* Added new function rtp_count_rated_item() to be use to count # of user who rate.
     78* Updated aft_plgn_fetch_article_rate() function removed redundant sql select query string on querying list of rated posts/pages.
     79* Updated Ratings Report tab on displaying the average rating of the posts/pages rated to include displaying the count of users who rated.
     80* Admin settings now using cookies to store the last selected tab.
     81* Fixed table sorting not properly sorted from highest to lowest.
     82* Fixed table layout on admin settings for Insertion and Reports Tab.
     83* Fixed pagination on admin settings for Insertion and Reports Tab.
     84
    7685= 1.3 =
    7786* Fixed jQuery initialization on plugin admin page. It will now load only on its specific page.
  • rate-this-page-plugin/trunk/rtp-admin-scripts.php

    r475733 r479087  
    22    jQuery(document).ready(function() {
    33        /** Initialize jQuery Tabs **/
    4         jQuery(".tabs").tabs();
     4        jQuery(".tabs").tabs({
     5            cookie: { expires: 30 },
     6            fx: { opacity: 'toggle', duration: 'fast' }
     7        });
    58       
    69        /** Initialize jQuery Table Sorter **/
    7         jQuery("#report-result").tablesorter({
    8             sortList: [[0,0]],
     10        jQuery("#report-result")
     11        .tablesorter({
     12            sortList: [[6,1]],
    913            headers: {
    1014                2: { sorter: false },
     
    1317                5: { sorter: false }
    1418            }
     19        })
     20        .tablesorterPager({
     21            container: jQuery("#rpt-pager-report"),
     22            positionFixed: false
    1523        });
    1624       
     25        /** Pagination by Category **/
    1726        jQuery("#insertion-by-category").tablesorter({
    1827            sortList: [[1,0]],
    1928            headers: {0: { sorter: false } }
    20         });
     29        })
     30        .tablesorterPager({
     31            container: jQuery("#rpt-pager-bycategory"),
     32            positionFixed: false
     33        });
    2134       
     35        /** Pagination by Page **/
    2236        jQuery("#insertion-by-page").tablesorter({
    2337            sortList: [[1,0]],
    2438            headers: {0: { sorter: false } }
    25         });
     39        })
     40        .tablesorterPager({
     41            container: jQuery("#rpt-pager-bypage"),
     42            positionFixed: false
     43        });
    2644       
    27         jQuery("#insertion-category").tablesorter({
     45        /** Pagination Page and Category **/
     46        jQuery("#insertion-category")
     47        .tablesorter({
    2848            sortList: [[1,0]],
    2949            headers: {0: { sorter: false } }
    30         });
     50        })
     51        .tablesorterPager({
     52            container: jQuery("#rpt-pager-category"),
     53            positionFixed: false
     54        });
    3155       
    32         jQuery("#insertion-page").tablesorter({
     56        jQuery("#insertion-page")
     57        .tablesorter({
    3358            sortList: [[1,0]],
    3459            headers: {0: { sorter: false } }
     60        })
     61        .tablesorterPager({
     62            container: jQuery("#rpt-pager-page"),
     63            positionFixed: false
    3564        });
    3665       
  • rate-this-page-plugin/trunk/rtp-admin.php

    r475764 r479087  
    142142    <div id="message" class="updated"
    143143    <?php
    144         if( (! isset( $_REQUEST['aft_plgn_submit_options'] ) || $error != "") && (! isset( $_REQUEST['rtp_submit_custom'] ) || $error != "" ) )
     144        if( ( !isset( $_REQUEST['aft_plgn_submit_options'] ) || $error != "") &&
     145            ( !isset( $_REQUEST['rtp_submit_custom'] ) || $error != "" ) &&
     146            ( !isset( $_REQUEST['submit-insertion'] ) || $error != "") &&
     147            ( !isset( $_REQUEST['rtp-install-table'] ) || $error != "") &&
     148            ( !isset( $_REQUEST['rtp-uninstall-table'] ) || $error != "") )
    145149            echo "style=\"display:none\"";
    146150    ?>>
     
    257261        </div>
    258262        <div id="rtp-insertion">
    259             <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>#rtp-insertion" enctype="multipart/form-data" >
     263            <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>" enctype="multipart/form-data" >
     264                <input type="hidden" name="submit-insertion" value="submit" />
    260265                <div class="rtp-label-top">
    261                     <input class="button-secondary" name="submit-insertion" type="submit" value="<?php _e( 'Apply Insertion' ); ?>" />
     266                    <input class="button-secondary" type="submit" value="<?php _e( 'Apply Insertion' ); ?>" />
    262267                </div>
    263268                <?php if ( $options['aft_insertion'] == 'by-category' ) : ?>
     
    269274                        <th><?php _e( 'ID', RTP_PLUGIN_SNAME ); ?></th>
    270275                        <th><?php _e( 'Title', RTP_PLUGIN_SNAME ); ?></th>
    271                         <th><?php _e( 'Description', RTP_PLUGIN_SNAME ); ?></th>
    272276                        <th><?php _e( 'Slug', RTP_PLUGIN_SNAME ); ?></th>
    273277                    </thead>
     
    286290                            <input id="aft-category-check-<?php echo $i; ?>" type="checkbox" name="aft-category-check-<?php echo $i; ?>" value="<?php echo $cat_arr->term_id; ?>" <?php if ( $cat_arr->term_id == $cat_opt_id[$i] ) echo 'checked="checked"'; ?> />
    287291                            </th>
    288                             <td><?php echo $cat_arr->term_id; ?></td>
    289                             <td><?php echo $cat_arr->name; ?></td>
    290                             <td><?php echo $cat_arr->description; ?></td>
    291                             <td><?php echo $cat_arr->slug; ?></td>
     292                            <td class="rtp-ins-id"><?php echo $cat_arr->term_id; ?></td>
     293                            <td class="rtp-ins-name"><?php echo $cat_arr->name; ?></td>
     294                            <td class="rtp-ins-slug"><?php echo $cat_arr->slug; ?></td>
    292295                        </tr>
    293296                        <?php $i++; ?>
    294297                        <?php endforeach; ?>
    295298                    </tbody>
     299                    <tfoot>
     300                        <tr id="rpt-pager-bycategory" style="text-align: center;">
     301                            <td colspan="4">
     302                                <img class="first" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop-180.png" />
     303                                <img class="prev" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-180.png" />
     304                                <input class="pagedisplay" type="text" readonly="true" />
     305                                <img class="next" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow.png" />
     306                                <img class="last" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop.png" />
     307                                <input type="hidden" class="pagesize" value="10">
     308                            </td>
     309                        </tr>
     310                    </tfoot>
    296311                </table>
    297                 <div id="category-navigation"></div>
    298                 <script type="text/javascript">
    299                     var cat_pager = new Pager('insertion-by-category', 10);
    300                     cat_pager.init();
    301                     cat_pager.showPageNav('cat_pager', 'category-navigation');
    302                     cat_pager.showPage(1);
    303                 </script>
    304312                <?php elseif ( $options['aft_insertion'] == 'by-page' ) : ?>
    305313                <table id="insertion-by-page" class="tablesorter">
     
    326334                                <input id="aft-page-check-<?php echo $i; ?>" type="checkbox" name="aft-page-check-<?php echo $i; ?>" value="<?php echo $id; ?>" <?php if ( $id == $page_opt_id[$i] ) echo 'checked="checked"'; ?> />
    327335                            </th>
    328                             <td><?php echo $page_data->ID; ?></td>
    329                             <td><?php echo $page_data->post_title; ?></td>
    330                             <td><?php echo $page_data->post_name; ?></td>
     336                            <td class="rtp-ins-id"><?php echo $page_data->ID; ?></td>
     337                            <td class="rtp-ins-name"><?php echo $page_data->post_title; ?></td>
     338                            <td class="rtp-ins-slug"><?php echo $page_data->post_name; ?></td>
    331339                        </tr>
    332340                        <?php $i++; ?>
    333341                        <?php endforeach; ?>
    334342                    </tbody>
     343                    <tfoot>
     344                        <tr id="rpt-pager-bypage" style="text-align: center;">
     345                            <td colspan="4">
     346                                <img class="first" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop-180.png" />
     347                                <img class="prev" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-180.png" />
     348                                <input class="pagedisplay" type="text" readonly="true" />
     349                                <img class="next" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow.png" />
     350                                <img class="last" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop.png" />
     351                                <input type="hidden" class="pagesize" value="10">
     352                            </td>
     353                        </tr>
     354                    </tfoot>
    335355                </table>
    336                 <div id="page-navigation"></div>
    337                 <script type="text/javascript">
    338                     var page_pager = new Pager('insertion-by-page', 10);
    339                     page_pager.init();
    340                     page_pager.showPageNav('page_pager', 'page-navigation');
    341                     page_pager.showPage(1);
    342                 </script>
    343356                <?php else: ?>
    344357                <div style="clear: both;"></div>
     
    353366                                <th><?php _e( 'ID', RTP_PLUGIN_SNAME ); ?></th>
    354367                                <th><?php _e( 'Title', RTP_PLUGIN_SNAME ); ?></th>
    355                                 <th><?php _e( 'Description', RTP_PLUGIN_SNAME ); ?></th>
    356368                                <th><?php _e( 'Slug', RTP_PLUGIN_SNAME ); ?></th>
    357369                            </thead>
     
    370382                                    <input id="aft-category-check-<?php echo $i; ?>" type="checkbox" name="aft-category-check-<?php echo $i; ?>" value="<?php echo $cat_arr->term_id; ?>" <?php if ( $cat_arr->term_id == $cat_opt_id[$i] ) echo 'checked="checked"'; ?> />
    371383                                    </th>
    372                                     <td><?php echo $cat_arr->term_id; ?></td>
    373                                     <td><?php echo $cat_arr->name; ?></td>
    374                                     <td><?php echo $cat_arr->description; ?></td>
    375                                     <td><?php echo $cat_arr->slug; ?></td>
     384                                    <td class="rtp-ins-id"><?php echo $cat_arr->term_id; ?></td>
     385                                    <td class="rtp-ins-name"><?php echo $cat_arr->name; ?></td>
     386                                    <td class="rtp-ins-slug"><?php echo $cat_arr->slug; ?></td>
    376387                                </tr>
    377388                                <?php $i++; ?>
    378389                                <?php endforeach; ?>
    379390                            </tbody>
     391                            <tfoot>
     392                                <tr id="rpt-pager-category" style="text-align: center;">
     393                                    <td colspan="4">
     394                                        <img class="first" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop-180.png" />
     395                                        <img class="prev" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-180.png" />
     396                                        <input class="pagedisplay" type="text" readonly="true" />
     397                                        <img class="next" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow.png" />
     398                                        <img class="last" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop.png" />
     399                                        <input type="hidden" class="pagesize" value="10">
     400                                    </td>
     401                                </tr>
     402                            </tfoot>
    380403                        </table>
    381                         <div id="category-navigation"></div>
    382404                    </fieldset>
    383                     <script type="text/javascript">
    384                         var cat_pager = new Pager('insertion-category', 10);
    385                         cat_pager.init();
    386                         cat_pager.showPageNav('cat_pager', 'category-navigation');
    387                         cat_pager.showPage(1);
    388                     </script>
    389405                </div>
    390                 <br />
    391406                <div>
    392407                    <fieldset>
     
    415430                                        <input id="aft-page-check-<?php echo $i; ?>" type="checkbox" name="aft-page-check-<?php echo $i; ?>" value="<?php echo $page_data->ID; ?>" <?php if ( $page_data->ID == $page_opt_id[$i] ) echo 'checked="checked"'; ?> />
    416431                                    </th>
    417                                     <td><?php echo $page_data->ID; ?></td>
    418                                     <td><?php echo $page_data->post_title; ?></td>
    419                                     <td><?php echo $page_data->post_name; ?></td>
     432                                    <td class="rtp-ins-id"><?php echo $page_data->ID; ?></td>
     433                                    <td class="rtp-ins-name"><?php echo $page_data->post_title; ?></td>
     434                                    <td class="rtp-ins-slug"><?php echo $page_data->post_name; ?></td>
    420435                                </tr>
    421436                                <?php $i++; ?>
    422437                                <?php endforeach; ?>
    423438                            </tbody>
     439                            <tfoot>
     440                                <tr id="rpt-pager-page" style="text-align: center;">
     441                                    <td colspan="4">
     442                                        <img class="first" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop-180.png" />
     443                                        <img class="prev" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-180.png" />
     444                                        <input class="pagedisplay" type="text" readonly="true" />
     445                                        <img class="next" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow.png" />
     446                                        <img class="last" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop.png" />
     447                                        <input type="hidden" class="pagesize" value="10">
     448                                    </td>
     449                                </tr>
     450                            </tfoot>
    424451                        </table>
    425                         <div id="page-navigation"></div>
    426452                    </fieldset>
    427                     <script type="text/javascript">
    428                         var page_pager = new Pager('insertion-page', 10);
    429                         page_pager.init();
    430                         page_pager.showPageNav('page_pager', 'page-navigation');
    431                         page_pager.showPage(1);
    432                     </script>
    433453                </div>
    434454                <?php endif; ?>
    435455                <div class="rtp-label-top">
    436                     <input class="button-secondary" name="submit-insertion" type="submit" value="<?php _e( 'Apply Insertion' ); ?>" />
     456                    <input class="button-secondary" type="submit" value="<?php _e( 'Apply Insertion' ); ?>" />
    437457                </div>
    438458            </form>
     
    447467                    }
    448468                ?>
    449                 <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>#rtp-reporting">
     469                <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>">
    450470                    <div class="rtp-label-top">
    451471                        <?php _e( 'Filter By', RTP_PLUGIN_SNAME ); ?>:&nbsp;
     
    474494                                <th><?php _e( $lbl_wellwritten, RTP_PLUGIN_SNAME ); ?></th>
    475495                                <?php if ( $_POST['aft-filter'] != 'last-update' ) : ?>
    476                                 <th><?php _e( 'Ave. Rating', RTP_PLUGIN_SNAME ); ?></th>
     496                                <th><?php _e( 'Ratings', RTP_PLUGIN_SNAME ); ?></th>
    477497                                <?php else : ?>
    478498                                <th><?php _e( 'Date Modified', RTP_PLUGIN_SNAME ); ?></th>
     
    485505                            <tr valign="top">
    486506                                <td><?php echo $rows->post_id; ?></td>
    487                                 <td>
     507                                <td class="rtp-rpt-name">
    488508                                    <div class="rtp-title">
    489509                                        <a class="rtp-post-title" href="<?php echo admin_url(); ?>post.php?post=<?php echo $rows->post_id ?>&action=edit"><?php echo $rows->post_title; ?></a>
    490510                                    </div>
    491511                                </td>
    492                                 <td><?php echo $rows->trustworthy_rate; ?></td>
    493                                 <td><?php echo $rows->objective_rate; ?></td>
    494                                 <td><?php echo $rows->complete_rate; ?></td>
    495                                 <td><?php echo $rows->wellwritten_rate; ?></td>
     512                                <td class="rtp-rpt-rate">
     513                                    [<strong><?php echo max('0.00', $rows->trustworthy_rate); ?></strong>] Rate /
     514                                    <br />[<strong><?php echo rtp_count_rated_item($rows->post_id, 'trustworthy_rate' ); ?></strong>] Count
     515                                </td>
     516                                <td class="rtp-rpt-rate">
     517                                    [<strong><?php echo max('0.00', $rows->objective_rate); ?></strong>] Rate /
     518                                    <br />[<strong><?php echo rtp_count_rated_item($rows->post_id, 'objective_rate' ); ?></strong>] Count
     519                                </td>
     520                                <td class="rtp-rpt-rate">
     521                                    [<strong><?php echo max('0.00', $rows->complete_rate); ?></strong>] Rate /
     522                                    <br />[<strong><?php echo rtp_count_rated_item($rows->post_id, 'complete_rate' ); ?></strong>] Count
     523                                </td>
     524                                <td class="rtp-rpt-rate">
     525                                    [<strong><?php echo max('0.00', $rows->wellwritten_rate); ?></strong>] Rate /
     526                                    <br />[<strong><?php echo rtp_count_rated_item($rows->post_id, 'wellwritten_rate' ); ?></strong>] Count
     527                                </td>
    496528                                <?php if ( $_POST['aft-filter'] != 'last-update' ) : ?>
    497                                 <td><?php echo $rows->rate_average; ?></td>
     529                                <td class="rtp-rpt-average">
     530                                    [<strong><?php echo $rows->rate_average; ?></strong>] Ave. /
     531                                    <br />[<strong><?php echo rtp_count_rated_item($rows->post_id, array('trustworthy_rate', 'objective_rate', 'complete_rate', 'wellwritten_rate') ); ?></strong>] Count
     532                                </td>
    498533                                <?php else : ?>
    499534                                <td><?php echo $rows->rate_modified; ?></td>
     
    503538                            <?php endif; ?>
    504539                        </tbody>
     540                        <tfoot>
     541                            <tr id="rpt-pager-report" style="text-align: center;">
     542                                <td colspan="7">
     543                                    <img class="first" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop-180.png" />
     544                                    <img class="prev" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-180.png" />
     545                                    <input class="pagedisplay" type="text" readonly="true" />
     546                                    <img class="next" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow.png" />
     547                                    <img class="last" src="<?php echo RTP_PLUGIN_DIR_IMG; ?>arrow-stop.png" />
     548                                    <input type="hidden" class="pagesize" value="10">
     549                                </td>
     550                            </tr>
     551                        </tfoot>
    505552                    </table>
    506                     <div id="pagenavigation"></div>
    507553                </form>
    508                 <script type="text/javascript">
    509                     var pager = new Pager('report-result', 10);
    510                     pager.init();
    511                     pager.showPageNav('pager', 'pagenavigation');
    512                     pager.showPage(1);
    513                 </script>
    514554            </div>
    515555            <div style="clear: both;"></div>
     
    524564        <div id="rtp-db-configuration">
    525565            <div>
    526                 <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>#rtp-db-configuration" enctype="multipart/form-data">
     566                <form method="post" action="admin.php?page=<?php echo RTP_PLUGIN_SNAME; ?>" enctype="multipart/form-data">
    527567                    <table class="rtp-form-table">
    528568                        <tr>
     
    550590    <?php if ( $wpdb->get_var("SHOW TABLES LIKE '$tbl_feedbacks'") != $tbl_feedbacks
    551591            && $wpdb->get_var("SHOW TABLES LIKE '$tbl_feedbacks_summary'") != $tbl_feedbacks_summary ) : ?>
    552             <p class='rtp-p rtp-bg corners'><b><?php _e( 'Warning', RTP_PLUGIN_SNAME ); ?>:<b><br />
    553             <i><?php _e( "No tables found inside the database.<br />
     592            <p class='rtp-p rtp-bg corners'><strong><?php _e( 'Warning', RTP_PLUGIN_SNAME ); ?>:</strong><br />
     593            <em><?php _e( "No tables found inside the database.<br />
    554594            Please go to Database Configuration Tab then (Click Install) to install
    555             the required database tables.", RTP_PLUGIN_SNAME ); ?></i></p>
     595            the required database tables.", RTP_PLUGIN_SNAME ); ?></em></p>
    556596    <?php endif; ?>
    557597</div>
  • rate-this-page-plugin/trunk/rtp-hooks.php

    r476197 r479087  
    5454            wp_enqueue_script( 'jquery-tablesorter', RTP_PLUGIN_DIR_JS . 'jquery.tablesorter.min.js', array( 'jquery' ) );
    5555            wp_enqueue_script( 'jquery-tablesorter-pager', RTP_PLUGIN_DIR_JS . 'jquery.tablesorter.pager.js', array('jquery' ) );
    56             wp_enqueue_script( 'jquery-paging', RTP_PLUGIN_DIR_JS . 'paging.js', array( 'jquery' ) );
     56            wp_enqueue_script( 'jquery-ui-cookie', RTP_PLUGIN_DIR_JS . 'external/jquery.cookie.js', array( 'jquery' ) );
    5757        } else {
    5858            //Initialize jQuery Raty script
  • rate-this-page-plugin/trunk/rtp-query.php

    r439968 r479087  
    104104        $is_page = $aft_data['is_page']; // Identify if the summary stored is a page rated summary.
    105105       
    106         $count_trustworthy = 1;
    107         $count_objective = 1;
    108         $count_complete = 1;
    109         $count_wellwritten = 1;
     106        // Counting the # of user who rated the posts/pages based on each items.
     107        $count_trustworthy = rtp_count_rated_item( $post_id, 'trustworthy_rate' );
     108        $count_objective = rtp_count_rated_item( $post_id, 'objective_rate' );
     109        $count_complete = rtp_count_rated_item( $post_id, 'complete_rate' );
     110        $count_wellwritten = rtp_count_rated_item( $post_id, 'wellwritten_rate' );
    110111       
    111112        // Check if post_id already exist in wp_feedbacks_summary table.
     
    147148                    $total_wellwritten = intval($aft_fetch_data->total_wellwritten + $temp_total);
    148149                }
    149                
    150                 $count_trustworthy = $aft_fetch_data->count_trustworthy;
    151                 $count_objective = $aft_fetch_data->count_objective;
    152                 $count_complete = $aft_fetch_data->count_complete;
    153                 $count_wellwritten = $aft_fetch_data->count_wellwritten;
    154150            } else {
    155151                $total_trustworthy = intval($aft_fetch_data->total_trustworthy + $aft_data['trustworthy_rate']);
     
    157153                $total_complete = intval($aft_fetch_data->total_complete + $aft_data['complete_rate']);
    158154                $total_wellwritten = intval($aft_fetch_data->total_wellwritten + $aft_data['wellwritten_rate']);
    159                
    160                 $count_trustworthy += $aft_fetch_data->count_trustworthy;
    161                 $count_objective += $aft_fetch_data->count_objective;
    162                 $count_complete += $aft_fetch_data->count_complete;
    163                 $count_wellwritten += $aft_fetch_data->count_wellwritten;
    164155            }
    165156        }
     
    216207        global $wpdb;
    217208       
     209        $_sql = "SELECT post_id, post_title,
     210                CAST((total_trustworthy / count_trustworthy) AS decimal(3,2)) AS trustworthy_rate,
     211                CAST((total_objective / count_objective) AS decimal(3,2)) AS objective_rate,
     212                CAST((total_complete / count_complete) AS decimal(3,2)) AS complete_rate,
     213                CAST((total_wellwritten / count_wellwritten) AS decimal(3,2)) AS wellwritten_rate, rate_average
     214                FROM %sfeedbacks_summary ";
     215       
    218216        switch ( $filter ) {
    219217            case "highest":
    220                 $_sql = "SELECT post_id, post_title,
    221                         CAST((total_trustworthy / count_trustworthy) AS decimal(3,2)) AS trustworthy_rate ,
    222                         CAST((total_objective / count_objective) AS decimal(3,2)) AS objective_rate,
    223                         CAST((total_complete / count_complete) AS decimal(3,2)) AS complete_rate,
    224                         CAST((total_wellwritten / count_wellwritten) AS decimal(3,2)) AS wellwritten_rate, rate_average
    225                         FROM %sfeedbacks_summary
    226                         INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id
     218                $_sql .= "INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id
    227219                        WHERE rate_average >= 3.5";
    228220                if ( $insertion == 'page' ) {
     
    235227                break;
    236228            case "lowest":
    237                 $_sql = "SELECT post_id, post_title,
    238                         CAST((total_trustworthy / count_trustworthy) AS decimal(3,2)) AS trustworthy_rate ,
    239                         CAST((total_objective / count_objective) AS decimal(3,2)) AS objective_rate,
    240                         CAST((total_complete / count_complete) AS decimal(3,2)) AS complete_rate,
    241                         CAST((total_wellwritten / count_wellwritten) AS decimal(3,2)) AS wellwritten_rate, rate_average
    242                         FROM %sfeedbacks_summary
    243                         INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id
    244                         WHERE rate_average <= 3.5";
     229                $_sql .= "INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id
     230                        WHERE rate_average <= 3.4";
    245231                if ( $insertion == 'page' ) {
    246232                    $_sql .= " AND is_page = 'true'";
     
    269255            case "all":
    270256            default:
    271                 $_sql = "SELECT post_id, post_title,
    272                         CAST((total_trustworthy / count_trustworthy) AS decimal(3,2)) AS trustworthy_rate ,
    273                         CAST((total_objective / count_objective) AS decimal(3,2)) AS objective_rate,
    274                         CAST((total_complete / count_complete) AS decimal(3,2)) AS complete_rate,
    275                         CAST((total_wellwritten / count_wellwritten) AS decimal(3,2)) AS wellwritten_rate, rate_average
    276                         FROM %sfeedbacks_summary
    277                         INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id";
     257                $_sql .= "INNER JOIN $wpdb->posts ON $wpdb->posts.id = %sfeedbacks_summary.post_id";
    278258                if ( $insertion == 'page' ) {
    279259                    $_sql .= " WHERE is_page = 'true'";
     
    334314    }
    335315}
     316
     317if ( !function_exists( 'rtp_count_rated_item' ) ) {
     318    function rtp_count_rated_item( $post_id, $field_name, $field_value = '' ) {
     319        global $wpdb;
     320       
     321        if ( !is_array( $field_name ) ) {
     322            $sql = "SELECT COUNT(%s) AS count
     323                    FROM %sfeedbacks
     324                    WHERE post_id = %d";
     325                   
     326            if ( empty( $field_value ) ) {
     327                $sql .= " AND %s > 0";
     328                $data = $wpdb->get_row( sprintf( $sql, $field_name, $wpdb->prefix, $post_id, $field_name ) );
     329            }
     330           
     331            return $data->count;
     332        } else {
     333            $sql = "SELECT COUNT(%s) AS count_trustworthy,
     334                    COUNT(%s) AS count_objective,
     335                    COUNT(%s) AS count_complete,
     336                    COUNT(%s) AS count_wellwritten
     337                    FROM %sfeedbacks
     338                    WHERE post_id = %d";
     339                   
     340            $data = $wpdb->get_row( sprintf(
     341                            $sql,
     342                            $field_name[0],
     343                            $field_name[1],
     344                            $field_name[2],
     345                            $field_name[3],
     346                            $wpdb->prefix,
     347                            $post_id ) );
     348                           
     349            $data_arr = array(  $data->count_trustworthy,
     350                                $data->count_objective,
     351                                $data->count_complete,
     352                                $data->count_wellwritten );
     353                               
     354            return array_sum( $data_arr ) / count( $data_arr );
     355        }
     356    }
     357}
    336358?>
Note: See TracChangeset for help on using the changeset viewer.