[fusionregistry-commitlog] SF.net SVN: fusionregistry: [50] branches/stable_3_0_x/upload/sources
Brought to you by:
copland007
From: SVN c. <fus...@li...> - 2008-02-17 21:12:20
|
Revision: 50 http://fusionregistry.svn.sourceforge.net/fusionregistry/?rev=50&view=rev Author: copland007 Date: 2008-02-17 13:12:11 -0800 (Sun, 17 Feb 2008) Log Message: ----------- Implemented client side rating_def cache. ACP custom fields page, change get_cf_groups to get_cf_groups_live call to ensure database data not cache. Fix item modification not saving custom field data correctly. Added ksort to both rating_def and field_def cache retrieval routines for ASC sort type. Results were not being properly sorted from cache. Modified Paths: -------------- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php 2008-02-17 09:56:12 UTC (rev 49) +++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php 2008-02-17 21:12:11 UTC (rev 50) @@ -643,7 +643,7 @@ { // Grab all the custom field definitions and groups first as they will be used by a few things below $cf_defs = $this->lib['custom_fields']->get_cf_defs_live( array( 'ORDER BY' => 'field_order ASC, field_name ASC' ) ); - $cf_groups = $this->lib['custom_fields']->get_cf_groups(); + $cf_groups = $this->lib['custom_fields']->get_cf_groups_live(); $this->ipsclass->html .= $this->ipsclass->skin_acp_global->information_box( "Fusion Registry Custom Fields Overview", "You can manage your garage custom fields from here.<br /><br /><span style='color:red'><b>PLEASE NOTE:</b> You must not configure the same order number for more than 1 custom field. Doing so will result in some of your custom fields not showing up!</span>".'<br /> ' ) . "<br >"; Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php 2008-02-17 09:56:12 UTC (rev 49) +++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php 2008-02-17 21:12:11 UTC (rev 50) @@ -206,9 +206,9 @@ } // Go get our Custom Field definition - $rating_data = $this->lib['rating_fields']->get_rating_defs( array( 'WHERE' => 'rating_id='.$this->ipsclass->input['r'] ) ); + $rating_data = $this->lib['rating_fields']->get_rating_defs_live( array( 'WHERE' => 'rating_id='.$this->ipsclass->input['r'] ) ); - // Since get_rating_defs() returns an array of arrays, we are removing a layer here. + // Since get_rating_defs_live() returns an array of arrays, we are removing a layer here. // The key is the rating_id which was passed in from the beginning ;) $rating = $rating_data[$this->ipsclass->input['r']]; @@ -365,7 +365,7 @@ $this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Fusion Registry Rating Fields" ); // Grab all the rating definitions - $rating_defs = $this->lib['rating_fields']->get_rating_defs( array( 'ORDER BY' => 'rating_order ASC, rating_name ASC' ) ); + $rating_defs = $this->lib['rating_fields']->get_rating_defs_live( array( 'ORDER BY' => 'rating_order ASC, rating_name ASC' ) ); // Loop through our custom field definitions we got from up above foreach ( $rating_defs as $rating_id => $rating_row ) Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php 2008-02-17 09:56:12 UTC (rev 49) +++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php 2008-02-17 21:12:11 UTC (rev 50) @@ -394,17 +394,17 @@ unset($db_string); // Now save their custom field data - foreach ( $cf_input as $cf_num => $cf_value ) + foreach ( $cf_input as $cf_id => $cf_value ) { // Determine if we need to update or insert row - $rs = $this->ipsclass->DB->query("SELECT entry_id FROM ibf_registry_field_entries WHERE item_id = '". $this->ipsclass->input['CID'] ."' AND field_id = '". $cf_row['field_id'] ."'"); + $rs = $this->ipsclass->DB->query("SELECT entry_id FROM ibf_registry_field_entries WHERE item_id = '". $this->ipsclass->input['CID'] ."' AND field_id = '". $cf_id ."'"); $existing = $this->ipsclass->DB->fetch_row($rs); if ( isset($existing['entry_id']) and !empty($existing['entry_id']) ) { // Update existing entry - $db_string = $this->ipsclass->DB->compile_db_update_string( array( 'field_id' => $cf_row['field_id'], + $db_string = $this->ipsclass->DB->compile_db_update_string( array( 'field_id' => $cf_id, 'item_id' => $this->ipsclass->input['CID'], 'field_value' => $cf_value, ) ); @@ -414,7 +414,7 @@ else { // Insert new entry - $db_string = $this->ipsclass->DB->compile_db_insert_string( array( 'field_id' => $cf_row['field_id'], + $db_string = $this->ipsclass->DB->compile_db_insert_string( array( 'field_id' => $cf_id, 'item_id' => $this->ipsclass->input['CID'], 'field_value' => $cf_value, ) ); @@ -639,11 +639,11 @@ $ratings_def = $this->lib['ratings']->get_rating_defs(); - foreach ( $ratings_def as $rating_id => $rating_row ) + foreach ( $ratings_def as $rating_num => $rating_row ) { - if ( !empty( $this->ipsclass->input[$rating_id] ) ) + if ( !empty( $this->ipsclass->input[ $rating_row['rating_id'] ] ) ) { - $user_ratings[$rating_id] = intval( $this->ipsclass->input[$rating_id] ); + $user_ratings[ $rating_row['rating_id'] ] = intval( $this->ipsclass->input[ $rating_row['rating_id'] ] ); } } @@ -1056,7 +1056,7 @@ } // Load the ratings defs - $rating_defs = $this->lib['ratings']->get_rating_defs( array( 'ORDER BY' => 'rating_order ASC' ) ); + $rating_defs = $this->lib['ratings']->get_rating_defs( array( 'ORDER BY' => array( 'rating_order' => 'ASC' ) ) ); // They shouldn't even get to this function if there aren't rating defs if ( empty($rating_defs) ) @@ -1067,7 +1067,7 @@ // Loop through and produce our inner html $inner_html = ''; - foreach ( $rating_defs as $rating_id => $rating_row ) + foreach ( $rating_defs as $rating_num => $rating_row ) { // Create our html select field $select_html = $this->lib['ratings']->build_rating_select( array( 'rating_row' => $rating_row ) ); @@ -1656,7 +1656,7 @@ { $ratings_html = ''; - foreach ( $rating_report as $rating_id => $rating_row ) + foreach ( $rating_report as $rating_num => $rating_row ) { $ratings_html .= $this->ipsclass->compiled_templates['skin_registry_item']->view_rating_row( array( 'rating_name' => $rating_row['rating_name'], 'rating_image' => $rating_row['rating_image'], Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php 2008-02-17 09:56:12 UTC (rev 49) +++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php 2008-02-17 21:12:11 UTC (rev 50) @@ -179,10 +179,14 @@ $sorted[ intval($field_row[ $order_field ]) ] = $field_row; } - if ( $order_value == 'DESC' ) + if ( $order_value == 'ASC' ) { - $sorted = array_reverse($results); + ksort($sorted); } + elseif ( $order_value == 'DESC' ) + { + $sorted = array_reverse($sorted); + } } $results = $sorted; @@ -271,7 +275,7 @@ /** - * Get all the Custom Field Groups, cached if possible + * Get all the Custom Field Groups from the cache * * This function's job is only to retrieve the data from the database, * it should not process the returned data. If this data has already @@ -313,6 +317,40 @@ /** + * Get all the Custom Field Groups from the database + * + * This function's job is only to retrieve the data from the database, + * it should not process the returned data. If this data has already + * been retrieved and stored into cache it will not query the database. + * + * @return array|NULL Success returns an array of an array, outer key is field_group_id; Failure returns NULL. + */ + function get_cf_groups_live() + { + $query = 'SELECT field_id, field_name, field_type, field_options, '. + 'field_default, field_required, field_size, field_rows, '. + 'field_cols, field_order, field_browse, field_highlight, '. + 'field_group_id, field_search '. + 'FROM ibf_registry_field_defs '. + 'WHERE field_group_id IS NOT NULL '. + 'ORDER BY field_group_id ASC, field_order ASC, field_name ASC'; + + $rs = $this->ipsclass->DB->query($query); + + // Build our Custom Field Group data structure, we will be returning + // a complex structure of arrays of arrays + $this->_cf_groups = array(); + + while ( $row = $this->ipsclass->DB->fetch_row($rs) ) + { + $this->_cf_groups[$row['field_group_id']][] = $row; + } + + return $this->_cf_groups; + } + + + /** * Get the Custom Field or Group that has been chosen as the highlight item * * This function's job is only to retrieve the highlight group or item from Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php =================================================================== --- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php 2008-02-17 09:56:12 UTC (rev 49) +++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php 2008-02-17 21:12:11 UTC (rev 50) @@ -70,9 +70,9 @@ /** - * Get Rating definitions + * Get Rating definitions from cache * - * This function's job is only to retrieve the data from the database, + * This function's job is only to retrieve the data from the cache, * it should not process the returned data. * * @todo Cache just like get_field_defs, create new get_field_defs_live for ACP @@ -81,6 +81,67 @@ */ function get_rating_defs($opts=array()) { + $results = $this->ipsclass->cache['registry_rating_defs']; + + // Did we get any restrictions passed? + if ( count($opts) > 0 && is_array($this->ipsclass->cache['registry_rating_defs']) ) + { + // First handle the WHERE clause + if ( isset($opts['WHERE']) && is_array($opts['WHERE']) ) + { + foreach ( $opts['WHERE'] as $where_field => $where_value ) + { + foreach ( $results as $field_id => $field_row ) + { + if ( $field_row[ $where_field ] != $where_value ) + { + // WHERE did not match, remove from results + unset( $results[ $field_id ] ); + } + } + } + } + + // Now handle the ORDER BY clause + if ( isset($opts['ORDER BY']) && is_array($opts['ORDER BY']) ) + { + $sorted = array(); + foreach ( $opts['ORDER BY'] as $order_field => $order_value ) + { + foreach ( $results as $field_num => $field_row ) + { + $sorted[ intval($field_row[ $order_field ]) ] = $field_row; + } + + if ( $order_value == 'ASC' ) + { + ksort($sorted); + } + elseif ( $order_value == 'DESC' ) + { + $sorted = array_reverse($sorted); + } + } + + $results = $sorted; + } + } + + return $results; + } + + + /** + * Get Rating definitions live from database + * + * This function's job is only to retrieve the data from the database, + * it should not process the returned data. + * + * @param array $opts Optional custom SQL cmd/value pair attributes + * @return array An array of an array, outer key is field_id + */ + function get_rating_defs_live($opts=array()) + { $query = "SELECT rating_id,rating_name,rating_order FROM ibf_registry_rating_defs"; // Did we get any restrictions passed? @@ -207,40 +268,41 @@ $report = array(); // First get the current list of rating defs - $ratings_defs = $this->get_rating_defs( array( 'ORDER BY' => 'rating_order ASC' ) ); + $ratings_defs = $this->get_rating_defs( array( 'ORDER BY' => array( 'rating_order' => 'ASC' ) ) ); // Then get report for each of the rating defs for this item - foreach ( $ratings_defs as $rating_id => $rating_row ) + foreach ( $ratings_defs as $rating_num => $rating_row ) { // Initialize the report for this rating - $report[$rating_id] = array(); + $report[ $rating_num ] = array(); $query = "SELECT rating_count, rating_sum FROM ibf_registry_rating_reports ". - "WHERE item_id = '$item_id' AND rating_id = '$rating_id'"; + "WHERE item_id = '$item_id' AND rating_id = '".$rating_row['rating_id']."'"; $rs = $this->ipsclass->DB->query($query); // Add to report to be returned if ( $this->ipsclass->DB->get_num_rows() ) { - $report[$rating_id] = $this->ipsclass->DB->fetch_row($rs); + $report[ $rating_num ] = $this->ipsclass->DB->fetch_row($rs); } // While we are at it, let's generate the html here also. - if ( $report[$rating_id]['rating_count'] > 0 ) + if ( $report[ $rating_num ]['rating_count'] > 0 ) { // If there are votes, report real value - $report[$rating_id]['rating_image'] = $this->get_rating_image( $report[$rating_id]['rating_sum'] / $report[$rating_id]['rating_count'] ); + $report[ $rating_num ]['rating_image'] = $this->get_rating_image( $report[ $rating_num ]['rating_sum'] / $report[ $rating_num ]['rating_count'] ); } else { // If there aren't any votes report medium neutral value - $report[$rating_id]['rating_image'] = $this->get_rating_image( ($this->class->registry_config['rating_max'] + $this->class->registry_config['rating_min'])/2 ); + $report[ $rating_num ]['rating_image'] = $this->get_rating_image( ($this->class->registry_config['rating_max'] + $this->class->registry_config['rating_min'])/2 ); } // Also cram in rating info - $report[$rating_id]['rating_name'] = $rating_row['rating_name']; - $report[$rating_id]['rating_order'] = $rating_row['rating_order']; + $report[ $rating_num ]['rating_id'] = $rating_row['rating_id']; + $report[ $rating_num ]['rating_name'] = $rating_row['rating_name']; + $report[ $rating_num ]['rating_order'] = $rating_row['rating_order']; } return $report; @@ -282,14 +344,14 @@ $rating_default = round( ($this->class->registry_config['rating_min'] + $this->class->registry_config['rating_min'])/2 ); // Loop through each valid rating def and determine if they have voted before or not - foreach ( $ratings_def as $rating_id => $rating_row ) + foreach ( $ratings_def as $rating_num => $rating_row ) { // Determine rating value to be recorded - $rating_value = ( !empty( $user_ratings[$rating_id] ) ) ? $user_ratings[$rating_id] : $rating_default; + $rating_value = ( !empty( $user_ratings[ $rating_row['rating_id'] ] ) ) ? $user_ratings[ $rating_row['rating_id'] ] : $rating_default; // Have they voted for this before? $query = "SELECT entry_id,rating_value FROM ibf_registry_rating_entries ". - "WHERE item_id = '$item_id' AND rating_id = '$rating_id' AND member_id = '". $this->ipsclass->member['id'] ."'"; + "WHERE item_id = '$item_id' AND rating_id = '". $rating_row['rating_id'] ."' AND member_id = '". $this->ipsclass->member['id'] ."'"; $rs = $this->ipsclass->DB->query($query); @@ -298,7 +360,7 @@ // They have not voted for this before, add new entry $db_string = $this->ipsclass->DB->compile_db_insert_string( array( 'member_id' => $this->ipsclass->member['id'], 'item_id' => $item_id, - 'rating_id' => $rating_id, + 'rating_id' => $rating_row['rating_id'], 'rating_value' => $rating_value, 'rating_date' => $epoch_time, ) ); @@ -308,13 +370,13 @@ // Now we need to add this to the rating report. First see if a report exists, // if not create one. $rs2 = $this->ipsclass->DB->query("SELECT entry_id, rating_count, rating_sum FROM ibf_registry_rating_reports ". - "WHERE item_id = '$item_id' AND rating_id = '$rating_id'"); + "WHERE item_id = '$item_id' AND rating_id = '". $rating_row['rating_id'] ."'"); if ( !$this->ipsclass->DB->get_num_rows() ) { // No report yet, create new one $db_string = $this->ipsclass->DB->compile_db_insert_string( array( 'item_id' => $item_id, - 'rating_id' => $rating_id, + 'rating_id' => $rating_row['rating_id'], 'rating_count' => 1, 'rating_sum' => $rating_value, ) ); @@ -351,13 +413,13 @@ // we'll create a new one here just incase. This will patch a problem if it exists // but a clean up routine will need to be run to fix this items rating report. $rs2 = $this->ipsclass->DB->query("SELECT entry_id, rating_count, rating_sum FROM ibf_registry_rating_reports ". - "WHERE item_id = '$item_id' AND rating_id = '$rating_id'"); + "WHERE item_id = '$item_id' AND rating_id = '". $rating_row['rating_id'] ."'"); if ( !$this->ipsclass->DB->get_num_rows() ) { // No report yet, create new one $db_string = $this->ipsclass->DB->compile_db_insert_string( array( 'item_id' => $item_id, - 'rating_id' => $rating_id, + 'rating_id' => $rating_row['rating_id'], 'rating_count' => 1, 'rating_sum' => $rating_value, ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |