Пример #1
0
 /**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $fldUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function get($fldUid = null)
 {
     $result = array();
     try {
         $noArguments = true;
         $argumentList = func_get_args();
         foreach ($argumentList as $arg) {
             if (!is_null($arg)) {
                 $noArguments = false;
             }
         }
         if ($noArguments) {
             $criteria = new Criteria('workflow');
             $criteria->addSelectColumn(FieldsPeer::FLD_UID);
             $criteria->addSelectColumn(FieldsPeer::ADD_TAB_UID);
             $criteria->addSelectColumn(FieldsPeer::FLD_INDEX);
             $criteria->addSelectColumn(FieldsPeer::FLD_NAME);
             $criteria->addSelectColumn(FieldsPeer::FLD_DESCRIPTION);
             $criteria->addSelectColumn(FieldsPeer::FLD_TYPE);
             $criteria->addSelectColumn(FieldsPeer::FLD_SIZE);
             $criteria->addSelectColumn(FieldsPeer::FLD_NULL);
             $criteria->addSelectColumn(FieldsPeer::FLD_AUTO_INCREMENT);
             $criteria->addSelectColumn(FieldsPeer::FLD_KEY);
             $criteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY);
             $criteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY_TABLE);
             $criteria->addSelectColumn(FieldsPeer::FLD_DYN_NAME);
             $criteria->addSelectColumn(FieldsPeer::FLD_DYN_UID);
             $criteria->addSelectColumn(FieldsPeer::FLD_FILTER);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = FieldsPeer::retrieveByPK($fldUid);
             if ($record) {
                 $result = $record->toArray(BasePeer::TYPE_FIELDNAME);
             } else {
                 $paramValues = "";
                 foreach ($argumentList as $arg) {
                     $paramValues .= strlen($paramValues) ? ', ' : '';
                     if (!is_null($arg)) {
                         $paramValues .= "{$arg}";
                     } else {
                         $paramValues .= "NULL";
                     }
                 }
                 throw new RestException(417, "table Fields ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }
Пример #2
0
 /**
  * save pm table
  */
 public function save($httpData, $alterTable = true)
 {
     //require_once 'classes/model/AdditionalTables.php';
     //require_once 'classes/model/Fields.php';
     try {
         ob_start();
         $data = (array) $httpData;
         $data['PRO_UID'] = trim($data['PRO_UID']);
         $data['columns'] = G::json_decode(stripslashes($httpData->columns));
         //decofing data columns
         $isReportTable = $data['PRO_UID'] != '' ? true : false;
         $oAdditionalTables = new AdditionalTables();
         $oFields = new Fields();
         $repTabClassName = $oAdditionalTables->getPHPName($data['REP_TAB_NAME']);
         $columns = $data['columns'];
         // Reserved Words Table
         $reservedWords = array('ALTER', 'CLOSE', 'COMMIT', 'CREATE', 'DECLARE', 'DELETE', 'DROP', 'FETCH', 'FUNCTION', 'GRANT', 'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK', 'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW', 'APP_UID', 'ROW', 'PMTABLE');
         // Reserved Words Field
         $reservedWordsPhp = array('case', 'catch', 'cfunction', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'do', 'else', 'elseif', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'interface', 'instanceof', 'private', 'namespace', 'new', 'old_function', 'or', 'throw', 'protected', 'public', 'static', 'switch', 'xor', 'try', 'use', 'var', 'while');
         $reservedWordsSql = G::reservedWordsSql();
         // verify if exists.
         if ($data['REP_TAB_UID'] == '' || isset($httpData->forceUid) && $httpData->forceUid) {
             //new report table
             if ($isReportTable && $alterTable) {
                 //setting default columns
                 $defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']);
                 $columns = array_merge($defaultColumns, $columns);
             }
             /**
              * validations *
              */
             if (is_array($oAdditionalTables->loadByName($data['REP_TAB_NAME']))) {
                 throw new Exception(G::loadTranslation('ID_PMTABLE_ALREADY_EXISTS', array($data['REP_TAB_NAME'])));
             }
             if (in_array(strtoupper($data["REP_TAB_NAME"]), $reservedWords) || in_array(strtoupper($data["REP_TAB_NAME"]), $reservedWordsSql)) {
                 throw new Exception(G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array($data["REP_TAB_NAME"])));
             }
         }
         //backward compatility
         foreach ($columns as $i => $column) {
             if (in_array(strtoupper($columns[$i]->field_name), $reservedWordsSql) || in_array(strtolower($columns[$i]->field_name), $reservedWordsPhp)) {
                 throw new Exception(G::LoadTranslation("ID_PMTABLE_INVALID_FIELD_NAME", array($columns[$i]->field_name)));
             }
             switch ($column->field_type) {
                 case 'INT':
                     $columns[$i]->field_type = 'INTEGER';
                     break;
                 case 'TEXT':
                     $columns[$i]->field_type = 'LONGVARCHAR';
                     break;
                     // propel DATETIME equivalent is TIMESTAMP
                 // propel DATETIME equivalent is TIMESTAMP
                 case 'DATETIME':
                     $columns[$i]->field_type = 'TIMESTAMP';
                     break;
             }
             // VALIDATIONS
             if ($columns[$i]->field_autoincrement) {
                 $typeCol = $columns[$i]->field_type;
                 if (!($typeCol === 'INTEGER' || $typeCol === 'TINYINT' || $typeCol === 'SMALLINT' || $typeCol === 'BIGINT')) {
                     $columns[$i]->field_autoincrement = false;
                 }
             }
         }
         G::LoadClass("pmTable");
         $pmTable = new pmTable($data['REP_TAB_NAME']);
         $pmTable->setDataSource($data['REP_TAB_CONNECTION']);
         $pmTable->setColumns($columns);
         $pmTable->setAlterTable($alterTable);
         if (isset($data["keepData"]) && $data["keepData"] == 1) {
             //PM Table
             $pmTable->setKeepData(true);
         }
         $pmTable->build();
         $buildResult = ob_get_contents();
         ob_end_clean();
         // Updating additional table struture information
         $addTabData = array('ADD_TAB_UID' => $data['REP_TAB_UID'], 'ADD_TAB_NAME' => $data['REP_TAB_NAME'], 'ADD_TAB_CLASS_NAME' => $repTabClassName, 'ADD_TAB_DESCRIPTION' => $data['REP_TAB_DSC'], 'ADD_TAB_PLG_UID' => '', 'DBS_UID' => $data['REP_TAB_CONNECTION'] ? $data['REP_TAB_CONNECTION'] : 'workflow', 'PRO_UID' => $data['PRO_UID'], 'ADD_TAB_TYPE' => $data['REP_TAB_TYPE'], 'ADD_TAB_GRID' => $data['REP_TAB_GRID']);
         if ($data['REP_TAB_UID'] == '' || isset($httpData->forceUid) && $httpData->forceUid) {
             //new report table
             //create record
             $addTabUid = $oAdditionalTables->create($addTabData);
         } else {
             //editing report table
             //updating record
             $addTabUid = $data['REP_TAB_UID'];
             $oAdditionalTables->update($addTabData);
             //removing old data fields references
             $oCriteria = new Criteria('workflow');
             $oCriteria->add(FieldsPeer::ADD_TAB_UID, $data['REP_TAB_UID']);
             FieldsPeer::doDelete($oCriteria);
         }
         // Updating pmtable fields
         foreach ($columns as $i => $column) {
             $field = array('FLD_UID' => $column->uid, 'FLD_INDEX' => $i, 'ADD_TAB_UID' => $addTabUid, 'FLD_NAME' => $column->field_name, 'FLD_DESCRIPTION' => $column->field_label, 'FLD_TYPE' => $column->field_type, 'FLD_SIZE' => $column->field_size == '' ? null : $column->field_size, 'FLD_NULL' => $column->field_null ? 1 : 0, 'FLD_AUTO_INCREMENT' => $column->field_autoincrement ? 1 : 0, 'FLD_KEY' => $column->field_key ? 1 : 0, 'FLD_FOREIGN_KEY' => 0, 'FLD_FOREIGN_KEY_TABLE' => '', 'FLD_DYN_NAME' => $column->field_dyn, 'FLD_DYN_UID' => $column->field_uid, 'FLD_FILTER' => isset($column->field_filter) && $column->field_filter ? 1 : 0);
             $oFields->create($field);
         }
         if ($isReportTable && $alterTable) {
             // the table was create successfully but we're catching problems while populating table
             try {
                 $oAdditionalTables->populateReportTable($data['REP_TAB_NAME'], $pmTable->getDataSource(), $data['REP_TAB_TYPE'], $data['PRO_UID'], $data['REP_TAB_GRID'], $addTabUid);
             } catch (Exception $e) {
                 $result->message = $result->msg = $e->getMessage();
             }
         }
         $result->success = true;
         $result->message = $result->msg = $buildResult;
     } catch (Exception $e) {
         $buildResult = ob_get_contents();
         ob_end_clean();
         $result->success = false;
         // if it is a propel exception message
         if (preg_match('/(.*)\\s\\[(.*):\\s(.*)\\]\\s\\[(.*):\\s(.*)\\]/', $e->getMessage(), $match)) {
             $result->message = $result->msg = $match[3];
             $result->type = ucfirst($pmTable->getDbConfig()->adapter);
         } else {
             $result->message = $result->msg = $e->getMessage();
             $result->type = G::loadTranslation('ID_EXCEPTION');
         }
         $result->trace = $e->getTraceAsString();
     }
     return $result;
 }
Пример #3
0
    /**
     * Update the report table with a determinated case data
     * @param string $proUid
     * @param string $appUid
     * @param string $appNumber
     * @param string $caseData
     */
    public function updateReportTables($proUid, $appUid, $appNumber, $caseData, $appStatus)
    {
        G::loadClass('pmTable');
        //get all Active Report Tables
        $criteria = new Criteria('workflow');
        $criteria->add(AdditionalTablesPeer::PRO_UID, $proUid);
        $dataset = AdditionalTablesPeer::doSelectRS($criteria);
        $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        // accomplish all related  report tables for this process that contain case data
        // for the target ($appUid) application
        while ($dataset->next()) {
            $row = $dataset->getRow();
            $className = $row['ADD_TAB_CLASS_NAME'];
            // verify if the report table class exists
            if (!file_exists(PATH_WORKSPACE . 'classes/' . $className . '.php')) {
                continue;
            }
            // the class exists then load it.
            require_once PATH_WORKSPACE . 'classes/' . $className . '.php';
            // create a criteria object of report table class
            $c = new Criteria(pmTable::resolveDbSource($row['DBS_UID']));
            // select all related records with this $appUid
            eval('$c->add(' . $className . 'Peer::APP_UID, \'' . $appUid . '\');');
            eval('$records = ' . $className . 'Peer::doSelect($c);');

            //Select all types
            require_once 'classes/model/Fields.php';
            $criteriaField = new Criteria('workflow');
            $criteriaField->add(FieldsPeer::ADD_TAB_UID, $row['ADD_TAB_UID']);
            $datasetField = FieldsPeer::doSelectRS($criteriaField);
            $datasetField->setFetchmode(ResultSet::FETCHMODE_ASSOC);
            $fieldTypes = array();
            while ($datasetField->next()) {
                $rowfield = $datasetField->getRow();
                switch ($rowfield['FLD_TYPE']) {
                    case 'FLOAT':
                    case 'DOUBLE':
                    case 'INTEGER':
                        $fieldTypes[] = array($rowfield['FLD_NAME']=>$rowfield['FLD_TYPE']);
                        break;
                    default:
                        break;
                }
            }

            switch ($row['ADD_TAB_TYPE']) {
                //switching by report table type
                case 'NORMAL':
                    // parsing empty values to null
                    if (!is_array($caseData)) {
                        $caseData = unserialize($caseData);
                    }
                    foreach ($caseData as $i => $v) {
                        foreach ($fieldTypes as $key => $fieldType) {
                            foreach ($fieldType as $name => $type) {
                                if ( strtoupper ( $i) == $name) {
                                    $v = validateType ($v, $type);
                                    unset($name);
                                }
                            }
                        }
                        $caseData[$i] = $v === '' ? null : $v;
                    }

                    if (is_array($records) && count($records) > 0) {
                        // if the record already exists on the report table
                        foreach ($records as $record) {
                            //update all records
                            if (method_exists($record, 'setAppStatus')) {
                                $record->setAppStatus($appStatus);
                            }
                            $record->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                            if ($record->validate()) {
                                $record->save();
                            }
                        }
                    } else {
                        // there are not any record for this application on the table, then create it
                        eval('$obj = new ' . $className . '();');
                        $obj->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                        $obj->setAppUid($appUid);
                        $obj->setAppNumber($appNumber);
                        if (method_exists($obj, 'setAppStatus')) {
                            $obj->setAppStatus($appStatus);
                        }
                        $obj->save();
                    }
                    break;
                case 'GRID':
                    list($gridName, $gridUid) = explode('-', $row['ADD_TAB_GRID']);
                    $gridData = isset($caseData[$gridName]) ? $caseData[$gridName] : array();

                    // delete old records
                    if (is_array($records) && count($records) > 0) {
                        foreach ($records as $record) {
                            $record->delete();
                        }
                    }
                    // save all grid rows on grid type report table
                    foreach ($gridData as $i => $gridRow) {
                        eval('$obj = new ' . $className . '();');
                        //Parsing values
                        foreach ($gridRow as $j => $v) {
                            foreach ($fieldTypes as $key => $fieldType) {
                                foreach ($fieldType as $name => $type) {
                                    if ( strtoupper ( $j) == $name) {
                                        $v = validateType ($v, $type);
                                        unset($name);
                                    }
                                }
                            }
                            $gridRow[$j] = $v === '' ? null : $v;
                        }
                        $obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                        $obj->setAppUid($appUid);
                        $obj->setAppNumber($appNumber);
                        if (method_exists($obj, 'setAppStatus')) {
                            $obj->setAppStatus($appStatus);
                        }
                        $obj->setRow($i);
                        $obj->save();
                    }
                    break;
            }
        }
    }
Пример #4
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(FieldsPeer::FLD_UID, $pks, Criteria::IN);
         $objs = FieldsPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Пример #5
0
     }
     //create record
     $addTabUid = $oAdditionalTables->create($repTabData);
 } else {
     //editing report table
     $addTabUid = $data['REP_TAB_UID'];
     //loading old data before update
     $addTabBeforeData = $oAdditionalTables->load($addTabUid, true);
     //updating record
     $oAdditionalTables->update($repTabData);
     //removing old data fields references
     $oCriteria = new Criteria('workflow');
     $oCriteria->add(FieldsPeer::ADD_TAB_UID, $data['REP_TAB_UID']);
     //$oCriteria->add(FieldsPeer::FLD_NAME, 'APP_UID', Criteria::NOT_EQUAL);
     //$oCriteria->add(FieldsPeer::FLD_NAME, 'ROW', Criteria::NOT_EQUAL);
     FieldsPeer::doDelete($oCriteria);
     //getting old fieldnames
     $oldFields = array();
     foreach ($addTabBeforeData['FIELDS'] as $field) {
         //if ($field['FLD_NAME'] == 'APP_UID' || $field['FLD_NAME'] == 'ROW') continue;
         $oldFields[$field['FLD_UID']] = $field;
     }
 }
 $aFields = array();
 $fieldsList = array();
 $editFieldsList = array();
 foreach ($columns as $i => $column) {
     $field = array('FLD_UID' => $column->uid, 'FLD_INDEX' => $i, 'ADD_TAB_UID' => $addTabUid, 'FLD_NAME' => $column->field_name, 'FLD_DESCRIPTION' => $column->field_label, 'FLD_TYPE' => $column->field_type, 'FLD_SIZE' => $column->field_size, 'FLD_NULL' => isset($column->field_null) ? $column->field_null : 1, 'FLD_AUTO_INCREMENT' => 0, 'FLD_KEY' => isset($column->field_key) ? $column->field_key : 0, 'FLD_FOREIGN_KEY' => 0, 'FLD_FOREIGN_KEY_TABLE' => '', 'FLD_DYN_NAME' => $column->field_dyn, 'FLD_DYN_UID' => $column->field_uid, 'FLD_FILTER' => isset($column->field_filter) && $column->field_filter ? 1 : 0);
     $fieldUid = $oFields->create($field);
     $fieldsList[] = $field;
     if ($data['REP_TAB_UID'] == '') {
Пример #6
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = FieldsPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setFldUid($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setAddTabUid($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setFldIndex($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setFldName($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setFldDescription($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setFldType($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setFldSize($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setFldNull($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setFldAutoIncrement($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setFldKey($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setFldForeignKey($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setFldForeignKeyTable($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setFldDynName($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setFldDynUid($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setFldFilter($arr[$keys[14]]);
     }
 }
Пример #7
0
 function remove($sUID)
 {
     $oConnection = Propel::getConnection(FieldsPeer::DATABASE_NAME);
     try {
         $oFields = FieldsPeer::retrieveByPK($sUID);
         if (!is_null($oFields)) {
             $oConnection->begin();
             $iResult = $oFields->delete();
             $oConnection->commit();
             return $iResult;
         } else {
             throw new Exception('This row doesn\'t exist!');
         }
     } catch (Exception $oError) {
         $oConnection->rollback();
         throw $oError;
     }
 }
Пример #8
0
 public function deleteAll($id)
 {
     //deleting pm table
     $additionalTable = AdditionalTables::load($id);
     AdditionalTables::remove($id);
     //deleting fields
     require_once 'classes/model/Fields.php';
     $criteria = new Criteria('workflow');
     $criteria->add(FieldsPeer::ADD_TAB_UID, $id);
     FieldsPeer::doDelete($criteria);
     //remove all related to pmTable
     G::loadClass('pmTable');
     $pmTable = new pmTable($additionalTable['ADD_TAB_NAME']);
     $pmTable->setDataSource($additionalTable['DBS_UID']);
     $pmTable->remove();
 }
Пример #9
0
    public function getAll(
        $userUid,
        $start = null,
        $limit = null,
        $action = null,
        $filter = null,
        $search = null,
        $process = null,
        $status = null,
        $type = null,
        $dateFrom = null,
        $dateTo = null,
        $callback = null,
        $dir = null,
        $sort = "APP_CACHE_VIEW.APP_NUMBER",
        $category = null,
        $configuration = true,
        $paged = true
    ) {
        $callback = isset($callback)? $callback : "stcCallback1001";
        $dir = isset($dir)? $dir : "DESC";

        if (isset($sort)) {
            G::LoadClass('phpSqlParser');
            $parser = new PHPSQLParser($sort);
            $sort = $parser->parsed;
            $sort = $sort[''][0];
        }

        $sort = isset($sort)? $sort : "";
        $start = isset($start)? $start : "0";
        $limit = isset($limit)? $limit : "25";
        $filter = isset($filter)? $filter : "";
        $search = isset($search)? $search : "";
        $process = isset($process)? $process : "";
        $category = isset($category)? $category : "";
        $status = isset($status)? $status : "";
        $action = isset($action)? $action : "todo";
        $type = isset($type)? $type : "extjs";
        $dateFrom = isset($dateFrom)? $dateFrom : "";
        $dateTo = isset($dateTo)? $dateTo : "";

        G::LoadClass("BasePeer");
        G::LoadClass("configuration");
        //require_once ("classes/model/AppCacheView.php");
        //require_once ("classes/model/AppDelegation.php");
        //require_once ("classes/model/AdditionalTables.php");
        //require_once ("classes/model/AppDelay.php");
        //require_once ("classes/model/Fields.php");
        //require_once ("classes/model/Users.php");
        //require_once ("classes/model/Process.php");

        $oAppCache = new AppCacheView();

        if ($configuration == true) {
            //get data configuration
            $conf = new Configurations();
            $confCasesList = $conf->getConfiguration("casesList", ($action == "search" || $action == "simple_search")? "search" : $action);
            $oAppCache->confCasesList = $confCasesList;
        }

        $delimiter = DBAdapter::getStringDelimiter();

        // get the action based list
        switch ($action) {
            case "draft":
                $Criteria = $oAppCache->getDraftListCriteria($userUid);
                $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
                break;
            case "sent":
                $Criteria = $oAppCache->getSentListCriteria($userUid);
                $CriteriaCount = $oAppCache->getSentCountCriteria($userUid);

                if (!empty($status)) {
                    $Criteria->add(AppCacheViewPeer::APP_STATUS, $status);
                    $CriteriaCount->add(AppCacheViewPeer::APP_STATUS, $status);
                }
                break;
            case "selfservice":
            case "unassigned":
                //$userUid can't be empty or null
                $Criteria = $oAppCache->getUnassignedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getUnassignedCountCriteria($userUid);
                break;
            case "paused":
                $Criteria = $oAppCache->getPausedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
                break;
            case "completed":
                $Criteria = $oAppCache->getCompletedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);
                break;
            case "cancelled":
                $Criteria = $oAppCache->getCancelledListCriteria($userUid);
                $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
                break;
            case "search":
                //$Criteria = $oAppCache->getSearchListCriteria();
                //$CriteriaCount = $oAppCache->getSearchCountCriteria();

                switch ($status) {
                    case "TO_DO":
                        $Criteria = $oAppCache->getToDoListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
                        break;
                    case "DRAFT":
                        $Criteria = $oAppCache->getDraftListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
                        break;
                    case "PAUSED":
                        $Criteria = $oAppCache->getPausedListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
                        break;
                    case "CANCELLED":
                        $Criteria = $oAppCache->getCancelledListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
                        break;
                    case "COMPLETED":
                        $Criteria = $oAppCache->getCompletedListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);

                        $Criteria->add (AppCacheViewPeer::DEL_LAST_INDEX,"1");
                        $CriteriaCount->add (AppCacheViewPeer::DEL_LAST_INDEX,"1");
                        break;
                    default:
                        //All status
                        $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
                        $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
                        break;
                }
                break;
            case "simple_search":
                $Criteria = $oAppCache->getSimpleSearchListCriteria();
                $CriteriaCount = $oAppCache->getSimpleSearchCountCriteria();
                break;
            case "to_revise":
                $Criteria = $oAppCache->getToReviseListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToReviseCountCriteria($userUid);
                break;
            case "to_reassign":
                $Criteria = $oAppCache->getToReassignListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToReassignCountCriteria($userUid);
                break;
            case "all":
                $Criteria = $oAppCache->getAllCasesListCriteria($userUid);
                $CriteriaCount = $oAppCache->getAllCasesCountCriteria($userUid);
                break;
            case "gral":
                //General criteria probably will be deprecated
                $Criteria = $oAppCache->getGeneralListCriteria();
                $CriteriaCount = $oAppCache->getGeneralCountCriteria();
                break;
            case "todo":
                $Criteria = $oAppCache->getToDoListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
                break;
            default:
                //All status
                $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
                $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
                break;
        }

        $arrayTaskTypeToExclude = array("WEBENTRYEVENT", "END-MESSAGE-EVENT", "START-MESSAGE-EVENT", "INTERMEDIATE-THROW-MESSAGE-EVENT", "INTERMEDIATE-CATCH-MESSAGE-EVENT");

        $Criteria->addJoin(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
        $Criteria->add(TaskPeer::TAS_TYPE, $arrayTaskTypeToExclude, Criteria::NOT_IN);

        $CriteriaCount->addJoin(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
        $CriteriaCount->add(TaskPeer::TAS_TYPE, $arrayTaskTypeToExclude, Criteria::NOT_IN);

        $Criteria->addAlias( 'CU', 'USERS' );
        $Criteria->addJoin( AppCacheViewPeer::USR_UID, 'CU.USR_UID', Criteria::LEFT_JOIN );
        $Criteria->addAsColumn( 'USR_UID', 'CU.USR_UID' );
        $Criteria->addAsColumn( 'USR_FIRSTNAME', 'CU.USR_FIRSTNAME' );
        $Criteria->addAsColumn( 'USR_LASTNAME', 'CU.USR_LASTNAME' );
        $Criteria->addAsColumn( 'USR_USERNAME', 'CU.USR_USERNAME' );

        $CriteriaCount->addAlias( 'CU', 'USERS' );
        $CriteriaCount->addJoin( AppCacheViewPeer::USR_UID, 'CU.USR_UID', Criteria::LEFT_JOIN );
        $CriteriaCount->addAsColumn( 'USR_UID', 'CU.USR_UID' );
        $CriteriaCount->addAsColumn( 'USR_FIRSTNAME', 'CU.USR_FIRSTNAME' );
        $CriteriaCount->addAsColumn( 'USR_LASTNAME', 'CU.USR_LASTNAME' );
        $CriteriaCount->addAsColumn( 'USR_USERNAME', 'CU.USR_USERNAME' );

        //Current delegation
        $appdelcrTableName = AppCacheViewPeer::TABLE_NAME;
        $appdelcrAppTasTitle = "APPDELCR.APP_TAS_TITLE";
        $appdelcrAppTasTitleCount = $appdelcrAppTasTitle;

        switch ($action) {
            case "sent":
                $appdelcrTableName = AppDelegationPeer::TABLE_NAME;
                $appdelcrAppTasTitle = "(SELECT CON_VALUE FROM CONTENT WHERE CON_ID = APPDELCR.TAS_UID AND CON_LANG = " . $delimiter . SYS_LANG . $delimiter . " AND CON_CATEGORY = " . $delimiter . "TAS_TITLE" . $delimiter . ")";
                $appdelcrAppTasTitleCount = "APPDELCR.TAS_UID";
                break;
            case "to_reassign":
                $appdelcrAppTasTitle = "APP_CACHE_VIEW.APP_TAS_TITLE";
                $appdelcrAppTasTitleCount = $appdelcrAppTasTitle;
                break;
        }

        $Criteria->addAsColumn("APPDELCR_APP_TAS_TITLE", $appdelcrAppTasTitle);
        $CriteriaCount->addAsColumn("APPDELCR_APP_TAS_TITLE", $appdelcrAppTasTitleCount);

        $Criteria->addAsColumn("USRCR_USR_UID", "USRCR.USR_UID");
        $Criteria->addAsColumn("USRCR_USR_FIRSTNAME", "USRCR.USR_FIRSTNAME");
        $Criteria->addAsColumn("USRCR_USR_LASTNAME", "USRCR.USR_LASTNAME");
        $Criteria->addAsColumn("USRCR_USR_USERNAME", "USRCR.USR_USERNAME");

        $CriteriaCount->addAsColumn("USRCR_USR_UID", "USRCR.USR_UID");
        $CriteriaCount->addAsColumn("USRCR_USR_FIRSTNAME", "USRCR.USR_FIRSTNAME");
        $CriteriaCount->addAsColumn("USRCR_USR_LASTNAME", "USRCR.USR_LASTNAME");
        $CriteriaCount->addAsColumn("USRCR_USR_USERNAME", "USRCR.USR_USERNAME");

        $Criteria->addAlias("APPDELCR", $appdelcrTableName);
        $Criteria->addAlias("USRCR", UsersPeer::TABLE_NAME);

        $CriteriaCount->addAlias("APPDELCR", $appdelcrTableName);
        $CriteriaCount->addAlias("USRCR", UsersPeer::TABLE_NAME);

        $arrayCondition = array();
        $arrayCondition[] = array(AppCacheViewPeer::APP_UID, "APPDELCR.APP_UID");
        $arrayCondition[] = array("APPDELCR.DEL_LAST_INDEX", 1);
        $Criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
        $CriteriaCount->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);

        $arrayCondition = array();
        $arrayCondition[] = array("APPDELCR.USR_UID", "USRCR.USR_UID");
        $Criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
        $CriteriaCount->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);

        //Previous user

        if (($action == "todo" || $action == "selfservice" || $action == "unassigned" || $action == "paused" || $action == "to_revise" || $action == "sent") || ($status == "TO_DO" || $status == "DRAFT" || $status == "PAUSED" || $status == "CANCELLED" || $status == "COMPLETED")) {
            $Criteria->addAlias( 'PU', 'USERS' );
            $Criteria->addJoin( AppCacheViewPeer::PREVIOUS_USR_UID, 'PU.USR_UID', Criteria::LEFT_JOIN );
            $Criteria->addAsColumn( 'PREVIOUS_USR_FIRSTNAME', 'PU.USR_FIRSTNAME' );
            $Criteria->addAsColumn( 'PREVIOUS_USR_LASTNAME', 'PU.USR_LASTNAME' );
            $Criteria->addAsColumn( 'PREVIOUS_USR_USERNAME', 'PU.USR_USERNAME' );

            $CriteriaCount->addAlias( 'PU', 'USERS' );
            $CriteriaCount->addJoin( AppCacheViewPeer::PREVIOUS_USR_UID, 'PU.USR_UID', Criteria::LEFT_JOIN );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_FIRSTNAME', 'PU.USR_FIRSTNAME' );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_LASTNAME', 'PU.USR_LASTNAME' );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_USERNAME', 'PU.USR_USERNAME' );
        }

        /*
        if (! is_array( $confCasesList )) {
            $rows = $this->getDefaultFields( $action );
            $result = $this->genericJsonResponse( '', array (), $rows, 20, '' );
            //$conf->saveObject($result,'casesList',$action,'','','');
        }
        */

        //Add the process filter
        if (!empty($process)) {
            $Criteria->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
            $CriteriaCount->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
        }

        //Add the category filter
        if (!empty($category)) {
            require_once 'classes/model/Process.php';
            $Criteria->addAlias("CP", "PROCESS");
            $Criteria->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
            $Criteria->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
            $Criteria->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");

            $CriteriaCount->addAlias("CP", "PROCESS");
            $CriteriaCount->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
            $CriteriaCount->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
            $CriteriaCount->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");
        }

        // add the user filter
        /*
        if ($user != '') {
            $Criteria->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
        }
        if ($status != '') {
            $Criteria->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
        }
        */

        if ($dateFrom != "") {
            if ($dateTo != "") {
                if ($dateFrom == $dateTo) {
                    $dateSame = $dateFrom;
                    $dateFrom = $dateSame . " 00:00:00";
                    $dateTo = $dateSame . " 23:59:59";
                } else {
                    $dateFrom = $dateFrom . " 00:00:00";
                    $dateTo = $dateTo . " 23:59:59";
                }

                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL )->addAnd( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL ) ) );
                $CriteriaCount->add( $CriteriaCount->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL )->addAnd( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL ) ) );
            } else {
                $dateFrom = $dateFrom . " 00:00:00";

                $Criteria->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL );
                $CriteriaCount->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL );
            }
        } elseif ($dateTo != "") {
            $dateTo = $dateTo . " 23:59:59";

            $Criteria->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL );
        }

        //add the filter
        if ($filter != '') {
            switch ($filter) {
                case 'read':
                    $Criteria->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL );
                    break;
                case 'unread':
                    $Criteria->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
                    break;
                case 'started':
                    $Criteria->add( AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL );
                    break;
                case 'completed':
                    $Criteria->add( AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL );
                    $CriteriaCount->add( AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL );
                    break;
            }
        }

        //Add the search filter
        if ($search != '') {
            $oTmpCriteria = '';

            //If there is PMTable for this case list
            if (is_array($oAppCache->confCasesList) && count($oAppCache->confCasesList) > 0 && isset($oAppCache->confCasesList["PMTable"]) && trim($oAppCache->confCasesList["PMTable"]) != "") {
                //Default configuration fields array
                $defaultFields = $oAppCache->getDefaultFields();

                //Getting the table name
                $additionalTableUid = $oAppCache->confCasesList["PMTable"];

                $additionalTable = AdditionalTablesPeer::retrieveByPK($additionalTableUid);
                $tableName = $additionalTable->getAddTabName();

                $additionalTable = new AdditionalTables();
                $tableData = $additionalTable->load($additionalTableUid, true);

                $tableField = array();

                foreach ($tableData["FIELDS"] as $arrayField) {
                    $tableField[] = $arrayField["FLD_NAME"];
                }

                $oNewCriteria = new Criteria("workflow");
                $sw = 0;

                foreach ($oAppCache->confCasesList["second"]["data"] as $fieldData) {
                    if (!in_array($fieldData["name"], $defaultFields)) {
                        if (in_array($fieldData["name"], $tableField)) {
                            $fieldName = $tableName . "." . $fieldData["name"];

                            if ($sw == 0) {
                                $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, "%" . $search . "%", Criteria::LIKE);
                            } else {
                                $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, "%" . $search . "%", Criteria::LIKE)->addOr($oTmpCriteria);
                            }

                            $sw = 1;
                        }
                    }
                }

                //add the default and hidden DEL_INIT_DATE
            }

            // the criteria adds new fields if there are defined PM Table Fields in the cases list
            if ($oTmpCriteria != '') {
                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE )->addOr( $oTmpCriteria ) ) ) );
            } else {
                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE ) ) ) );
            }

            // the count query needs to be the normal criteria query if there are defined PM Table Fields in the cases list
            if ($oTmpCriteria != '') {
                $CriteriaCount = $Criteria;
            } else {
                $CriteriaCount->add( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE ) ) ) );
            }
        }

        // this is the optimal way or query to render the cases search list
        // fixing the bug related to the wrong data displayed in the list
        /*
        if ($action == 'search') {
            $oDatasetIndex = AppCacheViewPeer::doSelectRS( $Criteria );
            $oDatasetIndex->setFetchmode( ResultSet::FETCHMODE_ASSOC );
            $oDatasetIndex->next();
            $maxDelIndexList = array ();
            // a list of MAX_DEL_INDEXES is required in order to validate the right row
            while ($aRow = $oDatasetIndex->getRow()) {
                $maxDelIndexList[] = $aRow['MAX_DEL_INDEX'];
                $oDatasetIndex->next();
            }
            // adding the validation condition in order to get the right row using the group by sentence
            $Criteria->add( AppCacheViewPeer::DEL_INDEX, $maxDelIndexList, Criteria::IN );
            //
            //$params = array($maxDelIndexList);
        }
        */

        //here we count how many records exists for this criteria.
        //BUT there are some special cases, and if we dont optimize them the server will crash.
        $doCountAlreadyExecuted = $paged;
        //case 1. when the SEARCH action is selected and none filter, search criteria is defined,
        //we need to count using the table APPLICATION, because APP_CACHE_VIEW takes 3 seconds

        /*
        if ($action == 'search' && $filter == '' && $search == '' && $process == '' && $status == '' && $dateFrom == '' && $dateTo == '' && $category == '') {
            $totalCount = $oAppCache->getSearchAllCount();
            $doCountAlreadyExecuted = true;
        }
        if ($category != '') {
            $totalCount = $oAppCache->getSearchCountCriteria();
            $doCountAlreadyExecuted = true;
        }
        */
        $tableNameAux = '';
        $totalCount = 0;
        if ($doCountAlreadyExecuted == true) {
            // in the case of reassign the distinct attribute shows a diferent count result comparing to the
            // original list
            //Check also $distinct in the method getListCounters(), this in AppCacheView.php
            $distinct = true;

            if ($action != "sent" && (($action == "todo" || $action == "selfservice" || $action == "unassigned" || $action == "to_reassign" || $action == "to_revise") || ($status == "TO_DO"))) {
                $distinct = false;
            }

            // first check if there is a PMTable defined within the list,
            // the issue that brokes the normal criteria query seems to be fixed
            if (isset( $oAppCache->confCasesList['PMTable'] ) && ! empty( $oAppCache->confCasesList['PMTable'] )) {
                // then
                $oAdditionalTables = AdditionalTablesPeer::retrieveByPK( $oAppCache->confCasesList['PMTable'] );
                $tableName = $oAdditionalTables->getAddTabName();
                $tableNameAux = $tableName;
                $tableName = strtolower( $tableName );
                $tableNameArray = explode( '_', $tableName );
                foreach ($tableNameArray as $item) {
                    $newTableName[] = ucfirst( $item );
                }
                $tableName = implode( '', $newTableName );
                // so the pm table class can be invoqued from the pm table model clases
                if (! class_exists( $tableName )) {
                    require_once (PATH_DB . SYS_SYS . PATH_SEP . "classes" . PATH_SEP . $tableName . ".php");
                }
            }
            $totalCount = AppCacheViewPeer::doCount($CriteriaCount, $distinct);
        }

        //Add sortable options
        $sortBk = $sort;

        if ($sortBk != "") {
            $sort = "";

            //Current delegation (*)
            if (($action == "sent" || $action == "search" || $action == "simple_search" || $action == "to_revise" || $action == "to_reassign") && ($status != "TO_DO")) {
                switch ($sortBk) {
                    case "APP_CACHE_VIEW.APP_CURRENT_USER":
                        $sort = "USRCR_" . $conf->userNameFormatGetFirstFieldByUsersTable();
                        break;
                    case "APP_CACHE_VIEW.APP_TAS_TITLE":
                        $sort = "APPDELCR_APP_TAS_TITLE";
                        break;
                }
            }

            if (isset( $oAppCache->confCasesList['PMTable'] ) && ! empty( $oAppCache->confCasesList['PMTable'] ) && $tableNameAux != '') {
                $sortTable = explode(".", $sortBk);

                $additionalTableUid = $oAppCache->confCasesList["PMTable"];

                require_once 'classes/model/Fields.php';
                $oCriteria = new Criteria('workflow');

                $oCriteria->addSelectColumn(FieldsPeer::FLD_UID);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_INDEX);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_NAME);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DESCRIPTION);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_TYPE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_SIZE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_NULL);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_AUTO_INCREMENT);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_KEY);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY_TABLE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_NAME);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_UID);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FILTER);
                $oCriteria->add(FieldsPeer::ADD_TAB_UID, $additionalTableUid);
                $oCriteria->add(FieldsPeer::FLD_NAME, $sortTable[1]);
                $oCriteria->addAscendingOrderByColumn(FieldsPeer::FLD_INDEX);

                $oDataset = FieldsPeer::doSelectRS($oCriteria);
                $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                $oDataset->next();
                $row = $oDataset->getRow();
                if (is_array($row)) {
                    $sort = $tableNameAux . "." . $sortTable[1];
                }
            }

            if ($sort == "") {
                $sort = $sortBk;
            }

            if (!in_array($sort, $Criteria->getSelectColumns())) {
                $sort = AppCacheViewPeer::APP_NUMBER; //DEFAULT VALUE
            }

            if ($dir == "DESC") {
                $Criteria->addDescendingOrderByColumn($sort);
            } else {
                $Criteria->addAscendingOrderByColumn($sort);
            }
        }

        //limit the results according the interface
        $Criteria->setLimit( $limit );
        $Criteria->setOffset( $start );

        //execute the query
        $oDataset = AppCacheViewPeer::doSelectRS( $Criteria, Propel::getDbConnection('workflow_ro') );

        $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

        $result = array ();
        $result['totalCount'] = $totalCount;
        $rows = array ();
        $aPriorities = array ('1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH');
        $index = $start;

        while ($oDataset->next()) {
            $aRow = $oDataset->getRow();

            //$aRow = $oAppCache->replaceRowUserData($aRow);

            /*
             * For participated cases, we want the last step in the case, not only the last step this user participated. To do that we get every case information again for the last step. (This could be solved by a subquery, but Propel might not support it and subqueries can be slower for larger
             * datasets).
             */
             /*if ($action == 'sent' || $action == 'search') {
             $maxCriteria = new Criteria('workflow');
             $maxCriteria->add(AppCacheViewPeer::APP_UID, $aRow['APP_UID'], Criteria::EQUAL);
             $maxCriteria->addDescendingOrderByColumn(AppCacheViewPeer::DEL_INDEX);
             $maxCriteria->setLimit(1);

             $maxDataset = AppCacheViewPeer::doSelectRS( $maxCriteria );
             $maxDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
             $maxDataset->next();

             $newData = $maxDataset->getRow();
             foreach ($aRow as $col => $value) {
             if (array_key_exists($col, $newData))
             $aRow[$col] = $newData[$col];
             }

             $maxDataset->close();
              }*/

            //Current delegation (*) || $action == "search" || $action == "to_revise"
            if (($action == "sent" || $action == "simple_search" || $action == "to_reassign") && ($status != "TO_DO")) {
                //Current task
                $aRow["APP_TAS_TITLE"] = $aRow["APPDELCR_APP_TAS_TITLE"];

                //Current user
                //if ($action != "to_reassign" ) {
                if (($action != "to_reassign") && ($action != "search") && ($action != "to revise")) {
                    $aRow["USR_UID"] = $aRow["USRCR_USR_UID"];
                    $aRow["USR_FIRSTNAME"] = $aRow["USRCR_USR_FIRSTNAME"];
                    $aRow["USR_LASTNAME"] = $aRow["USRCR_USR_LASTNAME"];
                    $aRow["USR_USERNAME"] = $aRow["USRCR_USR_USERNAME"];
                }
            }

            //Unassigned user
            if (! isset( $aRow['APP_CURRENT_USER'] )) {
                $aRow['APP_CURRENT_USER'] = "******" . strtoupper(G::LoadTranslation("ID_UNASSIGNED")) . "]";
            }

            // replacing the status data with their respective translation
            if (isset( $aRow['APP_STATUS'] )) {
                $aRow['APP_STATUS_LABEL'] = G::LoadTranslation( "ID_{$aRow['APP_STATUS']}" );
            }

            // replacing the priority data with their respective translation
            if (isset( $aRow['DEL_PRIORITY'] )) {
                $aRow['DEL_PRIORITY'] = G::LoadTranslation( "ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}" );
            }

            $rows[] = $aRow;
        }

        $result['data'] = $rows;

        return $result;
    }
Пример #10
0
 /**
  * Save Data for Table
  * @var string $tab_data. Data for table
  * @var string $pro_uid. Uid for process
  * @var string $reportFlag. If is report table
  * @var string $createRep. Flag for create table
  *
  * @author Brayan Pereyra (Cochalo) <*****@*****.**>
  * @copyright Colosa - Bolivia
  *
  * @return array
  */
 public function saveTable($tab_data, $pro_uid = '', $reportFlag = false, $createRep = true)
 {
     // CHANGE CASE UPPER TABLE
     $fieldsValidate = array();
     $tableName = '';
     $tableCon = 'workflow';
     $dataValidate = array_change_key_case($tab_data, CASE_UPPER);
     $oAdditionalTables = new AdditionalTables();
     // VALIDATION TABLE DATA
     if ($reportFlag) {
         $pro_uid = $this->validateProUid($pro_uid);
         $dataValidate['TAB_UID'] = isset($dataValidate['REP_UID']) ? $dataValidate['REP_UID'] : '';
         $dataValidate['PRO_UID'] = $pro_uid;
         $dataValidate['REP_TAB_NAME'] = $this->validateTabName($dataValidate['REP_TAB_NAME'], $reportFlag);
         $tempRepTabName = $dataValidate['REP_TAB_CONNECTION'];
         $dataValidate['REP_TAB_CONNECTION'] = $this->validateRepConnection($tempRepTabName, $pro_uid);
         if ($dataValidate['REP_TAB_TYPE'] == 'GRID') {
             $dataValidate['REP_TAB_GRID'] = $this->validateRepGrid($dataValidate['REP_TAB_GRID'], $pro_uid);
         }
         $fieldsValidate = $this->getDynafields($pro_uid, $dataValidate['REP_TAB_TYPE'], $dataValidate['REP_TAB_GRID']);
         if (empty($fieldsValidate)) {
             $fieldsValidate['NAMES'] = array();
             $fieldsValidate['INDEXS'] = array();
             $fieldsValidate['UIDS'] = array();
         }
         $repTabClassName = $oAdditionalTables->getPHPName($dataValidate['REP_TAB_NAME']);
         $tableName = $dataValidate['REP_TAB_NAME'];
         $tableCon = $dataValidate['REP_TAB_CONNECTION'];
     } else {
         $dataValidate['TAB_UID'] = isset($dataValidate['PMT_UID']) ? $dataValidate['PMT_UID'] : '';
         $dataValidate['PMT_TAB_NAME'] = $this->validateTabName($dataValidate['PMT_TAB_NAME']);
         $dataValidate['PMT_TAB_CONNECTION'] = 'workflow';
         $repTabClassName = $oAdditionalTables->getPHPName($dataValidate['PMT_TAB_NAME']);
         $tableName = $dataValidate['PMT_TAB_NAME'];
         $tableCon = $dataValidate['PMT_TAB_CONNECTION'];
     }
     // VERIFY COLUMNS TABLE
     $oFields = new Fields();
     $columns = $dataValidate['FIELDS'];
     // Reserved Words Table, Field, Sql
     $reservedWords = array('ALTER', 'CLOSE', 'COMMIT', 'CREATE', 'DECLARE', 'DELETE', 'DROP', 'FETCH', 'FUNCTION', 'GRANT', 'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK', 'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW', 'APP_UID', 'ROW', 'PMTABLE');
     $reservedWordsPhp = array('case', 'catch', 'cfunction', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'do', 'else', 'elseif', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'interface', 'instanceof', 'private', 'namespace', 'new', 'old_function', 'or', 'throw', 'protected', 'public', 'static', 'switch', 'xor', 'try', 'use', 'var', 'while');
     $reservedWordsSql = G::reservedWordsSql();
     if ($reportFlag) {
         $defaultColumns = $this->getReportTableDefaultColumns($dataValidate['REP_TAB_TYPE']);
         $columns = array_merge($defaultColumns, $columns);
     }
     // validations
     if ($createRep) {
         if (is_array($oAdditionalTables->loadByName($tableName))) {
             throw new \Exception(G::loadTranslation('ID_PMTABLE_ALREADY_EXISTS', array($tableName)));
         }
     }
     if (in_array(strtoupper($tableName), $reservedWords) || in_array(strtoupper($tableName), $reservedWordsSql)) {
         throw new \Exception(G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array($tableName)));
     }
     //backward compatility
     $flagKey = false;
     $columnsStd = array();
     foreach ($columns as $i => $column) {
         if (isset($columns[$i]['fld_dyn'])) {
             $columns[$i]['fld_dyn'] = $reportFlag ? $columns[$i]['fld_dyn'] : '';
             $columns[$i]['field_dyn'] = $columns[$i]['fld_dyn'];
             unset($columns[$i]['fld_dyn']);
         } else {
             $columns[$i]['fld_dyn'] = '';
         }
         if (isset($columns[$i]['fld_name'])) {
             $columns[$i]['field_name'] = G::toUpper($columns[$i]['fld_name']);
             unset($columns[$i]['fld_name']);
         }
         if (isset($columns[$i]['fld_label'])) {
             $columns[$i]['field_label'] = $columns[$i]['fld_label'];
             unset($columns[$i]['fld_label']);
         }
         if (isset($columns[$i]['fld_type'])) {
             $columns[$i]['field_type'] = $columns[$i]['fld_type'];
             unset($columns[$i]['fld_type']);
         }
         if (isset($columns[$i]['fld_size'])) {
             $columns[$i]['field_size'] = $columns[$i]['fld_size'];
             if (!is_int($columns[$i]['field_size'])) {
                 throw new \Exception("The property fld_size: '" . $columns[$i]['field_size'] . "' is incorrect numeric value.");
             } else {
                 $columns[$i]['field_size'] = (int) $columns[$i]['field_size'];
             }
             unset($columns[$i]['fld_size']);
         }
         if (isset($columns[$i]['fld_key'])) {
             $columns[$i]['field_key'] = $columns[$i]['fld_key'];
             unset($columns[$i]['fld_key']);
         }
         if (isset($columns[$i]['fld_null'])) {
             $columns[$i]['field_null'] = $columns[$i]['fld_null'];
             unset($columns[$i]['fld_null']);
         }
         if (isset($columns[$i]['fld_autoincrement'])) {
             $columns[$i]['field_autoincrement'] = $columns[$i]['fld_autoincrement'];
             unset($columns[$i]['fld_autoincrement']);
         }
         // VALIDATIONS
         if (in_array(strtoupper($columns[$i]['field_name']), $reservedWordsSql) || in_array(strtolower($columns[$i]['field_name']), $reservedWordsPhp) || $columns[$i]['field_name'] == '') {
             throw new \Exception("The property fld_name: '" . $columns[$i]['field_name'] . "' is incorrect value.");
         }
         if ($columns[$i]['field_label'] == '') {
             throw new \Exception("The property fld_label: '" . $columns[$i]['field_label'] . "' is incorrect value.");
         }
         $columns[$i]['field_type'] = $this->validateFldType($columns[$i]['field_type']);
         if (isset($columns[$i]['field_autoincrement']) && $columns[$i]['field_autoincrement']) {
             $typeCol = $columns[$i]['field_type'];
             if (!($typeCol === 'INTEGER' || $typeCol === 'TINYINT' || $typeCol === 'SMALLINT' || $typeCol === 'BIGINT')) {
                 $columns[$i]['field_autoincrement'] = false;
             }
         }
         if (isset($columns[$i]['field_dyn']) && $columns[$i]['field_dyn'] != '') {
             $res = array_search($columns[$i]['field_dyn'], $fieldsValidate['NAMES']);
             if ($res === false) {
                 throw new \Exception("The property fld_dyn: '" . $columns[$i]['field_dyn'] . "' is incorrect.");
             } else {
                 $columns[$i]['_index'] = $fieldsValidate['INDEXS'][$res];
                 $columns[$i]['field_uid'] = $fieldsValidate['UIDS'][$res];
             }
         }
         $temp = new \stdClass();
         foreach ($columns[$i] as $key => $valCol) {
             eval('$temp->' . str_replace('fld', 'field', $key) . " = '" . $valCol . "';");
         }
         $temp->uid = isset($temp->uid) ? $temp->uid : '';
         $temp->_index = isset($temp->_index) ? $temp->_index : '';
         $temp->field_uid = isset($temp->field_uid) ? $temp->field_uid : '';
         $temp->field_dyn = isset($temp->field_dyn) ? $temp->field_dyn : '';
         $temp->field_key = isset($temp->field_key) ? $temp->field_key : 0;
         $temp->field_null = isset($temp->field_null) ? $temp->field_null : 1;
         $temp->field_dyn = isset($temp->field_dyn) ? $temp->field_dyn : '';
         $temp->field_filter = isset($temp->field_filter) ? $temp->field_filter : 0;
         $temp->field_autoincrement = isset($temp->field_autoincrement) ? $temp->field_autoincrement : 0;
         if (!$reportFlag) {
             unset($temp->_index);
             unset($temp->field_filter);
         }
         if ($temp->field_key == 1 || $temp->field_key == true) {
             $flagKey = true;
         }
         $columnsStd[$i] = $temp;
     }
     if (!$flagKey) {
         throw new \Exception("The fields must have a key 'fld_key'");
     }
     $pmTable = new \pmTable($tableName);
     $pmTable->setDataSource($tableCon);
     $pmTable->setColumns($columnsStd);
     $pmTable->setAlterTable(true);
     if (!$createRep) {
         $pmTable->setKeepData(true);
     }
     $pmTable->build();
     $buildResult = ob_get_contents();
     ob_end_clean();
     unset($buildResult);
     // Updating additional table struture information
     if ($reportFlag) {
         $addTabData = array('ADD_TAB_UID' => $dataValidate['TAB_UID'], 'ADD_TAB_NAME' => $dataValidate['REP_TAB_NAME'], 'ADD_TAB_CLASS_NAME' => $repTabClassName, 'ADD_TAB_DESCRIPTION' => $dataValidate['REP_TAB_DSC'], 'ADD_TAB_PLG_UID' => '', 'DBS_UID' => $dataValidate['REP_TAB_CONNECTION'] ? $dataValidate['REP_TAB_CONNECTION'] : 'workflow', 'PRO_UID' => $dataValidate['PRO_UID'], 'ADD_TAB_TYPE' => $dataValidate['REP_TAB_TYPE'], 'ADD_TAB_GRID' => $dataValidate['REP_TAB_GRID']);
     } else {
         $addTabData = array('ADD_TAB_UID' => $dataValidate['TAB_UID'], 'ADD_TAB_NAME' => $dataValidate['PMT_TAB_NAME'], 'ADD_TAB_CLASS_NAME' => $repTabClassName, 'ADD_TAB_DESCRIPTION' => $dataValidate['PMT_TAB_DSC'], 'ADD_TAB_PLG_UID' => '', 'DBS_UID' => $dataValidate['PMT_TAB_CONNECTION'] ? $dataValidate['PMT_TAB_CONNECTION'] : 'workflow', 'PRO_UID' => '', 'ADD_TAB_TYPE' => '', 'ADD_TAB_GRID' => '');
     }
     if ($createRep) {
         //new report table
         //create record
         $addTabUid = $oAdditionalTables->create($addTabData);
     } else {
         //editing report table
         //updating record
         $addTabUid = $dataValidate['TAB_UID'];
         $oAdditionalTables->update($addTabData);
         //removing old data fields references
         $oCriteria = new \Criteria('workflow');
         $oCriteria->add(\FieldsPeer::ADD_TAB_UID, $dataValidate['TAB_UID']);
         \FieldsPeer::doDelete($oCriteria);
     }
     // Updating pmtable fields
     foreach ($columnsStd as $i => $column) {
         $column = (array) $column;
         $field = array('FLD_UID' => $column['uid'], 'FLD_INDEX' => $i, 'ADD_TAB_UID' => $addTabUid, 'FLD_NAME' => $column['field_name'], 'FLD_DESCRIPTION' => $column['field_label'], 'FLD_TYPE' => $column['field_type'], 'FLD_SIZE' => !isset($column['field_size']) || $column['field_size'] == '' ? null : $column['field_size'], 'FLD_NULL' => $column['field_null'] ? 1 : 0, 'FLD_AUTO_INCREMENT' => $column['field_autoincrement'] ? 1 : 0, 'FLD_KEY' => $column['field_key'] ? 1 : 0, 'FLD_FOREIGN_KEY' => 0, 'FLD_FOREIGN_KEY_TABLE' => '', 'FLD_DYN_NAME' => $column['field_dyn'], 'FLD_DYN_UID' => $column['field_uid'], 'FLD_FILTER' => isset($column['field_filter']) && $column['field_filter'] ? 1 : 0);
         $oFields->create($field);
     }
     if ($reportFlag) {
         $rep_uid = $addTabUid;
         $this->generateDataReport($pro_uid, $rep_uid, false);
     }
     if ($createRep) {
         $tab_uid = $addTabUid;
         return $this->getTable($tab_uid, $pro_uid, $reportFlag, false);
     }
 }
 $oCriteria->add(FieldsPeer::FLD_NAME, 'APP_UID', CRITERIA::NOT_EQUAL);
 //$oCriteria->add (AppCacheViewPeer::APP_STATUS, "TO_DO" , CRITERIA::EQUAL );
 //$oCriteria->add (AppCacheViewPeer::USR_UID, $sUIDUserLogged);
 //$totalCount = AppCacheViewPeer::doCount( $Criteria );
 //if ( isset($limit) ) $oCriteria->setLimit  ( $limit );
 //if ( isset($start) ) $oCriteria->setOffset ( $start );
 if ($sort != '') {
     if ($dir == 'DESC') {
         $oCriteria->addDescendingOrderByColumn($sort);
     } else {
         $oCriteria->addAscendingOrderByColumn($sort);
     }
     //else {
     //    $oCriteria->addDescendingOrderByColumn('FLD_INDEX');
     //}
     $oDataset = FieldsPeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $oDataset->next();
     $result = array();
     $rows = array();
     switch ($action) {
         case 'todo':
             // #, Case, task, process, sent by, due date, Last Modify, Priority
             $rows[] = array('name' => 'APP_UID', 'gridIndex' => '0', 'column2' => '0');
             $rows[] = array('name' => 'DEL_INDEX', 'gridIndex' => '3', 'column2' => '3');
             $rows[] = array('name' => 'APP_NUMBER', 'gridIndex' => '1', 'column2' => '1');
             $rows[] = array('name' => 'APP_TITLE', 'gridIndex' => '4', 'column2' => '4');
             $rows[] = array('name' => 'APP_TAS_TITLE', 'gridIndex' => '6', 'column2' => '6');
             $rows[] = array('name' => 'APP_PRO_TITLE', 'gridIndex' => '5', 'column2' => '5');
             $rows[] = array('name' => 'APP_DEL_PREVIOUS_USER', 'gridIndex' => '7', 'column2' => '7');
             $rows[] = array('name' => 'DEL_TASK_DUE_DATE', 'gridIndex' => '8', 'column2' => '8');
function xgetFieldsFromPMTable($tabUid)
{
    $rows = array();
    $result = array();
    //    $rows[] = array ( 'name' => 'val 1', 'gridIndex' => '21', 'fieldType' => 'PM Table' );
    //    $rows[] = array ( 'name' => 'val 2', 'gridIndex' => '22', 'fieldType' => 'PM Table' );
    //    $rows[] = array ( 'name' => 'val 3', 'gridIndex' => '23', 'fieldType' => 'PM Table' );
    //$result['success']    = true;
    //$result['totalCount']  =  count($rows);
    $oCriteria = new Criteria('workflow');
    $oCriteria->clearSelectColumns();
    $oCriteria->setDistinct();
    $oCriteria->addSelectColumn(FieldsPeer::FLD_NAME);
    $oCriteria->addSelectColumn(FieldsPeer::FLD_UID);
    $oCriteria->addSelectColumn(FieldsPeer::FLD_INDEX);
    $oCriteria->add(FieldsPeer::ADD_TAB_UID, $tabUid, CRITERIA::EQUAL);
    $oCriteria->add(FieldsPeer::FLD_NAME, 'APP_UID', CRITERIA::NOT_EQUAL);
    $oCriteria->addAnd(FieldsPeer::FLD_NAME, 'APP_NUMBER', CRITERIA::NOT_EQUAL);
    $oCriteria->addDescendingOrderByColumn('FLD_INDEX');
    $oDataset = FieldsPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    $oDataset->next();
    $index = count($rows);
    while ($aRow = $oDataset->getRow()) {
        $aRow['index'] = ++$index;
        $aTempRow['name'] = $aRow['FLD_NAME'];
        $aTempRow['gridIndex'] = $aRow['index'];
        $aTempRow['fieldType'] = 'PM Table';
        $rows[] = $aTempRow;
        $oDataset->next();
    }
    $result['data'] = $rows;
    print G::json_encode($result);
}