ocPortal Developer's Guide: OCF polls
» Return to Contents
sources/ocf_polls.php
Global_functions_ocf_polls.php
boolean ocf_may_edit_poll_by(AUTO_LINK forum_id, MEMBER poll_owner, ?MEMBER member_id)
Find whether a member can alter a poll owned by a certain member in a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The forum. |
| Type |
AUTO_LINK |
| Name |
poll_owner |
| Description |
The poll owner. |
| Type |
MEMBER |
| Name |
member_id |
| Description |
The member we are checking for (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_edit_poll_by($forum_id,$poll_owner,$member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if (has_specific_permission($member_id,'edit_midrange_content','topics',array('forums',$forum_id))) return true;
if ((has_specific_permission($member_id,'edit_own_polls','topics',array('forums',$forum_id))) && ($member_id==$poll_owner)) return true;
return false;
}
boolean ocf_may_attach_poll(AUTO_LINK topic_id, ?MEMBER topic_owner, ?boolean has_poll_already, ?MEMBER forum_id, ?MEMBER member_id)
Find whether a member may attach a poll to a detailed topic.
Parameters…
| Name |
topic_id |
| Description |
The topic. |
| Type |
AUTO_LINK |
| Name |
topic_owner |
| Description |
The topic owner (NULL: ask the DB for it). |
| Default value |
|
| Type |
?MEMBER |
| Name |
has_poll_already |
| Description |
Whether the topic already has a poll (NULL: ask the DB for it). |
| Default value |
|
| Type |
?boolean |
| Name |
forum_id |
| Description |
The forum the topic is in (NULL: ask the DB for it). |
| Default value |
|
| Type |
?MEMBER |
| Name |
member_id |
| Description |
The member we are checking for (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_attach_poll($topic_id,$topic_owner=NULL,$has_poll_already=NULL,$forum_id=NULL,$member_id=NULL)
{
if (is_null($topic_owner))
{
$topic_info=$GLOBALS['FORUM_DB']->query_select('f_topics',array('*'),array('id'=>$topic_id),'',1);
if (!array_key_exists(0,$topic_info)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$topic_owner=$topic_info[0]['t_cache_first_member_id'];
$has_poll_already=!is_null($topic_info[0]['t_poll_id']);
$forum_id=$topic_info[0]['t_forum_id'];
}
if (is_null($member_id)) $member_id=get_member();
if ($has_poll_already) return false;
if ($topic_owner==$member_id) return true;
if (ocf_may_moderate_forum($forum_id,$member_id)) return true;
return false;
}
boolean ocf_may_delete_poll_by(AUTO_LINK forum_id, MEMBER poll_owner, ?MEMBER member_id)
Find whether a member can delete a poll owned by a certain member in a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The forum. |
| Type |
AUTO_LINK |
| Name |
poll_owner |
| Description |
The poll owner. |
| Type |
MEMBER |
| Name |
member_id |
| Description |
The member we are checking for (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_delete_poll_by($forum_id,$poll_owner,$member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if (has_specific_permission($member_id,'delete_midrange_content','topics',array('forums',$forum_id))) return true;
if ((has_specific_permission($member_id,'delete_own_midrange_content','topics',array('forums',$forum_id))) && ($member_id==$poll_owner)) return true;
return false;
}
array ocf_poll_get_results(AUTO_LINK poll_id, boolean request_results)
Find a map of results relating to a certain poll.
Parameters…
| Name |
poll_id |
| Description |
The poll. |
| Type |
AUTO_LINK |
| Name |
request_results |
| Description |
Whether we must record that the current member is requesting the results, blocking future voting for them. |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The map of results. |
| Type |
array |
function ocf_poll_get_results($poll_id,$request_results=true)
{
$poll_info=$GLOBALS['FORUM_DB']->query_select('f_polls',array('*'),array('id'=>$poll_id),'',1);
if (!array_key_exists(0,$poll_info)) fatal_exit(do_lang_tempcode('_MISSING_RESOURCE','poll#'.strval($poll_id)));
$_answers=$GLOBALS['FORUM_DB']->query_select('f_poll_answers',array('*'),array('pa_poll_id'=>$poll_id),'ORDER BY id');
$answers=array();
foreach ($_answers as $_answer)
{
$answer=array();
$answer['answer']=$_answer['pa_answer'];
$answer['id']=$_answer['id'];
if ((($request_results) || ($poll_info[0]['po_is_open']==0)) && ($poll_info[0]['po_is_private']==0)) // We usually will show the results for a closed poll, but not one still private
$answer['num_votes']=$_answer['pa_cache_num_votes'];
$answers[]=$answer;
}
if ($request_results)
{
// Forfeighting this by viewing results?
$test=$GLOBALS['FORUM_DB']->query_value_null_ok('f_poll_votes','pv_answer_id',array('pv_poll_id'=>$poll_id,'pv_member_id'=>get_member()));
if (is_null($test))
{
$forfeight=!has_specific_permission(get_member(),'view_poll_results_before_voting');
if ($forfeight)
{
$GLOBALS['FORUM_DB']->query_insert('f_poll_votes',array(
'pv_poll_id'=>$poll_id,
'pv_member_id'=>get_member(),
'pv_answer_id'=>-1
));
}
}
}
$out=array(
'is_private'=>$poll_info[0]['po_is_private'],
'id'=>$poll_info[0]['id'],
'question'=>$poll_info[0]['po_question'],
'minimum_selections'=>$poll_info[0]['po_minimum_selections'],
'maximum_selections'=>$poll_info[0]['po_maximum_selections'],
'requires_reply'=>$poll_info[0]['po_requires_reply'],
'is_open'=>$poll_info[0]['po_is_open'],
'answers'=>$answers,
'total_votes'=>$poll_info[0]['po_cache_total_votes']
);
return $out;
}
sources/ocf_polls_action.php
Global_functions_ocf_polls_action.php
Function summary
|
AUTO_LINK
|
ocf_make_poll (AUTO_LINK topic_id, SHORT_TEXT question, BINARY is_private, BINARY is_open, integer minimum_selections, integer maximum_selections, BINARY requires_reply, array answers, boolean check_permissions)
|
AUTO_LINK ocf_make_poll(AUTO_LINK topic_id, SHORT_TEXT question, BINARY is_private, BINARY is_open, integer minimum_selections, integer maximum_selections, BINARY requires_reply, array answers, boolean check_permissions)
Add a forum poll.
Parameters…
| Name |
topic_id |
| Description |
The ID of the topic to add the poll to. |
| Type |
AUTO_LINK |
| Name |
question |
| Description |
The question. |
| Type |
SHORT_TEXT |
| Name |
is_private |
| Description |
Whether the result tallies are kept private until the poll is made non-private. |
| Type |
BINARY |
| Name |
is_open |
| Description |
Whether the poll is open for voting. |
| Type |
BINARY |
| Name |
minimum_selections |
| Description |
The minimum number of selections that may be made. |
| Type |
integer |
| Name |
maximum_selections |
| Description |
The maximum number of selections that may be made. |
| Type |
integer |
| Name |
requires_reply |
| Description |
Whether members must have a post in the topic before they made vote. |
| Type |
BINARY |
| Name |
answers |
| Description |
A list of pairs of the potential voteable answers and the number of votes. |
| Type |
array |
| Name |
check_permissions |
| Description |
Whether to check there are permissions to make the poll. |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The ID of the newly created forum poll. |
| Type |
AUTO_LINK |
function ocf_make_poll($topic_id,$question,$is_private,$is_open,$minimum_selections,$maximum_selections,$requires_reply,$answers,$check_permissions=true)
{
require_code('ocf_polls');
if (($check_permissions) && (!ocf_may_attach_poll($topic_id)))
access_denied('I_ERROR');
$poll_id=$GLOBALS['FORUM_DB']->query_insert('f_polls',array(
'po_question'=>$question,
'po_cache_total_votes'=>0,
'po_is_private'=>$is_private,
'po_is_open'=>$is_open,
'po_minimum_selections'=>$minimum_selections,
'po_maximum_selections'=>$maximum_selections,
'po_requires_reply'=>$requires_reply
),true);
foreach ($answers as $answer)
{
if (is_array($answer))
{
list($answer,$num_votes)=$answer;
} else $num_votes=0;
$GLOBALS['FORUM_DB']->query_insert('f_poll_answers',array(
'pa_poll_id'=>$poll_id,
'pa_answer'=>$answer,
'pa_cache_num_votes'=>$num_votes
));
}
$map=array('t_poll_id'=>$poll_id);
// Now make the topic validated if this is attaching immediately
if (get_param_integer('re_validate',0)==1)
{
$forum_id=$GLOBALS['FORUM_DB']->query_value('f_topics','t_forum_id',array('id'=>$topic_id));
if ((is_null($forum_id)) || (has_specific_permission(get_member(),'bypass_validation_midrange_content','topics',array('forums',$forum_id))))
$map['t_validated']=1;
}
$GLOBALS['FORUM_DB']->query_update('f_topics',$map,array('id'=>$topic_id),'',1);
return $poll_id;
}
0 reviews: Unrated (average)
There have been no comments yet