/**
  * 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;
 }