/** * @param array $pa_options * duplicate_subitems */ 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_subitems = caGetOption('duplicate_subitems', $pa_options, false); if ($vb_duplicate_subitems) { // Try to dupe related ca_tour_stops rows $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM ca_tour_stops\n\t\t\t\t\tWHERE \n\t\t\t\t\t\ttour_id = ? AND deleted = 0\n\t\t\t\t", (int) $this->getPrimaryKey()); $va_stops = array(); while ($qr_res->nextRow()) { //$va_stops[$qr_res->get('stop_id')] = $qr_res->getRow(); $t_stop = new ca_tour_stops(); $t_stop->setTransaction($o_t); $t_stop->load($qr_res->get('stop_id')); if ($t_dupe_stop = $t_stop->duplicate($pa_options)) { $t_dupe_stop->setTransaction($o_t); $t_dupe_stop->setMode(ACCESS_WRITE); $t_dupe_stop->set('tour_id', $t_dupe->getPrimaryKey()); $t_dupe_stop->update(); if ($t_dupe_stop->numErrors()) { $this->errors = $t_dupe_stop->errors; if ($vb_we_set_transaction) { $this->removeTransaction(false); } return false; } } } } } if ($vb_we_set_transaction) { $this->removeTransaction(true); } return $t_dupe; }
/** * @param array $pa_options * duplicate_subitems */ 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_subitems = caGetOption('duplicate_subitems', $pa_options, false); if ($vb_duplicate_subitems) { // Try to dupe related ca_bundle_display_placements rows $o_db = $this->getDb(); $qr_res = $o_db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM ca_bundle_display_placements\n\t\t\t\t\tWHERE display_id = ?\n\t\t\t\t", (int) $this->getPrimaryKey()); $va_items = array(); while ($qr_res->nextRow()) { $va_items[$qr_res->get('placement_id')] = $qr_res->getRow(); } foreach ($va_items as $vn_item_id => $va_item) { $t_item = new ca_bundle_display_placements(); if ($this->inTransaction()) { $t_item->setTransaction($this->getTransaction()); } $t_item->setMode(ACCESS_WRITE); $va_item['display_id'] = $t_dupe->getPrimaryKey(); $t_item->set($va_item); $t_item->insert(); if ($t_item->numErrors()) { $this->errors = $t_item->errors; if ($vb_we_set_transaction) { $this->removeTransaction(false); } return false; } } } } if ($vb_we_set_transaction) { $this->removeTransaction(true); } return $t_dupe; }