Example #1
0
 /**
  * @inheritdoc
  * @param $View TotalFlex\View object with table configuration
  * @param $context just one context, this method does not accept many context in a single call
  */
 public function generate(\TotalFlex\View $View, $context)
 {
     if (!in_array($context, array(\TotalFlex\TotalFlex::CtxNone, \TotalFlex\TotalFlex::CtxCreate, \TotalFlex\TotalFlex::CtxRead, \TotalFlex\TotalFlex::CtxUpdate, \TotalFlex\TotalFlex::CtxDelete))) {
         throw new \Exception("Please generate one context at a time");
     }
     $form = $this->_templateCollection['form']['start'];
     $form = str_replace("__method__", $View->getForm()->getMethod(), $form);
     $form = str_replace("__action__", $View->getForm()->getAction(), $form);
     $form = str_replace("__enctype__", $View->getForm()->getEnctype(), $form);
     // $form .= $this->generateField( \TotalFlex\Field\Hidden::getInstance ( "context" , null )->setValue($context) );
     // $form .= "<input type=\"hidden\" name=\"TFFields[".$View->getName()."][context]\" value=\"$context\" id=\"totalflex-context\" />\n";
     // $form .= "<input type=\"hidden\" name=\"TFFields[".$View->getName()."][view]\" value=\"".$View->getName()."\" id=\"totalflex-view\" />\n";
     foreach ($View->getFields() as $Field) {
         if (!$Field->isInContext($context)) {
             continue;
         }
         $form .= $Field->toHtml($context);
     }
     if ($context === \TotalFlex\TotalFlex::CtxUpdate) {
         // precisa adicionar o primary key
         // precisa também de um campo de proteção
         $primaryKeyFieldList = $View->getPrimaryKeyFields();
         $hashSource = "";
         foreach ($primaryKeyFieldList as $pkField) {
             $hashSource = $pkField->getColumn() . "=" . $pkField->getValue();
             $form .= "<input type=\"hidden\" name=\"TFFields[" . $View->getName() . "][{$context}][fields][" . $pkField->getColumn() . "]\" value=\"" . $pkField->getValue() . "\" />\n";
             // $form .= $this->generateField ( $pkField , $context );
         }
         $hash = sha1(md5($hashSource) . \TotalFlex\TotalFlex::SECURITY_SALT);
         $form .= "<input type=\"hidden\" name=\"TFFields[" . $View->getName() . "][{$context}][validation_hash]\" value=\"{$hash}\" />\n";
     }
     $form .= $this->_templateCollection['form']['end'];
     return $form;
 }