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));
     }
 }
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return LibraryDocument the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * 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 deletes a given document.<br />
  * The request has to provide the id of the document to delete in the url parameter 'document_id'.
  * @throws CHttpException 404, if the logged in User misses the rights to access this view.
  */
 public function actionDeleteItem()
 {
     $this->checkContainerAccess();
     $item_id = (int) Yii::app()->request->getQuery('item_id');
     $item = LibraryItem::model()->findByAttributes(array('id' => $item_id));
     if ($item == null) {
         throw new CHttpException(404, Yii::t('LibraryModule.exception', 'Requested item could not be found.'));
     } else {
         if ($this->accessLevel == 0 || $this->accessLevel == 1 && $item->content->created_by != Yii::app()->user->id) {
             throw new CHttpException(404, Yii::t('LibraryModule.exception', 'You miss the rights to delete this item!'));
         }
     }
     $item->delete();
     $this->redirect(Yii::app()->createUrl('library/library/showlibrary', array($this->guidParamName => $this->contentContainer->guid)));
 }