| 1 |
<?php |
<?php |
| 2 |
// $Id: cre.install,v 1.9.2.1.2.2 2007/03/22 15:17:46 hickory Exp $ |
// $Id: $ |
|
require_once(drupal_get_path('module', 'cre') . '/cre.module'); |
|
| 3 |
|
|
| 4 |
function cre_install() { |
function cre_install() { |
| 5 |
switch ($GLOBALS['db_type']) { |
switch ($GLOBALS['db_type']) { |
| 43 |
|
|
| 44 |
$voting_result = db_query("SELECT id FROM {sequences} WHERE name = 'votingapi_vote'"); |
$voting_result = db_query("SELECT id FROM {sequences} WHERE name = 'votingapi_vote'"); |
| 45 |
$vote_obj = db_fetch_object($voting_result); |
$vote_obj = db_fetch_object($voting_result); |
|
variable_set('cre_starting_position', $vote_obj->id + 1); |
|
|
//_cre_load_all_diff_avg(); |
|
| 46 |
|
|
| 47 |
_cre_user_average(); |
_cre_user_average(); |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
|
/* |
| 51 |
|
* This function will be responsible for installing the users' average vote |
| 52 |
|
*/ |
| 53 |
|
function _cre_user_average() { |
| 54 |
|
$result = db_query("SELECT DISTINCT uid from {votingapi_vote}"); |
| 55 |
|
while ($user = db_fetch_object($result)) { |
| 56 |
|
// get all 'percent' vote values made by this user |
| 57 |
|
$total = db_result(db_query("SELECT SUM(value) from {votingapi_vote} WHERE uid = %d AND value_type = 'percent'", $user->uid)); |
| 58 |
|
$num_rows = db_num_rows(db_query("SELECT vote_id from {votingapi_vote} where uid = %d", $user->uid)); |
| 59 |
|
|
| 60 |
|
db_query("INSERT INTO {cre_average_vote} (uid, sum, count) VALUES (%d, %d, %d)", $user->uid, $total, $num_rows); |
| 61 |
|
} |
| 62 |
|
} |
| 63 |
|
|
| 64 |
function cre_update_1() { |
function cre_update_1() { |
| 65 |
$db_average = db_query( |
$db_average = db_query( |
| 66 |
'CREATE TABLE {cre_average_vote}( |
'CREATE TABLE {cre_average_vote}( |
| 76 |
update_sql('ALTER TABLE {cre_similarity_matrix} ADD COLUMN similarity_id int(10) NOT NULL auto_increment, ADD PRIMARY KEY(similarity_id);'); |
update_sql('ALTER TABLE {cre_similarity_matrix} ADD COLUMN similarity_id int(10) NOT NULL auto_increment, ADD PRIMARY KEY(similarity_id);'); |
| 77 |
|
|
| 78 |
_cre_user_average(); |
_cre_user_average(); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
function cre_update_2() { |
| 82 |
|
$ret[] = variable_set('cre_starting_position', 0); |
| 83 |
|
|
| 84 |
|
return $ret; |
| 85 |
} |
} |