/**
  * Load needed JS, CSS and settings for the backend Volunteer Management UI
  */
 public static function addResources($entity_id, $entity_table)
 {
     static $loaded = FALSE;
     $ccr = CRM_Core_Resources::singleton();
     if ($loaded || $ccr->isAjaxMode()) {
         return;
     }
     $loaded = TRUE;
     $config = CRM_Core_Config::singleton();
     // Vendor libraries
     $ccr->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE);
     $ccr->addScriptFile('civicrm', 'packages/backbone/backbone-min.js', 120, 'html-header', FALSE);
     $ccr->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.min.js', 125, 'html-header', FALSE);
     // Our stylesheet
     $ccr->addStyleFile('org.civicrm.volunteer', 'css/volunteer_app.css');
     // Add all scripts for our js app
     $weight = 0;
     $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/';
     // This glob pattern will recurse the js directory up to 4 levels deep
     foreach (glob($baseDir . 'js/backbone/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) {
         $fileName = substr($file, strlen($baseDir));
         $ccr->addScriptFile('org.civicrm.volunteer', $fileName, $weight++);
     }
     // Add our template
     CRM_Core_Smarty::singleton()->assign('isModulePermissionSupported', CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported());
     CRM_Core_Region::instance('page-header')->add(array('template' => 'CRM/Volunteer/Form/Manage.tpl'));
     // Fetch event so we can set the default start time for needs
     // FIXME: Not the greatest for supporting non-events
     $entity = civicrm_api3(str_replace('civicrm_', '', $entity_table), 'getsingle', array('id' => $entity_id));
     // Static variables
     $ccr->addSetting(array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => CRM_Utils_Array::value('start_date', $entity)), 'config' => array('timeInputFormat' => $config->timeInputFormat), 'constants' => array('CRM_Core_Action' => array('NONE' => 0, 'ADD' => 1, 'UPDATE' => 2, 'VIEW' => 4, 'DELETE' => 8, 'BROWSE' => 16, 'ENABLE' => 32, 'DISABLE' => 64, 'EXPORT' => 128, 'BASIC' => 256, 'ADVANCED' => 512, 'PREVIEW' => 1024, 'FOLLOWUP' => 2048, 'MAP' => 4096, 'PROFILE' => 8192, 'COPY' => 16384, 'RENEW' => 32768, 'DETACH' => 65536, 'REVERT' => 131072, 'CLOSE' => 262144, 'REOPEN' => 524288, 'MAX_ACTION' => 1048575))));
     // Check for problems
     _volunteer_checkResourceUrl();
 }
Example #2
0
 /**
  * Load needed JS, CSS and settings for the backend Volunteer Management UI
  */
 public static function addResources($entity_id, $entity_table)
 {
     static $loaded = FALSE;
     if ($loaded) {
         return;
     }
     $loaded = TRUE;
     $config = CRM_Core_Config::singleton();
     $ccr = CRM_Core_Resources::singleton();
     // Vendor libraries
     $ccr->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE);
     $ccr->addScriptFile('civicrm', 'packages/backbone/backbone-min.js', 120, 'html-header');
     $ccr->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.min.js', 125, 'html-header', FALSE);
     // Our stylesheet
     $ccr->addStyleFile('org.civicrm.volunteer', 'css/volunteer_app.css');
     // Add all scripts for our js app
     $weight = 0;
     $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/';
     // This glob pattern will recurse the js directory up to 4 levels deep
     foreach (glob($baseDir . 'js/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) {
         $fileName = substr($file, strlen($baseDir));
         $ccr->addScriptFile('org.civicrm.volunteer', $fileName, $weight++);
     }
     // Add our template
     CRM_Core_Smarty::singleton()->assign('isModulePermissionSupported', CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported());
     CRM_Core_Region::instance('page-header')->add(array('template' => 'CRM/Volunteer/Form/Manage.tpl'));
     // Fetch event so we can set the default start time for needs
     // FIXME: Not the greatest for supporting non-events
     $entity = civicrm_api3(str_replace('civicrm_', '', $entity_table), 'getsingle', array('id' => $entity_id));
     // Static variables
     $ccr->addSetting(array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => CRM_Utils_Array::value('start_date', $entity)), 'config' => array('timeInputFormat' => $config->timeInputFormat)));
     // Check for problems
     _volunteer_civicrm_check_resource_url();
 }
/**
 * This function will return the needed pieces to load up the backbone/
 * marionette project backend from within an angular page.
 *
 * @param array $params
 *   Not presently used.
 * @return array
 *   Keyed with "css," "templates," "scripts," and "settings," this array
 *   contains the dependencies of the backbone-based volunteer app.
 *
 */
function civicrm_api3_volunteer_util_loadbackbone($params)
{
    $results = array("css" => array(), "templates" => array(), "scripts" => array(), "settings" => array());
    $ccr = CRM_Core_Resources::singleton();
    $config = CRM_Core_Config::singleton();
    $results['css'][] = $ccr->getUrl('org.civicrm.volunteer', 'css/volunteer_app.css');
    $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/';
    // This glob pattern will recurse the js directory up to 4 levels deep
    foreach (glob($baseDir . 'js/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) {
        $fileName = substr($file, strlen($baseDir));
        $results['scripts'][] = $ccr->getUrl('org.civicrm.volunteer', $fileName);
    }
    $results['templates'][] = 'civicrm/volunteer/backbonetemplates';
    $results['settings'] = array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => date("Y-m-d H:i:s", strtotime('tomorrow noon'))), 'config' => array('timeInputFormat' => $config->timeInputFormat), 'constants' => array('CRM_Core_Action' => array('NONE' => 0, 'ADD' => 1, 'UPDATE' => 2, 'VIEW' => 4, 'DELETE' => 8, 'BROWSE' => 16, 'ENABLE' => 32, 'DISABLE' => 64, 'EXPORT' => 128, 'BASIC' => 256, 'ADVANCED' => 512, 'PREVIEW' => 1024, 'FOLLOWUP' => 2048, 'MAP' => 4096, 'PROFILE' => 8192, 'COPY' => 16384, 'RENEW' => 32768, 'DETACH' => 65536, 'REVERT' => 131072, 'CLOSE' => 262144, 'REOPEN' => 524288, 'MAX_ACTION' => 1048575)));
    return civicrm_api3_create_success($results, "VolunteerUtil", "loadbackbone", $params);
}
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $volunteerRoles = CRM_Volunteer_BAO_Need::buildOptions('role_id', 'create');
     $viewLinks = FALSE;
     $seperator = CRM_CORE_DAO::VALUE_SEPARATOR;
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'report');
     if (CRM_Core_Permission::check('access CiviCRM')) {
         $viewLinks = TRUE;
         $onHover = ts('View Contact Summary for this Contact', array('domain' => 'org.civicrm.volunteer'));
         $onHoverAct = ts('View Activity Record', array('domain' => 'org.civicrm.volunteer'));
     }
     foreach ($rows as $rowNum => $row) {
         if (array_key_exists('civicrm_contact_contact_source', $row)) {
             if ($value = $row['civicrm_activity_assignment_contact_id']) {
                 if ($viewLinks) {
                     $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $value, $this->_absoluteUrl);
                     $rows[$rowNum]['civicrm_contact_contact_source_link'] = $url;
                     $rows[$rowNum]['civicrm_contact_contact_source_hover'] = $onHover;
                 }
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('civicrm_contact_contact_assignee', $row)) {
             $assigneeNames = explode($seperator, $row['civicrm_contact_contact_assignee']);
             if ($value = $row['civicrm_activity_assignment_contact_id']) {
                 $assigneeContactIds = explode($seperator, $value);
                 $link = array();
                 if ($viewLinks) {
                     foreach ($assigneeContactIds as $id => $value) {
                         $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $value, $this->_absoluteUrl);
                         $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$assigneeNames[$id]}</a>";
                     }
                     $rows[$rowNum]['civicrm_contact_contact_assignee'] = implode('; ', $link);
                 }
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('civicrm_contact_contact_target', $row)) {
             $targetNames = explode($seperator, $row['civicrm_contact_contact_target']);
             if ($value = $row['civicrm_activity_target_contact_id']) {
                 $targetContactIds = explode($seperator, $value);
                 $link = array();
                 if ($viewLinks) {
                     foreach ($targetContactIds as $id => $value) {
                         $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $value, $this->_absoluteUrl);
                         $link[] = "<a title='" . $onHover . "' href='" . $url . "'>{$targetNames[$id]}</a>";
                     }
                     $rows[$rowNum]['civicrm_contact_contact_target'] = implode('; ', $link);
                 }
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
             if ($value = $row['civicrm_activity_activity_type_id']) {
                 $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value];
                 if ($viewLinks) {
                     // Check for assignee contact id(s) (since they are the volunteer and use the first contact id in that list for view activity link if found,
                     // else use source contact id
                     if (!empty($rows[$rowNum]['civicrm_activity_assignment_contact_id'])) {
                         $targets = explode($seperator, $rows[$rowNum]['civicrm_activity_assignment_contact_id']);
                         $cid = $targets[0];
                     } else {
                         $cid = $rows[$rowNum]['civicrm_activity_source_contact_id'];
                     }
                     $actionLinks = CRM_Activity_Selector_Activity::actionLinks($row['civicrm_activity_activity_type_id'], CRM_Utils_Array::value('civicrm_activity_source_record_id', $rows[$rowNum]), FALSE, $rows[$rowNum]['civicrm_activity_id']);
                     $linkValues = array('id' => $rows[$rowNum]['civicrm_activity_id'], 'cid' => $cid, 'cxt' => $context);
                     $url = CRM_Utils_System::url($actionLinks[CRM_Core_Action::VIEW]['url'], CRM_Core_Action::replace($actionLinks[CRM_Core_Action::VIEW]['qs'], $linkValues), TRUE);
                     $rows[$rowNum]['civicrm_activity_activity_type_id_link'] = $url;
                     $rows[$rowNum]['civicrm_activity_activity_type_id_hover'] = $onHoverAct;
                 }
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('civicrm_activity_status_id', $row)) {
             if ($value = $row['civicrm_activity_status_id']) {
                 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('role_role', $row)) {
             if ($value = $row['role_role']) {
                 $rows[$rowNum]['role_role'] = $volunteerRoles[$value];
                 $entryFound = TRUE;
             }
         }
         if (array_key_exists('civicrm_activity_activity_date_time', $row)) {
             $rows[$rowNum]['civicrm_activity_activity_date_time'] = CRM_Utils_Date::customFormat($row['civicrm_activity_activity_date_time']);
             // Display overdue marker
             if (array_key_exists('civicrm_activity_status_id', $row) && CRM_Utils_Date::overdue($rows[$rowNum]['civicrm_activity_activity_date_time']) && $activityStatus[$row['civicrm_activity_status_id']] != 'Completed') {
                 $rows[$rowNum]['class'] = "status-overdue";
                 $entryFound = TRUE;
             }
         }
         $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this ') ? TRUE : $entryFound;
         if (!$entryFound) {
             break;
         }
     }
 }
 /**
  * Set default values for the form.
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     $i = 1;
     $volunteerRole = CRM_Volunteer_BAO_Need::buildOptions('role_id', 'create');
     $volunteerStatus = CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate');
     foreach ($this->_volunteerData as $data) {
         $defaults['field'][$i]['scheduled_duration'] = $data['time_scheduled_minutes'];
         $defaults['field'][$i]['actual_duration'] = $data['time_completed_minutes'];
         $defaults['field'][$i]['volunteer_role'] = CRM_Utils_Array::value($data['volunteer_role_id'], $volunteerRole);
         $defaults['field'][$i]['volunteer_status'] = $data['status_id'];
         $defaults['field'][$i]['activity_id'] = $data['id'];
         $defaults['field'][$i]['start_date'] = CRM_Utils_Date::customFormat($data['activity_date_time'], "%m/%E/%Y %l:%M %P");
         $defaults['field'][$i]["contact_id"] = $data['contact_id'];
         $i++;
     }
     $completed = CRM_Utils_Array::key('Completed', $volunteerStatus);
     for ($j = $i; $j < $this->_batchInfo['item_count']; $j++) {
         $defaults['field'][$j]['volunteer_status'] = $completed;
         $startDate = CRM_Utils_Date::customFormat($this->_start_date, "%m/%E/%Y  %l:%M %P");
         $date = explode('  ', $startDate);
         $defaults['field'][$j]['start_date'] = $date[0];
         $defaults['field'][$j]['start_date_time'] = $date[1];
     }
     return $defaults;
 }