ILIAS  release_4-4 Revision
ilObjPoll Class Reference

Class ilObjPoll. More...

+ Inheritance diagram for ilObjPoll:
+ Collaboration diagram for ilObjPoll:

Public Member Functions

 __construct ($a_id=0, $a_reference=true)
 
 initType ()
 
 setOnline ($a_value)
 
 isOnline ()
 
 setAccessType ($a_value)
 
 getAccessType ()
 
 setAccessBegin ($a_value)
 
 getAccessBegin ()
 
 setAccessEnd ($a_value)
 
 getAccessEnd ()
 
 setAccessVisibility ($a_value)
 
 getAccessVisibility ()
 
 setQuestion ($a_value)
 
 getQuestion ()
 
 setImage ($a_value)
 
 getImage ()
 
 setViewResults ($a_value)
 
 getViewResults ()
 
 setVotingPeriod ($a_value)
 
 getVotingPeriod ()
 
 setVotingPeriodBegin ($a_value)
 
 getVotingPeriodBegin ()
 
 setVotingPeriodEnd ($a_value)
 
 getVotingPeriodEnd ()
 
 doCloneObject (ilObjPoll $new_obj, $a_target_id, $a_copy_id=0)
 Clone poll. More...
 
 getImageFullPath ($a_as_thumb=false)
 Get image incl. More...
 
 deleteImage ()
 remove existing file More...
 
 uploadImage (array $a_upload, $a_clone=false)
 Upload new image file. More...
 
 getAnswers ()
 
 getAnswer ($a_id)
 
 saveAnswer ($a_text, $a_pos=null)
 
 updateAnswer ($a_id, $a_text)
 
 rebuildAnswerPositions ()
 
 updateAnswerPositions (array $a_pos)
 
 deleteAnswer ($a_id)
 
 deleteAllVotes ()
 
 saveAnswers (array $a_answers)
 
 saveVote ($a_user_id, $a_answer_id)
 
 hasUserVoted ($a_user_id)
 
 countVotes ()
 
 getVotePercentages ()
 
- Public Member Functions inherited from ilObject2
 __construct ($a_id=0, $a_reference=true)
 Constructor public. More...
 
 withReferences ()
 
 read ($a_force_db=false)
 Read data from db. More...
 
 getId ()
 
 setId ($a_id)
 
 setRefId ($a_id)
 
 getRefId ()
 
 getType ()
 
 setType ($a_type)
 
 getPresentationTitle ()
 
 getTitle ()
 
 getUntranslatedTitle ()
 
 setTitle ($a_title)
 
 getDescription ()
 
 setDescription ($a_desc)
 
 getLongDescription ()
 
 getImportId ()
 
 setImportId ($a_import_id)
 
 getOwner ()
 
 getOwnerName ()
 
 _lookupOwnerName ($a_owner_id)
 
 setOwner ($a_owner)
 
 getCreateDate ()
 
 getLastUpdateDate ()
 
 setObjDataRecord ($a_record)
 
 create ($a_clone_mode=false)
 
 update ()
 
 MDUpdateListener ($a_element)
 
 createMetaData ()
 
 updateMetaData ()
 
 deleteMetaData ()
 
 updateOwner ()
 
 _getIdForImportId ($a_import_id)
 
 _lookupOwner ($a_id)
 
 _lookupLastUpdate ($a_id, $a_as_string=false)
 
 _getLastUpdateOfObjects ($a_objs)
 
 _setDeletedDate ($a_ref_id)
 
 _resetDeletedDate ($a_ref_id)
 
 _lookupDeletedDate ($a_ref_id)
 
 _writeTitle ($a_obj_id, $a_title)
 
 _writeDescription ($a_obj_id, $a_desc)
 
 _writeImportId ($a_obj_id, $a_import_id)
 
 _isInTrash ($a_ref_id)
 
 _hasUntrashedReference ($a_obj_id)
 
 _getObjectsDataForType ($a_type, $a_omit_trash=false)
 
 putInTree ($a_parent_ref)
 
 setPermissions ($a_parent_ref)
 
 createReference ()
 
 countReferences ()
 
 delete ()
 
 initDefaultRoles ()
 
 createRoleFolder ()
 
 notify ($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
 
 setRegisterMode ($a_bool)
 
 isUserRegistered ($a_user_id=0)
 
 requireRegistration ()
 
 appendCopyInfo ($a_target_id, $a_copy_id)
 
 cloneMetaData ($target_obj)
 
 cloneObject ($a_target_id, $a_copy_id=null, $a_omit_tree=false)
 
 cloneDependencies ($a_target_id, $a_copy_id)
 
- Public Member Functions inherited from ilObject
 ilObject ($a_id=0, $a_reference=true)
 Constructor public. More...
 
 withReferences ()
 determines wehter objects are referenced or not (got ref ids or not) More...
 
 read ($a_force_db=false)
 read object data from db into object More...
 
 getId ()
 get object id public More...
 
 setId ($a_id)
 set object id public More...
 
 setRefId ($a_id)
 set reference id public More...
 
 getRefId ()
 get reference id public More...
 
 getType ()
 get object type public More...
 
 setType ($a_type)
 set object type public More...
 
 getPresentationTitle ()
 get presentation title Normally same as title Overwritten for sessions More...
 
 getTitle ()
 get object title public More...
 
 getUntranslatedTitle ()
 get untranslated object title public More...
 
 setTitle ($a_title)
 set object title More...
 
 getDescription ()
 get object description More...
 
 setDescription ($a_desc)
 set object description More...
 
 getLongDescription ()
 get object long description (stored in object_description) More...
 
 getImportId ()
 get import id More...
 
 setImportId ($a_import_id)
 set import id More...
 
 getOwner ()
 get object owner More...
 
 getOwnerName ()
 
 _lookupOwnerName ($a_owner_id)
 lookup owner name for owner id More...
 
 setOwner ($a_owner)
 set object owner More...
 
 getCreateDate ()
 get create date public More...
 
 getLastUpdateDate ()
 get last update date public More...
 
 getDiskUsage ()
 Gets the disk usage of the object in bytes. More...
 
 setObjDataRecord ($a_record)
 set object_data record (note: this method should only be called from the ilObjectFactory class) More...
 
 create ()
 create More...
 
 update ()
 update object in db More...
 
 MDUpdateListener ($a_element)
 Meta data update listener. More...
 
 createMetaData ()
 create meta data entry More...
 
 updateMetaData ()
 update meta data entry More...
 
 deleteMetaData ()
 delete meta data entry More...
 
 updateOwner ()
 update owner of object in db More...
 
 _getIdForImportId ($a_import_id)
 get current object id for import id (static) More...
 
 _lookupOwner ($a_id)
 lookup object owner More...
 
 _lookupLastUpdate ($a_id, $a_as_string=false)
 lookup last update More...
 
 _getLastUpdateOfObjects ($a_objs)
 Get last update for a set of media objects. More...
 
 _setDeletedDate ($a_ref_id)
 only called in ilTree::saveSubTree More...
 
 _resetDeletedDate ($a_ref_id)
 only called in ilObjectGUI::insertSavedNodes More...
 
 _lookupDeletedDate ($a_ref_id)
 only called in ilObjectGUI::insertSavedNodes More...
 
 _writeTitle ($a_obj_id, $a_title)
 write title to db (static) More...
 
 _writeDescription ($a_obj_id, $a_desc)
 write description to db (static) More...
 
 _writeImportId ($a_obj_id, $a_import_id)
 write import id to db (static) More...
 
 _isInTrash ($a_ref_id)
 checks wether object is in trash More...
 
 _hasUntrashedReference ($a_obj_id)
 checks wether an object has at least one reference that is not in trash More...
 
 _getObjectsDataForType ($a_type, $a_omit_trash=false)
 get all objects of a certain type More...
 
 putInTree ($a_parent_ref)
 maybe this method should be in tree object!? More...
 
 setPermissions ($a_parent_ref)
 set permissions of object More...
 
 createReference ()
 creates reference for object More...
 
 countReferences ()
 count references of object More...
 
 delete ()
 delete object or referenced object (in the case of a referenced object, object data is only deleted if last reference is deleted) This function removes an object entirely from system!! More...
 
 initDefaultRoles ()
 init default roles settings Purpose of this function is to create a local role folder and local roles, that are needed depending on the object type If you want to setup default local roles you MUST overwrite this method in derived object classes (see ilObjForum for an example) public More...
 
 createRoleFolder ()
 creates a local role folder More...
 
 applyDidacticTemplate ($a_tpl_id)
 Apply template. More...
 
 notify ($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
 notifys an object about an event occured Based on the event passed, each object may decide how it reacts. More...
 
 setRegisterMode ($a_bool)
 
 isUserRegistered ($a_user_id=0)
 
 requireRegistration ()
 
 getXMLZip ()
 
 getHTMLDirectory ()
 
 cloneObject ($a_target_id, $a_copy_id=0, $a_omit_tree=false)
 Clone object permissions, put in tree ... More...
 
 appendCopyInfo ($a_target_id, $a_copy_id)
 Prepend Copy info if object with same name exists in that container. More...
 
 cloneDependencies ($a_target_id, $a_copy_id)
 Clone object dependencies. More...
 
 cloneMetaData ($target_obj)
 Copy meta data. More...
 
 _lookupCreationDate ($a_id)
 Lookup creation date. More...
 

Static Public Member Functions

static initStorage ($a_id, $a_subdir=null)
 Init file system storage. More...
 
static getImageSize ()
 
- Static Public Member Functions inherited from ilObject2
static _lookupObjIdByImportId ($a_import_id)
 
static _getAllReferences ($a_id)
 
static _lookupTitle ($a_id)
 
static _getIdsForTitle ($title, $type='', $partialmatch=false)
 
static _lookupDescription ($a_id)
 
static _lookupObjId ($a_id)
 
static _lookupType ($a_id, $a_reference=false)
 
static _lookupObjectId ($a_ref_id)
 
static _exists ($a_id, $a_reference=false)
 
static _getObjectsByType ($a_obj_type="", $a_owner="")
 
static _prepareCloneSelection ($a_ref_ids, $new_type)
 
static _getIcon ($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
 
- Static Public Member Functions inherited from ilObject
static _lookupObjIdByImportId ($a_import_id)
 
static _getAllReferences ($a_id)
 get all reference ids of object More...
 
static _lookupTitle ($a_id)
 lookup object title More...
 
static _getIdsForTitle ($title, $type='', $partialmatch=false)
 
static _lookupDescription ($a_id)
 lookup object description More...
 
static _lookupObjId ($a_id)
 
static setDeletedDates ($a_ref_ids)
 Set deleted date type $ilDB. More...
 
static _lookupType ($a_id, $a_reference=false)
 lookup object type More...
 
static _lookupObjectId ($a_ref_id)
 lookup object id More...
 
static _exists ($a_id, $a_reference=false, $a_type=null)
 checks if an object exists in object_data More...
 
static _getObjectsByType ($a_obj_type="", $a_owner="")
 Get objects by type. More...
 
static _prepareCloneSelection ($a_ref_ids, $new_type, $show_path=true)
 Prepare copy wizard object selection. More...
 
static _getIcon ($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
 Get icon for repository item. More...
 
static collectDeletionDependencies (&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
 Collect deletion dependencies. More...
 
static getDeletionDependencies ($a_obj_id)
 Get deletion dependencies. More...
 
static getLongDescriptions (array $a_obj_ids)
 Get long description data. More...
 
static getAllOwnedRepositoryObjects ($a_user_id)
 Get all ids of objects user owns. More...
 
static hasAutoRating ($a_type, $a_ref_id)
 Check if auto rating is active for parent group/course. More...
 

Data Fields

const VIEW_RESULTS_ALWAYS = 1
 
const VIEW_RESULTS_NEVER = 2
 
const VIEW_RESULTS_AFTER_VOTE = 3
 
const VIEW_RESULTS_AFTER_PERIOD = 4
 
- Data Fields inherited from ilObject
const TITLE_LENGTH = 255
 max length of object title More...
 
const DESC_LENGTH = 128
 
 $ilias
 
 $lng
 
 $id
 
 $ref_id
 
 $type
 
 $title
 
 $untranslatedTitle
 
 $desc
 
 $long_desc
 
 $owner
 
 $create_date
 
 $last_update
 
 $import_id
 
 $register = false
 
 $referenced
 
 $objectList
 
 $max_title
 
 $max_desc
 
 $add_dots
 
 $obj_data_record
 object_data record More...
 

Protected Member Functions

 doRead ()
 
 propertiesToDB ()
 
 doCreate ()
 
 doUpdate ()
 
 doDelete ()
 
 deleteAllAnswers ()
 
- Protected Member Functions inherited from ilObject2
 initType ()
 
 doRead ()
 
 doCreate ()
 
 beforeCreate ()
 
 doUpdate ()
 
 beforeUpdate ()
 
 doMDUpdateListener ($a_element)
 
 beforeMDUpdateListener ($a_element)
 
 doCreateMetaData ()
 
 beforeCreateMetaData ()
 
 doUpdateMetaData ()
 
 beforeUpdateMetaData ()
 
 doDelete ()
 
 beforeDelete ()
 
 doCloneObject ($new_obj, $a_target_id, $a_copy_id=null)
 
 beforeCloneObject ()
 

Protected Attributes

 $online
 
 $access_type
 
 $access_begin
 
 $access_end
 
 $access_visibility
 
 $question
 
 $image
 
 $view_results
 
 $period
 
 $period_begin
 
 $period_end
 

Detailed Description

Class ilObjPoll.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id
class.ilObjFolder.php 25528 2010-09-03 10:37:11Z smeyer

Definition at line 16 of file class.ilObjPoll.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjPoll::__construct (   $a_id = 0,
  $a_reference = true 
)

Definition at line 35 of file class.ilObjPoll.php.

References setAccessType(), setOnline(), setViewResults(), setVotingPeriod(), and ilObjectActivation\TIMINGS_DEACTIVATED.

36  {
37  // default
38  $this->setOnline(false);
39  $this->setViewResults(self::VIEW_RESULTS_AFTER_VOTE);
41  $this->setVotingPeriod(false);
42 
43  parent::__construct($a_id, $a_reference);
44  }
setVotingPeriod($a_value)
setAccessType($a_value)
setOnline($a_value)
setViewResults($a_value)
+ Here is the call graph for this function:

Member Function Documentation

◆ countVotes()

ilObjPoll::countVotes ( )

Definition at line 660 of file class.ilObjPoll.php.

References $row, and ilObject2\getId().

661  {
662  global $ilDB;
663 
664  $sql = "SELECT count(*) cnt".
665  " FROM il_poll_vote".
666  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer");
667  $set = $ilDB->query($sql);
668  $row = $ilDB->fetchAssoc($set);
669  return (int)$row["cnt"];
670  }
+ Here is the call graph for this function:

◆ deleteAllAnswers()

ilObjPoll::deleteAllAnswers ( )
protected

Definition at line 550 of file class.ilObjPoll.php.

References deleteAllVotes(), and ilObject2\getId().

Referenced by doDelete().

551  {
552  global $ilDB;
553 
554  if($this->getId())
555  {
556  $this->deleteAllVotes();
557 
558  $ilDB->manipulate("DELETE FROM il_poll_answer".
559  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer"));
560  }
561  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAllVotes()

ilObjPoll::deleteAllVotes ( )

Definition at line 563 of file class.ilObjPoll.php.

References ilObject2\getId().

Referenced by deleteAllAnswers().

564  {
565  global $ilDB;
566 
567  if($this->getId())
568  {
569  $ilDB->manipulate("DELETE FROM il_poll_vote".
570  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer"));
571  }
572  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAnswer()

ilObjPoll::deleteAnswer (   $a_id)

Definition at line 536 of file class.ilObjPoll.php.

Referenced by saveAnswers().

537  {
538  global $ilDB;
539 
540  if($a_id)
541  {
542  $ilDB->manipulate("DELETE FROM il_poll_vote".
543  " WHERE answer_id = ".$ilDB->quote($this->getId(), "integer"));
544 
545  $ilDB->manipulate("DELETE FROM il_poll_answer".
546  " WHERE id = ".$ilDB->quote($a_id, "integer"));
547  }
548  }
+ Here is the caller graph for this function:

◆ deleteImage()

ilObjPoll::deleteImage ( )

remove existing file

Definition at line 335 of file class.ilObjPoll.php.

References setImage().

Referenced by doDelete(), and uploadImage().

336  {
337  if($this->id)
338  {
339  include_once "Modules/Poll/classes/class.ilFSStoragePoll.php";
340  $storage = new ilFSStoragePoll($this->id);
341  $storage->delete();
342 
343  $this->setImage(null);
344  }
345  }
setImage($a_value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doCloneObject()

ilObjPoll::doCloneObject ( ilObjPoll  $new_obj,
  $a_target_id,
  $a_copy_id = 0 
)

Clone poll.

Parameters
ilObjPollnew object
inttarget ref_id
intcopy id
Returns
ilObjPoll

Definition at line 278 of file class.ilObjPoll.php.

References $image, getAnswers(), getImage(), getImageFullPath(), getQuestion(), getViewResults(), saveAnswer(), setQuestion(), setViewResults(), ilObject2\update(), and uploadImage().

279  {
280  // question/image
281  $new_obj->setQuestion($this->getQuestion());
282  $image = $this->getImageFullPath();
283  if($image)
284  {
285  $image = array("tmp_name"=>$image,
286  "name"=>$this->getImage());
287  $new_obj->uploadImage($image, true);
288  }
289  $new_obj->setViewResults($this->getViewResults());
290  $new_obj->update();
291 
292  // answers
293  $answers = $this->getAnswers();
294  if($answers)
295  {
296  foreach($answers as $item)
297  {
298  $new_obj->saveAnswer($item["answer"]);
299  }
300  }
301 
302  return $new_obj;
303  }
getImageFullPath($a_as_thumb=false)
Get image incl.
setQuestion($a_value)
saveAnswer($a_text, $a_pos=null)
uploadImage(array $a_upload, $a_clone=false)
Upload new image file.
setViewResults($a_value)
+ Here is the call graph for this function:

◆ doCreate()

ilObjPoll::doCreate ( )
protected

Definition at line 201 of file class.ilObjPoll.php.

References ilObject2\getId(), and propertiesToDB().

202  {
203  global $ilDB;
204 
205  if($this->getId())
206  {
207  $fields = $this->propertiesToDB();
208  $fields["id"] = array("integer", $this->getId());
209 
210  $ilDB->insert("il_poll", $fields);
211 
212 
213  // object activation default entry will be created on demand
214 
215 
216  // block handling
217  include_once "Modules/Poll/classes/class.ilPollBlock.php";
218  $block = new ilPollBlock();
219  $block->setType("poll");
220  $block->setContextObjId($this->getId());
221  $block->setContextObjType("poll");
222  $block->create();
223  }
224  }
Custom block for polls.
+ Here is the call graph for this function:

◆ doDelete()

ilObjPoll::doDelete ( )
protected

Definition at line 251 of file class.ilObjPoll.php.

References deleteAllAnswers(), ilObjectActivation\deleteAllEntries(), deleteImage(), and ilObject2\getId().

252  {
253  global $ilDB;
254 
255  if($this->getId())
256  {
257  $this->deleteImage();
258  $this->deleteAllAnswers();
259 
260  if($this->ref_id)
261  {
263  }
264 
265  $ilDB->manipulate("DELETE FROM il_poll".
266  " WHERE id = ".$ilDB->quote($this->id, "integer"));
267  }
268  }
deleteImage()
remove existing file
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
+ Here is the call graph for this function:

◆ doRead()

ilObjPoll::doRead ( )
protected

Definition at line 161 of file class.ilObjPoll.php.

References $row, ilObjectActivation\getItem(), setAccessBegin(), setAccessEnd(), setAccessType(), setAccessVisibility(), setImage(), setOnline(), setQuestion(), setViewResults(), setVotingPeriod(), setVotingPeriodBegin(), and setVotingPeriodEnd().

162  {
163  global $ilDB;
164 
165  $set = $ilDB->query("SELECT * FROM il_poll".
166  " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
167  $row = $ilDB->fetchAssoc($set);
168  $this->setQuestion($row["question"]);
169  $this->setImage($row["image"]);
170  $this->setOnline($row["online_status"]);
171  $this->setViewResults($row["view_results"]);
172  $this->setVotingPeriod($row["period"]);
173  $this->setVotingPeriodBegin($row["period_begin"]);
174  $this->setVotingPeriodEnd($row["period_end"]);
175 
176  if($this->ref_id)
177  {
178  $activation = ilObjectActivation::getItem($this->ref_id);
179  $this->setAccessType($activation["timing_type"]);
180  $this->setAccessBegin($activation["timing_start"]);
181  $this->setAccessEnd($activation["timing_end"]);
182  $this->setAccessVisibility($activation["visible"]);
183  }
184  }
setAccessEnd($a_value)
setVotingPeriod($a_value)
setAccessVisibility($a_value)
setAccessType($a_value)
static getItem($a_ref_id)
Get item data.
setQuestion($a_value)
setOnline($a_value)
setAccessBegin($a_value)
setImage($a_value)
setViewResults($a_value)
setVotingPeriodBegin($a_value)
setVotingPeriodEnd($a_value)
+ Here is the call graph for this function:

◆ doUpdate()

ilObjPoll::doUpdate ( )
protected

Definition at line 226 of file class.ilObjPoll.php.

References getAccessBegin(), getAccessEnd(), getAccessType(), getAccessVisibility(), ilObject2\getId(), and propertiesToDB().

227  {
228  global $ilDB;
229 
230  if($this->getId())
231  {
232  $fields = $this->propertiesToDB();
233 
234  $ilDB->update("il_poll", $fields,
235  array("id"=>array("integer", $this->getId())));
236 
237 
238  if($this->ref_id)
239  {
240  $activation = new ilObjectActivation();
241  $activation->setTimingType($this->getAccessType());
242  $activation->setTimingStart($this->getAccessBegin());
243  $activation->setTimingEnd($this->getAccessEnd());
244  $activation->toggleVisible($this->getAccessVisibility());
245  $activation->update($this->ref_id);
246  }
247 
248  }
249  }
Class ilObjectActivation.
+ Here is the call graph for this function:

◆ getAccessBegin()

ilObjPoll::getAccessBegin ( )

Definition at line 76 of file class.ilObjPoll.php.

References $access_begin.

Referenced by doUpdate().

77  {
78  return $this->access_begin;
79  }
+ Here is the caller graph for this function:

◆ getAccessEnd()

ilObjPoll::getAccessEnd ( )

Definition at line 86 of file class.ilObjPoll.php.

References $access_end.

Referenced by doUpdate().

87  {
88  return $this->access_end;
89  }
+ Here is the caller graph for this function:

◆ getAccessType()

ilObjPoll::getAccessType ( )

Definition at line 66 of file class.ilObjPoll.php.

References $access_type.

Referenced by doUpdate().

67  {
68  return $this->access_type;
69  }
+ Here is the caller graph for this function:

◆ getAccessVisibility()

ilObjPoll::getAccessVisibility ( )

Definition at line 96 of file class.ilObjPoll.php.

References $access_visibility.

Referenced by doUpdate().

97  {
99  }
+ Here is the caller graph for this function:

◆ getAnswer()

ilObjPoll::getAnswer (   $a_id)

Definition at line 454 of file class.ilObjPoll.php.

455  {
456  global $ilDB;
457 
458  $sql = "SELECT * FROM il_poll_answer".
459  " WHERE id = ".$ilDB->quote($a_id, "integer");
460  $set = $ilDB->query($sql);
461  return (array)$ilDB->fetchAssoc($set);
462  }

◆ getAnswers()

ilObjPoll::getAnswers ( )

Definition at line 437 of file class.ilObjPoll.php.

References $res, $row, and ilObject2\getId().

Referenced by doCloneObject(), rebuildAnswerPositions(), and saveAnswers().

438  {
439  global $ilDB;
440 
441  $res = array();
442 
443  $sql = "SELECT * FROM il_poll_answer".
444  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer").
445  " ORDER BY pos ASC";
446  $set = $ilDB->query($sql);
447  while($row = $ilDB->fetchAssoc($set))
448  {
449  $res[] = $row;
450  }
451  return $res;
452  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImage()

ilObjPoll::getImage ( )

Definition at line 116 of file class.ilObjPoll.php.

References $image.

Referenced by doCloneObject(), getImageFullPath(), and propertiesToDB().

117  {
118  return $this->image;
119  }
+ Here is the caller graph for this function:

◆ getImageFullPath()

ilObjPoll::getImageFullPath (   $a_as_thumb = false)

Get image incl.

path

Parameters
bool$a_as_thumb

Definition at line 315 of file class.ilObjPoll.php.

References $img, $path, getImage(), and initStorage().

Referenced by doCloneObject().

316  {
317  $img = $this->getImage();
318  if($img)
319  {
320  $path = $this->initStorage($this->id);
321  if(!$a_as_thumb)
322  {
323  return $path.$img;
324  }
325  else
326  {
327  return $path."thb_".$img;
328  }
329  }
330  }
static initStorage($a_id, $a_subdir=null)
Init file system storage.
$path
Definition: index.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageSize()

static ilObjPoll::getImageSize ( )
static

Definition at line 426 of file class.ilObjPoll.php.

427  {
428  // :TODO:
429  return "300x300";
430  }

◆ getQuestion()

ilObjPoll::getQuestion ( )

Definition at line 106 of file class.ilObjPoll.php.

References $question.

Referenced by doCloneObject(), and propertiesToDB().

107  {
108  return $this->question;
109  }
+ Here is the caller graph for this function:

◆ getViewResults()

ilObjPoll::getViewResults ( )

Definition at line 126 of file class.ilObjPoll.php.

References $view_results.

Referenced by doCloneObject(), and propertiesToDB().

127  {
128  return $this->view_results;
129  }
+ Here is the caller graph for this function:

◆ getVotePercentages()

ilObjPoll::getVotePercentages ( )

Definition at line 672 of file class.ilObjPoll.php.

References ilObject\$id, $res, $row, and ilObject2\getId().

673  {
674  global $ilDB;
675 
676  $res = array();
677  $cnt = 0;
678 
679  $sql = "SELECT answer_id, count(*) cnt".
680  " FROM il_poll_vote".
681  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer").
682  " GROUP BY answer_id";
683  $set = $ilDB->query($sql);
684  while($row = $ilDB->fetchAssoc($set))
685  {
686  $cnt += $row["cnt"];
687  $res[$row["answer_id"]] = array("abs"=>$row["cnt"], "perc"=>0);
688  }
689 
690  foreach($res as $id => $item)
691  {
692  $res[$id]["perc"] = $item["abs"]/$cnt*100;
693  }
694 
695  return array("perc"=>$res, "total"=>$cnt);
696  }
+ Here is the call graph for this function:

◆ getVotingPeriod()

ilObjPoll::getVotingPeriod ( )

Definition at line 136 of file class.ilObjPoll.php.

References $period.

Referenced by propertiesToDB().

137  {
138  return $this->period;
139  }
+ Here is the caller graph for this function:

◆ getVotingPeriodBegin()

ilObjPoll::getVotingPeriodBegin ( )

Definition at line 146 of file class.ilObjPoll.php.

References $period_begin.

Referenced by propertiesToDB().

147  {
148  return $this->period_begin;
149  }
+ Here is the caller graph for this function:

◆ getVotingPeriodEnd()

ilObjPoll::getVotingPeriodEnd ( )

Definition at line 156 of file class.ilObjPoll.php.

References $period_end.

Referenced by propertiesToDB().

157  {
158  return $this->period_end;
159  }
+ Here is the caller graph for this function:

◆ hasUserVoted()

ilObjPoll::hasUserVoted (   $a_user_id)

Definition at line 648 of file class.ilObjPoll.php.

References ilObject2\getId().

Referenced by saveVote().

649  {
650  global $ilDB;
651 
652  $sql = "SELECT user_id".
653  " FROM il_poll_vote".
654  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer").
655  " AND user_id = ".$ilDB->quote($a_user_id, "integer");
656  $set = $ilDB->query($sql);
657  return (bool)$ilDB->numRows($set);
658  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initStorage()

static ilObjPoll::initStorage (   $a_id,
  $a_subdir = null 
)
static

Init file system storage.

Parameters
type$a_id
type$a_subdir
Returns
string

Definition at line 354 of file class.ilObjPoll.php.

References $path.

Referenced by getImageFullPath(), ilPollDataSet\getXmlRecord(), ilPollDataSet\importRecord(), and uploadImage().

355  {
356  include_once "Modules/Poll/classes/class.ilFSStoragePoll.php";
357  $storage = new ilFSStoragePoll($a_id);
358  $storage->create();
359 
360  $path = $storage->getAbsolutePath()."/";
361 
362  if($a_subdir)
363  {
364  $path .= $a_subdir."/";
365 
366  if(!is_dir($path))
367  {
368  mkdir($path);
369  }
370  }
371 
372  return $path;
373  }
$path
Definition: index.php:22
+ Here is the caller graph for this function:

◆ initType()

ilObjPoll::initType ( )

Definition at line 46 of file class.ilObjPoll.php.

47  {
48  $this->type = "poll";
49  }

◆ isOnline()

ilObjPoll::isOnline ( )

Definition at line 56 of file class.ilObjPoll.php.

References $online.

Referenced by propertiesToDB().

57  {
58  return $this->online;
59  }
+ Here is the caller graph for this function:

◆ propertiesToDB()

ilObjPoll::propertiesToDB ( )
protected

Definition at line 186 of file class.ilObjPoll.php.

References getImage(), getQuestion(), getViewResults(), getVotingPeriod(), getVotingPeriodBegin(), getVotingPeriodEnd(), and isOnline().

Referenced by doCreate(), and doUpdate().

187  {
188  $fields = array(
189  "question" => array("text", $this->getQuestion()),
190  "image" => array("text", $this->getImage()),
191  "online_status" => array("integer", $this->isOnline()),
192  "view_results" => array("integer", $this->getViewResults()),
193  "period" => array("integer", $this->getVotingPeriod()),
194  "period_begin" => array("integer", $this->getVotingPeriodBegin()),
195  "period_end" => array("integer", $this->getVotingPeriodEnd())
196  );
197 
198  return $fields;
199  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rebuildAnswerPositions()

ilObjPoll::rebuildAnswerPositions ( )

Definition at line 506 of file class.ilObjPoll.php.

References getAnswers(), and updateAnswerPositions().

507  {
508  $answers = $this->getAnswers();
509 
510  $pos = array();
511  foreach($answers as $item)
512  {
513  $pos[$item["id"]] = $item["pos"];
514  }
515 
516  $this->updateAnswerPositions($pos);
517  }
updateAnswerPositions(array $a_pos)
+ Here is the call graph for this function:

◆ saveAnswer()

ilObjPoll::saveAnswer (   $a_text,
  $a_pos = null 
)

Definition at line 464 of file class.ilObjPoll.php.

References ilObject\$id, and ilObject2\getId().

Referenced by doCloneObject(), and saveAnswers().

465  {
466  global $ilDB;
467 
468  if(!trim($a_text))
469  {
470  return;
471  }
472 
473  $id = $ilDB->nextId("il_poll_answer");
474 
475  if(!$a_pos)
476  {
477  // append
478  $sql = "SELECT max(pos) pos".
479  " FROM il_poll_answer".
480  " WHERE poll_id = ".$ilDB->quote($this->getId(), "integer");
481  $set = $ilDB->query($sql);
482  $a_pos = $ilDB->fetchAssoc($set);
483  $a_pos = (int)$a_pos["pos"]+10;
484  }
485 
486  $fields = array(
487  "id" => array("integer", $id),
488  "poll_id" => array("integer", $this->getId()),
489  "answer" => array("text", trim($a_text)),
490  "pos" => array("integer", $a_pos)
491  );
492  $ilDB->insert("il_poll_answer", $fields);
493 
494  return $id;
495  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAnswers()

ilObjPoll::saveAnswers ( array  $a_answers)

Definition at line 574 of file class.ilObjPoll.php.

References ilObject\$id, deleteAnswer(), getAnswers(), saveAnswer(), and updateAnswerPositions().

575  {
576  $existing = $this->getAnswers();
577 
578  $ids = array();
579  $pos = 0;
580  foreach($a_answers as $answer)
581  {
582  if(trim($answer))
583  {
584  // existing answer?
585  $found = false;
586  foreach($existing as $idx => $item)
587  {
588  if(trim($answer) == $item["answer"])
589  {
590  $found = true;
591  unset($existing[$idx]);
592 
593  $id = $item["id"];
594  }
595  }
596 
597  // create new answer
598  if(!$found)
599  {
600  $id = $this->saveAnswer($answer);
601  }
602 
603  // add existing answer id to order
604  if($id)
605  {
606  $ids[$id] = ++$pos;
607  }
608  }
609  }
610 
611  // remove obsolete answers
612  if(sizeof($existing))
613  {
614  foreach($existing as $item)
615  {
616  $this->deleteAnswer($item["id"]);
617  }
618  }
619 
620  // save current order
621  if(sizeof($ids))
622  {
623  $this->updateAnswerPositions($ids);
624  }
625  }
saveAnswer($a_text, $a_pos=null)
updateAnswerPositions(array $a_pos)
deleteAnswer($a_id)
+ Here is the call graph for this function:

◆ saveVote()

ilObjPoll::saveVote (   $a_user_id,
  $a_answer_id 
)

Definition at line 632 of file class.ilObjPoll.php.

References ilObject2\getId(), and hasUserVoted().

633  {
634  global $ilDB;
635 
636  if($this->hasUserVoted($a_user_id))
637  {
638  return;
639  }
640 
641  $fields = array("user_id" => array("integer", $a_user_id),
642  "poll_id" => array("integer", $this->getId()),
643  "answer_id" => array("integer", $a_answer_id));
644 
645  $ilDB->insert("il_poll_vote", $fields);
646  }
hasUserVoted($a_user_id)
+ Here is the call graph for this function:

◆ setAccessBegin()

ilObjPoll::setAccessBegin (   $a_value)

Definition at line 71 of file class.ilObjPoll.php.

Referenced by doRead().

72  {
73  $this->access_begin = (int)$a_value;
74  }
+ Here is the caller graph for this function:

◆ setAccessEnd()

ilObjPoll::setAccessEnd (   $a_value)

Definition at line 81 of file class.ilObjPoll.php.

Referenced by doRead().

82  {
83  $this->access_end = (int)$a_value;
84  }
+ Here is the caller graph for this function:

◆ setAccessType()

ilObjPoll::setAccessType (   $a_value)

Definition at line 61 of file class.ilObjPoll.php.

Referenced by __construct(), and doRead().

62  {
63  $this->access_type = (int)$a_value;
64  }
+ Here is the caller graph for this function:

◆ setAccessVisibility()

ilObjPoll::setAccessVisibility (   $a_value)

Definition at line 91 of file class.ilObjPoll.php.

Referenced by doRead().

92  {
93  $this->access_visibility = (bool)$a_value;
94  }
+ Here is the caller graph for this function:

◆ setImage()

ilObjPoll::setImage (   $a_value)

Definition at line 111 of file class.ilObjPoll.php.

Referenced by deleteImage(), doRead(), and uploadImage().

112  {
113  $this->image = (string)$a_value;
114  }
+ Here is the caller graph for this function:

◆ setOnline()

ilObjPoll::setOnline (   $a_value)

Definition at line 51 of file class.ilObjPoll.php.

Referenced by __construct(), and doRead().

52  {
53  $this->online = (bool)$a_value;
54  }
+ Here is the caller graph for this function:

◆ setQuestion()

ilObjPoll::setQuestion (   $a_value)

Definition at line 101 of file class.ilObjPoll.php.

Referenced by doCloneObject(), and doRead().

102  {
103  $this->question = (string)$a_value;
104  }
+ Here is the caller graph for this function:

◆ setViewResults()

ilObjPoll::setViewResults (   $a_value)

Definition at line 121 of file class.ilObjPoll.php.

Referenced by __construct(), doCloneObject(), and doRead().

122  {
123  $this->view_results = (int)$a_value;
124  }
+ Here is the caller graph for this function:

◆ setVotingPeriod()

ilObjPoll::setVotingPeriod (   $a_value)

Definition at line 131 of file class.ilObjPoll.php.

Referenced by __construct(), and doRead().

132  {
133  $this->period = (bool)$a_value;
134  }
+ Here is the caller graph for this function:

◆ setVotingPeriodBegin()

ilObjPoll::setVotingPeriodBegin (   $a_value)

Definition at line 141 of file class.ilObjPoll.php.

Referenced by doRead().

142  {
143  $this->period_begin = (int)$a_value;
144  }
+ Here is the caller graph for this function:

◆ setVotingPeriodEnd()

ilObjPoll::setVotingPeriodEnd (   $a_value)

Definition at line 151 of file class.ilObjPoll.php.

Referenced by doRead().

152  {
153  $this->period_end = (int)$a_value;
154  }
+ Here is the caller graph for this function:

◆ updateAnswer()

ilObjPoll::updateAnswer (   $a_id,
  $a_text 
)

Definition at line 497 of file class.ilObjPoll.php.

498  {
499  global $ilDB;
500 
501  $ilDB->update("il_poll_answer",
502  array("answer" => array("text", $a_text)),
503  array("id" => array("integer", $a_id)));
504  }

◆ updateAnswerPositions()

ilObjPoll::updateAnswerPositions ( array  $a_pos)

Definition at line 519 of file class.ilObjPoll.php.

References ilObject\$id.

Referenced by rebuildAnswerPositions(), and saveAnswers().

520  {
521  global $ilDB;
522 
523  asort($a_pos);
524 
525  $pos = 0;
526  foreach(array_keys($a_pos) as $id)
527  {
528  $pos += 10;
529 
530  $ilDB->update("il_poll_answer",
531  array("pos" => array("integer", $pos)),
532  array("id" => array("integer", $id)));
533  }
534  }
+ Here is the caller graph for this function:

◆ uploadImage()

ilObjPoll::uploadImage ( array  $a_upload,
  $a_clone = false 
)

Upload new image file.

Parameters
array$a_upload
Returns
bool

Definition at line 381 of file class.ilObjPoll.php.

References $path, $success, deleteImage(), ilUtil\escapeShellArg(), ilUtil\execConvert(), initStorage(), and setImage().

Referenced by doCloneObject().

382  {
383  if(!$this->id)
384  {
385  return false;
386  }
387 
388  $this->deleteImage();
389 
390  // #10074
391  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
392 
393  $path = $this->initStorage($this->id);
394  $original = "org_".$this->id."_".$clean_name;
395  $thumb = "thb_".$this->id."_".$clean_name;
396  $processed = $this->id."_".$clean_name;
397 
398  $success = false;
399  if(!$a_clone)
400  {
401  $success = @move_uploaded_file($a_upload["tmp_name"], $path.$original);
402  }
403  else
404  {
405  $success = @copy($a_upload["tmp_name"], $path.$original);
406  }
407 
408  if($success)
409  {
410  chmod($path.$original, 0770);
411 
412  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
413  // taking only frame [0] to avoid problems with animated gifs
414  $original_file = ilUtil::escapeShellArg($path.$original);
415  $thumb_file = ilUtil::escapeShellArg($path.$thumb);
416  $processed_file = ilUtil::escapeShellArg($path.$processed);
417  ilUtil::execConvert($original_file."[0] -geometry \"100x100>\" -quality 100 PNG:".$thumb_file);
418  ilUtil::execConvert($original_file."[0] -geometry \"".self::getImageSize().">\" -quality 100 PNG:".$processed_file);
419 
420  $this->setImage($processed);
421  return true;
422  }
423  return false;
424  }
deleteImage()
remove existing file
setImage($a_value)
$success
Definition: Utf8Test.php:87
static execConvert($args)
execute convert command
static initStorage($a_id, $a_subdir=null)
Init file system storage.
static escapeShellArg($a_arg)
$path
Definition: index.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access_begin

ilObjPoll::$access_begin
protected

Definition at line 20 of file class.ilObjPoll.php.

Referenced by getAccessBegin().

◆ $access_end

ilObjPoll::$access_end
protected

Definition at line 21 of file class.ilObjPoll.php.

Referenced by getAccessEnd().

◆ $access_type

ilObjPoll::$access_type
protected

Definition at line 19 of file class.ilObjPoll.php.

Referenced by getAccessType().

◆ $access_visibility

ilObjPoll::$access_visibility
protected

Definition at line 22 of file class.ilObjPoll.php.

Referenced by getAccessVisibility().

◆ $image

ilObjPoll::$image
protected

Definition at line 24 of file class.ilObjPoll.php.

Referenced by doCloneObject(), and getImage().

◆ $online

ilObjPoll::$online
protected

Definition at line 18 of file class.ilObjPoll.php.

Referenced by isOnline().

◆ $period

ilObjPoll::$period
protected

Definition at line 26 of file class.ilObjPoll.php.

Referenced by getVotingPeriod().

◆ $period_begin

ilObjPoll::$period_begin
protected

Definition at line 27 of file class.ilObjPoll.php.

Referenced by getVotingPeriodBegin().

◆ $period_end

ilObjPoll::$period_end
protected

Definition at line 28 of file class.ilObjPoll.php.

Referenced by getVotingPeriodEnd().

◆ $question

ilObjPoll::$question
protected

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

Referenced by getQuestion().

◆ $view_results

ilObjPoll::$view_results
protected

Definition at line 25 of file class.ilObjPoll.php.

Referenced by getViewResults().

◆ VIEW_RESULTS_AFTER_PERIOD

const ilObjPoll::VIEW_RESULTS_AFTER_PERIOD = 4

◆ VIEW_RESULTS_AFTER_VOTE

const ilObjPoll::VIEW_RESULTS_AFTER_VOTE = 3

◆ VIEW_RESULTS_ALWAYS

const ilObjPoll::VIEW_RESULTS_ALWAYS = 1

◆ VIEW_RESULTS_NEVER

const ilObjPoll::VIEW_RESULTS_NEVER = 2

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