      1: <?php
      2:
      3: /**
      4:  *
      5:  * The group level rights object for the application permissions
      6:  *
      7:  * @package alpha::model
      8:  * @since 1.0
      9:  * @author John Collins <dev@alphaframework.org>
     10:  * @version $Id: RightsObject.inc 1617 2012-12-19 15:05:31Z alphadevx $
     11:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     12:  * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).
     13:  * All rights reserved.
     14:  *
     15:  * <pre>
     16:  * Redistribution and use in source and binary forms, with or
     17:  * without modification, are permitted provided that the
     18:  * following conditions are met:
     19:  *
     20:  * * Redistributions of source code must retain the above
     21:  *   copyright notice, this list of conditions and the
     22:  *   following disclaimer.
     23:  * * Redistributions in binary form must reproduce the above
     24:  *   copyright notice, this list of conditions and the
     25:  *   following disclaimer in the documentation and/or other
     26:  *   materials provided with the distribution.
     27:  * * Neither the name of the Alpha Framework nor the names
     28:  *   of its contributors may be used to endorse or promote
     29:  *   products derived from this software without specific
     30:  *   prior written permission.
     31:  *
     32:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     33:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     34:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     35:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     36:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     37:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     38:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     39:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     40:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     42:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     43:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     44:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     45:  * </pre>
     46:  *
     47:  */
     48: class RightsObject extends AlphaDAO {
     49:     /**
     50:      * The name of the rights
     51:      *
     52:      * @var String
     53:      * @since 1.0
     54:      */
     55:     protected $name;
     56:
     57:     /**
     58:      * A Relation containing all of the PersonObjects that have these rights
     59:      *
     60:      * @var Relation
     61:      * @since 1.0
     62:      */
     63:     protected $members;
     64:
     65:     /**
     66:      * An array of data display labels for the class properties
     67:      *
     68:      * @var array
     69:      * @since 1.0
     70:      */
     71:     protected $dataLabels = array("OID"=>"Rights Group ID#","name"=>"Rights Group Name","members"=>"Rights Group Members");
     72:
     73:     /**
     74:      * The name of the database table for the class
     75:      *
     76:      * @var string
     77:      * @since 1.0
     78:      */
     79:     const TABLE_NAME = 'Rights';
     80:
     81:     /**
     82:      * Trace logger
     83:      *
     84:      * @var Logger
     85:      * @since 1.1
     86:      */
     87:     private static $logger = null;
     88:
     89:     /**
     90:      * Constructor
     91:      *
     92:      * @since 1.0
     93:      */
     94:     public function __construct() {
     95:         self::$logger = new Logger('RightsObject');
     96:
     97:         // ensure to call the parent constructor
     98:         parent::__construct();
     99:         $this->name = new String();
    100:
    101:         // add unique key to name field
    102:         $this->markUnique('name');
    103:
    104:         $this->members = new Relation();
    105:         $this->markTransient('members');
    106:         $this->setupRels();
    107:     }
    108:
    109:     /**
    110:      * Get the group members Relation
    111:      *
    112:      * @return Relation
    113:      * @since 1.0
    114:      */
    115:     public function getMembers() {
    116:         return $this->members;
    117:     }
    118:
    119:     /**
    120:      * Set up the transient attributes for the rights group after it has loaded
    121:      *
    122:      * @since 1.0
    123:      */
    124:     protected function after_load_callback() {
    125:         $this->setupRels();
    126:     }
    127:
    128:     /**
    129:      * Set up the transient attributes for the rights group after it has been created
    130:      *
    131:      * @since 1.2.1
    132:      */
    133:     protected function after_save_callback() {
    134:         $this->setupRels();
    135:     }
    136:
    137:     /**
    138:      * Set up the transient attributes for the rights group after it has loaded
    139:      *
    140:      * @since 1.0
    141:      */
    142:     protected function after_loadByAttribute_callback() {
    143:         $this->setupRels();
    144:     }
    145:
    146:     /**
    147:      * Sets up the Relation definitions on this BO
    148:      *
    149:      * @since 1.0
    150:      */
    151:     private function setupRels() {
    152:         // set up MANY-TO-MANY relation person2rights
    153:         $this->members->setRelatedClass('PersonObject', 'left');
    154:         $this->members->setRelatedClassDisplayField('email', 'left');
    155:         $this->members->setRelatedClass('RightsObject', 'right');
    156:         $this->members->setRelatedClassDisplayField('name', 'right');
    157:         $this->members->setRelationType('MANY-TO-MANY');
    158:         $this->members->setValue($this->getOID());
    159:     }
    160: }
    161:
    162: ?>