/**
  * @param string             $name
  * @param DataModelInterface $model
  *
  * @return null|MongoGateway
  * @throws \Exception
  */
 public function getGateway($name, DataModelInterface $model = null)
 {
     if ($model == null) {
         throw new \Exception(' Raw Gateway needs a DataModelInterface instance as the second parameter ');
     }
     $adapterConfig = $this->getConfig($model);
     $gwName = Arr::getDoubtField($adapterConfig, 'gateway', null);
     if ($gwName === null) {
         $gwName = Arr::getDoubtField($adapterConfig, 'driver', null);
     }
     if ($gwName === null) {
         throw new \Exception('Unknown gateway');
     }
     // create resultSet prototype
     $resultSetPrototype = new ResultSet();
     $resultSetPrototype->setArrayObjectPrototype($model);
     // create custom transport for the model
     $dbAdapter = $this->getServiceLocator()->get($model->_adapter);
     // use general gw class
     if ($gwName == 'Pdo') {
         throw new \Exception(' TODO: Needs to implement PDO Gateway create !! ');
     }
     $gw = Obj::create('\\ModelFramework\\GatewayService\\MongoGateway', ['table' => $model->getTableName(), 'adapter' => $dbAdapter, 'resultSetPrototype' => $resultSetPrototype]);
     return $gw;
 }
 /**
  * @param \SplSubject|Query $subject
  *
  * @return string
  */
 public function update(\SplSubject $subject)
 {
     $this->setSubject($subject);
     $data = ['params' => [], 'column' => []];
     $order = [];
     $queryConfig = $subject->getQueryConfig();
     //        $defaults    = $queryConfig->order;
     $defaults = $this->getRootConfig();
     $sort = null;
     $s = null;
     if ($subject->getParams() !== null) {
         $sort = $subject->getParam('sort', null);
         $s = $subject->getParam('desc', null);
     }
     if ($sort === null || !in_array($sort, $queryConfig->fields)) {
         $sort = Arr::getDoubtField($defaults, 'sort', null);
         if ($sort === null) {
             return '';
         }
     } else {
         $data['params']['sort'] = $sort;
     }
     if ($s === null) {
         $s = Arr::getDoubtField($defaults, 'desc', 0);
     } else {
         $data['params']['desc'] = $s;
     }
     $order[$sort] = $s == 1 ? 'desc' : 'asc';
     $subject->setOrder($order);
     $data['column']['sort'] = $sort;
     $data['column']['desc'] = $s;
     $subject->setData($data);
 }
 public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = Arr::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
 }
 public function addParsedConfig(array $a)
 {
     $parsedFormConfig = $this->getParsedFormConfig();
     if ($parsedFormConfig === null) {
         $parsedFormConfig = new ParsedFormConfig();
     }
     $conf = $parsedFormConfig->toArray();
     $newConf = Arr::merge($conf, $a);
     $parsedFormConfig->exchangeArray($newConf);
     return $this->setParsedFormConfig($parsedFormConfig);
 }
 public function update(\SplSubject $subject)
 {
     /** @var ModelConfigParser $subject */
     $this->setSubject($subject);
     $modelConfig = $subject->getModelConfig();
     $config = [];
     // process fields
     foreach ($modelConfig->fields as $field_name => $field_conf) {
         $config = Arr::merge($config, $this->createField($field_name, $field_conf));
     }
     $subject->addParsedConfig($config);
 }
 /**
  * @param string $domain
  * @param string $key
  * @param null   $subKey
  * @param array  $default
  *
  *
  * @return null
  */
 public function getConfigDomainPart($domain, $key, $subKey = null, $default = [])
 {
     $domainConfig = Arr::getDoubtField($this->getConfigPart($domain), $key, $default);
     if ($subKey !== null) {
         $subConfig = Arr::getDoubtField($domainConfig, $subKey, $default);
         //            if ( $subConfig === $default && strtolower($subKey)!==$subKey )
         //            {
         //                $keyMap = [];
         //                foreach (  array_keys($domainConfig) as $_key )
         //                {
         //                    $keyMap[ strtolower($_key) ] = $_key;
         //                }
         //                $subConfig = Arr::getDoubtField( $domainConfig, $keyMap[ strtolower($subKey) ], $default );
         //            }
         $domainConfig = $subConfig;
     }
     return $domainConfig;
 }
 public function process($aclModel)
 {
     $model = $this->getModelData();
     $subject = $this->getSubject();
     $viewConfig = $subject->getViewConfigVerify();
     $logic = $subject->getLogicServiceVerify()->get('convert', $model->getModelName());
     if ($subject->getParamsVerify()->fromPost('object_id', null) !== null) {
         $logic->setData(['save' => true]);
     }
     $logic->trigger($model);
     if (Arr::getDoubtField($logic->getData(), 'save', false)) {
         $url = $subject->getBackUrl();
         if ($url == null || $url == '/') {
             $url = $subject->getParams()->getController()->url()->fromRoute('common', ['data' => strtolower($viewConfig->model), 'view' => 'list']);
         }
         $subject->setRedirect($subject->refresh($model->getModelName() . ' data was successfully converted', $url));
     }
 }
 public function s(FieldConfigInterface $conf, FieldTypeInterface $_fieldType)
 {
     $_fieldSets = [];
     $_joins = [];
     $_fieldType->label = isset($conf->label) ? $conf->label : ucfirst($this->getName());
     if (isset($conf->group)) {
         $_fieldSets[$conf->group]['elements'][$this->getName()] = $_fieldType->label;
         $_fieldType->group = $conf->group;
     }
     //FIXME this does not work for lookup fields, only for source fields. Need update.
     $_fieldType->default = isset($conf->default) ? $conf->default : '';
     $_fieldType->source = $this->getName();
     $_fields = [$this->getName() => $_fieldType->toArray()];
     $_labels = [$this->getName() => $_fieldType->label];
     $_fields = Arr::merge($_fields, [$this->getName() . '_id' => ['type' => 'field', 'fieldtype' => 'source', 'datatype' => 'string', 'default' => 0, 'label' => '']]);
     $result = ['labels' => $_labels, 'fields' => $_fields, 'joins' => $_joins, 'fieldsets' => $_fieldSets];
     return $result;
 }
 /**
  * @param $model
  *
  * @return array
  * @throws \Exception
  */
 public function getAvailableIndexes($model)
 {
     $modelConfig = $this->getModelConfig($model);
     $indexes = [];
     foreach ($modelConfig['fields'] as $_key => $_field) {
         if ($_key == '_id' || $_field['datatype'] == 'array' || $_field['type'] == 'source') {
             continue;
         }
         /**
          * if we want to index all text field in text search
          */
         /**
          * if ($_field['type'] == 'field' && $_field['datatype'] == 'string') {
          * $indexes = Arr::put2ArrayKey($indexes, 'text', [$_key => 'text']);
          * }
          */
         if ($_key == 'title') {
             $indexes = Arr::put2ArrayKey($indexes, 'text', [$_key => 'text']);
         }
         /**
          * end
          */
         if ($_field['fieldtype'] == 'textarea') {
             continue;
         }
         $indexes = Arr::put2ArrayKey($indexes, 'idx_' . $_key, [$_key => 1]);
     }
     return $indexes;
 }
Example #10
0
 public function setOrder(array $order)
 {
     $this->_order = Arr::merge($this->_order, $order);
     return $this;
 }
 public function saveConfigToDbByObject(DataModelInterface $configObject)
 {
     $configArray = Arr::getDoubtField($this->getConfigPart($configObject->getModelName()), 'custom', []);
     foreach ($configArray as $config) {
         $object = clone $configObject;
         $object->exchangeArray($config);
         $this->getGatewayServiceVerify()->get($configObject->getModelName(), $configObject)->save($object);
     }
     return $this;
 }
Example #12
0
 public function setData(array $data)
 {
     $this->_data = Arr::merge($this->_data, $data);
 }
Example #13
0
 /**
  * @return $this|void
  * @throws \Exception
  */
 public function process()
 {
     $this->setDataFields();
     $params = [];
     foreach ($this->getViewBoxConfigVerify()->blocks as $blockName => $viewNames) {
         foreach ($viewNames as $viewName) {
             $modelView = $this->getViewServiceVerify()->get($viewName);
             $modelView->setParams($this->getParamsVerify());
             $modelView->process();
             if (!$modelView->isAllowed()) {
                 continue;
             }
             if ($modelView->hasRedirect()) {
                 $this->setRedirect($modelView->getRedirect());
                 return;
             }
             if ($modelView->hasResponse()) {
                 $this->setResponse($modelView->getResponse());
                 return;
             }
             $data = $modelView->getData();
             $vParams = Arr::getDoubtField($data, 'params', []);
             if (count($vParams)) {
                 $params = Arr::merge($params, $vParams);
             }
             $viewResults = ['data' => [$blockName => [$viewName => $modelView->getData()]]];
             $this->setData($viewResults);
         }
     }
     $params['data'] = strtolower($this->getViewBoxConfigVerify()->document);
     $params['view'] = strtolower($this->getViewBoxConfigVerify()->mode);
     $this->setData(['viewboxparams' => $params, 'user' => $this->getAuthServiceVerify()->getUser()]);
     return $this;
 }
 public function addParsedConfig(array $a)
 {
     return $this->setParsedFieldConfig(Arr::merge($this->getParsedFieldConfig(), $a));
 }
 /**
  * @param DataModel $model
  *
  * @throws \Exception
  */
 public function saveModel($model, $mode)
 {
     /**
      * @var Logic $subject
      */
     $subject = $this->getSubject();
     if (!Arr::getDoubtField($subject->getData(), 'save', false)) {
         return;
     }
     //        $mode = 'insert';
     //        if ( $model->id() !== '' )
     //        {
     //            $mode = 'update';
     //        }
     $subject->getLogicServiceVerify()->get('pre' . $mode, $model->getModelName())->trigger($model);
     $subject->getGatewayServiceVerify()->get($model->getModelName(), $model)->save($model);
     $subject->getLogicServiceVerify()->get('post' . $mode, $model->getModelName())->trigger($model);
 }