本文整理汇总了PHP中SplSubject::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP SplSubject::setData方法的具体用法?PHP SplSubject::setData怎么用?PHP SplSubject::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplSubject
的用法示例。
在下文中一共展示了SplSubject::setData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* @param \SplSubject|View $subject
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$query = $subject->getQueryServiceVerify()->get($viewConfig->query)->setParams($subject->getParams())->process();
$subject->setData($query->getData());
$data = $subject->getData();
foreach (['actions', 'links'] as $datapartam) {
foreach ($data[$datapartam] as $key => $link) {
foreach (['routeparams', 'queryparams'] as $keyparams) {
foreach ($link[$keyparams] as $paramkey => $param) {
if ($param[0] == ':') {
$data[$datapartam][$key][$keyparams][$paramkey] = $subject->getParam(substr($param, 1), '');
}
}
}
}
}
$subject->setData(['actions' => $data['actions'], 'links' => $data['links']]);
$result['paginator'] = $subject->getGatewayVerify()->getPages([], $query->getWhere(), $query->getOrder());
if ($result['paginator']->count() > 0) {
$result['paginator']->setCurrentPageNumber($subject->getParam('page', 1))->setItemCountPerPage($viewConfig->rows);
}
$subject->getLogicServiceVerify()->get('prelist', $viewConfig->model)->trigger($result['paginator']->getCurrentItems());
$subject->getLogicServiceVerify()->get('postlist', $viewConfig->model)->trigger($result['paginator']->getCurrentItems());
$result['rows'] = [5, 10, 25, 50, 100];
$result['params'] = ['data' => strtolower($viewConfig->model), 'view' => $viewConfig->mode];
$subject->setData($result);
}
示例2: update
/**
* @param \SplSubject|View $subject
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$query = $subject->getQueryServiceVerify()->get($viewConfig->query)->setParams($subject->getParams())->process();
$subject->setData($query->getData());
$model = $subject->getGatewayServiceVerify()->get($viewConfig->model)->find($query->getWhere());
if (!$model->count()) {
return;
}
foreach ($model as $row) {
$result['selectlinks'][] = ['route' => 'common', 'label' => $row->title, 'routeparams' => ['view' => $viewConfig->params['view'], 'data' => $subject->getParams()->fromRoute('data')], 'queryparams' => ['id' => $subject->getParams()->fromRoute('id'), 'template' => $row->_id]];
}
$subject->setData($result);
}
示例3: update
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$query = $subject->getQueryServiceVerify()->get($viewConfig->query)->setParams($subject->getParams())->process();
$subject->setData($query->getData());
$result = [];
$model = $subject->getGatewayVerify()->findOne($query->getWhere());
if (!$model) {
$result['data'] = 'Sorry, some error occured. We can\'t display message. Ask administrator';
} else {
$result['data'] = $model->text;
}
// $data = $subject->getData();
$subject->setData($result);
}
示例4: update
public function update(\SplSubject $subject)
{
$this->allow_models[] = 'Account';
$this->allow_models[] = 'Order';
$this->allow_models[] = 'OrderDetail';
$this->allow_models[] = 'Lead';
$this->allow_models[] = 'Patient';
$this->allow_models[] = 'User';
$Recipient_id = $subject->getParam('recipient', 0);
if ($Recipient_id) {
$dataModel = $subject->getGatewayServiceVerify()->get('Email')->findOne(['model_id' => $Recipient_id]);
if ($dataModel) {
$this->allow_models[] = ucfirst($dataModel->data);
}
}
if (!is_array($this->allow_models)) {
return;
}
foreach ($this->allow_models as $model) {
$visibleFields['pattern_items'][$model] = $subject->getAclServiceVerify()->getVisibleFields($model);
}
/* Copy current recipient data to array 'Contacts' */
if (isset($dataModel)) {
$visibleFields['pattern_items']['Contacts'] = $visibleFields['pattern_items'][ucfirst($dataModel->data)];
}
$subject->setData($visibleFields);
}
示例5: update
/**
* @param \SplSubject|View $subject
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$query = $subject->getQueryServiceVerify()->get($viewConfig->query)->setParams($subject->getParams())->process();
$subject->setData($query->getData());
$model = $subject->getGatewayServiceVerify()->get($viewConfig->model)->find($query->getWhere());
if (!$model->count()) {
return;
}
foreach ($model as $key => $row) {
$result['selectlinks'][] = ['route' => 'common', 'label' => $row->title, 'folder_title' => $row->folder_title, 'routeparams' => ['view' => 'send', 'data' => 'mail'], 'queryparams' => ['recipient' => $subject->getParams()->fromRoute('id'), 'template' => $row->_id]];
}
usort($result['selectlinks'], function ($a, $b) {
return strnatcmp($a['folder_title'], $b['folder_title']);
});
$subject->setData($result);
}
示例6: update
/**
* @param \SplSubject|View $subject
*
* @throws \Exception
*/
public function update(\SplSubject $subject)
{
$data = $subject->getParam('data', null);
$view = $subject->getParam('view', null);
if ($data == null || $view == null) {
throw new \Exception('Please specify data param');
}
$data = ucfirst($data);
$viewConfig = $subject->getConfigServiceVerify()->getByObject($data . '.' . $view, new ViewConfig());
if ($viewConfig == null) {
throw new \Exception('Please fill ViewConfig for the ' . $data . '.' . $view);
}
$this->viewViewConfig = $viewConfig;
$modelConfig = $subject->getModelServiceVerify()->getParsedModelConfig($data);
$aclData = $subject->getAclServiceVerify()->getAclConfig($data);
$fieldConfigs = ['fields' => [], 'labels' => []];
foreach ($viewConfig->fields as $field) {
if (array_key_exists($field, $modelConfig['fields'])) {
$fieldConfigs['fields'][$field] = false;
}
}
// ksort( $modelConfig['fields']);
uasort($modelConfig['fields'], function ($a, $b) {
return strcmp($a['label'], $b['label']);
});
foreach ($modelConfig['fields'] as $field => $fConfig) {
if ($fConfig['type'] == 'field') {
//check $field in acl
if (!array_key_exists($field, $aclData->fields) || !in_array($aclData->fields[$field], ['read', 'write'])) {
unset($fieldConfigs['fields'][$field]);
continue;
}
}
if ($fConfig['type'] == 'alias') {
//check $fConfig['source'] in acl
if (!array_key_exists($fConfig['source'], $aclData->fields) || !in_array($aclData->fields[$fConfig['source']], ['read', 'write'])) {
unset($fieldConfigs['fields'][$field]);
continue;
}
}
if ($fConfig['type'] == 'source') {
if ($fConfig['source'] !== $field || !array_key_exists($fConfig['source'], $aclData->fields) || !in_array($aclData->fields[$fConfig['source']], ['read', 'write'])) {
unset($fieldConfigs['fields'][$field]);
continue;
}
}
if ($fConfig['type'] == 'pk') {
continue;
}
$fieldConfigs['fields'][$field] = in_array($field, $viewConfig->fields) ? true : false;
$fieldConfigs['labels'][$field] = $fConfig['label'];
}
$result = [];
$result['fieldconfigs'] = $fieldConfigs;
$result['params'] = ['data' => $data, 'view' => $view];
$subject->setData($result);
$this->postVerify($subject);
}
示例7: update
/**
* @param View|\SplSubject $subject
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getConfigServiceVerify()->getByObject($subject->getName(), new ViewConfig());
if ($viewConfig == null) {
throw new \Exception('Please fill ViewConfig for the ' . $subject->getName() . '. I can\'t work on');
}
$result['rowcount'] = $subject->getParam('rowcount', $viewConfig->rows);
if ($result['rowcount'] != $viewConfig->rows) {
$viewConfig->rows = $result['rowcount'];
$subject->getViewConfigVerify()->rows = $result['rowcount'];
$subject->getConfigServiceVerify()->saveByObject($viewConfig);
}
$subject->setData($result);
}
示例8: update
public function update(\SplSubject $subject)
{
/**
* @var View $subject
*/
$result = [];
$model = $subject->getUser();
if (!$model) {
throw new \Exception('User not found');
}
$result['model'] = $model;
$result['title'] = $subject->getViewConfigVerify()->title . ' ' . $model->title;
// $this->widgets( $subject, $model );
$subject->setData($result);
}
示例9: update
/**
* @param \SplSubject|View $subject
*
* @throws \Exception
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$modelRoute = strtolower($viewConfig->model);
$request = $subject->getParams()->getController()->getRequest();
$results = [];
$results['view'] = $subject->getParam('view');
$ids = $request->getPost('checkedid', null);
if (!is_array($ids)) {
$id = $subject->getParams()->fromRoute('id', 0);
if ($id) {
$ids = array($id);
} else {
$subject->setRedirect($subject->getParams()->getController()->redirect()->toRoute('common', ['data' => $modelRoute, 'view' => $results['view'] == 'delete' ? 'list' : 'recyclelist']));
return;
}
}
$results['ids'] = $ids;
foreach ($ids as $id) {
try {
$results['items'][$id] = $subject->getGateway()->findOne(['_id' => $id]);
} catch (\Exception $ex) {
$subject->setRedirect($subject->refresh('Data is invalid ' . $ex->getMessage(), $this->url()->fromRoute('common', ['data' => $modelRoute, 'view' => 'list'])));
return;
}
}
if ($request->isPost()) {
$delyes = $request->getPost('delyes', null);
$delno = $request->getPost('delno', null);
if ($delyes !== null) {
$view = $subject->getViewConfigVerify()->mode;
if (!in_array($view, ['delete', 'clean', 'restore'])) {
throw new \Exception('Action is not allowed');
}
$subject->getLogicServiceVerify()->get('pre' . $view, $viewConfig->model)->trigger($results['items']);
$subject->getLogicServiceVerify()->get($view, $viewConfig->model)->trigger($results['items']);
$subject->getLogicServiceVerify()->get('post' . $view, $viewConfig->model)->trigger($results['items']);
$url = $subject->getParams()->fromPost('saurl')['back'];
$output = null;
if (isset($url['query'])) {
parse_str(parse_url($url)['query'], $output);
}
$temp = $subject->getGateway()->findOne(['_id' => $id]);
if ($temp) {
if (isset($output['back']) && $temp->toArray()['status_id'] != Status::DELETED) {
$url = $subject->getSaUrlBack($output['back']);
}
}
if (!isset($url) || $view == 'clean') {
$url = $subject->getParams()->getController()->url()->fromRoute('common', ['data' => $modelRoute, 'view' => $results['view'] == 'delete' ? 'list' : 'recyclelist']);
}
$subject->setRedirect($subject->refresh(ucfirst($results['view']) . ' was successfull ', $url));
return;
}
if ($delno !== null) {
$subject->setRedirect($subject->getParams()->getController()->redirect()->toRoute('common', ['data' => $modelRoute, 'view' => $results['view'] == 'delete' ? 'list' : 'recyclelist']));
return;
}
}
$subject->setData($results);
}
示例10: update
/**
* @param \SplSubject|View $subject
*
* @throws \Exception
*/
public function update(\SplSubject $subject)
{
$viewConfig = $subject->getViewConfigVerify();
$query = $subject->getQueryServiceVerify()->get($viewConfig->query)->setParams($subject->getParams())->process();
$subject->setData($query->getData());
$result = [];
$model = $subject->getGatewayVerify()->findOne($query->getWhere());
if (!$model) {
throw new \Exception('Data not found');
}
$subject->setDataModel($model);
$data = $subject->getData();
foreach (['actions', 'links'] as $datapartam) {
foreach ($data[$datapartam] as $key => $link) {
foreach (['routeparams', 'queryparams'] as $keyparams) {
foreach ($link[$keyparams] as $paramkey => $param) {
if ($param[0] == ':') {
$_f = substr($param, 1);
$data[$datapartam][$key][$keyparams][$paramkey] = $model->{$_f};
}
}
}
}
}
$result['fieldsets'] = [];
$aclData = $subject->getAclServiceVerify()->getAclConfig($viewConfig->model);
$modelFields = $subject->getParsedModelConfigVerify()->fields;
$usedGroups = [];
foreach ($viewConfig->fields as $field) {
if (!array_key_exists($field, $modelFields)) {
continue;
}
$fConfig = $modelFields[$field];
//check $field in acl
if (!array_key_exists($field, $aclData->fields) || !in_array($aclData->fields[$field], ['read', 'write'])) {
continue;
}
if ($fConfig['type'] == 'pk') {
continue;
}
$usedGroups[$modelFields[$field]['group']][] = $field;
}
$chosenGroups = [];
$fieldSet2Group = [];
foreach ($viewConfig->groups as $grKey => $groupBlock) {
if (is_array($groupBlock)) {
foreach ($groupBlock as $group) {
if (array_key_exists($group, $usedGroups)) {
$chosenGroups[$group] = $usedGroups[$group];
$fieldSet2Group[$group] = $grKey;
}
}
continue;
}
if (array_key_exists($groupBlock, $usedGroups)) {
$chosenGroups[$groupBlock] = $usedGroups[$groupBlock];
$fieldSet2Group[$groupBlock] = $groupBlock;
}
}
foreach ($chosenGroups as $group => $groupElements) {
$fieldSet = $subject->getParsedModelConfigVerify()->fieldsets[$group];
$elements = $fieldSet['elements'];
$fieldSet['elements'] = [];
foreach ($groupElements as $field) {
$fieldSet['elements'][$field] = $elements[$field];
}
$fieldSet['group'] = $fieldSet2Group[$group];
$chosenGroups[$group] = $fieldSet;
}
$result['fieldsets'] = $chosenGroups;
$subject->getLogicServiceVerify()->get('preview', $viewConfig->model)->trigger($model);
$result['model'] = $model;
$result['title'] = $viewConfig->title . ': ' . $model->title;
$result['actions'] = $data['actions'];
$result['links'] = $data['links'];
$subject->setData($result);
$subject->getLogicServiceVerify()->get('postview', $viewConfig->model)->trigger($model);
}