✏️ 正在编辑: Form.php
路径:
/srv/systems_dir/yuppiecred-bkp/library/Core/Form.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Form extends Zend_Form { private $_front = null; /** @var string */ public const MASK_NUM = 'mascara(this, soNumeros)', MASK_VAL = 'mascara(this, mvalor)', WLOCATION = "window.location='%s'" ; public function __construct($options = null) { $this->setMethod('post'); $this->setAttrib('autocomplete', 'off'); $this->setAction($this->getView()->url()); parent::__construct($options); foreach ( $this->getElements() as $element ) { $label = $element->getDecorator('Label'); if ($label) { $label->setReqSuffix(' *'); } if ($element instanceof Zend_Form_Element_File) { $this->setAttrib('enctype', 'multipart/form-data'); } } } protected function _getParams() { $this->_front = Zend_Controller_Front::getInstance(); return $this->_front->getRequest()->getParams(); } protected function _getReferer() { $params = $this->_getParams(); $request = $this->_front->getRequest(); $urlReturn = $request->getHeader('referer'); $urlView = str_replace("{$request->getScheme()}://{$request->getServer("SERVER_NAME")}", "", $urlReturn); if( $this->getView()->url() == $urlView ){ $urlReturn = $this->getView()->url( array( 'module' => $params['module'], 'controller' => $params['controller'], 'action' => 'index' ), null, true); } return $urlReturn; } /** * função para popular elemento, de acordo com o parametro encontrado * @param type $campoAPopular * @param type $campoParametro */ protected function _populateId($campoAPopular, $campoParametro) { $front = Zend_Controller_Front::getInstance(); //pega o id do parametro $id = (int) $front->getRequest()->getParam($campoParametro); //verifica se passou o id por parâmetro if( $id > 0 ){ $element = $this->getElement($campoAPopular); $element->setValue($id); } } /** * função para verificar se existe permissão * @param type $permissao * @return boolean */ protected function _verificarPermissao($permissao) { $ns = new Zend_Session_Namespace(); if( $ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, $permissao) ){ return true; } return false; } /** * @param string $name * @param string $label * @param string|null $default * @return $this * @throws Zend_Form_Exception */ protected function addDateElement(string $name, string $label, ?string $default = ''): self { $this->addElement(Form_DatePicker::getDatePicker($name, $label, $default)); return $this; } /** * @param string $name * @param string $label * @param string $class * @param array $multiOptions * @param bool|null $required * * @return $this * * @throws Zend_Form_Exception */ protected function addMultiOptionElement( string $name, string $label, string $class, array $multiOptions, ?bool $required = false ): self { $select = new Zend_Form_Element_Multiselect($name); $select->setLabel($label) ->setAttrib("class", $class) ->addMultiOptions($multiOptions) ; if ($required) { $select->setRequired(); } $this->addElement($select); return $this; } /** * @param string $name * @param string $label * @return $this * @throws Zend_Form_Exception */ protected function addValueElement( string $name, string $label ): self { $this->addElement('text', $name, [ 'label' => $label, 'onkeypress' => 'mascara(this, mvalor)', 'placeholder' => '0,00' ]); return $this; } /** * @param string $name * @param string $label * @param bool|null $nullable * @return $this * @throws Zend_Form_Exception */ protected function addTwoOptionsElement( string $name, string $label, ?bool $nullable = true ): self { $null = [ '' => '', ]; $options = [ '0' => 'NÃO', '1' => 'SIM' ]; $options = $nullable ? $null + $options : $options ; $this->addElement('select', $name, [ 'style' => 'width:80px', 'label' => $label, 'multiOptions' => $options ]); return $this; } /** * @param string $name * @param string $label * @param array $options * @param bool|null $required * @return $this * @throws Zend_Form_Exception */ protected function addSelect( string $name, string $label, array $options, ?bool $required = false ): self { $this->addElement('select', $name, [ 'label' => $label, 'multiOptions' => $options ]); if ($required) { $this->getElement($name) ->setRequired(); } return $this; } /** * @param string $name * @param array|null $options * @param string|null $type * @return $this * @throws Zend_Form_Exception */ public function addElementWith( string $name, ?array $options = [], ?string $type = 'text' ): self { $this->addElement($type, $name, $options); return $this; } /** * @param string|null $label * @param int|null $size * @param int|null $maxlength * @param string|null $keypress * @param array|null $validators * @param string|null $class * @return array */ protected function getOptions( ?string $label = null, ?int $size = null, ?int $maxlength = null, ?string $keypress = null, ?array $validators = null, ?string $class = null, ?string $onclick = null ): array { $options = []; if ($label) { $options['label'] = $label; } if ($size) { $options['size'] = $size; } if ($maxlength) { $options['maxlength'] = $maxlength; } if (!empty($validators)) { $options['validators'] = $validators; } if ($keypress) { $options['onkeypress'] = $keypress; } if ($class) { $options['class'] = $class; } if ($onclick) { $options['onclick'] = $onclick; } return $options; } /** * @param string $name * @param null $value * @return $this * @throws Zend_Form_Exception */ protected function addHidden(string $name, $value = null): self { $this->addElement('hidden', $name, [ 'class' => 'invisible' ]); if ($value) { $this->getElement($name)->setValue($value); } return $this; } /** * @param string $name * @param string $label * @param int|null $size * @return $this * @throws Zend_Form_Exception */ protected function addInt( string $name, string $label, ?int $size = 3 ): self { $this->addElementWith($name, $this->getOptions($label, null, $size, self::MASK_NUM)); return $this; } /** * @param string $name * @param string $label * @param int|null $size * @return $this * @throws Zend_Form_Exception */ protected function addVal( string $name, string $label, ?int $size = 8 ): self { $this->addElementWith($name, $this->getOptions($label, null, $size, self::MASK_VAL)); return $this; } /** * @param array $elements * @return $this */ protected function setRequireds(array $elements): self { array_map(function ($element) { $this->getElement($element)->setRequired(true); }, $elements); return $this; } /** * @param array $elements * @return $this * @throws Zend_Form_Exception */ protected function setDisableds(array $elements): self { array_map(function ($element) { $this->getElement($element)->setAttrib('disabled', true); }, $elements); return $this; } /** * @param string|null $decorators * @return $this */ public function removeGroupDecorator(?string $decorators = 'DtDdWrapper'): self { array_map(function ($group) use ($decorators) { $group->removeDecorator($decorators); }, $this->getDisplayGroups()); return $this; } /** * @param array $elements * @param array $attributes * * @return $this */ public function setElementsAttrib(array $elements, array $attributes): self { array_map(function ($element) use ($attributes) { $this->getElement($element)->setAttrib($attributes[0], $attributes[1]); }, $elements); return $this; } /** * @return $this * @throws \Zend_Form_Exception */ public function addRecaptcha(): self { $this->addElement( 'hidden', 'recaptcha', [ 'required' => false, 'ignore' => true, 'autoInsertNotEmptyValidator' => false, 'decorators' => [ [ 'HtmlTag', [ 'tag' => 'div', 'class' => 'g-recaptcha', 'data-sitekey' => '6Le9ULoUAAAAAEq884Eo7lKiYxddiITSnJkccpdO', 'data-size' => 'invisible', 'data-callback' => 'onSubmit', ] ] ] ] ); $this->recaptcha->clearValidators(); return $this; } }
💾 保存文件
← 返回文件管理器