Exemplo n.º 1
0
 /**
  * Camelize string
  *
  * @param  string   $value
  * @param  string   $separator          default: "-"
  * @param  bool     $firstCharIsLower   default: null
  *
  * @return string
  */
 public static function camelize($value, $separator = null, $firstCharIsLower = null)
 {
     static $filter = null;
     if (null === $filter) {
         $filter = new Word\SeparatorToCamelCase();
     }
     if (null === $firstCharIsLower) {
         $firstCharIsLower = lcfirst($value) === $value;
     }
     $filtered = $filter->setSeparator($separator ?: self::DEFAULT_SEPARATOR)->filter($value);
     if (true === $firstCharIsLower) {
         $filtered = lcfirst($filtered);
     } else {
         if (false === $firstCharIsLower) {
             $filtered = ucfirst($filtered);
         }
     }
     return $filtered;
 }
Exemplo n.º 2
0
 /**
  * Binds the grid to the database entity and assigns an ID to the grid
  *
  * @param        $entityClassName
  * @param string $gridId
  * @param null   $idSuffix When display multiple grids on the same entity, use to make the gridId unique
  * @param bool   $displayTree
  * @param array  $queryParams
  *
  * @return $this
  */
 public function setGridIdentity($entityClassName, $gridId = '', $idSuffix = null, $displayTree = true, $queryParams = array())
 {
     $this->setEntityId($gridId);
     $this->setId($gridId . $idSuffix);
     $this->setEntity($entityClassName);
     $this->setService($this->getServiceLocator());
     $filter = new SeparatorToCamelCase('-');
     $configKey = lcfirst($filter->filter($gridId));
     $config = $this->getConfig();
     $utils = new ArrayUtils();
     if ($displayTree) {
         $mapping = $this->getEntityManager()->getClassMetadata($this->getEntity());
         if ('Gedmo\\Tree\\Entity\\Repository\\NestedTreeRepository' == $mapping->customRepositoryClassName) {
             $this->setTreeGrid(true);
             $this->isTreeGrid = true;
             //Set tree grid options
             $treeOptions = isset($config['tree_grid_options']) ? $config['tree_grid_options'] : array();
             $treeOptions['rownumbers'] = false;
             $config['grid_options'] = $utils->arrayMergeRecursiveCustom($config['grid_options'], $treeOptions);
         }
     }
     /**
      * Merge grid specific configurations
      */
     if (isset($config[$configKey])) {
         $config['grid_options'] = $utils->arrayMergeRecursiveCustom($config['grid_options'], $config[$configKey]);
     }
     /**
      * Merge column model overrides
      */
     if (isset($config['column_model_override'][$configKey])) {
         $config['column_model'] = $utils->arrayMergeRecursiveCustom($config['column_model'], $config['column_model_override'][$configKey]);
     }
     /**
      * Set default crud route
      */
     /** @var $service \SynergyDataGrid\Service\GridService' */
     $service = $this->getServiceLocator()->get('synergy\\service\\grid');
     $entityKey = $service->getEntityKeyFromClassname($entityClassName);
     $crudUrl = $this->getCrudUrl($entityKey, $queryParams);
     if (!empty($config['api_domain'])) {
         $crudUrl = rtrim($config['api_domain'], '/') . '/' . ltrim($crudUrl, '/');
         //disable local data
         $config['first_data_as_local'] = false;
     }
     $this->setUrl($crudUrl);
     $this->setSubGridUrl($crudUrl);
     /**
      * Set grid caption
      */
     if (!($caption = $this->getCaption())) {
         $this->setCaption(ucwords(str_replace('-', ' ', $entityKey)));
     }
     if (!empty($config['grid_options']['onSelectRow']) && is_string($config['grid_options']['onSelectRow'])) {
         $config['grid_options']['onSelectRow'] = new Expr($config['grid_options']['onSelectRow']);
     }
     $this->setConfig($config);
     return $this;
 }