Esempio n. 1
0
 /**
  * The constructor.
  *
  * @throws Alpha\Exception\FailedLookupCreateException
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @since 1.0
  */
 public function __construct($leftClassName, $rightClassName)
 {
     self::$logger = new Logger('RelationLookup');
     self::$logger->debug('>>__construct(leftClassName=[' . $leftClassName . '], rightClassName=[' . $rightClassName . '])');
     // ensure to call the parent constructor
     parent::__construct();
     if (empty($leftClassName) || empty($rightClassName)) {
         throw new IllegalArguementException('Cannot create RelationLookup object without providing the left and right class names!');
     }
     $this->leftClassName = $leftClassName;
     $this->rightClassName = $rightClassName;
     $this->leftID = new Integer();
     $this->rightID = new Integer();
     $this->markTransient('leftClassName');
     $this->markTransient('rightClassName');
     $this->markTransient('helper');
     $this->markTransient('TABLE_NAME');
     // add a unique composite key to these fields
     $this->markUnique('leftID', 'rightID');
     // make sure the lookup table exists
     if (!$this->checkTableExists() && ActiveRecord::isInstalled()) {
         // first make sure that the two BO tables exist before relating them with a lookup table
         if (ActiveRecord::checkBOTableExists($leftClassName) && ActiveRecord::checkBOTableExists($rightClassName)) {
             $this->makeTable();
         } else {
             throw new FailedLookupCreateException('Error trying to create a lookup table [' . $this->getTableName() . '], as tables for BOs [' . $leftClassName . '] or [' . $rightClassName . '] don\'t exist!');
         }
     }
     self::$logger->debug('<<__construct');
 }