Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 1.40 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. abstract class Example_Editable extends Example_PermissionableRecord
  2. {
  3.     //Require these for every Br_Editable class.
  4.     public $id;
  5.    
  6.     public $date_created;
  7.    
  8.     public $date_edited;
  9.    
  10.     public $owner_id;
  11.    
  12.     public $creator_id;
  13.    
  14.     function __construct($options = array())
  15.     {
  16.         //Check to see if we are editing this bro.
  17.         if (isset($options['model']) && get_called_class() != $options['model']) {
  18.             //We are not viewing this model, return.
  19.             return;
  20.         }
  21.        
  22.         //An Id was not passed, so we are just making a new one.
  23.         if (!isset($options['id'])) {
  24.             return;
  25.         }
  26.        
  27.         if (!$class = $this->getByID($options['id'])) {
  28.             throw new Exception("Could not find that", 400);
  29.         }
  30.        
  31.         $this->synchronizeWithArray($class->toArray());
  32.        
  33.         if (!Example_ACL::isAllowed(Br_Controller::getAccount(), $this, 'view')) {
  34.             throw new Exception("You do not have permission to view this object", 401);
  35.         }
  36.        
  37.         if (isset($options['model']) && substr($options['model'], -5) != '_Edit') {
  38.             //We are not viewing the Edit model for this class, return.
  39.             return;
  40.         }
  41.  
  42.         if (!Example_ACL::isAllowed(Br_Controller::getAccount(), $this, 'edit')) {
  43.             throw new Exception("You do not have permission to edit this.", 401);
  44.         }
  45.     }
  46. }