-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckan.module
executable file
·150 lines (133 loc) · 3.76 KB
/
ckan.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
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
<?php
/**
* @file
*
* A Module to Integrate CKAN and Drupal.
*
*
*/
module_load_include('inc', 'ckan', 'ckan.tags');
module_load_include('inc', 'ckan', 'ckan.users');
module_load_include('inc', 'ckan', 'ckan.groups');
module_load_include('inc', 'ckan', 'ckan.licenses');
module_load_include('inc', 'ckan', 'ckan.packages');
/**
*
*
* hook_menu
*
*
*/
function ckan_menu(){
$items = array();
$items['ckan/list'] = array(
'page callback' => 'ckan_list',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ckan.packages.inc',
);
$items['ckan/tags'] = array(
'page callback' => 'ckan_tags',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ckan.packages.inc',
);
$items['ckan/groups'] = array(
'page callback' => 'ckan_groups',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ckan.groups.inc',
);
$items['ckan/users'] = array(
'page callback' => 'ckan_users',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ckan.users.inc',
);
$items['ckan/licenses'] = array(
'page callback' => 'ckan_licenses',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'ckan.licenses.inc',
);
$items['admin/config/system/ckan'] = array(
'title' => 'Ckan',
'description' => 'Configure Ckan',
'page callback' => 'drupal_get_form',
'page arguments' => array('ckan_admin_settings_form'),
'access arguments' => array('administer Ckan'),
'type' => MENU_NORMAL_ITEM,
'file' => 'ckan.admin.inc',
);
$items['recline'] = array(
'title' => 'Ckan',
'description' => 'Configure Ckan',
'page callback' => 'ckan_display_recline',
'access arguments' => array('administer Ckan'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Initialize the ckan object
*
*
*/
function ckan_ckan(){
static $ckan=null;
if (!$ckan){
require_once(dirname(__FILE__) . '/ckan.php');
$ckan=new Ckan(variable_get('ckan_url', ''),variable_get('ckan_api', ''));
}
return $ckan;
}
/**
* create a node extrafield
*
*/
function ckan_createnodeextra($name,$value,$uid=1){
$nd = new stdClass(); // We create a new node object
$nd->type = "ckan_extrafields"; // Or any other content type you want
$nd->title = "Extra field ".$name;
$nd->uid = $uid;
$nd->language = LANGUAGE_NONE;
//$nd->created =strtotime(str_replace("T"," ",$ckan_data-> metadata_created));
//$nd->changed=strtotime(str_replace("T"," ",$ckan_data-> metadata_last_modified));
$nd->field_labelchamp[LANGUAGE_NONE][0]['value'] = $name;
$nd->field_valuechamp[LANGUAGE_NONE][0]['value'] = $value;
$ndextra = node_submit($nd); // Prepare node for a submit
node_save($ndextra);
$nidextra=$ndextra->nid;
return $nidextra;
}
/**
* check if a node extrafield exists already
*
*/
function ckan_checkextra($name,$value){
$query = db_select('field_data_field_labelchamp', 'l');
$query->join('field_data_field_valuechamp', 'v', 'l.entity_id = v.entity_id'); // inner_join file_usage table against file_managed
$query->fields('l', array('entity_id'))->condition('l.field_labelchamp_value', $name, '=')->condition("v.field_valuechamp_value",$value,'=');
$result = $query->execute();
$nidextra=key($result->fetchAllAssoc('entity_id'));
return $nidextra;
}
/**
* Th hook_cron
*
*
*/
function ckan_cron(){
echo "Debut tags import<br/>";
ckan_tags();
echo "fin tags import<br/>";
echo "Debut users import<br/>";
ckan_users();
echo "fin users import<br/>";
echo "Debut groupes import<br/>";
ckan_groups();
echo "fin groupes import<br/>";
echo "Debut packages import<br/>";
ckan_list();
echo "fin packages import<br/>";
}