/** * @param array $pa_options * duplicate_media */ public function duplicate($pa_options = null) { $vb_we_set_transaction = false; if (!$this->inTransaction()) { $this->setTransaction($o_t = new Transaction($this->getDb())); $vb_we_set_transaction = true; } else { $o_t = $this->getTransaction(); } if ($t_dupe = parent::duplicate($pa_options)) { $vb_duplicate_media = isset($pa_options['duplicate_media']) && $pa_options['duplicate_media']; if ($vb_duplicate_media) { // Try to link representations $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM ca_objects_x_object_representations\n\t\t\t\t\tWHERE object_id = ?\n\t\t\t\t", (int) $this->getPrimaryKey()); $va_reps = array(); while ($qr_res->nextRow()) { $va_reps[$qr_res->get('representation_id')] = $qr_res->getRow(); } $t_object_x_rep = new ca_objects_x_object_representations(); foreach ($va_reps as $vn_representation_id => $va_rep) { $t_object_x_rep->setMode(ACCESS_WRITE); $va_rep['object_id'] = $t_dupe->getPrimaryKey(); $t_object_x_rep->set($va_rep); $t_object_x_rep->insert(); if ($t_object_x_rep->numErrors()) { $this->errors = $t_object_x_rep->errors; if ($vb_we_set_transaction) { $o_t->rollback(); } return false; } } } } else { if ($vb_we_set_transaction) { $o_t->rollback(); } return false; } if ($vb_we_set_transaction) { $o_t->commit(); } return $t_dupe; }