19 declare(strict_types=1);
    30     protected \ILIAS\Notes\Service 
$notes;
    57     public function __construct(
int $a_id = 0, 
bool $a_reference = 
true)
    61         $this->db = $DIC->database();
    62         $this->image_converter = $DIC->fileConverters()->legacyImages();
    67         $this->notes = $DIC->notes();
    79         $this->access_type = $a_value;
    89         $this->access_begin = $a_value;
    99         $this->access_end = $a_value;
   109         $this->access_visibility = $a_value;
   119         $this->question = $a_value;
   129         $this->image = $a_value;
   139         $this->view_results = $a_value;
   149         $this->period = $a_value;
   159         $this->period_begin = $a_value;
   169         $this->period_end = $a_value;
   179         $this->max_number_answers = $a_value;
   189         $this->result_sort_by_votes = $a_value;
   199         $this->mode_non_anonymous = $a_value;
   209         $this->show_comments = $a_value;
   219         $this->show_results_as = $a_value;
   231         $set = 
$ilDB->query(
"SELECT * FROM il_poll" .
   232                 " WHERE id = " . 
$ilDB->quote($this->getId(), 
"integer"));
   233         $row = 
$ilDB->fetchAssoc($set);
   234         $this->
setQuestion((
string) ($row[
"question"] ?? 
''));
   235         $this->
setImage((
string) ($row[
"image"] ?? 
''));
   236         $this->
setViewResults((
int) ($row[
"view_results"] ?? self::VIEW_RESULTS_AFTER_VOTE));
   243         $this->
setShowResultsAs((
int) ($row[
"show_results_as"] ?? self::SHOW_RESULTS_AS_BARCHART));
   253                 $this->
setAccessBegin((
int) ($activation[
"timing_start"] ?? time()));
   254                 $this->
setAccessEnd((
int) ($activation[
"timing_end"] ?? time()));
   264             "image" => array(
"text", $this->
getImage()),
   276     protected function doCreate(
bool $clone_mode = 
false): void
   280         if ($this->
getId()) {
   282             $fields[
"id"] = array(
"integer", $this->
getId());
   284             $ilDB->insert(
"il_poll", $fields);
   292             $block->setType(
"poll");
   293             $block->setContextObjId($this->
getId());
   294             $block->setContextObjType(
"poll");
   303         if ($this->
getId()) {
   309                 array(
"id" => array(
"integer", $this->
getId()))
   321                 $activation->update($this->ref_id);
   330         if ($this->
getId()) {
   338             $ilDB->manipulate(
"DELETE FROM il_poll" .
   339                 " WHERE id = " . 
$ilDB->quote($this->id, 
"integer"));
   351             $image = array(
"tmp_name" => $image,
   353             $new_obj->uploadImage($image, 
true);
   359         if ($cp_options->isRootNode($this->getRefId())) {
   369         $new_obj->setViewResults($view_results);
   380             foreach ($answers as $item) {
   381                 $new_obj->saveAnswer($item[
"answer"]);
   395             $path = self::initStorage($this->
id);
   399                 return $path . 
"thb_" . $img;
   416     public static function initStorage(
int $a_id, ?
string $a_subdir = null): string
   421         $path = $storage->getAbsolutePath() . 
"/";
   424             $path .= $a_subdir . 
"/";
   426             if (!is_dir(
$path)) {
   434     public function uploadImage(array $a_upload, 
bool $a_clone = 
false): bool
   443         $name = (string) ($a_upload[
'name'] ?? 
'');
   444         $tmp_name = (string) ($a_upload[
'tmp_name'] ?? 
'');
   445         $clean_name = preg_replace(
"/[^a-zA-Z0-9\_\.\-]/", 
"", $name);
   447         $path = self::initStorage($this->
id);
   448         $original = 
"org_" . $this->
id . 
"_" . $clean_name;
   449         $thumb = 
"thb_" . $this->
id . 
"_" . $clean_name;
   450         $processed = $this->
id . 
"_" . $clean_name;
   456             $success = copy($tmp_name, 
$path . $original);
   459             chmod(
$path . $original, 0770);
   462             $original_file = 
$path . $original;
   463             $thumb_file = 
$path . $thumb;
   464             $processed_file = 
$path . $processed;
   466             $this->image_converter->croppedSquare(
   470                 ImageOutputOptions::FORMAT_PNG
   473             $this->image_converter->croppedSquare(
   477                 ImageOutputOptions::FORMAT_PNG
   503         $sql = 
"SELECT * FROM il_poll_answer" .
   504             " WHERE poll_id = " . 
$ilDB->quote($this->
getId(), 
"integer") .
   506         $set = 
$ilDB->query($sql);
   507         while ($row = 
$ilDB->fetchAssoc($set)) {
   517         $sql = 
"SELECT * FROM il_poll_answer" .
   518             " WHERE id = " . 
$ilDB->quote($a_id, 
"integer");
   519         $set = 
$ilDB->query($sql);
   520         return (array) 
$ilDB->fetchAssoc($set);
   527         if (!trim($a_text)) {
   531         $id = 
$ilDB->nextId(
"il_poll_answer");
   535             $sql = 
"SELECT max(pos) pos" .
   536                 " FROM il_poll_answer" .
   537                 " WHERE poll_id = " . 
$ilDB->quote($this->
getId(), 
"integer");
   538             $set = 
$ilDB->query($sql);
   539             $a_pos = 
$ilDB->fetchAssoc($set);
   540             $a_pos = (
int) ($a_pos[
"pos"] ?? 0) + 10;
   544             "id" => array(
"integer", 
$id),
   545             "poll_id" => array(
"integer", $this->
getId()),
   546             "answer" => array(
"text", trim($a_text)),
   547             "pos" => array(
"integer", $a_pos)
   549         $ilDB->insert(
"il_poll_answer", $fields);
   560             array(
"answer" => array(
"text", $a_text)),
   561             array(
"id" => array(
"integer", $a_id))
   570         foreach ($answers as $item) {
   571             $id = (
int) ($item[
'id'] ?? 0);
   572             $pos[
$id] = (
int) ($item[
"pos"] ?? 10);
   585         foreach (array_keys($a_pos) as 
$id) {
   590                 array(
"pos" => array(
"integer", $pos)),
   591                 array(
"id" => array(
"integer", $id))
   601             $ilDB->manipulate(
"DELETE FROM il_poll_vote" .
   602                 " WHERE answer_id = " . 
$ilDB->quote($this->getId(), 
"integer"));
   604             $ilDB->manipulate(
"DELETE FROM il_poll_answer" .
   605                 " WHERE id = " . 
$ilDB->quote($a_id, 
"integer"));
   613         if ($this->
getId()) {
   616             $ilDB->manipulate(
"DELETE FROM il_poll_answer" .
   617                 " WHERE poll_id = " . 
$ilDB->quote($this->getId(), 
"integer"));
   625         if ($this->
getId()) {
   626             $ilDB->manipulate(
"DELETE FROM il_poll_vote" .
   627                 " WHERE poll_id = " . 
$ilDB->quote($this->getId(), 
"integer"));
   638         foreach ($a_answers as $answer) {
   642                 foreach ($existing as $idx => $item) {
   643                     if (trim($answer) === (
string) ($item[
"answer"] ?? 
'')) {
   645                         unset($existing[$idx]);
   647                         $id = (
int) ($item[
"id"] ?? 0);
   657                 if (isset(
$id) && is_int(
$id)) {
   664         if (count($existing)) {
   665             foreach ($existing as $item) {
   666                 if (isset($item[
"id"])) {
   685     public function saveVote(
int $a_user_id, array $a_answers): void
   691         foreach ($a_answers as $answer_id) {
   692             $fields = array(
"user_id" => array(
"integer", $a_user_id),
   693                 "poll_id" => array(
"integer", $this->
getId()),
   694                 "answer_id" => array(
"integer", $answer_id));
   695             $this->db->insert(
"il_poll_vote", $fields);
   701         $sql = 
"SELECT user_id" .
   702             " FROM il_poll_vote" .
   703             " WHERE poll_id = " . $this->db->quote($this->
getId(), 
"integer") .
   704             " AND user_id = " . $this->db->quote($a_user_id, 
"integer");
   705         $this->db->setLimit(1, 0);
   706         $set = $this->db->query($sql);
   707         return (
bool) $this->db->numRows($set);
   712         $sql = 
"SELECT COUNT(DISTINCT(user_id)) cnt" .
   713             " FROM il_poll_vote" .
   714             " WHERE poll_id = " . $this->db->quote($this->
getId(), 
"integer");
   715         $set = $this->db->query($sql);
   716         $row = $this->db->fetchAssoc($set);
   717         return (
int) $row[
"cnt"];
   725         $sql = 
"SELECT answer_id, count(*) cnt" .
   726             " FROM il_poll_vote" .
   727             " WHERE poll_id = " . $this->db->quote($this->
getId(), 
"integer") .
   728             " GROUP BY answer_id";
   729         $set = $this->db->query($sql);
   730         while ($row = $this->db->fetchAssoc($set)) {
   731             $cnt += (
int) $row[
"cnt"];
   732             $res[(
int) $row[
"answer_id"]] = array(
"abs" => (
int) $row[
"cnt"], 
"perc" => 0);
   735         foreach (
$res as 
$id => $item) {
   736             $abs = (
int) ($item[
'abs'] ?? 0);
   741                 $res[
$id][
"perc"] = $abs / $cnt * 100;
   754         $sql = 
"SELECT answer_id, user_id, firstname, lastname, login" .
   755             " FROM il_poll_vote" .
   756             " JOIN usr_data ON (usr_data.usr_id = il_poll_vote.user_id)" .
   757             " WHERE poll_id = " . 
$ilDB->quote($this->
getId(), 
"integer");
   758         $set = 
$ilDB->query($sql);
   759         while ($row = 
$ilDB->fetchAssoc($set)) {
   760             $user_id = (
int) ($row[
"user_id"] ?? 0);
   761             if (!isset(
$res[$user_id])) {
   762                 $res[$user_id] = $row;
   764             $res[$user_id][
"answers"][] = (
int) ($row[
"answer_id"] ?? 0);
 
static deleteAllEntries(int $ref_id)
Delete all db entries for ref id. 
 
setAccessBegin(int $a_value)
 
const VIEW_RESULTS_AFTER_PERIOD
 
const VIEW_RESULTS_AFTER_VOTE
 
hasUserVoted(int $a_user_id)
 
setSortResultByVotes(bool $a_value)
 
bool $result_sort_by_votes
 
setImage(string $a_value)
 
const VIEW_RESULTS_ALWAYS
 
setAccessType(int $a_value)
 
const SHOW_RESULTS_AS_PIECHART
 
const TIMINGS_DEACTIVATED
 
setAccessEnd(int $a_value)
 
setQuestion(string $a_value)
 
updateAnswer(int $a_id, string $a_text)
 
const SHOW_RESULTS_AS_BARCHART
 
setShowComments(bool $a_value)
 
ILIAS Filesystem Util Convert LegacyImages $image_converter
 
setVotingPeriod(bool $a_value)
 
setMaxNumberOfAnswers(int $a_value)
 
setShowResultsAs(int $a_value)
 
setNonAnonymous(bool $a_value)
 
setViewResults(int $a_value)
 
setVotingPeriodBegin(int $a_value)
 
updateAnswerPositions(array $a_pos)
 
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file 
 
__construct(int $a_id=0, bool $a_reference=true)
 
uploadImage(array $a_upload, bool $a_clone=false)
 
setOfflineStatus(bool $status)
 
saveAnswers(array $a_answers)
 
setAccessVisibility(bool $a_value)
 
static getItem(int $ref_id)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
doCreate(bool $clone_mode=false)
 
static initStorage(int $a_id, ?string $a_subdir=null)
 
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=0)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
ILIAS Notes Service $notes
 
saveAnswer(string $a_text, ?int $a_pos=null)
 
static _getInstance(int $a_copy_id)
 
Class ilObjectActivation. 
 
saveVote(int $a_user_id, array $a_answers)
 
getImageFullPath(bool $a_as_thumb=false)
 
setVotingPeriodEnd(int $a_value)