diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php new file mode 100644 index 000000000..7e7442058 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php @@ -0,0 +1,275 @@ + 1, + 'type' => 'inbox', + 'name' => 'test1', + 'description' => 'my description', + 'tableUid' => '', + 'columns' => [], + 'userId' => 1, + 'iconList' => 'deafult.png', + 'iconColor' => 'red', + 'iconColorScreen' => 'blue', + 'createDate' => date('Y-m-d H:m:s'), + 'updateDate' => date('Y-m-d H:m:s') + ]; + $array = CaseList::getColumnNameFromAlias($data); + + //asserts + $this->assertArrayHasKey("CAL_ID", $array); + $this->assertArrayHasKey("CAL_TYPE", $array); + $this->assertArrayHasKey("CAL_NAME", $array); + $this->assertArrayHasKey("CAL_DESCRIPTION", $array); + $this->assertArrayHasKey("ADD_TAB_UID", $array); + $this->assertArrayHasKey("CAL_COLUMNS", $array); + $this->assertArrayHasKey("USR_ID", $array); + $this->assertArrayHasKey("CAL_ICON_LIST", $array); + $this->assertArrayHasKey("CAL_ICON_COLOR", $array); + $this->assertArrayHasKey("CAL_ICON_COLOR_SCREEN", $array); + $this->assertArrayHasKey("CAL_CREATE_DATE", $array); + $this->assertArrayHasKey("CAL_UPDATE_DATE", $array); + } + + /** + * This tests the getAliasFromColumnName method. + * @test + * @covers \ProcessMaker\Model\CaseList::createSetting() + */ + public function it_should_test_getAliasFromColumnName() + { + $data = [ + 'CAL_ID' => 1, + 'CAL_TYPE' => 'inbox', + 'CAL_NAME' => 'test1', + 'CAL_DESCRIPTION' => 'my description', + 'ADD_TAB_UID' => 'my description', + 'CAL_COLUMNS' => [], + 'USR_ID' => 1, + 'CAL_ICON_LIST' => 'deafult.png', + 'CAL_ICON_COLOR' => 'red', + 'CAL_ICON_COLOR_SCREEN' => 'blue', + 'CAL_CREATE_DATE' => date('Y-m-d H:m:s'), + 'CAL_UPDATE_DATE' => date('Y-m-d H:m:s') + ]; + $array = CaseList::getAliasFromColumnName($data); + + //asserts + $this->assertArrayHasKey("id", $array); + $this->assertArrayHasKey("type", $array); + $this->assertArrayHasKey("name", $array); + $this->assertArrayHasKey("description", $array); + $this->assertArrayHasKey("tableUid", $array); + $this->assertArrayHasKey("columns", $array); + $this->assertArrayHasKey("userId", $array); + $this->assertArrayHasKey("iconList", $array); + $this->assertArrayHasKey("iconColor", $array); + $this->assertArrayHasKey("iconColorScreen", $array); + $this->assertArrayHasKey("createDate", $array); + $this->assertArrayHasKey("updateDate", $array); + } + + /** + * This tests the createSetting method. + * @test + * @covers \ProcessMaker\Model\CaseList::createSetting() + */ + public function it_should_test_createSetting() + { + $data = [ + 'type' => 'inbox', + 'name' => 'test1', + 'description' => 'my description', + 'tableUid' => '', + 'columns' => [], + 'userId' => 1, + 'iconList' => 'deafult.png', + 'iconColor' => 'red', + 'iconColorScreen' => 'blue', + 'createDate' => date('Y-m-d H:m:s'), + 'updateDate' => date('Y-m-d H:m:s') + ]; + $caseList = CaseList::createSetting($data); + + //asserts + $this->assertEquals($data['type'], $caseList->CAL_TYPE); + $this->assertEquals($data['name'], $caseList->CAL_NAME); + $this->assertEquals($data['description'], $caseList->CAL_DESCRIPTION); + $this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID); + $this->assertEquals($data['columns'], $caseList->CAL_COLUMNS); + $this->assertEquals($data['userId'], $caseList->USR_ID); + $this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST); + $this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR); + $this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN); + } + + /** + * This tests the updateSetting method. + * @test + * @covers \ProcessMaker\Model\CaseList::updateSetting() + */ + public function it_should_test_updateSetting() + { + $data = [ + 'type' => 'inbox', + 'name' => 'test1', + 'description' => 'my description', + 'tableUid' => '', + 'columns' => [], + 'userId' => 1, + 'iconList' => 'deafult.png', + 'iconColor' => 'red', + 'iconColorScreen' => 'blue', + 'createDate' => date('Y-m-d H:m:s'), + 'updateDate' => date('Y-m-d H:m:s') + ]; + $model = CaseList::createSetting($data); + + $id = $model->CAL_ID; + $data2 = [ + 'type' => 'todo', + 'name' => 'new name', + 'description' => 'new deescription', + ]; + $caseList = CaseList::updateSetting($id, $data2); + + //asserts + $this->assertEquals($data2['type'], $caseList->CAL_TYPE); + $this->assertEquals($data2['name'], $caseList->CAL_NAME); + $this->assertEquals($data2['description'], $caseList->CAL_DESCRIPTION); + $this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID); + $this->assertEquals($data['columns'], $caseList->CAL_COLUMNS); + $this->assertEquals($data['userId'], $caseList->USR_ID); + $this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST); + $this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR); + $this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN); + } + + /** + * This tests the deleteSetting method. + * @test + * @covers \ProcessMaker\Model\CaseList::deleteSetting() + */ + public function it_should_test_deleteSetting() + { + $data = [ + 'type' => 'inbox', + 'name' => 'test1', + 'description' => 'my description', + 'tableUid' => '', + 'columns' => [], + 'userId' => 1, + 'iconList' => 'deafult.png', + 'iconColor' => 'red', + 'iconColorScreen' => 'blue', + 'createDate' => date('Y-m-d H:m:s'), + 'updateDate' => date('Y-m-d H:m:s') + ]; + $model = CaseList::createSetting($data); + + $id = $model->CAL_ID; + $caseList = CaseList::deleteSetting($id); + + //asserts + $this->assertEquals($data['type'], $caseList->CAL_TYPE); + $this->assertEquals($data['name'], $caseList->CAL_NAME); + $this->assertEquals($data['description'], $caseList->CAL_DESCRIPTION); + $this->assertEquals($data['tableUid'], $caseList->ADD_TAB_UID); + $this->assertEquals($data['columns'], $caseList->CAL_COLUMNS); + $this->assertEquals($data['userId'], $caseList->USR_ID); + $this->assertEquals($data['iconList'], $caseList->CAL_ICON_LIST); + $this->assertEquals($data['iconColor'], $caseList->CAL_ICON_COLOR); + $this->assertEquals($data['iconColorScreen'], $caseList->CAL_ICON_COLOR_SCREEN); + } + + /** + * This tests the getSetting method. + * @test + * @covers \ProcessMaker\Model\CaseList::deleteSetting() + */ + public function it_should_test_getSetting() + { + CaseList::truncate(); + + $data = [ + 'type' => 'inbox', + 'name' => 'test1', + 'description' => 'my description', + 'tableUid' => '', + 'columns' => [], + 'userId' => 1, + 'iconList' => 'deafult.png', + 'iconColor' => 'red', + 'iconColorScreen' => 'blue' + ]; + $model1 = CaseList::createSetting($data); + $model2 = CaseList::createSetting($data); + $model3 = CaseList::createSetting($data); + $model4 = CaseList::createSetting($data); + + //assert total + $result = CaseList::getSetting('inbox', '', 0, 10); + $this->assertArrayHasKey("total", $result); + $this->assertArrayHasKey("data", $result); + $this->assertEquals(4, $result['total']); + + //assert page 1 + $result = CaseList::getSetting('inbox', '', 0, 2); + $this->assertArrayHasKey("total", $result); + $this->assertArrayHasKey("data", $result); + $this->assertEquals(4, $result['total']); + $this->assertEquals(2, count($result['data'])); + + //assert page 2 + $result = CaseList::getSetting('inbox', '', 2, 2); + $this->assertArrayHasKey("total", $result); + $this->assertArrayHasKey("data", $result); + $this->assertEquals(4, $result['total']); + $this->assertEquals(2, count($result['data'])); + + //assert search + $result = CaseList::getSetting('inbox', 'test1', 0, 10); + $this->assertArrayHasKey("total", $result); + $this->assertArrayHasKey("data", $result); + $this->assertEquals(4, $result['total']); + $this->assertEquals(4, count($result['data'])); + + //assert search no exist result + $result = CaseList::getSetting('inbox', 'xxxx', 0, 10); + $this->assertArrayHasKey("total", $result); + $this->assertArrayHasKey("data", $result); + $this->assertEquals(0, $result['total']); + $this->assertEquals(0, count($result['data'])); + } +} diff --git a/workflow/engine/classes/model/CaseList.php b/workflow/engine/classes/model/CaseList.php new file mode 100644 index 000000000..94b2948db --- /dev/null +++ b/workflow/engine/classes/model/CaseList.php @@ -0,0 +1,19 @@ +dbMap !== null); + } + + /** + * Gets the databasemap this map builder built. + * + * @return the databasemap + */ + public function getDatabaseMap() + { + return $this->dbMap; + } + + /** + * The doBuild() method builds the DatabaseMap + * + * @return void + * @throws PropelException + */ + public function doBuild() + { + $this->dbMap = Propel::getDatabaseMap('workflow'); + + $tMap = $this->dbMap->addTable('CASE_LIST'); + $tMap->setPhpName('CaseList'); + + $tMap->setUseIdGenerator(true); + + $tMap->addPrimaryKey('CAL_ID', 'CalId', 'int', CreoleTypes::INTEGER, true, null); + + $tMap->addColumn('CAL_TYPE', 'CalType', 'string', CreoleTypes::VARCHAR, true, 255); + + $tMap->addColumn('CAL_NAME', 'CalName', 'string', CreoleTypes::VARCHAR, true, 255); + + $tMap->addColumn('CAL_DESCRIPTION', 'CalDescription', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('ADD_TAB_UID', 'AddTabUid', 'string', CreoleTypes::VARCHAR, true, 32); + + $tMap->addColumn('CAL_COLUMNS', 'CalColumns', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('USR_ID', 'UsrId', 'string', CreoleTypes::BIGINT, true, 20); + + $tMap->addColumn('CAL_ICON_LIST', 'CalIconList', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('CAL_ICON_COLOR', 'CalIconColor', 'string', CreoleTypes::VARCHAR, false, 255); + + $tMap->addColumn('CAL_ICON_COLOR_SCREEN', 'CalIconColorScreen', 'string', CreoleTypes::VARCHAR, false, 255); + + $tMap->addColumn('CAL_CREATE_DATE', 'CalCreateDate', 'int', CreoleTypes::TIMESTAMP, true, null); + + $tMap->addColumn('CAL_UPDATE_DATE', 'CalUpdateDate', 'int', CreoleTypes::TIMESTAMP, true, null); + + } // doBuild() + +} // CaseListMapBuilder diff --git a/workflow/engine/classes/model/om/BaseCaseList.php b/workflow/engine/classes/model/om/BaseCaseList.php new file mode 100644 index 000000000..5f5bea7b6 --- /dev/null +++ b/workflow/engine/classes/model/om/BaseCaseList.php @@ -0,0 +1,1206 @@ +cal_id; + } + + /** + * Get the [cal_type] column value. + * + * @return string + */ + public function getCalType() + { + + return $this->cal_type; + } + + /** + * Get the [cal_name] column value. + * + * @return string + */ + public function getCalName() + { + + return $this->cal_name; + } + + /** + * Get the [cal_description] column value. + * + * @return string + */ + public function getCalDescription() + { + + return $this->cal_description; + } + + /** + * Get the [add_tab_uid] column value. + * + * @return string + */ + public function getAddTabUid() + { + + return $this->add_tab_uid; + } + + /** + * Get the [cal_columns] column value. + * + * @return string + */ + public function getCalColumns() + { + + return $this->cal_columns; + } + + /** + * Get the [usr_id] column value. + * + * @return string + */ + public function getUsrId() + { + + return $this->usr_id; + } + + /** + * Get the [cal_icon_list] column value. + * + * @return string + */ + public function getCalIconList() + { + + return $this->cal_icon_list; + } + + /** + * Get the [cal_icon_color] column value. + * + * @return string + */ + public function getCalIconColor() + { + + return $this->cal_icon_color; + } + + /** + * Get the [cal_icon_color_screen] column value. + * + * @return string + */ + public function getCalIconColorScreen() + { + + return $this->cal_icon_color_screen; + } + + /** + * Get the [optionally formatted] [cal_create_date] column value. + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the integer unix timestamp will be returned. + * @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL). + * @throws PropelException - if unable to convert the date/time to timestamp. + */ + public function getCalCreateDate($format = 'Y-m-d H:i:s') + { + + if ($this->cal_create_date === null || $this->cal_create_date === '') { + return null; + } elseif (!is_int($this->cal_create_date)) { + // a non-timestamp value was set externally, so we convert it + $ts = strtotime($this->cal_create_date); + if ($ts === -1 || $ts === false) { + throw new PropelException("Unable to parse value of [cal_create_date] as date/time value: " . + var_export($this->cal_create_date, true)); + } + } else { + $ts = $this->cal_create_date; + } + if ($format === null) { + return $ts; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $ts); + } else { + return date($format, $ts); + } + } + + /** + * Get the [optionally formatted] [cal_update_date] column value. + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the integer unix timestamp will be returned. + * @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL). + * @throws PropelException - if unable to convert the date/time to timestamp. + */ + public function getCalUpdateDate($format = 'Y-m-d H:i:s') + { + + if ($this->cal_update_date === null || $this->cal_update_date === '') { + return null; + } elseif (!is_int($this->cal_update_date)) { + // a non-timestamp value was set externally, so we convert it + $ts = strtotime($this->cal_update_date); + if ($ts === -1 || $ts === false) { + throw new PropelException("Unable to parse value of [cal_update_date] as date/time value: " . + var_export($this->cal_update_date, true)); + } + } else { + $ts = $this->cal_update_date; + } + if ($format === null) { + return $ts; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $ts); + } else { + return date($format, $ts); + } + } + + /** + * Set the value of [cal_id] column. + * + * @param int $v new value + * @return void + */ + public function setCalId($v) + { + + // Since the native PHP type for this column is integer, + // we will cast the input value to an int (if it is not). + if ($v !== null && !is_int($v) && is_numeric($v)) { + $v = (int) $v; + } + + if ($this->cal_id !== $v) { + $this->cal_id = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_ID; + } + + } // setCalId() + + /** + * Set the value of [cal_type] column. + * + * @param string $v new value + * @return void + */ + public function setCalType($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_type !== $v) { + $this->cal_type = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_TYPE; + } + + } // setCalType() + + /** + * Set the value of [cal_name] column. + * + * @param string $v new value + * @return void + */ + public function setCalName($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_name !== $v) { + $this->cal_name = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_NAME; + } + + } // setCalName() + + /** + * Set the value of [cal_description] column. + * + * @param string $v new value + * @return void + */ + public function setCalDescription($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_description !== $v) { + $this->cal_description = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_DESCRIPTION; + } + + } // setCalDescription() + + /** + * Set the value of [add_tab_uid] column. + * + * @param string $v new value + * @return void + */ + public function setAddTabUid($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->add_tab_uid !== $v) { + $this->add_tab_uid = $v; + $this->modifiedColumns[] = CaseListPeer::ADD_TAB_UID; + } + + } // setAddTabUid() + + /** + * Set the value of [cal_columns] column. + * + * @param string $v new value + * @return void + */ + public function setCalColumns($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_columns !== $v) { + $this->cal_columns = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_COLUMNS; + } + + } // setCalColumns() + + /** + * Set the value of [usr_id] column. + * + * @param string $v new value + * @return void + */ + public function setUsrId($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->usr_id !== $v) { + $this->usr_id = $v; + $this->modifiedColumns[] = CaseListPeer::USR_ID; + } + + } // setUsrId() + + /** + * Set the value of [cal_icon_list] column. + * + * @param string $v new value + * @return void + */ + public function setCalIconList($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_icon_list !== $v) { + $this->cal_icon_list = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_ICON_LIST; + } + + } // setCalIconList() + + /** + * Set the value of [cal_icon_color] column. + * + * @param string $v new value + * @return void + */ + public function setCalIconColor($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_icon_color !== $v) { + $this->cal_icon_color = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_ICON_COLOR; + } + + } // setCalIconColor() + + /** + * Set the value of [cal_icon_color_screen] column. + * + * @param string $v new value + * @return void + */ + public function setCalIconColorScreen($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->cal_icon_color_screen !== $v) { + $this->cal_icon_color_screen = $v; + $this->modifiedColumns[] = CaseListPeer::CAL_ICON_COLOR_SCREEN; + } + + } // setCalIconColorScreen() + + /** + * Set the value of [cal_create_date] column. + * + * @param int $v new value + * @return void + */ + public function setCalCreateDate($v) + { + + if ($v !== null && !is_int($v)) { + $ts = strtotime($v); + //Date/time accepts null values + if ($v == '') { + $ts = null; + } + if ($ts === -1 || $ts === false) { + throw new PropelException("Unable to parse date/time value for [cal_create_date] from input: " . + var_export($v, true)); + } + } else { + $ts = $v; + } + if ($this->cal_create_date !== $ts) { + $this->cal_create_date = $ts; + $this->modifiedColumns[] = CaseListPeer::CAL_CREATE_DATE; + } + + } // setCalCreateDate() + + /** + * Set the value of [cal_update_date] column. + * + * @param int $v new value + * @return void + */ + public function setCalUpdateDate($v) + { + + if ($v !== null && !is_int($v)) { + $ts = strtotime($v); + //Date/time accepts null values + if ($v == '') { + $ts = null; + } + if ($ts === -1 || $ts === false) { + throw new PropelException("Unable to parse date/time value for [cal_update_date] from input: " . + var_export($v, true)); + } + } else { + $ts = $v; + } + if ($this->cal_update_date !== $ts) { + $this->cal_update_date = $ts; + $this->modifiedColumns[] = CaseListPeer::CAL_UPDATE_DATE; + } + + } // setCalUpdateDate() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (1-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos. + * @param int $startcol 1-based offset column which indicates which restultset column to start with. + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate(ResultSet $rs, $startcol = 1) + { + try { + + $this->cal_id = $rs->getInt($startcol + 0); + + $this->cal_type = $rs->getString($startcol + 1); + + $this->cal_name = $rs->getString($startcol + 2); + + $this->cal_description = $rs->getString($startcol + 3); + + $this->add_tab_uid = $rs->getString($startcol + 4); + + $this->cal_columns = $rs->getString($startcol + 5); + + $this->usr_id = $rs->getString($startcol + 6); + + $this->cal_icon_list = $rs->getString($startcol + 7); + + $this->cal_icon_color = $rs->getString($startcol + 8); + + $this->cal_icon_color_screen = $rs->getString($startcol + 9); + + $this->cal_create_date = $rs->getTimestamp($startcol + 10, null); + + $this->cal_update_date = $rs->getTimestamp($startcol + 11, null); + + $this->resetModified(); + + $this->setNew(false); + + // FIXME - using NUM_COLUMNS may be clearer. + return $startcol + 12; // 12 = CaseListPeer::NUM_COLUMNS - CaseListPeer::NUM_LAZY_LOAD_COLUMNS). + + } catch (Exception $e) { + throw new PropelException("Error populating CaseList object", $e); + } + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param Connection $con + * @return void + * @throws PropelException + * @see BaseObject::setDeleted() + * @see BaseObject::isDeleted() + */ + public function delete($con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getConnection(CaseListPeer::DATABASE_NAME); + } + + try { + $con->begin(); + CaseListPeer::doDelete($this, $con); + $this->setDeleted(true); + $con->commit(); + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. This method + * wraps the doSave() worker method in a transaction. + * + * @param Connection $con + * @return int The number of rows affected by this insert/update + * @throws PropelException + * @see doSave() + */ + public function save($con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getConnection(CaseListPeer::DATABASE_NAME); + } + + try { + $con->begin(); + $affectedRows = $this->doSave($con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Stores the object in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param Connection $con + * @return int The number of rows affected by this insert/update and any referring + * @throws PropelException + * @see save() + */ + protected function doSave($con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + + // If this object has been modified, then save it to the database. + if ($this->isModified()) { + if ($this->isNew()) { + $pk = CaseListPeer::doInsert($this, $con); + $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which + // should always be true here (even though technically + // BasePeer::doInsert() can insert multiple rows). + + $this->setCalId($pk); //[IMV] update autoincrement primary key + + $this->setNew(false); + } else { + $affectedRows += CaseListPeer::doUpdate($this, $con); + } + $this->resetModified(); // [HL] After being saved an object is no longer 'modified' + } + + $this->alreadyInSave = false; + } + return $affectedRows; + } // doSave() + + /** + * Array of ValidationFailed objects. + * @var array ValidationFailed[] + */ + protected $validationFailures = array(); + + /** + * Gets any ValidationFailed objects that resulted from last call to validate(). + * + * + * @return array ValidationFailed[] + * @see validate() + */ + public function getValidationFailures() + { + return $this->validationFailures; + } + + /** + * Validates the objects modified field values and all objects related to this table. + * + * If $columns is either a column name or an array of column names + * only those columns are validated. + * + * @param mixed $columns Column name or an array of column names. + * @return boolean Whether all columns pass validation. + * @see doValidate() + * @see getValidationFailures() + */ + public function validate($columns = null) + { + $res = $this->doValidate($columns); + if ($res === true) { + $this->validationFailures = array(); + return true; + } else { + $this->validationFailures = $res; + return false; + } + } + + /** + * This function performs the validation work for complex object models. + * + * In addition to checking the current object, all related objects will + * also be validated. If all pass then true is returned; otherwise + * an aggreagated array of ValidationFailed objects will be returned. + * + * @param array $columns Array of column names to validate. + * @return mixed true if all validations pass; + array of ValidationFailed objects otherwise. + */ + protected function doValidate($columns = null) + { + if (!$this->alreadyInValidation) { + $this->alreadyInValidation = true; + $retval = null; + + $failureMap = array(); + + + if (($retval = CaseListPeer::doValidate($this, $columns)) !== true) { + $failureMap = array_merge($failureMap, $retval); + } + + + + $this->alreadyInValidation = false; + } + + return (!empty($failureMap) ? $failureMap : true); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return mixed Value of field. + */ + public function getByName($name, $type = BasePeer::TYPE_PHPNAME) + { + $pos = CaseListPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM); + return $this->getByPosition($pos); + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch($pos) { + case 0: + return $this->getCalId(); + break; + case 1: + return $this->getCalType(); + break; + case 2: + return $this->getCalName(); + break; + case 3: + return $this->getCalDescription(); + break; + case 4: + return $this->getAddTabUid(); + break; + case 5: + return $this->getCalColumns(); + break; + case 6: + return $this->getUsrId(); + break; + case 7: + return $this->getCalIconList(); + break; + case 8: + return $this->getCalIconColor(); + break; + case 9: + return $this->getCalIconColorScreen(); + break; + case 10: + return $this->getCalCreateDate(); + break; + case 11: + return $this->getCalUpdateDate(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = BasePeer::TYPE_PHPNAME) + { + $keys = CaseListPeer::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getCalId(), + $keys[1] => $this->getCalType(), + $keys[2] => $this->getCalName(), + $keys[3] => $this->getCalDescription(), + $keys[4] => $this->getAddTabUid(), + $keys[5] => $this->getCalColumns(), + $keys[6] => $this->getUsrId(), + $keys[7] => $this->getCalIconList(), + $keys[8] => $this->getCalIconColor(), + $keys[9] => $this->getCalIconColorScreen(), + $keys[10] => $this->getCalCreateDate(), + $keys[11] => $this->getCalUpdateDate(), + ); + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name peer name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return void + */ + public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME) + { + $pos = CaseListPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM); + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch($pos) { + case 0: + $this->setCalId($value); + break; + case 1: + $this->setCalType($value); + break; + case 2: + $this->setCalName($value); + break; + case 3: + $this->setCalDescription($value); + break; + case 4: + $this->setAddTabUid($value); + break; + case 5: + $this->setCalColumns($value); + break; + case 6: + $this->setUsrId($value); + break; + case 7: + $this->setCalIconList($value); + break; + case 8: + $this->setCalIconColor($value); + break; + case 9: + $this->setCalIconColorScreen($value); + break; + case 10: + $this->setCalCreateDate($value); + break; + case 11: + $this->setCalUpdateDate($value); + break; + } // switch() + } + + /** + * 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 = CaseListPeer::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setCalId($arr[$keys[0]]); + } + + if (array_key_exists($keys[1], $arr)) { + $this->setCalType($arr[$keys[1]]); + } + + if (array_key_exists($keys[2], $arr)) { + $this->setCalName($arr[$keys[2]]); + } + + if (array_key_exists($keys[3], $arr)) { + $this->setCalDescription($arr[$keys[3]]); + } + + if (array_key_exists($keys[4], $arr)) { + $this->setAddTabUid($arr[$keys[4]]); + } + + if (array_key_exists($keys[5], $arr)) { + $this->setCalColumns($arr[$keys[5]]); + } + + if (array_key_exists($keys[6], $arr)) { + $this->setUsrId($arr[$keys[6]]); + } + + if (array_key_exists($keys[7], $arr)) { + $this->setCalIconList($arr[$keys[7]]); + } + + if (array_key_exists($keys[8], $arr)) { + $this->setCalIconColor($arr[$keys[8]]); + } + + if (array_key_exists($keys[9], $arr)) { + $this->setCalIconColorScreen($arr[$keys[9]]); + } + + if (array_key_exists($keys[10], $arr)) { + $this->setCalCreateDate($arr[$keys[10]]); + } + + if (array_key_exists($keys[11], $arr)) { + $this->setCalUpdateDate($arr[$keys[11]]); + } + + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(CaseListPeer::DATABASE_NAME); + + if ($this->isColumnModified(CaseListPeer::CAL_ID)) { + $criteria->add(CaseListPeer::CAL_ID, $this->cal_id); + } + + if ($this->isColumnModified(CaseListPeer::CAL_TYPE)) { + $criteria->add(CaseListPeer::CAL_TYPE, $this->cal_type); + } + + if ($this->isColumnModified(CaseListPeer::CAL_NAME)) { + $criteria->add(CaseListPeer::CAL_NAME, $this->cal_name); + } + + if ($this->isColumnModified(CaseListPeer::CAL_DESCRIPTION)) { + $criteria->add(CaseListPeer::CAL_DESCRIPTION, $this->cal_description); + } + + if ($this->isColumnModified(CaseListPeer::ADD_TAB_UID)) { + $criteria->add(CaseListPeer::ADD_TAB_UID, $this->add_tab_uid); + } + + if ($this->isColumnModified(CaseListPeer::CAL_COLUMNS)) { + $criteria->add(CaseListPeer::CAL_COLUMNS, $this->cal_columns); + } + + if ($this->isColumnModified(CaseListPeer::USR_ID)) { + $criteria->add(CaseListPeer::USR_ID, $this->usr_id); + } + + if ($this->isColumnModified(CaseListPeer::CAL_ICON_LIST)) { + $criteria->add(CaseListPeer::CAL_ICON_LIST, $this->cal_icon_list); + } + + if ($this->isColumnModified(CaseListPeer::CAL_ICON_COLOR)) { + $criteria->add(CaseListPeer::CAL_ICON_COLOR, $this->cal_icon_color); + } + + if ($this->isColumnModified(CaseListPeer::CAL_ICON_COLOR_SCREEN)) { + $criteria->add(CaseListPeer::CAL_ICON_COLOR_SCREEN, $this->cal_icon_color_screen); + } + + if ($this->isColumnModified(CaseListPeer::CAL_CREATE_DATE)) { + $criteria->add(CaseListPeer::CAL_CREATE_DATE, $this->cal_create_date); + } + + if ($this->isColumnModified(CaseListPeer::CAL_UPDATE_DATE)) { + $criteria->add(CaseListPeer::CAL_UPDATE_DATE, $this->cal_update_date); + } + + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(CaseListPeer::DATABASE_NAME); + + $criteria->add(CaseListPeer::CAL_ID, $this->cal_id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getCalId(); + } + + /** + * Generic method to set the primary key (cal_id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setCalId($key); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of CaseList (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false) + { + + $copyObj->setCalType($this->cal_type); + + $copyObj->setCalName($this->cal_name); + + $copyObj->setCalDescription($this->cal_description); + + $copyObj->setAddTabUid($this->add_tab_uid); + + $copyObj->setCalColumns($this->cal_columns); + + $copyObj->setUsrId($this->usr_id); + + $copyObj->setCalIconList($this->cal_icon_list); + + $copyObj->setCalIconColor($this->cal_icon_color); + + $copyObj->setCalIconColorScreen($this->cal_icon_color_screen); + + $copyObj->setCalCreateDate($this->cal_create_date); + + $copyObj->setCalUpdateDate($this->cal_update_date); + + + $copyObj->setNew(true); + + $copyObj->setCalId(NULL); // this is a pkey column, so set to default value + + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return CaseList Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + return $copyObj; + } + + /** + * Returns a peer instance associated with this om. + * + * Since Peer classes are not to have any instance attributes, this method returns the + * same instance for all member of this class. The method could therefore + * be static, but this would prevent one from overriding the behavior. + * + * @return CaseListPeer + */ + public function getPeer() + { + if (self::$peer === null) { + self::$peer = new CaseListPeer(); + } + return self::$peer; + } +} + diff --git a/workflow/engine/classes/model/om/BaseCaseListPeer.php b/workflow/engine/classes/model/om/BaseCaseListPeer.php new file mode 100644 index 000000000..c08932671 --- /dev/null +++ b/workflow/engine/classes/model/om/BaseCaseListPeer.php @@ -0,0 +1,624 @@ + array ('CalId', 'CalType', 'CalName', 'CalDescription', 'AddTabUid', 'CalColumns', 'UsrId', 'CalIconList', 'CalIconColor', 'CalIconColorScreen', 'CalCreateDate', 'CalUpdateDate', ), + BasePeer::TYPE_COLNAME => array (CaseListPeer::CAL_ID, CaseListPeer::CAL_TYPE, CaseListPeer::CAL_NAME, CaseListPeer::CAL_DESCRIPTION, CaseListPeer::ADD_TAB_UID, CaseListPeer::CAL_COLUMNS, CaseListPeer::USR_ID, CaseListPeer::CAL_ICON_LIST, CaseListPeer::CAL_ICON_COLOR, CaseListPeer::CAL_ICON_COLOR_SCREEN, CaseListPeer::CAL_CREATE_DATE, CaseListPeer::CAL_UPDATE_DATE, ), + BasePeer::TYPE_FIELDNAME => array ('CAL_ID', 'CAL_TYPE', 'CAL_NAME', 'CAL_DESCRIPTION', 'ADD_TAB_UID', 'CAL_COLUMNS', 'USR_ID', 'CAL_ICON_LIST', 'CAL_ICON_COLOR', 'CAL_ICON_COLOR_SCREEN', 'CAL_CREATE_DATE', 'CAL_UPDATE_DATE', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 + */ + private static $fieldKeys = array ( + BasePeer::TYPE_PHPNAME => array ('CalId' => 0, 'CalType' => 1, 'CalName' => 2, 'CalDescription' => 3, 'AddTabUid' => 4, 'CalColumns' => 5, 'UsrId' => 6, 'CalIconList' => 7, 'CalIconColor' => 8, 'CalIconColorScreen' => 9, 'CalCreateDate' => 10, 'CalUpdateDate' => 11, ), + BasePeer::TYPE_COLNAME => array (CaseListPeer::CAL_ID => 0, CaseListPeer::CAL_TYPE => 1, CaseListPeer::CAL_NAME => 2, CaseListPeer::CAL_DESCRIPTION => 3, CaseListPeer::ADD_TAB_UID => 4, CaseListPeer::CAL_COLUMNS => 5, CaseListPeer::USR_ID => 6, CaseListPeer::CAL_ICON_LIST => 7, CaseListPeer::CAL_ICON_COLOR => 8, CaseListPeer::CAL_ICON_COLOR_SCREEN => 9, CaseListPeer::CAL_CREATE_DATE => 10, CaseListPeer::CAL_UPDATE_DATE => 11, ), + BasePeer::TYPE_FIELDNAME => array ('CAL_ID' => 0, 'CAL_TYPE' => 1, 'CAL_NAME' => 2, 'CAL_DESCRIPTION' => 3, 'ADD_TAB_UID' => 4, 'CAL_COLUMNS' => 5, 'USR_ID' => 6, 'CAL_ICON_LIST' => 7, 'CAL_ICON_COLOR' => 8, 'CAL_ICON_COLOR_SCREEN' => 9, 'CAL_CREATE_DATE' => 10, 'CAL_UPDATE_DATE' => 11, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) + ); + + /** + * @return MapBuilder the map builder for this peer + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getMapBuilder() + { + include_once 'classes/model/map/CaseListMapBuilder.php'; + return BasePeer::getMapBuilder('classes.model.map.CaseListMapBuilder'); + } + /** + * Gets a map (hash) of PHP names to DB column names. + * + * @return array The PHP to DB name map for this peer + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @deprecated Use the getFieldNames() and translateFieldName() methods instead of this. + */ + public static function getPhpNameMap() + { + if (self::$phpNameMap === null) { + $map = CaseListPeer::getTableMap(); + $columns = $map->getColumns(); + $nameMap = array(); + foreach ($columns as $column) { + $nameMap[$column->getPhpName()] = $column->getColumnName(); + } + self::$phpNameMap = $nameMap; + } + return self::$phpNameMap; + } + /** + * Translates a fieldname to another type + * + * @param string $name field name + * @param string $fromType One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @param string $toType One of the class type constants + * @return string translated name of the field. + */ + static public function translateFieldName($name, $fromType, $toType) + { + $toNames = self::getFieldNames($toType); + $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null; + if ($key === null) { + throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true)); + } + return $toNames[$key]; + } + + /** + * Returns an array of of field names. + * + * @param string $type The type of fieldnames to return: + * One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return array A list of field names + */ + + static public function getFieldNames($type = BasePeer::TYPE_PHPNAME) + { + if (!array_key_exists($type, self::$fieldNames)) { + throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.'); + } + return self::$fieldNames[$type]; + } + + /** + * Convenience method which changes table.column to alias.column. + * + * Using this method you can maintain SQL abstraction while using column aliases. + * + * $c->addAlias("alias1", TablePeer::TABLE_NAME); + * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN); + * + * @param string $alias The alias for the current table. + * @param string $column The column name for current table. (i.e. CaseListPeer::COLUMN_NAME). + * @return string + */ + public static function alias($alias, $column) + { + return str_replace(CaseListPeer::TABLE_NAME.'.', $alias.'.', $column); + } + + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param criteria object containing the columns to add. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria) + { + + $criteria->addSelectColumn(CaseListPeer::CAL_ID); + + $criteria->addSelectColumn(CaseListPeer::CAL_TYPE); + + $criteria->addSelectColumn(CaseListPeer::CAL_NAME); + + $criteria->addSelectColumn(CaseListPeer::CAL_DESCRIPTION); + + $criteria->addSelectColumn(CaseListPeer::ADD_TAB_UID); + + $criteria->addSelectColumn(CaseListPeer::CAL_COLUMNS); + + $criteria->addSelectColumn(CaseListPeer::USR_ID); + + $criteria->addSelectColumn(CaseListPeer::CAL_ICON_LIST); + + $criteria->addSelectColumn(CaseListPeer::CAL_ICON_COLOR); + + $criteria->addSelectColumn(CaseListPeer::CAL_ICON_COLOR_SCREEN); + + $criteria->addSelectColumn(CaseListPeer::CAL_CREATE_DATE); + + $criteria->addSelectColumn(CaseListPeer::CAL_UPDATE_DATE); + + } + + const COUNT = 'COUNT(CASE_LIST.CAL_ID)'; + const COUNT_DISTINCT = 'COUNT(DISTINCT CASE_LIST.CAL_ID)'; + + /** + * Returns the number of rows matching criteria. + * + * @param Criteria $criteria + * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria). + * @param Connection $con + * @return int Number of matching rows. + */ + public static function doCount(Criteria $criteria, $distinct = false, $con = null) + { + // we're going to modify criteria, so copy it first + $criteria = clone $criteria; + + // clear out anything that might confuse the ORDER BY clause + $criteria->clearSelectColumns()->clearOrderByColumns(); + if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { + $criteria->addSelectColumn(CaseListPeer::COUNT_DISTINCT); + } else { + $criteria->addSelectColumn(CaseListPeer::COUNT); + } + + // just in case we're grouping: add those columns to the select statement + foreach ($criteria->getGroupByColumns() as $column) { + $criteria->addSelectColumn($column); + } + + $rs = CaseListPeer::doSelectRS($criteria, $con); + if ($rs->next()) { + return $rs->getInt(1); + } else { + // no rows returned; we infer that means 0 matches. + return 0; + } + } + /** + * Method to select one object from the DB. + * + * @param Criteria $criteria object used to create the SELECT statement. + * @param Connection $con + * @return CaseList + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelectOne(Criteria $criteria, $con = null) + { + $critcopy = clone $criteria; + $critcopy->setLimit(1); + $objects = CaseListPeer::doSelect($critcopy, $con); + if ($objects) { + return $objects[0]; + } + return null; + } + /** + * Method to do selects. + * + * @param Criteria $criteria The Criteria object used to build the SELECT statement. + * @param Connection $con + * @return array Array of selected Objects + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelect(Criteria $criteria, $con = null) + { + return CaseListPeer::populateObjects(CaseListPeer::doSelectRS($criteria, $con)); + } + /** + * Prepares the Criteria object and uses the parent doSelect() + * method to get a ResultSet. + * + * Use this method directly if you want to just get the resultset + * (instead of an array of objects). + * + * @param Criteria $criteria The Criteria object used to build the SELECT statement. + * @param Connection $con the connection to use + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return ResultSet The resultset object with numerically-indexed fields. + * @see BasePeer::doSelect() + */ + public static function doSelectRS(Criteria $criteria, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + if (!$criteria->getSelectColumns()) { + $criteria = clone $criteria; + CaseListPeer::addSelectColumns($criteria); + } + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + // BasePeer returns a Creole ResultSet, set to return + // rows indexed numerically. + return BasePeer::doSelect($criteria, $con); + } + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(ResultSet $rs) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = CaseListPeer::getOMClass(); + $cls = Propel::import($cls); + // populate the object(s) + while ($rs->next()) { + + $obj = new $cls(); + $obj->hydrate($rs); + $results[] = $obj; + + } + return $results; + } + /** + * Returns the TableMap related to this peer. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME); + } + + /** + * The class that the Peer will make instances of. + * + * This uses a dot-path notation which is tranalted into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @return string path.to.ClassName + */ + public static function getOMClass() + { + return CaseListPeer::CLASS_DEFAULT; + } + + /** + * Method perform an INSERT on the database, given a CaseList or Criteria object. + * + * @param mixed $values Criteria or CaseList object containing data that is used to create the INSERT statement. + * @param Connection $con the connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + } else { + $criteria = $values->buildCriteria(); // build Criteria from CaseList object + } + + //$criteria->remove(CaseListPeer::CAL_ID); // remove pkey col since this table uses auto-increment + + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->begin(); + $pk = BasePeer::doInsert($criteria, $con); + $con->commit(); + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + + return $pk; + } + + /** + * Method perform an UPDATE on the database, given a CaseList or Criteria object. + * + * @param mixed $values Criteria or CaseList object containing data create the UPDATE statement. + * @param Connection $con The connection to use (specify Connection exert more control over transactions). + * @return int The number of affected rows (if supported by underlying database driver). + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doUpdate($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + $selectCriteria = new Criteria(self::DATABASE_NAME); + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + + $comparison = $criteria->getComparison(CaseListPeer::CAL_ID); + $selectCriteria->add(CaseListPeer::CAL_ID, $criteria->remove(CaseListPeer::CAL_ID), $comparison); + + } else { + $criteria = $values->buildCriteria(); // gets full criteria + $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s) + } + + // set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + return BasePeer::doUpdate($selectCriteria, $criteria, $con); + } + + /** + * Method to DELETE all rows from the CASE_LIST table. + * + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll($con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->begin(); + $affectedRows += BasePeer::doDeleteAll(CaseListPeer::TABLE_NAME, $con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Method perform a DELETE on the database, given a CaseList or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or CaseList object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param Connection $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + * This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(CaseListPeer::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + } elseif ($values instanceof CaseList) { + + $criteria = $values->buildPkeyCriteria(); + } else { + // it must be the primary key + $criteria = new Criteria(self::DATABASE_NAME); + $criteria->add(CaseListPeer::CAL_ID, (array) $values, Criteria::IN); + } + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->begin(); + + $affectedRows += BasePeer::doDelete($criteria, $con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Validates all modified columns of given CaseList object. + * If parameter $columns is either a single column name or an array of column names + * than only those columns are validated. + * + * NOTICE: This does not apply to primary or foreign keys for now. + * + * @param CaseList $obj The object to validate. + * @param mixed $cols Column name or array of column names. + * + * @return mixed TRUE if all columns are valid or the error message of the first invalid column. + */ + public static function doValidate(CaseList $obj, $cols = null) + { + $columns = array(); + + if ($cols) { + $dbMap = Propel::getDatabaseMap(CaseListPeer::DATABASE_NAME); + $tableMap = $dbMap->getTable(CaseListPeer::TABLE_NAME); + + if (! is_array($cols)) { + $cols = array($cols); + } + + foreach ($cols as $colName) { + if ($tableMap->containsColumn($colName)) { + $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); + $columns[$colName] = $obj->$get(); + } + } + } else { + + } + + return BasePeer::doValidate(CaseListPeer::DATABASE_NAME, CaseListPeer::TABLE_NAME, $columns); + } + + /** + * Retrieve a single object by pkey. + * + * @param mixed $pk the primary key. + * @param Connection $con the connection to use + * @return CaseList + */ + public static function retrieveByPK($pk, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + $criteria = new Criteria(CaseListPeer::DATABASE_NAME); + + $criteria->add(CaseListPeer::CAL_ID, $pk); + + + $v = CaseListPeer::doSelect($criteria, $con); + + return !empty($v) > 0 ? $v[0] : null; + } + + /** + * 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(CaseListPeer::CAL_ID, $pks, Criteria::IN); + $objs = CaseListPeer::doSelect($criteria, $con); + } + return $objs; + } +} + + +// static code to register the map builder for this Peer with the main Propel class +if (Propel::isInit()) { + // the MapBuilder classes register themselves with Propel during initialization + // so we need to load them here. + try { + BaseCaseListPeer::getMapBuilder(); + } catch (Exception $e) { + Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR); + } +} else { + // even if Propel is not yet initialized, the map builder class can be registered + // now and then it will be loaded when Propel initializes. + require_once 'classes/model/map/CaseListMapBuilder.php'; + Propel::registerMapBuilder('classes.model.map.CaseListMapBuilder'); +} + diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 690d338f7..27e16ae9d 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -6117,4 +6117,22 @@ + + + + + + + + + + + + + + + + + +
diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index 13f44bc08..cd1647c3c 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -3406,5 +3406,28 @@ CREATE TABLE `USER_CONFIG` `USC_SETTING` MEDIUMTEXT NOT NULL, PRIMARY KEY (`USR_ID`,`USC_NAME`) )ENGINE=InnoDB DEFAULT CHARSET='utf8'; +#----------------------------------------------------------------------------- +#-- CASE_LIST +#----------------------------------------------------------------------------- + +DROP TABLE IF EXISTS `CASE_LIST`; + + +CREATE TABLE `CASE_LIST` +( + `CAL_ID` INTEGER NOT NULL AUTO_INCREMENT, + `CAL_TYPE` VARCHAR(255) NOT NULL, + `CAL_NAME` VARCHAR(255) NOT NULL, + `CAL_DESCRIPTION` MEDIUMTEXT, + `ADD_TAB_UID` VARCHAR(32) NOT NULL, + `CAL_COLUMNS` MEDIUMTEXT, + `USR_ID` BIGINT(20) NOT NULL, + `CAL_ICON_LIST` MEDIUMTEXT, + `CAL_ICON_COLOR` VARCHAR(255), + `CAL_ICON_COLOR_SCREEN` VARCHAR(255), + `CAL_CREATE_DATE` DATETIME NOT NULL, + `CAL_UPDATE_DATE` DATETIME NOT NULL, + PRIMARY KEY (`CAL_ID`) +)ENGINE=InnoDB DEFAULT CHARSET='utf8'; # This restores the fkey checks, after having unset them earlier SET FOREIGN_KEY_CHECKS = 1; diff --git a/workflow/engine/src/ProcessMaker/Model/CaseList.php b/workflow/engine/src/ProcessMaker/Model/CaseList.php new file mode 100644 index 000000000..a225079f9 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/CaseList.php @@ -0,0 +1,215 @@ + 'id', + 'CAL_TYPE' => 'type', + 'CAL_NAME' => 'name', + 'CAL_DESCRIPTION' => 'description', + 'ADD_TAB_UID' => 'tableUid', + 'CAL_COLUMNS' => 'columns', + 'USR_ID' => 'userId', + 'CAL_ICON_LIST' => 'iconList', + 'CAL_ICON_COLOR' => 'iconColor', + 'CAL_ICON_COLOR_SCREEN' => 'iconColorScreen', + 'CAL_CREATE_DATE' => 'createDate', + 'CAL_UPDATE_DATE' => 'updateDate', + 'USR_USERNAME' => 'userName', + 'USR_FIRSTNAME' => 'userFirstname', + 'USR_LASTNAME' => 'userLastname', + 'USR_EMAIL' => 'userEmail', + 'ADD_TAB_NAME' => 'tableName' + ]; + + /** + * Get column name from alias. + * @param array $array + * @return array + */ + public static function getColumnNameFromAlias(array $array): array + { + foreach (self::$columnAliases as $key => $value) { + if (array_key_exists($value, $array)) { + $array[$key] = $array[$value]; + unset($array[$value]); + } + } + return $array; + } + + /** + * Get alias from column name. + * @param array $array + * @return array + */ + public static function getAliasFromColumnName(array $array) + { + foreach (self::$columnAliases as $key => $value) { + if (array_key_exists($key, $array)) { + $array[$value] = $array[$key]; + unset($array[$key]); + } + } + return $array; + } + + /** + * Create and save this model from array values. + * @param array $values + * @return object + */ + public static function createSetting(array $values) + { + $attributes = CaseList::getColumnNameFromAlias($values); + + $attributes['CAL_CREATE_DATE'] = date("Y-m-d H:i:s"); + $attributes['CAL_UPDATE_DATE'] = date("Y-m-d H:i:s"); + if (empty($attributes['CAL_COLUMNS'])) { + $attributes['CAL_COLUMNS'] = []; + } + $attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']); + + $model = CaseList::create($attributes); + $model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS); + return $model; + } + + /** + * Update and save this model from array values. + * @param int $id + * @param array $values + * @return object + */ + public static function updateSetting(int $id, array $values) + { + $attributes = CaseList::getColumnNameFromAlias($values); + + $attributes['CAL_UPDATE_DATE'] = date("Y-m-d H:i:s"); + if (empty($attributes['CAL_COLUMNS'])) { + $attributes['CAL_COLUMNS'] = []; + } + $attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']); + + $caseList = CaseList::where('CAL_ID', '=', $id); + $caseList->update($attributes); + $model = $caseList->get()->first(); + if (!is_null($model)) { + $model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS); + } + return $model; + } + + /** + * Delete this model. + * @param int $id + * @return object + */ + public static function deleteSetting(int $id) + { + $caseList = CaseList::where('CAL_ID', '=', $id); + $model = $caseList->get()->first(); + if (!is_null($model)) { + $caseList->delete(); + $model->CAL_COLUMNS = json_decode($model->CAL_COLUMNS); + } + return $model; + } + + /** + * Get the array of the elements of this model, this method supports the filter by: + * name, description, user name, first user name, second user name, user email. + * The result is returned based on the delimiters to allow pagination and the total + * of the existing models. + * @param string $type + * @param string $search + * @param int $offset + * @param int $limit + * @return array + */ + public static function getSetting(string $type, string $search, int $offset, int $limit): array + { + $order = 'asc'; + $model = CaseList::where('CAL_TYPE', '=', $type) + ->leftJoin('USERS', 'USERS.USR_ID', '=', 'CASE_LIST.USR_ID') + ->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID') + ->select([ + 'CASE_LIST.*', + 'USERS.USR_UID', 'USERS.USR_USERNAME', 'USERS.USR_FIRSTNAME', 'USERS.USR_LASTNAME', 'USERS.USR_EMAIL', + 'ADDITIONAL_TABLES.ADD_TAB_NAME' + ]) + ->where(function ($query) use ($search) { + $query + ->orWhere('CASE_LIST.CAL_NAME', 'like', '%' . $search . '%') + ->orWhere('CASE_LIST.CAL_DESCRIPTION', 'like', '%' . $search . '%') + ->orWhere('USERS.USR_USERNAME', 'like', '%' . $search . '%') + ->orWhere('USERS.USR_FIRSTNAME', 'like', '%' . $search . '%') + ->orWhere('USERS.USR_LASTNAME', 'like', '%' . $search . '%') + ->orWhere('USERS.USR_EMAIL', 'like', '%' . $search . '%'); + }) + ->orderBy('CASE_LIST.CAL_NAME', $order); + + $count = $model->count(); + + $data = $model->offset($offset)->limit($limit)->get(); + $data->transform(function ($item, $key) { + if (is_null($item->CAL_COLUMNS)) { + $item->CAL_COLUMNS = '[]'; + } + + $result = CaseList::getAliasFromColumnName($item->toArray()); + + $result['columns'] = json_decode($result['columns']); + $result['userAvatar'] = System::getServerMainPath() . '/users/users_ViewPhotoGrid?pUID=' . $result['USR_UID'] . '&h=' . microtime(true); + unset($result['USR_UID']); + + return $result; + }); + + return [ + 'total' => $count, + 'data' => $data + ]; + } +} diff --git a/workflow/engine/src/ProcessMaker/Services/Api/CaseList.php b/workflow/engine/src/ProcessMaker/Services/Api/CaseList.php new file mode 100644 index 000000000..6f634a5f8 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Services/Api/CaseList.php @@ -0,0 +1,148 @@ +sSystem = 'PROCESSMAKER'; + $RBAC->initRBAC(); + $RBAC->loadUserRolePermission($RBAC->sSystem, $this->getUserId()); + } + } + + /** + * Create the Case List setting. + * @url POST + * @param array $request_data + * @access protected + * @class AccessControl {@permission PM_CASES} + * @return array + */ + public function doPost(array $request_data) + { + $caseList = CaseListBusinessModel::createSetting($request_data); + $caseList = CaseListBusinessModel::getAliasFromColumnName($caseList->toArray()); + return $caseList; + } + + /** + * Update the Case List setting. + * @url PUT /:id + * @param string $id + * @param array $request_data + * @access protected + * @class AccessControl {@permission PM_CASES} + * @throws RestException + * @return array + */ + public function doPut(int $id, array $request_data) + { + $caseList = CaseListBusinessModel::updateSetting($id, $request_data); + if (is_null($caseList)) { + throw new RestException(Api::STAT_APP_EXCEPTION, G::LoadTranslation('ID_DOES_NOT_EXIST')); + } + $caseList = CaseListBusinessModel::getAliasFromColumnName($caseList->toArray()); + return $caseList; + } + + /** + * Delete the Case List setting. + * @url DELETE /:id + * @param string $id + * @access protected + * @class AccessControl {@permission PM_CASES} + * @throws RestException + * @return array + */ + public function doDelete(int $id) + { + try { + $caseList = CaseListBusinessModel::deleteSetting($id); + if (is_null($caseList)) { + throw new RestException(Api::STAT_APP_EXCEPTION, G::LoadTranslation('ID_DOES_NOT_EXIST')); + } + $caseList = CaseListBusinessModel::getAliasFromColumnName($caseList->toArray()); + return $caseList; + } catch (Exception $e) { + throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); + } + } + + /** + * Get inbox Case List settings. + * @url GET /inbox + * @param string $search + * @param string $offset + * @param string $limit + * @access protected + * @class AccessControl {@permission PM_CASES} + * @return array + */ + public function doGetInbox(string $search = '', int $offset = 0, int $limit = 10) + { + return CaseListBusinessModel::getSetting('inbox', $search, $offset, $limit); + } + + /** + * Get draft Case List settings. + * @url GET /draft + * @param string $search + * @param string $offset + * @param string $limit + * @access protected + * @class AccessControl {@permission PM_CASES} + * @return array + */ + public function doGetDraft(string $search = '', int $offset = 0, int $limit = 10) + { + return CaseListBusinessModel::getSetting('draft', $search, $offset, $limit); + } + + /** + * Get paused Case List settings. + * @url GET /paused + * @param string $search + * @param string $offset + * @param string $limit + * @access protected + * @class AccessControl {@permission PM_CASES} + * @return array + */ + public function doGetPaused(string $search = '', int $offset = 0, int $limit = 10) + { + return CaseListBusinessModel::getSetting('paused', $search, $offset, $limit); + } + + /** + * Get unassigned Case List settings. + * @url GET /unassigned + * @param string $search + * @param string $offset + * @param string $limit + * @access protected + * @class AccessControl {@permission PM_CASES} + * @return array + */ + public function doGetUnassigned(string $search, int $offset, int $limit) + { + return CaseListBusinessModel::getSetting('unassigned', $search, $offset, $limit); + } +}