Exemple #1
0
 /**
  * Builds a condition for filtering records by the configured match field,
  * e.g. MM_match_fields, foreign_match_fields or foreign_table_field.
  *
  * @param ExpressionBuilder $exprBuilder
  * @param ColumnMap $columnMap The column man for which the condition should be build.
  * @param string $childTableAlias The alias of the child record table used in the query.
  * @param string $parentTable The real name of the parent table (used for building the foreign_table_field condition).
  * @return string The match field conditions or an empty string.
  */
 protected function getAdditionalMatchFieldsStatement($exprBuilder, $columnMap, $childTableAlias, $parentTable = null)
 {
     $additionalWhereForMatchFields = [];
     $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
     if (is_array($relationTableMatchFields) && !empty($relationTableMatchFields)) {
         foreach ($relationTableMatchFields as $fieldName => $value) {
             $additionalWhereForMatchFields[] = $exprBuilder->eq($childTableAlias . '.' . $fieldName, $this->queryBuilder->createNamedParameter($value));
         }
     }
     if (isset($parentTable)) {
         $parentTableFieldName = $columnMap->getParentTableFieldName();
         if (!empty($parentTableFieldName)) {
             $additionalWhereForMatchFields[] = $exprBuilder->eq($childTableAlias . '.' . $parentTableFieldName, $this->queryBuilder->createNamedParameter($parentTable));
         }
     }
     if (!empty($additionalWhereForMatchFields)) {
         return $exprBuilder->andX(...$additionalWhereForMatchFields);
     } else {
         return '';
     }
 }
 /**
  * @test
  */
 public function getPlainValueReturnsCorrectDateTimeFormat()
 {
     $subject = new DataMapper();
     $columnMap = new ColumnMap('column_name', 'propertyName');
     $columnMap->setDateTimeStorageFormat('datetime');
     $datetimeAsString = '2013-04-15 09:30:00';
     $input = new \DateTime($datetimeAsString);
     $this->assertEquals('2013-04-15 09:30:00', $subject->getPlainValue($input, $columnMap));
     $columnMap->setDateTimeStorageFormat('date');
     $this->assertEquals('2013-04-15', $subject->getPlainValue($input, $columnMap));
 }
 /**
  * Builds a condition for filtering records by the configured match field,
  * e.g. MM_match_fields, foreign_match_fields or foreign_table_field.
  *
  * @param ColumnMap $columnMap The column man for which the condition should be build.
  * @param string $childTableName The real name of the child record table.
  * @param string $childTableAlias The alias of the child record table used in the query.
  * @param string $parentTable The real name of the parent table (used for building the foreign_table_field condition).
  * @return string The match field conditions or an empty string.
  */
 protected function getAdditionalMatchFieldsStatement($columnMap, $childTableName, $childTableAlias, $parentTable = null)
 {
     $additionalWhereForMatchFields = '';
     $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
     if (is_array($relationTableMatchFields) && !empty($relationTableMatchFields)) {
         $additionalWhere = array();
         foreach ($relationTableMatchFields as $fieldName => $value) {
             $additionalWhere[] = $childTableAlias . '.' . $fieldName . ' = ' . $this->databaseHandle->fullQuoteStr($value, $childTableName);
         }
         $additionalWhereForMatchFields .= ' AND ' . implode(' AND ', $additionalWhere);
     }
     if (isset($parentTable)) {
         $parentTableFieldName = $columnMap->getParentTableFieldName();
         if (isset($parentTableFieldName) && $parentTableFieldName !== '') {
             $additionalWhereForMatchFields .= ' AND ' . $childTableAlias . '.' . $parentTableFieldName . ' = ' . $this->databaseHandle->fullQuoteStr($parentTable, $childTableAlias);
         }
     }
     return $additionalWhereForMatchFields;
 }