Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Added new functions: AddMultiUser, build_csv_multi, UpdatePermission #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions MadMimi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ function build_csv($arr) {
$csv .= "\n";
return $csv;
}
function build_csv_multi($arr){
$csv = "";
$keys = array_keys($arr['0']);
foreach ($keys as $key => $value) {
$value = $this->escape_for_csv($value);
$csv .= $value . ",";
}
$csv = substr($csv, 0, -1);
$csv .= "\n";

foreach ($arr as $member){
foreach ($member as $key => $value) {
$value = $this->escape_for_csv($value);
$csv .= $value . ",";
}
$csv = substr($csv, 0, -1);
$csv .= "\n";
}
return $csv;
}
function Import($csv_data, $return = false) {
$options = array('csv_file' => $csv_data) + $this->default_options();
$request = $this->DoRequest('/audience_members', $options, $return, 'POST');
Expand All @@ -135,10 +155,19 @@ function Lists($return = false) {
$request = $this->DoRequest('/audience_lists/lists.xml', $this->default_options(), $return);
return $request;
}
function UpdatePermission($email, $full = '', $read = '', $none = '', $return = false) {
$options = array('email' => $email, 'full' => $full, 'read' => $read, 'none' => $none ) + $this->default_options();
$request = $this->DoRequest('/participants/update_permissions_for', $options, $return, 'POST');
return $request;
}
function AddUser($user, $return = false) {
$csv = $this->build_csv($user);
$this->Import($csv, $return);
}
function AddMultiUser($user, $return = false) {
$csv = $this->build_csv_multi($user);
$this->Import($csv, $return);
}
function RemoveUser($email, $list_name, $return = false) {
$options = array('email' => $email) + $this->default_options();
$request = $this->DoRequest('/audience_lists/' . rawurlencode($list_name) . "/remove", $options, $return, 'POST');
Expand Down