Fork me on GitHub

Impressions on updating a module  Bottom

  • I have just finished updating the book module for zikula from PostNuke 0.76 and I just want to say I am impressed. Kudos to the development team for creating some very powerful classes for handling data retrieval and and data base interaction. Here is what was required to update my module for zikula

    DBUtil
    This is an excellent abstraction, but is very different to what I was doing before. In my postnuke version, mysql calls were built in the API files and then used to access the database. Obviously this tied my module to MySQL -- not good. Some little things I had to learn were....
    Changing table structure
    To utilize DBUtil effectively you have to be consistent in your naming of arguments in your API functions and the names that you place in the DBUtil calls. This caught me a few times (using content in the $args parameter, when contents was used in the table).
    Understand the DBUtil calls
    Read through DBUtil and make sure you know what is going on. When grabbing information, an ID or a where statement is required and make sure you're using the right function call. When you are doing an update to a table, you have to pass in the arguments that you want to update in an args array and the keys have to match the table structure you are trying to update. A really cool feature of DBUtil is that it will only update the values that you provide keys for.
    Back up your DB when you are converting
    Yeah I know its obvious, but I will still say it. When you are testing your code, DBUtil will happily wipe out your whole database table if you code just right. Make sure you have a back up to restore it.
    You save 100s of lines of code
    DBUtil makes it much simpler to write the database code, since it handles the dirty work. My API files shrunk big time.
    Enable Search
    To get search to work with your module takes a bit of work, again to smooth out the table structure and re-learn how zikula does search vs. PostNuke. The zikula way is much better. I found looking at the search file for the News and FAQ modules very useful for learning.
    Error messages
    When bugs appear, the error messages that get generated make much more sense and will often point to the actual problem in your code. I especially found it useful that a stack trace will be printed when there is an error in a database call.
    Its easier
    Once you start to get your head around the new style, it is much easier to write robust code and zikula take much of the housekeeping away from you. You can then concentrate on your cool features, and that is the point.
    The learning curve is steep
    My one complaint is that the learning curve for writing this stuff is very steep. I do wish there had been a bit more in tutorials and I commend the efforts the developers have put into this. I did find this section of the Wiki useful.
    http://community.zik…g-DeveloperDocs.htm

    Lots of goodies, especially the module development stuff.

    However, I think a tutorial written by someone outside the development team would be useful. Sometimes being too close to the code causes the writer to not explain things that need explaining. And yes I will volunteer to do this, just point me to where I could place the tutorial. Looks like adding/updating pages to the above link might be useful.

    Overall I commend the team, you have done a wonderful job creating a powerful and useful platform.



    edited by: Paustian, Mar 24, 2009 - 08:38 PM
  • Quote

    However, I think a tutorial written by someone outside the development team would be useful. Sometimes being too close to the code causes the writer to not explain things that need explaining. And yes I will volunteer to do this, just point me to where I could place the tutorial. Looks like adding/updating pages to the above link might be useful.

    http://community.zikula.org/Wiki-tag-DeveloperDocs.htm
    Edit, change, create what you need.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • Another useful tool is Eclipse PDT
    and the very helpful tooltips with the Classes:: available methods and parameter lists. Once you memorize them you write code very fast, and without errors because the tooltip icon_razz

    Add more Wiki pages complementing the DeveloperDocs if you want
    or ask for Help using the Wiki, it's very powerful too
    its rewrite was very cool and the code reduced a lot too icon_smile

    Zikula rocks icon_cool

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Quote

    You save 100s of lines of code
    DBUtil makes it much simpler to write the database code, since it handles the dirty work. My API files shrunk big time.

    Thank you for your (positive) remarks about the stuff that we have built. I would like to point out that (as you said) using DBUtil will save you lots of code. However, this is only the first step. The second step is to use the PNObject/PNObjectArray object model. If done correctly this allows you to use a single view/edit/delete function to handle all your object. On a system with 3 objects this doesn't save you all that much, but on a more complex system (for example, zWebstore has 160 class files) this results in huge code savings. Some examples:

    To create a class which knows how to select/insert/update/delete itself:

    Code

    class PNProduct extends PNObject
    {
        function PNProduct ($init=null, $key=null, $field=null)
        {
            $this->PNObject();

            $this->_objType          = 'zws_product';
            $this->_objColumnPrefix  = 'wpr';
            $this->_objPath          = 'product';

            $this->_init ($init, $key, $field);
        }
    }


    Then in your pnuser (for exmaple, for the detail function), you can do the following:

    Code

    function MyModule_user_detail ()
    {
        $ot  = FormUtil::getPassedValue ('ot', 'product');
        $id  = (int)FormUtil::getPassedValue ('id', 0);
        $url = pnModURL('zWebstore', 'user', 'view');

        if (!$ot) {
            return LogUtil::registerError ('Invalid [ot] parameter received', null, $url);
        }

        if (!$id) {
            return LogUtil::registerError ('Invalid [id] parameter received', null, $url);
        }

        if (!SecurityUtil::checkPermission("MyModule::$ot", "$id::", ACCESS_OVERVIEW)) {
            return LogUtil::registerError (_PN_TEXT_NOAUTH_OVERVIEW . " [MyModule::$ot][$id::]", 403, $url);
        }

        if (!($class = Loader::loadClassFromModule ('zWebstore', $ot))) {
            return LogUtil::registerError ("Unable to load class [$ot]", null, $url);
        }

        $pnRender = pnRender::getInstance('zWebstore', false);
        $object = new $class ();
        $data   = $object->get ($id);

        $pnRender->assign ('ot', $ot);
        $pnRender->assign ('object', $data);

        $tpl = 'zwebstore_detail_' . $ot . '.html';
        return $pnRender->fetch($tpl);
    }


    If you have implemented logic in PNObject/PNObjectArray classes, you can use the same type of class loading in the code which handles your form submits to save your objects through a generic layer of code. The additional benefit of this approach is that it forces template naming consistency and that all your logic is nicely separated into distinct object files and thus easier to find and maintain.

    Hack on ...

    Greetings
    R
  • Thanks for the nice words!

    It would be great if you could help improving the Wiki and add your learnings to it.

    --
    best regards from Kiel, sailing city

    Steffen Voss

    Member of the Zikula Steering Committee
    Read The Zikulan's Blog "If you want people to RTFM, make a better FM!"
  • 0 users

This list is based on users active over the last 60 minutes.