Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
view_workflow_graph.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Edition to affect document
8  *
9  * @author Anakeen
10  * @version $Id: view_workflow_graph.php,v 1.8 2008/12/31 16:05:20 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.WDoc.php");
18 // -----------------------------------
19 
20 /**
21  * Edition to affect document
22  * @param Action &$action current action
23  * @global string $id Http var : document id to affect
24  * @global string $type Http var : type of graph
25  * @global string $format Http var : file format pnh or svg
26  * @global string $orient Http var :orientation TB (TopBottom) or LR (LeftRight)
27  * @global string $size Http var : global size of graph
28  * @return void
29  */
31 {
32  $usage = new ActionUsage($action);
33  $usage->setDefinitionText("Generate graph image for workflow");
34  $docid = $usage->addRequiredParameter("id", "workflow id");
35  $type = $usage->addOptionalParameter("type", "graph detail level", array(
36  "justactivity",
37  "simple",
38  "activity",
39  "complet",
40  "cluster"
41  ) , "justactivity");
42  $format = $usage->addOptionalParameter("format", "image format", array(
43  "png",
44  "svg",
45  "dot"
46  ) , "png");
47  $orient = $usage->addOptionalParameter("orient", "orientation", array(
48  "LR",
49  "TB"
50  ) , "LR");
51  $size = $usage->addOptionalParameter("size", "image size", array() , "auto");
52  $ratio = $usage->addOptionalParameter("ratio", "ration", array(
53  "fill",
54  "compress",
55  "auto",
56  "expand"
57  ) , "fill");
58  $tool = $usage->addOptionalParameter("tool", "tool used to generate", array(
59  "dot",
60  "sfdp",
61  "neato",
62  "fdp",
63  "twopi",
64  "circo"
65  ) , "dot");
66  $usage->verify();
67 
68  $dbaccess = $action->dbaccess;
69 
70  if ($tool == "sfdp") {
71  $tool.= " -Goverlap=prism";
72  } elseif ($tool == "neato") {
73  $tool.= " -Goverlap=prism";
74  } elseif ($tool == "twopi") {
75  $tool.= " -Granksep=3.0 -Gnodesep=2.0 -Goverlap=false";
76  }
77  /*
78  * @var WDoc $doc
79  */
80  $doc = new_doc($dbaccess, $docid);
81  $cmd = getWshCmd(false, $action->user->id);
82 
83  if (count($doc->cycle) == 0) {
84  $action->lay->template = _("no cycle defined");
85  $action->lay->noparse = true;
86  } else {
87 
88  $cmd.= sprintf("--api=wdoc_graphviz --size=%s --ratio=%s --type=%s --orient=%s --docid=%d", escapeshellarg($size) , escapeshellarg($ratio) , escapeshellarg($type) , escapeshellarg($orient) , $doc->id);
89  $svgfile = "var/cache/image/w$type-" . $action->getParam("CORE_LANG") . "-" . $doc->id . ".$format";
90  if ($format == "dot") $svgfile.= ".txt"; // conflict with document template
91  $dest = DEFAULT_PUBDIR . "/$svgfile";
92  if ($format == "dot") {
93  $cmd.= sprintf(" > %s", escapeshellarg($dest));
94  } else {
95  $cmd.= sprintf(" | %s -T%s -o%s 2>&1", $tool, escapeshellarg($format) , escapeshellarg($dest));
96  }
97 
98  exec($cmd, $out, $ret);
99 
100  if ($ret != 0) $action->exitError(implode("\n", $out));
101  // print_r2( $cmd);
102  if ($format == "png") $mime = "image/png";
103  elseif ($format == "svg") $mime = "image/svg+xml";
104  else $mime = "text/plain";
105  Http_DownloadFile($svgfile, sprintf("graph %s.%s", $doc->getTitle() , $format) , $mime, true, false, true);
106  exit;
107  }
108 }
$dest
Definition: resizeimg.php:231
view_workflow_graph(Action &$action)
global $action
$ratio
$size
Definition: resizeimg.php:110
$ret
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
exitError($texterr, $exit=true, $code="")
foreach($argv as $arg) $cmd
$orient
$docid
Definition: cleanFamily.php:13
getWshCmd($nice=false, $userid=0, $sudo=false)
Definition: Lib.Common.php:594
Verify arguments for action function.
switch($command) exit
Definition: checkVault.php:46
getParam($name, $def="")
Http_DownloadFile($filename, $name, $mime_type= '', $inline=false, $cache=true, $deleteafter=false)
Definition: Lib.Http.php:225
$dbaccess
Definition: checkVault.php:17
$usage
← centre documentaire © anakeen