So last week I had burst the quota of the maximum amount of emails we could send out a month and the quota hasn’t renew yet. So, this week I am focusing on my next task. What I have to achieve in task number 4 is to generate a final report for the competition. This report is going to be used by the organizers for archival purpose. Basically, the big picture of my task is to figure out a way to generate PDF reports with necessary information.  However, this is a little different from what I have done in the registration system.

For this task, I have to create a new REST API endpoint so that when the user send a CURL request pointing to that endpoint, they will get the report saved in PDF format. Not only this, the design of the template is very different as well. Previously in task number 1 and 2, I have designed a fixed template using WTemplate. However, this is not the case now. I couldn’t design a fix template for this task because the number of participants in each events vary. Hence, I have to design the template so that it would automatically determine how many rows to have in the table depending on the number of participants. Huhhhhrrr… things are not easy!

Yes, the tasks that I had done previously involved WTemplate and also generating PDF output but somehow I have no idea on how to finish this task. Dr Shawn told me that, I could customize a function in WTemplate, so that the function would do what I need. For example, I could define a place holder like this, “${generate:report}” , and what it does is that it will call the function generate with report as the argument. It might look easy, but not for me. I have struggled for quite some time to define a customize function that could be used by WTemplate. After a lot of trial and error, something popped up in my mind. What if I add in the new function in the library header file? That could work. Deep inside I know it is not the way to do it, but I have decided to give it a try. I copied the WTemplate header file and defined a new function in it. I included the modified header file instead and run the code. Woahhh, now I am using a new function in WTemplate. However, I still think that it’s not the way to do, so I asked my colleagues’ opinions. They are surprised and agreed that I shouldn’t do it that way. I am very thankful that I have a lot of helpful colleagues, they came to my desktop and discuss with me. After some research, we found out that we could use a customize function without modifying the library header file. So,what we found is that, Wt::WTemplate::Function is a typedef  of a boost::function. My colleague, Wen Yan told me that I might have to define the new function so that it matches the typedef and then it might work. We gave it a try and it did work. I appreciate their helps a lot!

I think this week is the most stressful week for me so far but, no pain no gain! My task is not over yet, and in fact I still have a lot to do. Right now, I am just testing to use a customize function in WTemplate. The function we have called just now is not the function I needed. To design the function I needed, I still have to figure out a way on how could I query the required information from the database, how should I iterate through the database, how do I get information from different tables, how do I bind it to the template and how do I create the REST API endpoint. There are so many “HOW”! Tough week, but LET’S GET IT DONE!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.