/** * Return file as inline attachment, uses $_GET['id'] as input param. */ public function actionIndex() { #$this->render('index'); if (!$_GET['id']) { throw new CException('No file specified.'); } else { $model = P3Media::model()->findByPk($_GET['id']); $filename = Yii::getPathOfAlias($this->module->dataAlias) . DIRECTORY_SEPARATOR . $model->path; if (!is_file($filename)) { throw new CException('File not found.'); } else { header('Content-Disposition: attachment; filename="' . $model->title . '"'); header('Content-type: ' . $model->mimeType); readfile($filename); exit; } } }
public function actionBrowser() { $files = new P3Media('search'); // select files $files->type = P3Media::TYPE_FILE; $files->status = null; // apply search terms if (isset($_GET['P3Media'])) { $files->attributes = $_GET['P3Media']; } // select files from folder if (isset($_GET['id'])) { $files->tree_parent_id = $_GET['id']; } else { $files->tree_parent_id = null; } // directories $directories = P3Media::model()->getFolderItems(); $criteria = new CDbCriteria(); $criteria->condition = "t.type = '" . P3Media::TYPE_FOLDER . "'"; $this->directoriesList = CHtml::listData(P3Media::model()->findAll($criteria), 'id', 'title'); $this->render('browser', array('files' => $files, 'directories' => $directories)); }
/** * Returns all records with type folder in a CMenu compatible tree structure * @return array */ public function getFolderItems() { $criteria = new CDbCriteria(); $criteria->order = "default_title"; if ($this->id === null) { $criteria->condition = "t.type = '" . P3Media::TYPE_FOLDER . "' AND t.tree_parent_id IS NULL"; } else { $criteria->condition = "t.type = '" . P3Media::TYPE_FOLDER . "' AND t.tree_parent_id = " . $this->id; } $models = P3Media::model()->findAll($criteria); $items = array(); foreach ($models as $model) { if ($model->getFolderItems() === array()) { $items[] = array('label' => $model->title, 'url' => array("", "id" => $model->id)); } else { $items[] = array('label' => $model->title, 'url' => array("", "id" => $model->id), 'items' => $model->getFolderItems()); } } return $items; }
public function loadModel($id) { $m = P3Media::model(); // apply scope, if available $scopes = $m->scopes(); if (isset($scopes[$this->scope])) { $m->{$this->scope}(); } $model = $m->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('P3MediaModule.crud', 'The requested page does not exist.')); } return $model; }
<div class="wide form"> <?php $form = $this->beginWidget('CActiveForm', array('action' => Yii::app()->createUrl($this->route), 'method' => 'get')); ?> <div class="row"> <?php echo $form->label($model, 'id'); ?> <?php echo $form->dropDownList($model, 'id', CHtml::listData(P3Media::model()->findAll(), 'id', '_label'), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'status'); ?> <?php $form->textField($model, 'status'); ?> </div> <div class="row"> <?php echo $form->label($model, 'type'); ?> <?php $form->textField($model, 'type', array('size' => 60, 'maxlength' => 64)); ?>
private function findMd5($md5) { $model = P3Media::model()->findByAttributes(array('md5' => $md5)); if ($model === null) { return false; } else { return true; } }
private function getMediaModel() { $model = P3Media::model()->findByPk($this->model->{$this->attribute}); return $model; }
public function loadModel($id) { $model = P3Media::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }
private static function findModel($id) { return P3Media::model()->with('metaData')->findByPk($id); // TODO? }
echo Yii::t('app', 'Manage'); ?> <?php echo Yii::t('app', 'P3 Media Metas'); ?> </h1> <ul> <li>Data <?php echo CHtml::link("P3Media", array("/p3media/p3Media/admin")); ?> </li> <li>Parent-Child Relationship <?php echo CHtml::link("P3MediaMeta", array("/p3media/p3MediaMeta/admin")); ?> </li> </ul> <?php echo CHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div> <?php $locale = CLocale::getInstance(Yii::app()->language); $this->widget('zii.widgets.grid.CGridView', array('id' => 'p3-media-meta-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'id', 'value' => 'CHtml::value($data,\'id0._label\')', 'filter' => CHtml::listData(P3Media::model()->findAll(), 'id', '_label')), 'status', 'type', 'language', array('name' => 'treeParent_id', 'value' => 'CHtml::value($data,\'p3MediaMetas._label\')', 'filter' => CHtml::listData(P3MediaMeta::model()->findAll(), 'id', '_label')), 'treePosition', array('class' => 'CButtonColumn', 'viewButtonUrl' => "Yii::app()->controller->createUrl('view', array('id' => \$data->id))", 'updateButtonUrl' => "Yii::app()->controller->createUrl('update', array('id' => \$data->id))", 'deleteButtonUrl' => "Yii::app()->controller->createUrl('delete', array('id' => \$data->id))"))));
private function loadModel() { $criteria = new CDbCriteria(); $criteria->addSearchCondition('mime', 'image'); $this->_models = P3Media::model()->findAllByAttributes($criteria); }
private static function findModel($identifier) { if (key($identifier) == 'id') { $model = P3Media::model()->findByPk($identifier[key($identifier)]); // TODO? } elseif (key($identifier) == 'nameId') { $model = P3Media::model()->findByAttributes(array(key($identifier) => $identifier[key($identifier)])); // TODO? } return $model; }