Пример #1
0
$popular_users = $get_popular['users'];
if (!empty($popular_users)) {
    $users_info = array();
    foreach ($popular_users as $users_id) {
        $data = get_user_info($database, $users_id);
        $users_info[] = $data[0];
    }
    #print_r($users_info);
    foreach ($users_info as $key => $v) {
        $rating = avg_rating("users", $v['id'], $database);
        $users_info[$key]['rating'] = $rating;
    }
    $users_info = sortMultiArrayByKey($users_info, "rating");
    #print_r($users_info);
    $tpl->popular_users = $users_info;
}
$popular_poems = $get_popular['poems'];
if (!empty($popular_poems)) {
    $poem_info = array();
    foreach ($popular_poems as $poem_id) {
        $poem_info[] = get_poem($database, $poem_id);
    }
    foreach ($poem_info as $key => $v) {
        $rating = avg_rating("poems", $v['id'], $database);
        $poem_info[$key]['rating'] = $rating;
    }
    $poem_info = sortMultiArrayByKey($poem_info, "rating");
    $tpl->popular_poems = $poem_info;
    #print_r($poem_info);
}
echo $tpl->render("themes/site/" . theme_name . "/html/index.php");
Пример #2
0
 function get_top_rated($database, $options = null)
 {
     $get_top_rated = array();
     $start = null;
     $limit = null;
     if (is_numeric($options) && $options != 0) {
     }
     if (isset($options['LIMIT'])) {
         if (is_numeric($options['LIMIT']) && $options['LIMIT'] != 0) {
             $limit = $options['LIMIT'];
         } else {
             if (is_array($options['LIMIT'])) {
                 if (is_numeric($options['LIMIT'][0])) {
                     $start = $options['LIMIT'][0];
                 }
                 if (is_numeric($options['LIMIT'][1]) && $options['LIMIT'][1] != 0) {
                     $limit = $options['LIMIT'][1];
                 }
             }
         }
     }
     $get_all = $database->select("ratings", "*", array("ORDER" => "id DESC"));
     if (!empty($get_all)) {
         foreach ($get_all as $all) {
             $avg_rating = avg_rating($all['module_type'], $all['module_id'], $database);
             $all_module_data[$all['module_type']][$all['module_id']] = $avg_rating;
         }
         //pr($all_module_data);
     }
     //pr($all_module_data);
     foreach ($all_module_data as $module_type => $v) {
         arsort($all_module_data[$module_type]);
         //pr($all_module_data[$module_type]);
         $skipped = array();
         $modules = array();
         foreach ($v as $module_id => $rating) {
             if ($start) {
                 if (count($skipped) < $start) {
                     $skipped[] = $module_id;
                 } else {
                     if ($limit) {
                         if (count($modules) < $limit) {
                             $modules[] = $module_id;
                         }
                     } else {
                         $modules[] = $module_id;
                     }
                 }
             } else {
                 if ($limit) {
                     if (count($modules) < $limit) {
                         $modules[] = $module_id;
                     }
                 } else {
                     $modules[] = $module_id;
                 }
             }
             //ksort($modules);
             $get_top_rated[$module_type] = $modules;
         }
     }
     //pr($all_module_data);
     if (isset($options['MODULE'])) {
         $new_rated = array();
         if (!is_array($options['MODULE'])) {
             $required_modules = explode(",", $options['MODULE']);
         } else {
             $required_modules = $options['MODULE'];
         }
         foreach ($get_top_rated as $module_type => $v) {
             if (in_array($module_type, $required_modules)) {
                 $new_rated[$module_type] = $v;
             }
         }
         $get_top_rated = $new_rated;
     }
     return $get_top_rated;
 }