コード例 #1
0
 public function getItemById($itemId)
 {
     list($type, $id) = explode('-', $itemId);
     if ($type == 'file') {
         return models\File::findOne(['id' => $id]);
     } elseif ($type == 'folder') {
         return models\Folder::findOne(['id' => $id]);
     }
     return null;
 }
コード例 #2
0
 public function disableContentContainer(\humhub\modules\content\components\ContentContainerActiveRecord $container)
 {
     $folders = Content::findAll(['object_model' => Folder::className(), 'space_id' => $container->id]);
     foreach ($folders as $key => $folderContent) {
         $folder = Folder::findOne(['id' => $folderContent->object_id]);
         $folder->delete();
     }
     $files = Content::findAll(['object_model' => File::className(), 'space_id' => $container->id]);
     foreach ($files as $key => $fileContent) {
         $file = File::findOne(['id' => $fileContent->object_id]);
         $file->delete();
     }
 }
コード例 #3
0
 /**
  * Check if a parent folder is valid or lies in itsself, etc.
  * @param integer $id
  * @param array $params
  */
 public function validateParentFolderId($id, $params)
 {
     $parent = Folder::findOne(['id' => $this->{$id}]);
     if ($this->{$id} != 0 && !$parent instanceof Folder) {
         $this->addError($id, Yii::t('CfilesModule.base', 'Please select a valid destination folder for %title%.', ['%title%' => $this->title]));
     }
     // check if one of the parents is oneself to avoid circles
     while (!empty($parent)) {
         if ($this->id == $parent->id) {
             $this->addError($id, Yii::t('CfilesModule.base', 'Please select a valid destination folder for %title%.', ['%title%' => $this->title]));
             break;
         }
         $parent = Folder::findOne(['id' => $parent->parent_folder_id]);
     }
 }
コード例 #4
0
 public function getItemById($itemId)
 {
     $params = explode('_', $itemId);
     if (sizeof($params) < 2) {
         return null;
     }
     list($type, $id) = explode('_', $itemId);
     if ($type == 'file') {
         return models\File::findOne(['id' => $id]);
     } elseif ($type == 'folder') {
         return models\Folder::findOne(['id' => $id]);
     } elseif ($type == 'baseFile') {
         return \humhub\modules\file\models\File::findOne(['id' => $id]);
     }
     return null;
 }
コード例 #5
0
 public static function getPathFromId($id, $parentFolderPath = false, $separator = '/')
 {
     if ($id == 0) {
         return $separator;
     }
     $item = Folder::findOne(['id' => $id]);
     if (empty($item)) {
         return null;
     }
     $tempFolder = $item->parentFolder;
     $path = $separator;
     if (!$parentFolderPath) {
         $path .= $item->title;
     }
     while (!empty($tempFolder)) {
         $path = $separator . $tempFolder->title . $path;
     }
     return $path;
 }
コード例 #6
0
 public static function getPathFromId($id, $parentFolderPath = false, $separator = '/', $withRoot = false)
 {
     if ($id == 0) {
         return $separator;
     }
     $item = Folder::findOne(['id' => $id]);
     if (empty($item)) {
         return null;
     }
     $tempFolder = $item->parentFolder;
     $path = '';
     if (!$parentFolderPath) {
         if ($item->isRoot()) {
             if ($withRoot) {
                 $path .= $item->title;
             }
         } else {
             $path .= $separator . $item->title;
         }
     }
     $counter = 0;
     // break at maxdepth to avoid hangs
     while (!empty($tempFolder)) {
         if ($tempFolder->isRoot()) {
             if ($withRoot) {
                 $path = $tempFolder->title . $path;
             }
             break;
         } else {
             if (++$counter > 10) {
                 $path = '...' . $path;
                 break;
             }
             $path = $separator . $tempFolder->title . $path;
         }
         $tempFolder = $tempFolder->parentFolder;
     }
     return $path;
 }