A few beginner question from the new module dev tutorial

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

A few beginner question from the new module dev tutorial

Post by Guido »

Since I've spent a lot of time learning PHP the past year, I want to become an active developer for CMSMS. I'm reading the new module development tutorial (thanks for this), and thought I'd ask some questions as I'm reading it to be able to learn the app's secrets.

My first one:

If I understand correctly, all files prefixed as 'action' (so action.do_something.php) are the handler files. They handle any data manipulation and database interaction. After this, you display a Smarty template file with the results. Now for my question, is it mandatory to name the Smaty template files the same as the accompanying action/handler file? So in the example, there's a handler file called action.edit_holiday.php. Is it mandatory to name the smarty template file 'edit_holidat.tpl'? Or is this just a good idea to keep thing organised?
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few beginner question from the new module dev tutorial

Post by Guido »

My second question:

I see there is a method called: 'Insert_ID()', which is a method of the database object. I looked at the api documentation, but couldn't find a database class. I'd like to know what this method does, and why it's called separately from the insertion from the rest of the record.

EDIT
I read there is a 'CmsDbQueryBase' class, but I can't find that on this page: http://www.cmsmadesimple.org/APIDOC2_0/ ... s/CMS.html
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few beginner question from the new module dev tutorial

Post by Guido »

My third question:

Code: Select all

$holidays = $query->GetMatches();
I see this method used, which is a method if the 'LayoutTemplateQuery' class. It doesn't accept any arguments, am I correct to assume that this method knows from which module it's being called, so that it returns the records for this module automatically?
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few beginner question from the new module dev tutorial

Post by Guido »

Shouldn't the following line on page 23:

Code: Select all

$obj = new HolidayItem;
be:

Code: Select all

$obj = new HolidayItem();
?

EDIT
No, that's optional, didn't know that but I just looked it up on PHP.net
Last edited by Guido on Wed Jan 06, 2016 12:42 pm, edited 1 time in total.
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few beginner question from the new module dev tutorial

Post by Guido »

I don't fully understand this part:

Code: Select all

public function execute()
{
if( !is_null($this->_rs) ) return;
$sql = 'SELECT SQL_CALC_FOUND_ROWS H.*
FROM '.CMS_DB_PREFIX.'mod_holidays H ORDER BY the_date DESC';
$db = \cms_utils::get_db();
$this->_rs = $db->SelectLimit($sql,$this->_limit,$this->_offset);
IF( $db->ErrorMsg() ) throw new \CmsSQLErrorException($db->sql.' -- '.$db->ErrorMsg());
$this->_totalmatchingrows = $db->GetOne('SELECT FOUND_ROWS()');
}
You assign the result set to $this->_rs, (I'm guessing the underscore is a CMSMS naming convention?), what is the actual query in which the rows are returned? Is it:

Code: Select all

$this->_totalmatchingrows = $db->GetOne('SELECT FOUND_ROWS()');
The 'FOUND_ROWS();' is a MySQL function I'm guessing, (will investigate this) but how does it know what rows to select? You'd think it wants to base it on the result set, but '$this->_rs' isn't mentioned in this call.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: A few beginner question from the new module dev tutorial

Post by Jo Morg »

Guido wrote: Is it mandatory to name the smarty template file 'edit_holidat.tpl'? Or is this just a good idea to keep thing organised?
It's jut a good practice.
Guido wrote:My second question:

I see there is a method called: 'Insert_ID()', which is a method of the database object. I looked at the api documentation, but couldn't find a database class. I'd like to know what this method does, and why it's called separately from the insertion from the rest of the record.
CMSMS is using ADOdb Lite 3rd party library for the db interactions, although it will slowly move away from it on the new versions. It should keep backwards compatibility as much as possible though. The $db object referenced there comes from that lib.
Docs on external site: http://adodblite.sourceforge.net/functions.php
Guido wrote: I read there is a 'CmsDbQueryBase' class, but I can't find that on this page: http://www.cmsmadesimple.org/APIDOC2_0/ ... s/CMS.html
It is not documented on the API (yet) but the best documentation is looking at the code itself :). Peek the file and look at the comments: it's fairly well documented.
Guido wrote:My third question:

Code: Select all

$holidays = $query->GetMatches();
I see this method used, which is a method if the 'LayoutTemplateQuery' class. It doesn't accept any arguments, am I correct to assume that this method knows from which module it's being called, so that it returns the records for this module automatically?
No, it's not a method of LayoutTemplateQuery class, but of HolidayQuery class. It seems that there is a line missing there, on the original code of the tutorial, the $query->execute(): call, which would execute the query itself, just before the $holidays = $query->GetMatches();... probably like:

Code: Select all

$query = new HolidayQuery;
$query->execute();
$holidays = $query->GetMatches();
But I'll leave it to the author to clarify that.

HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: A few beginner question from the new module dev tutorial

Post by calguy1000 »

Nope. This is correct.

Code: Select all

$query = new HolidayQuery;
$holidays = $query->GetMatches();
The GetMatches() method calls the MoveFirst() method which calls the execute() method... so all of the internals of executing the query are handled.

The CmsDbQuery base class contains a 'resultset/recordset' object, and has wrappers for many of the methods in that class. Derived classes are responsible for converting each and every returned row into an object of some type for returning to the application.

http://www.cmsmadesimple.org/APIDOC2_0/ ... yBase.html
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: A few beginner question from the new module dev tutorial

Post by Jo Morg »

calguy1000 wrote:Nope. This is correct.

Code: Select all

$query = new HolidayQuery;
$holidays = $query->GetMatches();
The GetMatches() method calls the MoveFirst() method which calls the execute() method... so all of the internals of executing the query are handled.
I suspected as much but missed that bit in the code itself when I looked. Makes sense and makes the code cleaner too :) .
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Guido
Forum Members
Forum Members
Posts: 221
Joined: Sat Aug 29, 2009 3:00 pm

Re: A few beginner question from the new module dev tutorial

Post by Guido »

Thanks, I'll study you answers as soon as I get the time.
Locked

Return to “Developers Discussion”