/** * calculateTagSize * modified the script so only one table is now used to calculate the tag size. * Add a time parameter so more recently clicked tag have more weigth than older clicks. * */ function calculateTagSize($do_User = NULL) { $max_font = 40; $min_font = 12; $tag_weight = 20; $reference_type = $this->default_reference; $this->setLog("\n Calculating tag sizes at " . date("Y/m/d H:i:s") . " last_calculate:" . $_SESSION['last_tag_refresh']); if ($do_User == NULL) { $do_User = $_SESSION['do_User']; } $q_clicks = new DataObject(); $q_clicks->setTable("tag_click"); $q_clicks->query("SELECT tag_name, clicked FROM tag_click WHERE tag_click.iduser="******" ORDER BY clicked DESC"); $this->setLog("\n Tag click list:" . $q_clicks->getSqlQuery()); $num_tag_clicked = 0; $max_weight = 0; while ($q_clicks->next()) { $ar_tags_weight[$q_clicks->tag_name] += $tag_weight; if ($ar_tags_weight[$q_clicks->tag_name] > $max_weight) { $max_weight = $ar_tags_weight[$q_clicks->tag_name]; } $this->setLog("\n " . $q_clicks->tag_name . " at " . $q_clicks->clicked . " weight:" . $tag_weight . " tag weight:" . $ar_tags_weight[$q_clicks->tag_name]); } if ($q_clicks->getNumRows() == 0) { $q_size = new sqlQuery($this->getDbCon()); $q_size->query("DELETE FROM tag_size WHERE iduser="******"SELECT tag_name FROM tag WHERE reference_type='" . $reference_type . "' AND iduser="******" GROUP BY tag_name"); while ($this->next()) { $q_size->query("INSERT INTO tag_size (tag_name, clicks, iduser) VALUES ('" . $this->tag_name . "', 16, " . $do_User->iduser . ")"); } $q_size->free(); } if ($max_weight > 0) { $q_size = new sqlQuery($this->getDbCon()); $q_size->query("DELETE FROM tag_size WHERE iduser="******"\n Tag " . $tag_name . " size: " . $ar_tag_size[$tag_name] . " = " . $final_weight . "*(" . $max_font . "/" . $max_weight . ") = " . $max_font / ($max_weight + 1) . " -"); } $q_tags = new sqlQuery($this->getDbCon()); $this->query("SELECT tag_name FROM tag WHERE reference_type='" . $reference_type . "' AND iduser="******" GROUP BY tag_name"); while ($this->next()) { if (isset($ar_tag_size[$this->tag_name])) { $tag_size = $ar_tag_size[$this->tag_name]; } else { $tag_size = $min_font; } $q_size->query("INSERT INTO tag_size (tag_name, clicks, iduser) VALUES ('" . $this->tag_name . "', " . $tag_size . ", " . $do_User->iduser . ")"); } $q_size->free(); } $q_clicks->query("DELETE FROM tag_click WHERE iduser="******" AND clicked < date_sub(now(), interval 1 month)"); $q_clicks->free(); }