function render()
 {
     $this->template->setFile(dirname(__FILE__) . '/default.latte');
     if ($this->id_product) {
         $this->template->product_alternative = ProductModel::getProductAlternativeValues($this->id_product, $this->id_lang, $this->user, 'RAND()', 4);
     }
     $this->template->product_news = ProductModel::getFluent($this->id_lang)->removeClause('select')->select('id_product')->where('%if', $this->id_category, 'id_category = %i', $this->id_category, 'AND %end news = 1')->orderBy('RAND()')->limit('0,6')->fetchAll();
     foreach ($this->template->product_news as $k => $product) {
         $this->template->product_news[$k] = ProductModel::getProductWithParams($product->id_product, $this->id_lang, $this->user);
     }
     $this->template->product_sale = ProductModel::getFluent($this->id_lang)->removeClause('select')->select('id_product')->where('%if', $this->id_category, 'id_category = %i', $this->id_category, 'AND %end sale = 1')->orderBy('RAND()')->limit('0,6')->fetchAll();
     foreach ($this->template->product_sale as $k => $product) {
         $this->template->product_sale[$k] = ProductModel::getProductWithParams($product->id_product, $this->id_lang, $this->user);
     }
     $this->template->product_our_tip = ProductModel::getFluent($this->id_lang)->removeClause('select')->select('id_product')->where('%if', $this->id_category, 'id_category = %i', $this->id_category, 'AND %end our_tip = 1')->orderBy('RAND()')->limit('0,6')->fetchAll();
     foreach ($this->template->product_our_tip as $k => $product) {
         $this->template->product_our_tip[$k] = ProductModel::getProductWithParams($product->id_product, $this->id_lang, $this->user);
     }
     $this->template->render();
 }
예제 #2
0
 protected function createComponentProductTabella($name)
 {
     //		ProductModel::repairAllProductSequence();
     $id_category = $this->getParam('id_category');
     $fluent = ProductModel::getFluent()->orderBy('product_sequence');
     if ($id_category) {
         $fluent->where('id_category = %i', $id_category);
     } else {
         $fluent->groupBy('id_product');
     }
     $datasource = $fluent->toDatasource();
     $grid = new Tabella($datasource, array('sorting' => 'product_sequence', 'order' => 'product_sequence', 'limit' => 400, "onSuccess" => function ($post) {
         LogModel::save($post, $post['id_log']);
     }));
     $grid->addColumn("Názov", "name", array("width" => 300, "editable" => false));
     $grid->addColumn("Cena", "min_price", array("width" => 100, "editable" => false));
     $_active = array('' => '', 0 => 'Zakázaný', 1 => 'Povolený');
     $grid->addColumn("Akcia", "sale", array("width" => 100, 'type' => Tabella::SELECT, "filter" => array('' => '', 0 => 'nie', 1 => 'áno'), "options" => NULL, "renderer" => function ($row) {
         $el = NHtml::el("td");
         $pom = array('' => '', 0 => 'nie', 1 => 'áno');
         return $el->add($pom[$row['sale']]);
     }));
     $grid->addColumn("Najpredá.", "our_tip", array("width" => 100, 'type' => Tabella::SELECT, "filter" => array('' => '', 0 => 'nie', 1 => 'áno'), "options" => NULL, "renderer" => function ($row) {
         $el = NHtml::el("td");
         $pom = array('' => '', 0 => 'nie', 1 => 'áno');
         return $el->add($pom[$row['our_tip']]);
     }));
     $grid->addColumn("_", "active", array("width" => 100, 'type' => Tabella::SELECT, "filter" => $_active, "options" => '', "editable" => false, "renderer" => function ($row) use($_active) {
         $el = NHtml::el("td");
         //					print_r($row);exit;
         /*
          * link na zmazanie produktu
          */
         $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('deleteProduct!', array('id' => $row->id_product)))->addClass('deleteIcon ajax')->title('Naozaj chcete zmazať položku?'));
         /*
          * link na editaciu produktu
          */
         $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('Product:edit', array('id' => $row->id_product)))->addClass('editIcon'));
         /*
          * posuvanie - ak sa spusti posubanie, treba vypnut zoradovanie !!! order=>false
          */
         //					$el->add(
         //					NHtml::el( 'a' )->href('#')->addClass( 'moveIcon' )
         //							->addId( 'index_'.$row['id_product'] )
         //					);
         /*
          * ikona aktivan polozka, neaktivan polozka
          */
         $span = NHtml::el('span');
         if ($row->active) {
             $span->addClass('activeIcon active');
         } else {
             $span->addClass('unactiveIcon active ');
         }
         $el->add($span);
         return $el;
     }));
     //
     //	$grid->addColumn( "", "id_product",
     //	    array( "width" => 55,
     //		'filter'=>null,
     //		'order'=>false,
     //		"renderer" => function( $row ) {
     //
     //		return NHtml::el( "td" )->add(
     //			NHtml::el( 'a' )->href(
     //				NEnvironment::getApplication()->getPresenter()->link( 'Product:edit' , array('id'=>$row->id_product))
     //			)
     //			->addClass( 'editIcon' )
     //		);
     //
     //	    })
     //	);
     $this->addComponent($grid, $name);
 }
예제 #3
0
 function createComponent($name)
 {
     switch ($name) {
         //	    case 'addForm':
         //			$form = $this->baseForm();
         //			$form->addSubmit('btn', 'Pridať');
         ////			$values['product_alternative'] = ProductModel::getFluent($this->id_lang)->where('id_category = 5')->fetchPairs("id_product",'id_product');
         //			//poziadavka klienta - zobrat vsetky produkty z doplnkov
         //
         //
         //			$form->setDefaults( array('id_product_template_group'=>$this->getService('ProductTemplateGroupModel')->getIdDefaultTemplate()) );
         //
         //
         //			$form->onSuccess[] = callback($this, 'add');
         //			return $form;
         //		break;
         case 'editForm':
             $id_product = $this->getPresenter()->getParam('id');
             $form = $this->baseForm();
             $form['id_product']->setValue($id_product);
             $values = array();
             //Titulok 	- doplnit categoria+ nazov produktu
             //Kľúčové slová -
             //Meta popis - doplnit categoria+ nazov produktu  + Výkon + Dĺžka Horenia
             foreach ($this->template->langs as $l) {
                 $val = ProductModel::get($id_product, $l['id_lang']);
                 // ziste ktore komponenty maju jazykovu mutaciu
                 $controls_for_lang = array();
                 foreach ($form->getComponents() as $control) {
                     if (strpos($control->getName(), CategoryFormControl::$_separator)) {
                         if (strpos($control->getName(), CategoryFormControl::$_separator . $l['iso'])) {
                             list($val_key) = explode(CategoryFormControl::$_separator . $l['iso'], $control->getName());
                             $values += array($control->getName() => $val[$val_key]);
                         }
                     } else {
                         if (isset($val[$control->getName()])) {
                             $values += array($control->getName() => $val[$control->getName()]);
                         }
                     }
                 }
             }
             //print_r(ProductModel::getProductAlternative($id_product));exit;
             $values['product_alternative'] = ProductModel::getProductAlternative($id_product);
             // vyriesenie categorii
             //nacitanie prveho parametru - iba pre jednoparametrove produkty
             $param = (array) dibi::fetch("SELECT * FROM [product_param] WHERE id_product = %i", $id_product);
             $form->setDefaults(array_merge($param, $values));
             $form->addSubmit('btn_save_and_stay', 'Upraviť a zostať tu');
             $form->addSubmit('btn_save', 'Upraviť');
             $form->onSuccess[] = callback($this, 'save');
             return $form;
             break;
             /*
              * generator
              */
         /*
          * generator
          */
         case 'generatorForm':
             //ProductModel::repairMinPrice();
             NFormContainer::extensionMethod('NFormContainer::addCheckboxList', array('CheckboxList', 'addCheckboxList'));
             $sizes = dibi::query("SELECT size FROM [product_param] WHERE size !='' GROUP BY size")->fetchPairs('size', 'size');
             $colors = dibi::query("SELECT color FROM [product_param] WHERE color !='' GROUP BY color")->fetchPairs('color', 'color');
             $materials = dibi::query("SELECT material FROM [product_param] WHERE material !='' GROUP BY material")->fetchPairs('material', 'material');
             $f = new MyForm();
             //			$f->getElementPrototype()->addClass('ajax');
             $renderer = $f->getRenderer();
             $renderer->wrappers['controls']['container'] = NHtml::el('div')->addClass('container');
             $renderer->wrappers['pair']['container'] = NHtml::el('div')->addClass('pair-container');
             $renderer->wrappers['label']['container'] = NHtml::el('h3');
             $renderer->wrappers['control']['container'] = NHtml::el('div')->addClass('input-container');
             //			usort($sizes, 'EshopProductControl::cmp');
             $f->addCheckboxList('size', 'Veľkosť', $sizes);
             $f->addCheckboxList('color', 'Farba', $colors);
             $f->addCheckboxList('material', 'Material', $materials);
             //ak je pridavanie a neexistuje id
             $f->addHidden('id_product', $this->getParam('id'));
             //
             //
             //			$renderer = $f->getRenderer();
             //			$renderer->wrappers['label']['container'] = NULL;
             //
             //			//ziskaj vsetky mozne velkosti
             //			$sizes = dibi::fetchAll("SELECT size FROM [product_param] GROUP BY size");
             //			$f->addGroup('Veľkosť');
             //			foreach($sizes as $k=>$size){
             //				$f->addCheckbox('size_'.$k, $size['size']);
             //			}
             //
             //			//ziskaj vsetky mozne farby
             //			$colors = dibi::fetchAll("SELECT color FROM [product_param] GROUP BY color");
             //			$f->addGroup('Farba');
             //			foreach($colors as $k=>$color){
             //				$f->addCheckbox('color_'.$k, $color['color']);
             //			}
             //
             //			//ziskaj vsetky mozne material
             //			$materials = dibi::fetchAll("SELECT material FROM [product_param] GROUP BY material");
             //			$f->addGroup('Material');
             //			foreach($materials as $k=>$material){
             //				$f->addCheckbox('material_'.$k, $material['material']);
             //			}
             $f->addGroup()->setOption('container', 'fieldset class=clear');
             $f->addSubmit('btn_generate', 'Generovať');
             $f->onSuccess[] = array($this, 'handleAddGeneratedParam');
             return $f;
             break;
         case 'productParams':
             //			$d = ProductModel::getProductParamDatasource( $this->getParam('id'))->fetchAll();
             $id_product = $this->getParam('id');
             $grid = new Tabella(ProductModel::getProductParamDatasource($id_product), array('sorting' => 'asc', 'order' => 'sequence', 'id_table' => 'id_product_param', 'limit' => 50, "onSubmit" => function ($post) {
                 //						print_r($post);exit;
                 ProductModel::setProductParamValue($post, $post['id_product_param']);
             }, "onDelete" => function ($id) {
                 ProductModel::deleteProductParamValue($id);
             }));
             $el = NHtml::el("div");
             $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('addEmptyParam!', array('id_product' => $id_product)))->addClass('addIcon ajax'));
             $grid->addColumn($el, 'sequence', array('width' => 20, 'filter' => NULL, "editable" => true));
             //vytiahnutie template_group pre produkt - ake bude mat parametre
             if ($id_product) {
                 $id_product_template_group = ProductModel::getFluent(1, false, false)->removeClause('select')->select('id_product_template_group')->where('id_product = %i', $id_product)->fetchSingle();
             } else {
                 //ak je id_product NULL jedna sa pridavanie produktu
                 if ($id_product == NULL and $this->getParam('id_product_template_group') != NULL) {
                     $id_product_template_group = $this->getParam('id_product_template_group');
                 } else {
                     $id_product_template_group = $this->getService('ProductTemplateGroupModel')->getIdDefaultTemplate();
                 }
             }
             $params = $this->getService('ProductTemplateGroupModel')->fetchAssocAllParam($id_product_template_group);
             foreach ($params as $p) {
                 if ($p['checked']) {
                     $grid->addColumn($this->getService('translator')->translate($p['row_name']), $p['row_name'], array("width" => 50, "editable" => true));
                 }
             }
             $grid->addColumn("Cena", "price", array("width" => 100, "editable" => true));
             //			_repairPriceForView
             //
             //
             //			$grid->addColumn( "Na sklade", "stock", array( "width" => 50, "editable" => true ) );
             ////			$grid->addColumn( "Farba", "color", array( "width" => 100, "editable" => true ) );
             ////			$grid->addColumn( "Veľkosť", "size", array( "width" => 100, "editable" => true ) );
             ////			$grid->addColumn( "Material", "material", array( "width" => 100, "editable" => true ) );
             //			$grid->addColumn( "Napojenie", "connection", array( "width" => 100, "editable" => true ) );
             //			$grid->addColumn( "Cena", "price", array( "width" => 100, "editable" => true ) );
             $grid->addColumn("", "", array("width" => 30, 'filter' => NULL, "options" => '', "renderer" => function ($row) {
                 $el = NHtml::el("td");
                 $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('deleteProductParam!', array('id_product_param' => $row->id_product_param)))->addClass('deleteIcon ajax'));
                 return $el;
             }));
             $this->addComponent($grid, $name);
             break;
         case 'pictogram':
             $p = new PictogramControl($this, $name);
             return $p;
             break;
         case 'keyword':
             return new KeywordControl();
             break;
         case 'ajaxtest':
             return new AjaxTextControl();
             break;
         default:
             return parent::createComponent($name);
             break;
     }
 }