Exemple #1
0
 /**
  * Test action
  *
  * @param array $params
  * @return void
  */
 protected function _execute(array $params)
 {
     $base = new Model_Base();
     $options = $base->getOptions();
     $excel = new Model_Excel();
     $file = DOCROOT . '/upload/task/file.xlsx';
     $load = $excel->load_xls($file, 602, $options['xls_offset'], $options['xls_limit']);
     $new_offset = $options['xls_offset'] + $options['xls_limit'];
     $options = $base->saveOptions(array('xls_offset' => $new_offset));
 }
Exemple #2
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     $folders = $this->getFolders();
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $addToChildren = Arr::get($_POST, 'add_to_children', '');
         $ordering = $previousPos + 1;
         $param_data = array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering);
         if ($addToChildren) {
             $parent_data = $group->getGroup($groupId);
             $children_groups = DB::select()->from('groups')->where('left_key', '>', $parent_data['left_key'])->and_where('right_key', '<', $parent_data['right_key'])->execute();
             foreach ($children_groups as $group_data) {
                 $param_data["gid"] = $group_data["id"];
                 $result = $group->addParam($param_data);
                 if (!$result) {
                     $data['groupErrors'] = $group->getErrors();
                 }
             }
         }
         $param_data["gid"] = $groupId;
         $result = $group->addParam($param_data);
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $groupId = $this->request->param('id');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         if (!empty($ids)) {
             $result = $group->changeGroup($groupId, $newGroup, $ids);
         }
     }
     if (isset($_POST['save_selects'])) {
         $selects = new Model_Params_Selects();
         $values = $_POST;
         unset($values['save_selects']);
         $selects->saveSelectsValues($values, $_POST['save_selects']);
     }
     if (isset($_POST['sort_fields'])) {
         $groupId = $this->request->param('id');
         $group->sortParams($_POST['params'], $groupId);
     }
     if (isset($_POST['save_param'])) {
         $selects = new Model_Selects();
         $values = $_POST;
         unset($values['save_param']);
         $selects->saveSelectsParam($values, $_POST['save_param'], $_FILES);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         //  $file = DOCROOT . '/upload/task/file.xlsx';
         //  $load = $excel->load_xls($file, 602, 11, 20);
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_GET['exportExcel'])) {
         $excel = new Model_Excel();
         $res = $excel->uploadFile($_GET['exportExcel']);
         if ($res) {
             $data['messages'] = $res;
         }
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         $data['admfields'] = $group->getAdminFields($groupId, TRUE);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials, 'items_per_page' => 100, 'view' => 'pagination/basic2'));
             $pagination->current_page = intval($pageNum);
             if (isset($_GET['sort']) && $_GET['sort'] != '') {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'), $groupId);
             $data['material'] = $group->getAdminMaterial($materialId);
             //                    //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //комментарии
             //$docs['data'] = $group->getDocs($materialId);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 if ($field['type'] == 'photoalbum') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['photos_base_path'] = $options['photos_base_path'];
                 }
                 if ($field['type'] == 'files') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['files_base_path'] = $options['files_base_path'];
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->bind('multiselect', $field['multiselect'])->bind('folders', $folders)->bind('user', $this->user)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $pictures = $this->action_pictures($wpm['folder']);
     //$comments['status'] = Cookie::get('comments', FALSE);
     // $docs['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     //$this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments));
 }
Exemple #3
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $ordering = $previousPos + 1;
         $result = $group->addParam(array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering));
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $oldGroup = Arr::get($_POST, 'old_group', '0');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         $result = $group->changeGroup($oldGroup, $newGroup, $ids);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials));
             $pagination->current_page = $pageNum;
             if (isset($_GET['sort'])) {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'));
             $data['material'] = $group->getAdminMaterial($materialId);
             //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $folders = $this->getFolders();
     $pictures = $this->action_pictures($wpm['folder']);
     $comments['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     // $this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments, 'pictures' => $pictures, 'wpm' => $wpm, ));
 }