public function filterResults($survey_code, $a_words = NULL, $emote = NULL, $intensity_distr = NULL, $starting = 0, $ending = 0) { $db = new DB(); $starting = (int) $starting; $ending = (int) $ending; $sql = "SELECT * FROM survey_result WHERE is_removed = 0 AND code = '" . mysql_real_escape_string($survey_code) . "'"; if ($a_words) { if (!is_array($a_words)) { $a_words = array($a_words); } $search_criteria = implode(" OR ", array_map(array($this, 'like_mapper'), array_filter($a_words))); if ($search_criteria) { $sql .= ' AND (' . $search_criteria . ')'; } } if ($emote) { $sql .= " AND emote= '" . mysql_real_escape_string($emote) . "' "; } if ($intensity_distr) { //pp, mp, pn or mn $emote_obj = new Emotion(); $a_positive = $emote_obj->listPositive(); $a_negative = $emote_obj->listNegative(); // Changed by Roger on 2011/03/08 to use new segmentation if ($intensity_distr == 'pp') { // Enthusiasts $sql .= " AND emote IN (" . implode(", ", array_map(array('DB', 'mysql_escape'), $a_positive)) . ") AND intensity_level >= '66' "; } else { if ($intensity_distr == 'pn') { // Detractors $sql .= " AND emote IN (" . implode(", ", array_map(array('DB', 'mysql_escape'), $a_negative)) . ") AND intensity_level >= '66' "; } else { if ($intensity_distr == 'mp') { // Participants $sql .= " AND intensity_level >= '34' AND intensity_level <= 65"; } else { if ($intensity_distr == 'mn') { // Indifferent $sql .= " AND intensity_level <= '33' "; } } } } /* OLD CODE HERE if($intensity_distr == 'pp'){ $sql .= " AND emote IN (" . implode(", ", array_map(array('DB','mysql_escape'),$a_positive)) . ") AND intensity_level > '50' "; }else if($intensity_distr == 'mp'){ $sql .= " AND emote IN (" . implode(", ", array_map(array('DB','mysql_escape'),$a_positive)) . ") AND intensity_level <= '50' "; }else if($intensity_distr == 'pn'){ $sql .= " AND emote IN (" . implode(", ", array_map(array('DB','mysql_escape'),$a_negative)) . ") AND intensity_level > '50' "; }else if($intensity_distr == 'mn'){ $sql .= " AND emote IN (" . implode(", ", array_map(array('DB','mysql_escape'),$a_negative)) . ") AND intensity_level <= '50' "; } */ } //Sorting by time by default $sql .= ' ORDER BY end_time DESC '; $limit_str = ''; if ($starting) { $limit_str = ' LIMIT ' . $starting; if ($ending) { $limit_str .= ', ' . $ending; } else { $limit_str .= ', 100'; } } else { if ($ending) { $limit_str = ' LIMIT 0,' . $ending; } } $sql .= $limit_str; return $db->runQuery($sql); }
public function call() { try { $survey_code = strtoupper($this->getArgument('survey')); $survey_mng = new SurveyManager(); if (!$survey_code || !$survey_mng->isSurvey($survey_code)) { $answer = new Answer('error', array("error" => "Survey not found"), 'xml'); $answer->setXMLOpt("rootName", "dashboard"); return $answer; } $emotion_obj = new Emotion(); $emote = NULL; $intensity_distr = NULL; $subset = $this->getArgument('subset'); if ($subset) { if ($emotion_obj->isEmotion($subset)) { $emote = $subset; } else { $intensity_distr = $subset; } } $a_split_words = preg_split('/[\\n\\r\\s]+/', $this->getArgument('search')); $a_words = array(); foreach ($a_split_words as $word) { $a_words[$word] = 1; } $a_words = array_keys($a_words); $a_words = array_filter($a_words); $survey_result_mng = new SurveyResultManager(); $starting = $this->getArgument('starting'); $ending = $this->getArgument('ending'); if ($survey_result_mng->isSurveyFree($survey_code)) { $starting = $starting ? $starting : 0; $ending = $ending ? $ending : 0; if (!$starting && !$ending) { $ending = 50; } else { if ($ending > $starting + 50) { $ending = $starting + 50; } } } $a_survey_results = $survey_result_mng->filterResults($survey_code, $a_words, $emote, $intensity_distr, $starting, $ending); $a_results = array(); foreach ($a_survey_results as $result) { $verbatims = $result['verbatim']; if ($a_words) { $patterns = array(); $replacements = array(); foreach ($a_words as $search_word) { array_push($patterns, "/{$search_word}/"); array_push($replacements, "<b>{$search_word}</b>"); } $verbatims = preg_replace($patterns, $replacements, $verbatims); } $a_verbatims = preg_split('/[\\n\\r\\s]+/', $verbatims); $verbatims = implode(" ", $a_verbatims); $intensity_level = 1; if ($result['intensity_level'] >= 33 && $result['intensity_level'] < 66) { $intensity_level = 2; } else { if ($result['intensity_level'] >= 66) { $intensity_level = 3; } } list($timestamp, $ts_color) = verbatim_date($result['end_time']); array_push($a_results, array($verbatims, "_attributes" => array("face" => $result['emote'] . "_intensity_{$intensity_level}", "id" => $result['survey_result_id'], 'timestamp' => $timestamp, 'ts_color' => $ts_color))); } //$test_str = var_export($a_survey_results,true); $to_xml = array(); if (count($a_results)) { $to_xml = array('verbatim' => $a_results); } $answer = new Answer('ok', $to_xml, 'xml'); $answer->setXMLOpt("rootName", "verbatims"); $answer->setXMLOpt("rootAttributes", array("survey" => $survey_code, "search" => $this->getArgument('search'), "starting" => $this->getArgument('starting'), "ending" => $this->getArgument('ending'), "subset" => $this->getArgument('subset'))); return $answer; } catch (Exception $e) { $answer = new Answer('error', array("error" => $e->getMessage()), 'xml'); $answer->setXMLOpt("rootName", "verbatims"); return $answer; } }
echo $_SESSION["user"]["user_nick_name"]; ?> </li> <li><a href="logout.php">Logout</a></li> </ul> </div> </nav> <div class="" > <h2>Comments</h2> <h3>Persons who was say "thank" you.</h3> <?php foreach ($comments as $comment) { Emotion::add_emotion($comment['comment_content']); echo "<p><span class='comment_date'>{$comment['comment_reg_datetime']}</span> | "; echo "<span class='comment_content'>{$comment['comment_content']}</span> | "; echo "<span class='comment_content'>{$comment['who_thank']}</span></p>"; } ?> </div> <!--Import jQuery before materialize.js--> <script type="text/javascript" src="/bower_components/jquery/dist/jquery.min.js"></script> <script> $("input[name='keyword']").focus(); </script> <!-- Compiled and minified JavaScript --> <script src="/bower_components/Materialize/dist/js/materialize.min.js"></script> </body>
</div> <div style="border-left: 1px solid #ccc;float: left;width: 48%;margin-left: 5px;padding-left: 5px;"> <table class="striped bordered" > <thead> <th>EID <a href="list.php?sort=1">▲</a><a href="list.php?sort=2">▼</a></th> <th>Image</th> <th style="width:140px">Nick Name <a href="list.php?sort=3">▲</a><a href="list.php?sort=4">▼</a></th> <th>Last Comment</th> <th>Thanks</th> </thead> <tbody> <?php for ($i = 0; $i < count($users); $i++) { if ($i % 2 == 1) { $img = "<img class='img_avatar' src='" . PATH_IMG . "{$users[$i]['user_img']}' width='40' height='55' />"; Emotion::add_emotion($users[$i]['last_comment']); echo "<tr>"; echo "<td>{$users[$i]['user_eid']}</td>"; echo "<td>{$img}</td>"; echo "<td>{$users[$i]['user_nick_name']}</td>"; echo "<td>{$users[$i]['last_comment']}"; if ($users[$i]['user_id'] == $_SESSION['user']['user_id']) { echo "<br><a href='whothank.php'>Persons who was say 'thank' you.<a/>"; } echo "</td>"; echo "<td>"; echo "\r\n\t\t\t\t\t\t\t<a href='thanks.php?uid={$users[$i]['user_id']}&img={$users[$i]['user_gwid']}' class='waves-effect waves-light blue darken-2 btn'>Thanks!</a>\r\n\t\t\t\t\t\t</td>"; echo "</tr>"; } } ?>