Exemplo n.º 1
0
 /**
  * Checks our POST data and acts accordingly
  */
 public function process()
 {
     $handle_locks = false;
     if ($this->datamanager->storage instanceof midcom_helper_datamanager_storage_midgard && $this->datamanager->storage->object) {
         if (midcom_core_helpers_metadata::is_locked($this->datamanager->storage->object)) {
             throw new midcom_helper_datamanager_exception_locked();
         }
         $handle_locks = true;
     }
     $results = $this->get_submit_values();
     $operation = $this->compute_form_result();
     switch ($operation) {
         case 'cancel':
             if ($handle_locks) {
                 midcom_core_helpers_metadata::unlock($this->datamanager->storage->object);
             }
             throw new midcom_helper_datamanager_exception_cancel();
         case 'previous':
         case 'edit':
             // What ?
             if ($handle_locks) {
                 midcom_core_helpers_metadata::lock($this->datamanager->storage->object);
             }
             break;
         case 'next':
             $this->pass_results_to_method('on_submit', $results, true);
             $this->pass_results_to_method('sync_widget2type', $results, false);
             if ($handle_locks) {
                 midcom_core_helpers_metadata::lock($this->datamanager->storage->object);
             }
             // and then what ?
             break;
         case 'save':
             if ($handle_locks) {
                 midcom_core_helpers_metadata::unlock($this->datamanager->storage->object);
             }
             $this->pass_results_to_method('on_submit', $results, true);
             $this->pass_results_to_method('sync_widget2type', $results, false);
             $this->datamanager->save();
             throw new midcom_helper_datamanager_exception_save();
             // and then what ?
             break;
         default:
             throw new midcom_helper_datamanager_exception_datamanager("Don't know how to handle operation {$operation}");
     }
     return $operation;
 }
Exemplo n.º 2
0
 public static function unlock(&$object)
 {
     $_MIDCOM->authorization->require_do('midgard:update', $object);
     $allowed = false;
     if ($_MIDCOM->authentication->is_user()) {
         $person = $_MIDCOM->authentication->get_person();
         if ($object->metadata->locker == $person->guid) {
             // The person who locked an object can always unlock it
             $allowed = true;
         }
     }
     if (!$allowed) {
         // If user didn't lock it herself require the unlock privilege
         $_MIDCOM->authorization->require_do('midcom:unlock', $object);
     }
     $object->metadata->locked = '';
     $object->metadata->locker = '';
     $approved = midcom_core_helpers_metadata::is_approved(&$object);
     $object->update();
     if ($approved) {
         // TODO: This should be a SUDO operation
         midcom_core_helpers_metadata::approve(&$object);
     }
 }