-
Notifications
You must be signed in to change notification settings - Fork 1
/
pg_simplepay.install
executable file
·149 lines (142 loc) · 3.82 KB
/
pg_simplepay.install
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* @file
* Installation file for module "Simple pay".
*/
/**
* Implements hook_install().
*/
function pg_simplepay_install() {
// Create a newsletter type if needed.
$type = node_type_get_type('pg_simplepay');
if (!$type) {
$type = node_type_set_defaults(array(
'type' => 'pg_simplepay',
'name' => t('Simplepay node'),
'base' => 'node_content',
'description' => t('Create a node with paid access.'),
'locked' => 0,
'custom' => 1,
'modified' => 1,
));
node_type_save($type);
node_add_body_field($type);
}
}
/**
* Implements hook_enable().
*/
function pg_simplepay_enable(){
if (!field_read_field('pg_simplepay_price', array('include_inactive' => TRUE))) {
$field = array(
'field_name' => 'pg_simplepay_price',
'type' => 'number_decimal',
'settings' => array(
'precision' => 10,
'scale' => 2,
'decimal_separator' => '.',
),
);
field_create_field($field);
}
// Create the instance if needed.
if (!field_read_instance('pg_simplepay_price', 'pg_simplepay_price', 'pg_simplepay_price', array('include_inactive' => TRUE))) {
field_attach_create_bundle('pg_simplepay_price', 'pg_simplepay_price');
// Attaches the price field by default.
$instance = array(
'field_name' => 'pg_simplepay_price',
'label' => 'Price',
'entity_type' => 'node',
'bundle' => 'pg_simplepay',
'required' => TRUE,
'widget' => array(
'type' => 'number',
),
'display' => array(
'default' => array(
'type' => 'number_decimal',
),
'teaser' => array(
'type' => 'number_decimal',
),
),
);
field_create_instance($instance);
}
if (!field_read_field('pg_simplepay_free', array('include_inactive' => TRUE))) {
$field = array(
'field_name' => 'pg_simplepay_free',
'type' => 'list_boolean',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(1 => t('Free access'), 0 => t('Paid access')),
),
);
field_create_field($field);
}
// Create the instance if needed.
if (!field_read_instance('pg_simplepay_free', 'pg_simplepay_free', 'pg_simplepay_free', array('include_inactive' => TRUE))) {
field_attach_create_bundle('pg_simplepay_free', 'pg_simplepay_free');
// Attaches the price field by default.
$instance = array(
'field_name' => 'pg_simplepay_free',
'label' => 'Free access',
'entity_type' => 'node',
'bundle' => 'pg_simplepay',
'widget' => array(
'type' => 'options_onoff',
),
'display' => array(
'default' => array(
'type' => 'hidden',
),
),
);
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall.
*/
function pg_simplepay_uninstall() {
field_delete_field('pg_simplepay_price');
field_delete_field('pg_simplepay_free');
node_type_delete('pg_simplepay');
}
/**
* Implements hook_schema.
*/
function pg_simplepay_schema() {
$schema['pg_simplepay_payment'] = array(
'description' => 'Simplepay node price information.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'session' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'txnid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('nid'),
);
return $schema;
}