Skip to content

Commit

Permalink
New feature #10177: have a checkbox on Survey settings to to enforce …
Browse files Browse the repository at this point in the history
…or not checking quota

Dev: adding management of unused active attribute. Set to 1 by default
  • Loading branch information
Shnoulle committed May 8, 2016
1 parent 722b2d8 commit 7b9f2c3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 57 deletions.
2 changes: 2 additions & 0 deletions application/controllers/admin/quotas.php
Expand Up @@ -223,6 +223,7 @@ function insertquota($iSurveyId)
$oQuota->qlimit = Yii::app()->request->getPost('quota_limit');
$oQuota->action = Yii::app()->request->getPost('quota_action');
$oQuota->autoload_url = Yii::app()->request->getPost('autoload_url');
$oQuota->active = Yii::app()->request->getPost('active');
$oQuota->save();
$iQuotaId = $oQuota->id;

Expand Down Expand Up @@ -278,6 +279,7 @@ function modifyquota($iSurveyId)
$oQuota->qlimit = Yii::app()->request->getPost('quota_limit');
$oQuota->action = Yii::app()->request->getPost('quota_action');
$oQuota->autoload_url = Yii::app()->request->getPost('autoload_url');
$oQuota->active = Yii::app()->request->getPost('active');
$oQuota->save();

//Iterate through each language posted, and make sure there is a quota message for it
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/frontend_helper.php
Expand Up @@ -1982,6 +1982,8 @@ function checkCompletedQuota($surveyid,$return=false)
$aPostedFields = explode("|",Yii::app()->request->getPost('fieldnames','')); // Needed for quota allowing update
foreach ($aQuotasInfo as $aQuotaInfo)
{
if(!$aQuotaInfo['active'])
continue;
if(count($aQuotaInfo['members'])===0)
continue;
$iMatchedAnswers=0;
Expand Down
108 changes: 56 additions & 52 deletions application/models/Quota.php
Expand Up @@ -10,60 +10,64 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* Files Purpose: lots of common functions
* Files Purpose: lots of common functions
*/

class Quota extends LSActiveRecord
{
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param string $class
* @return CActiveRecord
*/
public static function model($class = __CLASS__)
{
return parent::model($class);
}

/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{quota}}';
}
/* Default attributes */
public $active=1;

/**
* Returns the primary key of this table
*
* @access public
* @return string
*/
public function primaryKey()
{
return 'id';
}
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param string $class
* @return CActiveRecord
*/
public static function model($class = __CLASS__)
{
return parent::model($class);
}

/**
* Returns the relations
*
* @access public
* @return array
*/
public function relations()
{
$alias = $this->getTableAlias();
return array(
'languagesettings' => array(self::HAS_MANY, 'QuotaLanguageSetting', '',
'on' => "$alias.id = languagesettings.quotals_quota_id"),
);
}
/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{quota}}';
}

/**
* Returns the primary key of this table
*
* @access public
* @return string
*/
public function primaryKey()
{
return 'id';
}

/**
* Returns the relations
*
* @access public
* @return array
*/
public function relations()
{
$alias = $this->getTableAlias();
return array(
'languagesettings' => array(self::HAS_MANY, 'QuotaLanguageSetting', '',
'on' => "$alias.id = languagesettings.quotals_quota_id"),
);
}

/**
* Returns this model's validation rules
Expand All @@ -72,11 +76,11 @@ public function relations()
public function rules()
{
return array(
array('name','LSYii_Validators'),// Maybe more restrictive
array('qlimit', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'allowEmpty'=>true),
array('name','LSYii_Validators'),// Maybe more restrictive
array('qlimit', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'allowEmpty'=>true),
array('action', 'numerical', 'integerOnly'=>true, 'min'=>'1', 'max'=>'2', 'allowEmpty'=>true), // Default is null ?
array('active', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true),
array('autoload_url', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true),
array('active', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true),
array('autoload_url', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true),
);
}

Expand All @@ -96,7 +100,7 @@ function insertRecords($data)
return false;
}
}

function deleteQuota($condition = false, $recursive = true)
{
if ($recursive == true)
Expand Down
19 changes: 15 additions & 4 deletions application/views/admin/quotas/editquota_view.php
@@ -1,6 +1,6 @@
<div class='side-body <?php echo getSideBodyClass(false); ?>'>
<div class='col-lg-8'>
<div class="row">
<div class="row">
<div class="col-lg-12 content-right">
<h3>
<?php eT("Edit quota");?>
Expand Down Expand Up @@ -41,7 +41,18 @@
?>
</div>
</div>

<div class='form-group'>
<label class='control-label col-sm-2' for='active'><?php eT("Active:");?></label>
<div class='col-sm-5'>
<?php $this->widget('yiiwheels.widgets.switch.WhSwitch', array(
'name' => 'active',
'id'=>'active',
'value' => $quotainfo['active'],
'onLabel'=>gT('Yes'),
'offLabel' => gT('No')));
?>
</div>
</div>
<!-- Language tabs -->
<ul class="nav nav-tabs">
<?php foreach ($langs as $lang): ?>
Expand All @@ -57,11 +68,11 @@
<?php foreach ($aTabContents as $i => $sTabContent)
{
echo CHtml::tag(
'div',
'div',
array(
'id' => 'edittxtele' . $i,
'class' => 'tab-pane fade in' . ($i == $baselang ? ' active ' : ''),
),
),
$sTabContent
);
}?>
Expand Down
13 changes: 12 additions & 1 deletion application/views/admin/quotas/newquota_view.php
Expand Up @@ -46,7 +46,18 @@
?>
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="active"><?php eT("Active:");?></label>
<div class="col-sm-10">
<?php $this->widget('yiiwheels.widgets.switch.WhSwitch', array(
'name' => 'active',
'id'=>'active',
'value' => 1,
'onLabel'=>gT('Yes'),
'offLabel' => gT('No')));
?>
</div>
</div>
<!--
<div class="form-group">
<div class="col-sm-10">
Expand Down

2 comments on commit 7b9f2c3

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? I cannot remember that we agreed on such a feature?

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? We already have active since a long time in Quota table. There are 2 and more Feature Request on mantis for this. Since a long time ago.
Actually : i just have a little fix to set "active" to 1 in DB. But i don't found a way to have active to 0 in old version.

PS : with 2.50 : if you set manually 0 to active columns : you see "Not active" : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/views/admin/quotas/viewquotasrow_view.php#L8 but this don't change something in code.

Please sign in to comment.