Beispiel #1
0
 /**
  * Lists all models.
  * @param integer $id the ID of the folder to display
  */
 public function actionIndex($id = null)
 {
     $model = new DocFolders();
     $model->parentFolder = $id;
     if (Yii::app()->request->isAjaxRequest && isset($_POST['DocFolders'])) {
         $model->setAttributes($_POST['DocFolders']);
         if ($model->parentFolder == 0) {
             $model->parentFolder = null;
         }
         if ($model->save()) {
             echo CJSON::encode(array('success' => 1));
         } else {
             $form = $this->renderPartial('_folderCreate', array('model' => $model), true, true);
             echo CJSON::encode(array('form' => $form));
             Yii::app()->end();
         }
     } else {
         if (empty($id)) {
             $folderDataProvider = DocFolders::getRootFolderContents();
         } elseif ($id == -1) {
             $folderDataProvider = DocFolders::getTemplatesFolderContents();
         } else {
             $folder = DocFolders::model()->findByPk($id);
             if (!$this->checkPermissions($folder, 'view')) {
                 $this->denied();
             }
             if (isset($folder)) {
                 $folderDataProvider = $folder->getContents();
             } else {
                 throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
             }
         }
         $attachments = new CActiveDataProvider('Media', array('criteria' => array('order' => 'createDate DESC', 'condition' => 'associationType="docs"')));
         $this->render('index', array('currentFolder' => $id, 'model' => $model, 'folderDataProvider' => $folderDataProvider, 'attachments' => $attachments));
     }
 }