|
5 | 5 | */
|
6 | 6 | class ItemModel extends MIDASItemModel
|
7 | 7 | {
|
| 8 | + /** get random items |
| 9 | + * |
| 10 | + * @param UserDao $userDao |
| 11 | + * @param type $policy |
| 12 | + * @param type $limit |
| 13 | + * @return array of ItemDao |
| 14 | + */ |
| 15 | + function getRandomItems($userDao=null,$policy=0,$limit=10,$thumbnailFilter=false) |
| 16 | + { |
| 17 | + if($userDao==null) |
| 18 | + { |
| 19 | + $userId= -1; |
| 20 | + } |
| 21 | + else if(!$userDao instanceof UserDao) |
| 22 | + { |
| 23 | + throw new Zend_Exception("Should be an user."); |
| 24 | + } |
| 25 | + else |
| 26 | + { |
| 27 | + $userId = $userDao->getUserId(); |
| 28 | + } |
| 29 | + |
| 30 | + /* |
| 31 | + if(Zend_Registry::get('configDatabase')->database->adapter=='PDO_MYSQL') |
| 32 | + { |
| 33 | + $rand='RAND()'; |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + $rand='random()'; |
| 38 | + } |
| 39 | + $sql=$this->database->select() |
| 40 | + ->setIntegrityCheck(false) |
| 41 | + ->from(array('i' => 'item')) |
| 42 | + ->join(array('tt'=> $this->database->select() |
| 43 | + ->from(array('i' => 'item'),array('maxid'=>'MAX(item_id)')) |
| 44 | + ), |
| 45 | + ' i.item_id >= FLOOR(tt.maxid*'.$rand.')') |
| 46 | + ->joinLeft(array('ip' => 'itempolicyuser'),' |
| 47 | + i.item_id = ip.item_id AND '.$this->database->getDB()->quoteInto('ip.policy >= ?', $policy).' |
| 48 | + AND '.$this->database->getDB()->quoteInto('user_id = ? ',$userId).' ',array('userpolicy'=>'ip.policy')) |
| 49 | + ->joinLeft(array('ipg' => 'itempolicygroup'),' |
| 50 | + i.item_id = ipg.item_id AND '.$this->database->getDB()->quoteInto('ipg.policy >= ?', $policy).' |
| 51 | + AND ( '.$this->database->getDB()->quoteInto('group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR |
| 52 | + group_id IN (' .new Zend_Db_Expr( |
| 53 | + $this->database->select() |
| 54 | + ->setIntegrityCheck(false) |
| 55 | + ->from(array('u2g' => 'user2group'), |
| 56 | + array('group_id')) |
| 57 | + ->where('u2g.user_id = ?' , $userId) |
| 58 | + ) .'))' ,array('grouppolicy'=>'ipg.policy')) |
| 59 | + ->where( |
| 60 | + '( |
| 61 | + ip.item_id is not null or |
| 62 | + ipg.item_id is not null)' |
| 63 | + ) |
| 64 | + ->limit($limit*2) |
| 65 | + ; |
| 66 | + if($thumbnailFilter) |
| 67 | + { |
| 68 | + $sql->where('thumbnail != ?',''); |
| 69 | + } |
| 70 | +
|
| 71 | + $rowset = $this->database->fetchAll($sql); |
| 72 | + */ |
| 73 | + $rowsetAnalysed=array(); |
| 74 | + /* |
| 75 | + foreach ($rowset as $keyRow=>$row) |
| 76 | + { |
| 77 | + if($row['userpolicy']==null)$row['userpolicy']=0; |
| 78 | + if($row['grouppolicy']==null)$row['grouppolicy']=0; |
| 79 | + if(!isset($rowsetAnalysed[$row['item_id']])||($rowsetAnalysed[$row['item_id']]->policy<$row['userpolicy']&&$rowsetAnalysed[$row['item_id']]->policy<$row['grouppolicy'])) |
| 80 | + { |
| 81 | + $tmpDao= $this->initDao('Item', $row); |
| 82 | + if($row['userpolicy']>=$row['grouppolicy']) |
| 83 | + { |
| 84 | + $tmpDao->policy=$row['userpolicy']; |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + $tmpDao->policy=$row['grouppolicy']; |
| 89 | + } |
| 90 | + $rowsetAnalysed[$row['item_id']] = $tmpDao; |
| 91 | + unset($tmpDao); |
| 92 | + } |
| 93 | + } |
| 94 | + */ |
| 95 | + return $rowsetAnalysed; |
| 96 | + }//end get random |
8 | 97 | }
|
9 | 98 | ?>
|
0 commit comments