/**
  * Detach file from related object
  *
  * @param void
  * @return null
  */
 function detach_from_object()
 {
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $file_id = get_id('file_id');
     $object = get_object_by_manager_and_id($object_id, $manager_class);
     if (!$object instanceof ProjectDataObject) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $file = ProjectFiles::findById($file_id);
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $attached_file = AttachedFiles::findById(array('rel_object_manager' => $manager_class, 'rel_object_id' => $object_id, 'file_id' => $file_id));
     // findById
     if (!$attached_file instanceof AttachedFile) {
         flash_error(lang('file not attached to object'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     try {
         DB::beginWork();
         $attached_file->delete();
         DB::commit();
         flash_success(lang('success detach file'));
     } catch (Exception $e) {
         flash_error(lang('error detach file'));
         DB::rollback();
     }
     // try
     $this->redirectToReferer($object->getObjectUrl());
 }
 /**
  * Attach project file to this object
  *
  * @param ProjectFile $file
  * @return AttachedFiles
  */
 function attachFile(ProjectFile $file)
 {
     $manager_class = get_class($this->manager());
     $object_id = $this->getObjectId();
     $attached_file = AttachedFiles::findById(array('rel_object_manager' => $manager_class, 'rel_object_id' => $object_id, 'file_id' => $file->getId()));
     // findById
     if ($attached_file instanceof AttachedFile) {
         return $attached_file;
         // Already attached
     }
     // if
     $attached_file = new AttachedFile();
     $attached_file->setRelObjectManager($manager_class);
     $attached_file->setRelObjectId($object_id);
     $attached_file->setFileId($file->getId());
     $attached_file->save();
     if (!$file->getIsVisible()) {
         $file->setIsVisible(true);
         $file->setExpirationTime(EMPTY_DATETIME);
         $file->save();
     }
     // if
     return $attached_file;
 }