/** * @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); }
/** * @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 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 swipeDataKey($key) { $ar = Arr::getDoubtField($this->getData(), $key, []); unset($this->_data[$key]); return $ar; }
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; }
/** * @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; }
/** * @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); }