5 require_once
"Services/Object/classes/class.ilObject2.php";
6 require_once
"Services/Object/classes/class.ilObjectActivation.php";
63 $this->online = (bool)$a_value;
73 $this->access_type = (int)$a_value;
83 $this->access_begin = (int)$a_value;
93 $this->access_end = (int)$a_value;
103 $this->access_visibility = (bool)$a_value;
113 $this->question = (string)$a_value;
123 $this->image = (string)$a_value;
133 $this->view_results = (int)$a_value;
143 $this->period = (bool)$a_value;
153 $this->period_begin = (int)$a_value;
163 $this->period_end = (int)$a_value;
173 $this->max_number_answers = (int)$a_value;
183 $this->result_sort_by_votes = (bool)$a_value;
193 $this->mode_non_anonymous = (bool)$a_value;
203 $this->show_comments = (bool)$a_value;
213 $this->show_results_as = (int)$a_value;
225 $set = $ilDB->query(
"SELECT * FROM il_poll".
226 " WHERE id = ".$ilDB->quote($this->getId(),
"integer"));
227 $row = $ilDB->fetchAssoc($set);
241 include_once(
"./Services/Notes/classes/class.ilNote.php");
258 "image" => array(
"text", $this->
getImage()),
259 "online_status" => array(
"integer", $this->
isOnline()),
280 $fields[
"id"] = array(
"integer", $this->
getId());
282 $ilDB->insert(
"il_poll", $fields);
289 include_once
"Modules/Poll/classes/class.ilPollBlock.php";
291 $block->setType(
"poll");
292 $block->setContextObjId($this->
getId());
293 $block->setContextObjType(
"poll");
306 $ilDB->update(
"il_poll", $fields,
307 array(
"id"=>array(
"integer", $this->
getId())));
310 include_once(
"./Services/Notes/classes/class.ilNote.php");
320 $activation->update($this->ref_id);
340 $ilDB->manipulate(
"DELETE FROM il_poll".
341 " WHERE id = ".$ilDB->quote($this->id,
"integer"));
368 if(!$cp_options->isRootNode($this->getRefId()))
382 foreach($answers as $item)
425 include_once
"Modules/Poll/classes/class.ilFSStoragePoll.php";
442 include_once
"Modules/Poll/classes/class.ilFSStoragePoll.php";
446 $path = $storage->getAbsolutePath().
"/";
450 $path .= $a_subdir.
"/";
477 $clean_name = preg_replace(
"/[^a-zA-Z0-9\_\.\-]/",
"", $a_upload[
"name"]);
480 $original =
"org_".$this->id.
"_".$clean_name;
481 $thumb =
"thb_".$this->id.
"_".$clean_name;
482 $processed = $this->
id.
"_".$clean_name;
487 $success = @move_uploaded_file($a_upload[
"tmp_name"],
$path.$original);
496 chmod(
$path.$original, 0770);
503 ilUtil::execConvert($original_file.
"[0] -geometry \"100x100>\" -quality 100 PNG:".$thumb_file);
504 ilUtil::execConvert($original_file.
"[0] -geometry \"".self::getImageSize().
">\" -quality 100 PNG:".$processed_file);
529 $sql =
"SELECT * FROM il_poll_answer".
530 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer").
532 $set = $ilDB->query($sql);
533 while(
$row = $ilDB->fetchAssoc($set))
544 $sql =
"SELECT * FROM il_poll_answer".
545 " WHERE id = ".$ilDB->quote($a_id,
"integer");
546 $set = $ilDB->query($sql);
547 return (array)$ilDB->fetchAssoc($set);
559 $id = $ilDB->nextId(
"il_poll_answer");
564 $sql =
"SELECT max(pos) pos".
565 " FROM il_poll_answer".
566 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer");
567 $set = $ilDB->query($sql);
568 $a_pos = $ilDB->fetchAssoc($set);
569 $a_pos = (int)$a_pos[
"pos"]+10;
573 "id" => array(
"integer",
$id),
574 "poll_id" => array(
"integer", $this->
getId()),
575 "answer" => array(
"text", trim($a_text)),
576 "pos" => array(
"integer", $a_pos)
578 $ilDB->insert(
"il_poll_answer", $fields);
587 $ilDB->update(
"il_poll_answer",
588 array(
"answer" => array(
"text", $a_text)),
589 array(
"id" => array(
"integer", $a_id)));
597 foreach($answers as $item)
599 $pos[$item[
"id"]] = $item[
"pos"];
612 foreach(array_keys($a_pos) as
$id)
616 $ilDB->update(
"il_poll_answer",
617 array(
"pos" => array(
"integer", $pos)),
618 array(
"id" => array(
"integer", $id)));
628 $ilDB->manipulate(
"DELETE FROM il_poll_vote".
629 " WHERE answer_id = ".$ilDB->quote($this->getId(),
"integer"));
631 $ilDB->manipulate(
"DELETE FROM il_poll_answer".
632 " WHERE id = ".$ilDB->quote($a_id,
"integer"));
644 $ilDB->manipulate(
"DELETE FROM il_poll_answer".
645 " WHERE poll_id = ".$ilDB->quote($this->getId(),
"integer"));
655 $ilDB->manipulate(
"DELETE FROM il_poll_vote".
656 " WHERE poll_id = ".$ilDB->quote($this->getId(),
"integer"));
666 foreach($a_answers as $answer)
672 foreach($existing as $idx => $item)
674 if(trim($answer) == $item[
"answer"])
677 unset($existing[$idx]);
698 if(
sizeof($existing))
700 foreach($existing as $item)
729 if(!is_array($a_answers))
731 $a_answers = array($a_answers);
734 foreach($a_answers as $answer_id)
736 $fields = array(
"user_id" => array(
"integer", $a_user_id),
737 "poll_id" => array(
"integer", $this->
getId()),
738 "answer_id" => array(
"integer", $answer_id));
739 $ilDB->insert(
"il_poll_vote", $fields);
747 $sql =
"SELECT user_id".
748 " FROM il_poll_vote".
749 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer").
750 " AND user_id = ".$ilDB->quote($a_user_id,
"integer");
752 $set = $ilDB->query($sql);
753 return (
bool)$ilDB->numRows($set);
760 $sql =
"SELECT COUNT(DISTINCT(user_id)) cnt".
761 " FROM il_poll_vote".
762 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer");
763 $set = $ilDB->query($sql);
764 $row = $ilDB->fetchAssoc($set);
765 return (
int)
$row[
"cnt"];
775 $sql =
"SELECT answer_id, count(*) cnt".
776 " FROM il_poll_vote".
777 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer").
778 " GROUP BY answer_id";
779 $set = $ilDB->query($sql);
780 while(
$row = $ilDB->fetchAssoc($set))
783 $res[
$row[
"answer_id"]] = array(
"abs"=>$row[
"cnt"],
"perc"=>0);
788 $res[
$id][
"perc"] = $item[
"abs"]/$cnt*100;
800 $sql =
"SELECT answer_id, user_id, firstname, lastname, login".
801 " FROM il_poll_vote".
802 " JOIN usr_data ON (usr_data.usr_id = il_poll_vote.user_id)".
803 " WHERE poll_id = ".$ilDB->quote($this->
getId(),
"integer");
804 $set = $ilDB->query($sql);
805 while(
$row = $ilDB->fetchAssoc($set))
811 $res[$row[
"user_id"]][
"answers"][] = $row[
"answer_id"];