PageRenderTime 34ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/views/crud/delete_popup.view.php

https://github.com/jay3/core
PHP | 92 lines | 77 code | 6 blank | 9 comment | 15 complexity | 78d0a77a9c8e7c627f433a118d108c7a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * NOVIUS OS - Web OS for digital communication
  4. *
  5. * @copyright 2011 Novius
  6. * @license GNU Affero General Public License v3 or (at your option) any later version
  7. * http://www.gnu.org/licenses/agpl-3.0.html
  8. * @link http://www.novius-os.org
  9. */
  10. ?>
  11. <input type="hidden" name="id" value="<?= $item->{$crud['pk']} ?>" />
  12. <p>
  13. <?php
  14. if ($crud['behaviours']['twinnable']) {
  15. $item_contexts = $item->find_context('all');
  16. $context_count = count($item_contexts);
  17. if ($crud['behaviours']['tree']) {
  18. $children = array();
  19. $children_context = array();
  20. // Count the number of children in each context
  21. foreach ($item_contexts as $item_context) {
  22. $children_context[$item_context->get_context()] = 1;
  23. foreach ($item_context->find_children_recursive(false) as $child) {
  24. $children[$child->{$crud['behaviours']['twinnable']['common_id_property']}] = true;
  25. $children_context[$item_context->get_context()]++;
  26. }
  27. }
  28. $children_count = count($children);
  29. } else {
  30. $children_count = 0;
  31. }
  32. } else {
  33. $context_count = 1;
  34. if ($crud['behaviours']['tree']) {
  35. $children_count = count($item->find_children_recursive(false));
  36. } else {
  37. $children_count = 0;
  38. }
  39. }
  40. $context_or_language = count(Nos\Tools_Context::sites()) == 1 ? 'language' : 'context';
  41. if ($children_count > 0 || $context_count > 1) {
  42. $deletion_summary = array();
  43. if ($context_count > 1) {
  44. $deletion_summary[] = 'N '.$context_or_language.'s';
  45. }
  46. if ($children_count > 0) {
  47. $deletion_summary[] = $children_count == 1 ? '1 child' : 'N children';
  48. }
  49. $deletion_summary = $crud['config']['i18n']['deleting with '.implode(' and ', $deletion_summary)];
  50. $deletion_summary = strtr($deletion_summary, array(
  51. '{{'.$context_or_language.'_count}}' => $context_count,
  52. '{{children_count}}' => $children_count,
  53. '{{title}}' => $item->title_item(),
  54. ));
  55. ?>
  56. <p><?= $deletion_summary ?></p>
  57. <?php
  58. }
  59. if ($context_count > 1) {
  60. $contexts = \Nos\User\Permission::contexts();
  61. $contexts_list = array();
  62. ?>
  63. <table class="grid">
  64. <?php
  65. foreach ($item_contexts as $item_context) {
  66. $is_disabled = \Nos\Config_Common::checkActionDisabled('delete', $item_context, array(
  67. 'delete_popup' => true,
  68. ));
  69. $context = $item_context->get_context();
  70. $count = isset($children_context[$context]) ? $children_context[$context] : 1;
  71. ?>
  72. <tr>
  73. <td><?= Nos\Tools_Context::contextLabel($item_context->get_context()) ?></td>
  74. <td><?= strtr($crud['config']['i18n'][$count == 1 ? '1 item' : 'N items'], array('{{count}}' => $count)) ?></td>
  75. <td><input type="checkbox" name="contexts[]" class="count" data-count="<?= $count ?>" value="<?= $context ?>" <?= $is_disabled ? 'disabled' : 'checked' ?> /></td>
  76. </tr>
  77. <?php
  78. }
  79. ?>
  80. </table>
  81. <?php
  82. } else {
  83. ?>
  84. <input type="checkbox" name="contexts[]" class="count" data-count="<?= $children_count + 1 ?>" value="<?= $crud['behaviours']['twinnable'] ? $item->get_context() : 'all' ?>" checked style="display:none;" />
  85. <?php
  86. }