Exemplo n.º 1
0
 public function action_edit()
 {
     $request = $this->request->current();
     $id = (int) $request->param('id');
     $helper_orm = ORM_Helper::factory('video');
     $orm = $helper_orm->orm();
     if ((bool) $id) {
         $orm->where('id', '=', $id)->find();
         if (!$orm->loaded() or !$this->acl->is_allowed($this->user, $orm, 'edit')) {
             throw new HTTP_Exception_404();
         }
         $this->title = __('Edit video');
     } else {
         $this->title = __('Add video');
     }
     if (empty($this->back_url)) {
         $query_array = array();
         $query_array = Paginator::query($request, $query_array);
         $this->back_url = Route::url('modules', array('controller' => $this->controller_name['element'], 'query' => Helper_Page::make_query_string($query_array)));
     }
     if ($this->is_cancel) {
         $request->redirect($this->back_url);
     }
     $errors = array();
     $submit = $request->post('submit');
     if ($submit) {
         try {
             if ((bool) $id) {
                 $orm->updater_id = $this->user->id;
                 $orm->updated = date('Y-m-d H:i:s');
                 $reload = FALSE;
             } else {
                 $orm->site_id = SITE_ID;
                 $orm->creator_id = $this->user->id;
                 $reload = TRUE;
             }
             $values = $request->post();
             $values['public_date'] = $this->value_multiple_date($values, 'public_date');
             if (empty($values['uri'])) {
                 $values['uri'] = transliterate_unique($values['title'], $orm, 'uri');
             }
             $helper_orm->save($values + $_FILES);
             if ($reload) {
                 if ($submit != 'save_and_exit') {
                     $this->back_url = Route::url('modules', array('controller' => $request->controller(), 'action' => $request->action(), 'id' => $orm->id, 'query' => Helper_Page::make_query_string($request->query())));
                 }
                 $request->redirect($this->back_url);
             }
         } catch (ORM_Validation_Exception $e) {
             $errors = $this->errors_extract($e);
         }
     }
     // If add action then $submit = NULL
     if (!empty($errors) or $submit != 'save_and_exit') {
         $this->template->set_filename('modules/video/element/edit')->set('errors', $errors)->set('helper_orm', $helper_orm);
         $this->left_menu_element_add();
     } else {
         $request->redirect($this->back_url);
     }
 }
Exemplo n.º 2
0
 public function get_hook($orm)
 {
     if ($orm->blog_id == 0) {
         $blog_orm = ORM::factory('blog');
         $blog_orm->values(array('group' => $this->blog_group, 'site_id' => $orm->site_id, 'creator_id' => $this->user->id, 'status' => Kohana::$config->load('_blog.status_codes.hidden'), 'title' => $orm->title, 'uri' => transliterate_unique($orm->title, $blog_orm, 'uri'), 'for_all' => $orm->for_all))->save();
         $orm->blog_id = $blog_orm->id;
         $orm->save();
         unset($blog_orm);
     }
     return array(array($this, 'hook_callback'), array($orm));
 }
Exemplo n.º 3
0
 public function get_hook($orm)
 {
     if ($orm->photo_album_id == 0) {
         $photo_album_orm = ORM::factory('photo_Album');
         $photo_album_orm->values(array('group' => $this->album_group, 'site_id' => $orm->site_id, 'creator_id' => $this->user->id, 'public_date' => date('Y-m-d H:i:s'), 'status' => Kohana::$config->load('_photo.status_codes.hidden'), 'title' => $orm->title, 'uri' => transliterate_unique($orm->title, $photo_album_orm, 'uri'), 'for_all' => $orm->for_all))->save();
         $orm->photo_album_id = $photo_album_orm->id;
         $orm->save();
         unset($photo_album_orm);
     }
     return array(array($this, 'hook_callback'), array($orm));
 }
Exemplo n.º 4
0
 public function action_edit()
 {
     $request = $this->request->current();
     $id = (int) $request->param('id');
     $helper_orm = ORM_Helper::factory('page');
     $orm = $helper_orm->orm();
     if ((bool) $id) {
         $orm->and_where('id', '=', $id)->find();
         if (!$this->acl->is_allowed($this->user, $orm, 'edit')) {
             throw new HTTP_Exception_404();
         }
         $this->title = __('Edit page');
     } else {
         $this->title = __('Add page');
     }
     if (empty($this->back_url)) {
         $this->back_url = Route::url('admin', array('controller' => 'pages'));
     }
     if ($this->is_cancel) {
         $request->redirect($this->back_url);
     }
     $pages_db = ORM::factory('page')->order_by('level', 'asc')->order_by('parent_id', 'asc')->order_by('position', 'asc')->find_all();
     $pages = $pages_db->as_array('id');
     $errors = array();
     $submit = $request->post('submit');
     if ($submit) {
         try {
             if ((bool) $id) {
                 $orm->updater_id = $this->user->id;
                 $orm->updated = date('Y-m-d H:i:s');
             } else {
                 $orm->site_id = SITE_ID;
                 $orm->creator_id = $this->user->id;
             }
             $parent_id = (int) $request->post('parent_id');
             if ($parent_id > 0 and isset($pages[$parent_id])) {
                 $orm->level = $pages[$parent_id]->level + 1;
             } else {
                 $orm->level = Model_Page::LEVEL_START;
             }
             $values = $this->meta_seo_reset($this->request->current()->post(), 'meta_tags');
             if (empty($values['uri'])) {
                 $values['uri'] = transliterate_unique($values['title'], $orm, 'uri', array(array('and', 'parent_id', '=', $parent_id)));
             }
             if (!IS_MASTER_SITE) {
                 $values['for_all'] = 0;
             }
             if (!IS_MASTER_SITE) {
                 $values['can_hiding'] = 0;
             }
             $helper_orm->save($values + $_FILES);
             Helper_Page::clear_cache();
         } catch (ORM_Validation_Exception $e) {
             $errors = $this->errors_extract($e);
         }
     }
     if (!empty($errors) or $submit != 'save_and_exit') {
         $relations = $pages_db->as_array('id', 'parent_id');
         $modules = array();
         $linked_modules = Helper_Module::linked_modules();
         $leave_module_types = array(Helper_Module::MODULE_SINGLE, Helper_Module::MODULE_STANDALONE);
         $this_page = $helper_orm->orm()->as_array();
         foreach (Helper_Module::modules() as $key => $value) {
             $_own_module = ($this_page['type'] == 'module' and $this_page['data'] == $key);
             if (in_array($key, $linked_modules) and in_array($value['type'], $leave_module_types) and !$_own_module) {
                 continue;
             }
             $modules[$key] = __($value['name']);
         }
         if ((bool) $id) {
             $page_list = array_diff_key(Helper_Page::parse_to_list($pages), array_flip($this->_get_childrens($id, $relations)));
         } else {
             $page_list = Helper_Page::parse_to_list($pages);
         }
         $properties = $helper_orm->property_list();
         $this->template->set_filename('pages/edit')->set('errors', $errors)->set('helper_orm', $helper_orm)->set('pages', $page_list)->set('base_uri_list', Helper_Page::parse_to_base_uri($pages))->set('modules', $modules)->set('properties', $properties);
     } else {
         $request->redirect($this->back_url);
     }
 }
Exemplo n.º 5
0
 public function action_edit()
 {
     $blog_orm = ORM::factory('blog')->where('group', '=', $this->group_key)->and_where('id', '=', $this->blog_id)->find();
     if (!$blog_orm->loaded()) {
         throw new HTTP_Exception_404();
     }
     $request = $this->request->current();
     $id = (int) $this->request->current()->param('id');
     $helper_orm = ORM_Helper::factory('blog_Post');
     $orm = $helper_orm->orm();
     if ((bool) $id) {
         $orm->where('id', '=', $id)->find();
         if (!$orm->loaded() or !$this->acl->is_allowed($this->user, $orm, 'edit')) {
             throw new HTTP_Exception_404();
         }
         $this->title = __('Edit post');
     } else {
         $this->title = __('Add post');
     }
     if (empty($this->back_url)) {
         $query_array = array('group' => $this->group_key, 'blog' => $this->blog_id);
         $query_array = Paginator::query($request, $query_array);
         $this->back_url = Route::url('modules', array('controller' => $this->controller_name['element'], 'query' => Helper_Page::make_query_string($query_array)));
     }
     if ($this->is_cancel) {
         $request->redirect($this->back_url);
     }
     $errors = array();
     $submit = $request->post('submit');
     if ($submit) {
         try {
             if ((bool) $id) {
                 $orm->updater_id = $this->user->id;
                 $orm->updated = date('Y-m-d H:i:s');
                 $reload = FALSE;
             } else {
                 $orm->site_id = SITE_ID;
                 $orm->creator_id = $this->user->id;
                 $orm->blog_id = $this->blog_id;
                 $reload = TRUE;
             }
             $values = $this->meta_seo_reset($this->request->current()->post(), 'meta_tags');
             $values['public_date'] = $this->value_multiple_date($values, 'public_date');
             if (empty($values['uri'])) {
                 $values['uri'] = transliterate_unique($values['title'], $orm, 'uri');
             }
             $helper_orm->save($values + $_FILES);
             if ($reload) {
                 if ($submit != 'save_and_exit') {
                     $this->back_url = Route::url('modules', array('controller' => $request->controller(), 'action' => $request->action(), 'id' => $orm->id, 'query' => Helper_Page::make_query_string($request->query())));
                 }
                 $request->redirect($this->back_url);
             }
         } catch (ORM_Validation_Exception $e) {
             $errors = $this->errors_extract($e);
         }
     }
     // If add action then $submit = NULL
     if (!empty($errors) or $submit != 'save_and_exit') {
         $this->left_menu_blog_add($blog_orm);
         $this->left_menu_element_list();
         $this->left_menu_element_add();
         $blogs_list = ORM::factory('blog')->order_by('position', 'asc')->find_all()->as_array('id', 'title');
         if (!$orm->loaded()) {
             $orm->blog_id = $this->blog_id;
         }
         $properties = $helper_orm->property_list();
         $this->template->set_filename('modules/blog/element/edit')->set('helper_orm', $helper_orm)->set('blogs_list', $blogs_list)->set('properties', $properties);
         if (Helper_Module::check_module('kubikrubik-photo')) {
             $injector = $this->injectors['photo'];
             if ($orm->loaded()) {
                 try {
                     $this->hook_list_content[] = $injector->get_hook($orm);
                     $this->menu_left_add($injector->menu_list($orm->photo_album));
                     $this->menu_left_add($injector->menu_add($orm->photo_album));
                     $this->menu_left_add($injector->menu_fix($orm->photo_album));
                 } catch (ORM_Validation_Exception $e) {
                     $errors = array_merge($errors, $this->errors_extract($e));
                 }
             }
         }
         $this->template->set('errors', $errors);
     } else {
         $request->redirect($this->back_url);
     }
 }
Exemplo n.º 6
0
 public function action_edit()
 {
     $request = $this->request->current();
     $this->blog_id = $id = (int) $this->request->current()->param('id');
     $helper_orm = ORM_Helper::factory('blog');
     $orm = $helper_orm->orm();
     if ((bool) $id) {
         $orm->and_where('id', '=', $id)->find();
         if (!$orm->loaded() or !$this->acl->is_allowed($this->user, $orm, 'edit')) {
             throw new HTTP_Exception_404();
         }
         $this->title = __('Edit blog');
     } else {
         $this->title = __('Add blog');
     }
     if (empty($this->back_url)) {
         $query_array = array('group' => $this->group_key);
         $query_array = Paginator::query($request, $query_array);
         $this->back_url = Route::url('modules', array('controller' => $this->controller_name['entity'], 'query' => Helper_Page::make_query_string($query_array)));
     }
     if ($this->is_cancel) {
         $request->redirect($this->back_url);
     }
     $errors = array();
     $submit = Request::$current->post('submit');
     if ($submit) {
         try {
             if ($orm->loaded()) {
                 $orm->updater_id = $this->user->id;
                 $orm->updated = date('Y-m-d H:i:s');
                 $reload = FALSE;
             } else {
                 $orm->group = $this->group_key;
                 $orm->site_id = SITE_ID;
                 $orm->creator_id = $this->user->id;
                 $reload = TRUE;
             }
             $values = $this->meta_seo_reset($this->request->current()->post(), 'meta_tags');
             if (empty($values['uri'])) {
                 $values['uri'] = transliterate_unique($values['title'], $orm, 'uri');
             }
             $helper_orm->save($values + $_FILES);
             if ($reload) {
                 if ($submit != 'save_and_exit') {
                     $this->back_url = Route::url('modules', array('controller' => $request->controller(), 'action' => $request->action(), 'id' => $orm->id, 'query' => Helper_Page::make_query_string($request->query())));
                 }
                 $request->redirect($this->back_url);
             }
         } catch (ORM_Validation_Exception $e) {
             $errors = $this->errors_extract($e);
         }
     }
     // If add action then $submit = NULL
     if (!empty($errors) or $submit != 'save_and_exit') {
         $status_list = Kohana::$config->load('_blog.status');
         $this->template->set_filename('modules/blog/entity/edit')->set('errors', $errors)->set('helper_orm', $helper_orm)->set('status_list', $status_list);
         $this->left_menu_blog_add($orm);
         $this->left_menu_blog_fix($orm);
     } else {
         $request->redirect($this->back_url);
     }
 }
Exemplo n.º 7
0
 private function load_product(array $data, $directory)
 {
     $result = NULL;
     $orm_helper = ORM_Helper::factory('catalog_Element');
     $orm_helper->orm()->where('category_id', '=', $data['category_id'])->where('code', '=', $data['code'])->find();
     $values = array('category_id' => $data['category_id'], 'code' => $data['code'], 'title' => $data['name'], 'uri' => transliterate_unique($data['name'], $orm_helper->orm(), 'uri'), 'active' => '1', 'image_1' => '', 'image_2' => '', 'properties' => array('Characteristics.Material' => $data['material'], 'Characteristics.Density' => $data['density'], 'Brand.Name' => $data['brand'], 'Brand.Сountry' => $data['country'], 'Provider' => $data['provider']));
     $images = $this->make_images_value($data, $directory);
     foreach ($images as $_src) {
         if (empty($values['image_1'])) {
             $values['image_1'] = $_src;
         }
         if (empty($values['image_2'])) {
             $values['image_2'] = $_src;
         }
         if (!empty($values['image_1']) and !empty($values['image_2'])) {
             break;
         }
     }
     $log_action = '';
     if ($orm_helper->orm()->loaded()) {
         unset($values['uri']);
         $values['updated'] = date('Y-m-d H:i:s');
         $values['updater_id'] = $this->config['user_id'];
         $log_action = 'обновлен';
     } else {
         $values['creator_id'] = $this->config['user_id'];
         $log_action = 'добавлен';
     }
     try {
         $orm_helper->save($values);
         $result = $orm_helper->orm();
         $this->log[] = date('Y-m-d H:i:s') . " продукт {$data['code']} " . $log_action;
     } catch (ORM_Validation_Exception $e) {
         $this->errors = TRUE;
         $errors = $this->errors_extract($e);
         foreach ($errors as $_f => $_m) {
             $this->log[] = date('Y-m-d H:i:s') . " <span class=\"err\">[error]</span> для продукта {$data['code']}: " . $_m;
         }
     }
     return $result;
 }