[Customisation Database Commits] r204 - in /trunk/titania: includes/functions.php includes/objects/contribution.php includes/objects/rating.php install/index.php
Nathan Guse
exreaction at phpbb.com
Wed Jun 10 00:36:50 UTC 2009
Author: exreaction
Date: Wed Jun 10 00:36:50 2009
New Revision: 204
Log:
Some more work done on the installer and ratings class
Modified:
trunk/titania/includes/functions.php
trunk/titania/includes/objects/contribution.php
trunk/titania/includes/objects/rating.php
trunk/titania/install/index.php
Modified: trunk/titania/includes/functions.php
==============================================================================
*** trunk/titania/includes/functions.php (original)
--- trunk/titania/includes/functions.php Wed Jun 10 00:36:50 2009
***************
*** 28,31 ****
--- 28,46 ----
function titania_sid($page, $params = false, $is_amp = true, $session_id = false)
{
return append_sid(TITANIA_ROOT . $page . '.' . PHP_EXT, $params = false, $is_amp = true, $session_id = false);
+ }
+
+ /**
+ * Quick function to take a normal select query, turn it into a count query, run the query, then return the result.
+ *
+ * @param string $query The normal SQL Query
+ * @param string $count_column The name of the column you would like to count (probably the primary key...)
+ */
+ function sql_count_query($query, $count_column)
+ {
+ $query = preg_replace('#SELECT(.*)FROM#', 'SELECT COUNT(' . $count_column . ') AS cnt FROM', $query);
+ $query = preg_replace('#LIMIT ([0-9]+)(, ([0-9]+))?#', '', $query);
+
+ phpbb::$db->sql_query($query);
+ return (int) phpbb::$db->sql_fetchfield('cnt');
}
\ No newline at end of file
Modified: trunk/titania/includes/objects/contribution.php
==============================================================================
*** trunk/titania/includes/objects/contribution.php (original)
--- trunk/titania/includes/objects/contribution.php Wed Jun 10 00:36:50 2009
***************
*** 74,79 ****
--- 74,80 ----
'contrib_id' => array('default' => 0),
'contrib_type' => array('default' => 0),
'contrib_name' => array('default' => '', 'max' => 255),
+ 'contrib_name_clean' => array('default' => '', 'max' => 255),
'contrib_description' => array('default' => ''),
'contrib_desc_bitfield' => array('default' => '', 'readonly' => true),
***************
*** 95,101 ****
'contrib_phpbb_version' => array('default' => 3),
'contrib_release_date' => array('default' => 0),
'contrib_update_date' => array('default' => 0),
! 'contrib_visibility' => array('default' => 0),
'contrib_rating' => array('default' => 0.0),
'contrib_rating_count' => array('default' => 0),
--- 96,102 ----
'contrib_phpbb_version' => array('default' => 3),
'contrib_release_date' => array('default' => 0),
'contrib_update_date' => array('default' => 0),
! 'contrib_visible' => array('default' => 0),
'contrib_rating' => array('default' => 0.0),
'contrib_rating_count' => array('default' => 0),
***************
*** 122,127 ****
--- 123,130 ----
$this->generate_text_for_storage(false, false, false);
}
+ $this->contrib_name_clean = utf8_clean_string($this->contrib_name);
+
return parent::submit();
}
Modified: trunk/titania/includes/objects/rating.php
==============================================================================
*** trunk/titania/includes/objects/rating.php (original)
--- trunk/titania/includes/objects/rating.php Wed Jun 10 00:36:50 2009
***************
*** 74,79 ****
--- 74,87 ----
protected $cache_rating_count = '';
/**
+ * Object column
+ * The rating item primary key field (ex: author_id for rating authors)
+ *
+ * @var string
+ */
+ protected $object_column = '';
+
+ /**
* Object ID
* The rating item ID (ex: author_id for rating authors)
*
***************
*** 121,127 ****
$this->cache_table = CUSTOMISATION_AUTHORS_TABLE;
$this->cache_rating = 'author_rating';
$this->cache_rating_count = 'author_rating_count';
! $this->object_id = $object->author_id;
break;
case 'contrib' :
--- 129,135 ----
$this->cache_table = CUSTOMISATION_AUTHORS_TABLE;
$this->cache_rating = 'author_rating';
$this->cache_rating_count = 'author_rating_count';
! $this->object_column = 'author_id';
break;
case 'contrib' :
***************
*** 129,141 ****
$this->cache_table = CUSTOMISATION_CONTRIBS_TABLE;
$this->cache_rating = 'contrib_rating';
$this->cache_rating_count = 'contrib_rating_count';
! $this->object_id = $object->contrib_id;
break;
}
! // Get the rating and rating count
$this->rating = $object->{$this->cache_rating};
$this->rating_count = $object->{$this->cache_rating_count};
// Get the current user's rating (if any)
$this->get_rating();
--- 137,150 ----
$this->cache_table = CUSTOMISATION_CONTRIBS_TABLE;
$this->cache_rating = 'contrib_rating';
$this->cache_rating_count = 'contrib_rating_count';
! $this->object_column = 'contrib_id';
break;
}
! // Get the rating, rating count, and item id
$this->rating = $object->{$this->cache_rating};
$this->rating_count = $object->{$this->cache_rating_count};
+ $this->object_id = $object->{$this->object_column};
// Get the current user's rating (if any)
$this->get_rating();
***************
*** 197,202 ****
--- 206,230 ----
$this->rating_value = $rating;
$this->submit();
+
+ // Resync the cache table
+ $cnt = $total = 0;
+ $sql = 'SELECT rating_value FROM ' . $this->sql_table . '
+ WHERE rating_type_id = ' . (int) $this->rating_type . '
+ AND rating_object_id = ' . (int) $this->object_id;
+ $result = phpbb::$db->sql_query($sql);
+ while ($row = phpbb::$db->sql_fetchrow($result))
+ {
+ $cnt++;
+ $total += $row['rating_value'];
+ }
+ phpbb::$db->sql_freeresult($result);
+
+ $sql = 'UPDATE ' . $this->cache_table . ' SET ' .
+ $this->cache_rating . ' = ' . round($total / $cnt, 2) . ', ' .
+ $this->cache_rating_count . ' = ' . $cnt . '
+ WHERE ' . $this->object_column . ' = ' . $this->object_id;
+ phpbb::$db->sql_query($sql);
}
/**
***************
*** 209,215 ****
return;
}
! // delete a rating from this item
}
/**
--- 237,262 ----
return;
}
! $this->delete();
!
! // Resync the cache table
! $cnt = $total = 0;
! $sql = 'SELECT rating_value FROM ' . $this->sql_table . '
! WHERE rating_type_id = ' . (int) $this->rating_type . '
! AND rating_object_id = ' . (int) $this->object_id;
! $result = phpbb::$db->sql_query($sql);
! while ($row = phpbb::$db->sql_fetchrow($result))
! {
! $cnt++;
! $total += $row['rating_value'];
! }
! phpbb::$db->sql_freeresult($result);
!
! $sql = 'UPDATE ' . $this->cache_table . ' SET ' .
! $this->cache_rating . ' = ' . round($total / $cnt, 2) . ', ' .
! $this->cache_rating_count . ' = ' . $cnt . '
! WHERE ' . $this->object_column . ' = ' . $this->object_id;
! phpbb::$db->sql_query($sql);
}
/**
***************
*** 226,230 ****
--- 273,283 ----
WHERE rating_type_id = ' . (int) $this->rating_type . '
AND rating_object_id = ' . (int) $this->object_id;
phpbb::$db->sql_query($sql);
+
+ $sql = 'UPDATE ' . $this->cache_table . ' SET ' .
+ $this->cache_rating . ' = 0, ' .
+ $this->cache_rating_count . ' = 0
+ WHERE ' . $this->object_column . ' = ' . $this->object_id;
+ phpbb::$db->sql_query($sql);
}
}
\ No newline at end of file
Modified: trunk/titania/install/index.php
==============================================================================
*** trunk/titania/install/index.php (original)
--- trunk/titania/install/index.php Wed Jun 10 00:36:50 2009
***************
*** 41,47 ****
'author_website' => array('VCHAR_UNI:200', ''),
'author_email' => array('VCHAR_UNI:100', ''),
'author_email_hash' => array('BINT', 0),
! 'author_rating' => array('DECIMAL:6', 0),
'author_rating_count' => array('UINT', 0),
'author_contribs' => array('UINT', 0), //
'author_snippets' => array('UINT', 0), // Number of snippets
--- 41,47 ----
'author_website' => array('VCHAR_UNI:200', ''),
'author_email' => array('VCHAR_UNI:100', ''),
'author_email_hash' => array('BINT', 0),
! 'author_rating' => array('DECIMAL', 0),
'author_rating_count' => array('UINT', 0),
'author_contribs' => array('UINT', 0), //
'author_snippets' => array('UINT', 0), // Number of snippets
***************
*** 54,65 ****
'user_id' => array('INDEX', 'user_id'),
'phpbb_user_id' => array('INDEX', 'phpbb_user_id'),
'author_username_clean' => array('INDEX', 'author_username_clean'),
! 'author_rating' => array('INDEX', 'author_uauthor_ratingsername_clean'),
'author_contribs' => array('INDEX', 'author_contribs'),
'author_snippets' => array('INDEX', 'author_snippets'),
'author_mods' => array('INDEX', 'author_mods'),
'author_styles' => array('INDEX', 'author_styles'),
),
)),
array('customisation_ratings', array(
'COLUMNS' => array(
--- 54,131 ----
'user_id' => array('INDEX', 'user_id'),
'phpbb_user_id' => array('INDEX', 'phpbb_user_id'),
'author_username_clean' => array('INDEX', 'author_username_clean'),
! 'author_rating' => array('INDEX', 'author_rating'),
'author_contribs' => array('INDEX', 'author_contribs'),
'author_snippets' => array('INDEX', 'author_snippets'),
'author_mods' => array('INDEX', 'author_mods'),
'author_styles' => array('INDEX', 'author_styles'),
+ 'author_visible' => array('INDEX', 'author_visible'),
+ ),
+ )),
+ array('customisation_contribs', array(
+ 'COLUMNS' => array(
+ 'contrib_id' => array('UINT', NULL, 'auto_increment'),
+ 'contrib_author_id' => array('UINT', 0), // would like to replace with user_id...
+ 'contrib_maintainer' => array('UINT', 0), // ???
+ 'contrib_type' => array('TINT:1', 0),
+ 'contrib_name' => array('STEXT_UNI', '', 'true_sort'),
+ 'contrib_name_clean' => array('VCHAR_CI', ''),
+ 'contrib_description' => array('MTEXT_UNI', ''),
+ 'contrib_desc_bitfield' => array('VCHAR:255', ''),
+ 'contrib_desc_uid' => array('VCHAR:8', ''),
+ 'contrib_desc_options' => array('UINT:11', 7),
+ 'contrib_status' => array('TINT:2', 0),
+ 'contrib_version' => array('VCHAR:15', 0), // don't think we need, we will need to get all the revisions anyways when displaying the mod
+ 'contrib_revision' => array('UINT', 0), // don't think we need...
+ 'contrib_validated_version' => array('VCHAR:15', 0), // don't think we need...
+ 'contrib_validated_revision' => array('UINT', 0), // don't think we need...
+ 'contrib_release_date' => array('INT:11', 0), // don't think we need...
+ 'contrib_update_date' => array('INT:11', 0), // don't think we need...
+ 'contrib_downloads' => array('UINT', 0),
+ 'contrib_views' => array('UINT', 0),
+ 'contrib_phpbb_version' => array('TINT:2', 0), // 3.0.0 -> 30, 3.2.0 -> 32
+ 'contrib_rating' => array('DECIMAL', 0),
+ 'contrib_rating_count' => array('UINT', 0),
+ 'contrib_demo' => array('VCHAR:255', ''),
+ 'contrib_visible' => array('BOOL', 1),
+ ),
+ 'PRIMARY_KEY' => 'contrib_id',
+ 'KEYS' => array(
+ 'contrib_author_id' => array('INDEX', 'contrib_author_id'),
+ 'contrib_type' => array('INDEX', 'contrib_type'),
+ 'contrib_name_clean' => array('INDEX', 'contrib_name_clean'),
+ 'contrib_status' => array('INDEX', 'contrib_status'),
+ 'contrib_downloads' => array('INDEX', 'contrib_downloads'),
+ 'contrib_rating' => array('INDEX', 'contrib_rating'),
+ 'contrib_visible' => array('INDEX', 'contrib_visible'),
+ ),
+ )),
+ array('customisation_contrib_faq', array(
+ 'COLUMNS' => array(
+ 'faq_id' => array('UINT', NULL, 'auto_increment'),
+ 'contrib_id' => array('UINT', 0),
+ 'parent_id' => array('UINT', 0),
+ 'contrib_version' => array('VCHAR:15', 0), // Remove this later (if it applies to a specific version the Mod author should just note it in the FAQ item, this is too clunky)
+ 'faq_order_id' => array('UINT', 0),
+ 'faq_subject' => array('STEXT_UNI', '', 'true_sort'),
+ 'faq_text' => array('MTEXT_UNI', ''),
+ 'faq_text_bitfield' => array('VCHAR:255', ''),
+ 'faq_text_uid' => array('VCHAR:8', ''),
+ 'faq_text_options' => array('UINT:11', 7),
+ ),
+ 'PRIMARY_KEY' => 'faq_id',
+ 'KEYS' => array(
+ 'contrib_id' => array('INDEX', 'contrib_id'),
+ 'faq_order_id' => array('INDEX', 'faq_order_id'),
+ ),
+ )),
+ array('customisation_contrib_tags', array(
+ 'COLUMNS' => array(
+ 'contrib_id' => array('UINT', 0),
+ 'tag_id' => array('UINT', 0),
+ 'tag_value' => array('STEXT_UNI', '', 'true_sort'),
),
+ 'PRIMARY_KEY' => array('contrib_id', 'tag_id'),
)),
array('customisation_ratings', array(
'COLUMNS' => array(
***************
*** 67,73 ****
'rating_type_id' => array('UINT', 0),
'rating_user_id' => array('UINT', 0),
'rating_object_id' => array('UINT', 0),
! 'rating_value' => array('DECIMAL:6', 0), // Not sure if we should allow partial ratings (like 4.5/5) or just integer ratings...
),
'PRIMARY_KEY' => 'rating_id',
'KEYS' => array(
--- 133,139 ----
'rating_type_id' => array('UINT', 0),
'rating_user_id' => array('UINT', 0),
'rating_object_id' => array('UINT', 0),
! 'rating_value' => array('DECIMAL', 0), // Not sure if we should allow partial ratings (like 4.5/5) or just integer ratings...
),
'PRIMARY_KEY' => 'rating_id',
'KEYS' => array(
More information about the customisationdb-commits
mailing list