Jump to content

new status: period time


xavier
 Share

Recommended Posts

Hello,

I wonder if it could be possible to add a new status to the pages. Additionally to hidden, lock and unpublished, it could be helpful for some purpouses add a new option: publication period (i.e. when a page will pass from hidden to visible or when a page will dissappear, become hidden).

I hope you fill find this suggestion useful and, of course, easy to perform.

Best wishes

Xavier

Link to comment
Share on other sites

Could you explain a use case for this? Other than that, not sure if you know that there's a module that can auto-publish/unpublish at specified dates. There's also a published date property for pages. I don't know if those cover your needs, but good to know. 

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

...for such things there is no need for a whole fieldtype since you can make it in plain PHP.

Usecase that i have was to depublish entries after a fix timeperiod that a user could set to his entry (1 week, 3 weeks and so on)

Just as an very simple example from a .php file for a cronjob:

//get all items to check
foreach ($items as $e) {
/// FIRST STEP - send mail 1 week before the entry is being unpublished!
//set the calculate_type to the e_delay option value from the entry option field...
		$calculate_type = $e->e_delay;
		//calculate the to add time to the timestamp
		switch ($calculate_type) {
			case '1':
			$time_add = ' +3 week';
			break;
			case "2":
			$time_add = ' +7 week';
			break;
			case '3':
			$time_add = ' +11 week';
			break;
			default:
			$time_add = '1';
		}

		//timestamp to check is the modified date + $time_add
		$check_time = strtotime($time_add, $e->modified);

		//check if the current timestamp is greater than the $check_time == 1 week before e_delay is reached!
		if ($check_time >= $curtime) {

			//do something

		} else {

			//do something else
        }
}

the time peroids that you need could be a simple option field or a pagefield or even an integer field.

Best regards mr-fan

  • Like 2
Link to comment
Share on other sites

1 hour ago, mr-fan said:

it in plain PHP.

@mr-fan Thank you for the code. The problem is my low experience and that the template I am using contains Angular. At this moment I can't redo the code Angular->php

2 hours ago, kongondo said:

there's a module

@kongondoThank you very much for your suggestion. I can assure you that I have been searching a lot within the forum and the modules without success. Obviously, I searched  with the wrong key words.

2 hours ago, kongondo said:

There's also a published date property for pages

I also haven't found this, sorry.

 

However, I have installed that module SchedulePages and seems to work very fine. Thanks a lot, it is what I needed, a simple way to switch on the pages automatically.

Thanks again! !!

Best wishes

  • Like 1
Link to comment
Share on other sites

@xavier. Glad it worked. Since a couple of ProcessWire versions back (I can't remember how far back, but since 2.7 at least), pages have a property 'published'. So:

echo $page->published;// outputs the date when this page was published.

Oh, am not sure you've been properly welcomed. If not, welcome to the forums :).

Edited by kongondo
  • Like 3
Link to comment
Share on other sites

Publishing/unpublishing via a cron job is probably the way to go if you have many different templates that you want to limit the availability of based on date/time.

But where I only have one or two templates that I need to control this way (e.g. news items) I just code the limits directly into the template files rather than publish/unpublish. So in the news item template I check if the current date is within the start/end dates and throw a 404 if not. And in news listings I include the date check in the $pages->find() selector.

This approach works well if you want fine-grained control of page availability (e.g. make pages available/unavailable down to the minute or second) and don't want a cron job running that frequently.

Link to comment
Share on other sites

17 hours ago, kongondo said:

welcome to the forums :).

Thanks to all of you for warm and clever messages, it is a pleasure. ^-^

 

5 hours ago, Robin S said:

I just code the limits directly into the template files rather than publish/unpublish.

Hello @Robin S I appreciate your suggestions, however my knowledge in programming is not enough to rewrite much code. I must use simple ways (simplified and created by others) to solve my problems although, probably, less efficient. Thank you  very much ^-^

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...