Esempio n. 1
0
 /**
  * Displays the age in the position profileHeaderA
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function profileHeaderA($key, $user, $field)
 {
     $my = FD::user();
     $privacyLib = FD::privacy($my->id);
     if (!$privacyLib->validate('core.view', $field->id, SOCIAL_TYPE_FIELD, $user->id)) {
         return;
     }
     $params = $field->getParams();
     if ($params->get('show_age') && !$privacyLib->validate('field.birthday', $field->id, 'year', $user->id)) {
         return;
     }
     // Get the current stored value.
     $value = $field->data;
     if (empty($value)) {
         return false;
     }
     $data = new SocialFieldsUserDateTimeObject($value);
     $date = null;
     if (!empty($data->year) && !empty($data->month) && !empty($data->day)) {
         $date = $data->year . '-' . $data->month . '-' . $data->day;
     }
     if (!$date) {
         return;
     }
     $allowYear = true;
     $theme = FD::themes();
     if ($params->get('show_age')) {
         // Compute the age now.
         $age = $this->getAge($date);
         $theme->set('value', $age);
     } else {
         $allowYear = $privacyLib->validate('field.birthday', $field->id, 'year', $user->id);
         $format = $allowYear ? 'j F Y' : 'j F';
         $birthday = FD::date($date, false)->toFormat($format);
         $theme->set('value', $birthday);
     }
     // linkage to advanced search page.
     if ($allowYear && $field->searchable) {
         $date = $data->toFormat('Y-m-d');
         $params = array('layout' => 'advanced');
         $params['criterias[]'] = $field->unique_key . '|' . $field->element;
         $params['operators[]'] = 'between';
         $params['conditions[]'] = $date . ' 00:00:00' . '|' . $date . ' 23:59:59';
         $advsearchLink = FRoute::search($params);
         $theme->set('advancedsearchlink', $advsearchLink);
     }
     $theme->set('params', $params);
     echo $theme->output('fields/user/birthday/widgets/display');
 }
Esempio n. 2
0
 public function getDatetimeValue($data = null)
 {
     $dateObj = new SocialFieldsUserDateTimeObject();
     if (empty($data)) {
         return $dateObj;
     }
     $dateObj->init($data);
     return $dateObj;
 }