예제 #1
0
    private function log($type, $log) {
        if ($type < Config::LOGGING_LEVEL)
            return;

        $detailTime = \helper\DateHelper::getTimeWithMicroSeconds();
        $logTime = \helper\DateHelper::getSysdateCustomFormat(\helper\DateHelper::DT_ONLY_HOURS, true);
        $logDay = \helper\DateHelper::getSysdateCustomFormat(\helper\DateHelper::DT_WITHOUT_HOURS);

        $trace = array();
        foreach (debug_backtrace() as $line) {
            if (isset($line['file'])) {
                $trace[] = $line['class'].$line['type'].$line['function'].'('.$line['file'].':'.$line['line'].')';
            } else {
                $trace[] = $line['class'].$line['type'].$line['function'];
            }
        }

        if (is_a($log, 'Exception')) {
            $message = $log->getMessage();
        } else {
            $message = $log;
        }

        $content = $logTime.' '.self::getTypeText($type).' '.$line['class'].$line['type'].$line['function'].' - '.$message;
        $content .= ' <a href="'.$logDay.'/'.$detailTime.'.html">[ detail ]</a>'.'<br />';

        \helper\FileHelper::createFolder(Config::LOGGING_FOLDER, ROOT_PATH);

        \helper\FileHelper::createFolder($logDay, ROOT_PATH.Config::LOGGING_FOLDER);

        \helper\FileHelper::putContent($logDay.'.html', ROOT_PATH.Config::LOGGING_FOLDER, $content);

        \helper\FileHelper::putContent($detailTime.'.html', ROOT_PATH.Config::LOGGING_FOLDER.'/'.$logDay, implode('<br />', $trace));
    }
예제 #2
0
    /**
     * Generate HTML form
     * @param $className
     * @param $formAnnotations
     * @param $operationName
     * @param $formAction
     * @param $disabled
     * @param $submitCallback
     */
    protected function generateHtmlForm($className, $formAnnotations, $operationName, $formAction, $disabled = false, $submitCallback = null, $isJson = false) {
        $htmlForm = array();
        $className = strtolower($className);

        // FORM_ELEMENTS
        if ($formAnnotations) {
            $formElements = array();
            foreach ($formAnnotations as $formAnnotation) {
                $inputId = $className.'-'.$formAnnotation[Annotation::O_REFERS_TO];
                $label = '';
                $input = '';
                if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::SELECT) {
                    $fetchList = explode('.', $formAnnotation[Annotation::VALUES][Annotation::O_FETCH_LIST]);
                    $list = ReflectionHelper::getMethodResultFromName($fetchList[0], $fetchList[1]);
                    $optionList = array();
                    if (count($list) > 1) {
                        $optionList = array(0=>'Selecione');
                    }
                    foreach ($list as $item) {
                        $key = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_ID]));
                        $value = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_VALUE]));
                        $optionList[$key] = $value;
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createSelect($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    } else {
                        $input = HtmlHelper::createSelectDisabled($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    }

                } else if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::RADIO) {
                    $fetchList = explode('.', $formAnnotation[Annotation::VALUES][Annotation::O_FETCH_LIST]);
                    $list = ReflectionHelper::getMethodResultFromName($fetchList[0], $fetchList[1]);
                    $optionList = array();
                    foreach ($list as $item) {
                        $key = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_ID]));
                        $value = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_VALUE]));
                        $optionList[$key] = $value;
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createRadioList($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    } else {
                        p($optionList);
                    }

                } else if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::TEXTAREA) {
                    $value = $formAnnotation[Annotation::O_VALUE];
                    $input = HtmlHelper::createTextArea(
                            $inputId,
                            $inputId,
                            $formAnnotation[Annotation::VALUES][Annotation::O_COLS],
                            $formAnnotation[Annotation::VALUES][Annotation::O_ROWS],
                            $value
                    );

                } else {
                    $value = $formAnnotation[Annotation::O_VALUE];
                    $style = '';
                    if (isset($formAnnotation[Annotation::T_FORMAT]) && isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE])) {
                        if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_DATE) {
                            $style = 'formDate';
                            $pattern = '';
                            if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_JS])) {
                                $pattern = $formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_JS];
                            }
                            if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_PHP]) && \helper\StringHelper::isNotNull($value)) {
                                $value = DateHelper::getAsString($value, $formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_PHP]);
                            }
                            JavascriptManager::getInstance()->putCommand(JavascriptHelper::createDatePicker($inputId, $pattern));
                        } else if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_NUMBER) {
                            $style = 'formNumber';
                        }
                        if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK])) {
                            if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_DECIMAL) {
                                $style = 'formDecimal';
                                $mask = strrev($formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK]);
                                $mask = preg_replace('/[.]/', ',', $mask, 1);
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createMask($inputId, $mask, true));
                            } else {
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createMask($inputId, $formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK]));
                            }
                        }
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createInput(
                                $formAnnotation[Annotation::VALUES][Annotation::O_TYPE],
                                $inputId,
                                $inputId,
                                $value,
                                isset($formAnnotation[Annotation::VALUES][Annotation::O_MAX_LENGTH]) ? $formAnnotation[Annotation::VALUES][Annotation::O_MAX_LENGTH] : null,
                                null,
                                $style
                        );
                    } else {
                        $input = HtmlHelper::createInputDisabled(
                                $formAnnotation[Annotation::VALUES][Annotation::O_TYPE],
                                $value
                        );
                    }
                }
                if ($formAnnotation[Annotation::T_LABEL]) {
                    $label = HtmlHelper::createLabel(
                            $formAnnotation[Annotation::T_LABEL],
                            $inputId
                    );
                }
                if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::INPUT_TYPE_CHECKBOX) {
                    $formElements[$inputId] = array(self::FORM_INPUT => $label, self::FORM_LABEL => $input);

                } else {
                    $formElements[$inputId] = array(self::FORM_INPUT => $input, self::FORM_LABEL => $label);
                }
            }
            $htmlForm[self::FORM_ELEMENTS] = $formElements;
        }

        // FORM_PARAMS
        $formId = 'form-'.$className.'-'.strtolower($operationName);
        $htmlForm[self::FORM_PARAMS] = HtmlHelper::createFormParameters($formId, $formAction, 'POST', $submitCallback);

        // FORM SUBMIT
        $submitId = $formId.'-'.HtmlHelper::INPUT_TYPE_SUBMIT;
        if (!$isJson) {
            $htmlForm[self::FORM_SUBMIT] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_SUBMIT, $submitId, $submitId, ucfirst($operationName));
        } else {
            $htmlForm[self::FORM_SUBMIT] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_BUTTON, $submitId, $submitId, ucfirst($operationName));
            JavascriptManager::getInstance()->putCommand(JavascriptHelper::bindAjaxPostInClick($submitId, $formId));
        }

        // FORM CANCEL
        $cancelOperation = 'cancelar';
        $cancelId = $formId.'-'.$cancelOperation;
        $cancelCallback = JavascriptHelper::createLocationHrefChange(\App::getInstance()->getURIPrevious());
        $htmlForm[self::FORM_CANCEL] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_BUTTON, $cancelId, $cancelId, ucfirst($cancelOperation), null, $cancelCallback);

        return $htmlForm;
    }
예제 #3
0
    protected function extractListViewFromEntityList($entity, $listViewColumns, $list, ListViewControl $listViewControl, $showPaginator = false) {
        $listAnnotations = Annotation::extractAnnotations($entity);

        if (!$listAnnotations) {
            throw new AnnotationException(\core\Messages::CLASS_HAS_NO_ANNOTATIONS);

        } else if (!$listViewColumns) {
            throw new PresentationException('List of ListViewColumn is required');
        }

        // MAKE HEADER
        $header = array();
        foreach ($listViewColumns as $listViewColumn) {
            $headerLabel = '';
            foreach ($listAnnotations[Annotation::PROPERTIES] as $input=>$annotations) {
                if ($input == $listViewColumn->getName()) {
                    foreach ($annotations as $annotation) {
                        if ($annotation[Annotation::BEHAVIOR] == Annotation::T_LABEL) {
                            $headerLabel = $annotation[Annotation::VALUES][Annotation::O_VALUE];
                        } else if ($listViewColumn instanceof ListViewTextColumn) {
                            if ($annotation[Annotation::BEHAVIOR] == Annotation::T_INPUT) {
                                $listViewColumn->setType($annotation[Annotation::VALUES]);
                            }
                            if ($annotation[Annotation::BEHAVIOR] == Annotation::T_FORMAT) {
                                $listViewColumn->setFormat($annotation[Annotation::VALUES]);
                            }
                        }
                    }
                }
            }
            if ($headerLabel) {
                $linkOrderBy = null;
                if ($listViewColumn instanceof ListViewTextColumn) {
                    if ($listViewColumn->getOrderEnabled()) {
                        $linkOrderBy = $listViewControl->mountOrderByLink($listViewColumn->getName());
                    }
                }
                $header[] = array(HtmlHelper::ELEMENT_VALUE => $headerLabel, HtmlHelper::ELEMENT_LINK => $linkOrderBy);
            } else {
                $header[] = '';
            }
        }

        // MAKE CONTENT
        $content = array();
        foreach ($list as $item) {
            $row = array();
            foreach ($listViewColumns as $listViewColumn) {
                $type = null;
                $value = null;
                $link = null;
                $align = null;
                if ($listViewColumn instanceof ListViewTextColumn) {
                    $type = $listViewColumn->getType();
                    $format = $listViewColumn->getFormat();
                    $methodName = 'get'.ucfirst($listViewColumn->getName());
                    $value = ReflectionHelper::getMethodResultFromInstance($item, $methodName);
                    if (isset($format[Annotation::O_TYPE])) {
                        if ($format[Annotation::O_TYPE] == \helper\HtmlHelper::INPUT_FORMAT_DECIMAL) {
                            $value = \helper\StringHelper::convertToDecimal($value);
                            $align = 'right';
                        } else if ($format[Annotation::O_TYPE] == \helper\HtmlHelper::INPUT_FORMAT_DATE && isset($format[Annotation::O_PATTERN_PHP])) {
                            $value = \helper\DateHelper::getAsString($value, $format[Annotation::O_PATTERN_PHP]);
                            $align = 'center';
                        }
                        if (isset($format[Annotation::O_PREFIX])) {
                            $value = $format[Annotation::O_PREFIX].' '.$value;
                        }
                    }
                    $fetchEntity = null;
                    $fetchTypes = array(HtmlHelper::SELECT, HtmlHelper::RADIO);
                    if (in_array($type[Annotation::O_TYPE], $fetchTypes)) {
                        $fetch = preg_split('/\./', $type[Annotation::O_FETCH_ITEM]);
                        $fetchEntity = ReflectionHelper::getMethodResultFromName($fetch[0], $fetch[1], $value);
                        if ($fetchEntity) {
                            $value = ReflectionHelper::getMethodResultFromInstance($fetchEntity, 'get'.$type[Annotation::O_VALUE]);
                        } else {
                            $value = '-';
                        }
                    }
                    $callback = $listViewColumn->getCallback();
                    if ($callback) {
                        while (preg_match('/{(?P<element>.+?)}/', $callback, $matches)) {
                            $tempEntity = isset($fetchEntity) ? $fetchEntity : $item;
                            $param = ReflectionHelper::getMethodResultFromInstance($tempEntity, 'get'.ucfirst($matches['element']));
                            $callback = str_replace('{'.$matches['element'].'}', $param, $callback);
                        }
                        $link = $callback;
                    }
                } else if ($listViewColumn instanceof ListViewCommandColumn) {
                    $value = $listViewColumn->getName();
                    $callback = $listViewColumn->getCallback();
                    if ($callback) {
                        while (preg_match('/{(?P<element>.+?)}/', $callback, $matches)) {
                            $get = 'get'.ucfirst($matches['element']);
                            $param = ReflectionHelper::getMethodResultFromInstance($item, $get);
                            $callback = str_replace('{'.$matches['element'].'}', $param, $callback);
                        }
                        $link = $callback;
                    }
                }
                if ($link && strpos($link, 'http://') !== 0) {
                    $link = \App::getInstance()->getBasePrefix().$link;
                }
                $row[] = array(
                        HtmlHelper::ELEMENT_VALUE => $value,
                        HtmlHelper::ELEMENT_LINK => $link,
                        HtmlHelper::ELEMENT_TYPE => $type[Annotation::O_TYPE],
                        HtmlHelper::ELEMENT_ALIGN => $align
                );
            }
            $content[] = $row;
        }

        // MAKE PAGINATOR
        $paginator = null;
        if ($showPaginator) {
            $paginator = $listViewControl->makePagination();
        }

        return array(self::LIST_VIEW_HEADER => $header, self::LIST_VIEW_CONTENT => $content, self::LIST_VIEW_PAGINATOR => $paginator);
    }