Commit 2cda7fb8 authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Adds HTMLTABLE() syntax in artifact language

parent 00e6641a
......@@ -8,10 +8,12 @@ require_once("lib/wirk.php");
* Remove syntactic sugar from guards and actions in artifacts
*
* @param $str string: The string to unsugar
* @param $conn A valid pdo connection (optional)
* @return stringbool string: sugar-free string
*/
function sugarFree($str){
// TODO add $conn
function sugarFree($str,$conn=null){
if($str=="none")
$str="select true from dual";
if (preg_match("/^task ([0-9]+) is answered/",$str,$matches)){
......@@ -36,6 +38,11 @@ function sugarFree($str){
$str="select @CHECKER:='".$matches[1]."'";
}
if (preg_match("/^select @(.*):=HTMLTABLE\((.*)\)$/",$str,$matches)){
$str="select @".$matches[1].":=";
$str.=$conn->quote(showQueryAnswerAsString($conn, "", $matches[2]));
}
if (preg_match("/^prepare task ([0-9]+) as (basic|message|multi-line input)/",$str,$matches)){
$str="
select @TITLE:='default title';
......@@ -131,7 +138,7 @@ function updateonce($conn, $artifact, $artifactid, $count)
if( isset($artifact[$node][$dest]["guard"]) ){
$guard=$artifact[$node][$dest]["guard"];
$guard=sugarFree($guard);
$guard=sugarFree($guard,$conn);
}
else throw new Exception("No guard in artifact");
......@@ -265,7 +272,7 @@ function step($conn, $artifactid, $from, $to, $guard, $actions)
$conn->query("update Artifact set node=$to where ID=$artifactid");
foreach ($actions as $action) {
debug("executing $action");
$action=sugarFree($action);
$action=sugarFree($action,$conn);
$action=str_replace("CURRENT_ARTIFACT",$artifactid, $action);
if (preg_match("/^call wirk image annotator as task ([0-9]+) for '(.*)'/",$action,$matches)){
......
......@@ -29,7 +29,10 @@
"-- delete from profile",
"delete from Task where artifact=CURRENT_ARTIFACT",
"use 'headwork-step2' as template",
"insert into Task(id,title,description,body,type,artifact) select 2,'demo','Step 2: Making decisions',replace(@TEMPLATE,'TAG1',if(value='2','right!','wrong, sorry')),0,CURRENT_ARTIFACT from Answer where idtask=1 and artifact=CURRENT_ARTIFACT and user=SESSION_USER",
"select @BODY:=replace(@TEMPLATE,'TAG1',if(value='2','right!','wrong, sorry')),0,CURRENT_ARTIFACT from Answer where idtask=1 and artifact=CURRENT_ARTIFACT and user=SESSION_USER",
"select @TABLE:=HTMLTABLE(select id from users limit 10)",
"select @BODY:=replace(@BODY,'TAG2',@TABLE)",
"insert into Task(id,title,description,body,type,artifact) values (2,'demo','Step 2: Making decisions',@BODY,0,CURRENT_ARTIFACT)",
"delete from Profile where idartifact=CURRENT_ARTIFACT",
"insert into Profile values (2,CURRENT_ARTIFACT,1)"
]
......
......@@ -10,10 +10,12 @@ Thanks. In the meantime, four other participants have given their opinion. Here
<tr><td>Anonimal5</td><td>1</td></tr>
<tr><td>Sagarman</td><td>2</td></tr>
</table>
TAG2
</center>
</p>
<p>
In order to decide, crowdsourcing platforms typically perform MAJORITY VOTING. Hence, we conclude that there were 2 leopards. You where
In order to decide, crowdsourcing platforms typically perform MAJORITY VOTING. Hence, we conclude
that there were 2 leopards. You where
TAG1.
</p>
<p>Press submit for the next step.</p>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment