//Get user Id
$userId = $this->getUser()->getGuardUser()->getId();
- //Get data from user
- $checked = $request->getParameter('checked');
+ //Get data from user. Empty array by default.
+ $checked = $request->getParameter('checked', array());
$uniqChecked = array_unique($checked, SORT_NUMERIC);
$iterator = $userBaskets->getIterator();
while ($userBasket = $iterator->current())
{
- if (!empty($uniqChecked))
+ foreach ($uniqChecked as $index => $value)
{
- foreach ($uniqChecked as $index => $value)
+ if ($userBasket->getGeneralCategId() == $value)
{
- if ($userBasket->getGeneralCategId() == $value)
- {
- unset($uniqChecked[$index]);
- $iterator->next();
- continue 2;
- }
+ unset($uniqChecked[$index]);
+ $iterator->next();
+ //I know this sucks, but I am in a hurry.
+ continue 2;
}
}
$userBaskets->remove($iterator->key());
{
//Never trust in data coming from users... Performance vs security.
$generalCategory = GeneralCategoryTable::getInstance()->findOneById($value);
+ //TODO: some evil person could send the data without using my nice JavaScript code
+ //Here I should check if the node has child nodes and add them always, even if the user
+ //did not send them because she/he is not using my nice JavaScript code. My JavaScript code
+ //always checks the child nodes' checkbox following the hierarchy structure.
if ($generalCategory != null)
{
$userBasket = new UserBasket();
}, "json");
};
</script>
+<script type="text/javascript">
+ function hierarchyCheck(node, checkedInput) {
+ $("table.treeTable tbody tr.child-of-" + node[0].id).each(function(data){
+ $(this).children('td').eq(1).find('input').prop('checked', checkedInput);
+ $(this).children('td').eq(1).find('input').prop('disabled', checkedInput);
+ hierarchyCheck($(this), checkedInput);
+ });
+
+ }
+ $(document).ready(function(){
+ $('[id^=node]').change(function(){
+ var checkedInput = false;
+ if($(this).children('td').eq(1).find('input').is(':checked')) {
+ checkedInput = true;
+ }
+ hierarchyCheck($(this), checkedInput);
+ });
+ });
+</script>
+