| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJT_Models_Formgroups { |
| 10 |
|
| 11 |
/** |
| 12 |
* Delete parameter or group or parameters |
| 13 |
* or all parameters associasted to specific block. |
| 14 |
* |
| 15 |
* Each Key might has only the parameterId or blockId or both of them. |
| 16 |
* |
| 17 |
* @param array array('formId' => ID, 'groupId' => 'ID). |
| 18 |
* @return |
| 19 |
*/ |
| 20 |
public function delete($keys) { |
| 21 |
// Initialize. |
| 22 |
$tblFormGroup = CJTxTable::getInstance('form-group') |
| 23 |
->setTableKey(array('formId', 'groupId')); |
| 24 |
$tblGroupXFields= CJTxTable::getInstance('form-group-xfields') |
| 25 |
->setTableKey(array('groupId')); |
| 26 |
$tblGroupParam = CJTxTable::getInstance('group-parameter') |
| 27 |
->setTableKey(array('groupId')); |
| 28 |
$tblParamTypedef = CJTxTable::getInstance('parameter-typedef') |
| 29 |
->setTableKey(array('parameterId')); |
| 30 |
// Delete groups.. |
| 31 |
foreach ($keys as $key) { |
| 32 |
// Allow only blockId to be passed as scalar! |
| 33 |
if (!is_array($key)) { |
| 34 |
$key = array($key); |
| 35 |
} |
| 36 |
// Blolckid passed @index 0 while parameters id @index 1 |
| 37 |
$key = array( |
| 38 |
'formId' => $key[0], |
| 39 |
'groupId' => isset($key[1]) ? $key[1] : null, |
| 40 |
); |
| 41 |
// Get all exists ids |
| 42 |
$groups = $tblFormGroup->setData($key) |
| 43 |
->fetchAll(); |
| 44 |
// For each group get all assocuated parameters. |
| 45 |
foreach ($groups as $group) { |
| 46 |
// Delete GROUP XFields record associated with the group. |
| 47 |
$tblGroupXFields->set('groupId', $group['id']) |
| 48 |
->delete(); |
| 49 |
// Get all params. |
| 50 |
$params = $tblGroupParam->set('groupId', $group['id']) |
| 51 |
->fetchAll(); |
| 52 |
// Delete parameters typedef! |
| 53 |
foreach ($params as $param) { |
| 54 |
$tblParamTypedef->set('parameterId', $param['parameterId']) |
| 55 |
->delete(); |
| 56 |
} |
| 57 |
// Delete group parameters. |
| 58 |
$tblGroupParam->delete(); |
| 59 |
} |
| 60 |
// Delete groups. |
| 61 |
$tblFormGroup->delete(); |
| 62 |
} |
| 63 |
// Chaining. |
| 64 |
return $this; |
| 65 |
} |
| 66 |
|
| 67 |
} // End class. |
| 68 |
|