Home arrow MySQL arrow Page 8 - Data Management Made Easy Using Nennius: Advanced Data Handling

File Attachments and Component History - MySQL

Welcome to part three of this tutorial introducing application development for the Nennius engine. In this article, we will enhance the News Manager application from part two.

TABLE OF CONTENTS:
  1. Data Management Made Easy Using Nennius: Advanced Data Handling
  2. Advanced Application Configuration
  3. Expanding Our Application Menu
  4. Creating the User Comments Component
  5. Creating Component Dependencies
  6. Component Notes
  7. Help Files
  8. File Attachments
By: Brian Vaughn
Rating: starstarstarstarstar / 6
August 03, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that our Comments component is finished, let's re-visit our News component. Begin by opening the news component's descriptor file, '/descriptors/news.php'. Once again our file contains only the required information, but by making a few simple modifications our component can gain a great deal of added functionality.

For instance: what if we wanted to add functionality for admin users to attach images to news releases, so that the our front-end system can display a photo gallery? What if we wanted the system to keep records of when each release was posted and modified, and by whom? We could do that very simply by adding a few lines to the end of our existing defaults file:

# set file attachment associations for component

# NOTE: these fields allows for zero to an infinite number of file attachments

#       to be associated with component via a seperate indexing table.

$GLOBALS['g_optional_attachments_db_table']   = 'news_attachments';

$GLOBALS['g_optional_attachments_db_key']     = 'id';

$GLOBALS['g_optional_attachments_db_index']   = 'news_id';

$GLOBALS['g_optional_attachments_db_filename']       = 'filename';

# set record history table info (to record record creation & modification)

$GLOBALS['g_optional_history_db_table']              = 'news_history';

$GLOBALS['g_optional_history_db_key']         = 'id';

$GLOBALS['g_optional_history_db_index']              = 'news_id';

$GLOBALS['g_optional_history_db_user_id']     = 'user_id';

$GLOBALS['g_optional_history_db_datetime']    = 'datetime';

$GLOBALS['g_optional_history_db_description'] = 'description';

Using Hook Functions

At this point our example 'news' application is complete, but our learning exercise is not. We still have not discussed another powerful feature available to Nennius developers: hook functions.

Nennius supports a fairly robust set of p-defined hook functions, allowing developers to enhance or override default behavior without modifying the Nennius engine directly. A hook function isn't needed for this example application, but we'll create one anyway in order to familiarize ourselves with how to do so. Our hook function will simply prevent the modification or deletion of any news article older than one week.

Please begin by opening the '/components/news.php' file and adding the following information:

#-----------------------------------------------------------------

# returns TRUE / FALSE, indicating if record is locked for edit / delete

#-----------------------------------------------------------------

function is_edit_lock() {

        $f_component_details   = NULL;

       

        # retrieve necessary API objects from control class

        $db_api =& $this->nennius_control->get_db_api();

       

        # retrieve component's primary key

        $f_component_details   = $this->nennius_control->get_component_details();

        $news_id               = $f_component_details['id'];

       

        # run query to determine the date of record creation

        $db_query = "  SELECT  datetime

                       FROM    `news`

                       WHERE   id = $news_id

                         AND   datetime < NOW() - 5184000";

        $db_api->query( $db_query );

       

        # if a result has been found, then record is too old to edit

        if ( $db_api->get_num_rows() > 0 )

               return TRUE;

       

        # if no result has been found, record is editable

        else    return FALSE;

} # END is_edit_lock()

As you can see, the above function retrieves the current component's details from the Nennius Control class, runs a SQL query to determine if the record in question is older than one week, and then returns TRUE or FALSE, indicating whether the record is locked for deletion. This is a rather simple example, but it suggests the power available to Nennius developers through the use of hook functions.

Conclusion

Although this article has taken a brief look at several of the advanced features available to Nennius developers, it is in no way a comprehensive list. The main purpose of the example application we have constructed was to demonstrate a variety of common ways Nennius may be configured to handle data. You are encouraged to take the finished product, and modify it to gain a better understanding of the configuration options we have discussed. You may also want to refer to the Nennius developer manual (http://nennius.sourceforge.net/dev_manual.php) for a more detailed list of hook functions and configuration options.

A completed version of the application we have just created is available online (http://nennius.sourceforge.net/nennius/webapps/news_mod/). You may also download the source code for the application (http://nennius.sourceforge.net/nennius/webapps/news_mod.zip). If you have any questions or would like to learn more about the Nennius application engine, please visit the Nennius website (http://nennius.sourceforge.net/) or check out the Nennius forums (http://nennius.sourceforge.net/phpbb/).



 
 
>>> More MySQL Articles          >>> More By Brian Vaughn
 

blog comments powered by Disqus
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: