original_string: public static function fetch_all_helper($table, $classname, $params) {
          $instance = new $classname();
  
          $classvars = (array)$instance;
          $params    = (array)$params;
  
          $wheresql = array();
  
          $dbparams = array();
          foreach ($params as $var=>$value) {
              if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
                  continue;
              }
              if (is_null($value)) {
                  $wheresql[] = " $var IS NULL ";
              } else {
                  $wheresql[] = " $var = ? ";
                  $dbparams[] = $value;
              }
          }
  
          if (empty($wheresql)) {
              $wheresql = '';
          } else {
              $wheresql = implode("AND", $wheresql);
          }
  
          global $DB;
          if ($datas = $DB->get_records_select($table, $wheresql, $dbparams)) {
  
              $result = array();
              foreach($datas as $data) {
                  $instance = new $classname();
                  self::set_properties($instance, $data);
                  $result[$instance->id] = $instance;
              }
              return $result;
  
          } else {
  
              return false;
          }
      }
code: public static function fetch_all_helper($table, $classname, $params) {
          $instance = new $classname();
  
          $classvars = (array)$instance;
          $params    = (array)$params;
  
          $wheresql = array();
  
          $dbparams = array();
          foreach ($params as $var=>$value) {
              if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
                  continue;
              }
              if (is_null($value)) {
                  $wheresql[] = " $var IS NULL ";
              } else {
                  $wheresql[] = " $var = ? ";
                  $dbparams[] = $value;
              }
          }
  
          if (empty($wheresql)) {
              $wheresql = '';
          } else {
              $wheresql = implode("AND", $wheresql);
          }
  
          global $DB;
          if ($datas = $DB->get_records_select($table, $wheresql, $dbparams)) {
  
              $result = array();
              foreach($datas as $data) {
                  $instance = new $classname();
                  self::set_properties($instance, $data);
                  $result[$instance->id] = $instance;
              }
              return $result;
  
          } else {
  
              return false;
          }
      }
code_tokens: public static function fetch_all_helper ( $ table , $ classname , $ params ) { $ instance = new $ classname ( ) ; $ classvars = ( array ) $ instance ; $ params = ( array ) $ params ; $ wheresql = array ( ) ; $ dbparams = array ( ) ; foreach ( $ params as $ var => $ value ) { if ( ! in_array ( $ var , $ instance -> required_fields ) and ! array_key_exists ( $ var , $ instance -> optional_fields ) ) { continue ; } if ( is_null ( $ value ) ) { $ wheresql [ ] = " $var IS NULL " ; } else { $ wheresql [ ] = " $var = ? " ; $ dbparams [ ] = $ value ; } } if ( empty ( $ wheresql ) ) { $ wheresql = '' ; } else { $ wheresql = implode ( "AND" , $ wheresql ) ; } global $ DB ; if ( $ datas = $ DB -> get_records_select ( $ table , $ wheresql , $ dbparams ) ) { $ result = array ( ) ; foreach ( $ datas as $ data ) { $ instance = new $ classname ( ) ; self :: set_properties ( $ instance , $ data ) ; $ result [ $ instance -> id ] = $ instance ; } return $ result ; } else { return false ; } }
docstring: Factory method - uses the parameters to retrieve all matching instances from the DB.
  
  @final
  @param string $table The table name to fetch from
  @param string $classname The class that you want the result instantiated as
  @param array $params Any params required to select the desired row
  @return mixed array of object instances or false if not found
docstring_tokens: Factory method - uses the parameters to retrieve all matching instances from the DB .