This extension enables limiting the 'edit' action of a CActiveRecord to a certain time frame after model creation time.
Features ¶
- Two main modes of operation (provided by two different methods):
- 'All included' mode: In which when the configurable time period has passed this behavior will intervene the normal operation flow by calling the controller's render() with a predefined view file to show a customizable 'edit period expired' message. This mode requires as little as possible changes required on the controller/model classes.
- 'Just advise' mode: This mode is used to only advise the client code if edit is allowed or not. No rendering or anything is done. This allows for greater flexibility and customizing of workflow via your code.
- Configurable 'edit timeout' per model class, with a default of 60 min.
- Supports two formats for 'created on' value in the AR model - int (typical when using unix timestamps) or a string that can be used to initialize a DateTime object (supported formats: http://php.net/manual/en/datetime.formats.php).
- Customizable 'created on' attribute name per model class.
- Can use logging. This is configurable. Default = yes, will use logging.
- Customizable 'edit period expired' message per model class. This is useful if one class requires specific notification message shown to the user. This is relevant only in 'all included' mode (see above).
Installation ¶
- Unpack the contents of this package in some temporary directory.
- Copy the class in the components subdirectory (filename PcLimitEditTimePeriod.php) to /protected/components.
- Copy recursively the directory views/general to /protected/views
Usage ¶
- This extension is a behavior class (CActiveRecordBehavior) that needs to be attached to an CActiveRecord class. In the client class, alter its behaviors() method or create a new one (see instructions here and here). Example:
// For complete documentation on the parameters passed below please see class PcLimitEditTimePeriod
public function behaviors() {
return array(
// ...
'limitEditTimePeriod' => array(
'class' => 'PcLimitEditTimePeriod',
// Notice that some of the next config params are set according to values in AR class constants
//'createdOnAttrName' => 'created_at',
//'timeout' => self::EDIT_TIME_LIMIT,
//'message' => self::EDIT_TIMEOUT_MESSAGE (using Yii::t() is even better...)
//'useLogging' => true,
),
// ...
);
}
- If you wish to change the view file itself (the one that is rendered when edit timeout has expired) edit the line in the behavior class file that contains "Yii::app()->getController()->render".
- Be sure to configure timezones correctly. If your DB timezone is different from the PHP's environment's timezone you can expect problems. Make sure that all sing the same song with regard to timezones... .
- There are a couple of API methods that are your main entry points to use this behavior:
- isEditAllowed() is the method to use if 'just advise' mode is desired (see above).
- disallowEditIfExpired() is the method to use if 'all included' mode is desired (see above).
- Regarding both - please see the source code for any questions - the code is pretty documented.
great idea
wish I thought of it, I'll check it out
Not working,give me some idea
I have tried,is behavor method write i model,in which u want?I have tried like that, but it is not working correctly,no erroe found,after time ellapsed.
@abhishek2890
If I got you right (sorry - I had hard times understanding clearly what you meant... :-) , then you should use the API methods described in "Usage" section in the model controller class to check if the timeout has passed or not.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.