0

I'm building a Joomla! Website (currently running 3.9.0). It's a website of a Sports Club and we would like to add Live Score, Scoreboard and Last Result. The Sport Association told us the only two options currently are iFrame (please, no!) or data, that would be read from a CSV file (they are still building a system, that would work with a proper database). So, basically, I need a module that can read the file and show the required data.

Is this possible, can you give me some clues how to get started here?

What we are trying to do here:

We have a live CSV file on a remote server (read only) and we can access it through the link provided by the Association.

This is the example content of the CSV:

;;7. krog - sobota 24.11.2018;;;;
1185;M1158;PRO Volley;FužinarSijMetalRavne;0:3;20:25,22:25,20:25;

We would like to display it in a table in a Joomla module in a similar way as shown in the screenshot (the screenshot is from the Association, they are using the same source).

enter image description here

Thanks!

  • This is a bit Too Broad. We don't know what the csv file will look like. We don't know what the database schema will look like. Is it possible? Definitely. Is there an existing extension that is suitable? Maybe. Have you researched this extensively? Probably not. Can someone give you vague/general guidance? Yes, but the best questions for this Q&A are ones where you show your efforts and ask for support when you stuck with a specific challenge and layout the exact solution that you require. Please refine your question to include some sample data and your exact desired result. – mickmackusa Nov 26 '18 at 23:12
  • OK, I tried to refine everything in the main question. The general problem of my research was that most of extensions are either paid (and unfortunately the client is a reincarnation of Mr. Scrooge), they work with a local-based CSV files or they require a manual import of a CSV file each time you want to make a change. What I want here is an option where Joomla (or a module or a plugin) would read from a remote server and show the data. I'm ready to pay out of my own pocket if the price is relatively reasonable to my budget. Or I'd create a plugin (but I consider myself as a PHP Newbie). – JxM Nov 27 '18 at 8:12
  • @JxM, I don't get the "Customer requires but not paying". Certainly this isn't the place to address budget policy matters of projects, but adding new functionality/features to a site has a cost one way or another: either the purchase of software, or custom development by others, or even if the site owner develops the feature on his own, it's a cost of personal time and efforts. Otherwise the feature can not be added. I want to run with 250miles/hr - Can you give me a Ferrari for free? Would that make any sense? Anyway, the focus here shall remain on the features and the programming aspect. – FFrewin Nov 27 '18 at 10:21
  • @FFrewin, I couldn't agree more, but the matter here is a bit more complicated. I can't go into details, but let's just say there's a very good reason why this particular functionality needs to be implemented. And like I said, I'm willing to use a part of my not-exactly-big budget to get a functionality implemented, but as long as the price is reasonable. – JxM Nov 27 '18 at 13:29
0

From a quick search on the Joomla Extensions Directory, there are at least a couple of extensions that look like they will display information from an external CSV source:

Tabulizer (from €24)

"Tabulizer provides all the functionality to read data from various sources (typed plain text, Excel and CSV files, Web/HTML pages, RSS Feeds, Database Queries/Tables) and present them in various formats, such as responsive tables, graphs, charts, galleries, event calendars, etc"

ARI Data Tables ($15)

"Can load data from CSV files (can load remote CSV files)"

"Provide possibility to render plain HTML table based on data from CSV file or database. Display of this table can be customized with help CSS"

Unfortunately neither of these are free but they are probably quite affordable compared to the time it would take to code your own solution.

  • 1
    Yes! At the end we decided to try out ARI Data Tables. In both cases though we have some language specific encoding problems, but we are trying to work them out. Thanks! – JxM Dec 4 '18 at 18:08
0

CSV Improved is really powerful and you can import into Joomla content articles, K2, and others: https://csvimproved.com/

  • As far as I get info from their website it doesn't really allow you to use remote-server-based CSV files and read from them. I hope I'm wrong. – JxM Nov 27 '18 at 13:31
  • I would contact that developer to see if they have that option or what it would take to customize. How often do you need to import? You could put together a CLI script to fetch the CSV from the URL and put on your server – YellowWebMonkey Nov 27 '18 at 15:35
  • It will be updated three to four times a week and the Live Score module will have to fetch data every minute (that's the current refresh rate on the side of the Association). What I need is a completely automated system because when the website is out I won't deal with it thoroughly any longer, just the basic backend support. I will definitely contact the developer and see if they can help and check the other option! Thanks! – JxM Nov 27 '18 at 16:33
0

Start by reading Developing a Basic Module documentation to familiarize with module structure.

Assuming you don't need AJAX updates, helper function like this would work:

defined('_JEXEC') or die;

use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Http\HttpFactory;
use Joomla\Registry\Registry;

class ModExampleHelper
{
    public static function getData($params)
    {
        // Source URL not set.
        if (!$params->get('url'))
        {
            return array();
        }

        $file = JPATH_ADMINISTRATOR . '/cache/mod_example/' . md5($params->get('url'));

        // File exists and is fresh.
        if (File::exists($file) && filemtime($file) > microtime(true) - $params->get('refreshInterval', 60))
        {
            return json_decode(file_get_contents($file));
        }

        // Some servers may block requests without user agent.
        $options  = $params->get('userAgent') ? new Registry(array('userAgent' => $params->get('userAgent'))) : null;

        // Retrieve the data.
        $response = HttpFactory::getHttp($options)->get($params->get('url'));

        // Check that response is valid.
        if ($response->code === 200 && $response->body)
        {
            // Save data based on CSV structure. This could be configurable.
            foreach ($data = str_getcsv($response->body, "\n") as $key => $row)
            {
                $data[$key] = str_getcsv($row, ';');
            }

            // Save new data to file.
            File::write($file, json_encode($data));

            return $data;
        }

        // Retrieving data failed, return data from old file.
        if (File::exists($file))
        {
            return json_decode(file_get_contents($file));
        }

        return array();
    }
}

Call the function in main file:

$data = ModExampleHelper::getData($params);

And display the table in the template:

<table class="table">
    <?php foreach($data as $row) : ?>
        <tr>
            <?php foreach($row as $cell) : ?>
                <td><?php echo $cell; ?></td>
            <?php endforeach; ?>
        </tr>
    <?php endforeach; ?>
</table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.