You are here

function calendar_systems_get_calendar_instance in Calendar Systems 7.3

Same name and namespace in other branches
  1. 8 calendar_systems.helpers.inc \calendar_systems_get_calendar_instance()
  2. 5 calendar_systems.module \calendar_systems_get_calendar_instance()
  3. 6.3 calendar_systems.module \calendar_systems_get_calendar_instance()
  4. 6 calendar_systems.module \calendar_systems_get_calendar_instance()
  5. 7 calendar_systems.helpers.inc \calendar_systems_get_calendar_instance()
  6. 7.2 calendar_systems.helpers.inc \calendar_systems_get_calendar_instance()

Gets an instance of the calendar object for the selected calendar system acording to the settings or the passed arguments

Return value

Calendar object or default on fail.

3 calls to calendar_systems_get_calendar_instance()
calendar_systems_date_validate in ./calendar_systems.module
Element validation callback for date fields.
calendar_systems_format_date in ./calendar_systems.module
Implementation of hook format_date
SimpletestUnitTestExampleTestCase::testCalendarSystemsConversion in ./simpletest_calendar_systems.test

File

./calendar_systems.module, line 372
Contains Calendar Systems hook implementations and helpers.

Code

function calendar_systems_get_calendar_instance($calendar_system = NULL, $language = NULL) {

  // Load module dependencies:
  _calendar_systems_load_dependencies();

  // Load all available profiles:
  $profiles = _calendar_systems_profiles();

  // Get site's current language:
  if (is_null($language)) {
    $language = _calendar_systems_languages_active();
  }
  if (is_null($calendar_system)) {
    if (isset($profiles[$language])) {
      $calendar_system = $profiles[$language]->calendar_system;
    }
    elseif (isset($profiles['default'])) {
      $calendar_system = $profiles['default']->calendar_system;
    }
  }
  if (empty($calendar_system)) {
    $calendar_system = 'default';
  }
  if ($calendar_system == 'iranian') {
    $calendar = cmfcCalendar::factory('v1', array(
      'name' => 'iranian',
    ));
  }
  elseif ($calendar_system == 'arabic') {
    $calendar = cmfcCalendar::factory('v1', array(
      'name' => 'arabic',
    ));
  }
  elseif ($calendar_system == 'default') {
    $calendar = cmfcCalendar::factory('v1', array(
      'name' => 'gregorian',
    ));
  }
  return $calendar;
}