Exemplo n.º 1
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_PreferencesDate');
     $this->applyFilter('__ALL__', 'trim');
     $name =& $this->add('text', 'name', ts('Name'), $attributes['name'], true);
     $name->freeze();
     $this->add('text', 'description', ts('Description'), $attributes['description'], false);
     $this->add('text', 'start', ts('Start Offset'), $attributes['start'], true);
     $this->add('text', 'end', ts('End Offset'), $attributes['end'], true);
     $formatType = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', $this->_id, 'name');
     if ($formatType == 'creditCard') {
         $this->add('text', 'date_format', ts('Format'), $attributes['date_format'], true);
     } else {
         $this->add('select', 'date_format', ts('Format'), array('' => ts('- default input format -')) + CRM_Core_SelectValues::getDatePluginInputFormats());
         $this->add('select', 'time_format', ts('Time'), array('' => ts('- none -')) + CRM_Core_SelectValues::getTimeFormats());
     }
     $this->addRule('start', ts('Value should be a positive number'), 'positiveInteger');
     $this->addRule('end', ts('Value should be a positive number'), 'positiveInteger');
     // add a form rule
     $this->addFormRule(array('CRM_Admin_Form_PreferencesDate', 'formRule'));
 }
Exemplo n.º 2
0
 /**
  * Function get date format
  * @param  string $formatType Date name e.g. birth
  *
  * @return string $format 
  */
 static function getDateFormat($formatType = null)
 {
     $format = null;
     if ($formatType) {
         $format = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', $formatType, 'date_format', 'name');
     }
     if (!$format) {
         $config = CRM_Core_Config::singleton();
         $format = $config->dateInputFormat;
     }
     return $format;
 }
Exemplo n.º 3
0
 /**
  * Function is used to format the individual contact values
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  * @param array  $contact  contact object
  *
  * @return object CRM_Contact_BAO_Contact object
  * @access public
  * @static
  */
 static function format(&$params, &$contact)
 {
     if (!self::dataExists($params)) {
         return;
     }
     $sortName = "";
     $firstName = CRM_Utils_Array::value('first_name', $params, '');
     $middleName = CRM_Utils_Array::value('middle_name', $params, '');
     $lastName = CRM_Utils_Array::value('last_name', $params, '');
     $prefix_id = CRM_Utils_Array::value('prefix_id', $params, '');
     $suffix_id = CRM_Utils_Array::value('suffix_id', $params, '');
     // get prefix and suffix names
     $prefixes = CRM_Core_PseudoConstant::individualPrefix();
     $suffixes = CRM_Core_PseudoConstant::individualSuffix();
     $prefix = $suffix = null;
     if ($prefix_id) {
         $prefix = $prefixes[$prefix_id];
     }
     if ($suffix_id) {
         $suffix = $suffixes[$suffix_id];
     }
     $params['is_deceased'] = CRM_Utils_Array::value('is_deceased', $params, false);
     if ($contact->id) {
         $individual =& new CRM_Contact_BAO_Contact();
         $individual->id = $contact->id;
         if ($individual->find(true)) {
             //lets allow to update single name field though preserveDBName
             //but if db having null value and params contain value, CRM-4330.
             $useDBNames = array();
             foreach (array('last', 'middle', 'first') as $name) {
                 $dbName = "{$name}_name";
                 $value = $individual->{$dbName};
                 // the db has name values
                 if ($value && CRM_Utils_Array::value('preserveDBName', $params)) {
                     $useDBNames[] = $name;
                 }
             }
             foreach (array('prefix', 'suffix') as $name) {
                 $dbName = "{$name}_id";
                 $value = $individual->{$dbName};
                 if ($value && CRM_Utils_Array::value('preserveDBName', $params)) {
                     $useDBNames[] = $name;
                 }
             }
             // CRM-4430
             //1. preserve db name if want
             //2. lets get value from param if exists.
             //3. if not in params, lets get from db.
             foreach (array('last', 'middle', 'first') as $name) {
                 $phpName = "{$name}Name";
                 $dbName = "{$name}_name";
                 $value = $individual->{$dbName};
                 if (in_array($name, $useDBNames)) {
                     $params[$dbName] = $value;
                     $contact->{$dbName} = $value;
                     ${$phpName} = $value;
                 } else {
                     if (array_key_exists($dbName, $params)) {
                         ${$phpName} = $params[$dbName];
                     } else {
                         if ($value) {
                             ${$phpName} = $value;
                         }
                     }
                 }
             }
             foreach (array('prefix', 'suffix') as $name) {
                 $phpName = $name;
                 $dbName = "{$name}_id";
                 $vals = "{$name}es";
                 $value = $individual->{$dbName};
                 if (in_array($name, $useDBNames)) {
                     $params[$dbName] = $value;
                     $contact->{$dbName} = $value;
                     if ($value) {
                         $temp = ${$vals};
                         ${$phpName} = $temp[$value];
                     } else {
                         ${$phpName} = null;
                     }
                 } else {
                     if (array_key_exists($dbName, $params)) {
                         $temp = ${$vals};
                         // CRM-5278
                         if (!empty($params[$dbName])) {
                             ${$phpName} = CRM_Utils_Array::value($params[$dbName], $temp);
                         }
                     } else {
                         if ($value) {
                             $temp = ${$vals};
                             ${$phpName} = $temp[$value];
                         }
                     }
                 }
             }
         }
     }
     if ($lastName || $firstName || $middleName) {
         if ($lastName && $firstName) {
             $contact->sort_name = trim("{$lastName}, {$firstName}");
         } else {
             $contact->sort_name = trim("{$lastName} {$firstName}");
         }
         $display_name = trim("{$prefix} {$firstName} {$middleName} {$lastName} {$suffix}");
         $display_name = str_replace('  ', ' ', $display_name);
     }
     if (isset($display_name) && trim($display_name)) {
         $contact->display_name = trim($display_name);
     }
     if (CRM_Utils_Array::value('email', $params) && is_array($params['email'])) {
         foreach ($params['email'] as $emailBlock) {
             if (isset($emailBlock['is_primary'])) {
                 $email = $emailBlock['email'];
                 break;
             }
         }
     }
     $uniqId = CRM_Utils_Array::value('user_unique_id', $params);
     if (empty($contact->display_name)) {
         if (isset($email)) {
             $contact->display_name = $email;
         } else {
             if (isset($uniqId)) {
                 $contact->display_name = $uniqId;
             }
         }
     }
     if (empty($contact->sort_name)) {
         if (isset($email)) {
             $contact->sort_name = $email;
         } else {
             if (isset($uniqId)) {
                 $contact->sort_name = $uniqId;
             }
         }
     }
     $format = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', 'birth', 'date_format', 'name');
     if ($date = CRM_Utils_Array::value('birth_date', $params)) {
         if (in_array($format, array('dd/mm', 'mm/dd'))) {
             $date = "{$date}/1902";
         }
         $contact->birth_date = CRM_Utils_Date::processDate($date);
         //$contact->birth_date = preg_replace('/[^0-9]/', '', $date);
     } else {
         if ($contact->birth_date) {
             $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date);
         }
     }
     if ($date = CRM_Utils_Array::value('deceased_date', $params)) {
         if (in_array($format, array('dd/mm', 'mm/dd'))) {
             $date = "{$date}/1902";
         }
         $contact->deceased_date = CRM_Utils_Date::processDate($date);
     } else {
         if ($contact->deceased_date) {
             $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date);
         }
     }
     if ($middle_name = CRM_Utils_Array::value('middle_name', $params)) {
         $contact->middle_name = $middle_name;
     }
     return $contact;
 }
Exemplo n.º 4
0
 /**
  * check the validity of the birth date (in qf format)
  * note that only a year is valid, or a mon-year or day-month  is
  * also valid in addition to day-mon-year
  *
  * @param array $date
  *
  * @return bool true if valid date
  * @static
  * @access public
  */
 static function qfBirthDate($date)
 {
     //if birth format is not set then execute qfDate function
     if (!CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', 'birth', 'format', 'name')) {
         return self::qfDate($date);
     }
     $config =& CRM_Core_Config::singleton();
     $d = CRM_Utils_Array::value('d', $date);
     $m = CRM_Utils_Array::value($config->dateformatMonthVar, $date);
     $y = CRM_Utils_Array::value('Y', $date);
     if (!$d && !$m && !$y) {
         return true;
     }
     if (in_array('', $date)) {
         return false;
     }
     $day = $mon = 1;
     $year = 1000;
     if ($d) {
         $day = $d;
     }
     if ($m) {
         $mon = $m;
     }
     if ($y) {
         $year = $y;
     }
     if (!empty($day) || !empty($mon) || !empty($year)) {
         return checkdate($mon, $day, $year);
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  *  Function to convert mysql to date plugin format
  *
  *  @param string $mysqlDate date string
  *
  *  @return array $date and time 
  */
 static function setDateDefaults($mysqlDate = null, $formatType = null, $format = null, $timeFormat = null)
 {
     // if date is not passed assume it as today
     if (!$mysqlDate) {
         $mysqlDate = date('Y-m-d G:i:s');
     }
     $config =& CRM_Core_Config::singleton();
     if ($formatType) {
         $format = CRM_Core_Dao::getFieldValue('CRM_Core_DAO_PreferencesDate', $formatType, 'format', 'name');
     }
     if (!$format) {
         $format = $config->dateInputFormat;
     }
     // get actual format
     $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats();
     $dateFormat = $actualPHPFormats[$format];
     $date = date($dateFormat, strtotime($mysqlDate));
     if (!$timeFormat) {
         $timeFormat = $config->timeInputFormat;
     }
     $actualTimeFormat = "g:iA";
     $appendZeroLength = 7;
     if ($timeFormat > 1) {
         $actualTimeFormat = "G:i";
         $appendZeroLength = 5;
     }
     $time = date($actualTimeFormat, strtotime($mysqlDate));
     // need to append zero for hours < 10
     if (strlen($time) < $appendZeroLength) {
         $time = '0' . $time;
     }
     return array($date, $time);
 }