Example #1
0
 /**
  * Decamelize string
  *
  * @param  string   $value
  * @param  string   $separator    default: "-"
  *
  * @return string
  */
 public static function decamelize($value, $separator = null)
 {
     static $filter = null;
     if (null === $filter) {
         $filter = new Word\CamelCaseToSeparator();
     }
     $filtered = $filter->setSeparator($separator ?: self::DEFAULT_SEPARATOR)->filter($value);
     return mb_strtolower($filtered, self::DEFAULT_ENCODING);
 }
Example #2
0
 /**
  * List all modules
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function indexAction()
 {
     $collection = new ModuleCollection();
     $filter = new Filter\Word\CamelCaseToSeparator();
     $filter->setSeparator('-');
     $filterChain = new Filter\FilterChain();
     $filterChain->attach($filter)->attach(new Filter\StringToLower());
     foreach ($collection->getModules() as $module) {
         $module->setData('route', $filterChain->filter($module->getName()));
     }
     return array('modules' => $collection->getModules());
 }
Example #3
0
 /**
  * Load menu if module has view with name "menu.phtml"
  *
  * @param EventInterface $event Event
  *
  * @return void
  */
 public function loadMenu(EventInterface $event)
 {
     if ($route = $event->getRouter()->getRoute('module')->match($event->getRequest())) {
         if ($route->getParam('module') === 'module') {
             return;
         }
         $filter = new Filter\Word\CamelCaseToSeparator();
         $filter->setSeparator('-');
         $filterChain = new Filter\FilterChain();
         $filterChain->attach($filter)->attach(new Filter\StringToLower());
         $template = $filterChain->filter($route->getParam('module')) . '/menu';
         $target = $event->getTarget();
         $resolver = $event->getApplication()->getServiceManager()->get('Zend\\View\\Resolver\\TemplatePathStack');
         $navigation = $target->getServiceLocator()->get('navigation');
         $navigation->findByRoute('module')->addPage(array('label' => $route->getParam('module'), 'route' => $event->getRouteMatch()->getMatchedRouteName(), 'active' => true));
         if (false !== $resolver->resolve($template)) {
             $target->layout()->setVariable('moduleMenu', $template);
         }
     }
 }
 public function generate(\VisioCrudModeler\Generator\ParamsInterface $params)
 {
     $this->params = $params;
     $descriptor = $this->params->getParam("descriptor");
     if (!$descriptor instanceof \VisioCrudModeler\Descriptor\ListGeneratorInterface) {
         return;
     }
     $camelCaseToSeparator = new CamelCaseToSeparator('-');
     $moduleName = strtolower($this->params->getParam("moduleName"));
     @mkdir($this->moduleRoot() . "/view/", 0777);
     $viewClassFilePath = $this->moduleRoot() . "/view/" . strtolower($camelCaseToSeparator->filter($this->params->getParam("moduleName")));
     @mkdir($viewClassFilePath, 0777);
     foreach ($descriptor->listGenerator() as $name => $dataSet) {
         $className = $this->underscoreToCamelCase->filter($name);
         $viewName = strtolower($camelCaseToSeparator->filter($className));
         $viewFilePath = $this->moduleRoot() . "/view/" . $moduleName . "/" . $viewName;
         @mkdir($viewFilePath, 0777);
         $this->generateView($viewName, $viewFilePath, $moduleName);
         $this->console(sprintf('writing generated view for "%s" table', $viewName));
     }
 }
 /**
  * returns values map for template according to given dataSet
  *
  * @param DataSetDescriptorInterface $dataSet
  * @return array
  */
 protected function prepareTemplateSubstitutionData(DataSetDescriptorInterface $dataSet)
 {
     $name = $dataSet->getName();
     $data = array();
     if ($this->params->getParam('runtimeConfiguration') instanceof Config) {
         $runtime = (array) $this->params->getParam('runtimeConfiguration')->toArray();
         $data['%table%'] = $runtime['model'][$name]['table'];
         $data['%model%'] = $runtime['model'][$name]['model'];
         $data['%form%'] = $runtime['form'][$name]['form'];
         $data['%filter%'] = $runtime['inputFilter'][$name]['filter'];
         $data['%grid%'] = $runtime['form'][$name]['grid'];
         $data['%filteredModule%'] = strtolower($this->params->getParam('moduleName'));
         $data['%filteredController%'] = strtolower($this->camelCasToSeparator->filter($this->underscoreToCamelCase->filter($dataSet->getName())));
         $data['%adapterKey%'] = $this->params->getParam('adapterServiceKey');
     }
     return $data;
 }
 /**
  * @param $name
  * @param $type
  * @return string
  */
 private function createControl($name, $type, $length = 0, $isPrimary = false)
 {
     $isForeign = !$isPrimary && strpos($name, 'Id') && $type == 'int';
     $toCamelCase = new UnderscoreToCamelCase();
     $var = lcfirst($toCamelCase->filter($name));
     $toSeperator = new CamelCaseToSeparator(array(" "));
     $label = $toSeperator->filter($toCamelCase->filter($name));
     $code = '';
     if ($isPrimary) {
         $code .= "\t\${$var} = new Element\\Hidden('{$name}');\n";
     } else {
         if ($isForeign) {
             $code .= "\t\${$var} = new Element\\Select('{$name}');\n";
             $code .= "\t\${$var}->setAttribute('class', 'form-control');\n";
         } else {
             if (in_array($type, $this->typeNum) || in_array($type, $this->typeFloat)) {
                 $code .= "\t\${$var} = new Element\\Number('{$name}');\n";
                 if (in_array($type, $this->typeNum)) {
                     $code .= "\t\${$var}->setAttributes(array(\n";
                     $code .= "\t\t'min' => '0',\n";
                     $code .= "\t\t'max' => '99999999999',\n";
                     $code .= "\t\t'step' => '1',\n";
                     $code .= "\t));\n";
                 } elseif (in_array($type, $this->typeNum)) {
                     $code .= "\t\${$var}->setAttributes(array(\n";
                     $code .= "\t\t'min' => '0',\n";
                     $code .= "\t\t'max' => '99999999999',\n";
                     $code .= "\t\t'step' => '0.5',\n";
                     $code .= "\t));\n";
                 }
             } else {
                 if (in_array($type, $this->typeDate)) {
                     $code .= "\t\${$var} = new Element\\Date('{$name}');\n";
                     $code .= "\t\${$var}->setAttributes(array(\n";
                     $code .= "\t\t'allowPastDates' => true,\n";
                     $code .= "\t\t'momentConfig' => array('format' => 'YYYY-MM-DD'),\n";
                     $code .= "\t));\n";
                 } else {
                     if ($length >= 500) {
                         $code .= "\t" . '$' . $var . " = new Element\\Textarea('{$name}');\n";
                     } else {
                         $code .= "\t" . '$' . $var . " = new Element\\Text('{$name}');\n";
                     }
                     $code .= "\t\${$var}->setAttribute('class', 'form-control');\n";
                 }
             }
         }
     }
     if (!$isPrimary) {
         $code .= "\t\${$var}->setLabel('{$label}');\n";
     }
     $code .= "\t\$form->add(\${$var});\n";
     return $code;
 }
Example #7
0
 /**
  * Add given columns to the grid
  *
  * @param array $columns array of columns
  *
  * @return \SynergyDataGrid\Grid\GridType\BaseGrid
  */
 public function addColumns($columns = array())
 {
     $nameFilter = new CamelCaseToSeparator();
     if (is_array($columns) && count($columns)) {
         foreach ($columns as $column) {
             $title = ucwords($nameFilter->filter($column['name']));
             $this->addColumn($title, $column);
         }
         $this->setColNames($this->_columns);
         $this->setColModel($this->_columns);
     }
     return $this;
 }
 protected function generateViews()
 {
     $oViewGenerator = $this->getDi()->get('ZeDoGenerator\\Service\\Generators\\ViewGenerator');
     $oViewGenerator->setMetadata($this->getMetadata()[0]);
     $oViewGenerator->setRoute($this->getNamespace());
     //setting correct syntax
     $filter = new CamelCaseToSeparator('-');
     $sFilteredNamespace = strtolower($filter->filter($this->getNamespace()));
     $oViewGenerator->setFilePath($this->getFilePath() . '/view/' . $sFilteredNamespace . '/' . $sFilteredNamespace);
     $oViewGenerator->generateView('index');
     $oViewGenerator->generateView('add');
     $oViewGenerator->generateView('edit');
     $oViewGenerator->generateView('delete');
 }