/** * 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 actionAjaxSearch() { $model = new P3Media('search'); $model->title = $_GET['q']; $result = array(); foreach ($model->search()->getData() as $data) { $result[] = array('id' => $data->id, 'title' => $data->title, 'image' => $data->image('p3media-upload')); } echo $_GET['callback'] . "("; echo CJSON::encode($result); echo ")"; }
<?php ?> <div class="control-group"> <div class='control-label'> <?php echo $form->labelEx($model, 'access_append'); ?> </div> <div class='controls'> <span class="tooltip-wrapper" data-toggle='tooltip' data-placement="right" title='<?php echo ($t = Yii::t('p3MediaModule.model', 'tooltip.access_append')) != 'tooltip.access_append' ? $t : ''; ?> '> <?php echo $form->dropDownList($model, 'access_append', P3Media::optsaccessappend(), array('empty' => 'undefined')); echo $form->error($model, 'access_append'); ?> </span> </div> </div> <?php ?> <?php ?> <div class="control-group"> <div class='control-label'> <?php echo $form->labelEx($model, 'copied_from_id'); ?> </div>
<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)); ?>
<div class="row"> <div class="span7"> <h2> <?php echo Yii::t('P3MediaModule.crud', 'Data'); ?> <small> #<?php echo $model->id; ?> </small> </h2> <?php $this->widget('TbDetailView', array('data' => $model, 'attributes' => array(array('name' => 'Image', 'type' => 'raw', 'value' => $model->image('p3media-manager')), array('name' => 'status', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'emptytext' => 'Click to select', 'type' => 'select', 'source' => P3Media::optsstatus(), 'attribute' => 'status', 'url' => $this->createUrl('/p3media/p3Media/editableSaver'), 'select2' => array('placeholder' => 'Select...', 'allowClear' => true)), true)), array('name' => 'type', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'emptytext' => 'Click to select', 'type' => 'select', 'source' => P3Media::optstype(), 'attribute' => 'type', 'url' => $this->createUrl('/p3media/p3Media/editableSaver'), 'select2' => array('placeholder' => 'Select...', 'allowClear' => true)), true)), array('name' => 'name_id', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'attribute' => 'name_id', 'url' => $this->createUrl('/p3media/p3Media/editableSaver')), true)), array('name' => 'default_title', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'attribute' => 'default_title', 'url' => $this->createUrl('/p3media/p3Media/editableSaver')), true)), array('name' => 'default_description', 'type' => 'raw', 'value' => $model->default_description), array('name' => 'tree_parent_id', 'value' => $model->treeParent !== null ? CHtml::link('<i class="icon icon-circle-arrow-left"></i> ' . $model->treeParent->itemLabel, array('/p3media/p3Media/view', 'id' => $model->treeParent->id), array('class' => '')) . ' ' . CHtml::link('<i class="icon icon-pencil"></i> ', array('/p3media/p3Media/update', 'id' => $model->treeParent->id), array('class' => '')) : 'n/a', 'type' => 'html'), array('name' => 'tree_position', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'attribute' => 'tree_position', 'url' => $this->createUrl('/p3media/p3Media/editableSaver')), true)), array('name' => 'custom_data_json', 'type' => 'raw', 'value' => $model->custom_data_json), array('name' => 'original_name', 'type' => 'raw', 'value' => $model->original_name), array('name' => 'path', 'type' => 'raw', 'value' => $model->path), array('name' => 'hash', 'type' => 'raw', 'value' => $model->hash), array('name' => 'mime_type', 'type' => 'raw', 'value' => $model->mime_type), array('name' => 'size', 'type' => 'raw', 'value' => $model->size), array('name' => 'Image', 'type' => 'raw', 'value' => CVarDumper::dumpAsString(CJSON::decode($model->info_php_json), 5, true)), array('name' => 'Image', 'type' => 'raw', 'value' => CVarDumper::dumpAsString(CJSON::decode($model->info_image_magick_json), 5, true)), array('name' => 'access_owner', 'type' => 'raw', 'value' => $model->access_owner), array('name' => 'access_domain', 'type' => 'raw', 'value' => $this->widget('TbEditableField', array('model' => $model, 'emptytext' => 'Click to select', 'type' => 'select', 'source' => P3Media::optsaccessdomain(), 'attribute' => 'access_domain', 'url' => $this->createUrl('/p3media/p3Media/editableSaver'), 'select2' => array('placeholder' => 'Select...', 'allowClear' => true)), true)), array('name' => 'access_read', 'type' => 'raw', 'value' => $model->access_read), array('name' => 'access_update', 'type' => 'raw', 'value' => $model->access_update), array('name' => 'access_delete', 'type' => 'raw', 'value' => $model->access_delete), array('name' => 'access_append', 'type' => 'raw', 'value' => $model->access_append), array('name' => 'copied_from_id', 'type' => 'raw', 'value' => $model->copied_from_id), array('name' => 'created_at', 'type' => 'raw', 'value' => $model->created_at), array('name' => 'updated_at', 'type' => 'raw', 'value' => $model->updated_at)))); ?> </div> <div class="span5"> <div class="well"> <?php $this->renderPartial('_view-relations', array('model' => $model)); ?> </div> </div> </div> <?php $this->renderPartial("_toolbar", array("model" => $model));
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; }