/** * 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; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if (!($this->_action & CRM_Core_Action::UPDATE)) { CRM_Core_Session::setStatus(ts('Preferences Date Options can only be updated')); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); // action is taken depending upon the mode $dao = new CRM_Core_DAO_PreferencesDate(); $dao->id = $this->_id; $dao->description = $params['description']; $dao->start = $params['start']; $dao->end = $params['end']; $dao->date_format = $params['date_format']; $dao->time_format = $params['time_format']; $dao->save(); CRM_Core_Session::setStatus(ts('The date type \'%1\' has been saved.', array(1 => $params['name']))); }
/** * class constructor */ function __construct() { parent::__construct(); }
/** * 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; }
/** * Process the form submission. * * * @return void */ public function postProcess() { if (!($this->_action & CRM_Core_Action::UPDATE)) { CRM_Core_Session::setStatus(ts('Preferences Date Options can only be updated'), ts('Sorry'), 'error'); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); // action is taken depending upon the mode $dao = new CRM_Core_DAO_PreferencesDate(); $dao->id = $this->_id; $dao->description = $params['description']; $dao->start = $params['start']; $dao->end = $params['end']; $dao->date_format = $params['date_format']; $dao->time_format = $params['time_format']; $dao->save(); // Update dynamic js to reflect new date settings CRM_Core_Resources::singleton()->resetCacheCode(); CRM_Core_Session::setStatus(ts("The date type '%1' has been saved.", array(1 => $params['name'])), ts('Saved'), 'success'); }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['preferences_date'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * 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; }