Example #1
0
 /**
  * Creates records in the intermediate table of m:n relations for a given
  * model.
  *
  * @param Tx_Oelib_Model $model the model to create the records in the
  *                              intermediate table of m:n relations for
  *
  * @return void
  */
 private function createManyToManyRelationIntermediateRecords(Tx_Oelib_Model $model)
 {
     $data = $model->getData();
     foreach (array_keys($this->relations) as $key) {
         if ($this->isManyToManyRelationConfigured($key) && $data[$key] instanceof Tx_Oelib_List) {
             $sorting = 0;
             $relationConfiguration = $this->getRelationConfigurationFromTca($key);
             $mnTable = $relationConfiguration['MM'];
             /** @var Tx_Oelib_Model $relatedModel */
             foreach ($data[$key] as $relatedModel) {
                 if (isset($relationConfiguration['MM_opposite_field'])) {
                     $uidLocal = $relatedModel->getUid();
                     $uidForeign = $model->getUid();
                 } else {
                     $uidLocal = $model->getUid();
                     $uidForeign = $relatedModel->getUid();
                 }
                 Tx_Oelib_Db::insert($mnTable, $this->getManyToManyRelationIntermediateRecordData($mnTable, $uidLocal, $uidForeign, $sorting));
                 $sorting++;
             }
         }
     }
 }
Example #2
0
 /**
  * @test
  */
 public function existsExactlyOneRecordIgnoresNonDummyRecords()
 {
     Tx_Oelib_Db::insert('tx_oelib_test', array('title' => 'foo'));
     $testResult = $this->subject->existsExactlyOneRecord('tx_oelib_test', 'title = "foo"');
     Tx_Oelib_Db::delete('tx_oelib_test', 'title = "foo"');
     // We need to do this manually to not confuse the auto_increment counter
     // of the testing framework.
     $this->subject->resetAutoIncrement('tx_oelib_test');
     self::assertFalse($testResult);
 }
Example #3
0
 /**
  * @test
  */
 public function insertForTableWithoutUidReturnsZero()
 {
     $this->testingFramework->markTableAsDirty('tx_oelib_test_article_mm');
     self::assertSame(0, Tx_Oelib_Db::insert('tx_oelib_test_article_mm', array('is_dummy_record' => 1)));
 }
Example #4
0
 /**
  * Creates a relation between two records on different tables (so called
  * m:n relation).
  *
  * @param string $table name of the m:n table to which the record should be added, must not be empty
  * @param int $uidLocal UID of the local table, must be > 0
  * @param int $uidForeign UID of the foreign table, must be > 0
  * @param int $sorting
  *        sorting value of the relation, the default value is 0, which enables automatic sorting,
  *        a value >= 0 overwrites the automatic sorting
  *
  * @return void
  *
  * @throws InvalidArgumentException
  */
 public function createRelation($table, $uidLocal, $uidForeign, $sorting = 0)
 {
     if (!$this->isNoneSystemTableNameAllowed($table)) {
         throw new InvalidArgumentException('The table name "' . $table . '" is not allowed.', 1331490358);
     }
     // Checks that the two given UIDs are valid.
     if ((int) $uidLocal <= 0) {
         throw new InvalidArgumentException('$uidLocal must be an integer > 0, but actually is "' . $uidLocal . '"', 1331490370);
     }
     if ((int) $uidForeign <= 0) {
         throw new InvalidArgumentException('$uidForeign must be an integer > 0, but actually is "' . $uidForeign . '"', 1331490378);
     }
     $this->markTableAsDirty($table);
     $recordData = array('uid_local' => $uidLocal, 'uid_foreign' => $uidForeign, 'sorting' => $sorting > 0 ? $sorting : $this->getRelationSorting($table, $uidLocal), $this->getDummyColumnName($table) => 1);
     Tx_Oelib_Db::insert($table, $recordData);
 }