예제 #1
0
 /**
  * init module from data
  *
  * @param array $data
  * @return $this
  */
 public function initFromData(array $data)
 {
     if (isset($data[$this->getEntityCode()])) {
         $this->addData($data[$this->getEntityCode()]);
     }
     $settings = $this->settingsFactory->create();
     if (isset($data[$settings->getEntityCode()])) {
         $settings->setData($data[$settings->getEntityCode()]);
         $this->setSettings($settings);
     }
     $entitiesByIndex = [];
     if (isset($data['entity'])) {
         $entities = $data['entity'];
         if (is_array($entities)) {
             foreach ($entities as $key => $entityData) {
                 if (!$entityData) {
                     continue;
                 }
                 /** @var \Umc\Base\Model\Core\Entity $entity */
                 $entity = $this->entityFactory->create();
                 if (isset($entityData['attributes']) && is_array($entityData['attributes'])) {
                     if (isset($entityData['attributes']['is_name'])) {
                         $isName = $entityData['attributes']['is_name'];
                         unset($entityData['attributes']['is_name']);
                         if (isset($entityData['attributes'][$isName])) {
                             $entityData['attributes'][$isName]['is_name'] = 1;
                         }
                     }
                     foreach ($entityData['attributes'] as $attrKey => $attributeData) {
                         /** @var \Umc\Base\Model\Core\Attribute $attribute */
                         $attribute = $this->attributeFactory->create();
                         $attribute->addData($attributeData);
                         $attribute->setIndex($attrKey);
                         $entity->addAttribute($attribute);
                     }
                 }
                 unset($data['attribute']);
                 $entity->addData($entityData);
                 $entity->setIndex($key);
                 $this->addEntity($entity);
                 $entitiesByIndex[$key] = $entity;
             }
         }
     }
     if (isset($data['relation'])) {
         foreach ($data['relation'] as $index => $values) {
             foreach ($values as $jndex => $type) {
                 if (isset($entitiesByIndex[$index]) && isset($entitiesByIndex[$jndex])) {
                     /** @var \Umc\Base\Model\Core\Relation $relation */
                     $relation = $this->relationFactory->create();
                     $relation->setEntities($entitiesByIndex[$index], $entitiesByIndex[$jndex], $type);
                     $this->addRelation($relation);
                 }
             }
         }
     }
     return $this;
 }
예제 #2
0
 private function __construct()
 {
     try {
         // mysql:host=127.0.0.1;dbname=coding_physics, username, password
         $this->pdoObject = new PDO('mysql:host=' . SettingsFactory::getSettingsProperty(SettingsFactory::$HOST_PATH) . ';dbname=' . SettingsFactory::getSettingsProperty(SettingsFactory::$DATABASE_PATH), SettingsFactory::getSettingsProperty(SettingsFactory::$USERNAME_PATH), SettingsFactory::getSettingsProperty(SettingsFactory::$PASSWORD_PATH));
     } catch (PDOException $e) {
         die($e->getMessage());
     }
 }
예제 #3
0
파일: Token.php 프로젝트: swish24/sqllogin
 public static function check($token)
 {
     $tokenName = SettingsFactory::getSettingsProperty('session/token_name');
     if (Session::sessionExists($tokenName) && $token === Session::sessionGet($tokenName)) {
         Session::sessionDelete($tokenName);
         return true;
     }
     return false;
 }
예제 #4
0
 public function __construct($user = null)
 {
     $this->databaseController = DatabaseController::getDatabaseInstance();
     $this->sessionName = SettingsFactory::getSettingsProperty(SettingsFactory::$SESSIONNAME_PATH);
     if (!$user) {
         // no arg provided
         if (Session::sessionExists($this->sessionName)) {
             $user = Session::sessionGet($this->sessionName);
             if ($this->find($user)) {
                 $this->isLoggedIn = true;
             }
         }
     } else {
         $this->find($user);
     }
 }