src/flowcode/ceibo/EntityManager.php
public function findByGenericFilter($name, $filter = null, $page = 1, $orderColumn = null, $orderType = null) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $selectQuery = "";
        $whereQuery = "";
        $orderQuery = "";

        $selectQuery .= "SELECT * FROM `" . $mapper->getTable() . "` ";
        $filterList = array();
        if (!is_null($filter)) {
            $filterList = explode(" ", $filter);
        }

        if (!is_null($filter)) {
            $whereQuery .= " WHERE 1=2 ";
            foreach ($filterList as $searchedWord) {
                foreach ($mapper->getFilter("generic")->getColumns() as $filteredColumn) {
                    $whereQuery .= " OR $filteredColumn LIKE '%" . $searchedWord . "%'";
                }
            }
        } else {
            $whereQuery .= " WHERE 1 ";
        }

        if (!is_null($orderColumn)) {
            $orderQuery .= "ORDER BY $orderColumn ";
            if (!is_null($orderType)) {
                $orderQuery .= "$orderType";
            } else {
                $orderQuery .= "ASC";
            }
        }

        $from = ($page - 1) * $mapper->getFilter("generic")->getItemsPerPage();
        $pageQuery = " LIMIT $from , " . $mapper->getFilter("generic")->getItemsPerPage();

        $query = $selectQuery . $whereQuery . $orderQuery . $pageQuery;
        $result = $this->getDataSource()->query($query);

        if ($result) {
            $collection = new Collection($mapper->getClass(), $result, $mapper);
        } else {
            $collection = new Collection($mapper->getClass(), array(), $mapper);
        }

        $selectCountQuery = "SELECT count(*) as total FROM `" . $mapper->getTable() . "` ";
        $query = $selectCountQuery . $whereQuery;
        $result = $this->getDataSource()->query($query);
        $itemCount = $result[0]["total"];
        $pager = new Pager($collection, $itemCount, $mapper->getFilter("generic")->getItemsPerPage(), $page);

        return $pager;
    }
public function findByGenericFilter($name, $filter = null, $page = 1, $orderColumn = null, $orderType = null) {
        $this->load();
        $mapper = MapperBuilder::buildFromName($this->mapping, $name);

        $selectQuery = "";
        $whereQuery = "";
        $orderQuery = "";

        $selectQuery .= "SELECT * FROM `" . $mapper->getTable() . "` ";
        $filterList = array();
        if (!is_null($filter)) {
            $filterList = explode(" ", $filter);
        }

        if (!is_null($filter)) {
            $whereQuery .= " WHERE 1=2 ";
            foreach ($filterList as $searchedWord) {
                foreach ($mapper->getFilter("generic")->getColumns() as $filteredColumn) {
                    $whereQuery .= " OR $filteredColumn LIKE '%" . $searchedWord . "%'";
                }
            }
        } else {
            $whereQuery .= " WHERE 1 ";
        }

        if (!is_null($orderColumn)) {
            $orderQuery .= "ORDER BY $orderColumn ";
            if (!is_null($orderType)) {
                $orderQuery .= "$orderType";
            } else {
                $orderQuery .= "ASC";
            }
        }

        $from = ($page - 1) * $mapper->getFilter("generic")->getItemsPerPage();
        $pageQuery = " LIMIT $from , " . $mapper->getFilter("generic")->getItemsPerPage();

        $query = $selectQuery . $whereQuery . $orderQuery . $pageQuery;
        $result = $this->getDataSource()->query($query);

        if ($result) {
            $collection = new Collection($mapper->getClass(), $result, $mapper);
        } else {
            $collection = new Collection($mapper->getClass(), array(), $mapper);
        }

        $selectCountQuery = "SELECT count(*) as total FROM `" . $mapper->getTable() . "` ";
        $query = $selectCountQuery . $whereQuery;
        $result = $this->getDataSource()->query($query);
        $itemCount = $result[0]["total"];
        $pager = new Pager($collection, $itemCount, $mapper->getFilter("generic")->getItemsPerPage(), $page);

        return $pager;
    }
public function findByGenericFilter ( $ name , $ filter = null , $ page = 1 , $ orderColumn = null , $ orderType = null ) { $ this -> load ( ) ; $ mapper = MapperBuilder :: buildFromName ( $ this -> mapping , $ name ) ; $ selectQuery = "" ; $ whereQuery = "" ; $ orderQuery = "" ; $ selectQuery .= "SELECT * FROM `" . $ mapper -> getTable ( ) . "` " ; $ filterList = array ( ) ; if ( ! is_null ( $ filter ) ) { $ filterList = explode ( " " , $ filter ) ; } if ( ! is_null ( $ filter ) ) { $ whereQuery .= " WHERE 1=2 " ; foreach ( $ filterList as $ searchedWord ) { foreach ( $ mapper -> getFilter ( "generic" ) -> getColumns ( ) as $ filteredColumn ) { $ whereQuery .= " OR $filteredColumn LIKE '%" . $ searchedWord . "%'" ; } } } else { $ whereQuery .= " WHERE 1 " ; } if ( ! is_null ( $ orderColumn ) ) { $ orderQuery .= "ORDER BY $orderColumn " ; if ( ! is_null ( $ orderType ) ) { $ orderQuery .= "$orderType" ; } else { $ orderQuery .= "ASC" ; } } $ from = ( $ page - 1 ) * $ mapper -> getFilter ( "generic" ) -> getItemsPerPage ( ) ; $ pageQuery = " LIMIT $from , " . $ mapper -> getFilter ( "generic" ) -> getItemsPerPage ( ) ; $ query = $ selectQuery . $ whereQuery . $ orderQuery . $ pageQuery ; $ result = $ this -> getDataSource ( ) -> query ( $ query ) ; if ( $ result ) { $ collection = new Collection ( $ mapper -> getClass ( ) , $ result , $ mapper ) ; } else { $ collection = new Collection ( $ mapper -> getClass ( ) , array ( ) , $ mapper ) ; } $ selectCountQuery = "SELECT count(*) as total FROM `" . $ mapper -> getTable ( ) . "` " ; $ query = $ selectCountQuery . $ whereQuery ; $ result = $ this -> getDataSource ( ) -> query ( $ query ) ; $ itemCount = $ result [ 0 ] [ "total" ] ; $ pager = new Pager ( $ collection , $ itemCount , $ mapper -> getFilter ( "generic" ) -> getItemsPerPage ( ) , $ page ) ; return $ pager ; }
Finds entitys by its generic filter defined in the configured mapping.
@param type $name
@param type $filter
@param type $page
@param type $orderColumn
@param type $orderType
@return Pager
Finds entitys by its generic filter defined in the configured mapping .