Example #1
0
 /**
  * Builds an array containing the filters value and condition
  *
  * @param   string $value     Initial value
  * @param   string $condition Initial $condition
  * @param   string $eval      How the value should be handled
  *
  * @return  array    (value condition)
  */
 public function getFilterValue($value, $condition, $eval)
 {
     /* if its a search all value it may not be a date - so use parent method.
      * see http://fabrikar.com/forums/showthread.php?t=25255
      */
     if (!is_array($value) && !FabrikWorker::isDate($value)) {
         if ($this->rangeFilterSet) {
             // It's already been set as a range expression - so split that into an array
             $condition = 'between';
             $value = explode(' AND ', $value);
             foreach ($value as &$v) {
                 $v = str_replace(array("'", '"'), '', $v);
             }
         }
         return parent::getFilterValue($value, $condition, FABRIKFILTER_QUERY);
     }
     $params = $this->getParams();
     $storeAsLocal = (int) $params->get('date_store_as_local', 0);
     if (!$params->get('date_showtime', 0) || $storeAsLocal) {
         $this->resetToGMT = false;
     }
     $exactTime = $this->formatContainsTime($params->get('date_table_format'));
     // $$$ rob if filtering in querystring and ranged value set then force filter type to range
     $filterType = is_array($value) ? 'range' : $this->getFilterType();
     switch ($filterType) {
         case 'range':
             // Ranged dates should be sent in sql format
             break;
         case 'field':
         case 'dropdown':
         case 'auto-complete':
         default:
             // Oddity when filtering from qs
             $value = str_replace("'", '', $value);
             /**
              *  parse through JDate, to allow for special filters such as 'now' 'tomorrow' etc.
              *  for searches on simply the year - JDate will presume its a timestamp and mung the results
              *  so we have to use this specific format string to get now and next
              */
             if (is_numeric($value) && JString::strlen($value) == 4) {
                 // Will only work on php 5.3.6
                 $value = JFactory::getDate('first day of January ' . $value)->toSql();
                 $next = JFactory::getDate('first day of January ' . ($value + 1));
             } elseif ($this->isMonth($value)) {
                 $value = JFactory::getDate('first day of ' . $this->untranslateMonth($value))->toSql();
                 $next = JFactory::getDate('last day of ' . $this->untranslateMonth($value))->setTime(23, 59, 59);
             } elseif (trim(JString::strtolower($value)) === 'last week') {
                 $value = JFactory::getDate('last week')->toSql();
                 $next = JFactory::getDate();
             } elseif (trim(JString::strtolower($value)) === 'last month') {
                 $value = JFactory::getDate('last month')->toSql();
                 $next = JFactory::getDate();
             } elseif (trim(JString::strtolower($value)) === 'last year') {
                 $value = JFactory::getDate('last year')->toSql();
                 $next = JFactory::getDate();
             } elseif (trim(JString::strtolower($value)) === 'next week') {
                 $value = JFactory::getDate()->toSql();
                 $next = JFactory::getDate('next week');
             } elseif (trim(JString::strtolower($value)) === 'next month') {
                 $value = JFactory::getDate()->toSql();
                 $next = JFactory::getDate('next month');
             } elseif (trim(JString::strtolower($value)) === 'next year') {
                 $value = JFactory::getDate()->toSql();
                 $next = JFactory::getDate('next year');
             } else {
                 $value = JFactory::getDate($value)->toSql();
                 /**
                  *  $$$ hugh - strip time if not needed.  Specific case is element filter,
                  *  first time submitting filter from list, will have arbitrary "now" time.
                  *  Dunno if this will break anything else!
                  */
                 if (!$exactTime) {
                     $value = $this->setMySQLTimeToZero($value);
                 }
                 $next = JFactory::getDate(strtotime($this->addDays($value, 1)) - 1);
                 /**
                  *  $$$ now we need to reset $value to GMT.
                  *  Probably need to take $storeAsLocal into account here?
                  */
                 $this->resetToGMT = true;
                 $value = $this->toMySQLGMT(JFactory::getDate($value));
                 $this->resetToGMT = false;
             }
             // Only set to a range if condition is matching (so don't set to range for < or > conditions)
             if ($condition == 'contains' || $condition == '=' || $condition == 'REGEXP') {
                 if (!$params->get('date_showtime', 0) || $exactTime == false) {
                     // $$$ rob turn into a ranged filter to search the entire day  values should be in sql format
                     $value = (array) $value;
                     $condition = 'BETWEEN';
                     $value[1] = $next->toSql();
                     // Set a flat to stop getRangedFilterValue from adding an additional day to end value
                     $this->rangeFilterSet = true;
                 }
             } elseif ($condition == 'is null') {
                 $value = "";
             }
             break;
     }
     $this->resetToGMT = true;
     $value = parent::getFilterValue($value, $condition, $eval);
     return $value;
 }
Example #2
0
 /**
  * Builds an array containing the filters value and condition
  *
  * @param   string  $value      initial value
  * @param   string  $condition  initial $condition
  * @param   string  $eval       how the value should be handled
  *
  * @return  array	(value condition)
  */
 public function getFilterValue($value, $condition, $eval)
 {
     $value = $this->prepareFilterVal($value);
     $return = parent::getFilterValue($value, $condition, $eval);
     return $return;
 }
Example #3
0
 /**
  * Builds an array containing the filters value and condition
  *
  * @param   string  $value      Initial value
  * @param   string  $condition  Initial $condition
  * @param   string  $eval       How the value should be handled
  *
  * @since   3.0.6
  *
  * @return  array	(value condition)
  */
 public function getFilterValue($value, $condition, $eval)
 {
     $fType = $this->getElement()->filter_type;
     if ($fType == 'auto-complete') {
         $stringComparisons = array('begins', 'contains', 'equals', 'ends');
         if (in_array($condition, $stringComparisons)) {
             // Searching on value so set to equals
             $condition = '=';
         }
     }
     return parent::getFilterValue($value, $condition, $eval);
 }