Exemple #1
0
 /**
  * Returns a list of models where the field is equals one of the given values.
  * @param string $fieldName
  * @param IteratorAggregate $values
  * @return EntityArray 
  */
 public function filterIn($fieldName, IteratorAggregate $values)
 {
     $list = new ModelArray();
     $list->setModelTable($this->getModelTable());
     if ($values === null) {
         return $list;
     }
     if (!is_array($values) && !$values instanceof IteratorAggregate) {
         throw new \Exception('The parameters keys must be an array.');
     }
     foreach ($this as $object) {
         foreach ($values as $value) {
             if ($object->{$fieldName} === $value) {
                 $list->append($object);
                 break;
             }
         }
     }
     return $list;
 }
Exemple #2
0
 public static function where($where)
 {
     $self = self::instance();
     $rows = new ModelArray();
     //
     $sql = "select * from " . $self->DBtable . " where {$where} ";
     $data = Database::read($sql, 1);
     //
     foreach ($data as $key => $value) {
         $row = self::instance();
         //
         foreach ($value as $key2 => $value2) {
             $row->{$key2} = $value2;
         }
         //
         $rows->add($row);
     }
     //
     return $rows;
 }