Example #1
0
 function get_short_info($id = false, $current_language = 'English')
 {
     #
     $language = new Language();
     is_numeric($current_language) ? $language->get_by_id($current_language) : $language->get_by_name($current_language);
     #svazivaet nutrition s vibranim language
     if ($id) {
         $this->get_by_id($id);
         $this->language->include_join_fields()->get_iterated();
     } else {
         $full_list = new Nutrition();
         $full_list->select('id, tagname')->where('Group_List', 3)->get_iterated();
         #создает объектную модель данных для одбращения к данным через свойства объекта
         $this->select('id, tagname, value, units')->where('group_list', 3)->get();
         foreach ($this as $nutrition) {
             $this->data->{strtolower($nutrition->tagname)} = array('id' => $nutrition->id, 'value' => $nutrition->value, 'units' => $nutrition->units);
         }
         #добавляет нулевые значения к отсутствующим данным
         foreach ($full_list as $elem) {
             if (!isset($this->data->{strtolower($elem->tagname)})) {
                 $this->data->{strtolower($elem->tagname)} = array('id' => $elem->id, 'value' => '~', 'units' => '');
             }
         }
         $this->id = null;
     }
 }
Example #2
0
 function _nutrition_name_exists($name)
 {
     $nutrition = new Nutrition();
     $nutrition->where('name', $name)->get();
     if ($nutrition->exists()) {
         return false;
     }
     return true;
 }
Example #3
0
 function edit($id = false)
 {
     $this->load->library('form_validation');
     # Js function from main.js which loads by default
     array_push($this->data['js_functions'], array('name' => 'products_edit_init', 'data' => FALSE));
     $product = new Product($id);
     # if form validates
     if ($this->form_validation->run('products_edit')) {
         $product->product_category_id = $this->input->post('product_category_id');
         $product->mera_id = $this->input->post('mera_id');
         $product->price = $this->input->post('price');
         $product->units_for_price = $this->input->post('units_for_price');
         $product->mera_for_price = $this->input->post('mera_for_price');
         #
         if ($this->save_object_name($product)) {
             $nutrition_categories = new Nutrition_category();
             $nutrition_categories->get();
             #
             foreach ($nutrition_categories as $nc) {
                 if (!$this->input->post('nutrition_category_' . $nc->id)) {
                     continue;
                 }
                 $nc->save($product);
                 $nc->set_join_field($product, 'value', $this->input->post('nutrition_category_' . $nc->id));
             }
             #NUTRITION
             $hidden_nutrition_add = $this->input->post('hidden_nutrition') ? $this->input->post('hidden_nutrition') : array();
             $hidden_nutrition_remove = $this->input->post('hidden_nutrition_removed') ? $this->input->post('hidden_nutrition_removed') : array();
             #
             $hidden_nutrition_add = array_map('explode_ext', $hidden_nutrition_add);
             #
             $hidden_nutrition_remove = array_diff($hidden_nutrition_remove, return_subarray_by_key('id', $hidden_nutrition_add));
             #SAVE Nutrition
             $nutrition = new Nutrition();
             foreach ($hidden_nutrition_add as $hn_add) {
                 $nutrition->get_by_id($hn_add['id']);
                 $product->save($nutrition);
                 $product->set_join_field($nutrition, 'value', $hn_add['value']);
             }
             #DELETE Nutrition
             if ($hidden_nutrition_remove) {
                 $nutrition->where_in('id', $hidden_nutrition_remove)->get();
                 $product->delete($nutrition->all);
             }
             #MERAS-PRODUCT
             $selected_mera = $this->input->post('selected_meras');
             $meras = new Mera();
             if ($selected_mera) {
                 $meras->where_not_in('id', $selected_mera)->get();
                 $product->delete($meras->all);
                 $meras->where_in('id', $selected_mera)->get();
                 $product->save($meras->all);
             }
             #IMAGES
             #esli biblioteka my_upload_image_lib proinicializirovalas' verno to image zagrujaetca i resize
             $this->upload_image_lib->initialize(array('type' => 'product', 'size' => 'tiny'));
             #vozvrashaet polnoe ima kartinki primer: pi_id.jpg; v bazu sohranaetsa tol'ko $recipe_image_id
             $image_name = $this->upload_image_lib->upload_resize_img('image', $product->id);
             if ($image_name) {
                 $product->image = $image_name;
                 $product->save();
             }
             $this->data['form_success'] = 'Продукт добавлен';
         } else {
             $this->data['form_error'] = $product->error->string;
         }
     } else {
         echo validation_errors();
     }
     #
     $meras = new Mera();
     $product = new Product();
     $nutrition_categories = new Nutrition_category();
     $languages = new Language();
     $product_categories->get_full_info();
     $product_categories->product_type->get_full_info();
     $product_categories->product_type->product->get_full_info($id);
     $product_categories->product_type->product->language->get_full_info();
     $product_categories->product_type->product->nutrition->get_full_info();
     $product_categories->product_type->product->nutrition->convert_to_mera(1);
     $meras_available = array('100 gramms');
     foreach ($product_categories->product_type->product->mera as $mera) {
         $meras_available[$mera->join_seq] = $mera->join_name . ' ( ' . $mera->join_value . ' gm )';
     }
     #
     $meras->get_full_info();
     #
     $nutrition_categories->get_full_info();
     #
     $languages->get_iterated();
     #
     $this->data['meras_available'] = $meras_available;
     $this->data['dm_product_categories'] = $product_categories;
     $this->data['dm_product_types'] = $product_categories->product_type;
     $this->data['dm_product'] = $product_categories->product_type->product;
     $this->data['dm_nutrition_categories'] = $nutrition_categories;
     $this->data['dm_languages'] = $languages;
     $this->data['meras'] = $meras;
     $this->template->load('/admin/templates/main_template', '/admin/products/edit', $this->data);
 }