Advertisement
Guest User

Untitled

a guest
Nov 28th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author Kalle Moodh
  4.  * @copyright 2011
  5.  * @project Hamsterpaj
  6.  * @version 5.0
  7.  */
  8. class Hot_or_not_model extends HP_Model
  9. {
  10.     /**
  11.      * Hot_or_not_model::contestants()
  12.      *
  13.      * @param str $unique_gender
  14.      * @return array
  15.      */
  16.     function contestants($unique_gender = FALSE)
  17.     {
  18.         // Is there a cache set?
  19.         $mash_pool = $this->memcached->get('mash_pool');
  20.         if(IS_CRON || !$mash_pool) {
  21.        
  22.             // Get huge result set (2000 girls, 2000 boys, 4000 unknowns (might be able to use those later))
  23.             $this->db->select('l.*, u.*, z.spot');
  24.             $this->db->where('u.image !=', 0);
  25.             $this->db->where('u.gender !=', 'u');
  26.             $this->db->where('l.is_removed', 0);
  27.             $this->db->join('userinfo u', 'l.id = u.userid');
  28.             $this->db->join('zip_codes z', 'u.zip_code = z.zip_code');
  29.             $q = $this->db->get('login l');
  30.             $r = $q->result_array();
  31.            
  32.             $mash_pool = array();
  33.             foreach($r as $k => $v) {
  34.    
  35.                 $mash_pool[$v['gender']][] = array(
  36.                     'id' => $v['id'],
  37.                     'username' => $v['username'],
  38.                     'birthday' => (string) date_get_age($v['birthday']),
  39.                     'gender' => gender_readable($v['gender']),
  40.                     'location' => ($v['spot']) ? 'från ' . $v['spot'] : ''
  41.                 );
  42.            
  43.             }
  44.    
  45.             // Cache the huge result set
  46.             $this->memcached->set('mash_pool', $mash_pool);
  47.    
  48.         }
  49.        
  50.         // Shuffle away!
  51.        
  52.         shuffle($mash_pool['m']);
  53.         shuffle($mash_pool['f']);
  54.    
  55.         // Throw out boys or girls or both
  56.         if($unique_gender && in_array($unique_gender, array('m', 'f'))) {
  57.             $final = $mash_pool[$unique_gender];
  58.         } else {
  59.             $l = array('m', 'f');
  60.             $final = $mash_pool[$l[rand(0, 1)]];
  61.        
  62.         }
  63.        
  64.         // Pick two choices randomly
  65.         $contestants = array($final[7], $final[23]);
  66.         return $contestants;
  67.     }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement