/**
  * Clone reports of one project into another one
  *
  * @param $srcReport       Original report.
  * @param $dstGroupId      Id of the destination project.
  * @param $metadataMapping Mapping between $srcReport project metadata and $dstGroupId metadata (for fields associated to reports).
  * @param $user            User who will own the newly created reports.
  * @param $forceScopeToI   Force scope of the new reports to I (individual).
  * @param $itemMapping     Mapping between $srcReport project items and $dstGroupId items (for folders associated to report).
  */
 function cloneReport($srcReport, $dstGroupId, $metadataMapping, $user, $forceScopeToI = false, $itemMapping = array())
 {
     $dstReportFactory = new Docman_ReportFactory($dstGroupId);
     $srcFilterFactory = new Docman_FilterFactory($this->groupId);
     // Create new report
     // @php5: clone
     $dstReport = clone $srcReport;
     $dstReport->setGroupId($dstGroupId);
     $dstReport->setUserId($user->getId());
     if ($forceScopeToI) {
         $dstReport->setScope('I');
     }
     // Be carful with reports associated to an item.
     if ($srcReport->getGroupId() != $dstGroupId) {
         if ($srcReport->getItemId() !== null && $srcReport->getItemId() != 0 && isset($itemMapping[$srcReport->getItemId()])) {
             $dstReport->setItemId($itemMapping[$srcReport->getItemId()]);
         } else {
             $dstReport->setItemId(0);
         }
     }
     // Save report
     $rId = $dstReportFactory->createReport($dstReport);
     if ($rId !== false) {
         $dstReport->setId($rId);
         // Copy filters
         $srcFilterFactory->copy($srcReport, $dstReport, $metadataMapping);
         return true;
     } else {
         return false;
     }
 }