Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: Fixing cassandra's feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Jomier committed Mar 28, 2011
1 parent da4e2d1 commit deb6160
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 27 deletions.
1 change: 1 addition & 0 deletions core/models/base/FeedModelBase.php
Expand Up @@ -116,6 +116,7 @@ function createFeed($userDao,$type,$ressource,$communityDao=null)
if($communityDao instanceof CommunityDao)
{
$this->addCommunity($feed, $communityDao);
$feed->community = $communityDao;
}
return $feed;
} // end createFeed()
Expand Down
1 change: 1 addition & 0 deletions core/models/base/FeedpolicygroupModelBase.php
Expand Up @@ -53,6 +53,7 @@ public function createPolicy($group, $feed, $policy)
$policyGroupDao=new FeedpolicygroupDao();
$policyGroupDao->setGroupId($group->getGroupId());
$policyGroupDao->setFeedId($feed->getFeedId());
$policyGroupDao->community = $feed->community;
$policyGroupDao->setPolicy($policy);
$this->save($policyGroupDao);
return $policyGroupDao;
Expand Down
87 changes: 63 additions & 24 deletions core/models/cassandra/FeedModel.php
Expand Up @@ -33,22 +33,59 @@ protected function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$po
throw new Zend_Exception("Should be a community.");
}

// Select from the UserFeedPolicy
$userfeedpolicyarray = $this->database->getCassandra('userfeedpolicy',$userId);

// Get the groups from the user
$usergrouparray = $this->database->getCassandra('user',$userId,null,"group_","group_"); // need to get only the group_* columns

//print_r($usergrouparray);

$groupids[] = MIDAS_GROUP_ANONYMOUS_KEY;


// If we ask for the feeds for a user
if($userDao)
{
}
else if($communityDao)
{
$communityid = $communityDao->getCommunityId();
$communityfeed = $this->database->getCassandra('communityfeed',$communityid);

$userfeedpolicyarray = array();
$groupfeedpolicyarray = array();

foreach($communityfeed as $feed => $values)
{
// Groups
$groups = array();
foreach($groupids as $groupid)
{
$groups['group_'.$groupid] = 0;
}

foreach(array_intersect_key($values,$groups) as $group => $policy)
{
if(!isset($groupfeedpolicyarray[$feed])
|| $groupfeedpolicyarray[$feed][substr($feed,5)]<$policy )
{
$array[$feed] = $policy;
$groupfeedpolicyarray[$feed] = $array;
}
}

// User
if(key_exists('user_'.$userId,$values))
{
$userfeedpolicyarray[$feed] = $values;
}
}
}
else
{
// Select from the UserFeedPolicy
$userfeedpolicyarray = $this->database->getCassandra('userfeedpolicy',$userId);

// Select from the GroupFeedPolicy for the groups
// multiget
$groupfeedpolicyarray = $this->database->multigetCassandra('groupfeedpolicy',$groupids); // need to get only the group_* columns

//print_r($groupfeedpolicyarray);

// Select from the GroupFeedPolicy for the groups
// multiget
$groupfeedpolicyarray = $this->database->multigetCassandra('groupfeedpolicy',$groupids); // need to get only the group_* columns
}

$rowsetAnalysed=array();
// Start with the users
foreach($userfeedpolicyarray as $key=>$row)
Expand All @@ -61,12 +98,14 @@ protected function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$po
$rowsetAnalysed[$feed_id] = $dao;
unset($dao);
}

// Then the groups
foreach($groupfeedpolicyarray as $key=>$grouprow)
{
foreach($grouprow as $feedid=>$policy)
{
foreach($grouprow as $feed_id=>$policy)
{
$feed_id = substr($feed_id,5);

$feedrow = $this->database->getCassandra('feed',$feed_id);
$feedrow['feed_id'] = $feed_id;

Expand All @@ -76,18 +115,18 @@ protected function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$po
if($dao->policy<$policy)
{
$rowsetAnalysed[$feed_id]->policy = $policy;
}
}
}
else
{
$dao = $this->initDao('Feed', $feedrow);
$dao->policy = $policy;
$rowsetAnalysed[$feedid] = $dao;
$rowsetAnalysed[$feed_id] = $dao;
unset($dao);
}
}
}

$this->Component->Sortdao->field='date';
$this->Component->Sortdao->order='asc';
usort($rowsetAnalysed, array($this->Component->Sortdao,'sortByDate'));
Expand All @@ -109,14 +148,14 @@ function addCommunity($feed,$community)

$feedid = $feed->getFeedId();
$communityid = $community->getCommunityId();
$column = 'community_'.$communityid;
$column = 'feed_'.$feedid;

$dataarray = array();
$dataarray[$column] = date('c');
$column_family = new ColumnFamily($this->database->getDB(),'feed');
$column_family->insert($feedid,$dataarray);

$dataarray[$column] = array(); // supercolumn to be filled out when we set the policies
$dataarray[$column]['na'] = 'na';

$column_family = new ColumnFamily($this->database->getDB(),'communityfeed');
$column_family->insert($communityid,$dataarray);
} // end addCommunity


Expand Down
27 changes: 26 additions & 1 deletion core/models/cassandra/FeedpolicygroupModel.php
Expand Up @@ -26,7 +26,12 @@ public function getPolicy($group, $feed)

$column = 'feed_'.$feedid;
$feedarray = $this->database->getCassandra('groupfeedpolicy',$groupid,array($column));


if(empty($feedarray))
{
return null;
}

// Massage the data to the proper format
$newarray['feed_id'] = $feedid;
$newarray['group_id'] = $groupid;
Expand Down Expand Up @@ -65,6 +70,20 @@ public function save($dao)

$column_family = new ColumnFamily($this->database->getDB(),'userfeed');
$column_family->insert($groupid,$dataarray);

// Add the policy to the CommunityFeed if we have a community
if(isset($dao->community) && $dao->community)
{
$column = 'feed_'.$feedid;
$dataarray = array();
$dataarray[$column] = array();
$dataarray[$column]['group_'.$groupid] = $dao->getPolicy();

$column_family = new ColumnFamily($this->database->getDB(),'communityfeed');
$column_family->insert($dao->community->getCommunityId(),$dataarray);
}


}
catch(Exception $e)
{
Expand All @@ -78,6 +97,12 @@ public function save($dao)
/** Custome delete command */
public function delete($dao)
{
// No DAO passed we just return
if($dao == null)
{
return false;
}

$instance=ucfirst($this->_name)."Dao";
if(get_class($dao) != $instance)
{
Expand Down
13 changes: 12 additions & 1 deletion core/models/cassandra/FeedpolicyuserModel.php
Expand Up @@ -26,7 +26,12 @@ public function getPolicy($user, $feed)

$column = 'feed_'.$feedid;
$feedarray = $this->database->getCassandra('userfeedpolicy',$userid,array($column));


if(empty($feedarray))
{
return null;
}

// Massage the data to the proper format
$newarray['feed_id'] = $feedid;
$newarray['user_id'] = $userid;
Expand Down Expand Up @@ -79,6 +84,12 @@ public function save($dao)
/** Custome delete command */
public function delete($dao)
{
// No DAO passed we just return
if($dao == null)
{
return false;
}

$instance=ucfirst($this->_name)."Dao";
if(get_class($dao) != $instance)
{
Expand Down
13 changes: 12 additions & 1 deletion core/models/cassandra/FolderpolicygroupModel.php
Expand Up @@ -25,7 +25,12 @@ public function getPolicy($group, $folder)

$column = 'group_'.$groupid;
$folderarray = $this->database->getCassandra('folder',$folderid,array($column));


if(empty($folderarray))
{
return null;
}

// Massage the data to the proper format
$newarray['folder_id'] = $folderid;
$newarray['group_id'] = $groupid;
Expand Down Expand Up @@ -67,6 +72,12 @@ public function save($dao)
/** Custome delete command */
public function delete($dao)
{
// No DAO passed we just return
if($dao == null)
{
return false;
}

$instance=ucfirst($this->_name)."Dao";
if(get_class($dao) != $instance)
{
Expand Down
11 changes: 11 additions & 0 deletions core/models/cassandra/FolderpolicyuserModel.php
Expand Up @@ -28,6 +28,11 @@ public function getPolicy($user, $folder)
$column = 'user_'.$userid;
$folderarray = $this->database->getCassandra('folder',$folderid,array($column));

if(empty($folderarray))
{
return null;
}

// Massage the data to the proper format
$newarray['folder_id'] = $folderid;
$newarray['user_id'] = $userid;
Expand Down Expand Up @@ -69,6 +74,12 @@ public function save($dao)
/** Custome delete command */
public function delete($dao)
{
// No DAO passed we just return
if($dao == null)
{
return false;
}

$instance=ucfirst($this->_name)."Dao";
if(get_class($dao) != $instance)
{
Expand Down

0 comments on commit deb6160

Please sign in to comment.