ILIAS  release_7 Revision v7.30-3-g800a261c036
ilPollBlock Class Reference

Custom block for polls. More...

+ Inheritance diagram for ilPollBlock:
+ Collaboration diagram for ilPollBlock:

Public Member Functions

 __construct ($a_id=0)
 Constructor. More...
 
 setRefId ($a_id)
 Set ref id (needed for poll access) More...
 
 getPoll ()
 Get poll object. More...
 
 hasAnyContent ($a_user_id, $a_ref_id)
 Check if user will see any content (vote/result) More...
 
 maySeeQuestion ($a_user_id)
 
 mayVote ($a_user_id)
 
 mayNotResultsYet ()
 
 maySeeResults ($a_user_id)
 
 getMessage ($a_user_id)
 
 showResultsAs ()
 Show Results as (Barchart or Piechart) More...
 
 showComments ()
 Are Comments enabled or disabled. More...
 
- Public Member Functions inherited from ilCustomBlock
 __construct ($a_id=0)
 Constructor. More...
 
 setId ($a_id)
 Set Id. More...
 
 getId ()
 Get Id. More...
 
 setContextObjId ($a_context_obj_id)
 Set ContextObjId. More...
 
 getContextObjId ()
 Get ContextObjId. More...
 
 setContextObjType ($a_context_obj_type)
 Set ContextObjType. More...
 
 getContextObjType ()
 Get ContextObjType. More...
 
 setContextSubObjId ($a_context_sub_obj_id)
 Set ContextSubObjId. More...
 
 getContextSubObjId ()
 Get ContextSubObjId. More...
 
 setContextSubObjType ($a_context_sub_obj_type)
 Set ContextSubObjType. More...
 
 getContextSubObjType ()
 Get ContextSubObjType. More...
 
 setType ($a_type)
 Set Type. More...
 
 getType ()
 Get Type. More...
 
 setTitle ($a_title)
 Set Title. More...
 
 getTitle ()
 Get Title. More...
 
 create ()
 Create new item. More...
 
 read ()
 Read item from database. More...
 
 update ()
 Update item in database. More...
 
 delete ()
 Delete item from database. More...
 
 querygetBlocksForContext ()
 Query getBlocksForContext. More...
 
 queryBlocksForContext ($a_include_sub_obj=true)
 Query BlocksForContext. More...
 
 queryTitleForId ()
 Query TitleForId. More...
 
 queryCntBlockForContext ()
 Query CntBlockForContext. More...
 

Protected Attributes

 $lng
 
 $poll
 
 $answers
 
 $visible
 
 $active
 
- Protected Attributes inherited from ilCustomBlock
 $db
 
 $id
 
 $context_obj_id
 
 $context_obj_type
 
 $context_sub_obj_id
 
 $context_sub_obj_type
 
 $type
 
 $title
 

Additional Inherited Members

- Static Public Member Functions inherited from ilCustomBlock
static multiBlockQuery ($a_context_obj_type, array $a_context_obj_ids)
 

Detailed Description

Custom block for polls.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilPollBlock.php.

Constructor & Destructor Documentation

◆ __construct()

ilPollBlock::__construct (   $a_id = 0)

Constructor.

Definition at line 23 of file class.ilPollBlock.php.

References $DIC, and ILIAS\GlobalScreen\Provider\__construct().

24  {
25  global $DIC;
26 
27  parent::__construct($a_id);
28  $this->lng = $DIC->language();
29  }
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ getMessage()

ilPollBlock::getMessage (   $a_user_id)

Definition at line 143 of file class.ilPollBlock.php.

References $lng, ilDatePresentation\formatDate(), and IL_CAL_UNIX.

144  {
145  $lng = $this->lng;
146 
147  if (!sizeof($this->answers)) {
148  return $lng->txt("poll_block_message_no_answers");
149  }
150 
151  if (!$this->active) {
152  if (!$this->poll->isOnline()) {
153  return $lng->txt("poll_block_message_offline");
154  }
155  if ($this->poll->getAccessBegin() > time()) {
156  $date = ilDatePresentation::formatDate(new ilDateTime($this->poll->getAccessBegin(), IL_CAL_UNIX));
157  return sprintf($lng->txt("poll_block_message_inactive"), $date);
158  }
159  }
160  }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
+ Here is the call graph for this function:

◆ getPoll()

ilPollBlock::getPoll ( )

Get poll object.

Returns
ilObjPoll

Definition at line 53 of file class.ilPollBlock.php.

References $poll.

54  {
55  return $this->poll;
56  }

◆ hasAnyContent()

ilPollBlock::hasAnyContent (   $a_user_id,
  $a_ref_id 
)

Check if user will see any content (vote/result)

Parameters
int$a_user_id
Returns
boolean

Definition at line 64 of file class.ilPollBlock.php.

References ilObjPollAccess\_isActivated(), maySeeQuestion(), and maySeeResults().

65  {
66  if (!sizeof($this->answers)) {
67  return false;
68  }
69 
70  include_once "Modules/Poll/classes/class.ilObjPollAccess.php";
71  $this->active = ilObjPollAccess::_isActivated($a_ref_id);
72  if (!$this->active) {
73  return false;
74  }
75 
76  if (!$this->maySeeQuestion($a_user_id) &&
77  !$this->maySeeResults($a_user_id)) {
78  return false;
79  }
80 
81  return true;
82  }
maySeeQuestion($a_user_id)
static _isActivated($a_ref_id)
Is activated?
maySeeResults($a_user_id)
+ Here is the call graph for this function:

◆ mayNotResultsYet()

ilPollBlock::mayNotResultsYet ( )

Definition at line 108 of file class.ilPollBlock.php.

References ilObjPoll\VIEW_RESULTS_AFTER_PERIOD.

109  {
110  if ($this->poll->getViewResults() == ilObjPoll::VIEW_RESULTS_AFTER_PERIOD &&
111  $this->poll->getVotingPeriod() &&
112  $this->poll->getVotingPeriodEnd() > time()) {
113  return true;
114  }
115  return false;
116  }
const VIEW_RESULTS_AFTER_PERIOD

◆ maySeeQuestion()

ilPollBlock::maySeeQuestion (   $a_user_id)

Definition at line 84 of file class.ilPollBlock.php.

Referenced by hasAnyContent(), and mayVote().

85  {
86  if (!$this->active) {
87  return false;
88  }
89 
90  if ($this->poll->hasUserVoted($a_user_id)) {
91  return false;
92  }
93 
94  if ($this->poll->getVotingPeriod() &&
95  ($this->poll->getVotingPeriodBegin() > time() ||
96  $this->poll->getVotingPeriodEnd() < time())) {
97  return false;
98  }
99 
100  return true;
101  }
+ Here is the caller graph for this function:

◆ maySeeResults()

ilPollBlock::maySeeResults (   $a_user_id)

Definition at line 118 of file class.ilPollBlock.php.

References ilObjPoll\VIEW_RESULTS_AFTER_PERIOD, ilObjPoll\VIEW_RESULTS_AFTER_VOTE, ilObjPoll\VIEW_RESULTS_ALWAYS, and ilObjPoll\VIEW_RESULTS_NEVER.

Referenced by hasAnyContent().

119  {
120  if (!$this->active) {
121  return false;
122  }
123 
124  switch ($this->poll->getViewResults()) {
126  return false;
127 
129  // fallthrough
130 
131  // #12023 - see mayNotResultsYet()
133  return true;
134 
136  if ($this->poll->hasUserVoted($a_user_id)) {
137  return true;
138  }
139  return false;
140  }
141  }
const VIEW_RESULTS_AFTER_PERIOD
const VIEW_RESULTS_AFTER_VOTE
const VIEW_RESULTS_NEVER
const VIEW_RESULTS_ALWAYS
+ Here is the caller graph for this function:

◆ mayVote()

ilPollBlock::mayVote (   $a_user_id)

Definition at line 103 of file class.ilPollBlock.php.

References ANONYMOUS_USER_ID, and maySeeQuestion().

104  {
105  return $this->maySeeQuestion($a_user_id) && $a_user_id != ANONYMOUS_USER_ID;
106  }
maySeeQuestion($a_user_id)
const ANONYMOUS_USER_ID
Definition: constants.php:25
+ Here is the call graph for this function:

◆ setRefId()

ilPollBlock::setRefId (   $a_id)

Set ref id (needed for poll access)

Parameters
int$a_id

Definition at line 41 of file class.ilPollBlock.php.

42  {
43  include_once "Modules/Poll/classes/class.ilObjPoll.php";
44  $this->poll = new ilObjPoll($a_id, true);
45  $this->answers = $this->poll->getAnswers();
46  }
Class ilObjPoll.

◆ showComments()

ilPollBlock::showComments ( )

Are Comments enabled or disabled.

Returns
bool

Definition at line 176 of file class.ilPollBlock.php.

177  {
178  return $this->poll->getShowComments();
179  }

◆ showResultsAs()

ilPollBlock::showResultsAs ( )

Show Results as (Barchart or Piechart)

Returns
int

Definition at line 167 of file class.ilPollBlock.php.

168  {
169  return $this->poll->getShowResultsAs();
170  }

Field Documentation

◆ $active

ilPollBlock::$active
protected

Definition at line 34 of file class.ilPollBlock.php.

◆ $answers

ilPollBlock::$answers
protected

Definition at line 32 of file class.ilPollBlock.php.

◆ $lng

ilPollBlock::$lng
protected

Definition at line 17 of file class.ilPollBlock.php.

Referenced by getMessage().

◆ $poll

ilPollBlock::$poll
protected

Definition at line 31 of file class.ilPollBlock.php.

Referenced by getPoll().

◆ $visible

ilPollBlock::$visible
protected

Definition at line 33 of file class.ilPollBlock.php.


The documentation for this class was generated from the following file: