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