Skip to content

Commit

Permalink
Dev: User administration Pagination based on select
Browse files Browse the repository at this point in the history
  • Loading branch information
markusfluer committed Aug 12, 2016
1 parent 047efc9 commit 52c317e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
35 changes: 8 additions & 27 deletions application/controllers/admin/useraction.php
Expand Up @@ -56,42 +56,23 @@ public function index()
App()->getClientScript()->registerPackage('jquery-tablesorter');
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'users.js');


$userlist = getUserList();
$usrhimself = $userlist[0];
unset($userlist[0]);

$aData = array();

if (Permission::model()->hasGlobalPermission('superadmin','read')) {
$noofsurveys = Survey::model()->countByAttributes(array("owner_id" => $usrhimself['uid']));
$aData['noofsurveys'] = $noofsurveys;
}
$aData['row'] = 0;
if (isset($usrhimself['parent_id']) && $usrhimself['parent_id'] != 0)
// Page size
if (!empty(Yii::app()->request->getParam('pageSize')))
{
$aData['row'] = User::model()->findByAttributes(array('uid' => $usrhimself['parent_id']))->users_name;
Yii::app()->user->setState('pageSize',(int)Yii::app()->request->getParam('pageSize'));
}


$aData['usrhimself'] = $usrhimself;
// other users
$aData['usr_arr'] = $userlist;
$noofsurveyslist = array();

//This loops through for each user and checks the amount of surveys against them.
$limit = count($userlist);
for ($i = 1; $i <= $limit; $i++)
else
{
$noofsurveyslist[$i] = $this->_getSurveyCountForUser($userlist[$i]);
Yii::app()->user->setState('pageSize',(int)Yii::app()->params['defaultPageSize']);
}

$aData['noofsurveyslist'] = $noofsurveyslist;
$aData['pageSize']= Yii::app()->user->getState('pageSize');

$aData['title_bar']['title'] = gT('User administration');
$aData['fullpagebar']['closebutton']['url'] = true;
$model = new User();
$this->_renderWrappedTemplate('user', 'editusers',array('model'=>$model));
$aData['model']=$model;
$this->_renderWrappedTemplate('user', 'editusers', $aData);
}

private function _getSurveyCountForUser(array $user)
Expand Down
4 changes: 2 additions & 2 deletions application/models/User.php
Expand Up @@ -472,7 +472,7 @@ public function getColums(){
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$pageSize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
$criteria=new CDbCriteria;

// $criteria->compare('uid',$this->uid);
Expand All @@ -492,7 +492,7 @@ public function search()
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize' => 20
'pageSize' => $pageSize
)
));
}
Expand Down
25 changes: 21 additions & 4 deletions application/views/admin/user/editusers.php
Expand Up @@ -14,10 +14,27 @@
'itemsCssClass' => 'table table-striped items',
'dataProvider' => $model->search(),
'columns' => $model->colums,
'afterAjaxUpdate' => 'bindButtons'
));
?>
</div>
'afterAjaxUpdate' => 'bindButtons',
'summaryText' => gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
CHtml::dropDownList(
'pageSize',
$pageSize,
Yii::app()->params['pageSizeOptions'],
array('class'=>'changePageSize form-control', 'style'=>'display: inline; width: auto'))
),
));

?>
</div>

<!-- To update rows per page via ajax -->
<script type="text/javascript">
jQuery(function($) {
jQuery(document).on("change", '#pageSize', function(){
$.fn.yiiGridView.update('all_users',{ data:{ pageSize: $(this).val() }});
});
});
</script>
</div>
</div>
<div id='adduser-modal' class="modal fade " tabindex="-1" role="dialog">
Expand Down

0 comments on commit 52c317e

Please sign in to comment.