Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature #09816: Using quotas to prevent new entries #365

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions application/controllers/admin/quotas.php
Expand Up @@ -126,18 +126,26 @@ function index($iSurveyId, $quickreport = false)
$aData['completed'] = $completed;
$aData['totalquotas'] = $totalquotas;
$aData['totalcompleted'] = $totalcompleted;
$aResults2 = QuotaMember::model()->findAllByAttributes(array('quota_id' => $aQuotaListing['id']));
$aData['totalquestion'] = count($aResults2);
$aViewUrls['output'] .= $this->getController()->renderPartial("/admin/quotas/viewquotasrow_view", $aData, true);

//check how many sub-elements exist for a certain quota
$aResults2 = QuotaMember::model()->findAllByAttributes(array('quota_id' => $aQuotaListing['id']));

//loop through all sub-parts
foreach ($aResults2 as $aQuotaQuestions)
if(count($aResults2)==0)
{
$aViewUrls['output'] .= $this->getController()->renderPartial('/admin/quotas/viewemptyquotasrowsub_view', $aData, true);
}
else
{
$aQuestionAnswers = self::getQuotaAnswers($aQuotaQuestions['qid'], $iSurveyId, $aQuotaListing['id']);
$aData['question_answers'] = $aQuestionAnswers;
$aData['quota_questions'] = $aQuotaQuestions;
$aViewUrls['output'] .= $this->getController()->renderPartial('/admin/quotas/viewquotasrowsub_view', $aData, true);
//loop through all sub-parts
foreach ($aResults2 as $aQuotaQuestions)
{
$aQuestionAnswers = self::getQuotaAnswers($aQuotaQuestions['qid'], $iSurveyId, $aQuotaListing['id']);
$aData['question_answers'] = $aQuestionAnswers;
$aData['quota_questions'] = $aQuotaQuestions;
$aViewUrls['output'] .= $this->getController()->renderPartial('/admin/quotas/viewquotasrowsub_view', $aData, true);
}
}
}
}
Expand Down Expand Up @@ -182,6 +190,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',0);
$oQuota->save();
$iQuotaId = $oQuota->id;

Expand Down Expand Up @@ -236,6 +245,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',0);
$oQuota->save();

//Iterate through each language posted, and make sure there is a quota message for it
Expand Down Expand Up @@ -265,9 +275,9 @@ function modifyquota($iSurveyId)

$oQuotaLanguageSettings = QuotaLanguageSetting::model()->findByAttributes(array('quotals_quota_id' => Yii::app()->request->getPost('quota_id'), 'quotals_language' => $sLang));
$oQuotaLanguageSettings->quotals_name = Yii::app()->request->getPost('quota_name');
$oQuotaLanguageSettings->quotals_message = $_POST['quotals_message_' . $sLang];
$oQuotaLanguageSettings->quotals_url = $_POST['quotals_url_' . $sLang];
$oQuotaLanguageSettings->quotals_urldescrip = $_POST['quotals_urldescrip_' . $sLang];
$oQuotaLanguageSettings->quotals_message = Yii::app()->request->getPost('quotals_message_' . $sLang);
$oQuotaLanguageSettings->quotals_url = Yii::app()->request->getPost('quotals_url_' . $sLang);
$oQuotaLanguageSettings->quotals_urldescrip = Yii::app()->request->getPost('quotals_urldescrip_' . $sLang);
$oQuotaLanguageSettings->save();
}
} //End insert language based components
Expand Down
3 changes: 1 addition & 2 deletions application/helpers/common_helper.php
Expand Up @@ -5423,8 +5423,7 @@ function getQuotaCompletedCount($iSurveyId, $quotaid)
$aColumnName=SurveyDynamic::model($iSurveyId)->getTableSchema()->getColumnNames();
$aQuotas = getQuotaInformation($iSurveyId, Survey::model()->findByPk($iSurveyId)->language, $quotaid);
$aQuota = $aQuotas[0];
if (Yii::app()->db->schema->getTable('{{survey_' . $iSurveyId . '}}') &&
count($aQuota['members']) > 0)
if (Yii::app()->db->schema->getTable('{{survey_' . $iSurveyId . '}}') )
{
// Keep a list of fields for easy reference
$aQuotaColumns = array();
Expand Down
3 changes: 2 additions & 1 deletion application/helpers/frontend_helper.php
Expand Up @@ -1926,8 +1926,9 @@ function checkCompletedQuota($surveyid,$return=false)
$aPostedFields = explode("|",Yii::app()->request->getPost('fieldnames','')); // Needed for quota allowing update
foreach ($aQuotasInfo as $aQuotaInfo)
{
if(count($aQuotaInfo['members'])===0)
if(!$aQuotaInfo['active']) // Maybe add || ($aQuotaInfo['qlimit'] == 0 && count($aQuotaInfo['members'])==0) : this is a broken quota or not ?
continue;

$iMatchedAnswers=0;
$bPostedField=false;
// Array of field with quota array value
Expand Down
1 change: 1 addition & 0 deletions application/views/admin/quotas/editquota_view.php
Expand Up @@ -8,6 +8,7 @@
<option value ="2" <?php if($quotainfo['action'] == 2) echo "selected='selected'"; ?>><?php eT("Terminate survey with warning");?></option>
</select></li>
<li><label for='autoload_url'><?php eT("Autoload URL:");?></label><input id="autoload_url" name="autoload_url" type="checkbox" value="1"<?php if($quotainfo['autoload_url'] == "1") {echo " checked";}?> /></li>
<li><label for='active'><?php eT("Active:");?></label><input id="active" name="active" type="checkbox" value="1"<?php if($quotainfo['active']) {echo " checked";}?> /></li>
</ul>
<div id="tabs">
<ul>
Expand Down
4 changes: 4 additions & 0 deletions application/views/admin/quotas/newquota_view.php
Expand Up @@ -20,6 +20,10 @@
<label for="autoload_url"><?php eT("Autoload URL");?>:</label>
<input id="autoload_url" name="autoload_url" type="checkbox" value="1" />
</li>
<li>
<label for="active"><?php eT("Active");?>:</label>
<input id="active" name="active" type="checkbox" value="1" checked/>
</li>
</ul>
<div id="tabs"><ul>
<?php foreach ($langs as $lang) { ?>
Expand Down
5 changes: 5 additions & 0 deletions application/views/admin/quotas/viewemptyquotasrowsub_view.php
@@ -0,0 +1,5 @@
<tr class="warning">
<td colspan=6>
<?php echo gt("You didn't add any questions to this quota. Thus, the system will just compare all completed responses with the max value you have set"); ?>
</td>
</tr>
43 changes: 22 additions & 21 deletions application/views/admin/quotas/viewquotasrow_view.php
Expand Up @@ -7,9 +7,9 @@
<td>
<?php if ($quotalisting['active'] == 1)
{
echo '<font color="#48B150">'.gT("Active").'</font>';
echo '<span class="success">'.gT("Active").'</span>';
} else {
echo '<font color="#B73838">'.gT("Not Active").'</font>';
echo '<span class="warning">'.gT("Not Active").'</span>';
}
?>
</td>
Expand Down Expand Up @@ -45,22 +45,23 @@
echo CHtml::link(gT("Validate"),array('admin/validate','sa'=>'quota','sid'=>$surveyid,'quota'=>$quotalisting['id']),array('class'=>'btn btn-link','title'=>sprintf(gT("Validation of quota %s"),$quotalisting['name']),"target"=>"dialog"));
} ?>
</td></tr>

<tr class="evenrow">
<td>&nbsp;</td>
<td><strong><?php eT("Questions");?></strong></td>
<td><strong><?php eT("Answers");?></strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td style="padding: 3px;">
<?php if (Permission::model()->hasSurveyPermission($iSurveyId, 'quotas','update')) { ?>
<?php echo CHtml::form(array("admin/quotas/sa/new_answer/surveyid/{$iSurveyId}"), 'post'); ?>
<input name="submit" type="submit" class="quota_new" value="<?php eT("Add answer");?>" />
<input type="hidden" name="sid" value="<?php echo $iSurveyId;?>" />
<input type="hidden" name="action" value="quotas" />
<input type="hidden" name="quota_id" value="<?php echo $quotalisting['id'];?>" />
<input type="hidden" name="subaction" value="new_answer" />
</form>
<?php } ?>
</td>
</tr>
<?php if ($totalquestion > 0 ) { ?>
<tr class="evenrow">
<td>&nbsp;</td>
<td><strong><?php eT("Questions");?></strong></td>
<td><strong><?php eT("Answers");?></strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td style="padding: 3px;">
<?php if (Permission::model()->hasSurveyPermission($iSurveyId, 'quotas','update')) { ?>
<?php echo CHtml::form(array("admin/quotas/sa/new_answer/surveyid/{$iSurveyId}"), 'post'); ?>
<input name="submit" type="submit" class="quota_new" value="<?php eT("Add answer");?>" />
<input type="hidden" name="sid" value="<?php echo $iSurveyId;?>" />
<input type="hidden" name="action" value="quotas" />
<input type="hidden" name="quota_id" value="<?php echo $quotalisting['id'];?>" />
<input type="hidden" name="subaction" value="new_answer" />
</form>
<?php } ?>
</td>
</tr>
<?php } ?>