Skip to content

Commit

Permalink
Dev Added new formatter component.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Feb 25, 2015
1 parent 6550fd5 commit e7606f2
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 91 deletions.
24 changes: 24 additions & 0 deletions application/components/LocalizedFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
class LocalizedFormatter extends CLocalizedFormatter {

public function formatSurveyStatus($value) {
switch ($value) {
case 'active':
$icon = TbHtml::ICON_PLAY;
break;
case 'inactive':
$icon = TbHtml::ICON_STOP;
break;
case 'expired':
$icon = TbHtml::ICON_PAUSE;
break;

}
return TbHtml::icon($icon);
}

public function formatPercentage($factor) {
return number_format($factor * 100, 1) . '%';
}

}
3 changes: 3 additions & 0 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
'bootstrap' => [
'class' => 'TbApi',
],
'format' => [
'class' => 'LocalizedFormatter'
],
'clientScript'=> [
'class' => 'ext.ExtendedClientScript.ExtendedClientScript',
'combineCss' => false,
Expand Down
3 changes: 1 addition & 2 deletions application/controllers/SurveysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function actionOrganize($surveyId)

public function actionIndex() {
$this->layout = 'main';
$surveys = getSurveyList(true);
$this->render('index', ['surveys' => $surveys]);
$this->render('index', ['surveys' => new \CActiveDataProvider(Survey::model()->accessible())]);
}

public function actionPublicList()
Expand Down
30 changes: 24 additions & 6 deletions application/models/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,40 @@ public function __construct($scenario = 'insert') {
*/

public static function model($className = null) {
if (!isset($className))
{
if (!isset($className)) {
$className = get_called_class();
}
elseif (is_numeric($className))
{
} elseif (is_numeric($className)) {
$className = get_called_class() . '_' . $className;
}
if ($className == 'Response') {
throw new Exception('noo');
}
return parent::model($className);
}

public static function create($id, $scenario = 'insert')
public static function create($id, $scenario = 'insert')
{
$className = get_called_class() . '_' . $id;
return new $className($scenario);
}

/**
* This function checks if a table with the specified $id can be opened.
* @param int $id
* @return boolean Returns true if the table is found.
*/
public static function valid($id)
{
$result = false;
if (is_numeric($id)) {
try {
static::model($id);
} catch (\CDbException $e) {
$result = false;
}
}
return $result;
}

}

Expand Down
11 changes: 11 additions & 0 deletions application/models/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ public function relations()
return $result;
}

public function scopes() {
return [
'complete' => [
'condition' => 'submitdate IS NOT NULL',
],
'incomplete' => [
'condition' => 'submitdate IS NULL'
]
];
}
public function tableName()
{
return '{{survey_' . $this->dynamicId . '}}';
}

}

?>
62 changes: 57 additions & 5 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class Survey extends LSActiveRecord
/* Set some setting not by default database */
public $format = 'G';

public function attributeLabels() {
return [

'localizedTitle' => 'Title'
];
}
/**
* init to set default
*
Expand Down Expand Up @@ -155,13 +161,11 @@ public static function model($class = __CLASS__)
public function relations()
{
$alias = $this->getTableAlias();
return array(
return [
'languagesettings' => array(self::HAS_MANY, 'SurveyLanguageSetting', 'surveyls_survey_id', 'index' => 'surveyls_language'),
'defaultlanguage' => array(self::BELONGS_TO, 'SurveyLanguageSetting', array('language' => 'surveyls_language', 'sid' => 'surveyls_survey_id'), 'together' => true),
'owner' => array(self::BELONGS_TO, 'User', '', 'on' => "$alias.owner_id = owner.uid"),
'questionCount' => [self::STAT, 'Question', 'sid', 'select' => 'COUNT(DISTINCT qid)'],
'groupCount' => [self::STAT, 'QuestionGroup', 'sid', 'select' => 'COUNT(DISTINCT gid)']
);
];
}

/**
Expand Down Expand Up @@ -334,8 +338,24 @@ public function getAllLanguages()
array_unshift($sLanguages,$baselang);
return $sLanguages;
}


/**
* Returns the status for this survey.
* Possible values are:
* - inactive
* - active
* - expired
*/
public function getStatus() {
if (!$this->isActive) {
$result = 'inactive';
} elseif ($this->isExpired()) {
$result = 'expired';
} else {
$result = 'active';
}
return $result;
}
public function getIsActive() {
return $this->active != 'N';
}
Expand Down Expand Up @@ -645,4 +665,36 @@ public function getInfo($language = null) {

return $result;
}

/**
* Scope to remove surveys for which the current user doesn't have access.
*/
public function accessible()
{
if (!App()->user->checkAccess('superadmin')) {
$this->permission(Yii::app()->user->id);
}
return $this;
}

public function getCompletedResponseCount() {
return $this->isNewRecord || !Response::valid($this->sid) ? 0 : Response::model($this->sid)->complete()->count();
}

public function getPartialResponseCount() {
return $this->isNewRecord || !Response::valid($this->sid) ? 0 : Response::model($this->sid)->incomplete()->count();
}

public function getResponseCount() {
return $this->isNewRecord || !Response::valid($this->sid) ? 0 : Response::model($this->sid)->count();
}

/**
* Returns the response rate of the survey as a float.
* @todo We should decide how to define this, a good metric would be sent completed / invitation count
* @return float
*/
public function getResponseRate() {
return 0;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
107 changes: 29 additions & 78 deletions application/views/surveys/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,32 @@
if (empty($surveys)) {
return $this->renderPartial('firstSteps');
}
App()->clientScript->registerPackage('jqgrid');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "listsurvey.js");
?>
<script type='text/javascript'>
var getuserurl = '<?php echo $this->createUrl('admin/survey/sa/ajaxgetusers'); ?>';
var ownerediturl = '<?php echo $this->createUrl('admin/survey/sa/ajaxowneredit'); ?>';
var delmsg ='<?php eT("Are you sure you want to delete these surveys?",'js');?>';
var sWarningMsg = "<?php eT("Warning", 'js') ?>";
var sCaption ='<?php eT("Surveys",'js');?>';
var sSelectColumns ='<?php eT("Select columns",'js');?>';
var sRecordText = '<?php eT("View {0} - {1} of {2}",'js');?>';
var sPageText = '<?php eT("Page {0} of {1}",'js');?>';
var sSelectRowMsg = "<?php eT("Select at least one survey.", 'js') ?>";
var sLoadText = '<?php eT("Loading...",'js');?>';
var sDelTitle = '<?php eT("Delete selected survey(s)",'js');?>';
var sDelCaption = '<?php eT("Delete",'js');?>';
var sSearchCaption = '<?php eT("Filter...",'js');?>';
var sOperator1= '<?php eT("equal",'js');?>';
var sOperator2= '<?php eT("not equal",'js');?>';
var sOperator3= '<?php eT("less",'js');?>';
var sOperator4= '<?php eT("less or equal",'js');?>';
var sOperator5= '<?php eT("greater",'js');?>';
var sOperator6= '<?php eT("greater or equal",'js');?>';
var sOperator7= '<?php eT("begins with",'js');?>';
var sOperator8= '<?php eT("does not begin with",'js');?>';
var sOperator9= '<?php eT("is in",'js');?>';
var sOperator10= '<?php eT("is not in",'js');?>';
var sOperator11= '<?php eT("ends with",'js');?>';
var sOperator12= '<?php eT("does not end with",'js');?>';
var sOperator13= '<?php eT("contains",'js');?>';
var sOperator14= '<?php eT("does not contain",'js');?>';
var sOperator15= '<?php eT("is null",'js');?>';
var sOperator16= '<?php eT("is not null",'js');?>';
var sFind= '<?php eT("Filter",'js');?>';
var sReset= '<?php eT("Reset",'js');?>';
var sSelectColumns= '<?php eT("Select columns",'js');?>';
var sSubmit= '<?php eT("Save",'js');?>';

var sCancel = '<?php eT("Cancel",'js');?>';
var sSearchTitle ='<?php eT("Filter surveys",'js');?>';
var sRefreshTitle ='<?php eT("Reload survey list",'js');?>';
var delBtnCaption ='<?php eT("Save",'js');?>';
var sEmptyRecords ='<?php eT("There are currently no surveys.",'js');?>';
var sConfirmationExpireMessage='<?php eT("Are you sure you want to expire these surveys?",'js');?>';
var sConfirmationArchiveMessage='<?php eT("This function creates a ZIP archive of several survey archives and can take some time - please be patient! Do you want to continue?",'js');?>';
var jsonUrl = "<?php echo Yii::app()->getController()->createUrl('admin/survey/sa/getSurveys_json'); ?>";
var editUrl = "<?php echo $this->createUrl('admin/survey/sa/editSurvey_json'); ?>";
var colNames = ["<?php eT("Status") ?>","<?php eT("SID") ?>","<?php eT("Survey") ?>","<?php eT("Date created") ?>","<?php eT("Owner") ?>","<?php eT("Access") ?>","<?php eT("Anonymized responses") ?>","<?php eT("Full") ?>","<?php eT("Partial") ?>","<?php eT("Total") ?>","<?php eT("Tokens available") ?>","<?php eT("Response rate") ?>"];
var colModels = [{ "name":"status", "index":"status", "width":25, "align":"center", "sorttype":"string", "sortable": true, "editable":false},
{ "name":"sid", "index":"sid", "sorttype":"int", "sortable": true, "width":15, "align":"center", "editable":false},
{ "name":"survey", "index":"survey", "sorttype":stripLinkSort, "sortable": true, "width":100, "align":"left", "editable":true},
{ "name":"date_created", "index":"date_created", "sorttype":"string", "sortable": true,"width":25, "align":"center", "editable":false},
{ "name":"owner", "index":"owner","align":"center","width":40, "sorttype":"string", "sortable": true, "editable":true},
{ "name":"access", "index":"access","align":"center","width":25,"sorttype":"string", "sortable": true, "editable":true, "edittype":"checkbox", "editoptions":{ "value":"Y:N"}},
{ "name":"anonymous", "index":"anonymous","align":"center", "sorttype":"string", "sortable": true,"width":25,"editable":true, "edittype":"checkbox", "editoptions":{ "value":"Y:N"}},
{ "name":"full", "index":"full","align":"center", "sorttype":"int", "sortable": true,"width":25,"editable":false},
{ "name":"partial", "index":"partial","align":"center", "sorttype":"int", "sortable": true,"width":25,"editable":false},
{ "name":"total", "index":"total","align":"center", "sorttype":"int", "sortable": true,"width":25,"editable":false},
{ "name":"available", "index":"available","align":"center", "sorttype":"int", "sortable": true,"width":25,"editable":false},
{ "name":"rate", "index":"rate","align":"center", "sorttype":"int", "sortable": true,"width":25,"editable":false}];
function stripLinkSort(cell) {
var cellText = $(cell).text().toLowerCase();
return cellText;
}
</script>
<table id="displaysurveys"></table> <div id="pager"></div>
<select id='gs_status_select' style='display: none'>
<option value=''><?php eT("Any") ?></option>
<option value='--a--'><?php eT("Expired") ?></option>
<option value='--e--'><?php eT("Inactive") ?></option>
<option value='--c--'><?php eT("Active") ?></option>
</select>
<select id='gs_access_select' style='display: none'>
<option value=''><?php eT("Any") ?></option>
<option><?php eT("Open") ?></option>
<option><?php eT("Closed") ?></option>
</select>
<br />

echo $this->widget('TbGridView', [
'dataProvider' => $surveys,
'filter' => new Survey(),
'columns' => [
[
'name' => 'status',
'type' => 'surveyStatus',
'filter' => TbHtml::dropdownList('Survey[status]', '', [
'' => 'All',
'active' => 'Active',
'inactive' => 'Inactive',
'expired' => 'Expired'


])
],
'sid',
'localizedTitle',
'completedResponseCount',
'partialResponseCount',
'responseCount',
[
'name' => 'responseRate',
'type' => 'percentage'
]
]
]);
?>

0 comments on commit e7606f2

Please sign in to comment.