Source for file date.php

Documentation is available at date.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  model
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. /**
  12.  * FrameworkOnFramework model behavior class
  13.  *
  14.  * @package  FrameworkOnFramework
  15.  * @since    2.1
  16.  */
  17. {
  18.     /**
  19.      * Returns the default search method for this field.
  20.      *
  21.      * @return  string 
  22.      */
  23.     public function getDefaultSearchMethod()
  24.     {
  25.         return 'exact';
  26.     }
  27.  
  28.     /**
  29.      * Perform a between limits match. When $include is true
  30.      * the condition tested is:
  31.      * $from <= VALUE <= $to
  32.      * When $include is false the condition tested is:
  33.      * $from < VALUE < $to
  34.      *
  35.      * @param   mixed    $from     The lowest value to compare to
  36.      * @param   mixed    $to       The higherst value to compare to
  37.      * @param   boolean  $include  Should we include the boundaries in the search?
  38.      *
  39.      * @return  string  The SQL where clause for this search
  40.      */
  41.     public function between($from$to$include true)
  42.     {
  43.         if ($this->isEmpty($from|| $this->isEmpty($to))
  44.         {
  45.             return '';
  46.         }
  47.  
  48.         $extra '';
  49.  
  50.         if ($include)
  51.         {
  52.             $extra '=';
  53.         }
  54.  
  55.         $sql '((' $this->getFieldName(' >' $extra ' ' $from ') AND ';
  56.         $sql .= '(' $this->getFieldName(' <' $extra ' ' $to '))';
  57.  
  58.         return $sql;
  59.     }
  60.  
  61.     /**
  62.      * Perform an outside limits match. When $include is true
  63.      * the condition tested is:
  64.      * (VALUE <= $from) || (VALUE >= $to)
  65.      * When $include is false the condition tested is:
  66.      * (VALUE < $from) || (VALUE > $to)
  67.      *
  68.      * @param   mixed    $from     The lowest value of the excluded range
  69.      * @param   mixed    $to       The higherst value of the excluded range
  70.      * @param   boolean  $include  Should we include the boundaries in the search?
  71.      *
  72.      * @return  string  The SQL where clause for this search
  73.      */
  74.     public function outside($from$to$include false)
  75.     {
  76.         if ($this->isEmpty($from|| $this->isEmpty($to))
  77.         {
  78.             return '';
  79.         }
  80.  
  81.         $extra '';
  82.  
  83.         if ($include)
  84.         {
  85.             $extra '=';
  86.         }
  87.  
  88.         $sql '((' $this->getFieldName(' <' $extra ' ' $from ') AND ';
  89.         $sql .= '(' $this->getFieldName(' >' $extra ' ' $to '))';
  90.  
  91.         return $sql;
  92.     }
  93.  
  94.     /**
  95.      * Interval date search
  96.      *
  97.      * @param   string               $value     The value to search
  98.      * @param   string|array|object   $interval  The interval. Can be (+1 MONTH or array('value' => 1, 'unit' => 'MONTH', 'sign' => '+'))
  99.      * @param   boolean              $include   If the borders should be included
  100.      *
  101.      * @return  string  the sql string
  102.      */
  103.     public function interval($value$interval$include true)
  104.     {
  105.         if ($this->isEmpty($value|| $this->isEmpty($interval))
  106.         {
  107.             return '';
  108.         }
  109.  
  110.         $interval $this->getInterval($interval);
  111.  
  112.         if ($interval['sign'== '+')
  113.         {
  114.             $function 'DATE_ADD';
  115.         }
  116.         else
  117.         {
  118.             $function 'DATE_SUB';
  119.         }
  120.  
  121.         $extra '';
  122.  
  123.         if ($include)
  124.         {
  125.             $extra '=';
  126.         }
  127.  
  128.         $sql '(' $this->getFieldName(' >' $extra ' ' $function;
  129.         $sql .= '(' $this->getFieldName(', INTERVAL ' $interval['value'' ' $interval['unit''))';
  130.  
  131.         return $sql;
  132.     }
  133.  
  134.     /**
  135.      * Parses an interval â€“which may be given as a string, array or object– into
  136.      * a standardised hash array that can then be used bu the interval() method.
  137.      *
  138.      * @param   string|array|object   $interval  The interval expression to parse
  139.      *
  140.      * @return  array  The parsed, hash array form of the interval
  141.      */
  142.     protected function getInterval($interval)
  143.     {
  144.         if (is_string($interval))
  145.         {
  146.             if (strlen($interval2)
  147.             {
  148.                 $interval explode(" "$interval);
  149.                 $sign ($interval[0== '-''-' '+';
  150.                 $value = (int) substr($interval[0]1);
  151.  
  152.                 $interval array(
  153.                     'unit' => $interval[1],
  154.                     'value' => $value,
  155.                     'sign' => $sign
  156.                 );
  157.             }
  158.             else
  159.             {
  160.                 $interval array(
  161.                     'unit' => 'MONTH',
  162.                     'value' => 1,
  163.                     'sign' => '+'
  164.                 );
  165.             }
  166.         }
  167.         else
  168.         {
  169.             $interval = (array) $interval;
  170.         }
  171.  
  172.         return $interval;
  173.     }
  174. }

Documentation generated on Tue, 19 Nov 2013 14:57:56 +0100 by phpDocumentor 1.4.3