/** * 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; }
/** * 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; }
/** * 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; }