public function __construct($pn_id = null)
 {
     parent::__construct($pn_id);
     # call superclass constructor
 }
 function __construct($pn_id = null)
 {
     parent::__construct($pn_id);
 }
 public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null)
 {
     list($vs_target_table, $vs_target_key) = $this->_getTarget();
     $vs_rel_table = $this->tableName();
     $t_target = $this->getAppDatamodel()->getInstanceByTableName($vs_target_table);
     $vn_target_id = $this->get($vs_target_key);
     if (!$t_target->load($vn_target_id)) {
         // invalid object
         $this->postError(720, _t("Related %1 does not exist", $t_target->getProperty('NAME_SINGULAR')), "BaseRepresentationRelationship->delete()");
         return false;
     }
     $vb_we_set_transaction = false;
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
     } else {
         $o_trans = new Transaction();
         $this->setTransaction($o_trans);
         $vb_we_set_transaction = true;
     }
     $o_db = $o_trans->getDb();
     if ($vb_rc = parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list)) {
         if ($this->get('is_primary')) {
             // make some other row primary
             $qr_res = $o_db->query("\n\t\t\t\t\t\tSELECT oxor.relation_id\n\t\t\t\t\t\tFROM {$vs_rel_table} oxor\n\t\t\t\t\t\tINNER JOIN ca_object_representations AS o_r ON o_r.representation_id = oxor.representation_id\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\toxor.{$vs_target_key} = ? AND oxor.is_primary = 0 AND o_r.deleted = 0 AND oxor.relation_id <> ?\n\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\toxor.rank, oxor.relation_id\n\t\t\t\t\t", (int) $vn_target_id, (int) $this->getPrimaryKey());
             if ($qr_res->nextRow()) {
                 // nope - force this one to be primary
                 $t_rep_link = $this->getAppDatamodel()->getInstanceByTableName($vs_rel_table);
                 $t_rep_link->setTransaction($o_trans);
                 if ($t_rep_link->load($qr_res->get('relation_id'))) {
                     $t_rep_link->setMode(ACCESS_WRITE);
                     $t_rep_link->set('is_primary', 1);
                     $t_rep_link->update();
                     if ($t_rep_link->numErrors()) {
                         $this->postError(2700, _t('Could not update primary flag for representation: %1', join('; ', $t_rep_link->getErrors())), 'BaseRepresentationRelationship->delete()');
                         if ($vb_we_set_transaction) {
                             $o_trans->rollbackTransaction();
                         }
                         return false;
                     }
                 } else {
                     $this->postError(2700, _t('Could not load %1-representation link', $t_target->getProperty('NAME_SINGULAR')), 'BaseRepresentationRelationship->delete()');
                     if ($vb_we_set_transaction) {
                         $o_trans->rollbackTransaction();
                     }
                     return false;
                 }
             }
         }
         if ($vb_we_set_transaction) {
             $o_trans->commitTransaction();
         }
     } else {
         if ($vb_we_set_transaction) {
             $o_trans->rollbackTransaction();
         }
     }
     return $vb_rc;
 }
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
     $this->BUNDLES['ca_object_representation_chooser'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Media representation chooser'));
 }
 /**
  *
  */
 public function update($pa_options = null)
 {
     if (!$this->get('effective_date', array('getDirectDate' => true))) {
         $this->set('effective_date', $this->_getMovementDate());
         $this->set('source_info', $this->_getStorageLocationInfo());
     }
     return parent::update($pa_options);
 }