providerService();
$serviceCreds = PR()->serviceLogin();
$activities = array();
$groups = get_option('pr_activity_groups');
// Look up the info if we have the login.
if ($serviceCreds['username']) {
$activityList = new PonoRezActivityList ($psc, $serviceCreds);
$activities = $activityList->displayItems(array('filter' => @$_GET['pra_filter'],
'page' => @$_GET['pra_page'],
'count' => @$_GET['pra_count']));
}
// List our groups.
if ($groups): ?>
Activity Groups
Name
Activities
Shortcode
$activityIds): ?>
[pr_group name=""]
Available Activities
< Prev
| Page currentPage ?> of maxPage ?> |
Next >
Loading and displaying a single activity is simple. Use the pr_activity shortcode as displayed in
the Available Activities below. A group of activities takes a little more work. For a sample
template of how an activity group can be used, check
out the Activity Group
Example in our wiki.
Enter login information above to see your activity list.
providerService();
$testResult = $psc->testLogin(array('serviceLogin' => array('username' => $username,
'password' => $password)));
// Return values kept here.
$ajaxResult = array();
if (true == $testResult->return) {
update_option('pr_username', $username);
update_option('pr_password', $password);
$ajaxResult['success'] = true;
}
else {
$ajaxResult['success'] = false;
$ajaxResult['message'] = $testResult->out_status;
}
header( "Content-Type: application/json" );
echo json_encode($ajaxResult);
wp_die();
}
/**
* Delete groups.
*/
public function ajaxDeleteGroups () {
$groups = get_option('pr_activity_groups');
if (!$groups) {
$groups == array();
}
$groupsToDelete = $_GET['groups'];
$deleteCount = 0;
foreach ($groupsToDelete as $gn) {
if ($groups[$gn]) {
unset($groups[$gn]);
$deleteCount++;
}
}
// If we've deleted things, save our modified array.
if (0 < $deleteCount) {
update_option('pr_activity_groups', $groups);
}
$ajaxResult = array(
'success' => true,
'deleteCount' => $deleteCount
);
header( "Content-Type: application/json" );
echo json_encode($ajaxResult);
wp_die();
}
/**
* Store group information submitted by form.
*/
public function ajaxStoreGroup () {
$groups = get_option('pr_activity_groups');
if (!$groups) {
$groups == array();
}
$groupName = $_GET['groupname'];
$activityIds = $_GET['idlist'];
// Sanitize the group name. All lower case, numbers and letters only. Must start with a letter.
$groupName = preg_replace('/\W+/', '', strtolower($groupName));
if ('' === $groupName) {
$groupName = 'g' . date('Ymd');
}
// If there is no groupName or groupIds, we fail now.
if (!$groupName || 0 >= count($activityIds)) {
$ajaxResult = array(
'success' => false,
'message' => sprintf('Cannot add %d activities to group "%s".',
count($activityIds),
$groupName)
);
} else {
// Store our new group.
$groups[$groupName] = $activityIds;
update_option('pr_activity_groups', $groups);
$ajaxResult = array(
'success' => true,
'groupName' => $groupName,
'activityIds' => $activityIds
);
}
header( "Content-Type: application/json" );
echo json_encode($ajaxResult);
wp_die();
}
public function init () {
if (!is_admin()) {
return;
}
// Setup AJAX calls
add_action('wp_ajax_pr_store_login', array($this, 'ajaxStoreLogin'));
add_action('wp_ajax_pr_activity_list', array($this, 'prActivityList'));
add_action('wp_ajax_pr_store_group', array($this, 'ajaxStoreGroup'));
add_action('wp_ajax_pr_delete_groups', array($this, 'ajaxDeleteGroups'));
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
}
// Non-Ajax admin stuff.
//wp_enqueue_script('pr_admin', plugins_url('assets/pr_admin.min.js', dirname(__FILE__)), array('jquery'));
wp_enqueue_script('pr_admin', plugins_url('assets/original/pr_admin.js', dirname(__FILE__)), array('jquery'));
add_action('admin_menu', array($this, 'addSettingsMenu'));
add_action('admin_init', array($this, 'registerSettings'));
}
}