//save workflow for behaviours
$WCollectionID 				= $WorkFlowData['WFlowCollection'];
$WCollectionTable 			= $this -> _getCollectionTableName($WCollectionID);
$WCollectionFieldName 		= $this->_getCollectionFieldName($WCollectionID, 1);
$WCollectionFieldNameApply 	= $this->_getCollectionFieldName($WCollectionID, 2);

$ApplyIn = array();
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_ADMIN_ADD] 			= 'wFlowBehaviourAddAdminActive';
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_ADMIN_EDIT] 			= 'wFlowBehaviourEditAdminActive';
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_ADMIN_DELETE] 		= 'wFlowBehaviourDeleteAdminActive';
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_ADD] 		= 'wFlowBehaviourAddFrontEndActive';
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_EDIT] 		= 'wFlowBehaviourEditFrontEndActive';
$ApplyIn[COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_DELETE] 		= 'wFlowBehaviourDeleteFrontEndActive';

foreach ($ApplyIn as $ApplyKey => $ApplyValue)
{

$q = "SELECT * FROM ". $WCollectionTable. " WHERE " . $WCollectionFieldName . " = " . $CollectionID . " AND " . $WCollectionFieldNameApply . " = " . $ApplyKey;
$res = $db->query($q);

if ($res->numRows() == 0)
{
		$addArray = array();
		$addArray[$WCollectionFieldName] = $CollectionID;
		$addArray[$WCollectionFieldNameApply] = $ApplyKey;
		$addArray[$this->_getCollectionFieldName($WCollectionID, 3)] = $Data[$ApplyValue];
		$addArray[$this->_getCollectionFieldName($WCollectionID, 4)] = $Data[$ApplyValue];
		$db->extended->autoExecute($WCollectionTable, $addArray, MDB2_AUTOQUERY_INSERT);
}
else
{
		$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
		$addArray = array();
		$addArray[$this->_getCollectionFieldName($WCollectionID, 3)] = $Data[$ApplyValue];
		$addArray[$this->_getCollectionFieldName($WCollectionID, 4)] = $Data[$ApplyValue];
		$db->extended->autoExecute($WCollectionTable, $addArray, MDB2_AUTOQUERY_UPDATE, ' '.$this->_getCollectionFieldName($WCollectionID, 'ID').' = ' . $row[$this->_getCollectionFieldName($WCollectionID, 'ID')]);
}

}//end foreach