Example #1
0
 /**
  * Adds the new OrmClass object to the domain
  *
  * @throws OrmModelIntegrityException if the сдфыы with the same name already added
  *
  * @return OrmDomain
  */
 function addClass(OrmClass $class)
 {
     $name = $class->getName();
     if (isset($this->classes[$name])) {
         throw new OrmModelIntegrityException("Class {$class->getName()} already defined");
     }
     $this->classes[$name] = $class;
     return $this;
 }
Example #2
0
 function controller_orm($args)
 {
     /*
         if (!User::authorized("orm"))
           throw new Exception("not allowed");
     */
     $ret = $this->GetComponentResponse("./orm.tpl");
     /*
     $user = User::singleton();
     if (!($user->isLoggedIn() && $user->HasRole("ORM"))) // display the access violation message
       $ret->SetTemplate("access_violation.tpl");
     */
     if (!empty($args["ormaction"]) && !empty($args["model"])) {
         $ret["model"] = $args["model"];
         $ret["ormcfg"] = new OrmModel($args["model"]);
         if ($args["ormaction"] == "create" && !empty($args["classname"])) {
             $ormclass = new OrmClass($ret["ormcfg"]->classes->{$args["classname"]});
             //$sql = $ormclass->getCreateSql();
             $sqlkey = "db." . $ormclass->table . ".create:nocache";
             /*
                     print_pre($ormclass->table);
                     print_pre($ormclass->getColumns());
             */
             $outlet = Outlet::getInstance();
             $pdo = $outlet->getConnection()->getPDO();
             if ($pdo) {
                 $ret["sql"] = $ormclass->getCreateSQL();
                 try {
                     $pdo->query($ret["sql"]);
                     $ret["success"] = "Table '{$ormclass->table}' created successfully";
                 } catch (Exception $e) {
                     $ret["error"] = $e->getMessage();
                 }
             }
             /*
             $data = DataManager::singleton();
             $data->QueryCreate($sqlkey, $ormclass->table, $ormclass->getColumns($sql));
             */
         }
     }
     return $ret;
 }
 /**
  * @return void
  */
 private function importClass()
 {
     $this->dbTable = new DBTable($this->ormClass->getTable());
     if ($this->ormIdentifier = $this->ormClass->getIdentifier()) {
         $this->ormProperty = $this->ormIdentifier;
         $this->importProperty();
         $this->ormProperty = null;
     }
     $this->dbSchema->addTable($this->dbTable);
     $this->dbTable = null;
 }
Example #4
0
 /**
  * @return void
  */
 private function generateContainerFiles(OrmClass $class)
 {
     foreach ($class->getProperties() as $property) {
         $type = $property->getType();
         if ($type instanceof OneToManyContainerPropertyType) {
             $this->buildClass(new OrmOneToManyAutoClassCodeConstructor($class, $property));
             $this->buildClass(new OrmOneToManyClassCodeConstructor($class, $property));
         } else {
             if ($type instanceof ManyToManyContainerPropertyType) {
                 $this->buildClass(new OrmManyToManyAutoClassCodeConstructor($class, $property));
                 $this->buildClass(new OrmManyToManyClassCodeConstructor($class, $property));
             }
         }
     }
 }
 /**
  * @return OrmProperty
  */
 private function generateContainer(OrmClass $type, SimpleXMLElement $xmlContainer)
 {
     $referredTypeName = (string) $xmlContainer['type'];
     if (!($referredType = $this->importEntity($referredTypeName))) {
         if (TypeUtils::isExists($referredTypeName) && TypeUtils::isInherits($referredTypeName, 'IDaoRelated')) {
             $referredType = call_user_func(array($referredTypeName, 'orm'));
         } else {
             $referrer = $type->getName() . '.' . (string) $xmlContainer['name'];
             throw new OrmModelIntegrityException($referrer . ' refers to unknown entity ' . $referredTypeName);
         }
     }
     try {
         // one-to-many
         $referredProperty = $referredType->getProperty((string) $xmlContainer['refs']);
         $propertyType = new OneToManyContainerPropertyType($type, $referredType, $referredProperty);
     } catch (OrmModelIntegrityException $e) {
         // many to many
         try {
             $proxy = $this->ormDomain->getClass((string) $xmlContainer['refs']);
         } catch (OrmModelIntegrityException $e) {
             $proxy = new OrmClass();
             $proxy->setHasDao(true);
             $proxy->setName((string) $xmlContainer['refs']);
             $this->ormDomain->addClass($proxy);
         }
         $propName = strtolower($type->getEntityName());
         try {
             $mtmType = new AssociationPropertyType($type, AssociationMultiplicity::exactlyOne(), AssociationBreakAction::cascade());
             $type_property = new OrmProperty($propName, $this->makeFields($type->getTable(), $mtmType), $mtmType, OrmPropertyVisibility::full(), AssociationMultiplicity::exactlyOne());
             $proxy->addProperty($type_property);
         } catch (OrmModelIntegrityException $e) {
             $type_property = $proxy->getProperty($propName);
         }
         $propName = strtolower($referredType->getEntityName());
         try {
             $mtmType = new AssociationPropertyType($referredType, AssociationMultiplicity::exactlyOne(), AssociationBreakAction::cascade());
             $referredType_property = new OrmProperty($propName, $this->makeFields($referredType->getTable(), $mtmType), $mtmType, OrmPropertyVisibility::full(), AssociationMultiplicity::exactlyOne());
             $proxy->addProperty($referredType_property);
         } catch (OrmModelIntegrityException $e) {
             $referredType_property = $proxy->getProperty($propName);
         }
         $propertyType = new ManyToManyContainerPropertyType($proxy, $type_property, $referredType_property);
     }
     $property = new OrmProperty((string) $xmlContainer['name'], array(), $propertyType, new OrmPropertyVisibility(OrmPropertyVisibility::READONLY), AssociationMultiplicity::zeroOrOne(), false);
     if (isset($xmlContainer['db-columns'])) {
         $property->setDBColumnNames($this->getFields($xmlContainer['db-columns']));
     }
     return $property;
 }