/** * Adds m:n records that are referenced by this record. * * Before this function may be called, $this->recordData['uid'] must be set * correctly. * * @param string $mmTable * the name of the m:n table, having the fields uid_local, uid_foreign and sorting, must not be empty * @param int[] $references * UIDs of records from the foreign table to which we should create references, may be empty * * @return int the number of created m:n records * * @throws InvalidArgumentException * @throws BadMethodCallException */ protected function createMmRecords($mmTable, array $references) { if ($mmTable == '') { throw new InvalidArgumentException('$mmTable must not be empty.', 1333292359); } if (!$this->hasUid()) { throw new BadMethodCallException('createMmRecords may only be called on objects that have a UID.', 1333292371); } if (empty($references)) { return 0; } $numberOfCreatedMmRecords = 0; $isDummyRecord = $this->getRecordPropertyBoolean('is_dummy_record'); $sorting = 1; foreach ($references as $currentRelationUid) { // We might get unsafe data here, so better be safe. $foreignUid = (int) $currentRelationUid; if ($foreignUid > 0) { $dataToInsert = array('uid_local' => $this->getUid(), 'uid_foreign' => $foreignUid, 'sorting' => $sorting, 'is_dummy_record' => $isDummyRecord); tx_oelib_db::insert($mmTable, $dataToInsert); $sorting++; $numberOfCreatedMmRecords++; } } return $numberOfCreatedMmRecords; }