I have a results set using Zend Paginator, its all working fine but I need to filter the results by using checkbox options like on eBay, Amazon etc..
I have read about Zend filter but dont know where to start.
Do anyone have any experience of this please?
Thanks
John
Zend_Filter is to transform something into something, like a translator.
The huge advantage of Zend_Paginator is that it retrieves data page by page. Figure out you want to display 30 items from a several millions table. It would be a very slow process if you retrieve all data and then filter accordingly to take out those 30 items.
Supposing you are retrieving your items from the database, your should use a DbSelect or DbTableSelect adaptor. Use DbTableSelect if you retrieve from one table and DbSelect if you retrieve from more than one table by joining.
Once you have your $select object with which you would retrieve all items in all pages, the paginator will retrieve the items page by page by setting a limit and offset. For instance, if you are displaying 30 items per page and you want to display the page number 3, the paginator will set $select->limit(30, 60) (you don't need to do this, the paginator does it for you). To accomplish this, try following in your controller:
// pass ?page=N in the url
$pageNumber = $this->getRequest()->getParam('page', 1);
// itemsPerPage can also be read from the url
$itemsPerPage = 30;
// this $select must retrieve all items in all pages
$select = new Zend_Db_Select();
$select->from(...)
// eventually joins, where, or order statements
$paginator = new Zend_Paginator($select);
$paginator->setCurrentPageNumber($pageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
You finally need to pass the paginator to the template is rendering the items and the pagination control. So add
$this->view->paginator = $paginator;
and edit the template as in http://framework.zend.com/manual/1.12/en/zend.paginator.usage.html#zend.paginator.rendering
So it's the basic functionality of the paginator. I hope this helps. It would be very similar if you are using other type of adapters like Array or Iterator.
The checkbox options have nothing to do with Zend_Paginator.
Zend_Paginator is just a Helper class that helps you paginate your results, it adds LIMIT clause and make templating the results easier, nothing more.
What you're lookig for is called 'Faceted search', you have to develop the logic behind it or use a search engine like Solr that can generate it automatically
Related
This seems like it should be obvious, but everything I find relates to returning a collection extracted from records, rather then returning a collection of new results derived from calculations on the records.
For instance, say I have records of property in my database. I can extract a collection of a subset (or the entire set) of the records. But I want to loop through this collection, calculate new values for each line item, (like marketValue-debt=netValue) and return a new collection of just those results to my view. I'm trying to keep my (much more complicated than this example) calculation in my controller and out of my view, but I'm not getting the way to stuff new values into a new collection of results for return to display in the view.
I could derive my results and stuff them into an array, but how do I pass this as a new collection for looping through in my view to show those results? Seems like there should be an Eloquent way to do this.
My project is in Laravel 6 running on Apache/Laragon, PHP 7 with MariaDb
Thanks in advance for helping me out.
Take a look at this. Hope it will be of some help.
If you want a new collection, use the map method.
$new_collection = $old_collection->map(function ($item) {
return $item->marketValue - $item->debtValue;
});
I need to export the products catalog after I applied a filter. I made a custom button for this, but in the query I need the filters already applied on the grid. Is it possible to get them from the global variable? I noticed that if I refresh the page, the filters are kept, but I do not know where they are from.
You can find applied filters data at the ui_bookmark table of your database;
SELECT `namespace`, `config` FROM `ui_bookmark`;
I want to create custom content elements. I know how this works basically. But I asking myself, if there is a way to store the configuration data of this elements in a decent database table?
I only know the way to extend the tt_content table and store my data there. But with a bigger amount of elements and fields the tt_content would be become bigger and bigger too. I would like to prevent this.
And just before you ask: I don't want to use FluidTYPO3. ;) I just would like to do it with basic TYPO3 functionality.
Don‘t know if there is a nicer way, but maybe you can create your elements with no field definition but with IRRE and min:1 and max:1 - but this is not really a nice way.
The better way is to reuse the fields given in tt_content as often as possible and only add more fields if really needed.
Maybe you should have a look on EXT:mask and EXT:mask_export - those two are very powerful tools to create custom content elements (EXT:mask) and export them as an own extension (EXT:mask_export) so there is no need for these two extensions in production but only in development.
As you create a content element you will always need to use the database table tt_content. Of course it makes sense to use relations to custom records, e.g. if you create elements like tabs, accordions, ...
What you can do is to reuse existing columns as there are - as you said - a lot of those. So reuse fields like header, bodytext, image, ... Take a look at /sysext/frontend/Configuration/TCA/tt_content.php. The benefits are
a bit smaller table which is most of the time not really relevant to performance
well designed fields including a label whith translations into all languages
You can also reuse a field and its configuration and override it with overrideChildTca. See https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Properties/InlineOverrideChildTCa.html?highlight=overridechildtca in the docs.
I recommend you to have a look at the typo3 extension mask. You can create custom contents and map existing tt_content fields to your new elements. It makes sense to reuse the header, bodytext, media, image fields because the backend preview will adopt automatically.
I used it recently and it works really nice! Here is some resource to jump in (only german)
If you do not need to have indexes on your new fields it is not a big problem to blow up tt_content with new fields. It does not impact the performance so much.
If you need to have new 1:N relations from your content to some child-record (accordion, team-listing, etc), simply add them as inline elements (IRRE) and add the field to your types-string.
If you need to have a new kind of data, that should be filterable, sortable and so on, you should create a new type of record with its own table structure and use extbase plugins to display that data.
As long as you simply need custom contents, you are fine with extending/remapping tt_content.
You can use hooks for this.
In your ext_localconf.php:
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = \Namespace\Hooks\Classname::class;
And in Classes/Hooks/Classname:
<?php
namespace Namespace\Hooks;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\DataHandling\DataHandler;
class Classname implements SingletonInterface {
public function processDatamap_beforeStart(&$dataHandler) {
$datamap = &$dataHandler->datamap;
}
}
Here you have to modify the $datamap to your needs.
Documentation is here: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Typo3CoreEngine/Database/Index.html
Kind regards
It is explained here https://learn-typo3.com/blog/news-detail/how-to-create-custom-content-elements-on-typo3, however I prefer extending and reusing tt_content fields.
I´m using GWT 2.4 with a DataGrid and a SimplePager along with a MultiSelectionModel. I want to implement a simple select-all-feature over all pages.
I´m only able to select all visible items on the current page. What is the best way to select all items on all pages?
I know the MultiSelectionModel stores the proxy keys provided by a ProvidesKey object in a HashMap. I think I have to request all proxy objects from server or at least all keys. But actually I don´t want to store information about the ProvidesKey´s getKey()-method on server-side. But I also can not access the MultiSelectionModel´s HashMap of the selected proxies´ keys. This all looks cumbersome, so is there a better way to solve this?
As mentioned in https://developers.google.com/web-toolkit/doc/latest/DevGuideUiCellWidgets#selection, one way to achieve this would be to implement your own SelectionModel (e.g. by extending AbstractSelectionModel or DefaultSelectionModel):
A complex implementation can handle "select all" across multiple pages using a boolean to indicate that everything is selected, and then keep track of negative selections.
Why do you need all keys for select all? When you select some objects from a list, you need to remember which ones are selected, but when you select all objects, you need a single Boolean:
// on click Select All button/checkbox
boolean selectAll = true;
// ask a user what he wants to do
// send a request to server with a parameter selectAll to update/delete all objects
Select all across multiple pages will work only if you are NOT lazy loading. First of all why do you need to select all? If you want to do some actions on all the grid data, you will already have the list and you can perform your actions on the list directly. Nonetheless you can select all the rows of the grid over multiple pages by iterating through the list and using the following API on each item.
public void setSelected(T item, boolean selected);
Note: This will work only if you are NOT lazy loading.
I am using cakephp with postgresql. Some of my tables are very large.When using cakephp's pagination, it runs COUNT() on the large table and then it queries for the actual result. The count query takes 2.5 minutes, while the actual query that returns the data takes 95ms.
Is it possible to remove the need for the count, or replace it with something that may go faster?
I don't need an exact number of rows returned, much like the way a Google search returns results 1-10 of about 765,000.
EDIT: Alternately, is there a way I can disable count altogether? There will often be so many results knowing how many pages is not necessary. All I need is a "Next" button that increases the SQL OFFSET like the cakephp pagination already has, and if no rows are returned on the next page then that is fine.
I found the way to bypass the pagination count query in cakephp.
In the model that you want to paginate you can override the function that runs the count query, the function is paginateCount($conditions = null, $recursive = 0, $extra = array())
I used the following code to fix my issue:
function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
return 0;
}
Then I edited the pagination in the view to always display the next button. Going to a page with no results will just display nothing.
Official documentation gives you an ability to just force cake to fetch actual results:
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#custom-query-pagination
I hope it helps :-)