-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcivicrm_mer.module
97 lines (86 loc) · 2.98 KB
/
civicrm_mer.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
function civicrm_mer_civicrm_config( &$config ) {
$civicrm_mer_dir_path = dirname( __FILE__ );
set_include_path( $civicrm_mer_dir_path . PATH_SEPARATOR . get_include_path() );
$civicrm_mer_template_dir_path = civicrm_mer_paths_join($civicrm_mer_dir_path, 'templates');
$template =& CRM_Core_Smarty::singleton();
if (is_array($template->template_dir))
{
array_push( $template->template_dir, $civicrm_mer_template_dir_path );
}
else
{
$template->template_dir = array($civicrm_mer_template_dir_path, $template->template_dir);
}
}
function civicrm_mer_civicrm_pageRun( &$page ) {
$template = $page->getTemplate( );
$register_url = $template->get_template_vars( 'registerURL' );
if ( !is_null( $register_url ) ) {
require_once 'CRM/Event/BAO/Cart.php';
$action = CRM_Utils_Request::retrieve( 'action', 'String', $page, false );
$event_id = CRM_Utils_Request::retrieve( 'id', 'Positive', $page, true );
$cart = CRM_Event_BAO_Cart::find_or_create_for_current_session( );
$cart->load_associations( );
$in_cart = false;
foreach ( $cart->events_in_carts as $event_in_cart ) {
if ($event_id == $event_in_cart->event->id) {
$in_cart = true;
break;
}
}
if ( $action == CRM_Core_Action::PREVIEW ) {
if ($in_cart) {
$register_url = CRM_Utils_System::url( 'civicrm/event/remove_from_cart', "id={$event_id}&reset=1&action=preview", true, null, true, true );
} else {
$register_url = CRM_Utils_System::url( 'civicrm/event/add_to_cart', "id={$event_id}&reset=1&action=preview", true, null, true, true );
}
}
else {
if ($in_cart) {
$register_url = CRM_Utils_System::url( 'civicrm/event/remove_from_cart', "id={$event_id}&reset=1", true, null, true, true );
} else {
$register_url = CRM_Utils_System::url( 'civicrm/event/add_to_cart', "id={$event_id}&reset=1", true, null, true, true );
}
}
$page->assign( 'registerURL', $register_url );
}
}
function civicrm_mer_civicrm_xmlMenu( &$files ) {
$menu_files_path = civicrm_mer_paths_join( getcwd( ), drupal_get_path( 'module', 'civicrm_mer' ), "CRM", "Event", "xml", "Menu" );
$menu_files_paths = CRM_Utils_File::getFilesByExtension( $menu_files_path, "xml" );
$files = array_merge( $files, $menu_files_paths );
return $files;
}
function civicrm_mer_init( ) {
if ( ! civicrm_initialize( ) ) {
return;
}
if ( arg(0) != 'civicrm' ) {
$session = CRM_Core_Session::singleton( );
if ( $session->getStatus( false ) ) {
$status = $session->getStatus( true );
if ( is_array( $status ) ) {
foreach ( $status as $key => $value ) {
drupal_set_message ( $value, $key );
}
}
else
{
drupal_set_message( $status, 'status' );
}
}
}
}
function civicrm_mer_paths_join( ) {
return join( DIRECTORY_SEPARATOR, func_get_args( ) );
}
function civicrm_mer_perm ( ) {
return null;
}
function civicrm_mer_views_api() {
return array(
'api' => 2,
);
}
?>