/** * Fetch object based on array of properties. * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $defaults * (reference ) an assoc array to hold the flattened values. * * @return CRM_Core_BAO_PreferencesDate|null * object on success, null otherwise */ public static function retrieve(&$params, &$defaults) { $dao = new CRM_Core_DAO_PreferencesDate(); $dao->copyValues($params); if ($dao->find(TRUE)) { CRM_Core_DAO::storeValues($dao, $defaults); return $dao; } return NULL; }
/** * compose the parameters for a date select object * * @param $type the type of date * @param $format date format ( QF format) * * @return array the date array * @static */ static function &date($type = null, $format = null, $minOffset = null, $maxOffset = null) { $date = array('addEmptyOption' => true, 'emptyOptionText' => ts('- select -'), 'emptyOptionValue' => ''); if ($format) { $date['format'] = $format; } else { if ($type) { require_once 'CRM/Core/DAO/PreferencesDate.php'; $dao = new CRM_Core_DAO_PreferencesDate(); $dao->name = $type; if (!$dao->find(true)) { CRM_Core_Error::fatal(); } } if ($type == 'creditCard') { $minOffset = $dao->start; $maxOffset = $dao->end; $date['format'] = $dao->date_format; $date['addEmptyOption'] = true; $date['emptyOptionText'] = ts('- select -'); $date['emptyOptionValue'] = ''; } if (!CRM_Utils_Array::value('format', $date)) { $date['format'] = 'M d'; } } $year = date('Y'); $date['minYear'] = $year - $minOffset; $date['maxYear'] = $year + $maxOffset; return $date; }
/** * Compose the parameters for a date select object. * * @param string|NULL $type * the type of date * @param string|NULL $format * date format (QF format) * @param null $minOffset * @param null $maxOffset * * @return array * the date array */ public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) { $date = array('addEmptyOption' => TRUE, 'emptyOptionText' => ts('- select -'), 'emptyOptionValue' => ''); if ($format) { $date['format'] = $format; } else { if ($type) { $dao = new CRM_Core_DAO_PreferencesDate(); $dao->name = $type; if (!$dao->find(TRUE)) { CRM_Core_Error::fatal(); } } if ($type == 'creditCard') { $minOffset = $dao->start; $maxOffset = $dao->end; $date['format'] = $dao->date_format; $date['addEmptyOption'] = TRUE; $date['emptyOptionText'] = ts('- select -'); $date['emptyOptionValue'] = ''; } if (empty($date['format'])) { $date['format'] = 'M d'; } } $year = date('Y'); $date['minYear'] = $year - $minOffset; $date['maxYear'] = $year + $maxOffset; return $date; }
/** * compose the parameters for a date select object * * @param $type the type of date * * @return array the date array * @static */ static function &date($type = 'birth', $min = null, $max = null, $dateParts = null) { static $_date = null; static $config = null; if (!$config) { $config =& CRM_Core_Config::singleton(); } if (!$_date) { require_once 'CRM/Utils/Date.php'; $_date = array('format' => 'M d Y', 'addEmptyOption' => true, 'emptyOptionText' => ts('- select -'), 'emptyOptionValue' => ''); } $newDate = $_date; require_once 'CRM/Core/DAO/PreferencesDate.php'; $dao = new CRM_Core_DAO_PreferencesDate(); $dao->name = $type; if (!$dao->find(true)) { CRM_Core_Error::fatal(); } if ($type == 'birth') { $minOffset = $dao->start; $maxOffset = $dao->end; // support for birthdate format, CRM-3090 $format = trim($dao->format); $birthDateFormat = CRM_Utils_Date::checkBirthDateFormat($format); if ($birthDateFormat) { $formatParts = $birthDateFormat['dateParts']; if (in_array('M', $formatParts)) { $formatParts[array_search('M', $formatParts)] = $config->dateformatMonthVar; } $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDate, $formatParts); } else { $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDate); } } elseif ($type == 'relative') { $minOffset = $dao->start; $maxOffset = $dao->end; } elseif ($type == 'custom') { $minOffset = $min; $maxOffset = $max; if ($dateParts) { require_once 'CRM/Core/BAO/CustomOption.php'; $filter = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dateParts); $format = $config->dateformatQfDate; foreach ($filter as $val) { switch ($val) { case 'M': $filter[] = 'F'; $filter[] = 'm'; break; case 'd': $filter[] = 'j'; break; case 'h': $filter[] = 'H'; $filter[] = 'G'; $filter[] = 'g'; case 'i': $format = $config->dateformatQfDatetime; break; } } $newDate['format'] = CRM_Utils_Date::posixToPhp($format, $filter); } } elseif ($type == 'activityDate') { $minOffset = $dao->start; $maxOffset = $dao->end; } elseif ($type == 'fixed') { $minOffset = $dao->start; $maxOffset = $dao->end; } elseif ($type == 'manual') { $minOffset = $min; $maxOffset = $max; } elseif ($type == 'creditCard') { $minOffset = $dao->start; $maxOffset = $dao->end; $newDate['format'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PreferencesDate', 'creditCard', 'date_format', 'name'); } elseif ($type == 'mailing') { $minOffset = $dao->start; $maxOffset = $dao->end; $format = explode(' ', trim($dao->format)); $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDatetime, $format); $newDate['optionIncrement']['i'] = $dao->minute_increment; } elseif ($type == 'activityDatetime') { require_once 'CRM/Utils/Date.php'; //for datetime use datetime format from config $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDatetime); $newDate['optionIncrement']['i'] = $dao->minute_increment; $minOffset = $dao->start; $maxOffset = $dao->end; } elseif ($type == 'datetime') { require_once 'CRM/Utils/Date.php'; //for datetime use datetime format from config $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDatetime); $newDate['optionIncrement']['i'] = $dao->minute_increment; $minOffset = $dao->start; $maxOffset = $dao->end; } elseif ($type == 'duration') { $format = explode(' ', trim($dao->format)); $newDate['format'] = CRM_Utils_Date::posixToPhp($config->dateformatQfDate, $format); $newDate['optionIncrement']['i'] = $dao->minute_increment; } $year = date('Y'); $newDate['minYear'] = $year - $minOffset; $newDate['maxYear'] = $year + $maxOffset; return $newDate; }