public function indexAction() { $numberPage = 1; if ($this->request->isPost()) { $query = \Phalcon\Mvc\Model\Criteria::fromInput($this->di, "Models\\ArticleCategories", $_POST); $query->order("id ASC, name ASC"); $this->persistent->searchParams = $query->getParams(); if (!\Helpers\Arr::is_array_empty($this->persistent->searchParams)) { $categories = \Models\ArticleCategories::find($this->persistent->searchParams); } } else { $numberPage = $this->request->getQuery("page", "int"); if (!$numberPage or $numberPage <= 0) { $numberPage = 1; } if ($numberPage > 1 and !\Helpers\Arr::is_array_empty($this->persistent->searchParams)) { $categories = \Models\ArticleCategories::find($this->persistent->searchParams); } else { $categories = \Models\ArticleCategories::find(); $this->persistent->searchParams = null; } } if (count($categories) == 0) { $this->flashSession->notice("Не найдено ни одной категории"); $this->persistent->searchParams = null; } $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $categories, "limit" => 10, "page" => $numberPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); //$this->view->setVar('searchparams', $this->persistent->searchParams); //$this->view->setVar('numpage', $numberPage); }
public function indexAction() { $numberPage = 1; if (isset($_GET['tags'])) { $tags = $this->request->getQuery("tags", "string"); $criteria = new \Phalcon\Mvc\Model\Criteria(); $criteria->setModelName("\\Models\\Posts"); //$criteria->setDI($this->di); $criteria->where("tags LIKE :tags:"); $criteria->andWhere("status = :1:"); $criteria->bind(array('tags' => "%{$tags}%", '1' => '0')); $this->persistent->searchParams = $criteria->getParams(); $models = \Models\Posts::find($criteria); } else { $numberPage = $this->request->getQuery("page", "int"); if (!$numberPage or $numberPage <= 0) { $numberPage = 1; } if ($numberPage > 1 and !\Helpers\Arr::is_array_empty($this->persistent->searchParams)) { $models = \Models\Posts::find($this->persistent->searchParams); } else { $models = \Models\Posts::find("status = '0'"); $this->persistent->searchParams = null; } } if (!$models->count()) { $this->flashSession->notice("Ничего не найдено"); $this->persistent->searchParams = null; } $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $models, "limit" => 10, "page" => $numberPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); //$this->view->setVar('searchparams', $this->persistent->searchParams); //$this->view->setVar('numpage', $numberPage); }
public function set($type, $messages) { if (is_string($messages)) { $this->_messages[$type][] = $messages; } elseif (is_array($messages)) { isset($this->_messages[$type]) ? Arr::merge($this->_messages[$type], $messages) : ($this->_messages[$type] = $messages); } $this->save(); }
public function anyResult() { $quiz = (new Quiz())->setQuizId(self::CurrentQuizId)->setUserId(self::CurrentUserId)->find(); $data = (int) Arr::get($this->getPostData(), 'quiz'); if (isset($data)) { $quiz->addResponse($data); } $content = View::make('test/quiz/result')->with('quiz', $quiz); echo $content; }
/** * Главная страница сайта */ public function anyQuizResponse() { $this->layout = null; $quiz = (new Quiz())->setQuizId(1)->setUserId(1)->find(); $data = (int) Arr::get($this->getPostData(), 'quiz'); if (isset($data)) { if (\UserModel::whereIp(\App::instance()->http()->getIpAddress())->first()) { echo 'nok'; } else { $quiz->addResponse($data); echo 'ok'; } } }
/** * Редактирование материалов */ public function anyEdit() { $id = (int) $this->getRequestParam('id') ?: null; $article = ArticleModel::find($id); if (empty($article)) { throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Article'])); } if (Arr::get($this->getPostData(), 'submit') !== null) { $data = Arr::extract($this->getPostData(), ['slug', 'parentId', 'status', 'content']); $parent = ArticleModel::find($data['parentId']); // Транзакция для Записание данных в базу try { Event::fire('Admin.beforeArticleUpdate', $article); Capsule::connection()->transaction(function () use($data, $article, $parent) { if ($parent) { $article->makeChildOf($parent); } else { $article->makeRoot(); } // Заодно обновляет и пункты меню привязанные к slug-у (new \MenuItemModel())->whereSlug($article->slug)->update(['slug' => $data['slug']]); $article->update(['slug' => $data['slug'], 'status' => $data['status']]); foreach ($data['content'] as $iso => $item) { $lang_id = Lang::instance()->getLang($iso)['id']; if ((int) $item['id'] != 0) { $content = ContentModel::find($item['id']); $content->update(['title' => $item['title'], 'crumb' => $item['crumb'], 'desc' => $item['desc'], 'meta_title' => $item['metaTitle'], 'meta_desc' => $item['metaDesc'], 'meta_keys' => $item['metaKeys'], 'lang_id' => $lang_id]); } else { //todo: надо по тестить почему без ID каждий раз создаётся все записи а не обновляются $content = ContentModel::create(['article_id' => $data['content']['ru']['id'], 'title' => $item['title'], 'crumb' => $item['crumb'], 'desc' => $item['desc'], 'meta_title' => $item['metaTitle'], 'meta_desc' => $item['metaDesc'], 'meta_keys' => $item['metaKeys'], 'lang_id' => $lang_id]); $article->contents()->attach($content); } // $article->contents()->attach($content); } }); Event::fire('Admin.articleUpdate', $article); } catch (QueryException $e) { Message::instance()->warning('Article was don\'t edited'); } } // Загрузка контента для каждово языка $contents = []; foreach (Lang::instance()->getLangs() as $iso => $lang) { $contents[$iso] = $article->contents()->where('lang_id', '=', $lang['id'])->first(); } $this->layout->content = View::make('back/articles/edit')->with('node', $article::getNode())->with('article', $article)->with('contents', $contents); }
/** * Редактирование */ public function anyEdit() { //die; $id = (int) $this->getRequestParam('id') ?: null; $item = \SettingsModel::find($id); if (null !== Arr::get($this->getPostData(), 'submit')) { $data = Arr::get($this->getPostData(), 'value'); $item->value = $data; try { //изменения елемента по id $item->save(); Event::fire('Admin.settingsUpdate'); } catch (QueryException $e) { // Message::instance()->warning('Setting was don\'t edited'); //echo '<pre>'; //print_r($e->getMessage());die; } } $this->layout->content = View::make('back/setting/edit')->with('id', $id)->with('item', $item); }
public function anySaveSorting() { $this->layout = false; $data = Arr::get($this->getPostData(), 'data'); //В качестве ответа выводим окно логина $response = 'Unfaithful Categories Sorting'; if (!empty($data)) { $data = json_decode($data, true); $article = new ArticleModel(); if (!empty($data)) { Capsule::connection()->transaction(function () use($data, $article, &$response) { foreach ($data as $item) { $article::find($item['id'])->update(['parent_id' => $item['parent_id'], 'lvl' => $item['depth'], 'lft' => $item['left'], 'rgt' => $item['right']]); } $response = 'Categories Sorting has successfully saved'; }); } } Message::instance()->info($response); echo Message::instance()->flash_all(); }
echo Language::show('category', 'blog'); ?> <span class="text-danger">*</span></label> <select tabindex="4" class="select" name="category" data-placeholder="" required> <option value=""><?php echo Language::show('none', 'blog'); ?> </option> <?php if ($data['categories']) { if (isset($error)) { $selected_category = $_POST['category']; } else { $selected_category = ''; } echo Arr::buildOptionsTree($data['categories'], 11, 0, 10, $selected_category); } ?> </select> </div> </div> </div> <div class="row"> <hr /> <div class="col-md-12"> <div class="form-group text-right"> <button type="submit" name="save" tabindex="5" class="btn btn-primary btn-labeled position-right pull-right mb-10"><b><i class="icon-floppy-disk"></i></b><?php echo Language::show('save', 'blog'); ?> </button>
private function SaveImages($model) { if (!\Helpers\Arr::is_array_empty($_FILES['News']['tmp_name'])) { $path = 'uploads' . DIRECTORY_SEPARATOR . 'news' . DIRECTORY_SEPARATOR . 'images_id_' . $model->id; $errors = array(); $images = $model->getImages(); if ($images) { $num = count($images); } else { $num = $this->config->application->images_number; } foreach ($_FILES['News']['tmp_name'] as $key => $tmp_name) { if ($key >= $num) { break; } $file_name = $_FILES['News']['name'][$key]; $file_size = $_FILES['News']['size'][$key]; $file_tmp = $_FILES['News']['tmp_name'][$key]; $file_type = $_FILES['News']['type'][$key]; if (\Helpers\CFileHelper::is_kir($file_tmp)) { $nameParts = explode('.', $file_tmp); $imageName = \Helpers\Translite::$rustable($nameParts[0]) . '.' . $nameParts[1]; } if ($file_size > 259715) { $errors[] = 'Размер файла не больше 2 мегабайт'; } $extensions = array("gif", "jpg", "png", "jpeg"); $file_ext = explode('.', $file_name); $file_ext = strtolower(end($file_ext)); if (in_array($file_ext, $extensions) === false) { $errors[] = "Недопустимый формат файла, допускаются изображения форматов: jpg, gif, png, jpeg"; } if (empty($errors) == true) { if (is_dir($path) == false) { mkdir("{$path}", 0777); // Create directory if it does not exist } if (is_dir("{$path}/" . $file_name) == false) { move_uploaded_file($file_tmp, $path . DIRECTORY_SEPARATOR . $file_name); } } else { foreach ($errors as $error) { $this->flashSession->error((string) $error); } return $this->response->redirect("backend/news/edit/{$model->id}"); } } } }
public static function removeTags($tags) { if (empty($tags)) { return; } $names = ''; if (!\Helpers\Arr::is_array_empty($tags)) { $names = \Helpers\TextHelper::array2string($tags); } $names = rtrim($names, " ,"); $criteria = new \Phalcon\Mvc\Model\Criteria(); $criteria->setModelName("\\Models\\Tags"); //$criteria->setDI($this->di); //$criteria->addInCondition('name',$tags); $criteria->andWhere("name IN ({$names})"); //$this->updateCounters(array('frequency' => 1), $criteria); $models = \Models\Tags::find($criteria); if ($models->count()) { foreach ($models as $model) { $model->frequency = $model->frequency - 1; $model->update(); } } foreach (\Models\Tags::find("frequency<='0'") as $model) { $model->delete(); } }
echo Language::show('role', 'navigation'); ?> <span class="text-danger">*</span></label> <select tabindex="6" class="select" required name="role"> <option value=""><?php echo Language::show('none', 'navigation'); ?> </option> <?php if ($data['role']) { if (isset($error)) { $selected_role = $_POST['role']; } else { $selected_role = ''; } echo Arr::buildOptions($data['role'], $selected_role); } ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <label><?php echo Language::show('status', 'navigation'); ?> <span class="text-danger">*</span></label> <div class="checkbox checkbox-switch no-margin-top">
/** * Авторизация * Params: - (string)username; //required - (string)password; //required * @return string */ public function login() { $this->request_data(Arr::merge(array('action' => self::ACTION_LOGIN), $this->_api_auth)); $response = $this->execute(); $this->_logged_in = true; return $this->_logged_in; }
echo Language::show('company', 'offices'); ?> <span class="text-danger">*</span></label> <select tabindex="1" class="select" name="company" required> <option value=""><?php echo Language::show('none', 'offices'); ?> </option> <?php if ($data['companies']) { if (isset($error)) { $selected_company = $_POST['company']; } else { $selected_company = $data['office'][0]->company_id; } echo Arr::buildOptionsTree($data['companies'], 0, 0, 10, $selected_company); } ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label><?php echo Language::show('name', 'offices'); ?> <span class="text-danger">*</span></label> <input tabindex="3" type="text" class="form-control" name="name" required="required" value="<?php
echo Language::show('department', 'teams'); ?> <span class="text-danger">*</span></label> <select tabindex="3" class="select" name="department" required="required"> <option value=""><?php echo Language::show('none', 'teams'); ?> </option> <?php if ($data['departments']) { if (isset($error)) { $selected_department = $_POST['department']; } else { $selected_department = ''; } echo Arr::buildOptionsTree($data['departments'], 0, 0, 10, $selected_department); } ?> </select> </div> </div> <div class="col-md-6"> <?php if (isset($error)) { if ($_POST['status'] == 1) { $checked = 'checked="checked"'; } else { $checked = ''; } } else {
function subsubCategories($menuSubsubCategories, $requested_url) { foreach ($menuSubsubCategories as $menuSubSubItem) { if ($menuSubSubItem[link] == 'navigation-divider') { echo "<li class=\"" . $menuSubSubItem[link] . "\"></li>"; } else { if ($menuSubSubItem['link'] == '/blog/category/##') { $link = '/blog/category/' . $menuSubSubItem['id']; } else { $link = $menuSubSubItem['link']; } if ($requested_url == $link) { $active = "active"; } else { $active = ""; } $category = Arr::objArraySearch($data['countsCat'], 'category_id', $menuSubSubItem['id']); if ($category == '') { $quantity = '0'; } else { $quantity = $category->quantity; } //if (Rbac::canUser($menuSubItem['rbac']) OR $menuSubItem['rbac'] == '(rol)everyone') { echo "<li class=\"{$active}\"><a href=\"{$link}\"><i class=\"{$menuSubSubItem['icon']}\"></i><span>{$menuSubSubItem['name']} ({$quantity})</span></a></li>"; //} } } }
/** * Удаление картинки флага */ public function postImageDelete() { $this->layout = null; $id = (int) Arr::get($this->getPostData(), 'key'); $item = Capsule::table('langs')->find($id); if (empty($item)) { Message::instance()->warning('Image was not delete'); } else { try { // Удаление картинки из сервера @unlink(ltrim(UploadFile::getImagePath($item['flag']), '/')); Capsule::table('langs')->whereId($id)->update(['flag' => null]); Message::instance()->success('Image was successfully deleted'); } catch (Exception $e) { Message::instance()->warning('Image was not delete'); } } echo json_encode(['errorMessage' => Message::instance()->flash_all()]); }
/** * Fetch an item from the SERVER array * * @param string The index key * @param mixed The default value * @return string|array */ public static function server($index = null, $default = null) { return func_num_args() === 0 ? $_SERVER : Arr::get($_SERVER, strtoupper($index), $default); }
/** * Редактирование */ public function anyEdit() { $id = (int) $this->getRequestParam('id') ?: null; $model = PlayerModel::find($id); $firstNameModel = $model->firstNameModel()->first(); $lastNameModel = $model->lastNameModel()->first(); if (empty($model)) { throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Player'])); } if (Arr::get($this->getPostData(), 'submit') !== null) { $data = Arr::extract($this->getPostData(), ['slug', 'image', 'country', 'position', 'status', 'number', 'team', 'first_name', 'last_name', 'content']); // Транзакция для Записание данных в базу try { Capsule::connection()->transaction(function () use($data, $model, $firstNameModel, $lastNameModel) { // Загрузка картинки $file = new UploadFile('image', new FileSystem('uploads/images')); // Optionally you can rename the file on upload $file->setName(uniqid()); // // Validate file upload // $file->addValidations(array( // // Ensure file is of type image // new UploadMimeType(['image/png','image/jpg','image/gif']), // // // Ensure file is no larger than 5M (use "B", "K", M", or "G") // new UploadSize('50M') // )); // Try to upload file try { // Success! $file->upload(); $image = '/' . static::IMAGE_PATH . '/' . $file->getNameWithExtension(); } catch (UploadException $e) { // Fail! $image = null; Message::instance()->warning($file->getErrors()); } catch (Exception $e) { // Fail! $image = null; Message::instance()->warning($file->getErrors()); } $firstNameModel->updateOrCreate(['id' => $firstNameModel->id], ['text' => $data['first_name']]); $lastNameModel->updateOrCreate(['id' => $lastNameModel->id], ['text' => $data['last_name']]); foreach ($data['content'] as $iso => $d) { $lang_id = Lang::instance()->getLang($iso)['id']; EntityTranslationModel::updateOrCreate(['id' => $d['first_name_id']], ['text' => $d['first_name'], 'lang_id' => $lang_id, 'entity_id' => $firstNameModel->id]); EntityTranslationModel::updateOrCreate(['id' => $d['last_name_id']], ['text' => $d['last_name'], 'lang_id' => $lang_id, 'entity_id' => $lastNameModel->id]); } Event::fire('Admin.entitiesUpdate'); // если нету нового изображения оставить прежний if ($image) { $imageId = PhotoModel::create(['path' => $image, 'is_bound' => 1])->id; $model->update(['image_id' => $imageId]); } $model->update(['team_id' => $data['team'], 'slug' => $data['slug'], 'number' => $data['number'], 'status' => $data['status'], 'country_id' => $data['country'], 'position_id' => $data['position'], 'first_name_id' => $firstNameModel->id, 'last_name_id' => $lastNameModel->id]); }); Message::instance()->success('Player was successfully saved'); } catch (Exception $e) { Message::instance()->warning('Player was don\'t saved'); } } $model = PlayerModel::find($id); $firstNameModel = $model->firstNameModel()->first(); $lastNameModel = $model->lastNameModel()->first(); // Загрузка контента для каждово языка $contents = []; foreach (Lang::instance()->getLangsExcept(Lang::DEFAULT_LANGUAGE) as $iso => $lang) { $contents[$iso]['firstName'] = $firstNameModel->translations()->whereLang_id($lang['id'])->first(); $contents[$iso]['lastName'] = $lastNameModel->translations()->whereLang_id($lang['id'])->first(); } //echo "<pre>"; //print_r($contents); //die; $this->layout->content = View::make('back/players/edit')->with('item', $model)->with('contents', $contents); }
</div> <!-- /page header --> <!-- Content Area --> <div class="content"> <?php echo Session::message('success'); ?> <!-- Panel --> <div class="panel panel-flat"> <?php $dataset = Arr::buildTree($data['users']); ?> <script type="text/javascript"> $(function() { var dataset = <?php echo substr(json_encode($dataset), 1, -1); ?> ; $('#chart-container').orgchart({ 'data' : dataset, 'pan': true, 'direction': 'l2r', //'depth': 2, 'zoom': true, 'nodeContent': 'title',
echo Language::show('interface_language', 'users'); ?> <span class="text-danger">*</span></label> <select class="select" name="interface_language" data-placeholder="" required> <option value=""><?php echo Language::show('none', 'users'); ?> </option> <?php if ($data['offices']) { if (isset($error)) { $selected_language = $_POST['languages']; } else { $selected_language = $data['user'][0]->language_id; } echo Arr::buildOptions($data['languages'], $selected_language); } ?> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label><?php echo Language::show('timezone', 'users'); ?> <span class="text-danger">*</span></label> <select class="select" name="timezone" data-placeholder="" required> <option value=""><?php echo Language::show('none', 'users'); ?>
echo Language::show('parent', 'permissions'); ?> <span class="text-danger">*</span></label> <select tabindex="5" class="select" name="parent" required="required"> <option value=""><?php echo Language::show('none', 'permissions'); ?> </option> <?php if ($data['parent']) { if (isset($error)) { $selected_parent = $_POST['parent']; } else { $selected_parent = ''; } echo Arr::buildOptionsTree($data['parent'], 0, 0, 1, $selected_parent); } ?> </select> </div> </div> </div> <?php $languageL18n = L18n::getLanguagesForL18n(); if (!empty($languageL18n)) { echo "<legend class=\"text-semibold text-grey border-bottom-grey-100\">" . Language::show('localize_data', 'l18n') . "</legend>"; echo "<div class=\"row\">"; foreach ($languageL18n as $language) { ?>
echo Language::show('supervisor', 'departments'); ?> </label> <select tabindex="3" class="select" name="supervisor"> <option value=""><?php echo Language::show('none', 'departments'); ?> </option> <?php if ($data['users']) { if (isset($error)) { $selected_user = $_POST['supervisor']; } else { $selected_user = $data['department'][0]->user_id; } echo Arr::buildOptions($data['users'], $selected_user, 'first_name,last_name'); } ?> </select> </div>--> </div> </div> <?php $languageL18n = L18n::getLanguagesForL18n(); if (!empty($languageL18n)) { echo "<legend class=\"text-semibold text-grey border-bottom-grey-100\">" . Language::show('localize_data', 'l18n') . "</legend>"; echo "<div class=\"row\">"; foreach ($languageL18n as $language) { foreach ($data['departmentsL18n'] as $key => $value) { if ($data['departmentsL18n'][$key]->language_id == $language->id) {