|
7 | 7 | */
|
8 | 8 | class FeedModel extends FeedModelBase
|
9 | 9 | {
|
| 10 | + |
10 | 11 | protected function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$policy=0,$limit=20)
|
11 | 12 | {
|
| 13 | + if($loggedUserDao==null) |
| 14 | + { |
| 15 | + $userId=0; // anonymous |
| 16 | + } |
| 17 | + else if(!$loggedUserDao instanceof UserDao) |
| 18 | + { |
| 19 | + throw new Zend_Exception("Should be an user."); |
| 20 | + } |
| 21 | + else |
| 22 | + { |
| 23 | + $userId = $loggedUserDao->getUserId(); |
| 24 | + } |
| 25 | + |
| 26 | + if($userDao!=null&&!$userDao instanceof UserDao) |
| 27 | + { |
| 28 | + throw new Zend_Exception("Should be an user."); |
| 29 | + } |
| 30 | + |
| 31 | + if($communityDao!=null&&!$communityDao instanceof CommunityDao) |
| 32 | + { |
| 33 | + throw new Zend_Exception("Should be a community."); |
| 34 | + } |
| 35 | + |
| 36 | + // Select from the UserFeedPolicy |
| 37 | + $userfeedpolicyarray = $this->database->getCassandra('userfeedpolicy',$userId); |
| 38 | + |
| 39 | + // Get the groups from the user |
| 40 | + $usergrouparray = $this->database->getCassandra('user',$userId,null,"group_","group_"); // need to get only the group_* columns |
| 41 | + |
| 42 | + //print_r($usergrouparray); |
| 43 | + |
| 44 | + $groupids[] = MIDAS_GROUP_ANONYMOUS_KEY; |
| 45 | + |
| 46 | + // Select from the GroupFeedPolicy for the groups |
| 47 | + // multiget |
| 48 | + $groupfeedpolicyarray = $this->database->multigetCassandra('groupfeedpolicy',$groupids); // need to get only the group_* columns |
| 49 | + |
| 50 | + //print_r($groupfeedpolicyarray); |
| 51 | + |
| 52 | + $rowsetAnalysed=array(); |
| 53 | + // Start with the users |
| 54 | + foreach($userfeedpolicyarray as $key=>$row) |
| 55 | + { |
| 56 | + $feed_id = substr($key,5); |
| 57 | + $feedrow = $this->database->getCassandra('feed',$feed_id); |
| 58 | + $feedrow['feed_id'] = $feed_id; |
| 59 | + $dao = $this->initDao('Feed', $feedrow); |
| 60 | + $dao->policy = $row; |
| 61 | + $rowsetAnalysed[$feed_id] = $dao; |
| 62 | + unset($dao); |
| 63 | + } |
| 64 | + |
| 65 | + // Then the groups |
| 66 | + foreach($groupfeedpolicyarray as $key=>$grouprow) |
| 67 | + { |
| 68 | + foreach($grouprow as $feedid=>$policy) |
| 69 | + { |
| 70 | + $feedrow = $this->database->getCassandra('feed',$feed_id); |
| 71 | + $feedrow['feed_id'] = $feed_id; |
| 72 | + |
| 73 | + if(isset($rowsetAnalysed[$feed_id])) |
| 74 | + { |
| 75 | + $dao = $rowsetAnalysed[$feed_id]; |
| 76 | + if($dao->policy<$policy) |
| 77 | + { |
| 78 | + $rowsetAnalysed[$feed_id]->policy = $policy; |
| 79 | + } |
| 80 | + } |
| 81 | + else |
| 82 | + { |
| 83 | + $dao = $this->initDao('Feed', $feedrow); |
| 84 | + $dao->policy = $policy; |
| 85 | + $rowsetAnalysed[$feedid] = $dao; |
| 86 | + unset($dao); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + $this->Component->Sortdao->field='date'; |
| 92 | + $this->Component->Sortdao->order='asc'; |
| 93 | + usort($rowsetAnalysed, array($this->Component->Sortdao,'sortByDate')); |
| 94 | + return $rowsetAnalysed; |
12 | 95 | }
|
| 96 | + |
| 97 | + /** Add a community to a feed |
| 98 | + * @return void */ |
| 99 | + function addCommunity($feed,$community) |
| 100 | + { |
| 101 | + if(!$community instanceof CommunityDao) |
| 102 | + { |
| 103 | + throw new Zend_Exception("Should be a community."); |
| 104 | + } |
| 105 | + if(!$feed instanceof FeedDao) |
| 106 | + { |
| 107 | + throw new Zend_Exception("Should be an feed."); |
| 108 | + } |
| 109 | + |
| 110 | + $feedid = $feed->getFeedId(); |
| 111 | + $communityid = $community->getCommunityId(); |
| 112 | + $column = 'community_'.$communityid; |
| 113 | + |
| 114 | + $dataarray = array(); |
| 115 | + $dataarray[$column] = date('c'); |
| 116 | + |
| 117 | + $column_family = new ColumnFamily($this->database->getDB(),'feed'); |
| 118 | + $column_family->insert($feedid,$dataarray); |
13 | 119 |
|
| 120 | + } // end addCommunity |
| 121 | + |
| 122 | + |
14 | 123 | } // end class
|
15 | 124 | ?>
|
0 commit comments