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 FunctionsAt 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. #----------------------------------------------------------------- # 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. ConclusionAlthough 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.
blog comments powered by Disqus |
|
|
|
|
|
|
|