public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * 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 view to add a document.<br />
  * The request has to provide the id of the category the document 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 actionAddDocument()
 {
     $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;
     $lastfile = '';
     // 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 documents!'));
     } else {
         $document = new LibraryDocument();
         $document->date = date('Y-m-d');
         if (LibraryCategory::model()->findByAttributes(array('id' => $category_id)) == null) {
             throw new CHttpException(404, Yii::t('LibraryModule.exception', 'The category you want to create your document 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 documents to public categories!'));
         }
         $document->category_id = $category_id;
         $isCreated = true;
     }
     // if form content is sent back, validate and save
     if (isset($_POST['LibraryDocument'])) {
         $_POST = Yii::app()->input->stripClean($_POST);
         $document->attributes = $_POST['LibraryDocument'];
         $document->content->container = $this->contentContainer;
         $document->content->visibility = $category->content->visibility;
         // Handle uploaded files. array_filter removes empty elements.
         $pre_files = array_filter(explode(",", Yii::app()->request->getParam('fileList')));
         $has_files = count($pre_files) > 0;
         $lastfile = array_pop($pre_files);
         // Validate and save item. At least one file needs to be attached.
         if ($document->validate()) {
             if (!$has_files) {
                 $document->addError('file', Yii::t('LibraryModule.base', 'You must upload a file.'));
             }
             if ($has_files && $document->validate()) {
                 $document->save();
                 // Attach the uploaded file. If multiple were uploaded, just attach the last one.
                 // TODO: Fix the ugly mess with multiple uploaded files.
                 File::attachPrecreated($document, $lastfile);
                 $this->redirect(Yii::app()->createUrl('library/library/showlibrary', array($this->guidParamName => $this->contentContainer->guid)));
             }
         }
     }
     // Render document edit form
     $this->render('editDocument', array($this->guidParamName => $this->contentContainer->guid, 'document' => $document, 'isCreated' => $isCreated));
 }