uc_coupon.views.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <?php
  2. /**
  3. * @file
  4. * Views 2 hooks and callback registries.
  5. */
  6. /**
  7. * Implements hook_views_data().
  8. */
  9. function uc_coupon_views_data() {
  10. $data['uc_coupons']['table']['group'] = t('Coupon');
  11. $data['uc_coupons']['table']['base'] = array(
  12. 'field' => 'cid',
  13. 'title' => t('Coupon'),
  14. 'help' => t("Ubercart discount coupons."),
  15. );
  16. $data['uc_coupons']['cid'] = array(
  17. 'title' => t('ID'),
  18. 'help' => t('The unique ID of the coupon.'),
  19. 'field' => array(
  20. 'handler' => 'views_handler_field',
  21. 'click sortable' => TRUE,
  22. ),
  23. 'sort' => array(
  24. 'handler' => 'views_handler_sort',
  25. ),
  26. 'filter' => array(
  27. 'handler' => 'views_handler_filter_numeric',
  28. ),
  29. 'argument' => array(
  30. 'handler' => 'views_handler_argument_numeric',
  31. ),
  32. );
  33. $data['uc_coupons']['name'] = array(
  34. 'title' => t('Name'),
  35. 'help' => t('The name of the coupon.'),
  36. 'field' => array(
  37. 'handler' => 'views_handler_field',
  38. 'click sortable' => TRUE,
  39. ),
  40. 'sort' => array(
  41. 'handler' => 'views_handler_sort',
  42. ),
  43. 'filter' => array(
  44. 'handler' => 'views_handler_filter_string',
  45. ),
  46. 'argument' => array(
  47. 'handler' => 'views_handler_argument_string',
  48. ),
  49. );
  50. $data['uc_coupons']['code'] = array(
  51. 'title' => t('Code'),
  52. 'help' => t('The coupon code, or prefix for bulk coupons.'),
  53. 'field' => array(
  54. 'handler' => 'views_handler_field',
  55. 'click sortable' => TRUE,
  56. ),
  57. 'sort' => array(
  58. 'handler' => 'views_handler_sort',
  59. ),
  60. 'filter' => array(
  61. 'handler' => 'views_handler_filter_string',
  62. ),
  63. 'argument' => array(
  64. 'handler' => 'views_handler_argument_string',
  65. ),
  66. );
  67. $data['uc_coupons']['bulk_codes'] = array(
  68. 'title' => t('Codes'),
  69. 'help' => t('All codes associated with this coupon.'),
  70. 'field' => array(
  71. 'handler' => 'uc_coupon_handler_field_codes',
  72. 'field' => 'cid',
  73. ),
  74. );
  75. $data['uc_coupons']['bulk'] = array(
  76. 'title' => t('Bulk'),
  77. 'help' => t('Whether the coupon is a bulk coupon with multiple suffixes.'),
  78. 'field' => array(
  79. 'handler' => 'views_handler_field_boolean',
  80. 'click sortable' => TRUE,
  81. ),
  82. 'filter' => array(
  83. 'handler' => 'views_handler_filter_boolean_operator',
  84. 'label' => t('Is a bulk coupon'),
  85. 'type' => 'yes-no',
  86. ),
  87. 'sort' => array(
  88. 'handler' => 'views_handler_sort',
  89. ),
  90. );
  91. $data['uc_coupons']['created'] = array(
  92. 'title' => t('Creation date'),
  93. 'help' => t('The date the coupon was created.'),
  94. 'field' => array(
  95. 'handler' => 'views_handler_field_date',
  96. 'click sortable' => TRUE,
  97. ),
  98. 'sort' => array(
  99. 'handler' => 'views_handler_sort_date',
  100. ),
  101. 'filter' => array(
  102. 'handler' => 'views_handler_filter_date',
  103. ),
  104. );
  105. $data['uc_coupons']['valid_from'] = array(
  106. 'title' => t('Valid from'),
  107. 'help' => t('The date the coupon becomes valid.'),
  108. 'field' => array(
  109. 'handler' => 'views_handler_field_date',
  110. 'click sortable' => TRUE,
  111. ),
  112. 'sort' => array(
  113. 'handler' => 'views_handler_sort_date',
  114. ),
  115. 'filter' => array(
  116. 'handler' => 'views_handler_filter_date',
  117. ),
  118. );
  119. $data['uc_coupons']['valid_until'] = array(
  120. 'title' => t('Valid until'),
  121. 'help' => t('The date the coupon expires.'),
  122. 'field' => array(
  123. 'handler' => 'views_handler_field_date',
  124. 'click sortable' => TRUE,
  125. ),
  126. 'sort' => array(
  127. 'handler' => 'views_handler_sort_date',
  128. ),
  129. 'filter' => array(
  130. 'handler' => 'views_handler_filter_date',
  131. ),
  132. );
  133. $data['uc_coupons']['status'] = array(
  134. 'title' => 'Active',
  135. 'help' => t('Whether the coupon is available to use.'),
  136. 'field' => array(
  137. 'handler' => 'views_handler_field_boolean',
  138. 'click sortable' => TRUE,
  139. ),
  140. 'filter' => array(
  141. 'handler' => 'views_handler_filter_boolean_operator',
  142. 'label' => t('Active'),
  143. 'type' => 'yes-no',
  144. ),
  145. 'sort' => array(
  146. 'handler' => 'views_handler_sort',
  147. ),
  148. );
  149. $data['uc_coupons']['type'] = array(
  150. 'title' => 'Type',
  151. 'help' => t('The discount type of the coupon.'),
  152. 'field' => array(
  153. 'handler' => 'views_handler_field',
  154. 'click sortable' => TRUE,
  155. ),
  156. 'sort' => array(
  157. 'handler' => 'views_handler_sort',
  158. ),
  159. 'filter' => array(
  160. 'handler' => 'views_handler_filter_string',
  161. ),
  162. 'argument' => array(
  163. 'handler' => 'views_handler_argument_string',
  164. ),
  165. );
  166. $data['uc_coupons']['value'] = array(
  167. 'title' => t('Value'),
  168. 'help' => t('The value of the coupon.'),
  169. 'field' => array(
  170. 'handler' => 'uc_coupon_handler_field_value',
  171. 'click sortable' => TRUE,
  172. 'float' => TRUE,
  173. 'additional fields' => array(
  174. 'type' => 'type',
  175. ),
  176. ),
  177. 'sort' => array(
  178. 'handler' => 'views_handler_sort',
  179. ),
  180. 'filter' => array(
  181. 'handler' => 'views_handler_filter_numeric',
  182. ),
  183. 'argument' => array(
  184. 'handler' => 'views_handler_argument_numeric',
  185. ),
  186. );
  187. $data['uc_coupons']['minimum_order'] = array(
  188. 'title' => t('Minimum order total'),
  189. 'help' => t('The minimum order total that applies to the coupon.'),
  190. 'field' => array(
  191. 'handler' => 'views_handler_field_numeric',
  192. 'click sortable' => TRUE,
  193. 'float' => TRUE,
  194. ),
  195. 'sort' => array(
  196. 'handler' => 'views_handler_sort',
  197. ),
  198. 'filter' => array(
  199. 'handler' => 'views_handler_filter_numeric',
  200. ),
  201. 'argument' => array(
  202. 'handler' => 'views_handler_argument_numeric',
  203. ),
  204. );
  205. $data['uc_coupons']['max_uses'] = array(
  206. 'title' => t('Max uses per code'),
  207. 'help' => t('The maximum number of times this coupon can be redeemed.'),
  208. 'field' => array(
  209. 'handler' => 'views_handler_field',
  210. 'click sortable' => TRUE,
  211. ),
  212. 'sort' => array(
  213. 'handler' => 'views_handler_sort',
  214. ),
  215. 'filter' => array(
  216. 'handler' => 'views_handler_filter_numeric',
  217. ),
  218. 'argument' => array(
  219. 'handler' => 'views_handler_argument_numeric',
  220. ),
  221. );
  222. $data['uc_coupons']['actions'] = array(
  223. 'title' => t('Actions'),
  224. 'help' => t('A set of actions the current user can perform on the coupon.'),
  225. 'field' => array(
  226. 'handler' => 'uc_coupon_handler_field_actions',
  227. 'field' => 'cid',
  228. 'additional fields' => array(
  229. 'name' => 'name',
  230. 'bulk' => 'bulk',
  231. ),
  232. ),
  233. );
  234. $data['uc_coupons']['product_type'] = array(
  235. 'title' => t('Product classes'),
  236. 'help' => t('Product classes for which this coupon is valid.'),
  237. 'field' => array(
  238. 'field' => 'cid',
  239. 'handler' => 'uc_coupon_handler_field_product_type',
  240. 'label' => t('Product types'),
  241. 'additional fields' => array(
  242. 'data' => 'data',
  243. ),
  244. ),
  245. 'filter' => array(
  246. 'handler' => 'uc_coupon_handler_filter_product_type',
  247. 'label' => 'Is a product type',
  248. ),
  249. 'argument' => array(
  250. 'handler' => 'uc_coupon_handler_argument_product_type',
  251. 'label' => 'Is a product type',
  252. ),
  253. );
  254. $data['uc_coupons']['bulk_number'] = array(
  255. 'title' => t('Bulk number'),
  256. 'help' => t('Number of bulk codes based on this coupon.'),
  257. 'field' => array(
  258. 'handler' => 'uc_coupon_handler_field_bulk_number',
  259. 'field' => 'data',
  260. ),
  261. );
  262. $data['uc_coupons']['all_orders_count'] = array(
  263. 'title' => t('All orders count'),
  264. 'help' => t('The number of orders to which this coupon was applied.'),
  265. 'field' => array(
  266. 'handler' => 'uc_coupon_handler_field_all_orders_count',
  267. ),
  268. );
  269. $data['uc_coupons']['table']['join']['uc_orders'] = array(
  270. 'left_table' => 'uc_coupons_orders',
  271. 'left_field' => 'oid',
  272. 'field' => 'order_id',
  273. );
  274. $data['uc_coupons']['all_orders_total'] = array(
  275. 'title' => t('All orders total'),
  276. 'help' => t('The total bottom-line for all orders to which this coupon was applied.'),
  277. 'field' => array(
  278. 'handler' => 'uc_coupon_handler_field_all_orders_total',
  279. 'float' => TRUE,
  280. ),
  281. );
  282. $data['uc_coupons']['all_orders_value'] = array(
  283. 'title' => t('All orders total value'),
  284. 'help' => t('The total value of this coupon for all orders to which it was applied.'),
  285. 'field' => array(
  286. 'handler' => 'uc_coupon_handler_field_all_orders_value',
  287. 'float' => TRUE,
  288. ),
  289. );
  290. $data['uc_coupons']['all_orders_gross'] = array(
  291. 'title' => t('All orders gross total'),
  292. 'help' => t('The pre-discount total for all orders to which this coupon was applied.'),
  293. 'field' => array(
  294. 'handler' => 'uc_coupon_handler_field_all_orders_gross',
  295. 'float' => TRUE,
  296. ),
  297. );
  298. //
  299. // Table: uc_coupons_orders
  300. //
  301. $data['uc_coupons_orders']['table']['group'] = t('Coupon order');
  302. $data['uc_coupons_orders']['table']['join']['uc_coupons'] = array(
  303. 'left_field' => 'cid',
  304. 'field' => 'cid',
  305. );
  306. // Join to the uc_orders table.
  307. $data['uc_coupons_orders']['table']['join']['uc_orders'] = array(
  308. 'left_field' => 'order_id',
  309. 'field' => 'oid',
  310. );
  311. $data['uc_orders']['table']['join']['uc_coupons'] = array(
  312. 'left_table' => 'uc_coupons_orders',
  313. 'left_field' => 'oid',
  314. 'field' => 'order_id',
  315. );
  316. $data['uc_coupons_orders']['code'] = array(
  317. 'title' => t('Code'),
  318. 'help' => t('The coupon code used for this order'),
  319. 'field' => array(
  320. 'handler' => 'views_handler_field',
  321. 'click sortable' => TRUE,
  322. ),
  323. 'sort' => array(
  324. 'handler' => 'views_handler_sort',
  325. ),
  326. 'filter' => array(
  327. 'handler' => 'views_handler_filter_string',
  328. ),
  329. 'argument' => array(
  330. 'handler' => 'views_handler_argument_string',
  331. ),
  332. );
  333. $data['uc_coupons_orders']['value'] = array(
  334. 'title' => t('Value'),
  335. 'help' => t('The value of the coupon used for this order'),
  336. 'field' => array(
  337. 'handler' => 'uc_order_handler_field_money_amount',
  338. 'click sortable' => TRUE,
  339. 'float' => TRUE,
  340. ),
  341. 'sort' => array(
  342. 'handler' => 'views_handler_sort',
  343. ),
  344. 'filter' => array(
  345. 'handler' => 'views_handler_filter_string',
  346. ),
  347. 'argument' => array(
  348. 'handler' => 'views_handler_argument_string',
  349. ),
  350. );
  351. $data['uc_coupons_orders']['gross'] = array(
  352. 'title' => t('Gross'),
  353. 'help' => t('The pre-discount bottom-line for this order'),
  354. 'field' => array(
  355. 'handler' => 'uc_coupon_handler_field_gross',
  356. 'float' => TRUE,
  357. 'click sortable' => TRUE,
  358. ),
  359. 'sort' => array(
  360. 'handler' => 'views_handler_sort',
  361. ),
  362. 'filter' => array(
  363. 'handler' => 'uc_coupon_handler_filter_gross'
  364. ),
  365. );
  366. $data['uc_coupons_orders']['oid'] = array(
  367. 'title' => t('Order ID'),
  368. 'help' => t('The order ID of this coupon order'),
  369. 'field' => array(
  370. 'handler' => 'views_handler_field',
  371. 'click sortable' => TRUE,
  372. ),
  373. 'sort' => array(
  374. 'handler' => 'views_handler_sort',
  375. ),
  376. 'filter' => array(
  377. 'handler' => 'views_handler_filter_string',
  378. ),
  379. 'argument' => array(
  380. 'handler' => 'views_handler_argument_string',
  381. ),
  382. );
  383. return $data;
  384. }
  385. /**
  386. * Implements hook_views_handlers().
  387. */
  388. function uc_coupon_views_handlers() {
  389. return array(
  390. 'info' => array(
  391. 'path' => drupal_get_path('module', 'uc_coupon') . '/views',
  392. ),
  393. 'handlers' => array(
  394. 'uc_coupon_handler_field_value' => array(
  395. 'parent' => 'views_handler_field_numeric',
  396. ),
  397. 'uc_coupon_handler_field_actions' => array(
  398. 'parent' => 'views_handler_field',
  399. ),
  400. 'uc_coupon_handler_field_bulk_number' => array(
  401. 'parent' => 'views_handler_field_numeric',
  402. ),
  403. 'uc_coupon_handler_field_codes' => array(
  404. 'parent' => 'views_handler_field_prerender_list',
  405. ),
  406. 'uc_coupon_handler_filter_product_type' => array(
  407. 'parent' => 'views_handler_filter_in_operator',
  408. ),
  409. 'uc_coupon_handler_argument_product_type' => array(
  410. 'parent' => 'views_handler_argument',
  411. ),
  412. 'uc_coupon_handler_field_product_type' => array(
  413. 'parent' => 'views_handler_field_prerender_list',
  414. ),
  415. 'uc_coupon_handler_field_all_orders_count' => array(
  416. 'parent' => 'views_handler_field_numeric',
  417. ),
  418. 'uc_coupon_handler_field_all_orders_total' => array(
  419. 'parent' => 'uc_order_handler_field_money_amount',
  420. ),
  421. 'uc_coupon_handler_field_all_orders_value' => array(
  422. 'parent' => 'uc_coupon_handler_field_all_orders_total',
  423. ),
  424. 'uc_coupon_handler_field_all_orders_gross' => array(
  425. 'parent' => 'uc_coupon_handler_field_all_orders_total',
  426. ),
  427. 'uc_coupon_handler_field_gross' => array(
  428. 'parent' => 'uc_order_handler_field_money_amount',
  429. ),
  430. 'uc_coupon_handler_filter_gross' => array(
  431. 'parent' => 'views_handler_filter_numeric',
  432. ),
  433. ),
  434. );
  435. }