예제 #1
0
 public static function filterQueries($queries, $user)
 {
     $result = array();
     foreach ($queries as $qid => $title) {
         $qdao = new QueryDAO();
         $segments = $qdao->getSegmentsByQueryId($qid);
         $tristate = User::createPropertyMap(0);
         foreach (array_values($segments) as $segment) {
             $prop = $segment[0];
             $value = $segment[1];
             if ($tristate[$prop] != 1) {
                 $tristate[$prop] = User::indexOfUserValue($prop, $user) == $value ? 1 : -1;
             }
         }
         $applies = true;
         foreach (array_values($tristate) as $value) {
             if ($value == -1) {
                 $applies = false;
                 break;
             }
         }
         if ($applies) {
             $result[$qid] = $title;
         }
     }
     return $result;
 }
예제 #2
0
 public function searchQuery($queryTitle)
 {
     $dao = new QueryDAO();
     $queryId = $dao->getQueryIdByQueryTitle($queryTitle);
     if ($queryId != -1) {
         $this->result = $dao->getQueryById($queryId);
     } else {
         $this->result = -1;
     }
     $uid = getUID();
     $udao = new UserDAO();
     $this->result = ListQueriesController::filterQueries($this->result, $udao->selectUserById($uid));
 }
<?php

namespace Qnet\Controller;

require_once dirname(__FILE__) . '\\..\\..\\util.php';
require_dao('QueryDAO');
require_controller('listqueriescontroller');
require_dao('userDAO');
use Qnet\Dao\QueryDAO;
use Qnet\Dao\UserDAO;
use Qnet\Controller\ListQueriesController;
$searchQuery = $_GET["q"];
if ($searchQuery != null) {
    $userDaoIns = new QueryDAO();
    $queriesArray = $userDaoIns->getQueriesByPartialString($searchQuery);
    $uid = getUID();
    $udao = new UserDAO();
    $queriesArray = ListQueriesController::filterQueries($queriesArray, $udao->selectUserById($uid));
    $arraySize = count($queriesArray);
    $answer = "";
    foreach (array_values($queriesArray) as $queryname) {
        $answer = $answer . $queryname . "\n";
    }
    echo $answer;
}
<?php

namespace Qnet\Controller;

require_once dirname(__FILE__) . '\\..\\..\\util.php';
require_dao('queryDAO');
require_dao('answersDAO');
use Qnet\Dao\QueryDAO;
use Qnet\Dao\AnswersDAO;
$uid = getUID();
$qid = $_POST['qid'];
$dao = new AnswersDAO();
$qdao = new QueryDAO();
$questions = $qdao->getQuestionsByQueryId($qid);
$aid = $dao->persistAnswer($uid, $qid);
foreach (array_keys($questions) as $id) {
    $dao->persistAnswerOption($aid, $_POST['question' . $id]);
}
header("Location: /Qnet/target/classes/php/qnet/ui/answerquery.php?qid=" . $qid . "&commit=ok");
예제 #5
0
<?php

/**
 * Created by IntelliJ IDEA.
 * User: Tomi
 * Date: 23/06/2010
 * Time: 10:08:29
 * To change this template use File | Settings | File Templates.
 */
use PHPUnit_Framework_TestCase;
require_once dirname(__FILE__) . '\\..\\util.php';
require_dao('queryDAO');
require_dao('createQueryDAO');
use Qnet\Dao\QueryDAO;
use Qnet\Dao\CreateQueryDAO;
$cqd = new CreateQueryDAO();
$qd = new QueryDAO();
$cqd->initTransaction();
$expectedId = $cqd->persistNewQuery("testQuery", 1);
if ($expectedId == null) {
    echo "Coudn't persist query";
}
$foundId = $qd->getQueryIdByQueryTitle("testQuery");
if ($expectedId != $foundId) {
    echo "Queries id doesn't match. Expected {$expectedId}, found {$foundId}";
}