MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mcustomfield.class
Ir para a documentação deste ficheiro.
1<?php
2
26{
30 const FORMAT_TEXT = 'text';
31 const FORMAT_LONG_TEXT = 'longText';
32 const FORMAT_INTEGER = 'integer';
33 const FORMAT_DECIMAL = 'decimal';
34 const FORMAT_LIST = 'list';
35 const FORMAT_LISTSQL = 'listsql';
36 const FORMAT_MTAG = 'mtagselectionsql';
37 const FORMAT_MULTI_LIST = 'multList';
38 const FORMAT_MULTI_LISTSQL = 'multListsql';
39 const FORMAT_DATE = 'date';
40 const FORMAT_BOOLEAN = 'boolean';
41 const FORMAT_HIDDEN = 'oculto';
42 const FORMAT_SESCOLHA = 'sescolha';
43 const FORMAT_INTERVAL = 'interval';
44 const FORMAT_SESCOLHA_LIST = 'sescolhaList';
45 const FORMAT_SESCOLHA_LISTSQL = 'sescolhaListsql';
46 const FORMAT_JAVASCRIPT = 'javascript';
47 const FORMAT_FILE = 'file';
48 const FORMAT_EDITOR = 'editor';
49
53 public $id;
54
59
63 public $name;
64
70 public $label;
71
76
81
85 public $regexp;
86
90 public $minLength;
91
95 public $maxLength;
96
100 public $required;
101
105 public $position;
106
111
115 public $editable;
116
120 public $visible;
121
125 public $suffix;
126
131
136
141
145 public $visivel;
146
151
155 public $largura;
156
160 public $altura;
161
162 public $hint;
163
164 public $jshint;
165
171 public function __construct($data=NULL)
172 {
173 if ( $data )
174 {
175 $this->setData($data);
176 }
177 }
178
182 private static function getBusiness()
183 {
185 return new MBusiness('admin');
186 }
187
191 public function getInputId()
192 {
193 return self::generateInputId($this->identifier, $this->id, $this->suffix);
194 }
195
204 public static function generateInputId($identifier, $id, $suffix='')
205 {
206 return str_replace(" ", "_", "{$identifier}_$id$suffix");
207 }
208
214 public function setData($data)
215 {
216 $this->id = $data->id;
217 $this->identifier = $data->identifier;
218 $this->name = $data->name;
219 $this->fieldFormat = SAGU::NVL($data->fieldFormat, $data->fieldformat);
220 $this->possibleValues = SAGU::NVL($data->possibleValues, $data->possiblevalues);
221 $this->regexp = $data->regexp;
222 $this->minLength = SAGU::NVL($data->minLength, $data->minlength);
223 $this->maxLength = SAGU::NVL($data->maxLength, $data->maxlength);
224 $this->required = $data->required;
225 $this->position = $data->position;
226 $this->defaultValue = SAGU::NVL($data->defaultValue, $data->defaultvalue);
227 $this->editable = $data->editable;
228 $this->visible = $data->visible;
229 $this->filtroFormularioBusca = $data->filtroFormularioBusca;
230 $this->visivel = $data->visivel;
231 $this->objetoreferencia = $data->objetoreferencia;
232 $this->largura = $data->largura;
233 $this->altura = $data->altura;
234 $this->label = $data->label;
235 $this->possibleParameters = $data->possibleparameters;
236 $this->hint = $data->hint;
237 $this->jshint = $data->jshint;
238 }
239
245 public function insert()
246 {
247 $this->id = $this->getBusiness()->_db->getNewId('miolo_custom_field_id_seq', 'miolo_sequence');
248
249 $sql = new MSQL(
250 'id, identifier, name, field_format, possible_values, regexp, min_length, max_length, required, position, default_value, editable, visible, filtroFormularioBusca, visivel, hint, jshint',
251 'miolo_custom_field'
252 );
253
254 $args = array(
255 $this->id,
256 $this->identifier,
257 $this->name,
258 $this->fieldFormat,
259 $this->possibleValues,
260 $this->regexp,
261 $this->minLength,
262 $this->maxLength,
263 $this->required,
264 $this->position,
265 $this->defaultValue,
266 $this->editable,
267 $this->visible,
268 $this->filtroFormularioBusca,
269 $this->visivel,
270 $this->hint,
271 $this->jshint
272 );
273
274 return self::getBusiness()->execute($sql->insert($args));
275 }
276
282 public function update()
283 {
284 $sql = new MSQL(
285 'identifier, name, field_format, possible_values, regexp, min_length, max_length, required, position, default_value, editable, visible, filtroFormularioBusca, visivel, hint, jshint',
286 'miolo_custom_field',
287 'id = ?'
288 );
289
290 $args = array(
291 $this->identifier,
292 $this->name,
293 $this->fieldFormat,
294 $this->possibleValues,
295 $this->regexp,
296 $this->minLength,
297 $this->maxLength,
298 $this->required,
299 $this->position,
300 $this->defaultValue,
301 $this->editable,
302 $this->visible,
303 $this->filtroFormularioBusca,
304 $this->visivel,
305 $this->hint,
306 $this->jshint,
307 $this->id,
308 );
309
310 return self::getBusiness()->execute($sql->update($args));
311 }
312
318 public function delete()
319 {
320 if ( !isset($this->id) )
321 {
322 return false;
323 }
324
325 $sql = new MSQL('', 'miolo_custom_field', 'id = ?');
326 return self::getBusiness()->execute($sql->delete($this->id));
327 }
328
332 public function populate()
333 {
334 $sql = new MSQL(
335 'identifier, name, label, field_format, possible_values, regexp, min_length, max_length, required, position, default_value, editable, visible, possible_parameters, filtroFormularioBusca, visivel, objetoreferencia, largura, altura, hint, jshint',
336 'miolo_custom_field',
337 'id = ?'
338 );
339
340 $query = self::getBusiness()->query($sql, $this->id);
341
342 list(
343 $this->identifier,
344 $this->name,
345 $this->label,
346 $this->fieldFormat,
347 $this->possibleValues,
348 $this->regexp,
349 $this->minLength,
350 $this->maxLength,
351 $this->required,
352 $this->position,
353 $this->defaultValue,
354 $this->editable,
355 $this->visible,
356 $this->possibleParameters,
357 $this->filtroFormularioBusca,
358 $this->visivel,
359 $this->objetoreferencia,
360 $this->largura,
361 $this->altura,
362 $this->hint,
363 $this->jshint
364 ) = $query->result[0];
365 }
366
370 public function isRequired()
371 {
372 return $this->required == 't';
373 }
374
378 public function isEditable()
379 {
380 return $this->editable == 't';
381 }
382
386 public function isVisible()
387 {
388 return $this->visivel == 't';
389 }
390
397 public static function listByIdentifier($identifier, $actionURL = NULL, $step = null)
398 {
399 $sql = new MSQL(
400 'id, identifier, name, label, field_format, possible_values, regexp, min_length, max_length, required, position, default_value, editable, visible, possible_parameters, filtroFormularioBusca, visivel, objetoreferencia, largura, altura, hint, jshint',
401 'miolo_custom_field',
402 '',
403 'position, name'
404 );
405
406 $sql->addEqualCondition('identifier', $identifier);
407
408 if ( $step )
409 {
410 $sql->addEqualCondition('passo', $step);
411 }
412
413 if( strlen($actionURL) > 0 )
414 {
415 $sql->addEqualCondition('actionURL', $actionURL);
416 }
417 else
418 {
419 $sql->setWhereAnd('actionURL IS NULL');
420 }
421
422 $query = self::getBusiness()->query($sql);
423
424 $list = array();
425
426 if ( $query->result )
427 {
428 foreach ( $query->result as $row )
429 {
430 $cf = new self();
431
432 list(
433 $cf->id,
434 $cf->identifier,
435 $cf->name,
436 $cf->label,
437 $cf->fieldFormat,
438 $cf->possibleValues,
439 $cf->regexp,
440 $cf->minLength,
441 $cf->maxLength,
442 $cf->required,
443 $cf->position,
444 $cf->defaultValue,
445 $cf->editable,
446 $cf->visible,
447 $cf->possibleParameters,
448 $cf->filtroFormularioBusca,
449 $cf->visivel,
450 $cf->objetoreferencia,
451 $cf->largura,
452 $cf->altura,
453 $cf->hint,
454 $cf->jshint
455 ) = $row;
456
457 $list[] = $cf;
458 }
459 }
460
461 return $list;
462 }
463
470 public static function listForGrid($identifier='')
471 {
473
474 $where = $identifier ? 'identifier = ?' : '';
475
476 $sql = new MSQL(
477 'id,
478 identifier,
479 name,
480 field_format,
481 possible_values,
482 required,
483 filtroFormularioBusca ',
484 'miolo_custom_field',
485 $where,
486 'identifier, position, name'
487 );
488
489 $query = self::getBusiness()->query($sql, $identifier);
490
491 return $query->result;
492 }
493
497 public static function listFormatFields()
498 {
499 return array(
500 self::FORMAT_TEXT => _M('Text'),
501 self::FORMAT_LONG_TEXT => _M('Long text'),
502 self::FORMAT_INTEGER => _M('Integer'),
503 self::FORMAT_DECIMAL => _M('Decimal'),
504 self::FORMAT_LIST => _M('List'),
505 self::FORMAT_LISTSQL => _M('Lista (SQL)'),
506 self::FORMAT_MTAG => _M('MTagSelection (SQL)'),
507 self::FORMAT_MULTI_LIST => _M('Multi-seleção'),
508 self::FORMAT_MULTI_LISTSQL => _M('Multi-seleção (SQL)'),
509 self::FORMAT_DATE => _M('Date'),
510 self::FORMAT_BOOLEAN => _M('Boolean'),
511 self::FORMAT_SESCOLHA => _M('SEscolha'),
512 self::FORMAT_SESCOLHA_LIST => _M('SEscolha (Lista)'),
513 self::FORMAT_SESCOLHA_LISTSQL => _M('SEscolha (Sql)'),
514 self::FORMAT_JAVASCRIPT => _M('JavaScript'),
515 self::FORMAT_FILE => _M('Arquivo'),
516 self::FORMAT_EDITOR => _M('Editor'),
517 );
518 }
519
527 public function __get($attr)
528 {
529 if ( $attr == 'sId' ) return $this->id;
530 if ( $attr == 'sName' ) return $this->name;
531 if ( $attr == 'sVisible' ) return $this->visible;
532 }
533
537 public function hasSQLParameters()
538 {
539 return substr_count($this->possibleValues, '?') > 0;
540 }
541
547 public function parsePossibleParameters()
548 {
549 return (array) explode(',', $this->possibleParameters);
550 }
551
555 public function getParameterArgs()
556 {
558 $args = array();
559
560 foreach ( $this->parsePossibleParameters() as $parameter )
561 {
562 // Tenta buscar valor do REQUEST
563 $requestValue = MIOLO::_REQUEST($parameter);
564
565 // Se nao encontrar valor, busca do $_REQUEST ignorando maiusculas/minusculas
566 if ( strlen($requestValue) == 0 )
567 {
568 $data = array_change_key_case($_REQUEST, CASE_LOWER);
569
570 $requestValue = $data[strtolower($parameter)];
571 }
572
573 // Se nao encontrar valor, tenta buscar de dados de passo a passo
574 if ( strlen($requestValue) == 0 )
575 {
576 $isFromSAGU = $MIOLO->getConf('temp.is.from.sagu');
577
578 if ( $isFromSAGU )
579 {
580 $data = (array) sstepbystepform::getAllStepDataStatic();
581 $data = array_change_key_case($data, CASE_LOWER);
582
583 $requestValue = $data[strtolower($parameter)];
584 }
585 }
586
587 if ( strlen($requestValue) == 0 && strlen($this->paramNotFound) == 0 )
588 {
589 $this->paramNotFound = $parameter;
590 }
591
592 $args[] = $requestValue;
593 }
594
595 return $args;
596 }
597
603 public function replaceSQLParameters($sql)
604 {
605 if ( $this->hasSQLParameters() )
606 {
608 $isFromSAGU = $MIOLO->getConf('temp.is.from.sagu');
609
610 if ( $isFromSAGU )
611 {
612 $args = $this->getParameterArgs();
613
614 // executa o comando de substituicao dos coringas
615 $sql = SAGU::prepare($sql, $args, false);
616 }
617 }
618
619 return $sql;
620 }
621
626 public function getListSQL()
627 {
629 $list = array();
630
631 if ( strlen($this->possibleValues) > 0 && (( $this->fieldFormat == MCustomField::FORMAT_LISTSQL ) || ( $this->fieldFormat == MCustomField::FORMAT_MULTI_LISTSQL) || ($this->fieldFormat == MCustomField::FORMAT_SESCOLHA_LISTSQL) || $this->fieldFormat == MCustomField::FORMAT_MTAG))
632 {
633 $db = $MIOLO->GetDatabase('admin');
634 $query = $db->Query($this->replaceSQLParameters($this->possibleValues));
635
636 foreach ( (array) $query as $row )
637 {
638 $list[ $row[0] ] = $row[1];
639 }
640 }
641
642 return $list;
643 }
644
645 public function getFieldHint()
646 {
647 if ( $this->hasSQLParameters() && strlen($this->paramNotFound) > 0 )
648 {
649 return _M("Não foi encontrado valor para o parâmetro '@1' configurado.", null, $this->paramNotFound);
650 }
651 }
652
656 public function getListValues()
657 {
658 $possibleValues = explode("\n", trim($this->possibleValues));
659 $list = array();
660
661 foreach ( $possibleValues as $val )
662 {
663 $value = trim($val);
664 $list[$value] = $value;
665 }
666
667 return $list;
668 }
669
670 public static function getCustomFieldById($id)
671 {
672 $name = SDatabase::queryAssociative(SDatabase::prepareSQL("
673 SELECT id,
674 identifier,
675 name,
676 label,
677 field_format as fieldFormat,
678 possible_values as possibleValues,
679 possible_parameters as possibleParameters,
680 regexp,
681 min_length as minLength,
682 max_length as maxLength,
683 required,
684 position,
685 default_value as defaultValue,
686 editable,
687 visible,
688 filtroFormularioBusca,
689 visivel,
690 objetoreferencia,
691 largura,
692 altura,
693 hint,
694 jshint
695 FROM miolo_custom_field
696 WHERE id = ?", array($id)))[0];
697
698 return new MCustomField((object) $name);
699 }
700}
701?>
const FORMAT_LONG_TEXT
const FORMAT_SESCOLHA
const FORMAT_SESCOLHA_LISTSQL
const FORMAT_SESCOLHA_LIST
replaceSQLParameters($sql)
const FORMAT_MULTI_LIST
const FORMAT_INTEGER
const FORMAT_JAVASCRIPT
const FORMAT_DECIMAL
const FORMAT_LISTSQL
const FORMAT_MULTI_LISTSQL
static listFormatFields()
const FORMAT_INTERVAL
const FORMAT_BOOLEAN
static listForGrid($identifier='')
static generateInputId($identifier, $id, $suffix='')
static getCustomFieldById($id)
static listByIdentifier($identifier, $actionURL=NULL, $step=null)
__construct($data=NULL)
static _REQUEST( $vars, $from='ALL')
Definição miolo.class:1109
static getInstance()
Definição miolo.class:134
Definição msql.class:8