コード例 #1
0
 function &getAllocationsForDocumentAndRole($iDocumentId, $iRoleId)
 {
     $raTable = KTUtil::getTableName('document_role_allocations');
     $dTable = KTUtil::getTableName('documents');
     $sQuery = "SELECT ra.id as `id` FROM " . $raTable . " AS ra " . ' LEFT JOIN ' . $dTable . ' AS d ON (d.id = ra.document_id) ' . ' WHERE d.id = ?' . ' AND ra.role_id = ?';
     $aParams = array($iDocumentId, $iRoleId);
     $iAllocId = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
     if (PEAR::isError($iAllocId)) {
         return null;
     }
     if (false) {
         print '<pre>';
         var_dump($iAllocId);
         print '';
         print $sQuery;
         print '</pre>';
     }
     // magic for the Owner role here.
     if (empty($iAllocId) && $iRoleId == -2) {
         $permDescriptor = null;
         // THIS OBJECT MUST NEVER BE MODIFIED, without first calling CREATE.
         $oFakeAlloc = new DocumentRoleAllocation();
         $oFakeAlloc->setDocumentId($iDocumentId);
         $oFakeAlloc->setRoleId($iRoleId);
         $oFakeAlloc->setPermissionDescriptorId($permDescriptor);
         //var_dump($oFakeAlloc);
         return $oFakeAlloc;
     } else {
         if (empty($iAllocId)) {
             return null;
         }
     }
     return DocumentRoleAllocation::get($iAllocId);
 }