public function run() { $container = $this->getContainer(); if (!$container->getSetting('enableWidget', 'library')) { return; } $categoryBuffer = LibraryCategory::model()->contentContainer($container)->findAll(array('order' => 'sort_order ASC')); $categories = array(); $documents = array(); $render = false; foreach ($categoryBuffer as $category) { $itemBuffer = LibraryItem::model()->findAllByAttributes(array('category_id' => $category->id), array('order' => 'sort_order ASC')); // categories are only displayed in the widget if they have sidebar view enabled and contain at least one item if ($category->show_sidebar && !empty($itemBuffer)) { $categories[] = $category; $items[$category->id] = $itemBuffer; $render = true; } } // if none of the categories contains an item, the library widget is not rendered. if ($render) { // register script and css files $assetPrefix = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../resources', true, 0, defined('YII_DEBUG')); Yii::app()->clientScript->registerScriptFile($assetPrefix . '/library.js'); Yii::app()->clientScript->registerCssFile($assetPrefix . '/library.css'); $this->render('libraryPanel', array('container' => $container, 'categories' => $categories, 'items' => $items)); } }
/** * On disabling this module on a space, delete all module -> user related content/data. * Method stub is provided by "UserModuleBehavior" * * @param User $user */ public function disableUserModule(User $user) { foreach (LibraryDocument::model()->contentContainer($user)->findAll() as $content) { $content->delete(); } foreach (LibraryLink::model()->contentContainer($user)->findAll() as $content) { $content->delete(); } foreach (LibraryCategory::model()->contentContainer($user)->findAll() as $content) { $content->delete(); } }
/** * Action that renders the list view. * @see views/global/showLibrary.php */ public function actionShowLibrary() { $this->currentLibrary = (int) Yii::app()->request->getQuery('id'); $contentContainer = Space::model()->findByPk($this->currentLibrary); $categoryBuffer = LibraryCategory::model()->contentContainer($contentContainer)->findAll(array('order' => 'sort_order ASC')); $categories = array(); $items = array(); foreach ($categoryBuffer as $category) { // only show public categories if ($category->content->attributes['visibility'] == 1) { $categories[] = $category; $items[$category->id] = LibraryItem::model()->findAllByAttributes(array('category_id' => $category->id), array('order' => 'sort_order ASC')); } } $this->render('showLibrary', array('categories' => $categories, 'items' => $items)); }
/** * Action that renders the view to add a link.<br /> * The request has to provide the id of the category the link should be created in, in the url parameter 'category_id'.<br /> * @see views/library/editCategory.php * @throws CHttpException 404, if the logged in User misses the rights to access this view. */ public function actionAddLink() { $this->checkContainerAccess(); $category_id = (int) Yii::app()->request->getQuery('category_id'); $category = LibraryCategory::model()->findByAttributes(array('id' => $category_id)); $publicCategory = $category->content->isPublic(); $isCreated = false; // access level 0 may neither create nor edit if ($this->accessLevel == 0) { throw new CHttpException(404, Yii::t('LibraryModule.exception', 'You miss the rights to add links!')); } else { $link = new LibraryLink(); if (LibraryCategory::model()->findByAttributes(array('id' => $category_id)) == null) { throw new CHttpException(404, Yii::t('LibraryModule.exception', 'The category you want to create your link in could not be found!')); } if ($this->accessLevel == 1 && $category->content->isPublic()) { throw new CHttpException(404, Yii::t('LibraryModule.exception', 'You miss the rights to add links to public categories!')); } $link->category_id = $category_id; $isCreated = true; } // if form content is sent back, validate and save if (isset($_POST['LibraryLink'])) { $_POST = Yii::app()->input->stripClean($_POST); $link->attributes = $_POST['LibraryLink']; $link->content->container = $this->contentContainer; $link->content->visibility = $category->content->visibility; if ($link->validate()) { $link->save(); $this->redirect(Yii::app()->createUrl('library/library/showlibrary', array($this->guidParamName => $this->contentContainer->guid))); } } // Render link edit form $this->render('editLink', array($this->guidParamName => $this->contentContainer->guid, 'link' => $link, 'isCreated' => $isCreated)); }