forked from schoology/schoology_php_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchoologyContentApi.class.php
129 lines (117 loc) · 3.47 KB
/
SchoologyContentApi.class.php
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
<?php
require_once 'SchoologyApi.class.php';
require_once 'SchoologyExceptions.php';
class SchoologyContentApi extends SchoologyApi {
private $schoology_site_base = '';
public function __construct( $consumer_key, $consumer_secret, $site_base = '', $token_key = '', $token_secret = '') {
$this->schoology_site_base = $site_base;
parent::__construct($consumer_key, $consumer_secret, $site_base, $token_key, $token_secret);
}
/**
* Wrapper for importing embed content
*/
public function importEmbed($title, $embed) {
$info = array(
'title' => $title,
'embed' => $embed,
);
return $this->import('embed', $info);
}
/**
* Wrapper for importing link content
*/
public function importLink($title, $url) {
$info = array(
'title' => $title,
'url' => $url,
);
return $this->import('link', $info);
}
/**
* Wrapper for importing file content
*/
public function importFile($filepath) {
$info = array(
'filepath' => $filepath,
);
return $this->import('file', $info);
}
/**
* Import content to Schoology servers
*
* @param string $type content type embed|link|file
* @param array $info content info (title, url ..etc)
* @return
* import id and redirect url to Schoology content import form
*/
public function import($type, $info) {
switch($type) {
case 'embed':
$api_result = $this->api('content_app/import/embed', 'POST', $info);
break;
case 'link':
$api_result = $this->api('content_app/import/link', 'POST', $info);
break;
case 'file':
$info = array('file-attachment' => array(
'id' => $this->apiFileUpload($info['filepath'])
));
$api_result = $this->api('content_app/import/file', 'POST', $info);
break;
}
return $api_result->result->import_id;
}
/**
* Bulk import content into Schoology
*
* @param array $body content info
*
* eg,
* $body = array(
* 'link' => array(
* array('title' => $link_title, 'url' => $link_url),
* ...
* ),
*
* 'embed' => $embeds = array(
* array('title' => $embed_title, 'embed' => $embed_body),
* ...
* ),
*
* 'file-attachment' => array('id' => array(
* $schoology->apiFileUpload($filepath),
* ....
* )),
* );
*
* @return
* import id and redirect url to Schoology content import form
*/
public function importBulk($body) {
$api_result = $this->api('content_app/import', 'POST', $body);
return $api_result->result;
}
/**
* Build url to Schooology import form
*
* @param int $import_id schoology import id
* @param string $return_url url to schoology import form
* @return string
* Import Url, used to redirect the user to the Schoology Import Form
*/
public function buildImportUrl($import_id, $return_url = '') {
if(is_array($import_id)) {
$import_id_qs = '';
foreach($import_id as $i) {
$import_id_qs .= 'import_id[]='.$i.'&';
}
}
else {
$import_id_qs = 'import_id[]='.$import_id.'&';
}
if(!$return_url) {
$return_url = (@$_SERVER['HTTPS'] && @$_SERVER['HTTPS'] != 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
return $this->schoology_site_base . '/content_app/import?'. $import_id_qs .'return_url=' . $return_url;
}
}