Exemple #1
0
 private function toArrayFromModel(Disk\Internals\Model $model)
 {
     $entity = null;
     if ($model instanceof Disk\Storage) {
         $entity = new Entity\Storage();
     } elseif ($model instanceof Disk\File) {
         $entity = new Entity\Folder();
     } elseif ($model instanceof Disk\Folder) {
         $entity = new Entity\File();
     } else {
         throw new RestException('Unknown object ' . get_class($model));
     }
     $toArray = array_intersect_key($model->toArray(), $entity->getFieldsForShow());
     foreach ($entity->getFieldsForMap() as $fieldName => $modifiers) {
         if (!isset($toArray[$fieldName])) {
             continue;
         }
         $toArray[$fieldName] = call_user_func_array($modifiers['OUT'], array($toArray[$fieldName]));
     }
     unset($fieldName, $modifiers);
     if ($model instanceof Disk\File) {
         $toArray['DOWNLOAD_URL'] = $this->host . $this->urlManager->getUrlForDownloadFile($model) . '&auth=' . $this->restServer->getAuth();
         if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) {
             $toArray['DETAIL_URL'] = null;
         } else {
             $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathFileDetail($model);
         }
     } elseif ($model instanceof Disk\Folder) {
         if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) {
             $toArray['DETAIL_URL'] = null;
         } else {
             $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathInListing($model) . $model->getName();
         }
     }
     return $toArray;
 }
Exemple #2
0
 protected function externalizeProductFile($productID, $fieldName, $valueID, $fileID, $dynamic = true)
 {
     $handlerUrl = "/bitrix/components/bitrix/crm.product.file/download.php";
     $showUrl = CComponentEngine::MakePathFromTemplate("{$handlerUrl}?productId=#product_id#&fieldName=#field_name#&dynamic=#dynamic#&fileId=#file_id#", array('field_name' => $fieldName, 'file_id' => $fileID, 'product_id' => $productID, 'dynamic' => $dynamic ? 'Y' : 'N'));
     $downloadUrl = CComponentEngine::MakePathFromTemplate("{$handlerUrl}?auth=#auth#&productId=#product_id#&fieldName=#field_name#&dynamic=#dynamic#&fileId=#file_id#", array('auth' => $this->server ? $this->server->getAuth() : '', 'field_name' => $fieldName, 'file_id' => $fileID, 'product_id' => $productID, 'dynamic' => $dynamic ? 'Y' : 'N'));
     $result = array('id' => $fileID, 'showUrl' => $showUrl, 'downloadUrl' => $downloadUrl);
     if ($dynamic) {
         $result = array('valueId' => $valueID, 'value' => $result);
     }
     return $result;
 }