Skip to content

Commit

Permalink
Fixed issue #18696: Survey titles too short when I want to copy a sur…
Browse files Browse the repository at this point in the history
…vey (#3012)

* Fixed issue #18696: Survey titles too short when I want to copy a survey
Dev: PHP part

* Dev: activate select2 on copysurvey
Dev: adding activate-search class to any select activate select2

* Dev: add package to adminbasics (already included by yiiwheel)
  • Loading branch information
Shnoulle committed Apr 21, 2023
1 parent 721b003 commit fb8d697
Show file tree
Hide file tree
Showing 11 changed files with 702 additions and 690 deletions.
1 change: 1 addition & 0 deletions application/config/packages.php
Expand Up @@ -319,6 +319,7 @@
),
'depends' => array(
'jquery',
'bootstrap-select2',
'pjaxbackend',
'lslog'
)
Expand Down
27 changes: 14 additions & 13 deletions application/helpers/common_helper.php
Expand Up @@ -97,7 +97,7 @@ function quoteText($sText, $sEscapeMode = 'html')
/**
* getSurveyList() Queries the database (survey table) for a list of existing surveys
*
* @param boolean $bReturnArray If set to true an array instead of an HTML option list is given back
* @param boolean $bReturnArray If set to true an array instead of an HTML option list is given back (unused by core)
* @return string|array This string is returned containing <option></option> formatted list of existing surveys
*
*/
Expand All @@ -110,10 +110,16 @@ function getSurveyList($bReturnArray = false)
$surveynames = array();

if (is_null($cached)) {
$criteria = new CDBCriteria();
$criteria->select = ['sid','language', 'active', 'expires','startdate'];
$criteria->with = ['languagesettings' => [
'select'=>'surveyls_title',
'where'=>'t.language = languagesettings.language'
]
];
$surveyidresult = Survey::model()
->permission(Yii::app()->user->getId())
->with('languagesettings')
->findAll();
->findAll($criteria);
foreach ($surveyidresult as $result) {
if (isset($result->languagesettings[$result->language])) {
$surveynames[] = array_merge(
Expand All @@ -122,9 +128,8 @@ function getSurveyList($bReturnArray = false)
);
}
}

usort($surveynames, function ($a, $b) {
return strcmp($a['surveyls_title'], $b['surveyls_title']);
return strcmp($a['surveyls_title'], $b['surveyls_title']);
});
$cached = $surveynames;
} else {
Expand All @@ -138,27 +143,23 @@ function getSurveyList($bReturnArray = false)
$inactivesurveys = '';
$expiredsurveys = '';
foreach ($surveynames as $sv) {
$surveylstitle = flattenText($sv['surveyls_title']);
if (strlen($surveylstitle) > 70) {
$surveylstitle = htmlspecialchars(mb_strcut(html_entity_decode($surveylstitle, ENT_QUOTES, 'UTF-8'), 0, 70, 'UTF-8')) . "...";
}

$surveylstitle = CHtml::encode($sv['surveyls_title']) . " [" . $sv['sid'] . "]";
if ($sv['active'] != 'Y') {
$inactivesurveys .= "<option ";
if (Yii::app()->user->getId() == $sv['owner_id']) {
$inactivesurveys .= " class='mysurvey emphasis'";
$inactivesurveys .= " class='mysurvey emphasis inactivesurvey'";
}
$inactivesurveys .= " value='{$sv['sid']}'>{$surveylstitle}</option>\n";
} elseif ($sv['expires'] != '' && $sv['expires'] < dateShift((string) date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)) {
$expiredsurveys .= "<option ";
if (Yii::app()->user->getId() == $sv['owner_id']) {
$expiredsurveys .= " class='mysurvey emphasis'";
$expiredsurveys .= " class='mysurvey emphasis expiredsurvey'";
}
$expiredsurveys .= " value='{$sv['sid']}'>{$surveylstitle}</option>\n";
} else {
$activesurveys .= "<option ";
if (Yii::app()->user->getId() == $sv['owner_id']) {
$activesurveys .= " class='mysurvey emphasis'";
$activesurveys .= " class='mysurvey emphasis activesurvey'";
}
$activesurveys .= " value='{$sv['sid']}'>{$surveylstitle}</option>\n";
}
Expand Down
2 changes: 1 addition & 1 deletion application/views/surveyAdministration/tabCopy_view.php
Expand Up @@ -14,7 +14,7 @@
<div class="form-group">
<label for='copysurveylist' class=" control-label"><?php eT("Select survey to copy:"); ?> </label>
<div class="">
<select id='copysurveylist' name='copysurveylist' required="required" class="form-control">
<select id='copysurveylist' name='copysurveylist' required="required" class="form-control activate-search">
<?php echo getSurveyList(false); ?>
</select>
</div>
Expand Down

0 comments on commit fb8d697

Please sign in to comment.