/**
  * Convert a DateTime object or number a number of seconds into the most fitted unit
  * 3 ways to used it:
  *    user.date|relativeDatetime(other.date) => render the difference between the 2 dates given
  *    user.date|relativeDatetime => render the difference between now and the first date given
  *    86400|relativeDatetime => render the most fitted unit
  * @param $first The first datetime or number of seconds
  * @param $second The second datetime (most recent) optional
  * @return the string representation
  */
 public function relativeDatetimeStringFilter($first, $second = null)
 {
     if ($first instanceof \DateTime) {
         if ($second != null) {
             //first case
             $result = Inflexible::relativeDatetime($first, $second);
         } else {
             //second case
             $result = Inflexible::relativeDatetime($first, new \DateTime());
         }
     } else {
         //numeric : third case
         $result = Inflexible::relativeDatetime($first);
     }
     //Convert the array into a readable string
     $string = "";
     if (count($result) >= 1) {
         if ($result[0] > 1) {
             $unit = Inflexible::pluralize($result[1]);
         } else {
             $unit = $result[1];
         }
         $string = $result[0] . " " . $unit;
     }
     return $string;
 }
 /**
  * Convert a DateTime object or number a number of seconds into the most fitted unit
  * 3 ways to used it:
  *    user.date|relativeDatetime(other.date) => render the difference between the 2 dates given
  *    user.date|relativeDatetime => render the difference between now and the first date given
  *    86400|relativeDatetime => render the most fitted unit
  * @param $first The first datetime or number of seconds
  * @param $second The second datetime (most recent) optional
  * @return Array(first element is the value, the second is the unit)
  */
 public function relativeDatetimeFilter($first, $second = null)
 {
     if ($first instanceof \DateTime) {
         if ($second != null) {
             //first case
             $result = Inflexible::relativeDatetime($first, $second);
         } else {
             //second case
             $result = Inflexible::relativeDatetime($first, new \DateTime());
         }
     } else {
         //numeric : third case
         $result = Inflexible::relativeDatetime($first);
     }
     return $result;
 }
 /**
  * Formats a string
  * @param string $value
  * @param int $maxLength The max length of the shortened string, default to 80
  * @param string $affix The string to separate chunks
  * @param string $affixPosition The position of the affix, maybe 'start', 'middle', 'end' or a custom
  * @return string representation
  */
 public function ShortenStringFilter($value, $maxLength = null, $affix = null, $affixPosition = null)
 {
     return Inflexible::shortenString($value, $maxLength, $affix, $affixPosition);
 }
 /**
  * Returns the textual representation of a number
  * @param $value the number
  * @return string representation
  */
 public function TextualizeFilter($value)
 {
     return Inflexible::textualize($value);
 }
 /**
  * Convert number to its ordinal English form
  * @param $value the number
  * @return string representation
  */
 public function OrdinalizeFilter($value)
 {
     return Inflexible::ordinalize($value);
 }
 /**
  * Converts CamelCased word and underscore to space to return a readable string
  * @param $value the namespace
  * @return string the readable string
  */
 public function HumanizeFilter($value)
 {
     return Inflexible::humanize($value);
 }
 /**
  * Returns the CamelCase representation of a string
  * @param $value the string
  * @return string camelized
  */
 public function CamelizeFilter($value)
 {
     return Inflexible::camelize($value);
 }
 /**
  * Returns the namespace of a fully qualified class name
  * @param $value the fully qualified class name
  * @return string the namespace
  */
 public function NamespaceOnlyFilter($value)
 {
     return Inflexible::namespaceOnly($value);
 }
Ejemplo n.º 9
0
 /**
  * Slugify a string
  * @param $value the string
  * @param array the options (max length, lowercase,separator)
  * @return string the slugified string
  */
 public function SlugifyFilter($value, $options = array())
 {
     return Inflexible::slugify($value, $options);
 }
 /**
  * Formats a number or a string using the SI units (k, M, G, etc.)
  * @param $value the number
  * @return array representation
  */
 public function ShortenNumberFilter($value)
 {
     return Inflexible::shortenNumber($value);
 }
 /**
  * Convert bytes to an human readable representation
  * @param $value the bytes
  * @param $precision (2 by default)
  * @return string representation
  */
 public function HumanByteFilter($value, $precision = null)
 {
     return Inflexible::humanByte($value, $precision);
 }