You are here:  » New Filter: Drop record if length less than


New Filter: Drop record if length less than

Submitted by sirmanu on Thu, 2018-10-18 11:45 in

Hi David.
I have some merchants which have invalid names. For instance, there is a merchant with a lot of names "-". The must have some error exporting products...

Is any filter which I can save globally for dropping records less than an amount of chars?

Submitted by support on Thu, 2018-10-18 11:53

Sure - here's a quick adaption of the Price Range filter to drop records by field length with min / max (both optional)...

  /*************************************************/
  /* fieldLength */
  /*************************************************/
  $filter_names["fieldLength"] = "Field Length";
  function filter_fieldLengthConfigure($filter_data)
  {
    print "Min:<br />";
    print "<input type='text' name='min' value='".widget_safe($filter_data["min"])."' />";
    widget_errorGet("search");
    print "<br /><br />";
    print "Max: (leave blank for no upper limit)<br />";
    print "<input type='text' name='max' value='".widget_safe($filter_data["max"])."' />";
    widget_errorGet("replace");
  }
  function filter_fieldLengthValidate($filter_data)
  {
    if ($filter_data["min"])
    {
      if (!is_numeric($filter_data["min"]))
      {
        widget_errorSet("min","must be numeric");
      }
    }
    if ($filter_data["max"])
    {
      if (!is_numeric($filter_data["max"]))
      {
        widget_errorSet("max","must be numeric");
      }
    }
  }
  function filter_fieldLengthExec($filter_data,$text)
  {
    global $filter_dropRecordFlag;
    if ($filter_dropRecordFlag) return $text;
    $length = strlen($text);
    if ($filter_data["min"] && $filter_data["max"])
    {
      $filter_dropRecordFlag = (($length < $filter_data["min"]) || ($length > $filter_data["max"]));
    }
    elseif ($filter_data["min"])
    {
      $filter_dropRecordFlag = ($length < $filter_data["min"]);
    }
    elseif ($filter_data["max"])
    {
      $filter_dropRecordFlag = ($length > $filter_data["max"]);
    }
    return $text;
  }

Cheers,
David.
--
PriceTapestry.com