Exemplo n.º 1
0
 /**
  * This functions builds an array (key\value) with entity data, to later insert on the db
  *
  * @param Entity $entity
  *
  * @return array
  */
 private function getKeyValuePropertiesByEntity(Entity $entity)
 {
     $properties = array_keys($entity->getProperties());
     $keyValueProperties = array();
     foreach ($properties as $property) {
         $method = $this->getterMethodToGetPropertyValue($property);
         $propertyValue = $entity->{$method}();
         if (is_null($propertyValue)) {
             continue;
         }
         $annotations = $this->annotation->getAnnotationsByProperty($property, $entity);
         $propertyKey = $this->getValueOfAnnotation($annotations, self::PROPERTY_ANNOTATION);
         $keyValueProperties[$propertyKey] = $propertyValue;
     }
     return $keyValueProperties;
 }
Exemplo n.º 2
0
 private function generateSql(Entity $entity)
 {
     $table = $entity->getTable();
     $primKey = $entity->getPrimaryKey();
     $sql = "CREATE TABLE `{$table}` (\n";
     $sql .= "\t`{$primKey->getName()}` {$primKey->getDbType()} NOT NULL AUTO_INCREMENT,\n";
     foreach ($entity->getProperties() as $property) {
         $sql .= "\t`{$property->getName()}` {$property->getDbType()} NOT NULL,\n";
     }
     foreach (Singleton::create("ServiceBuilder")->getOneToManyMappedProperties($entity) as $property) {
         $sql .= "\t`{$property->getMappingKey()}` {$property->getEntity()->getPrimaryKey()->getDbType()} NOT NULL,\n";
     }
     $sql .= implode(",\n", $this->generateIndexes($entity));
     $sql .= "\n);";
     return $sql;
 }
Exemplo n.º 3
0
 /**
  * Валидирует значение свойств у объекта
  *
  * @param Entity $oTarget
  *
  * @return bool|string
  */
 public function ValidateEntityPropertiesCheck($oTarget)
 {
     /**
      * Пробуем получить свойства из реквеста
      */
     $oTarget->setProperties($oTarget->getProperties() ? $oTarget->getProperties() : getRequest('property'));
     $aPropertiesValue = $oTarget->getProperties();
     $aPropertiesResult = array();
     /**
      * Получаем весь список свойств у объекта
      */
     $aPropertiesObject = $this->Property_GetPropertyItemsByFilter(array('target_type' => $oTarget->property->getPropertyTargetType()));
     $this->Property_AttachValueForProperties($aPropertiesObject, $oTarget->property->getPropertyTargetType(), $oTarget->getId());
     foreach ($aPropertiesObject as $oProperty) {
         $oValue = $oProperty->getValue();
         $sValue = isset($aPropertiesValue[$oProperty->getId()]) ? $aPropertiesValue[$oProperty->getId()] : null;
         /**
          * Валидируем значение
          */
         $oValueType = $oValue->getValueTypeObject();
         $oValueType->setValueForValidate($sValue);
         if (true === ($sRes = $oValueType->validate())) {
             $oValueType->setValue($oValueType->getValueForValidate());
             $aPropertiesResult[$oProperty->getId()] = $oProperty;
         } else {
             return 'Поле "' . $oProperty->getTitle() . '": ' . ($sRes ? $sRes : 'неверное значение');
         }
     }
     $oTarget->setPropertiesObject($aPropertiesResult);
     return true;
 }