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

Commit ad3e421

Browse files
author
Charles Marion
committed
ENH: Added stats and policy management in the browser
1 parent ec2e1c4 commit ad3e421

File tree

10 files changed

+178
-60
lines changed

10 files changed

+178
-60
lines changed

application/Bootstrap.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ protected function _initConfig()
4343
// InitDatabase
4444
$configDatabase = new Zend_Config_Ini(DATABASE_CONFIG, $configGlobal->environment);
4545
if ($configDatabase->database->type == 'pdo')
46-
{
46+
{
47+
$pdoParams = array(
48+
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
49+
);
4750
$params= array(
4851
'host' => $configDatabase->database->params->host,
4952
'username' => $configDatabase->database->params->username,
5053
'password' => $configDatabase->database->params->password,
5154
'dbname' => $configDatabase->database->params->dbname,
55+
'driver_options' => $pdoParams
5256
);
5357
if($configGlobal->environment=="production")
5458
{

application/controllers/BrowseController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function getfolderscontentAction()
7474
$tmp['folder_id']=$folder->getFolderId();
7575
$tmp['name']=$folder->getName();
7676
$tmp['creation']=$this->Component->Date->ago($folder->getDate(),true);
77+
$tmp['policy']=$folder->policy;
7778
$jsonContent[$folder->getParentId()]['folders'][]=$tmp;
7879
unset($tmp);
7980
}
@@ -86,6 +87,7 @@ public function getfolderscontentAction()
8687
$itemRevision=$this->Item->getLastRevision($item);
8788
$tmp['creation']=$this->Component->Date->ago($itemRevision->getDate(),true);
8889
$tmp['size']=$this->Component->Utility->formatSize($item->getSizebytes());
90+
$tmp['policy']=$item->policy;
8991
$jsonContent[$item->parent_id]['items'][]=$tmp;
9092
unset($tmp);
9193
}

application/controllers/FeedController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
class FeedController extends AppController
77
{
8-
public $_models=array('Feed','Item');
8+
public $_models=array('Feed','Item','User','Community');
99
public $_daos=array();
1010
public $_components=array();
1111

@@ -20,6 +20,10 @@ public function indexAction()
2020
{
2121
$this->view->feeds=$this->Feed->getGlobalFeeds($this->userSession->Dao);
2222
$this->view->itemThumbnails=$this->Item->getRandomItems($this->userSession->Dao,0,12,true);
23+
$this->view->nUsers=$this->User->getCountAll();
24+
$this->view->nCommunities=$this->Community->getCountAll();
25+
$this->view->nItems=$this->Item->getCountAll();
26+
$this->view->notifications=array();
2327
}
2428

2529
/** get getfolders Items' size */

application/controllers/components/SortDaoComponent.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,29 @@ public function sortByDate($a,$b)
2626
{
2727
return ($a_t > $b_t ) ? 1 : -1;
2828
}
29-
}
29+
}//end sortByDate
3030

31+
/** sort by name*/
32+
public function sortByName($a,$b)
33+
{
34+
if($this->field==''||!isset($a->{$this->field}))
35+
{
36+
throw new Zend_Exception("Error field.");
37+
}
38+
$a_n = strtolower($a->{$this->field}) ;
39+
$b_n = strtolower($b->{$this->field}) ;
40+
41+
if( $a_n == $b_n )
42+
return 0 ;
43+
44+
if($this->order=='asc')
45+
{
46+
return ($a_n < $b_n) ? -1 : 1;
47+
}
48+
else
49+
{
50+
return ($a_n < $b_n ) ? 1 : -1;
51+
}
52+
}//end sortByDate
3153
} // end class
3254
?>

application/models/AppModelPdo.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
class AppModelPdo extends MIDAS_GlobalModelPdo
88
{
99

10+
11+
/** return the number row in the table
12+
*
13+
* @return int
14+
*/
15+
public function getCountAll()
16+
{
17+
$count = $this->fetchRow( $this->select()->from($this->_name, 'count(*) as COUNT' ));
18+
return $count['COUNT'];
19+
}//end getCountAll
1020
}//end class
1121

1222
?>

application/models/pdo/FolderModel.php

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FolderModel extends AppModelPdo
88
public $_name = 'folder';
99
public $_key = 'folder_id';
1010

11-
11+
public $_components = array('Sortdao');
1212

1313
public $_mainData= array(
1414
'folder_id'=> array('type'=>MIDAS_DATA),
@@ -388,8 +388,10 @@ function getItemsFiltered($folder,$userDao=null,$policy=0)
388388

389389
$subqueryUser= $this->select()
390390
->setIntegrityCheck(false)
391-
->from(array('p' => 'itempolicyuser'),
392-
array('item_id'))
391+
->from(array('f' => 'item'))
392+
->join(array('p' => 'itempolicyuser'),
393+
'f.item_id=p.item_id',
394+
array('p.policy'))
393395
->join(array('i' => 'item2folder'),
394396
$this->_db->quoteInto('i.folder_id IN (?)',$folderIds).'
395397
AND i.item_id = p.item_id' ,array('i.folder_id'))
@@ -398,14 +400,16 @@ function getItemsFiltered($folder,$userDao=null,$policy=0)
398400

399401
$subqueryGroup = $this->select()
400402
->setIntegrityCheck(false)
401-
->from(array('p' => 'itempolicygroup'),
402-
array('item_id'))
403+
->from(array('f' => 'item'))
404+
->join(array('p' => 'itempolicygroup'),
405+
'f.item_id=p.item_id',
406+
array('p.policy'))
403407
->join(array('i' => 'item2folder'),
404408
$this->_db->quoteInto('i.folder_id IN (?)',$folderIds).'
405409
AND i.item_id = p.item_id' ,array('i.folder_id'))
406410
->where('policy >= ?', $policy)
407-
->where('( '.$this->_db->quoteInto('group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR
408-
group_id IN (' .new Zend_Db_Expr(
411+
->where('( '.$this->_db->quoteInto('p.group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR
412+
p.group_id IN (' .new Zend_Db_Expr(
409413
$this->select()
410414
->setIntegrityCheck(false)
411415
->from(array('u2g' => 'user2group'),
@@ -415,22 +419,37 @@ function getItemsFiltered($folder,$userDao=null,$policy=0)
415419

416420
$sql = $this->select()
417421
->union(array($subqueryUser, $subqueryGroup));
422+
418423
$rowset = $this->fetchAll($sql);
419424
$items = array();
420425
$parents = array();
421-
foreach ($rowset as $row)
426+
foreach ($rowset as $keyRow=>$row)
422427
{
423-
$items[]=$row->item_id;
424-
$parents[$row->item_id]=$row->folder_id;
425-
}
426-
$this->ModelLoader = new MIDAS_ModelLoader();
427-
$model = $this->ModelLoader->loadModel('Item');
428-
$itemsDao=$model->load($items);
429-
foreach($itemsDao as $k => $v)
430-
{
431-
$itemsDao[$k]->parent_id=$parents[$v->getItemId()];
432-
}
433-
return $itemsDao;
428+
foreach($items as $keyIt=>$It)
429+
{
430+
if($It->getKey()==$row['item_id'])
431+
{
432+
if($It->policy<$row['policy'])
433+
{
434+
$items[$keyIt]->policy=$row['policy'];
435+
}
436+
unset($row);
437+
break;
438+
}
439+
}
440+
if(isset($row))
441+
{
442+
$tmpDao= $this->initDao('Item', $row);
443+
$tmpDao->policy=$row['policy'];
444+
$tmpDao->parent_id=$row['folder_id'];
445+
$items[] = $tmpDao;
446+
unset($tmpDao);
447+
}
448+
}
449+
$this->Component->Sortdao->field='name';
450+
$this->Component->Sortdao->order='asc';
451+
usort($items, array($this->Component->Sortdao,'sortByName'));
452+
return $items;
434453
}
435454

436455
/** getFolder with policy check */
@@ -556,21 +575,21 @@ function getChildrenFoldersFiltered($folder,$userDao=null,$policy=0)
556575

557576
$subqueryUser= $this->select()
558577
->setIntegrityCheck(false)
559-
->from(array('p' => 'folderpolicyuser'),
560-
array('folder_id'))
561-
->join(array('f' => 'folder'),
562-
$this->_db->quoteInto('f.parent_id IN (?)',$folderIds)
563-
.' AND p.folder_id = f.folder_id' ,array())
578+
->from(array('f' => 'folder'))
579+
->join(array('p' => 'folderpolicyuser'),
580+
'f.folder_id=p.folder_id',
581+
array('p.policy'))
582+
->where ('f.parent_id IN (?)',$folderIds)
564583
->where('policy >= ?', $policy)
565584
->where('user_id = ? ',$userId);
566585

567586
$subqueryGroup = $this->select()
568587
->setIntegrityCheck(false)
569-
->from(array('p' => 'folderpolicygroup'),
570-
array('folder_id'))
571-
->join(array('f' => 'folder'),
572-
$this->_db->quoteInto('f.parent_id IN (?)',$folderIds)
573-
.' AND p.folder_id = f.folder_id' ,array())
588+
->from(array('f' => 'folder'))
589+
->join(array('p' => 'folderpolicygroup'),
590+
'f.folder_id=p.folder_id',
591+
array('p.policy'))
592+
->where ('f.parent_id IN (?)',$folderIds)
574593
->where('policy >= ?', $policy)
575594
->where('( '.$this->_db->quoteInto('group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR
576595
group_id IN (' .new Zend_Db_Expr(
@@ -581,10 +600,8 @@ function getChildrenFoldersFiltered($folder,$userDao=null,$policy=0)
581600
->where('u2g.user_id = ?' , $userId)
582601
.'))' ));
583602
$sql = $this->select()
584-
->setIntegrityCheck(false)
585-
->from('folder')
586-
->where('folder_id IN ('.$subqueryUser.')' )
587-
->orWhere('folder_id IN ('.$subqueryGroup.')' );
603+
->union(array($subqueryUser, $subqueryGroup));
604+
588605
$rowset = $this->fetchAll($sql);
589606
$return = array();
590607
foreach ($rowset as $row)
@@ -593,7 +610,34 @@ function getChildrenFoldersFiltered($folder,$userDao=null,$policy=0)
593610
$return[] = $tmpDao;
594611
unset($tmpDao);
595612
}
596-
return $return;
613+
614+
$folders = array();
615+
foreach ($rowset as $keyRow=>$row)
616+
{
617+
foreach($folders as $keyIt=>$It)
618+
{
619+
if($It->getKey()==$row['folder_id'])
620+
{
621+
if($It->policy<$row['policy'])
622+
{
623+
$folders[$keyIt]->policy=$row['policy'];
624+
}
625+
unset($row);
626+
break;
627+
}
628+
}
629+
if(isset($row))
630+
{
631+
$tmpDao= $this->initDao('Folder', $row);
632+
$tmpDao->policy=$row['policy'];
633+
$folders[] = $tmpDao;
634+
unset($tmpDao);
635+
}
636+
}
637+
$this->Component->Sortdao->field='name';
638+
$this->Component->Sortdao->order='asc';
639+
usort($folders, array($this->Component->Sortdao,'sortByName'));
640+
return $folders;
597641
}
598642

599643
/** Get the child folder

application/models/pdo/UserModel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class UserModel extends AppModelPdo
3030

3131
);
3232

33+
34+
3335
/** Get user communities */
3436
public function getUserCommunities($userDao)
3537
{

application/views/feed/index.phtml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88
<?php echo $this->element('feed')?>
99
</div>
1010
<div class="viewSideBar">
11-
<div class="sideElementFirst feedNotification">
12-
<h1>Notifications</h1>
13-
</div>
14-
<div class="sideElement feedPub">
15-
<h1>Pub</h1>
16-
</div>
11+
12+
BlaBla
13+
<br/>
14+
<?php
15+
if(!empty($this->notifications))
16+
{
17+
echo "<div class='sideElementFirst feedNotification'>
18+
<h1>Notifications</h1>
19+
</div>";
20+
}
21+
?>
1722
<?php
1823
if(!empty($this->itemThumbnails))
1924
{
20-
echo '<div class="sideElement feedThumbnail">';
25+
echo '<div class="'.(empty($this->notifications)?'sideElementFirst':'sideElement').' feedThumbnail">';
2126
echo '<h1>Thumbnails</h1>';
2227
foreach($this->itemThumbnails as $item)
2328
{
@@ -30,6 +35,13 @@
3035
?>
3136
<div class="sideElementLast feedStats">
3237
<h1>Stats</h1>
38+
<?php
39+
echo "<ul>";
40+
echo " <li>{$this->nUsers} user".(($this->nUsers>1)?'s':'')."</li>";
41+
echo " <li>{$this->nCommunities} ".(($this->nCommunities>1)?'communities':'community')."</li>";
42+
echo " <li>{$this->nItems} item".(($this->nItems>1)?'s':'')."</li>";
43+
echo "</ul>";
44+
?>
3345
</div>
3446
</div>
3547

public/js/common/common.browser.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,54 @@
3939
{
4040
var type=node.attr('type');
4141
var element=node.attr('element');
42+
var policy=node.attr('policy');
4243
$('div.viewAction ul').fadeOut('fast',function()
4344
{
4445
$('div.viewAction ul').html('');
4546
var html='';
4647
if(type=='community')
4748
{
4849
html+='<li><a href="'+json.global.webroot+'/community/'+element+'">'+json.browse.view+'</a></li>';
49-
html+='<li><a>'+json.browse.edit+'</a></li>';
50-
html+='<li><a>'+json.browse.community.invit+'</a></li>';
51-
html+='<li><a>'+json.browse.community.advanced+'</a></li>';
50+
if(policy==2)
51+
{
52+
html+='<li><a>'+json.browse.edit+'</a></li>';
53+
}
54+
if(policy>=1)
55+
{
56+
html+='<li><a>'+json.browse.community.invit+'</a></li>';
57+
html+='<li><a>'+json.browse.community.advanced+'</a></li>';
58+
}
5259
}
5360
if(type=='folder')
5461
{
5562
html+='<li><a href="'+json.global.webroot+'/folder/'+element+'">'+json.browse.view+'</a></li>';
5663
html+='<li><a href="'+json.global.webroot+'/download?folders='+element+'">'+json.browse.download+'</a></li>';
57-
html+='<li><a>'+json.browse.edit+'</a></li>';
58-
html+='<li><a>'+json.browse['delete']+'</a></li>';
59-
html+='<li><a>'+json.browse.move+'</a></li>';
60-
html+='<li><a>'+json.browse.copy+'</a></li>';
61-
html+='<li><a>'+json.browse.share+'</a></li>';
64+
if(policy==2)
65+
{
66+
html+='<li><a>'+json.browse.edit+'</a></li>';
67+
html+='<li><a>'+json.browse['delete']+'</a></li>';
68+
html+='<li><a>'+json.browse.move+'</a></li>';
69+
html+='<li><a>'+json.browse.copy+'</a></li>';
70+
}
71+
if(policy>=1)
72+
{
73+
html+='<li><a>'+json.browse.share+'</a></li>';
74+
}
6275
}
6376
if(type=='item')
6477
{
6578
html+='<li><a href="'+json.global.webroot+'/item/'+element+'">'+json.browse.view+'</a></li>';
66-
html+='<li><a href="'+json.global.webroot+'/download?items='+element+'">'+json.browse.download+'</a></li>';
67-
html+='<li><a>'+json.browse.edit+'</a></li>';
68-
html+='<li><a>'+json.browse['delete']+'</a></li>';
69-
html+='<li><a>'+json.browse.move+'</a></li>';
70-
html+='<li><a>'+json.browse.copy+'</a></li>';
71-
html+='<li><a>'+json.browse.share+'</a></li>';
79+
if(policy==2)
80+
{
81+
html+='<li><a>'+json.browse.edit+'</a></li>';
82+
html+='<li><a>'+json.browse['delete']+'</a></li>';
83+
html+='<li><a>'+json.browse.move+'</a></li>';
84+
html+='<li><a>'+json.browse.copy+'</a></li>';
85+
}
86+
if(policy>=1)
87+
{
88+
html+='<li><a>'+json.browse.share+'</a></li>';
89+
}
7290
}
7391
$('div.viewAction ul').html(html);
7492
$('div.viewAction ul').fadeIn('fast');

0 commit comments

Comments
 (0)