~ubuntu-branches/ubuntu/lucid/ampache/lucid

« back to all changes in this revision

Viewing changes to lib/class/rating.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-07-07 07:23:35 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707072335-soq0jyo59mgopzd2
Tags: 3.5.1-0ubuntu1
 * New upstream release.  Summary of new features:  (LP: #377016)
   - Make the PHP error a little clearer for windows users by indicating
     that their version of PHP is < 5.3 (required for windows)
   - Fix random methods not working for Localplay
   - Fix extra space on prefixed albums (Thx ibizaman)
   - Add missing operator on tag and rating searches so they will
     work with other methods (Thx kiehnet@netscape.net)
   - Fix get_art_url() so it returns something... 
   - Fix problem with creating new playlists where it doesn't work
     but appending to an existing did. 
   - Fixed issue with url_to_song, also cleaned up the code a bit
   - Fixed issue with Random All Catalogs
   - Fixed issues with API and Tag methods not working as advertised
   - Fix endless loop in getid3() with malformed genre tags in mp3s
   - Fixed show test page always returning false on web path
   - Update Man page to adhear to newer Debian rules
   - Fixed issue with Videos being incorrectly registered with stats
     and now playing as songs. 
   - Fixed missing > in HTML for song row
 * Bumped Standards-Version to 3.8.2, no changes needed.
 * Bumped debhelper to dh 7.
   - increased debian/compat to 7.
   - debian/rules removed dh_clean -k in favor of dh_prep
 * Lintian complains of FreeMonoMedium.ttf being an embeded fonts package.
   FreeMonoMedium.ttf is actually part of the ttf-freefont package.
   - added ttf-freefont to the Depends section of debian/control.
   - added -XFreeMono-Medium to dh_install in debian/rules.
   - added FreeMono.ttf symbolic link to debian/links.
 * Lintian complains of the wrong file permissions for 
   -  /locale/base/gather-messages.sh, added -Xgather-messages.sh to 
   debian/rules, gather-messages.sh is not used by ampache proper and 
   can be safely removed.  It is only utilized by developers who are 
   creating or editing the translation files.
   -  /locale/pl_PL/LC_MESSAGES/messages.po added find and chmod rule 
   to debian/rules.
   -  /locale/pl_PL/LC_MESSAGES/messages.mo added find and chmod rule 
   to debian/rules.
   -  /docs/CHANGELOG added find and chmod rule to debian/rules.
 * Lintian complains of wrong-name-for-upstream-changelog
   -  install upstream CHANGELOG to /usr/share/ampache/www/docs
   -  added find and gzip -9 rule to debian/rules
   -  added symlink creation to debian/links to link
      /usr/share/ampache/www/docs/CHANGELOG.gz to 
      /usr/share/doc/ampache/changelog.gz  
 * Lacy Marrow has responded and has stated that he is dropping the GPL-3 
   licensing of his work and is now releasing version 5.9.5 of the 
   XSPF JukeBox under the same BSD license that the original version of XSPF 
   Music Player was released under (XSPF JukeBox is based on XSPF Music 
   Player).  So now XSPF Music Player and XSPF JukeBox are now released under
   the same BSD type license.  This closes RC Bug #526719.  Closes: #526719
   - Updated debian/copyright to refect this.
 * Added dh_installman to debian/rules so the manpage now installs correctly.
   - Added debian/ampache.manpages.
 * debian/ampache.config downgraded db_input to medium
 * debian/copyright removed (C) in favor of the word copyright.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * This is an amalgamation(sp?) of code from SoundOfEmotion
25
25
 * to track ratings for songs, albums and artists. 
26
26
*/
27
 
class Rating {
 
27
class Rating extends database_object {
28
28
 
29
29
        /* Provided vars */
30
30
        var $id;        // The ID of the object who's ratings we want to pull
58
58
        } // Constructor
59
59
 
60
60
        /**
 
61
         * build_cache
 
62
         * This attempts to get everything we'll need for this page load in a single query, saving
 
63
         * the connection overhead
 
64
         * //FIXME: Improve logic so that misses get cached as average
 
65
         */
 
66
        public static function build_cache($type, $ids) {
 
67
                
 
68
                if (!is_array($ids) OR !count($ids)) { return false; }
 
69
 
 
70
                $user_id = Dba::escape($GLOBALS['user']->id); 
 
71
 
 
72
                $idlist = '(' . implode(',', $ids) . ')';
 
73
                $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . 
 
74
                        "AND `object_type`='$type'";
 
75
                $db_results = Dba::read($sql);
 
76
 
 
77
                while ($row = Dba::fetch_assoc($db_results)) {
 
78
                        $user[$row['object_id']] = $row['rating']; 
 
79
                }
 
80
                
 
81
                $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; 
 
82
                $db_results = Dba::read($sql); 
 
83
                
 
84
                while ($row = Dba::fetch_assoc($db_results)) { 
 
85
                        $rating[$row['object_id']]['rating'] += $row['rating']; 
 
86
                        $rating[$row['object_id']]['total']++; 
 
87
                } 
 
88
 
 
89
                foreach ($ids as $id) { 
 
90
                        parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); 
 
91
 
 
92
                        // Do the bit of math required to store this
 
93
                        if (!isset($rating[$id])) { 
 
94
                                $entry = array('average'=>'0','percise'=>'0'); 
 
95
                        } 
 
96
                        else { 
 
97
                                $average = round($rating[$id]['rating']/$rating[$id]['total'],1); 
 
98
                                $entry = array('average'=>floor($average),'percise'=>$average); 
 
99
                        } 
 
100
                        
 
101
                        parent::add_to_cache('rating_' . $type . '_all',$id,$entry); 
 
102
                } 
 
103
 
 
104
                return true; 
 
105
 
 
106
        } // build_cache
 
107
 
 
108
        /**
61
109
         * get_user
62
110
         * Get the user's rating this is based off the currently logged
63
111
         * in user. It returns the value
64
112
         */
65
 
        public function get_user($user_id) { 
66
 
 
67
 
                $user_id        = Dba::escape($user_id); 
68
 
 
69
 
                $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'";
 
113
         public function get_user($user_id) {
 
114
                
 
115
                $id = intval($this->id); 
 
116
                
 
117
                if (parent::is_cached('rating_' . $this->type . '_user',$id)) { 
 
118
                        return parent::get_from_cache('rating_' . $this->type . '_user',$id); 
 
119
                } 
 
120
 
 
121
                $user_id = Dba::escape($user_id); 
 
122
 
 
123
                $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'";
70
124
                $db_results = Dba::query($sql);
71
125
                
72
126
                $results = Dba::fetch_assoc($db_results);
 
127
 
 
128
                parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']); 
73
129
                
74
130
                return $results['rating'];
75
131
 
84
140
         */
85
141
        public function get_average() { 
86
142
 
87
 
                $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'";
 
143
                $id = intval($this->id); 
 
144
 
 
145
                if (parent::is_cached('rating_' . $this->type . '_all',$id)) { 
 
146
                        $data = parent::get_from_cache('rating_' . $this->type . '_user',$id); 
 
147
                        $this->rating = $data['rating']; 
 
148
                        $this->perciserating = $data['percise']; 
 
149
                        return true; 
 
150
                } 
 
151
 
 
152
                $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$id' AND `object_type`='$this->type'";
88
153
                $db_results = Dba::query($sql);
89
154
 
90
155
                $i = 0;