Пример #1
0
 public function fileField($model, $attribute, $htmlOptions = array())
 {
     $limit = 1;
     if (isset($htmlOptions['limit'])) {
         $limit = $htmlOptions['limit'];
         unset($htmlOptions['limit']);
     }
     return parent::fileField($model, $attribute, $htmlOptions);
 }
Пример #2
0
 /**
  * Echos or returns the file field, temp name hidden field, the delete checkbox and preview image and set up the uploadcare widget if used.
  * 
  * @param CActiveForm $form the form in which the widget is called. Can be null if CActiveForm is not used. Defaults to null in parent class.
  * 
  * @param boolean $return whether to return the html or just echo it. Defaults to false in parent class.
  * 
  * @param string $attributePostName the fields name if non standard. Such as if using array notation. The format is [key1][key2][keyn...]attributeName, no class name. Defaults to null in parent class.
  * 
  * @param array $fileFieldHtmlOptions html options for file field. Defaults to empty array in parent class.
  * 
  * @param array $checkboxHtmlOptions html options for checkbox field. Defaults to empty array in parent class.
  * 
  * @param array $previewImageHtmlOptions html options for preview image. Defaults to empty array in parent class.
  * 
  * @return string the html.
  */
 public function makeField($form, $attributePostName, $fileFieldHtmlOptions, $checkboxHtmlOptions, $previewImageHtmlOptions)
 {
     $behavior = $this->_behavior;
     $owner = $behavior->owner;
     $attribute = $behavior->attribute;
     $ownerClass = get_class($owner);
     $html = '';
     if (isset($attributePostName)) {
         $postAttributeArrays = substr($attributePostName, 0, strrpos($attributePostName, ']') + 1);
     } else {
         $postAttributeArrays = '';
     }
     foreach ($owner->behaviors() as $ownerBehaviorName => $ownerBehaviorParams) {
         if (($ownerBehaviorParams['class'] == 'application.components.behaviors.UploadingBehavior.ActiveRecordUploadingBehavior' || $ownerBehaviorParams['class'] == 'application.components.behaviors.UploadingBehavior.ModelUploadingBehavior') && $ownerBehaviorParams['attribute'] == $behavior->attribute) {
             $behaviorName = $ownerBehaviorName;
             break;
         }
     }
     $html .= '<div class="uploadFieldWrap">';
     if ($owner->{$attribute} != '') {
         if ($behavior->showPreviewImage) {
             $html .= CHtml::image(Yii::app()->request->baseUrl . '/' . ($owner->{$behaviorName}->tempName != '' ? $owner->{$behaviorName}->tempDir . '/' . $this->fileSuffix($owner->{$behaviorName}->tempName, $behavior->previewImageSuffix) : $owner->{$behaviorName}->dir . '/' . $this->fileSuffix($owner->{$attribute}, $behavior->previewImageSuffix)), '', $previewImageHtmlOptions);
         }
         if ($behavior->allowDelete) {
             $html .= CHtml::checkbox($ownerClass . $postAttributeArrays . '[' . $behaviorName . '][delete]', $behavior->delete, $checkboxHtmlOptions) . '<span>' . Yii::t('admin', 'Supprimer ou') . '&nbsp;&nbsp;</span>';
         }
         $html .= CHtml::hiddenField($ownerClass . $postAttributeArrays . '[' . $behaviorName . '][tempName]', $behavior->tempName);
     }
     if ($behavior->uploadcare !== null) {
         Yii::app()->clientScript->registerScript('UploadingBehaviorUploadCarePublicKey', "UPLOADCARE_PUBLIC_KEY = '" . $this->_uploadcareApi->getPublicKey() . "'; UPLOADCARE_LOCALE = '" . (isset($behavior->uploadcare['language']) ? $behavior->uploadcare['language'] : Yii::app()->language) . "';", CClientScript::POS_HEAD);
         Yii::app()->clientScript->registerScriptFile($this->_uploadcareApi->widget->getScriptSrc(), CClientScript::POS_HEAD);
         $options = array('role' => 'uploadcare-uploader');
         $uploadcareArr = $behavior->uploadcare;
         unset($uploadcareArr['publicKey']);
         unset($uploadcareArr['privateKey']);
         unset($uploadcareArr['language']);
         $options = array_merge($options, $uploadcareArr);
         if (!isset($options['data-images-only']) && isset($behavior->formats)) {
             $options['data-images-only'] = 'true';
         }
         if (!isset($options['data-crop']) && isset($behavior->formats)) {
             $options['data-crop'] = 'true';
         }
         $html .= CHtml::hiddenField($ownerClass . $postAttributeArrays . '[' . $attribute . ']', '', $options);
     } else {
         if ($form !== null) {
             $html .= $form->fileField($owner, $postAttributeArrays . $attribute, $fileFieldHtmlOptions);
         } else {
             $html .= CHtml::activeFileField($owner, $postAttributeArrays . $attribute, $fileFieldHtmlOptions);
         }
     }
     $html .= '</div>';
     return $html;
 }
Пример #3
0
 /**
  * @inheritDoc
  */
 public function fileField($model, $attribute, $htmlOptions = array())
 {
     if (!$this->qualifyNames && !isset($htmlOptions['name'])) {
         $htmlOptions['name'] = $attribute;
     }
     if (!isset($htmlOptions['itemprop'])) {
         $htmlOptions['itemprop'] = $this->getItemPropName($attribute);
     }
     return parent::fileField($model, $attribute, $htmlOptions);
 }
Пример #4
0
 /**
  * Renders a file field for a model attribute.
  * @param CModel $parentModel the parent data model
  * @param string $attributedPath the attribute or path to related model attribute
  * @param array $htmlOptions additional HTML attributes
  * @return string the generated input field
  */
 public function fileField($parentModel, $attributedPath, $htmlOptions = array())
 {
     list($model, $attribute, $htmlOptions) = self::resolveArgs($parentModel, $attributedPath, $htmlOptions);
     return parent::fileField($model, $attribute, $htmlOptions);
 }