uc_termsofservice.rules.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @file
  4. * Conditional Actions hooks and functions for the terms of service panes.
  5. */
  6. /**
  7. * Implements hook_ca_predicate().
  8. */
  9. function uc_termsofservice_ca_predicate() {
  10. $predicates['uc_termsofservice_display_pane'] = array(
  11. '#title' => t('Display pane depending on the product classes'),
  12. '#class' => 'uc_termsofservice',
  13. '#trigger' => 'uc_termsofservice_display_pane',
  14. '#status' => 1,
  15. '#conditions' => array(
  16. '#operator' => 'AND',
  17. '#conditions' => array(
  18. array(
  19. '#name' => 'uc_termsofservice_condition_product_class',
  20. '#title' => t('Check if there are products of the selected product classes.'),
  21. '#argument_map' => array(
  22. 'cart' => 'cart',
  23. ),
  24. '#settings' => array(
  25. 'negate' => FALSE,
  26. 'class' => array('product'),
  27. ),
  28. ),
  29. ),
  30. ),
  31. '#actions' => array(),
  32. );
  33. return $predicates;
  34. }
  35. /**
  36. * Implements hook_ca_trigger().
  37. */
  38. function uc_termsofservice_ca_trigger() {
  39. $triggers['uc_termsofservice_display_pane'] = array(
  40. '#title' => t('Display checkout or cart panes'),
  41. '#category' => t('Checkout'),
  42. '#arguments' => array(
  43. 'cart' => array('#entity' => 'cart', '#title' => t('Cart')),
  44. ),
  45. );
  46. return $triggers;
  47. }
  48. /**
  49. * Implements hook_ca_condition().
  50. */
  51. function uc_termsofservice_ca_condition() {
  52. $conditions['uc_termsofservice_condition_product_class'] = array(
  53. '#title' => t('Order has a product of a particular class'),
  54. '#category' => t('Order: Product'),
  55. '#callback' => 'uc_termsofservice_condition_product_class',
  56. '#arguments' => array(
  57. 'cart' => array('#entity' => 'cart', '#title' => t('Cart')),
  58. ),
  59. );
  60. return $conditions;
  61. }
  62. /**
  63. * Condition Callbacks and Forms.
  64. */
  65. /**
  66. * Checks that an order has a product of the selected class.
  67. *
  68. * @see uc_termsofservice_condition_product_class_form()
  69. */
  70. function uc_termsofservice_condition_product_class($cart, $settings) {
  71. foreach ($cart as $cart_item) {
  72. if ($cart_item->nid) {
  73. $type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $cart_item->nid));
  74. if (in_array($type, array_values($settings['class']), TRUE)) {
  75. return TRUE;
  76. }
  77. }
  78. }
  79. return FALSE;
  80. }
  81. /**
  82. * @see uc_termsofservice_condition_product_class()
  83. */
  84. function uc_termsofservice_condition_product_class_form($form_state, $settings = array()) {
  85. $form['class'] = array(
  86. '#type' => 'checkboxes',
  87. '#title' => t('Product class'),
  88. '#options' => uc_product_type_names(),
  89. '#default_value' => $settings['class'],
  90. '#multiple' => TRUE,
  91. );
  92. return $form;
  93. }