public function actionPostDispatch() { $dispatch_model_1 = array(); $dispatch_model_2 = array(); $dispatch_id = Yii::$app->request->post('document_number'); if (isset($dispatch_id)) { //Yii::app()->session['dispatch_id'] = $dispatch_id; $full_dispatch_id = '00' . $dispatch_id; $dismodel = new DispatchModel(); $dispatch_model_1 = $dismodel->getDispatchList($full_dispatch_id); $dispatch_model_3 = $dismodel->getPickedBy($full_dispatch_id); $sap_dispatch = $this->getSapDispatch($full_dispatch_id); $ditems = $dismodel->getDispatchItems($full_dispatch_id); $dispatch_model_2 = array(); foreach ($ditems as $key => $item) { $mm = Yii::$app->modelFinder->getMaterialBy(null, ['like', 'item_code', $item->MATNR]); if (empty($mm)) { $speclist['0']['barcode'] = ""; $speclist['0']['upc_1'] = ""; $speclist['0']['upc_2'] = ""; $speclist = array(array('barcode' => '', 'upc_1' => '', 'upc_2' => '')); } else { $speclist = ArrayHelper::toArray($mm); } $result = array('MATNR' => $item->MATNR, 'ARKTX' => $item->ARKTX, 'CHARG' => $item->CHARG, 'UMVKZ' => $item->UMVKZ, 'BRGEW' => $item->BRGEW, 'VRKME' => $item->VRKME, 'LFIMG' => $item->LFIMG, 'VFDAT' => $item->VFDAT, 'MEINS' => $item->MEINS, 'VOLUM' => $item->VOLUM, 'UMVKN' => $item->UMVKN, 'BARCODE' => $speclist['0']['barcode'], 'UPC_1' => $speclist['0']['upc_1'], 'UPC_2' => $speclist['0']['upc_2']); $dispatch_model_2[] = (object) $result; } return $this->render('dispatch-print-form', ['dispatch_model_1' => $dispatch_model_1, 'dispatch_model_2' => $dispatch_model_2, 'dispatch_model_3' => $dispatch_model_3, 'full_dispatch_id' => $full_dispatch_id, 'sap_dispatch' => $sap_dispatch]); } else { return $this->render('index'); } }
public function __ModelTabsConstruct($rowParams = [], $value = "", $item = []) { $model_tabs = new \app\modelsActiveRecords\Tabs(); $getTabs = $model_tabs->GetItems($value); $tabs = ArrayHelper::toArray($getTabs); $params = yii::$app->request->bodyParams; if (!empty($params["tabs"])) { $model_tabs->Add($value, $params["tabs"]); } $tag = Html::beginTag('table', ['style' => 'width:100%']); $tag .= Html::a('Добавить поле', 'javascript:void(0)', ['onclick' => 'addTabRow(this)']); $tag .= Html::beginTag('tr'); $tag .= Html::tag('th', 'Имя вкладки'); $tag .= Html::tag('th', 'Название вкладки'); $tag .= Html::tag('th', 'Класс'); $tag .= Html::tag('th', 'Индекс сортировки'); $tag .= Html::tag('th', 'Действие'); $tag .= Html::endTag('tr'); if (!empty($tabs)) { foreach ($tabs as $index => $value) { $tag .= Html::beginTag('tr'); $tag .= Html::tag('td', Html::textInput("tabs[{$index}][name]", $value["name"])); $tag .= Html::tag('td', Html::textInput("tabs[{$index}][title]", $value["title"])); $tag .= Html::tag('td', Html::textInput("tabs[{$index}][class]", $value["class"])); $tag .= Html::tag('td', Html::textInput("tabs[{$index}][index]", $value["index"], ["type" => "number"])); $tag .= Html::tag('td', Html::a('Удалить', 'javascript:void(0)', ['onclick' => 'removeRow(this)'])); $tag .= Html::endTag('tr'); } } $tag .= Html::endTag('table'); return $tag; }
/** * * @param string $config * @return type */ public function run($config = []) { $id = $this->getId(); CalendarAsset::register($this->getView()); if (!empty($config['id'])) { $id = $config['id']; } if (!empty($config['source'])) { $this->source = $config['source']; } if (!isset($config['class'])) { $config['class'] = 'calendar-holder'; } $content = Html::tag('div', null, ['id' => $id]); switch (gettype($this->source)) { case 'object': case 'array': $this->source = ArrayHelper::toArray($this->source); $this->source = json_encode($this->source, true); break; } $js = new JsExpression("\$(document).ready(function(e){var calendar = \$('#" . $id . "').calendar({events_source: " . $this->source . " }); });"); $content .= Html::tag('script', $js, ['type' => 'text/javascript']); $this->registerPlugin(__CLASS__); return Html::tag('div', $content, ['class' => $config['class']]); }
public static function convertModelToArray($models) { if (is_array($models)) { $arrayMode = true; } else { $models = array($models); $arrayMode = false; } $result = []; foreach ($models as $model) { $attributes = ArrayHelper::toArray($model); $relations = []; if ($model instanceof yii\base\Model) { foreach ($model->getRelatedRecords() as $key => $related) { if ($model->getRelation($key)) { if (is_array($model->{$key}) || $model->{$key} instanceof yii\base\Model) { $relations[$key] = self::convertModelToArray($model->{$key}); } else { $relations[$key] = $model->{$key}; } } } } $all = array_merge($attributes, $relations); if ($arrayMode) { array_push($result, $all); } else { $result = $all; } } return $result; }
/** * Creates a new Sale model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($object_id = 0) { $model = new Sale(); if ($object_id) { $object = Object::findOne($object_id); if ($object) { $temp = ArrayHelper::toArray($object->sale); unset($temp['id']); foreach ($temp as $k => $v) { $model->{$k} = $v; } } $model->view_ids = ArrayHelper::toArray($object->sale->view_ids); $model->facility_ids = ArrayHelper::toArray($object->sale->facility_ids); } $model->status = 1; $model->sold = 1; $model->code = rand(100000000, 999999999); for ($i = 1; $i <= Lang::find()->count(); $i++) { $model_content[$i] = new SaleLang(); $model_content[$i]['lang_id'] = $i; $model_content[$i]['id'] = 0; } if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->validate() && $model->district_id > 0) { $model->save(); foreach ($model_content as $key => $content) { $content->id = $model->id; $content->lang_id = $key; $content->save(false); } return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'model_content' => $model_content]); } }
/** * Render page, query string 's' indicates that get page record regardless of published status */ public function actionPage($id = '') { $isPreview = \Yii::$app->request->get('s', 0); if (!empty($id)) { $id = new \MongoId($id); $page = Page::getPage($id, !!$isPreview); if (empty($page) || empty($page->url)) { $this->redirect(self::NOT_FOUND_PAGE_PATH); } if (empty($page['color'])) { $page['color'] = \Yii::$app->params['micrositeDefaultColor']; } if (empty($page->cpts) || $isPreview) { $cpts = PageComponent::getAllComponents($id); $page->cpts = ArrayHelper::toArray($cpts); } $sdk = Yii::$app->wechatSdk; $sdk->refererUrl = $sdk->refererDomain . 'msite/page/' . $id; $signPackage = $sdk->getSignPackage(); $actionView = $this->getView(); $actionView->registerJsFile('https://res.wx.qq.com/open/js/jweixin-1.0.0.js'); $this->view->params['page'] = $page; $this->view->params['pageRGBColor'] = join(',', StringUtil::hex2rgb($page['color'])); $this->layout = self::PAGE_PATH; $this->registerPageResource($isPreview); $params = ['signPackage' => $signPackage, 'components' => $page->cpts, 'page' => ['title' => $page->title, 'desc' => $page->description, 'url' => $page->url, 'isCover' => $page->type === Page::TYPE_COVER]]; if (BrowserUtil::isWeiboBrower() || BrowserUtil::isWeixinBrowser()) { $params['hideTitle'] = true; } return $this->render(self::PAGE_PATH, $params); } else { return $this->render(self::NOT_FOUND_PAGE_PATH); } }
/** * @return $this * @throws NotSupportedException */ public function save() { $paramsFilePath = \Yii::$app->paramsManager->paramsFilePath($this->paramsType()); file_put_contents($paramsFilePath, '<?php return ' . var_export(ArrayHelper::toArray($this), true) . ';'); @chmod($paramsFilePath, 0775); return $this; }
/** * 用户注册事件处理句柄 * @param object $event */ public function afterRegister($event) { //处理积分 $creditTask = new CreditTask(); $creditTask->task_name = TaskConstant::REGISTER_CREDITS_TASK; //任务名称 $creditTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO; //场景 $creditTask->data = ['user_id' => $event->userId, 'credits' => 500]; CreditsService::getService()->push(ArrayHelper::toArray($creditTask)); //处理耕币 $forumTask = new ForumTask(); $forumTask->task_name = TaskConstant::REGISTER_FORUM_TASK; $forumTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO; //场景 $forumTask->data = ['user_id' => $event->userId, 'forum' => 500]; ForumService::getService()->push(ArrayHelper::toArray($forumTask)); //用户邀请码 $invitationTask = new InvitationCodeTask(); $invitationTask->task_name = TaskConstant::REGISTER_FORUM_TASK; $invitationTask->scebario = TaskConstant::REGISTER_TASK_SCEBARIO; //场景 $invitationTask->data = ['user_id' => $event->userId]; InvitationService::getService()->push(ArrayHelper::toArray($invitationTask)); }
/** * @inheritdoc */ public static function getListCategories() { $arr = ArrayHelper::toArray(self::find()->active()->select('id, title')->orderBy('title ASC')->all()); array_unshift($arr, ['id' => NULL, 'title' => Yii::t('app/categories', 'Without Category')]); $arr2 = ArrayHelper::map($arr, 'id', 'title'); return $arr2; }
public function GetItems($model_id = 0) { if ($model_id !== 0) { $find = self::find()->select(['name', 'title', 'class', 'index'])->where(["model_id" => $model_id])->orderBy(['index' => 'ASC'])->all(); $result = ArrayHelper::toArray($find); return $result; } }
/** * @return array */ public function toArray() { if ($this->isOk()) { return ['result' => static::RESULT_OK, 'data' => $this->data ? ArrayHelper::toArray($this->data) : null]; } else { return ['result' => static::RESULT_OK, 'msg' => $this->msg ? $this->msg : null, 'data' => $this->data ? ArrayHelper::toArray($this->data) : null]; } }
/** * @return array(['id' => 'fullname]) */ public static function getAuthorsForDropDownList() { $authorsModels = Authors::find()->all(); $authors = ArrayHelper::toArray($authorsModels, ['app\\models\\Authors' => ['id', 'fullname' => function ($model) { return "{$model->firstname} {$model->lastname}"; }]]); return ArrayHelper::map($authors, 'id', 'fullname'); }
/** * Process a message and run a requested function from a client * * @param ConnectionInterface $client connection object * @param string $msg json message recieved from a client */ public function onMessage(ConnectionInterface $client, $msg) { $obj = json_decode($msg); $method = $obj->method; $params = ArrayHelper::toArray($obj->data); array_unshift($params, $client); call_user_func_array([$this, $method], $params); }
public function saveForm() { if (!$this->validate()) { return false; } Option::updateOption(ArrayHelper::toArray($this)); return true; }
/** * @test */ public function it_should_be_able_to_convert_existing_node_to_root() { $node = $this->tree('node_1_1'); self::assertEquals(1, Tree::find()->roots()->count(), 'there is only one root for now'); self::assertTrue($node->makeRoot(), 'node is transformed to root'); self::assertEquals(2, Tree::find()->roots()->count(), 'new root has been created'); $childData = [4 => ['id' => 4, 'label' => 'node 1.1.1', 'path' => '.2.', 'level' => 1, 'position' => 1]]; self::assertEquals($childData, ArrayHelper::toArray($node->getChildren()), 'node child got level up'); }
public function getAllRoles() { $allRolesobj = Role::find()->select(['RoleId', 'RoleName'])->where(['status' => 'Active'])->all(); $data = ArrayHelper::toArray($allRolesobj, ['RoleId', 'RoleName']); $roleIdCol = array_column($data, 'RoleId'); $RoleNameCol = array_column($data, 'RoleName'); $RolesData = array_combine($roleIdCol, $RoleNameCol); return $RolesData; }
/** * @inheritDoc */ protected function runTabular($models) { if ($success = Model::validateMultiple($models)) { foreach ($models as $model) { $model->save(false); } } return ['success' => $success, 'modeldata' => ArrayHelper::toArray($models)]; }
/** * {@inheritdoc} */ public function save() { $raw = $this->getManager()->getItems(); $themes = ArrayHelper::toArray($raw); foreach ($raw as $name => $theme) { $themes[$name]['class'] = get_class($theme); } return ['themes' => $themes, 'current' => $this->getManager()->getTheme()->name, 'default' => $this->getManager()->getDefaultTheme()]; }
public function testConvertNodeToRoot() { $node = $this->tree('node_1_1'); $this->specify('it should be able to convert existing node into root', function () use($node) { expect('node is transformed into root', $node->makeRoot())->true(); expect('new root created', Tree::find()->roots()->count())->equals(2); expect('node child got level up', ArrayHelper::toArray($node->getChildren()))->equals([4 => ['id' => 4, 'label' => 'node 1.1.1', 'path' => '.2.', 'level' => 1, 'position' => 1]]); }); }
public function save(CategoryDto $categoryDto) { $category = $this->findById($categoryDto->id); if ($category->load(['Category' => ArrayHelper::toArray($categoryDto)])) { $category->save(); return ArrayHelper::toArray($category, ['common\\models\\Category' => $categoryDto->activeAttributes()]); } else { return []; } }
/** * This function is used to return the data to the DepDrop widget * See more information on http://demos.krajee.com/widget-details/depdrop */ public function actionGetDistrictList() { $amphoeList = []; if (isset($_POST['depdrop_parents'])) { $id = end($_POST['depdrop_parents']); $efThaiDistrict = EfThaiDistrict::find()->where(['AMPHUR_ID' => $id])->all(); $amphoeList = ArrayHelper::toArray($efThaiDistrict, ['app\\models\\EfThaiDistrict' => ['id' => 'DISTRICT_ID', 'name' => 'DISTRICT_NAME']]); } echo Json::encode(['output' => $amphoeList, 'selected' => '']); }
public function save(BrandDto $brandDto) { $brand = $this->findById($brandDto->id); if ($brand->load(['Brand' => ArrayHelper::toArray($brandDto)])) { $brand->save(); return ArrayHelper::toArray($brand); } else { return []; } }
/** * Convert a Model to an Array * @param type $model * @param type $properties * @param type $properties * @return array */ public static function toArray($model, $properties = []) { if (empty($properties)) { foreach ($model->getTableSchema()->columns as $column) { $properties[] = $column->name; } } return ArrayHelper::toArray($model, $properties); // }
/** * Lists all UserRoleForm models. * @return mixed */ public function actionIndex() { $roles = UserRoleForm::getAllRoles(); $roles = ArrayHelper::toArray($roles); foreach ($roles as &$role) { $role['id'] = $role['name']; // Grid need id } return $this->render('index', ['dataProvider' => new ArrayDataProvider(['allModels' => $roles, 'sort' => ['attributes' => ['description', 'name'], 'defaultOrder' => ['description' => SORT_ASC]], 'pagination' => ['pageSize' => 10, 'pageSizeLimit' => [10, 100]]])]); }
public function save(ProductDto $productDto) { $product = $this->findById($productDto->id); if ($product->load(['Product' => ArrayHelper::toArray($productDto)])) { $product->type = ArrayUtil::arrayToInt($productDto->type); $product->save(); return ArrayHelper::toArray($product); } else { return []; } }
public function actionView($id) { $rutaDelDia = array(); $conjuntoRutas = ArrayHelper::toArray(Rutas::find()->all()); foreach ($conjuntoRutas as $value) { if ($value["idRuta"] == $id) { $rutaDelDia = $value; } } return $this->render('view', ['rutaDelDia' => $rutaDelDia]); }
public function __construct() { $clientCookies = Yii::$app->request->cookies; if ($clientCookies->has('USER_DATA')) { $cookieData = ArrayHelper::toArray(json_decode($clientCookies->getValue('USER_DATA'))); $this->cookie_id = $cookieData['cookie_id']; $this->email_id = $cookieData['email_id']; $this->behavioral = $cookieData['behavioral']; } else { } }
/** * Serializes a set of models. * @param array $models * @return array the array representation of the models */ public function serializeModels(array $models) { list($fields, $expand) = $this->getRequestedFields(); foreach ($models as $i => $model) { if ($model instanceof Arrayable) { $models[$i] = $model->toArray($fields, $expand); } elseif (is_array($model)) { $models[$i] = ArrayHelper::toArray($model); } } return $models; }
/** * Returns the translation model for the specified language. * @param string|null $language * @return ActiveRecord */ public function getTranslation($language = null) { $language = $language ?: $this->language; $translations = $this->getTranslateRelations(); if (isset($translations[$language])) { return $translations[$language]; } $attributes = isset($translations[$this->sourceLanguage]) ? ArrayHelper::toArray($translations[$this->sourceLanguage]) : []; $translations[$language] = $this->createTranslation($language, $attributes); $this->setTranslateRelations($translations); return $translations[$language]; }
public function testPublishAndConsumeDifferentType() { $amqp = $this->getAmqp(Client::MESSAGE_TYPE_JSON); $message = new TestMessage(); $message->data = ['testArray', 'timestamp' => time()]; $this->assertTrue($amqp->publish($message)); $amqp->consume(function (Envelope $envelope) use($message, $amqp) { $this->assertEquals($envelope->body, ArrayHelper::toArray($message)); $amqp->ack($envelope->deliveryTag); return false; }); }