Bitrix Site Manager

GetVoteDataByID

GetVoteDataByID( 
  int VOTE_ID, 
  array &arChannel, 
  array &arVote, 
  array &arQuestions, 
  array &arAnswers, 
  array &arDropDown, 
  array &arMultiSelect, 
  array &arGroupAnswers, 
  string getGroupAnswers
)

The function returns information describing the poll by its ID.

Parameters

ParameterDescription
VOTE_IDVote (poll) ID.
arChannel Array describing the channel of the poll. The array has the following keys.
  • ID - channel ID;
  • SYMBOLIC_NAME - symbolic name;
  • ACTIVE - active state flag ["Y"|"N"];
  • TITLE - name of the channel;
  • LID - site ID;
  • C_SORT - sort weight;
  • TIMESTAMP_X - modification date of the channel.
arVote Array describing the specified poll. The array has the following keys.
  • ID - poll ID;
  • CHANNEL_ID - poll channel ID;
  • C_SORT - sort weight;
  • ACTIVE - active state flag ["Y"|"N"];
  • TIMESTAMP_X - modification date of the poll;
  • DATE_START - starting date of the poll;
  • DATE_END - end date of the poll;
  • COUNTER - number of votings made in this poll; 
  • TITLE - name of the poll;
  • DESCRIPTION - poll description;
  • DESCRIPTION_TYPE - type of poll description ["html"|"text"]
  • IMAGE_ID - image ID;
  • EVENT1 - event type identifier "event1";
  • EVENT2 - event type identifier "event2";
  • EVENT3 - auxiliary event type identifier "event3";
  • UNIQUE_TYPE - voter uniqueness: 0 - unrestricted; 1 - single voting within a session; 2 - single voting within a session or with a known cookie; 3 - single voting within a session or with a known cookie or from an IP address;
  • KEEP_IP_SEC - number of seconds during which a visitor is disallowed to vote again from the same IP address;
  • TEMPLATE - template used to display the poll form;
  • RESULT_TEMPLATE - template used to display the poll results;
  • QUESTIONS - number of questions;
  • LAMP - flag: "red" means the poll is inactive or outdated; "green" - the poll is active and its date is within the poll date bounds.
arQuestions Array of arrays each describing a single question. The arrays has the following keys.
  • ID - question ID;
  • ACTIVE - active state flag ["Y"|"N"];
  • C_SORT - sort weight;
  • QUESTION - text of the question;
  • QUESTION_TYPE - type of the text ["html"|"text"]
  • IMAGE_ID - image ID;
  • DIAGRAM - denotes the question is to be included in the results diagram ["Y"|"N"];
  • TEMPLATE - template used to display the question result;
  • TIMESTAMP_X - modification date.
arAnswers Arrays of answers. Each key of the array is a question ID. Each value is a list of arrays each describing a single answer. Each array has the following keys.
  • ID - answer ID;
  • ACTIVE - active state flag ["Y"|"N"]
  • TIMESTAMP_X - modification date;
  • QUESTION_ID - question ID;
  • C_SORT - sort weight;
  • MESSAGE - text displayed both beside the answer control in the poll form and in the diagram;
  • COUNTER - counts how many times this answer has been selected;
  • FIELD_TYPE - control type: 0 - radio, 1 - checkbox, 2 - dropdown list; 3 - multiselect list, 4 - text; 5 - textarea;
  • FIELD_WIDTH - control width;
  • FIELD_HEIGHT - control height;
  • FIELD_PARAM - additional control attributes (style, class);
  • COLOR - color of the diagram element (e.g. #FFOOCC).
arDropDown Array describing all controls of the type "2" (drop-down list). Keys are the question ID's. Values are arrays with the following keys:
  • REFERENCE - option text;
  • REFERENCE_ID - option ID.
arMultiSelect Array describing all controls of the type "3" (multiselect list). Keys are the question ID's. Values are arrays with the following keys:
  • REFERENCE - option text;
  • REFERENCE_ID - option ID.
arGroupAnswers Array describing variants of answer of all controls of the type "4" (text) and "5" (textarea). Keys are the question ID's. Values are arrays with the following keys:
  • MESSAGE - answer text;
  • COUNTER - number of answers.
getGroupAnswers Specifies whether the array arGroupAnswers is to be returned. If set to "Y", the function GetVoteDataByID returns this array. If "N", this array is not returned.

Return Values

The function GetVoteDataByID returns the string with the poll ID. If the passed poll ID is correct, the ID value is non-zero.

Example

The following example displays a form with the required poll according to the user permissions.

<?
function ShowVote($VOTE_ID, $template1="")
{
    global $MESS, $VOTING_LAMP, $VOTING_OK, $USER_ALREADY_VOTE;
    global $USER_GROUP_PERMISSION, $VOTE_USER_ID, $VOTE_PERMISSION;
    $VOTE_ID = GetVoteDataByID($VOTE_ID, 
                               $arChannel, $arVote, $arQuestions, 
                               $arAnswers, $arDropDown, $arMultiSelect, 
                               $arGroupAnswers, "N");
    if (intval($VOTE_ID)>0)
    {
        $perm = CVoteChannel::GetGroupPermission($arChannel["ID"]);
        if (intval($perm) >= 2)
        {
            $template = (strlen($arVote["TEMPLATE"])<=0) ? 
                            "default.php" : $arVote["TEMPLATE"];
            $VOTE_PERMISSION = CVote::UserGroupPermission($arChannel["ID"]);
            require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/vote/include.php");
            @include_once(
                GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/lang/", 
                                "/".$template));
            $path = COption::GetOptionString("vote", 
                                             "VOTE_TEMPLATE_PATH", 
                                             "/bitrix/php_interface/include/vote/show/");
            if (strlen($template1)>0) $template = $template1;
            @include($_SERVER["DOCUMENT_ROOT"].$path.$template);
        }
    }
}
?>

The following example obtains the poll information.

<?
$VOTE_ID = GetVoteDataByID($PUBLIC_VOTE_ID, 
                           $arChannel, 
                           $arVote, 
                           $arQuestions, 
                           $arAnswers, 
                           $arDropDown, 
                           $arMultiSelect, 
                           $arGroupAnswers, "N", 
                           $template, $res_template);
$VOTE_ID = intval($VOTE_ID);
// if the poll ID is valid...
if ($VOTE_ID>0 && $arVote["LAMP"]=="green")
{
    ...
}
?>