Beispiel #1
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();
 }
 /**
  * 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();
 }
 /**
  * create a Volunteer Need
  * takes an associative array and creates a Need object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array   $params      (reference ) an assoc array of name/value pairs
  *
  * @return CRM_Volunteer_BAO_Need object
  * @access public
  * @static
  */
 static function &create($params)
 {
     $need = new CRM_Volunteer_BAO_Need();
     $need->copyValues($params);
     $projectId = $need->getProjectId();
     if ($projectId === FALSE) {
         CRM_Core_Error::fatal('Missing required Need ID or Project ID');
     }
     // creating a Need constitutes updating a Project
     $op = CRM_Core_Action::UPDATE;
     if (!empty($params['check_permissions']) && !CRM_Volunteer_Permission::checkProjectPerms($op, $projectId)) {
         CRM_Utils_System::permissionDenied();
         // FIXME: If we don't return here, the script keeps executing. This is not
         // what I expect from CRM_Utils_System::permissionDenied().
         return FALSE;
     }
     if (empty($params)) {
         return;
     }
     $need->save();
     return $need;
 }
 protected function saveProject($params)
 {
     $this->minimumProjectParams($params);
     $this->_project = CRM_Volunteer_BAO_Project::create($params);
     // if we created a project:
     if (!key_exists('id', $params)) {
         $form = $this->getSubmitValues();
         if (CRM_Utils_Array::value('is_active', $form, 0) === '1') {
             // create the flexible need
             $need = array('project_id' => $this->_project->id, 'is_flexible' => '1', 'visibility_id' => CRM_Core_OptionGroup::getValue('visibility', 'public', 'name'));
             CRM_Volunteer_BAO_Need::create($need);
         }
     }
     return $this->_project;
 }
/**
 * 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);
}
/**
 * Returns array of needs  matching a set of one or more group properties
 *
 * @param array $params  Array of one or more valid
 *                       property_name=>value pairs. If $params is set
 *                       as null, all needs will be returned
 *
 * @return array  (referance) Array of matching needs
 * {@getfields need_get}
 * @access public
 */
function civicrm_api3_volunteer_need_get($params)
{
    $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    if (!empty($result['values'])) {
        foreach ($result['values'] as &$need) {
            if (!empty($need['start_time'])) {
                $need['display_time'] = CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need));
            } else {
                $need['display_time'] = ts('Flexible', array('domain' => 'org.civicrm.volunteer'));
            }
            if (isset($need['role_id'])) {
                $need['role_label'] = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_Upgrader::customOptionGroupName, $need['role_id']);
            } elseif (CRM_Utils_Array::value('is_flexible', $need)) {
                $need['role_label'] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel();
            }
        }
    }
    return $result;
}
 /**
  * Function to process the form. Enables/disables Volunteer Project. If the
  * Project does not already exist, it is created, along with a "flexible" Need.
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $form = $this->exportValues();
     $form['is_active'] = CRM_Utils_Array::value('is_active', $form, 0);
     $params = array('entity_id' => $this->_id, 'entity_table' => CRM_Event_DAO_Event::$_tableName);
     // see if this project already exists
     $projects = CRM_Volunteer_BAO_Project::retrieve($params);
     if (count($projects)) {
         // force an update rather than an insert
         $params['id'] = current($projects)->id;
     }
     // save the project record
     $params += array('is_active' => $form['is_active'], 'target_contact_id' => $form['target_contact_id']);
     $project = CRM_Volunteer_BAO_Project::create($params);
     // if the project doesn't already exist and the user enabled vol management,
     // create the flexible need
     if (count($projects) !== 1 && $form['is_active'] === '1') {
         $need = array('project_id' => $project->id, 'is_flexible' => '1', 'visibility_id' => CRM_Core_OptionGroup::getValue('visibility', 'public', 'name'));
         CRM_Volunteer_BAO_Need::create($need);
     }
     parent::endPostProcess();
 }
 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;
         }
     }
 }
 /**
  * Sets and returns $this->open_needs. Delegate of __get().
  *
  * @return array Keyed by Need ID, with a subarray keyed by 'label' and 'role_id'
  */
 private function _get_open_needs()
 {
     if (empty($this->open_needs)) {
         if (empty($this->needs)) {
             $this->_get_needs();
         }
         foreach ($this->needs as $id => $need) {
             if (!empty($need['start_time']) && $need['quantity'] > $need['quantity_assigned'] && strtotime($need['start_time']) > time()) {
                 $this->open_needs[$id] = array('label' => CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need)), 'role_id' => $need['role_id']);
             }
         }
     }
     return $this->open_needs;
 }
/**
 * Returns array of needs  matching a set of one or more group properties
 *
 * @param array $params  Array of one or more valid
 *                       property_name=>value pairs. If $params is set
 *                       as null, all needs will be returned
 *
 * @return array  (referance) Array of matching needs
 * {@getfields need_get}
 * @access public
 */
function civicrm_api3_volunteer_need_get($params)
{
    $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    if (!empty($result['values'])) {
        foreach ($result['values'] as &$need) {
            if (!empty($need['start_time'])) {
                $need['display_time'] = CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need), CRM_Utils_Array::value('end_time', $need));
            } else {
                $need['display_time'] = CRM_Volunteer_BAO_Need::getFlexibleDisplayTime();
            }
            if (isset($need['role_id'])) {
                $role = CRM_Core_OptionGroup::getRowValues(CRM_Volunteer_BAO_Assignment::ROLE_OPTION_GROUP, $need['role_id'], 'value');
                $need['role_label'] = $role['label'];
                $need['role_description'] = $role['description'];
            } elseif (CRM_Utils_Array::value('is_flexible', $need)) {
                $need['role_label'] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel();
                $need['role_description'] = NULL;
            }
        }
    }
    return $result;
}
 /**
  * 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;
 }
 /**
  * Sets $this->roles and returns the Roles associated with this Project. Delegate of __get().
  * Note: only roles for active, visible needs are returned.
  *
  * @return array Roles, labels keyed by IDs
  */
 private function _get_roles()
 {
     if (empty($this->roles)) {
         $roles = array();
         if (empty($this->needs)) {
             $this->_get_needs();
         }
         foreach ($this->needs as $need) {
             if (CRM_Utils_Array::value('is_flexible', $need) == '1') {
                 $roles[CRM_Volunteer_BAO_Need::FLEXIBLE_ROLE_ID] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel();
             } else {
                 $role_id = CRM_Utils_Array::value('role_id', $need);
                 $roles[$role_id] = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_BAO_Assignment::ROLE_OPTION_GROUP, $role_id);
             }
         }
         asort($roles);
         $this->roles = $roles;
     }
     return $this->roles;
 }