Page 1 of 1

How to add autounpublish to module

Posted: Mon Aug 11, 2008 10:16 pm
by Rene vK
Hi,

I have made a custom announcement module. It works great and now I would like to enhance it. One of the things I would like to add is a way to type in an end date so the module will unpublish itselves when that date is reached. But were do I start. Do I have to use a standard plugin and how will I call that function?

thx in advance, Rene

Re: How to add autounpublish to module

Posted: Thu Aug 14, 2008 4:23 pm
by tcp
Slightly offtopic, so moving to the Coding 101 board.

Re: How to add autounpublish to module

Posted: Thu Aug 14, 2008 4:29 pm
by tcp
Rene vK wrote:Hi,

I have made a custom announcement module. It works great and now I would like to enhance it. One of the things I would like to add is a way to type in an end date so the module will unpublish itselves when that date is reached. But were do I start. Do I have to use a standard plugin and how will I call that function?

thx in advance, Rene
Seems like the best place to do this would be in your module code.

Re: How to add autounpublish to module

Posted: Mon Aug 18, 2008 1:04 pm
by Rene vK
Indeed I want to insert the code in my own module but I need a lead on how to unpublish the module in mu template 'user5' location. I read thru the core plugins, modules & components to find some lead. The only two things I found were the load_module and code in com_content, which kills an article on a given date/time.
A lead to a solution would be enough, I would like to understand what is happening whem using a solution. My php is not to standard but in that way my knowledge will grow.

Re: How to add autounpublish to module

Posted: Wed Aug 20, 2008 4:42 pm
by Rene vK
all,

I did it, thx to Jisse Reitsma. He sent me the update query I had to use. undeneath you will find the code I use in my module!

Code: Select all

$einde = $params->get('einddag');
$edag = substr($einde,0,2);
$emnd = substr($einde,3,2);
$ejr = substr($einde,6,4);
$smneinde = $ejr . $emnd . $edag;
$nu = Date('d-[URL banned]');
$nudag = substr($nu,0,2);
$numnd = substr($nu,3,2);
$nujr = substr($nu,6,4);
$smnnu = $nujr . $numnd . $nudag;

$db	=& JFactory::getDBO();
$query = "UPDATE #__modules " .
		"\n SET published='0' " . 
		"\n WHERE position='user5' " .
		"\n AND module='mod_mededeling' " ;

if ($smneinde < $smnnu) {
	$db->setQuery( $query, 0);
	$db->query();}
else {	
	echo '<style type="text/css">';
	echo '
This thread can be closed.