Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2 beta #3

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
63 changes: 38 additions & 25 deletions CRM/Contactcalendar/BAO/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,48 @@ class CRM_Contactcalendar_BAO_Calendar{
/**
* Get Calendar event by $contactId
*/
static function getActivities($contactId){

$queryParam = array(1 => array($contactId, 'Integer'));

//get assignee and target contact
$query = "
SELECT activity.id,
activity.subject,
activity.activity_date_time,
activity.duration,
activity.status_id
FROM civicrm_activity activity
LEFT JOIN civicrm_activity_assignment assignment ON assignment.activity_id = activity.id
LEFT JOIN civicrm_activity_target target ON target.activity_id = activity.id
WHERE (assignment.assignee_contact_id = %1 OR target.target_contact_id = %1)
AND activity.is_deleted = 0
AND activity.is_current_revision = 1
GROUP BY activity.id";
//static function getActivities($contactId){
static function getActivities($contactId, $start, $end, $show, $hide){

$queryParam = array(1 => array($contactId, 'Integer'), 2 => array($start, 'String'), 3 => array($end, 'String'));

$query1 = "SELECT activity.id,
activity.subject,
activity.activity_date_time,
activity.duration,
activity.status_id
FROM civicrm_activity activity
LEFT JOIN civicrm_activity_contact assignment ON assignment.activity_id = activity.id
LEFT JOIN civicrm_activity_contact target ON target.activity_id = activity.id
WHERE (assignment.contact_id = %1 OR target.contact_id = %1)
AND activity.activity_date_time BETWEEN %2 AND %3";

$query2 = "AND activity.activity_type_id IN ($show)";

$query3 = "AND activity.activity_type_id NOT IN ($hide)";

$query4 = "AND activity.is_deleted = 0
AND activity.is_current_revision = 1
AND activity.medium_id IS NULL
GROUP BY activity.id";

$query = $query1;

if(strtolower($show) != "all"){$query = $query." ".$query2;}
if($hide != "0"){$query = $query." ".$query3;}

$query = $query." ".$query4;

$activities = array();
$dao = CRM_Core_DAO::executeQuery($query, $queryParam);
while ($dao->fetch()) {
$activities[$dao->id]['id'] = $dao->id;
$activities[$dao->id]['subject'] = $dao->subject;
$activities[$dao->id]['duration'] = $dao->duration;
$activities[$dao->id]['status_id'] = $dao->status_id;
$activities[$dao->id]['activity_date_time'] = $dao->activity_date_time;
$activities[$dao->id]['id'] = $dao->id;
$activities[$dao->id]['cid'] = $contactId;
$activities[$dao->id]['subject'] = $dao->subject;
$activities[$dao->id]['duration'] = $dao->duration;
$activities[$dao->id]['status_id'] = $dao->status_id;
$activities[$dao->id]['activity_date_time'] = $dao->activity_date_time;
}

return $activities;
}
}
}
9 changes: 7 additions & 2 deletions api/v3/Calendar/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
function civicrm_api3_calendar_get($params) {
try{
$cid = CRM_Utils_Array::value('cid',$params);
$start = date('Y-m-d H:i:s', CRM_Utils_Array::value('start',$params));
$end = date('Y-m-d H:i:s', CRM_Utils_Array::value('end',$params));
$show = CRM_Utils_Array::value('show',$params);
$hide = CRM_Utils_Array::value('hide',$params);

require_once 'CRM/Contactcalendar/BAO/Calendar.php';
$activities = CRM_Contactcalendar_BAO_Calendar::getActivities($cid);
$activities = CRM_Contactcalendar_BAO_Calendar::getActivities($cid, $start, $end, $show, $hide);

$events = array();
foreach($activities as $k => $activity){

$events[$k]['cid'] = $activity['cid'];
$events[$k]['id'] = $activity['id'];
$events[$k]['title'] = $activity['subject'];
$events[$k]['start'] = $activity['activity_date_time'];

Expand All @@ -41,4 +47,3 @@ function civicrm_api3_calendar_get($params) {
throw new API_Exception($ex, 0001);
}
}

2 changes: 0 additions & 2 deletions resources/css/fullcalendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,3 @@ table.fc-border-separate {
.fc-agenda .ui-resizable-resizing { /* TODO: better selector */
_overflow: hidden;
}


2 changes: 0 additions & 2 deletions resources/css/fullcalendar.print.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,3 @@
.fc-event .ui-resizable-handle {
display: none !important;
}


138 changes: 132 additions & 6 deletions templates/CRM/Contactcalendar/Page/Calendar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
<style type="text/css" media="print">@import url("{$config->extensionsURL}/uk.co.compucorp.civicrm.contactcalendar/resources/css/fullcalendar.print.css");</style>

<div id='calendar'></div>

{literal}
<script type="text/javascript">
var crmajaxURL = '{/literal}{php} print base_path(); {/php}{literal}civicrm/ajax/rest';
var CiviBorderColor = "#36c";
var ActivityType = 1;

(function ($) {
jQuery(document).ready(function () {
jQuery(document).ready(function () {
jQuery('#calendar').fullCalendar({
header: {
left: 'prev,next, today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'month',
firstDay: 1,
firstDay: 0,
allDaySlot: true,
slotMinutes: 15,
events: function(start, end, callback) {
jQuery.ajax({
async: false,
cache: false,
url: crmajaxURL,
dataType: 'json',
Expand All @@ -30,6 +33,8 @@ var crmajaxURL = '{/literal}{php} print base_path(); {/php}{literal}civicrm/ajax
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000),
cid: {/literal}{$contactId}{literal},
show: 'all', // Activity Types (all = All types or Activity Type numbers separated by commas to only Show)
hide: '0', // Activity Types (0 = Hide none or Activity Type numbers separated by commas to Hide)
entity: 'Calendar',
action: 'Get',
json: 1,
Expand All @@ -39,6 +44,65 @@ var crmajaxURL = '{/literal}{php} print base_path(); {/php}{literal}civicrm/ajax
var events = new Array();
for(index in data.values){
e = data.values[index];

jQuery.ajax({
async: false,
cache: false,
url: crmajaxURL,
dataType: 'json',
data: {
id: e.id,
entity: 'Activity',
action: 'Get',
json: 1,
sequential: 1
},
success: function(data) {
var aevents = new Array();
for(aindex in data.values){
ae = data.values[aindex];

TheColors = CiviColor(parseInt(ae.activity_type_id));
var now = '{/literal}{php} print date("Y-m-d H:i:s"); {/php}{literal}';

var a=ae.activity_date_time.split(" ");
var b=a[0].split("-");
var c=a[1].split(":");
var TimeStart = new Date(b[0],(b[1]-1),b[2],b[0],c[1],c[2]);

var a=now.split(" ");
var b=a[0].split("-");
var c=a[1].split(":");
var TimeNow = new Date(b[0],(b[1]-1),b[2],b[0],c[1],c[2]);

TimeStartString = Math.round(TimeStart.getTime() / 1000);
TimeNowString = Math.round(TimeNow.getTime() / 1000);

if ((parseInt(ae.status_id) != 2) && (TimeStartString < TimeNowString) && (TheColors[2] != "Default")) { // Past Due
CiviBorderColor = '#FF0000';
// TheColors[1] = CiviBorderColor;
}else if (TheColors[2] != "Default"){ // Not Past Due
switch(parseInt(ae.status_id)) {
case 1: // Scheduled
CiviBorderColor = 'white';
// TheColors[1] = CiviBorderColor;
break;
case 2: // Completed
CiviBorderColor = 'Grey';
// TheColors[1] = CiviBorderColor;
break;
default: //default code block
CiviBorderColor = 'white';
// TheColors[1] = CiviBorderColor;
}
}else {
CiviBorderColor = 'white';
// TheColors[1] = CiviBorderColor;
}
}
}
});

ad = false;
if(e.allDay == 1){
ad = true;
Expand All @@ -47,15 +111,77 @@ var crmajaxURL = '{/literal}{php} print base_path(); {/php}{literal}civicrm/ajax
title: e.title,
start: e.start,
end: e.end,
allDay: ad
color: TheColors[0],
textColor: TheColors[1],
borderColor: CiviBorderColor,
allDay: ad,
url: "{/literal}{php} print base_path(); {/php}{literal}civicrm/activity?action=view&id="+e.id+"&cid="+e.cid
});
}
callback(events);
}
});
}
});
}); //end ready function
});
}); //end ready function

function CiviColor(ActivityType){
color = new Array();
switch(ActivityType) {
case 1: // Meeting
BGcolor = "green";
TextColor = "#FFF";
Type = "Not Default";
break;
case 19: // Bulk Email
case 37: // Cancel Recurring Contribution
case 35: // Change Membership Status
case 36: // Change Membership Type
case 48: // Change Registration
case 51: // Contact Merged
case 6: // Contribution
case 42: // Create Batch
case 49: // Downloaded Invoice
case 43: // Edit Batch
case 3: // Email
case 50: // Emailed Invoice
case 5: // Event Registration
case 41: // Export Accounting Batch
case 52: // Failed Payment
case 12: // Inbound Email
case 45: // Inbound SMS
case 34: // Mass SMS
case 8: // Membership Renewal
case 17: // Membership Renewal Reminder
case 7: // Membership Signup
case 4: // Outbound SMS
case 46: // Payment
case 2: // Phone Call
case 10: // Pledge Acknowledgment
case 11: // Pledge Reminder
case 22: // Print PDF Letter
case 47: // Refund
case 40: // Reminder Sent
case 44: // SMS delivery
case 9: // Tell a Friend
case 39: // Update Recurring Contribution
case 38: // Update Recurring Contribution Billing Details
BGcolor = "#36c";
TextColor = "#FFF";
Type = "Not Default";
break;
default: // Other Activity Types
BGcolor = "#36c";
TextColor = "#FFF";
Type = "Default";
}

color.push(BGcolor);
color.push(TextColor);
color.push(Type);

return color;
}
})(jQuery);
</script>
{/literal}