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

Commit da4e2d1

Browse files
author
Julien Jomier
committed
ENH: More fixes for Cassandra
1 parent c8fa411 commit da4e2d1

17 files changed

+254
-49
lines changed

core/controllers/CommunityController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init()
1212
{
1313
$this->view->activemenu = 'community'; // set the active menu
1414
$actionName=Zend_Controller_Front::getInstance()->getRequest()->getActionName();
15-
if(isset($actionName) && is_numeric($actionName))
15+
if(isset($actionName) && (is_numeric($actionName) || strlen($actionName)==32)) // This is tricky! and for Cassandra for now
1616
{
1717
$this->_forward('view',null,null,array('communityId'=>$actionName));
1818
}
@@ -42,7 +42,7 @@ function viewAction()
4242
$this->view->Date=$this->Component->Date;
4343
//TODO: add policy check
4444
$communityId=$this->_getParam("communityId");
45-
if(!isset($communityId)||!is_numeric($communityId))
45+
if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId)!=32)) // This is tricky! and for Cassandra for now
4646
{
4747
throw new Zend_Exception("Community ID should be a number");
4848
}

core/controllers/FeedController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function deleteajaxAction()
3939
$this->_helper->viewRenderer->setNoRender();
4040

4141
$feedId=$this->_getParam('feed');
42-
if(!isset($feedId)||!is_numeric($feedId))
42+
if(!isset($feedId) || (!is_numeric($feedId) && strlen($feedId)!=32)) // This is tricky! and for Cassandra for now)
4343
{
44-
throw new Zend_Exception("Please set the folder Id");
44+
throw new Zend_Exception("Please set the feed Id");
4545
}
4646
$feed= $this->Feed->load($feedId);
4747
if($feed==false)

core/controllers/FolderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init()
1212
{
1313
$this->view->activemenu = ''; // set the active menu
1414
$actionName=Zend_Controller_Front::getInstance()->getRequest()->getActionName();
15-
if(isset($actionName) && is_numeric($actionName))
15+
if(isset($actionName) && (is_numeric($actionName) || strlen($actionName)==32)) // This is tricky! and for Cassandra for now
1616
{
1717
$this->_forward('view',null,null,array('folderId'=>$actionName));
1818
}

core/controllers/ItemController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init()
1212
{
1313
$this->view->activemenu = ''; // set the active menu
1414
$actionName=Zend_Controller_Front::getInstance()->getRequest()->getActionName();
15-
if(isset($actionName) && is_numeric($actionName))
15+
if(isset($actionName)&& (is_numeric($actionName) || strlen($actionName)==32)) // This is tricky! and for Cassandra for now
1616
{
1717
$this->_forward('view',null,null,array('itemId'=>$actionName));
1818
}

core/models/base/FeedModelBase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public function __construct()
2222
} // end __construct()
2323

2424
protected abstract function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$policy=0,$limit=20);
25-
25+
protected abstract function addCommunity($feed,$community);
26+
27+
2628
/** get feeds (filtered by policies)
2729
* @return Array of FeedDao */
2830
function getGlobalFeeds($loggedUserDao,$policy=0,$limit=20)

core/models/base/FolderModelBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function __construct()
3030
abstract function getChildrenFoldersFiltered($folder,$userDao=null,$policy=0);
3131
abstract function getItemsFiltered($folder,$userDao=null,$policy=0);
3232
abstract function getSizeFiltered($folders,$userDao=null,$policy=0);
33+
abstract function getCommunity($folder);
34+
abstract function getUser($folder);
3335

3436
/** Create a folder */
3537
function createFolder($name,$description,$parent)

core/models/cassandra/CommunityModel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ function getPublicCommunities($limit=20)
2525
"", // end
2626
$limit // row count
2727
);
28+
2829
foreach($allcommunities as $key => $com)
2930
{
30-
if($com['privacy'] == MIDAS_COMMUNITY_PRIVATE)
31-
{
31+
if($com['privacy'] != MIDAS_COMMUNITY_PRIVATE)
32+
{
33+
$com[$this->_key] = $key;
3234
$communities[] = $this->initDao('Community', $com);
3335
}
3436
}

core/models/cassandra/FeedModel.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,118 @@
77
*/
88
class FeedModel extends FeedModelBase
99
{
10+
1011
protected function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$policy=0,$limit=20)
1112
{
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;
1295
}
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);
13119

120+
} // end addCommunity
121+
122+
14123
} // end class
15124
?>

core/models/cassandra/FeedpolicygroupModel.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public function getPolicy($group, $feed)
2020
{
2121
throw new Zend_Exception("Should be a feed.");
2222
}
23-
23+
2424
$feedid = $feed->getKey();
2525
$groupid = $group->getKey();
2626

27-
$column = 'group_'.$groupid;
28-
$feedarray = $this->database->getCassandra('feed',$feedid,array($column));
29-
27+
$column = 'feed_'.$feedid;
28+
$feedarray = $this->database->getCassandra('groupfeedpolicy',$groupid,array($column));
29+
3030
// Massage the data to the proper format
3131
$newarray['feed_id'] = $feedid;
3232
$newarray['group_id'] = $groupid;
@@ -48,13 +48,23 @@ public function save($dao)
4848
{
4949
$feedid = $dao->getFeedId();
5050
$groupid = $dao->getGroupId();
51-
$column = 'group_'.$groupid;
52-
51+
52+
// Add the feed to the UserFeedPolicy
53+
$column = 'feed_'.$feedid;
5354
$dataarray = array();
5455
$dataarray[$column] = $dao->getPolicy();
5556

56-
$column_family = new ColumnFamily($this->database->getDB(),'feed');
57-
$column_family->insert($feedid,$dataarray);
57+
$column_family = new ColumnFamily($this->database->getDB(),'groupfeedpolicy');
58+
$column_family->insert($groupid,$dataarray);
59+
60+
// Add the feed to the UserFeed (this is a super column)
61+
$column = 'feed_'.$feedid;
62+
$dataarray = array();
63+
$dataarray[$column] = array();
64+
$dataarray[$column]['group_'.$groupid] = $dao->getPolicy();
65+
66+
$column_family = new ColumnFamily($this->database->getDB(),'userfeed');
67+
$column_family->insert($groupid,$dataarray);
5868
}
5969
catch(Exception $e)
6070
{
@@ -80,12 +90,17 @@ public function delete($dao)
8090

8191
try
8292
{
83-
// Remove the column group from the feed
93+
// Remove the column user from the feed
8494
$feedid = $dao->getFeedId();
8595
$groupid = $dao->getGroupId();
86-
$column = 'group_'.$groupid;
87-
$cf = new ColumnFamily($this->database->getDB(),'feed');
88-
$cf->remove($feedid,array($column));
96+
$column = 'feed_'.$feedid;
97+
$cf = new ColumnFamily($this->database->getDB(),'groupfeedpolicy');
98+
$cf->remove($groupid,array($column));
99+
100+
// Remove from the UserFeed also
101+
$column = 'feed_'.$feedid; // super column
102+
$cf = new ColumnFamily($this->database->getDB(),'userfeed');
103+
$cf->remove($groupid,array('group_'.$groupid),$column);
89104
}
90105
catch(Exception $e)
91106
{

core/models/cassandra/FeedpolicyuserModel.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public function getPolicy($user, $feed)
2020
{
2121
throw new Zend_Exception("Should be a feed.");
2222
}
23-
23+
2424
$feedid = $feed->getKey();
2525
$userid = $user->getKey();
2626

27-
$column = 'user_'.$userid;
28-
$feedarray = $this->database->getCassandra('feed',$feedid,array($column));
27+
$column = 'feed_'.$feedid;
28+
$feedarray = $this->database->getCassandra('userfeedpolicy',$userid,array($column));
2929

3030
// Massage the data to the proper format
3131
$newarray['feed_id'] = $feedid;
@@ -49,13 +49,23 @@ public function save($dao)
4949
{
5050
$feedid = $dao->getFeedId();
5151
$userid = $dao->getUserId();
52-
$column = 'user_'.$userid;
53-
52+
53+
// Add the feed to the UserFeedPolicy
54+
$column = 'feed_'.$feedid;
5455
$dataarray = array();
5556
$dataarray[$column] = $dao->getPolicy();
5657

57-
$column_family = new ColumnFamily($this->database->getDB(),'feed');
58-
$column_family->insert($feedid,$dataarray);
58+
$column_family = new ColumnFamily($this->database->getDB(),'userfeedpolicy');
59+
$column_family->insert($userid,$dataarray);
60+
61+
// Add the feed to the UserFeed (this is a super column)
62+
$column = 'feed_'.$feedid;
63+
$dataarray = array();
64+
$dataarray[$column] = array();
65+
$dataarray[$column]['user_'.$userid] = $dao->getPolicy();
66+
67+
$column_family = new ColumnFamily($this->database->getDB(),'userfeed');
68+
$column_family->insert($userid,$dataarray);
5969
}
6070
catch(Exception $e)
6171
{
@@ -84,9 +94,14 @@ public function delete($dao)
8494
// Remove the column user from the feed
8595
$feedid = $dao->getFeedId();
8696
$userid = $dao->getUserId();
87-
$column = 'user_'.$userid;
88-
$cf = new ColumnFamily($this->database->getDB(),'feed');
89-
$cf->remove($feedid,array($column));
97+
$column = 'feed_'.$feedid;
98+
$cf = new ColumnFamily($this->database->getDB(),'userfeedpolicy');
99+
$cf->remove($userid,array($column));
100+
101+
// Remove from the UserFeed also
102+
$column = 'feed_'.$feedid; // super column
103+
$cf = new ColumnFamily($this->database->getDB(),'userfeed');
104+
$cf->remove($userid,array('user_'.$userid),$column);
90105
}
91106
catch(Exception $e)
92107
{

0 commit comments

Comments
 (0)