Exemple #1
0
    public function siteMap() {
        try {
            $presentationClasses = \helper\FolderHelper::listFilesByType(PAPRIKA_CUSTOM_PATH.'/'.Config::CUSTOM_CODE_PRESENTATION, '.php', true);

            echo '<ul>'.PHP_EOL;

            foreach ($presentationClasses as $class) {
                echo '<li>'.$class.'</li>';

                $listAnnotation = \annotation\Annotation::extractAnnotations($class);
                if (isset($listAnnotation[\annotation\Annotation::CLAZZ])) {
                    foreach ($listAnnotation[\annotation\Annotation::CLAZZ] as $annotation) {
                        if ($annotation[\annotation\Annotation::BEHAVIOR] == \annotation\Annotation::T_ROUTE
                                && $annotation[\annotation\Annotation::VALUES][\annotation\Annotation::O_TYPE] == 'static') {
                            if (isset($annotation[\annotation\Annotation::VALUES][\annotation\Annotation::O_ROLE]))
                                continue;
                            if (isset($annotation[\annotation\Annotation::VALUES][\annotation\Annotation::O_CONTENT_TYPE])
                                    && $annotation[\annotation\Annotation::VALUES][\annotation\Annotation::O_CONTENT_TYPE] == 'json')
                                continue;
                            $link = $annotation[\annotation\Annotation::VALUES][\annotation\Annotation::O_MAPPER];
                            $basePrefix = preg_replace('/\/sitemap.php$/', '', $_SERVER['SCRIPT_NAME']);
                            echo '<li style="margin-left: 25px; list-style: circle"><a href="'.$basePrefix.$link.'">'.$link.'</a></li>';
                        }
                    }
                }
            }

            echo '</ul>'.PHP_EOL;

        } catch (\Exception $e) {
            p($e);
        }
    }
 /**
  * Initialize the annotation.
  */
 public function initAnnotation($properties)
 {
     $this->_map($properties, array('type'));
     parent::initAnnotation($properties);
     if (!isset($this->type)) {
         throw new AnnotationException('VarAnnotation requires a type property');
     }
     $this->type = strtolower($this->type);
 }
 protected function generateUniqueMessages($entity, $messages = null, $identityProperty = null) {
     $listAnnotations = Annotation::extractAnnotations($entity);
     if ($messages == null) {
         $messages = array();
     }
     if ($listAnnotations[Annotation::PROPERTIES]) {
         $listBusinessRules = array(Annotation::T_UNIQUE);
         foreach ($listAnnotations[Annotation::PROPERTIES] as $property=>$annotations) {
             foreach ($annotations as $annotation) {
                 if (in_array($annotation[Annotation::BEHAVIOR], $listBusinessRules)) {
                     $value = ReflectionHelper::getMethodResultFromInstance($entity, 'get'.ucfirst($property));
                     $check = explode('.', $annotation[Annotation::VALUES][Annotation::O_CHECK]);
                     $result = \helper\ReflectionHelper::getMethodResultFromName($check[0], $check[1], $value);
                     if (isset($result) && count($result) > 0) {
                         $showMessage = true;
                         if (\helper\StringHelper::isNotNull($identityProperty)) {
                             $tmpProp = 'get'.ucfirst($identityProperty);
                             $simpleResult = null;
                             if (is_array($result)) {
                                 $simpleResult = $result[0];
                             } else {
                                 $simpleResult = $result;
                             }
                             if (\helper\ReflectionHelper::getMethodResultFromInstance($entity, $tmpProp) == \helper\ReflectionHelper::getMethodResultFromInstance($simpleResult, $tmpProp)) {
                                 $showMessage = false;
                             }
                         }
                         if ($showMessage) {
                             $messages[$property] = $annotation[Annotation::VALUES][Annotation::O_MESSAGE];
                         }
                     }
                 }
             }
         }
     }
     if (!count($messages)) {
         return null;
     }
     return $messages;
 }
Exemple #4
0
    private function findMapping($presentationClasses, $requestURI) {
        $queryString = $this->getQueryString();

        foreach ($presentationClasses as $className) {
            $listAnnotation = \annotation\Annotation::extractAnnotations($className);
            if (isset($listAnnotation[\annotation\Annotation::CLAZZ])) {
                foreach ($listAnnotation[\annotation\Annotation::CLAZZ] as $annotation) {
                    if ($annotation[Annotation::BEHAVIOR] == Annotation::T_ROUTE) {
                        if ($annotation[Annotation::VALUES][Annotation::O_TYPE] == 'static' && $annotation[Annotation::VALUES][Annotation::O_MAPPER] == $requestURI)  {
                            $reflectionClass = new \ReflectionClass($className);
                            $classInstance = $reflectionClass->newInstance();
                            if (!method_exists($classInstance, $annotation[Annotation::VALUES][Annotation::O_METHOD])) {
                                $annotation[Annotation::VALUES][Annotation::O_METHOD] = 'main';
                            }
                            $this->invokeMappingClass($classInstance, $annotation, $queryString, $requestURI);
                            return true;

                        } else if ($annotation[Annotation::VALUES][Annotation::O_TYPE] == 'dynamic') {
                            $var = addcslashes($annotation[Annotation::VALUES][Annotation::O_MAPPER], '/.');
                            $var = '/^'.$var.'$/';
                            $var = str_replace('?', '\?', $var);
                            $var = str_replace('{', '(?\'p', $var);
                            $var = str_replace('}', '\'([^\/])+?)', $var);
                            if (preg_match($var, $requestURI, $matches, PREG_OFFSET_CAPTURE)) {
                                $reflectionClass = new \ReflectionClass($className);
                                $classInstance = $reflectionClass->newInstance();
                                if (method_exists($classInstance, $annotation[Annotation::VALUES][Annotation::O_METHOD])) {
                                    $urlParams = array();
                                    foreach ($matches as $key=>$value) {
                                        if (strstr($key, 'p')) {
                                            $urlParams[substr($key, 1, strlen($key))] = $value[0];
                                        }
                                    }
                                    $this->invokeMappingClass($classInstance, $annotation, $queryString, $requestURI, $urlParams);
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }

        return false;
    }
 /**
  * Initialize the annotation.
  */
 public function initAnnotation($properties)
 {
     $this->_map($properties, array('order'));
     parent::initAnnotation($properties);
 }
    public function delete($entity, $usesTransaction) {
        try {
            $listAnnotations = Annotation::extractAnnotations($this->entity);
            $sql = $this->mountDeleteById($listAnnotations);
            $params = $this->prepareParameters($this::OPERATION_DELETE, $listAnnotations, $this->entity);
            $statement = $this->getConnection()->prepare($sql);
            foreach ($params as $key=>$value) {
                $statement->bindValue($key, $value);
            }
            $statement->execute();

        } catch (\core\exception\RepositoryException $e) {
            throw $e;

        } catch (\Exception $e) {
            throw new RepositoryException($e);
        }
    }
 /**
  * Cast Request info Entity, using SET defined properties;
  * @param AnnotatedEntity $entity
  * @param $request
  */
 protected function castRequestToEntity($entity, $request) {
     if ($request) {
         $listAnnotations = Annotation::extractAnnotations($entity);
         foreach ($request as $key=>$value) {
             $entityKey = preg_split('/[-]/', $key);
             if (count($entityKey) > 1) {
                 $method = 'set'.ucfirst($entityKey[1]);
                 if (method_exists($entity, $method)) {
                     foreach ($listAnnotations[Annotation::PROPERTIES][$entityKey[1]] as $annotation) {
                         if ($annotation[Annotation::BEHAVIOR] == Annotation::T_INPUT) {
                             if (isset($annotation[Annotation::VALUES][Annotation::T_FORMAT]) && \helper\StringHelper::isNotNull($value)) {
                                 if ($annotation[Annotation::VALUES][Annotation::T_FORMAT] == \helper\HtmlHelper::INPUT_FORMAT_DATE) {
                                     $value = \helper\DateHelper::invertDate($value);
                                     $value = \helper\DateHelper::getAsString($value, \helper\DateHelper::DT_MYSQL);
                                 } else if ($annotation[Annotation::VALUES][Annotation::T_FORMAT] == \helper\HtmlHelper::INPUT_FORMAT_NUMBER) {
                                     // TODO Fazer algo
                                 } else if ($annotation[Annotation::VALUES][Annotation::T_FORMAT] == \helper\HtmlHelper::INPUT_FORMAT_DECIMAL) {
                                     $value = \helper\StringHelper::convertFromDecimal($value);
                                 }
                             }
                             break;
                         }
                     }
                     $reflectionMethod = new \ReflectionMethod($entity, $method);
                     $reflectionMethod->invoke($entity, $value);
                     continue;
                 }
                 if ($entityKey[1] == 'confirm') {
                     $tmpKey = 'confirm'.$entityKey[2];
                     $entity->$tmpKey = $value;
                 }
             }
         }
     }
 }
    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);
    }