Beispiel #1
0
	<link href="http://imidiatv.dev/assets/bootstrap-3.3.2/css/bootstrap.min.css" rel="stylesheet" />

	<style>
		*,html,body{font-size: 1em;}
	</style>

</head>
<body>

<?php 
// Registering table `business_entity` with its fields
$TotalFlex->registerView('business_entity')->setContexts(TotalFlex::CtxUpdate | TotalFlex::CtxCreate)->addField(Field\Text::getInstance("id_user", "ID"))->setPrimaryKey()->addField("name", "Nome")->addField(Field\SelectMultiOptions::getInstance("Perfis de acesso do usuário", "role_user", "id_user", "4", \TotalFlex\DBSource::getInstance("description", "id_role", "SELECT id_role , description FROM role")))->addButton(Button::getInstance("Salvar", array("type" => "submit")))->setTable("user")->where("id_user = 4");
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxCreate , function ( ) { }) ;
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxUpdate ) ;
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxCreate ) ;
echo \TotalFlex\Feedback::dumpMessages();
// prs($pdo->query("SELECT * FROM news_label")->fetchAll());
// pr($consulta->fetchAll());
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxUpdate ) ;
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxRead ) ;
// $TotalFlex->processPost ( "business_entity" , TotalFlex::CtxUpdate|TotalFlex::CtxRead|TotalFlex::CtxCreate ) ;
/************************************************************
 * TotalFlex Use Case
 * ---------------------------------------------------------
 * This is the real code to generate some form with TotalFlex
 * AND handle the return.
 *************************************************************/
// $showForm = true;
// if (isset($_GET['callback'])) {
// $showForm = !$TotalFlex->handleCallback();
// }
Beispiel #2
0
 private function _processCreate($viewName)
 {
     $myContext = TotalFlex::CtxCreate;
     $view = $this->getView($viewName);
     if (empty($_POST['TFFields'][$viewName][$myContext])) {
         return;
     }
     $fieldList = $view->getFieldsFromContext($myContext);
     // DEVE COLOCAR A CHAMADA À VALIDAǘAO DE CADA FIELD AQUI
     // ** a validação deve:
     // * - validar todos os campos independente se um deles já não passou no teste
     // * - retornar ao formulario para que o usuário possa editar e indicar todos os campos que não passaram com sua respectiva mensagem de erro
     // * - passar o contexto para que a validação seja feita dentro de um contexto específico ex.:
     // *		pode ser que um campo seja obrigatório na criação mas não na edição
     // * 		os campos de validação já estão considerando que é necessário guardar o contexto conforme a classe FieldAbstract
     //
     // extract field names and values
     $queryFieldList = array();
     foreach ($fieldList as $Field) {
         if (!is_a($Field, 'TotalFlex\\Field\\Field')) {
             continue;
         }
         if ($Field->isPrimaryKey()) {
             continue;
         }
         if ($Field->skipOnCreate()) {
             continue;
         }
         $Field->processCreate();
         // $queryFieldList[$Field->getColumn()] = $Field->getValue();
         $columnList[] = $Field->getColumn();
         $valueList[] = $Field->getValue();
     }
     // now that we have all fields and it's values, let's get query to create and execute it
     $query = $view->queryBuilder()->getCreateQuery($columnList);
     $statement = $this->_targetDb->prepare($query);
     $exec = $statement->execute($valueList);
     // pr($columnList);
     // pr($valueList);
     // pr($query)		;
     // prd($exec);
     if ($exec) {
         // if executed with success, let's set empty to all fields to clear form,
         foreach ($fieldList as $Field) {
             if (!is_a($Field, 'TotalFlex\\Field\\Field')) {
                 continue;
             }
             if ($Field->isPrimaryKey()) {
                 continue;
             }
             $Field->setValue('');
         }
         Feedback::addMessage($this->_feedbackMessageList['success'][TotalFlex::CtxCreate], Feedback::MESSAGE_SUCCESS);
         return array('insert_id' => $this->_targetDb->lastInsertId());
         // need redirect here to avoid user repost
     } else {
         $errorInfo = $this->_targetDb->errorInfo();
         // pre($this->_targetDb->errorCode());
         Feedback::addMessage($errorInfo[2], Feedback::MESSAGE_DANGER);
         return false;
     }
 }