5 require_once
"Services/Object/classes/class.ilObject2.php";
6 require_once
"Services/Object/classes/class.ilObjectActivation.php";
49 $this->db = $DIC->database();
56 parent::__construct($a_id, $a_reference);
66 $this->online = (bool) $a_value;
76 $this->access_type = (int) $a_value;
86 $this->access_begin = (int) $a_value;
96 $this->access_end = (int) $a_value;
106 $this->access_visibility = (bool) $a_value;
116 $this->question = (
string) $a_value;
136 $this->view_results = (int) $a_value;
146 $this->period = (bool) $a_value;
156 $this->period_begin = (int) $a_value;
166 $this->period_end = (int) $a_value;
176 $this->max_number_answers = (int) $a_value;
186 $this->result_sort_by_votes = (bool) $a_value;
196 $this->mode_non_anonymous = (bool) $a_value;
206 $this->show_comments = (bool) $a_value;
216 $this->show_results_as = (int) $a_value;
228 $set =
$ilDB->query(
"SELECT * FROM il_poll" .
229 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
244 include_once(
"./Services/Notes/classes/class.ilNote.php");
282 if ($this->
getId()) {
284 $fields[
"id"] =
array(
"integer", $this->
getId());
286 $ilDB->insert(
"il_poll", $fields);
293 include_once
"Modules/Poll/classes/class.ilPollBlock.php";
295 $block->setType(
"poll");
296 $block->setContextObjId($this->
getId());
297 $block->setContextObjType(
"poll");
306 if ($this->
getId()) {
316 include_once(
"./Services/Notes/classes/class.ilNote.php");
325 $activation->update($this->ref_id);
334 if ($this->
getId()) {
342 $ilDB->manipulate(
"DELETE FROM il_poll" .
343 " WHERE id = " .
$ilDB->quote($this->id,
"integer"));
365 $new_obj->uploadImage(
$image,
true);
371 if (!$cp_options->isRootNode($this->getRefId())) {
372 $new_obj->setOnline($this->
isOnline());
383 foreach ($answers as $item) {
384 $new_obj->saveAnswer($item[
"answer"]);
420 include_once
"Modules/Poll/classes/class.ilFSStoragePoll.php";
437 include_once
"Modules/Poll/classes/class.ilFSStoragePoll.php";
441 $path = $storage->getAbsolutePath() .
"/";
444 $path .= $a_subdir .
"/";
446 if (!is_dir(
$path)) {
469 $clean_name = preg_replace(
"/[^a-zA-Z0-9\_\.\-]/",
"", $a_upload[
"name"]);
472 $original =
"org_" . $this->
id .
"_" . $clean_name;
473 $thumb =
"thb_" . $this->
id .
"_" . $clean_name;
474 $processed = $this->
id .
"_" . $clean_name;
478 $success = ilUtil::moveUploadedFile($a_upload[
"tmp_name"], $original,
$path . $original);
484 chmod(
$path . $original, 0770);
491 ilUtil::execConvert($original_file .
"[0] -geometry \"100x100>\" -quality 100 PNG:" . $thumb_file);
492 ilUtil::execConvert($original_file .
"[0] -geometry \"" . self::getImageSize() .
">\" -quality 100 PNG:" . $processed_file);
517 $sql =
"SELECT * FROM il_poll_answer" .
518 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer") .
520 $set =
$ilDB->query($sql);
531 $sql =
"SELECT * FROM il_poll_answer" .
532 " WHERE id = " .
$ilDB->quote($a_id,
"integer");
533 $set =
$ilDB->query($sql);
541 if (!trim($a_text)) {
545 $id =
$ilDB->nextId(
"il_poll_answer");
549 $sql =
"SELECT max(pos) pos" .
550 " FROM il_poll_answer" .
551 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer");
552 $set =
$ilDB->query($sql);
553 $a_pos =
$ilDB->fetchAssoc($set);
554 $a_pos = (int) $a_pos[
"pos"]+10;
559 "poll_id" =>
array(
"integer", $this->
getId()),
560 "answer" =>
array(
"text", trim($a_text)),
561 "pos" =>
array(
"integer", $a_pos)
563 $ilDB->insert(
"il_poll_answer", $fields);
584 foreach ($answers as $item) {
585 $pos[$item[
"id"]] = $item[
"pos"];
598 foreach (array_keys($a_pos) as
$id) {
614 $ilDB->manipulate(
"DELETE FROM il_poll_vote" .
615 " WHERE answer_id = " .
$ilDB->quote($this->getId(),
"integer"));
617 $ilDB->manipulate(
"DELETE FROM il_poll_answer" .
618 " WHERE id = " .
$ilDB->quote($a_id,
"integer"));
626 if ($this->
getId()) {
629 $ilDB->manipulate(
"DELETE FROM il_poll_answer" .
630 " WHERE poll_id = " .
$ilDB->quote($this->getId(),
"integer"));
638 if ($this->
getId()) {
639 $ilDB->manipulate(
"DELETE FROM il_poll_vote" .
640 " WHERE poll_id = " .
$ilDB->quote($this->getId(),
"integer"));
650 foreach ($a_answers as $answer) {
654 foreach ($existing as $idx => $item) {
655 if (trim($answer) == $item[
"answer"]) {
657 unset($existing[$idx]);
676 if (
sizeof($existing)) {
677 foreach ($existing as $item) {
703 if (!is_array($a_answers)) {
704 $a_answers =
array($a_answers);
707 foreach ($a_answers as $answer_id) {
708 $fields =
array(
"user_id" =>
array(
"integer", $a_user_id),
709 "poll_id" =>
array(
"integer", $this->
getId()),
710 "answer_id" =>
array(
"integer", $answer_id));
711 $ilDB->insert(
"il_poll_vote", $fields);
719 $sql =
"SELECT user_id" .
720 " FROM il_poll_vote" .
721 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer") .
722 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer");
724 $set =
$ilDB->query($sql);
725 return (
bool)
$ilDB->numRows($set);
732 $sql =
"SELECT COUNT(DISTINCT(user_id)) cnt" .
733 " FROM il_poll_vote" .
734 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer");
735 $set =
$ilDB->query($sql);
737 return (
int)
$row[
"cnt"];
747 $sql =
"SELECT answer_id, count(*) cnt" .
748 " FROM il_poll_vote" .
749 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer") .
750 " GROUP BY answer_id";
751 $set =
$ilDB->query($sql);
754 $res[
$row[
"answer_id"]] =
array(
"abs"=>$row[
"cnt"],
"perc"=>0);
757 foreach (
$res as
$id => $item) {
758 $res[
$id][
"perc"] = $item[
"abs"]/$cnt*100;
770 $sql =
"SELECT answer_id, user_id, firstname, lastname, login" .
771 " FROM il_poll_vote" .
772 " JOIN usr_data ON (usr_data.usr_id = il_poll_vote.user_id)" .
773 " WHERE poll_id = " .
$ilDB->quote($this->
getId(),
"integer");
774 $set =
$ilDB->query($sql);
776 if (!isset(
$res[
$row[
"user_id"]])) {
779 $res[$row[
"user_id"]][
"answers"][] = $row[
"answer_id"];
deleteImage()
remove existing file
const VIEW_RESULTS_AFTER_PERIOD
const VIEW_RESULTS_AFTER_VOTE
getImageFullPath($a_as_thumb=false)
Get image incl.
updateAnswer($a_id, $a_text)
setVotingPeriod($a_value)
const VIEW_RESULTS_ALWAYS
setAccessVisibility($a_value)
static getItem($a_ref_id)
Get item data.
const SHOW_RESULTS_AS_PIECHART
setSortResultByVotes($a_value)
const TIMINGS_DEACTIVATED
setShowResultsAs($a_value)
setShowComments($a_value)
saveAnswer($a_text, $a_pos=null)
setMaxNumberOfAnswers($a_value)
const SHOW_RESULTS_AS_BARCHART
saveVote($a_user_id, $a_answers)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
static execConvert($args)
execute convert command
updateAnswerPositions(array $a_pos)
uploadImage(array $a_upload, $a_clone=false)
Upload new image file.
Create styles array
The data for the language used.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
saveAnswers(array $a_answers)
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type)
Are comments activated for object?
doCloneObject($new_obj, $a_target_id, $a_copy_id=0)
Clone poll.
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
static escapeShellArg($a_arg)
__construct($a_id=0, $a_reference=true)
Class ilObject2 This is an intermediate progress of ilObject class.
setNonAnonymous($a_value)
setVotingPeriodBegin($a_value)
Class ilObjectActivation.
setVotingPeriodEnd($a_value)