Ejemplo n.º 1
0
 /**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param                         $name
  * @param                         $requestedName
  *
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     $gridType = trim(str_replace($this->_configPrefix, '', $requestedName), '\\');
     $config = $serviceLocator->get('Config');
     $gridConfig = $config['jqgrid'];
     if (array_key_exists('factories', $gridConfig)) {
         $util = new ArrayUtils();
         foreach ((array) $gridConfig['factories'] as $alias) {
             if ($serviceLocator->has($alias)) {
                 $addConfig = $serviceLocator->get($alias);
                 $gridConfig = $util->arrayMergeRecursiveCustom($gridConfig, $addConfig);
             }
         }
     }
     switch ($gridType) {
         case 'odm':
             $manager = $serviceLocator->get('doctrine.entitymanager.odm_default');
             $class = 'SynergyDataGrid\\Grid\\GridType\\DoctrineODMGrid';
             break;
         default:
             $manager = $serviceLocator->get('doctrine.entitymanager.orm_default');
             $class = 'SynergyDataGrid\\Grid\\GridType\\DoctrineORMGrid';
     }
     $grid = new $class($gridConfig, $serviceLocator, $manager);
     return $grid;
 }
Ejemplo n.º 2
0
 /**
  * Create Column object based on given options and add it to the grid
  *
  * @param string $columnTitle title of a column
  * @param array  $column      array of column options
  *
  * @return \SynergyDataGrid\Grid\GridType\BaseGrid
  */
 public function addColumn($columnTitle = '', $column = array())
 {
     if (is_array($column) && count($column) && array_key_exists('name', $column) && $columnTitle) {
         $columnName = $column['name'];
         $existingColumn = $this->getColumn($columnName);
         // if column with such a name already exists we will merge options and overwrite title with new one
         if ($existingColumn) {
             $utils = new ArrayUtils();
             $oldOptions = $existingColumn->getOptions();
             $newOptions = $utils->arrayMergeRecursiveCustom($oldOptions, $column);
             $columnObject = new Column($newOptions, $this);
         } else {
             $columnObject = new Column($column, $this);
         }
         $columnObject->setTitle($columnTitle);
         $this->_columns[$columnName] = $columnObject;
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Magic method to work with all object options without necessity to create tons of methods. Provide overloading features.
  *
  * @param $name
  * @param $arguments
  *
  * @return bool|mixed|Base
  * @throws \Exception
  */
 public function __call($name, $arguments)
 {
     $retv = true;
     // overload nonexistant set... methods to set particular object option
     if (substr($name, 0, 3) == 'set' && is_array($arguments) && count($arguments) == 1) {
         $value = $arguments[0];
         // overload nonexistant set...IfNotSet methods to set particular object option only if there is no such an option yet
         if (substr($name, -8) == 'IfNotSet') {
             $propertyName = lcfirst(substr($name, 3, strlen($name) - 11));
             $option = $this->getOption($propertyName);
             if (!$option) {
                 $this->setOption($propertyName, $value);
             }
         } else {
             $propertyName = lcfirst(substr($name, 3));
             $this->setOption($propertyName, $value);
         }
         // update ColModel array of option for jqGrid object
         if (substr(get_class($this), -7) == '\\Column') {
             $this->getGrid()->setColModel($this->getGrid()->getColumns());
         }
         $retv = $this;
         // overload nonexistant get... methods to get particular object option
     } elseif (substr($name, 0, 3) == 'get') {
         $retv = $this->getOption(lcfirst(substr($name, 3)));
         // overload nonexistant merge... methods to merge option arrays
     } elseif (substr($name, 0, 5) == 'merge' && is_array($arguments) && count($arguments) == 1) {
         $utils = new ArrayUtils();
         $methodGet = 'get' . ucfirst(substr($name, 5));
         $methodSet = 'set' . ucfirst(substr($name, 5));
         $oldParameters = $this->{$methodGet}();
         if (gettype($oldParameters) == 'object') {
             /** @var $oldParameters \SynergyDataGrid\Grid\Property */
             $oldParameters = $oldParameters->getOptions();
         } else {
             if (!is_array($oldParameters)) {
                 $oldParameters = array();
             }
         }
         /** @var $oldParameters array */
         $this->{$methodSet}($utils->arrayMergeRecursiveCustom($oldParameters, $arguments[0]));
         // throw an exception if method name doesn't match any known pattern
     } elseif (!method_exists($this, $name)) {
         throw new \Exception(sprintf('The required method "%s" does not exist for %s', $name, get_class($this)));
     }
     return $retv;
 }
Ejemplo n.º 4
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;
 }