File size: 3,892 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
  require_once ( "classes/model/Application.php" );
  require_once ( "classes/model/AppDelegation.php" );
  require_once ( "classes/model/Process.php" );

  class chartsClass extends PMPlugin  {

    function __construct (  ) {
    }

    function readConfig () {
    	$fileConf = PATH_PLUGINS . 'charts' . PATH_SEP . 'config' . PATH_SEP . 'setup.conf';
    	if ( !file_exists( dirname($fileConf) ) ) 
    	  throw ( new Exception ("The directory " . dirname($fileConf) . " doesn't exist." ) );
    	  
    	if ( file_exists ( $fileConf ) && !is_writable( $fileConf ) ) 
    	  throw ( new Exception ("The file $fileConf doesn't exist or this file is not writable." ) );
    	
    	$content = file_get_contents ( $fileConf);
    	$fields = unserialize ($content);
    	return $fields;
    }
    
    function getFieldsForPageSetup () {
    	$fileConf = PATH_PLUGINS . $this->sPluginFolder . PATH_SEP . 'config' . PATH_SEP . 'setup.conf';
    	if ( !file_exists( dirname($fileConf) ) ) 
    	  throw ( new Exception ("The directory " . dirname($fileConf) . " doesn't exist." ) );
    	  
    	if ( file_exists ( $fileConf ) && !is_writable( $fileConf ) ) 
    	  throw ( new Exception ("The file $fileConf doesn't exist or this file is not writable." ) );
    	
    	if ( file_exists ( $fileConf ) ) {
    	  $content = file_get_contents ( $fileConf);
    	  $fields = unserialize ($content);
    	}
    	else
    	  $fields = array();
    	return $fields;
    }

    function updateFieldsForPageSetup ( $oData) {
    	$content = serialize ($oData['form']);
    	$fileConf = PATH_PLUGINS . $this->sPluginFolder . PATH_SEP . 'config' . PATH_SEP . 'setup.conf';
    	if ( !is_writable( dirname($fileConf) ) ) 
    	  throw ( new Exception ("The directory " . dirname($fileConf) . " doesn't exist or this directory is not writable." ) );
    	  
    	if ( file_exists ( $fileConf ) && !is_writable( $fileConf ) ) 
    	  throw ( new Exception ("The file $fileConf doesn't exist or this file is not writable." ) );
    	
    	file_put_contents ( $fileConf, $content);
    	return true;
    }

    function setup() {
    }

    function getDatasetCasesByStatus ( ) {
      $dataSet = new XYDataSet();

     $c = new Criteria('workflow');
     $c->clearSelectColumns();
     $c->addSelectColumn ( ApplicationPeer::APP_STATUS );
     $c->addSelectColumn ( 'COUNT(*) AS CANT') ;
     $c->addGroupByColumn(ApplicationPeer::APP_STATUS);
     $rs = ApplicationPeer::doSelectRS( $c );
     $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $rs->next();
     $row = $rs->getRow();
     while ( is_array ( $row ) ) {
   	   $label = $row['APP_STATUS'];
   	   $value = $row['CANT'];
   	   $dataSet->addPoint(new Point($label , (int)$value ) );
	     $rs->next();
	     $row = $rs->getRow();
     }
     return $dataSet;
    }
    
    //we are trying to obtain the process title thru the long way, using the process object.
    //there is a short way, if you use a more complex query joining Content Table.
    function getDatasetCasesByProcess ( ) {
      $dataSet = new XYDataSet();
      $processObj = new Process;
 
      $c = new Criteria('workflow');
      $c->clearSelectColumns();
      $c->addSelectColumn ( ApplicationPeer::PRO_UID );
      $c->addSelectColumn ( 'COUNT(*) AS CANT') ;
	    //$c->addJoin( ProcessPeer::PRO_UID, ProcessPeer::PRO_UID, Criteria::LEFT_JOIN);
      $c->addGroupByColumn(ApplicationPeer::PRO_UID);
      $rs = ApplicationPeer::doSelectRS( $c );
      $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
      $rs->next();
      $row = $rs->getRow();
      while ( is_array ( $row ) ) {
   	    $processObj->load ( $row['PRO_UID'] );
   	    $label = $processObj->getProTitle();
   	    $value = $row['CANT'];
   	    $dataSet->addPoint(new Point($label , (int)$value) );
	      $rs->next();
	      $row = $rs->getRow();
      }
      return $dataSet;
    }
    
  }