what is the best way to get the items from categories.
I have a project with approx 40 categories and in total 3000 items and 4 level.
I found a way from TYPO3 self by collections but i must add them to the category manual?
I saw that the TYPO3 blog extension takes another way by an extra column "posts" and a objectstorage in the model categories. So not necessary to add the items / posts.
Somehow the second way like the blog does, sounds nicer but is this performant, when i have a list of 3 categories with each 4 to 5 subcategories and each approx 100 to 250 items?
Thank you
you could build a query and get all related items yourself from the DB.
// get QueryBuilder for table 'sys_category_record_mm'
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_category_record_mm');
// query the table
$result = $queryBuilder
->select('uid_foreign,tablenames')
->from('sys_category_record_mm')
->where($queryBuilder->expr()->eq('uid_local', $uidOfYourCategory))
->execute()
->fetchAll();
Now, $result is an array with all childs of the category wit the id $uidOfYourCategory. This array you can use to get the items from their repos.
If you only want items from tt_content, or maybe a table named tx_yourtable, you can add an andWhere to the query lik this:
$result = $queryBuilder
->select('uid_foreign,tablenames')
->from('sys_category_record_mm')
->where($queryBuilder->expr()->eq('uid_local', $uidOfYourCategory))
->andWhere($queryBuilder->expr()->eq('tablenames', 'tx_yourtable'))
->execute()
->fetchAll();
Related
I would like to output the data, from table tt_address in the database in an array and use it in my FluidStyledContent element. However, I only get an array with null.
in my setup.typoscript file in the Data Processing part i use this code
30 {
table = tt_address
as = myrecords
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = image
}
}
}
It works with the table tt_content but not tt_address.
I try to create an array with all records that are stored under tt_adress.
Do I have to adjust anything for this?
You need to specify, from which pid the address records should be fetched. A simple SELECT * FROM tablename is not possible.
pidInList needs to be added to your select query. By the way, what's the content type of the object 30. I assume it's CONTENT.
Please check the documentation for all the possibilities.
Hint: debugging database queries in TypoScript can be tedious work. To ease things I add a small typo e.g. to the table name. Then TYPO3 outputs the whole query in the frontend and you can spot easier what is wrong in your query.
I have the need to list links on a page, grouped together by category.
In MySql this would be easy - I'd have a category table and a links table. The Links table would include a category Id. I could then loop over the entries in the category table and
query the the links table where category matches the current category.
I've been reading about model tree structures in Mongo and things seem to work a little differently (link). The basic list seems to be either store a parent or child reference in the document directly which allows you to
create a tree strcuture. I'm unsure how to use these sort of structures to output the data as I need it. I need to somehow loop over the categories and then query the links based on that.
I'm wondering if I can just take the same approach as I would have with Sql? So have a seperate categories collection and then in the links collection just have an object Id that points to the categories? I can then loop over categories and query the links table each time for all links with a matching category.
I have the following text fields I search with Sphinx: Title, Description, keywords.
However, sometimes things are narrowed down using categories. We have 3 category fields: CatID1, CatID2 and CatID3.
So, for example, I need to see if the word "Kittens" is in the Title, Description, or Keywords, but I also want to filter so that only items that have the categories (Animals - ID Number 8) or (Pets - ID Number 9) or (Felines - Category ID Number 10) in either of those CatID fields.
To clarify, only show items that have a 8,9 or 10 in CatID1, 2 or 3.
Any ideas on how I would accomplish this using sphinx filtering or searching the CatID1 fields as keywords?
Note: I am able to filter and it works great only using one category, i.e:
if(!empty($cat_str)) {
$cl->SetFilter( 'catid1', array( $cat_str ));
}
Thanks!
Craig
SetFilter takes an array. In your example you are putting $cat_str into an array. A array of one item.
So you just needs to build array with all the ids.
$cl->SetFilter( 'catid', array( $cat1, $cat2, $cat3 ));
But thats not very flexible. So you probably build the array dynamically, rather than hard-coded like that. But thats upto your application how to build the array.
But also storing the ids, in three sperate attributes, makes it hard to search. Notice in the above example, just noticed a attribute called catid. This would be a single multi-value attribute, that contains the ids from all three cat fields. That way its easy to search for ids in ANY of the columns at once.
http://sphinxsearch.com/docs/current.html#mva
if using a sql source, could do with something like
sql_query = SELECT id, title ... , CONCAT_WS(',', CatID1, CatID2 and CatID3) as catid FROM ...
sql_attr_multi = uint catid from field;
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
I'm trying to retrieve records ordered by a DateTime with Linq to entities, but I need them as distinct records as well.
My table design looks like this:
Where blogItemNodeId is an Umbraco CMS node (the blog item node to which a comment can be created)
The requirement is that a list of blog items can be sorted by how many comments they have. So I need to get the latest comments distinct by blogItemNodeId to display those blog items.
My current linq query looks like this:
var distinctComments = (from c in ctx.BlogComments
orderby c.date
group c by c.blogItemNodeId
into uniqueRecords
select uniqueRecords.FirstOrDefault());
The problem with this query is that it finds the first (hence FirstOrDefault()) record with distinct blogItemNodeId where it should find the one which is newest of all comments with the same blogItemNodeId.
Does anyone know how to achieve this? :-)
Thanks a lot in advance.
EDIT
I managed to get it to work by doing this:
var allComments = (from c in ctx.BlogComments
orderby c.date descending
select c).ToList();
var distinctComments = allComments.GroupBy(x => x.blogItemNodeId).Select(y => y.FirstOrDefault());
But then I have to get all the comments before doing the group which is not very elegant nor performant.
Any help is greatly appreciated!
You could combine both the orderBy statement and the GroupBy statement into one single statement like this:
var distinctComments = ctx.BlogComments.OrderBy(c => c.date)
.GroupBy(x => x.blogItemNodeId)
.Select(y => y.FirstOrDefault());
If the performance is bad, you could cache your DataContext in the HttpCache through a Singleton. See this blogpost for an example. This is based on the Umbraco DataContext but can be easily modified for use with another type of context.