5 require_once 
"Services/Object/classes/class.ilObject2.php";
 
    6 require_once 
"Services/Object/classes/class.ilObjectActivation.php";
 
   53                 $this->online = (bool)$a_value;
 
   63                 $this->access_type = (int)$a_value;
 
   73                 $this->access_begin = (int)$a_value;
 
   83                 $this->access_end = (int)$a_value;
 
   93                 $this->access_visibility = (bool)$a_value;
 
  103                 $this->question = (string)$a_value;
 
  113                 $this->image = (string)$a_value;
 
  123                 $this->view_results = (int)$a_value;
 
  133                 $this->period = (bool)$a_value;
 
  143                 $this->period_begin = (int)$a_value;
 
  153                 $this->period_end = (int)$a_value;
 
  165                 $set = $ilDB->query(
"SELECT * FROM il_poll".
 
  166                                 " WHERE id = ".$ilDB->quote($this->getId(), 
"integer"));
 
  167                 $row = $ilDB->fetchAssoc($set);
 
  190                         "image" => array(
"text", $this->
getImage()),
 
  191                         "online_status" => array(
"integer", $this->
isOnline()),
 
  208                         $fields[
"id"] = array(
"integer", $this->
getId());
 
  210                         $ilDB->insert(
"il_poll", $fields);
 
  217                         include_once 
"Modules/Poll/classes/class.ilPollBlock.php";
 
  219                         $block->setType(
"poll");                
 
  220                         $block->setContextObjId($this->
getId());
 
  221                         $block->setContextObjType(
"poll");
 
  234                         $ilDB->update(
"il_poll", $fields,
 
  235                                 array(
"id"=>array(
"integer", $this->
getId())));
 
  245                                 $activation->update($this->ref_id);
 
  265                         $ilDB->manipulate(
"DELETE FROM il_poll".
 
  266                                 " WHERE id = ".$ilDB->quote($this->id, 
"integer"));
 
  296                         foreach($answers as $item)
 
  339                         include_once 
"Modules/Poll/classes/class.ilFSStoragePoll.php";
 
  356                 include_once 
"Modules/Poll/classes/class.ilFSStoragePoll.php";
 
  360                 $path = $storage->getAbsolutePath().
"/";
 
  364                         $path .= $a_subdir.
"/";
 
  391                 $clean_name = preg_replace(
"/[^a-zA-Z0-9\_\.\-]/", 
"", $a_upload[
"name"]);
 
  394                 $original = 
"org_".$this->id.
"_".$clean_name;
 
  395                 $thumb = 
"thb_".$this->id.
"_".$clean_name;
 
  396                 $processed = $this->
id.
"_".$clean_name;
 
  401                         $success = @move_uploaded_file($a_upload[
"tmp_name"], 
$path.$original);
 
  410                         chmod(
$path.$original, 0770);
 
  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);
 
  443                 $sql = 
"SELECT * FROM il_poll_answer".
 
  444                         " WHERE poll_id = ".$ilDB->quote($this->
getId(), 
"integer").
 
  446                 $set = $ilDB->query($sql);
 
  447                 while(
$row = $ilDB->fetchAssoc($set))
 
  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);
 
  473                 $id = $ilDB->nextId(
"il_poll_answer");
 
  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;         
 
  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)
 
  492                 $ilDB->insert(
"il_poll_answer", $fields);       
 
  501                 $ilDB->update(
"il_poll_answer",
 
  502                         array(
"answer" => array(
"text", $a_text)),
 
  503                         array(
"id" => array(
"integer", $a_id)));        
 
  511                 foreach($answers as $item)
 
  513                         $pos[$item[
"id"]] = $item[
"pos"];
 
  526                 foreach(array_keys($a_pos) as 
$id)
 
  530                         $ilDB->update(
"il_poll_answer",
 
  531                                 array(
"pos" => array(
"integer", $pos)),
 
  532                                 array(
"id" => array(
"integer", $id)));  
 
  542                         $ilDB->manipulate(
"DELETE FROM il_poll_vote".
 
  543                                 " WHERE answer_id = ".$ilDB->quote($this->getId(), 
"integer"));
 
  545                         $ilDB->manipulate(
"DELETE FROM il_poll_answer".
 
  546                                 " WHERE id = ".$ilDB->quote($a_id, 
"integer"));
 
  558                         $ilDB->manipulate(
"DELETE FROM il_poll_answer".
 
  559                                 " WHERE poll_id = ".$ilDB->quote($this->getId(), 
"integer"));
 
  569                         $ilDB->manipulate(
"DELETE FROM il_poll_vote".
 
  570                                 " WHERE poll_id = ".$ilDB->quote($this->getId(), 
"integer"));
 
  580                 foreach($a_answers as $answer)
 
  586                                 foreach($existing as $idx => $item)
 
  588                                         if(trim($answer) == $item[
"answer"])
 
  591                                                 unset($existing[$idx]);
 
  612                 if(
sizeof($existing))
 
  614                         foreach($existing as $item)
 
  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));
 
  645                 $ilDB->insert(
"il_poll_vote", $fields);
 
  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);
 
  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"];
 
  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))
 
  687                         $res[
$row[
"answer_id"]] = array(
"abs"=>$row[
"cnt"], 
"perc"=>0);
 
  692                         $res[
$id][
"perc"] = $item[
"abs"]/$cnt*100;
 
  695                 return array(
"perc"=>
$res, 
"total"=>$cnt);