Example #1
0
 /**
  * Converts a past time into an age sentence
  */
 public static function toAge($time = 0)
 {
     $time = Sanitize::toTime($time);
     $elapsed = time() - $time;
     $tokens = self::_getTokens();
     if ($elapsed > 0) {
         foreach ($tokens as $unit => $word) {
             if ($elapsed < $unit) {
                 continue;
             }
             $amount = floor($elapsed / $unit);
             return Numeric::toNoun($amount, $word, $word . 's') . ' old';
         }
     }
     return '0 years old';
 }
Example #2
0
 public function acceptExposedInput($input)
 {
     if (empty($this->options['exposed'])) {
         return TRUE;
     }
     // Store this because it will get overwritten.
     $type = $this->value['type'];
     $rc = parent::acceptExposedInput($input);
     // Don't filter if value(s) are empty.
     $operators = $this->operators();
     if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id'])) {
         $operator = $input[$this->options['expose']['operator_id']];
     } else {
         $operator = $this->operator;
     }
     if ($operators[$operator]['values'] == 1) {
         if ($this->value['value'] == '') {
             return FALSE;
         }
     } else {
         if ($this->value['min'] == '' || $this->value['max'] == '') {
             return FALSE;
         }
     }
     // restore what got overwritten by the parent.
     $this->value['type'] = $type;
     return $rc;
 }
Example #3
0
 /**
  * Returns a list of months, days and years, for use as a date-of-birth selector
  */
 public static function getDobList($min = 10, $max = 80)
 {
     $time = time();
     $year = date("Y", $time);
     $start = intval($year) - intval($min);
     $max = intval($max);
     $output = array("months" => array("01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "Decenber"), "days" => array(), "years" => array());
     for ($i = 1; $i <= 31; $i++) {
         $d = Numeric::padZeros($i);
         $output["days"][$d] = $d;
     }
     for ($i = $start; $i >= $year - $max; $i--) {
         $age = $year - $i;
         $output["years"][$i] = $i . " (" . $age . ")";
     }
     return $output;
 }
 public function adminLabel($short = FALSE)
 {
     return $this->getField(parent::adminLabel($short));
 }
Example #5
0
 public function testFrontendFormat()
 {
     $this->assertEquals('value', $this->model->frontendFormat('value'));
 }
 /**
  * @dataProvider validationProvider
  */
 public function testValidation($value, $options, $result)
 {
     $validator = new Numeric($options);
     $this->assertEquals($result, $validator->validate($value));
 }