コード例 #1
0
 /**
  * Performs two-step delete of an existing record. The first step is a confirmation dialog, followed by actual deletion upon user confirmation
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function Delete($pa_options = null)
 {
     list($vn_subject_id, $t_subject, $t_ui) = $this->_initView($pa_options);
     if (!$vn_subject_id) {
         return;
     }
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     if (!($vs_type_name = $t_subject->getTypeName())) {
         $vs_type_name = $t_subject->getProperty('NAME_SINGULAR');
     }
     //
     // Does user have access to row?
     //
     if ($t_subject->getAppConfig()->get('perform_item_level_access_checking')) {
         if ($t_subject->checkACLAccessForUser($this->request->user) < __CA_ACL_EDIT_DELETE_ACCESS__) {
             $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2580?r=' . urlencode($this->request->getFullUrlPath()));
             return;
         }
     }
     // get parent_id, if it exists, prior to deleting so we can
     // set the browse_last_id parameter to something sensible
     $vn_parent_id = null;
     if ($vs_parent_fld = $t_subject->getProperty('HIERARCHY_PARENT_ID_FLD')) {
         $vn_parent_id = $t_subject->get($vs_parent_fld);
     }
     if ($vn_subject_id && !$t_subject->getPrimaryKey()) {
         $this->notification->addNotification(_t("%1 does not exist", $vs_type_name), __NOTIFICATION_TYPE_ERROR__);
         return;
     }
     // Don't allow deletion of roots in simple mono-hierarchies... that's bad.
     if (!$vn_parent_id && in_array($t_subject->getProperty('HIERARCHY_TYPE'), array(__CA_HIER_TYPE_SIMPLE_MONO__, __CA_HIER_TYPE_MULTI_MONO__))) {
         $this->notification->addNotification(_t("Cannot delete root of hierarchy"), __NOTIFICATION_TYPE_ERROR__);
         return;
     }
     if ($vb_confirm = $this->request->getParameter('confirm', pInteger) == 1 ? true : false) {
         $vb_we_set_transaction = false;
         if (!$t_subject->inTransaction()) {
             $o_t = new Transaction();
             $t_subject->setTransaction($o_t);
             $vb_we_set_transaction = true;
         }
         // Do we need to move relationships?
         if (($vn_remap_id = $this->request->getParameter('remapToID', pInteger)) && $this->request->getParameter('referenceHandling', pString) == 'remap') {
             switch ($t_subject->tableName()) {
                 case 'ca_relationship_types':
                     if ($vn_c = $t_subject->moveRelationshipsToType($vn_remap_id)) {
                         $t_target = new ca_relationship_types($vn_remap_id);
                         $this->notification->addNotification($vn_c == 1 ? _t("Transferred %1 relationship to type <em>%2</em>", $vn_c, $t_target->getLabelForDisplay()) : _t("Transferred %1 relationships to type <em>%2</em>", $vn_c, $t_target->getLabelForDisplay()), __NOTIFICATION_TYPE_INFO__);
                     }
                     break;
                 default:
                     // update relationships
                     $va_tables = array('ca_objects', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_list_items', 'ca_loans', 'ca_movements', 'ca_tours', 'ca_tour_stops', 'ca_object_representations', 'ca_list_items');
                     $vn_c = 0;
                     foreach ($va_tables as $vs_table) {
                         $vn_c += $t_subject->moveRelationships($vs_table, $vn_remap_id);
                     }
                     // update existing metadata attributes to use remapped value
                     $t_subject->moveAuthorityElementReferences($vn_remap_id);
                     if ($vn_c > 0) {
                         $t_target = $this->opo_datamodel->getInstanceByTableName($this->ops_table_name);
                         $t_target->load($vn_remap_id);
                         $this->notification->addNotification($vn_c == 1 ? _t("Transferred %1 relationship to <em>%2</em> (%3)", $vn_c, $t_target->getLabelForDisplay(), $t_target->get($t_target->getProperty('ID_NUMBERING_ID_FIELD'))) : _t("Transferred %1 relationships to <em>%2</em> (%3)", $vn_c, $t_target->getLabelForDisplay(), $t_target->get($t_target->getProperty('ID_NUMBERING_ID_FIELD'))), __NOTIFICATION_TYPE_INFO__);
                     }
                     break;
             }
         } else {
             $t_subject->deleteAuthorityElementReferences();
         }
         $t_subject->setMode(ACCESS_WRITE);
         $vb_rc = false;
         if ($this->_beforeDelete($t_subject)) {
             if ($vb_rc = $t_subject->delete(true)) {
                 $this->_afterDelete($t_subject);
             }
         }
         if ($vb_we_set_transaction) {
             if (!$vb_rc) {
                 $o_t->rollbackTransaction();
             } else {
                 $o_t->commitTransaction();
             }
         }
     }
     $this->view->setVar('confirmed', $vb_confirm);
     if ($t_subject->numErrors()) {
         foreach ($t_subject->errors() as $o_e) {
             $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__);
         }
     } else {
         if ($vb_confirm) {
             $this->notification->addNotification(_t("%1 was deleted", caUcFirstUTF8Safe($vs_type_name)), __NOTIFICATION_TYPE_INFO__);
             // update result list since it has changed
             $this->opo_result_context->removeIDFromResults($vn_subject_id);
             $this->opo_result_context->invalidateCache();
             $this->opo_result_context->saveContext();
             // clear subject_id - it's no longer valid
             $t_subject->clear();
             $this->view->setVar($t_subject->primaryKey(), null);
             $this->request->setParameter($t_subject->primaryKey(), null, 'PATH');
             // set last browse id for hierarchy browser
             $this->request->session->setVar($this->ops_table_name . '_browse_last_id', $vn_parent_id);
             // Clear out row_id so sidenav is disabled
             $this->request->setParameter($t_subject->primaryKey(), null, 'POST');
             # trigger "DeleteItem" hook
             $this->opo_app_plugin_manager->hookDeleteItem(array('id' => $vn_subject_id, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject));
         }
     }
     $this->view->setVar('subject_name', $t_subject->getLabelForDisplay(false));
     $this->render('delete_html.php');
 }