Display Dynamic List of Articles in Joomla - php

In a category list, I'd like to be able to display the list of articles dynamically. The website I'm developing allows a user to "submit" an article once they have read it. When they hit the submit button, the ID of that article is stored in the database in a table called "completed_quests." What I need to do is have Joomla check to see if the article ID exists in both the "content" and the "completed_quests" tables. If the article ID exists in both tables, then the article should not be displayed in the category list as that article or "quest" has already been submitted. If the article ID exists in the "content" table, but NOT in the "completed_quests" table, then the article SHOULD be displayed in the category list as it has note yet been submitted.
I'm wondering if there is a specific core Joomla file I should override to alter the category list output, or if I should develop a custom module to create this dynamic list. Any guidance would be much appreciated. If you have any other thoughts about how to display this dynamic list, I'm all ears.
edit: I've started by developing a custom module within Joomla, at least for testing. The below code is not working as expected. When I take out the following line "WHERE arp2i_completed_quests.id IS NULL" it displays a list of articles that exist in both tables. But what I need it to do is display the rows that exist in the content table but NOT in the completed_quests table. When I add the WHERE , it displays the text "ID:" and "TABLE:" for each row that exists, but the actual id and title from that row is not echo'ed to the screen. Please help.
Working code (see comments).
<?php
$query = "SELECT * FROM arp2i_completed_quests RIGHT JOIN arp2i_content ON arp2i_content.id=arp2i_completed_quests.id WHERE arp2i_completed_quests.id IS NULL LIMIT 0, 30 "; // prepare query
$db = &JFactory::getDBO(); // get database object
$db->setQuery($query); // apply query
$articles = $db->loadObjectList(); // execute query, return result list
foreach($articles as $article){ // loop through articles
echo 'ID:' . $article->id . ' Title: ' . $article->title . '<br />';
}
?>

You could override the com_content's listings view in your template.
You do that by copying default.php from /components/com_content/views/categories/tmpl/ to /templates/yourtemplate/html/com_content/categories/
However, I believe that such template overrides only allow you to update the display files of modules and components (the default.php files), and not the models, which would mean you have to add database queries into this layout file (or into a library), which feels a very hacky approach. It should work, though.
A better solution would be to create a bespoke component with a single view, and a model that queries your database to create the appropriate listings. It may even make sense to just make the whole thing a bespoke component (saving the articles in that component) and not use Joomla's articles manager at all.
If your listings page is not paginated, or if you do not care about an SEO friendly URL on secondary pages, then you also could create a module to display the listings and insert that into an article area. Modules are often simpler to make than components. You enter the database query into the helper file of a module.

You should just develop a content view that does exactly what you want. Should be very simple if you have some programming experience. You needn't change any core files.

Related

How to fetch posts with pagination feature in WP on a custom table?

I have a custom table that I created named cars_plugin and it has columns id, name, color, model
Now, I can get list of cars using
$sql = "SELECT note FROM cars_plugin WHERE ID = '$id'";
$query = $wpdb->get_results($sql, ARRAY_A);
foreach($query as $car){
// list cars here
}
The above code works as planned, and I could create a pagination for that, although it will be difficult, now my question is, if I have a custom table like that how do I query the table so I can be able to use the built-in Wordpress pagination functions?
This can't be done I think
I found no way to use WordPress default pagination for custom table. Cause the default pagination is initiated in WP_Query class which is curated or built or written only for querying posts from {wp-table-prefix}_posts table and may be joining other table related to posts.
So what is the solution ???
May be you can create your own class which will return you the result with pagination and this could be by extending WP_Query class. But this method will need a lot of modifications to manipulate the base class default methods. So I would prefer writing a separate new class for this than extending the WP_Query.
Another way would be straight PHP method. You can chunk the queried result and show them page by page. And I think it would be the easiest and smart way to do pagination for custom table in WordPress. For finding more on this method you can check those below links-
https://wordpress.stackexchange.com/questions/53194/wordpress-paginate-wpdb-get-results
http://www.walkswithme.net/wordpress-pagination-for-custom-tables
Hope that helps.

New Category not showing on News options tab in typo3

I have created new category but when I want to create news and assign to a particular category that new category does not come in the available categories list.
It sounds like you are using the system categories in the form but are creating News categories. When creating the new category look for a second category record type under the "System Records" branch. You should probably also start by looking for the system folder that contains the correct type of categories (if I recall correctly, migrating the categories puts the new categories in the same sysfolder as the old ones).
You may then want to clean out the old News category records - assuming you have run all the necessary migration commands, those tables will no longer be in use.

Joining tables in MySql to store viewed article id's

I have a Joomla site that I am developing and I am a novice when it comes to MySql. I need to be able to track how many articles a user has viewed and then be able to display the total number of viewed articles on the front end of the page (for instance if the user has viewed 3 articles, it should just echo the value '3' to the front end).
I'd also like to be able to store the article id and alias and be able to retrieve that data later if needed. The idea is that any particular user will be able to see how many articles they have viewed and possibly even be able to go back and review those articles (as they will no longer be displayed once viewed).
I haven't the faintest idea of where to start as far as building the table to store this data, and how to join it to the current user. Any help would be greatly appreciated, even if it is just pointing me to a good tutorial or resource.
There are three approaches, I believe:
Store All Viewed Article IDs in New Column In User Table
You could add a column to your user table to store the viewed articles. You could store the article ids as comma-separated values. Each time a new article is viewed you can append a new article ID. On the front-end, you can retrieve this string with a select statement and parse it out to get the individual IDs.
This method may not be practical with a CMS such as Joomla as adding to columns to system tables is asking for trouble.
New Table With One Row Per User
You create a new two-column table, one column has the user id and the other has the comma-separated list of viewed articles. There would be a 1-0 relationship between the existing user table and the new table.
A simple join will allow you to retrieve the viewed articles associated with the associated user.
New Table With One Row Per User/Article Combination
You create a new two-column history table which stores the user and a single viewed article ID. If a user has viewed ten articles, there will be ten rows.
Retrieving the viewed articles for a given user takes some work as you have to pull in all rows for that user and iterate through them.
Edit - Sample Code:
<?php
$config['db'] = array (
'host' => '',
'username' => '',
'password' => '',
'dbname' => ''
);
$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname='.$config['db']['dbname'],$config['db']['username'],$config['db']['password']);
$query = $db->query("SELECT user_id, article_id FROM viewed_articles WHERE user_id = 1234");
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>',print_r($rows,true),'</pre>';
?>
You would put in your MySQL DB and credentials in the $config array.
A good approach is to use a module to show the data and a plugin to store it.
To track the articles viewed by an user start with the Joomla documentation for plugin development. and look for content plugins.
This plugin should store, at least, the user identifier and the article identifier on a table (call it articleviews) created specially for this plugin.
To build a module check the Joomla module development. On this module you will load the data stored with the plugin from the articleviews table. Remember to index the table by user identifier, otherwise it will kill your web response as data grows.
EDIT: article identifier should be part of the index too.

SQL Query master detail style

I am working on a php+jquery phone app. The dificulty I am having is with the SQL database calls. I have successfully connected to the Joomla Database. I have retrieved simple information, such as a list of tables. What I want to do, and what I am needing: a list of of data from a specific catagory..(jos_content) that will be restrained by a section id, and a state.
$st = $db->prepare("SELECT * FROM `jos_content` WHERE state=1 and sectionid=6");
this works. This returns a small list that I can sort and filter to get the most recent article entry. BUT, I want to display another select statement when this entry is selected. I have it where it navigates to another page, but how do I relate the 2 statements?
So, you get a list (list of 1 item) that is a featured article. Then clicking on it brings you to the article. and will display the img, text and author and date.
Any help would be awesome. I am just learning this SQL database stuff slowly.
Best,
Corey
I'm confused by what you mean by "I want to display another select statement when this entry is selected". If I understand you correctly, you'll need to use the columns your retrieved from the SELECT statement you've shown to construct a URL

joomla - where is category ordering stored?

I have a question that might seem simple, but yet I was unable to find the answer. Unlike articles, which are stored in table jos_content, categories in table jos_categories lack any column named ordering or any other that would have the desired information stored. I also tried to find anything similar in the jos_assets table, but it did not help either.
I am hacking the content component a little and I need to get my child categories ordered by the ordering when calling $parent->getChildren() or just find the ordering column so I can create my own query even though it's not clean, I just need to get it working ASAP.
So where can I find category ordering or how do I force getChildren method to return ordered results?
Thanks in advance, Elwhis
In Joomla categorises' order is stored in table "jos_categories" as hierarchical tree structure with a set of linked nodes. Columns used to set order are: "parent_id", "lft", "rgt" and "level".
Assets and menu items are stored in the same way.
You can read more about "Tree traversal" on wiki
Edit:
From Joomla 1.6 to load a specific category and all its children in a JCategoryNode object use:
jimport( 'joomla.application.categories' );
$extension = 'Content'; // com_content
$options['countItems'] = true;
$categoryId = 0;
$categories = JCategories::getInstance($extension, $options);
$categories->get($categoryId);

Categories