LimesurveyApi
in package
Class exposing a Limesurvey API to plugins.
This class is instantiated by the plugin manager, plugins can obtain it by calling getAPI() on the plugin manager.
Table of Contents
Methods
- addUserGroup() : bool
- Adds a new user group
- addUserInGroup() : bool
- Adds a user to a user group
- checkAccess() : bool
- createTable() : int|false
- Builds and executes a SQL statement for creating a new DB table.
- createUrl() : mixed
- dropTable() : mixed
- Builds and executes a SQL statement for dropping a DB table.
- EMevaluateExpression() : string
- Evaluates an expression via ExpressionScript Engine Uses the current context.
- getConfigKey() : string
- Read a key from the application config, and when not set return the default value
- getCurrentResponses() : Response|null
- Get the current Response
- getCurrentSurveyid() : false|int
- Get the current survey in current oage
- getCurrentUser() : User|null|false
- Retrieves user details for the currently logged in user
- getFormattedDateTime() : string
- Get a formatted date time by a string Used to return date from date input in admin
- getGroupList() : array<string|int, QuestionGroup>
- Gets a key value list using the group name as value and the group id as key.
- getOldResponseTables() : array<string|int, string>
- Gets an array of old response table names for a survey.
- getParticipant() : Participant|null
- Retrieves Participant data
- getPermissionSet() : array<string|int, mixed>|null
- Retrieves user permission details for a user
- getQuestionAttributes() : array<string, mixed>
- Returns an array of all the question attributes and their values for the specified question.
- getQuestions() : array<string|int, Question>
- getRequest() : LSHttpRequest
- Get the current request object
- getResponse() : array<string|int, mixed>|SurveyDynamic|null
- Gets a survey response from the database.
- getResponses() : array<string|int, Response>|null
- getResponseTable() : string
- Gets the table name for responses for the specified survey ID.
- getTable() : Plugin|null
- Gets an activerecord object associated to the table.
- getTableSchema() : CDbTableSchema
- Gets the metadata for a table.
- getTemplateList() : array<string|int, mixed>|string
- Returns an array of all available template names - does a basic check if the template might be valid
- getToken() : Token|null
- getTokenById() : Token|null
- Return a token object from a token id and a survey ID
- getUser() : User|null
- Retrieves user details for a user Returns null if the user does not exist anymore for some reason (should not really happen)
- getUserByEmail() : User|null
- Get the user object for a given email
- getUserByName() : User|null
- Get the user object for a given username
- getUserGroup() : UserGroup|null
- Returns a UserGroup object by ugid Returns null if the object does not exist
- getUserGroups() : array<string|int, mixed>
- Returns an array of all user groups
- getUserInGroup() : UserInGroup|null
- Returns a UserInGroup object Returns null if the object does not exist
- newModel() : PluginDynamic|null
- Creates a new active record object instance.
- pluginExists() : bool
- Returns true if a plugin exists with name $name (active or not)
- pluginIsActive() : bool
- Returns true if plugin with name $name is active; otherwise false
- removeResponse() : mixed
- removeUserInGroup() : bool
- Removes a user from a user group
- renderTwig() : string
- setFlash() : void
- Sets a flash message to be shown to the user.
- tableExists() : bool
- Check if a table does exist in the database
- getTableName() : mixed
- Generates the real table name from plugin and tablename.
Methods
addUserGroup()
Adds a new user group
public
addUserGroup(string $groupName, string $groupDescription) : bool
Parameters
- $groupName : string
-
Name of user group to be created
- $groupDescription : string
-
Description of user group to be created
Tags
Return values
bool —True or false if user group was added or not
addUserInGroup()
Adds a user to a user group
public
addUserInGroup(int $ugid, int $uid) : bool
Parameters
- $ugid : int
-
The user group ID
- $uid : int
-
The user ID
Tags
Return values
bool —True if user was added to group or false if not
checkAccess()
public
checkAccess(string $operation[, array<string|int, mixed> $params = array() ][, bool $allowCaching = true ]) : bool
Parameters
- $operation : string
- $params : array<string|int, mixed> = array()
- $allowCaching : bool = true
Tags
Return values
boolcreateTable()
Builds and executes a SQL statement for creating a new DB table.
public
createTable(PluginBase $plugin, string $sTableName, array<string|int, mixed> $aColumns[, string|null $sOptions = null ]) : int|false
Parameters
- $plugin : PluginBase
-
The plugin object, id or name.
- $sTableName : string
-
the name of the table to be created. The name will be properly quoted and prefixed by the method.
- $aColumns : array<string|int, mixed>
-
the columns (name=>definition) in the new table.
- $sOptions : string|null = null
-
additional SQL fragment that will be appended to the generated SQL.
Return values
int|false —number of rows affected by the execution.
createUrl()
public
createUrl(mixed $route, array<string|int, mixed> $params) : mixed
Parameters
- $route : mixed
- $params : array<string|int, mixed>
dropTable()
Builds and executes a SQL statement for dropping a DB table.
public
dropTable(mixed $plugin, string $sTableName) : mixed
Parameters
- $plugin : mixed
-
The plugin object, id or name.
- $sTableName : string
-
the name of the table to be created. The name will be properly quoted and prefixed by the method.
EMevaluateExpression()
Evaluates an expression via ExpressionScript Engine Uses the current context.
public
EMevaluateExpression(string $expression) : string
Parameters
- $expression : string
Return values
stringgetConfigKey()
Read a key from the application config, and when not set return the default value
public
getConfigKey(string $key[, mixed $defaultValue = false ]) : string
Parameters
- $key : string
-
The key to search for in the application config
- $defaultValue : mixed = false
-
Value to return when not found, default is false
Return values
stringgetCurrentResponses()
Get the current Response
public
getCurrentResponses([int $surveyId = null ]) : Response|null
Parameters
- $surveyId : int = null
Return values
Response|nullgetCurrentSurveyid()
Get the current survey in current oage
public
getCurrentSurveyid([bool $onlyactivated = false ]) : false|int
Parameters
- $onlyactivated : bool = false
-
return it only if activated
Return values
false|intgetCurrentUser()
Retrieves user details for the currently logged in user
public
getCurrentUser() : User|null|false
Return values
User|null|false —Returns false if the user is not logged and returns null if the user does not exist anymore for some reason (should not really happen)
getFormattedDateTime()
Get a formatted date time by a string Used to return date from date input in admin
public
static getFormattedDateTime(string $dateValue, string $returnFormat[, int|null $currentFormat = null ]) : string
Parameters
- $dateValue : string
-
the string as date value
- $returnFormat : string
-
the final date format
- $currentFormat : int|null = null
-
the current format of dateValue, defaut from App()->session['dateformat'] @see getDateFormatData function (in surveytranslator_helper)
Return values
stringgetGroupList()
Gets a key value list using the group name as value and the group id as key.
public
getGroupList(int $surveyId) : array<string|int, QuestionGroup>
Parameters
- $surveyId : int
Return values
array<string|int, QuestionGroup>getOldResponseTables()
Gets an array of old response table names for a survey.
public
getOldResponseTables(int $surveyId) : array<string|int, string>
Parameters
- $surveyId : int
Return values
array<string|int, string>getParticipant()
Retrieves Participant data
public
getParticipant(int $iParticipantID) : Participant|null
Parameters
- $iParticipantID : int
-
The Participant ID
Return values
Participant|null —Returns null if the user does not exist anymore for some reason (should not really happen)
getPermissionSet()
Retrieves user permission details for a user
public
getPermissionSet(int $iUserID[, mixed $iEntityID = null ][, string|null $sEntityName = null ]) : array<string|int, mixed>|null
Parameters
- $iUserID : int
-
The User ID
- $iEntityID : mixed = null
- $sEntityName : string|null = null
Return values
array<string|int, mixed>|null —Returns null if the user does not exist anymore for some reason (should not really happen)
getQuestionAttributes()
Returns an array of all the question attributes and their values for the specified question.
public
getQuestionAttributes(int $questionId[, string|null $language = null ]) : array<string, mixed>
Parameters
- $questionId : int
-
the ID of the question
- $language : string|null = null
-
restrict to this language
Tags
Return values
array<string, mixed> —array of question attributes and values (name=>value)
getQuestions()
public
getQuestions(int $surveyId[, string $language = 'en' ][, array<string|int, mixed> $conditions = array() ]) : array<string|int, Question>
Parameters
- $surveyId : int
- $language : string = 'en'
- $conditions : array<string|int, mixed> = array()
Return values
array<string|int, Question>getRequest()
Get the current request object
public
getRequest() : LSHttpRequest
Return values
LSHttpRequestgetResponse()
Gets a survey response from the database.
public
getResponse(int $surveyId, int $responseId[, bool $bMapQuestionCodes = true ]) : array<string|int, mixed>|SurveyDynamic|null
Parameters
- $surveyId : int
- $responseId : int
- $bMapQuestionCodes : bool = true
Return values
array<string|int, mixed>|SurveyDynamic|nullgetResponses()
public
getResponses(mixed $surveyId[, mixed $attributes = array() ][, mixed $condition = '' ][, mixed $params = array() ]) : array<string|int, Response>|null
Parameters
- $surveyId : mixed
- $attributes : mixed = array()
- $condition : mixed = ''
- $params : mixed = array()
Return values
array<string|int, Response>|nullgetResponseTable()
Gets the table name for responses for the specified survey ID.
public
getResponseTable(int $surveyId) : string
Parameters
- $surveyId : int
Return values
stringgetTable()
Gets an activerecord object associated to the table.
public
getTable(iPlugin $plugin, string $sTableName[, bool|null $bPluginTable = true ]) : Plugin|null
Parameters
- $plugin : iPlugin
- $sTableName : string
-
Name of the table.
- $bPluginTable : bool|null = true
-
True if the table is plugin specific.
Return values
Plugin|nullgetTableSchema()
Gets the metadata for a table.
public
getTableSchema(string $table[, bool $forceRefresh = false ]) : CDbTableSchema
For details on the object check: http://www.yiiframework.com/doc/api/1.1/CDbTableSchema
Parameters
- $table : string
-
Table name.
- $forceRefresh : bool = false
-
False if cached information is acceptable; setting this to true could affect performance.
Return values
CDbTableSchema —Table schema object, NULL if the table does not exist.
getTemplateList()
Returns an array of all available template names - does a basic check if the template might be valid
public
getTemplateList() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|stringgetToken()
public
getToken(mixed $surveyId, mixed $token) : Token|null
Parameters
- $surveyId : mixed
- $token : mixed
Return values
Token|nullgetTokenById()
Return a token object from a token id and a survey ID
public
getTokenById(int $iSurveyId, int $iTokenId) : Token|null
Parameters
- $iSurveyId : int
- $iTokenId : int
Return values
Token|null —Token
getUser()
Retrieves user details for a user Returns null if the user does not exist anymore for some reason (should not really happen)
public
getUser(int $iUserID) : User|null
Parameters
- $iUserID : int
-
The userid
Return values
User|nullgetUserByEmail()
Get the user object for a given email
public
getUserByEmail(string|null $email) : User|null
Parameters
- $email : string|null
Return values
User|null —Returns the user, or null when not found
getUserByName()
Get the user object for a given username
public
getUserByName(string $username) : User|null
Parameters
- $username : string
Return values
User|null —Returns the user, or null when not found
getUserGroup()
Returns a UserGroup object by ugid Returns null if the object does not exist
public
getUserGroup(int $ugid) : UserGroup|null
Parameters
- $ugid : int
-
The user group ID
Return values
UserGroup|nullgetUserGroups()
Returns an array of all user groups
public
getUserGroups() : array<string|int, mixed>
Return values
array<string|int, mixed>getUserInGroup()
Returns a UserInGroup object Returns null if the object does not exist
public
getUserInGroup(int $ugid, int $uid) : UserInGroup|null
Parameters
- $ugid : int
-
The user group ID
- $uid : int
-
The user ID
Return values
UserInGroup|nullnewModel()
Creates a new active record object instance.
public
newModel(iPlugin $plugin, string $sTableName[, string|null $scenario = 'insert' ][, bool|null $bPluginTable = true ]) : PluginDynamic|null
Parameters
- $plugin : iPlugin
- $sTableName : string
- $scenario : string|null = 'insert'
- $bPluginTable : bool|null = true
-
True if the table is plugin specific.
Return values
PluginDynamic|nullpluginExists()
Returns true if a plugin exists with name $name (active or not)
public
pluginExists(string $name) : bool
Parameters
- $name : string
-
Name of plugin
Tags
Return values
boolpluginIsActive()
Returns true if plugin with name $name is active; otherwise false
public
pluginIsActive(string $name) : bool
Parameters
- $name : string
-
Name of plugin
Tags
Return values
boolremoveResponse()
public
removeResponse(mixed $surveyId, mixed $responseId) : mixed
Parameters
- $surveyId : mixed
- $responseId : mixed
removeUserInGroup()
Removes a user from a user group
public
removeUserInGroup(int $ugid, int $uid) : bool
Parameters
- $ugid : int
-
The user group ID
- $uid : int
-
The user ID
Tags
Return values
bool —True if user was removed to group or false if not
renderTwig()
public
renderTwig(string $file, array<string|int, mixed> $data) : string
Parameters
- $file : string
- $data : array<string|int, mixed>
Return values
stringsetFlash()
Sets a flash message to be shown to the user.
public
setFlash(string $message[, string $key = 'api' ]) : void
Parameters
- $message : string
- $key : string = 'api'
tableExists()
Check if a table does exist in the database
public
tableExists(iPlugin $plugin, string $sTableName) : bool
Parameters
- $plugin : iPlugin
- $sTableName : string
-
Table name to check for (without dbprefix!))
Return values
bool —True or false if table exists or not
getTableName()
Generates the real table name from plugin and tablename.
protected
getTableName(iPlugin $plugin, string $tableName) : mixed
Parameters
- $plugin : iPlugin
- $tableName : string