Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Kalle Moodh
- * @copyright 2011
- * @project Hamsterpaj
- * @version 5.0
- */
- class Hot_or_not_model extends HP_Model
- {
- /**
- * Hot_or_not_model::contestants()
- *
- * @param str $unique_gender
- * @return array
- */
- function contestants($unique_gender = FALSE)
- {
- // Is there a cache set?
- $mash_pool = $this->memcached->get('mash_pool');
- if(IS_CRON || !$mash_pool) {
- // Get huge result set (2000 girls, 2000 boys, 4000 unknowns (might be able to use those later))
- $this->db->select('l.*, u.*, z.spot');
- $this->db->where('u.image !=', 0);
- $this->db->where('u.gender !=', 'u');
- $this->db->where('l.is_removed', 0);
- $this->db->join('userinfo u', 'l.id = u.userid');
- $this->db->join('zip_codes z', 'u.zip_code = z.zip_code');
- $q = $this->db->get('login l');
- $r = $q->result_array();
- $mash_pool = array();
- foreach($r as $k => $v) {
- $mash_pool[$v['gender']][] = array(
- 'id' => $v['id'],
- 'username' => $v['username'],
- 'birthday' => (string) date_get_age($v['birthday']),
- 'gender' => gender_readable($v['gender']),
- 'location' => ($v['spot']) ? 'från ' . $v['spot'] : ''
- );
- }
- // Cache the huge result set
- $this->memcached->set('mash_pool', $mash_pool);
- }
- // Shuffle away!
- shuffle($mash_pool['m']);
- shuffle($mash_pool['f']);
- // Throw out boys or girls or both
- if($unique_gender && in_array($unique_gender, array('m', 'f'))) {
- $final = $mash_pool[$unique_gender];
- } else {
- $l = array('m', 'f');
- $final = $mash_pool[$l[rand(0, 1)]];
- }
- // Pick two choices randomly
- $contestants = array($final[7], $final[23]);
- return $contestants;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement