コード例 #1
0
ファイル: democratic.class.php プロジェクト: cheese1/ampache
 /**
  * set_user_preferences
  * This sets up a (or all) user(s) to use democratic play. This sets
  * their play method and playlist method (clear on send) If no user is
  * passed it does it for everyone and also locks down the ability to
  * change to admins only
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public static function set_user_preferences($user = null)
 {
     //FIXME: Code in single user stuff
     $preference_id = Preference::id_from_name('play_type');
     Preference::update_level($preference_id, '75');
     Preference::update_all($preference_id, 'democratic');
     $allow_demo = Preference::id_from_name('allow_democratic_playback');
     Preference::update_all($allow_demo, '1');
     $play_method = Preference::id_from_name('playlist_method');
     Preference::update_all($play_method, 'clear');
     return true;
 }
コード例 #2
0
ファイル: stream.class.php プロジェクト: axelsimon/ampache
 /**
  * get_now_playing
  *
  * This returns the now playing information
  */
 public static function get_now_playing()
 {
     $sql = 'SELECT `session`.`agent`, `np`.* FROM `now_playing` AS `np` ';
     $sql .= 'LEFT JOIN `session` ON `session`.`id` = `np`.`id` ';
     if (AmpConfig::get('now_playing_per_user')) {
         $sql .= 'INNER JOIN ( ' . 'SELECT MAX(`insertion`) AS `max_insertion`, `user`, `id` ' . 'FROM `now_playing` ' . 'GROUP BY `user`' . ') `np2` ' . 'ON `np`.`user` = `np2`.`user` ' . 'AND `np`.`insertion` = `np2`.`max_insertion` ';
     }
     if (!Access::check('interface', '100')) {
         // We need to check only for users which have allowed view of personnal info
         $personal_info_id = Preference::id_from_name('allow_personal_info_now');
         if ($personal_info_id) {
             $current_user = $GLOBALS['user']->id;
             $sql .= "WHERE (`np`.`user` IN (SELECT `user` FROM `user_preference` WHERE ((`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}'))) ";
         }
     }
     $sql .= 'ORDER BY `np`.`expire` DESC';
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         $type = $row['object_type'];
         $media = new $type($row['object_id']);
         $media->format();
         $client = new User($row['user']);
         $results[] = array('media' => $media, 'client' => $client, 'agent' => $row['agent'], 'expire' => $row['expire']);
     }
     // end while
     return $results;
 }
コード例 #3
0
ファイル: song.class.php プロジェクト: nioc/ampache
 /**
  * get_recently_played
  * This function returns the last X songs that have been played
  * it uses the popular threshold to figure out how many to pull
  * it will only return unique object
  * @param int $user_id
  * @return array
  */
 public static function get_recently_played($user_id = 0)
 {
     $user_id = intval($user_id);
     $sql = "SELECT `object_id`, `user`, `object_type`, `date`, `agent`, `geo_latitude`, `geo_longitude`, `geo_name` " . "FROM `object_count` WHERE `object_type` = 'song' AND `count_type` = 'stream' ";
     if (AmpConfig::get('catalog_disable')) {
         $sql .= "AND " . Catalog::get_enable_filter('song', '`object_id`') . " ";
     }
     if ($user_id) {
         // If user is not empty, we're looking directly to user personal info (admin view)
         $sql .= "AND `user`='{$user_id}' ";
     } else {
         if (!Access::check('interface', '100')) {
             // If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
             $personal_info_id = Preference::id_from_name('allow_personal_info_recent');
             if ($personal_info_id) {
                 $current_user = $GLOBALS['user']->id;
                 $sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}') ";
             }
         }
     }
     $sql .= "ORDER BY `date` DESC ";
     $db_results = Dba::read($sql);
     $results = array();
     while ($row = Dba::fetch_assoc($db_results)) {
         if (empty($row['geo_name']) && $row['latitude'] && $row['longitude']) {
             $row['geo_name'] = Stats::get_cached_place_name($row['latitude'], $row['longitude']);
         }
         $results[] = $row;
         if (count($results) >= AmpConfig::get('popular_threshold')) {
             break;
         }
     }
     return $results;
 }