Changeset a6f44d6b86937e3b7a7f84eea82557562396a359
- Timestamp:
- 06/10/09 15:50:26
(9 years ago)
- Author:
- Umar Farooq <umar@omniti.com>
- git-committer:
- Umar Farooq <umar@omniti.com> 1244649026 +0000
- git-parent:
[e85722c8867aa49780d7494d535942c6d3669945]
- git-author:
- Umar Farooq <umar@omniti.com> 1244649026 +0000
- Message:
creating graphs from templates now track their genesis, and update if they match with an existing graph
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
r0a3bdfb |
ra6f44d6 |
|
155 | 155 | sidvarclass = $(selected).parents(".collapsable:eq(0)").find("span").attr("class"); |
---|
156 | 156 | if(sidvar_sid_map[sidvarclass] == undefined) sidvar_sid_map[sidvarclass] = Array(); |
---|
157 | | sids[i] = $(selected).val(); |
---|
158 | | sidvar_sid_map[sidvarclass].push($(selected).val()); |
---|
| 157 | sval = parseInt($(selected).val()); |
---|
| 158 | sids[i] = sval; |
---|
| 159 | sidvar_sid_map[sidvarclass].push(sval); |
---|
159 | 160 | }); |
---|
160 | 161 | |
---|
| 162 | sidvars.sort(); |
---|
| 163 | textvars.sort(); |
---|
| 164 | |
---|
161 | 165 | for (i=0; i<sidvars.length; i++){ |
---|
| 166 | sidvar_sid_map[sidvars[i]].sort(); |
---|
162 | 167 | sidvals+="&"+sidvars[i]+"="+sidvar_sid_map[sidvars[i]].join(","); |
---|
163 | 168 | } |
---|
164 | 169 | |
---|
165 | 170 | //if we have selected atleast one sid |
---|
166 | | if(sids.length > 0){ |
---|
| 171 | if(sids.length > 0){ |
---|
167 | 172 | var dataString = 'templateid='+templateid+'&textvars='+textvars.join(',')+'&sidvars='+sidvars.join(',')+textvals+sidvals; |
---|
168 | 173 | $.ajax({ |
---|
r43db6fd |
ra6f44d6 |
|
11 | 11 | $var_vals = array(); |
---|
12 | 12 | |
---|
| 13 | $genesis_base = "templateid=".$templateid; |
---|
| 14 | |
---|
13 | 15 | foreach ($text_vars as $tv) { |
---|
14 | 16 | $rparams[$tv] = $_POST[$tv]; |
---|
| 17 | $genesis_base.=$tv."=".$_POST[$tv]; |
---|
15 | 18 | } |
---|
16 | 19 | |
---|
… | … | |
21 | 24 | //this number is used so we dont end up trying to create multiple graphs with the same title |
---|
22 | 25 | $graph_num = 1; |
---|
23 | | |
---|
24 | | function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $rparams, $templateid, $graph_num) |
---|
| 26 | |
---|
| 27 | //this function will create each combination of values for each SID placeholder, against the TEXT placeholders set |
---|
| 28 | //then, it will create graphs for each of these combinations, updating a graph if one already exists with the same genesis |
---|
| 29 | //a graph's genesis is composed of its templateid, its text vars and their values, and its sid vars and their values, and |
---|
| 30 | //should be unique among saved_graphs |
---|
| 31 | function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num) |
---|
25 | 32 | { |
---|
26 | | |
---|
27 | | if ($i >= count($var_vals)){ |
---|
| 33 | $genesis = $genesis_base; |
---|
| 34 | if ($i >= count($var_vals)){ |
---|
28 | 35 | $vals_combo = explode(",", $combo); |
---|
29 | 36 | for ($j=0; $j<count($vals_combo); $j++) { |
---|
30 | 37 | $rparams[$sid_vars[$j]] = $vals_combo[$j]; |
---|
| 38 | $genesis.=",".$sid_vars[$j]."=".$vals_combo[$j]; |
---|
31 | 39 | } |
---|
| 40 | |
---|
32 | 41 | $template = new Reconnoiter_GraphTemplate($templateid); |
---|
33 | 42 | $db = Reconnoiter_DB::getDB(); |
---|
34 | | $graph_json = $template->newGraph($rparams); |
---|
| 43 | $graph_json = $template->getNewGraphJSON($rparams); |
---|
35 | 44 | $graph_json = stripslashes($graph_json); |
---|
36 | 45 | $graph_json = json_decode($graph_json, true); |
---|
37 | 46 | $graph_json['title'] = $graph_json['title'].$graph_num; |
---|
| 47 | $graph_json['genesis'] = $genesis; |
---|
| 48 | |
---|
| 49 | $grow = $db->getGraphByGenesis($genesis); |
---|
| 50 | if($grow['graphid']) { |
---|
| 51 | $graph_json['id'] = $grow['graphid']; |
---|
| 52 | $graph_id = $db->saveGraph($graph_json); |
---|
| 53 | return; |
---|
| 54 | } |
---|
38 | 55 | $graph_id = $db->saveGraph($graph_json); |
---|
39 | 56 | $graph_json['id'] = $graph_id; |
---|
40 | 57 | $graph_id = $db->saveGraph($graph_json); |
---|
| 58 | return; |
---|
41 | 59 | } |
---|
42 | 60 | else |
---|
… | … | |
44 | 62 | foreach ($var_vals[$i] as $vval){ |
---|
45 | 63 | $graph_num++; |
---|
46 | | createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $rparams, $templateid, $graph_num); |
---|
| 64 | createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num); |
---|
47 | 65 | } |
---|
48 | 66 | } |
---|
49 | 67 | } |
---|
50 | 68 | |
---|
51 | | createGraphsFromCombos('', $var_vals, 0, $sid_vars, $rparams, $templateid, $graph_num); |
---|
| 69 | createGraphsFromCombos('', $var_vals, 0, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num); |
---|
52 | 70 | |
---|
53 | 71 | ?> |
---|
r2444c13 |
ra6f44d6 |
|
419 | 419 | return $row; |
---|
420 | 420 | } |
---|
| 421 | function getGraphByGenesis($genesis) { |
---|
| 422 | $sth = $this->db->prepare("select * |
---|
| 423 | from prism.saved_graphs |
---|
| 424 | where genesis=?"); |
---|
| 425 | $sth->execute(array($genesis)); |
---|
| 426 | $row = $sth->fetch(); |
---|
| 427 | return $row; |
---|
| 428 | } |
---|
421 | 429 | function deleteWorksheetGraph($ws_id, $graphid) { |
---|
422 | 430 | $sth = $this->db->prepare("delete from prism.saved_worksheets_dep |
---|
… | … | |
470 | 478 | $sth = $this->db->prepare("insert into prism.saved_graphs |
---|
471 | 479 | (graphid, json, title, |
---|
472 | | last_update) |
---|
473 | | values (?, ?, ?, current_timestamp)"); |
---|
474 | | $sth->execute(array($id, $json, $graph['title'])); |
---|
| 480 | last_update, genesis) |
---|
| 481 | values (?, ?, ?, current_timestamp, ?)"); |
---|
| 482 | $sth->execute(array($id, $json, $graph['title'], $graph['genesis'])); |
---|
475 | 483 | } |
---|
476 | 484 | $sth = $this->db->prepare("insert into prism.saved_graphs_dep |
---|
r477b283 |
ra6f44d6 |
|
27 | 27 | return Reconnoiter_GraphTemplate::find_sids($this->row['json']); |
---|
28 | 28 | } |
---|
29 | | public function newGraph($params) { |
---|
| 29 | public function getNewGraphJSON($params) { |
---|
30 | 30 | $v = $this->variables(); |
---|
31 | 31 | global $__rgt_replace_set; |
---|