Exemplo n.º 1
0
 /**
  * ファイルインプットボックス出力
  * 画像の場合は画像タグ、その他の場合はファイルへのリンク
  * そして削除用のチェックボックスを表示する
  * [カスタムオプション]
  * imgsize・・・画像のサイズを指定する
  * 
  * @param string $fieldName
  * @param array $options
  * @return string
  * @access public
  */
 function file($fieldName, $options = array())
 {
     $linkOptions = $_options = array('imgsize' => 'midium', 'rel' => '', 'title' => '');
     $options = $this->_initInputField($fieldName, Set::merge($_options, $options));
     $linkOptions['imgsize'] = $options['imgsize'];
     $linkOptions['rel'] = $options['rel'];
     $linkOptions['title'] = $options['title'];
     unset($options['imgsize']);
     unset($options['rel']);
     unset($options['title']);
     $view =& ClassRegistry::getObject('view');
     $_field = $view->entity();
     $modelName = $_field[0];
     $field = $_field[1];
     if (ClassRegistry::isKeySet($modelName)) {
         $model =& ClassRegistry::getObject($modelName);
     } else {
         return;
     }
     $fileLinkTag = $this->fileLink($fieldName, $linkOptions);
     $fileTag = parent::file($fieldName, $options);
     $delCheckTag = parent::checkbox($modelName . '.' . $field . '_delete') . parent::label($modelName . '.' . $field . '_delete', '削除する');
     $hiddenValue = $this->value($fieldName . '_');
     $fileValue = $this->value($fieldName);
     if (is_array($fileValue) && empty($fileValue['tmp_name']) && $hiddenValue) {
         $hiddenTag = parent::hidden($modelName . '.' . $field . '_', array('value' => $hiddenValue));
     } else {
         $hiddenTag = parent::hidden($modelName . '.' . $field . '_', array('value' => $this->value($fieldName)));
     }
     $out = $fileTag;
     if ($fileLinkTag) {
         $out .= '&nbsp;' . $delCheckTag . $hiddenTag . '<br />' . $fileLinkTag;
     }
     return '<div class="upload-file">' . $out . '</div>';
 }
 public function file($fieldName, $options = array())
 {
     $retval = parent::file($fieldName, $options);
     $content = $this->value($fieldName);
     if (is_numeric($content) and $content > 0) {
         $retval .= '<br><img src="' . $this->value($fieldName . '_basepath') . 'md3.png" />';
         $retval .= '<span class="help-block">' . floor($content / 1024) . ' kB uploaded</span>';
     }
     return $retval;
 }
 public function render()
 {
     if ($this->getValue()) {
         $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getFile($this->getValue());
         echo '<a target="_blank" href="' . $file->getFileUrl() . '">' . $this->getValue() . '</a>';
         echo '<br />';
         echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']);
         echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить');
     }
     echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias()));
 }
 public function render()
 {
     if ($this->getValue()) {
         $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getImage($this->getValue());
         echo '<img src="' . $file->getThumbUrl(100) . '" alt="" />';
         echo '<br />';
         echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']);
         echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить');
     }
     echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias()));
 }
Exemplo n.º 5
0
 /**
  * overide form->input.
  *
  * @param string $fieldName This should be "Modelname.fieldname"
  * @param array $options Each type of input takes different options.
  */
 public function fileInput($field, $options = array())
 {
     // get model and field
     $explodeField = explode('.', $field);
     if (!is_array($explodeField)) {
         return;
     }
     $modelName = $explodeField[0];
     $fieldName = $explodeField[1];
     if (!empty($options['upload-flag'])) {
         $inputFile = parent::file($field, $options);
         $fileUploaed = parent::hidden($field . '_uploaded', array('value' => empty($this->request->data[$modelName][$fieldName]) ? '' : $this->request->data[$modelName][$fieldName]));
         $stepValidate = parent::hidden($modelName . '.upload_flag');
         return $inputFile . $fileUploaed . $stepValidate;
     } else {
         // input in step form confirm
         $inputFile = parent::hidden($field, array('value' => empty($this->request->data[$modelName][$fieldName]) ? '' : $this->request->data[$modelName][$fieldName]));
         $fileUploaed = parent::hidden($field . '_uploaded', array('value' => empty($this->request->data[$modelName][$fieldName]) ? '' : $this->request->data[$modelName][$fieldName]));
         return $inputFile . $fileUploaed;
     }
 }
Exemplo n.º 6
0
 /**
  * ファイルインプットボックス出力
  * 
  * 画像の場合は画像タグ、その他の場合はファイルへのリンク
  * そして削除用のチェックボックスを表示する
  * 
  * 《オプション》
  * imgsize	画像のサイズを指定する
  * rel		A タグの rel 属性を指定
  * title	A タグの title 属性を指定
  * link		大きいサイズへの画像へのリンク有無
  * delCheck	削除用チェックボックスの利用可否
  * force	ファイルの存在有無に関わらず強制的に画像タグを表示するかどうか
  * 
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 public function file($fieldName, $options = array())
 {
     $options = $this->_initInputField($fieldName, $options);
     $entity = $this->entity();
     $modelName = $this->model();
     $Model = ClassRegistry::init($modelName);
     if (empty($Model->Behaviors->BcUpload)) {
         return parent::file($fieldName, $options);
     }
     $fieldName = implode('.', $entity);
     $options = array_merge(array('imgsize' => 'medium', 'rel' => '', 'title' => '', 'link' => true, 'delCheck' => true, 'force' => false, 'width' => '', 'height' => ''), $options);
     extract($options);
     unset($options['imgsize']);
     unset($options['rel']);
     unset($options['title']);
     unset($options['link']);
     unset($options['delCheck']);
     unset($options['force']);
     unset($options['width']);
     unset($options['height']);
     $linkOptions = array('imgsize' => $imgsize, 'rel' => $rel, 'title' => $title, 'link' => $link, 'delCheck' => $delCheck, 'force' => $force, 'width' => $width, 'height' => $height);
     $fileLinkTag = $this->BcUpload->fileLink($fieldName, $linkOptions);
     $fileTag = parent::file($fieldName, $options);
     if (empty($options['value'])) {
         $value = $this->value($fieldName);
     } else {
         $value = $options['value'];
     }
     // PHP5.3対応のため、is_string($value) 判別を実行
     $delCheckTag = '';
     if ($fileLinkTag && $linkOptions['delCheck'] && (is_string($value) || empty($value['session_key']))) {
         $delCheckTag = $this->checkbox($fieldName . '_delete') . $this->label($fieldName . '_delete', '削除する');
     }
     $hiddenValue = $this->value($fieldName . '_');
     $fileValue = $this->value($fieldName);
     if ($fileLinkTag) {
         if (is_array($fileValue) && empty($fileValue['tmp_name']) && $hiddenValue) {
             $hiddenTag = $this->hidden($fieldName . '_', array('value' => $hiddenValue));
         } else {
             if (is_array($fileValue)) {
                 $fileValue = null;
             }
             $hiddenTag = $this->hidden($fieldName . '_', array('value' => $fileValue));
         }
     }
     $out = $fileTag;
     if ($fileLinkTag) {
         $out .= '&nbsp;' . $delCheckTag . $hiddenTag . '<br />' . $fileLinkTag;
     }
     return '<div class="upload-file">' . $out . '</div>';
 }