/**
  * create and add an individual element
  *
  * @param  SchemaProperty $schema_property
  * @param  int $userId
  * @param  int $fieldId
  * @param  int $statusId
  * @param string $language
  *
  * @param bool $isGenerated
  * @return SchemaPropertyElement
  */
 public static function createElement($schema_property, $userId, $fieldId, $statusId, $language = null, $isGenerated = false)
 {
     $element = new SchemaPropertyElement();
     $element->setCreatedUserId($userId);
     $element->setUpdatedUserId($userId);
     $element->setSchemaPropertyId($schema_property->getId());
     $element->setLanguage($language);
     $element->setStatusId($statusId);
     $element->setProfilePropertyId($fieldId);
     $element->setIsGenerated($isGenerated);
     return $element;
     //self::updateElement($schema_property, $element, $userId, $field, $con, $isSchemaProperty);
 }
    /**
     * @param \SchemaPropertyElement | \SchemaPropertyElement[] $dbElement
     * @param                                                   $value
     * @param                                                   $rowStatus
     * @param \SchemaProperty                                   $property
     * @param \ProfileProperty                                  $profileProperty
     * @param                                                   $language
     *
     * @param                                                   $key
     *
     * @return bool
     * @throws \Exception
     * @throws \PropelException
     */
    private function upsertElementFromRow(
        &$dbElement,
        $value,
        $rowStatus,
        &$property,
        $profileProperty,
        $language,
        $key
    ) {
        if ( ! is_array($dbElement)) {
            if (empty( $dbElement ) and $value) {
                $dbElement = new \SchemaPropertyElement();
                $dbElement->setProfilePropertyId($profileProperty->getId());
                $dbElement->setSchemaPropertyId($property->getId());
                $dbElement->setLanguage($language);
                $dbElement->setCreatedUserId($this->userId);
                $property->addSchemaPropertyElementRelatedBySchemaPropertyId($dbElement);
            }
            if ($dbElement and $value !== $dbElement->getObject()) {
                if (empty( $value )) {
                    $dbElement->delete();
                } else {
                    $dbElement->setStatusId($rowStatus);
                    $dbElement->setObject($value);
                    $dbElement->setUpdatedUserId($this->userId);
                    $dbElement->importId = $this->importId;
                    $dbElement->setDeletedAt(null);
                }
                //$dbElement->save();
                if ($profileProperty->getIsInForm()) {
                    if (( $profileProperty->getHasLanguage() and $property->getLanguage() == $dbElement->getLanguage() ) or ! $profileProperty->getHasLanguage()) {
                        $this->setPropertyValue($value,
                                                $property,
                                                $profileProperty->getName(), ! $profileProperty->getIsObjectProp(),
                                                $key);
                        $dbElement->setIsSchemaProperty(true);
                    }
                }

                return true;
            }
        } else {
            $foundOne = false;
            foreach ($dbElement as &$oneElement) {
                if ( ! $foundOne) {
                    $foundOne = $this->upsertElementFromRow($oneElement,
                                                            $value,
                                                            $rowStatus,
                                                            $property,
                                                            $profileProperty,
                                                            $language,
                                                            $key);
                }
            }
        }

        return true;
    }