<?php
/**
 * Generated: 2014-03-24 15:01:35
 * @author Rtn_Module_Tool
 */
class Bip_Controller_Admin_ChildrenController extends Eppe_Crud_Controller_Action {
	
	protected $grid = 'Bip_Jqgrid_Admin_Children';
	protected $crud = 'Bip_CRUD_Admin_Children';
	
	public function init() {
                parent::init();
        }
	
	public function indexAction() {
		$bean = R::findOne('biparticle', "WHERE `id` = {$this->getParam('id')} ORDER BY `id` desc");
		
		$session = new Zend_Session_Namespace('bip');
		$session->children_id = $bean->uid;
		
		if ($this->isAjax) {
			$this->ajaxResponse->data = $this->grid->render();
		}
		else {
			$this->view->grid = $this->grid->render();
		}
		$bean = R::findOne('biparticle', "WHERE `uid` = {$session->children_id} ORDER BY `id` desc");
		$this->view->groupId = $bean->category_id;
	}
	
	
	public function ajaxLoadDatagridAction() {
		$session = new Zend_Session_Namespace('bip');
		echo $this->grid->loadDatagrid($session->children_id);
		exit;
	}
}


//	public function indexAction() {
//		$beans = R::findAll('artykuly');
//		$cyrylicFrom = array(
//		    '³','æ','¿','¶','ê','±','¦','ñ','Ê'
//		);
//		$cyrylicTo = array(
//		    'ł','ć','ż','ś','ę','ą','Ś','ń','Ę'
//		);
//		
//		
//		foreach ($beans as $bean) {
//			$bean->tytul= str_replace($cyrylicFrom, $cyrylicTo, $bean->tytul);
//			$bean->tresc = str_replace($cyrylicFrom, $cyrylicTo, $bean->tresc);
//			$bean->autor = str_replace($cyrylicFrom, $cyrylicTo, $bean->autor);
//			R::store($bean);
//		}
///*		echo 'Go Go!' . PHP_EOL;
//		$counter = 0;
//		$magicArray = array();
//		if (($handle = fopen("oilcategorie.csv", "r")) !== FALSE) {
//			while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
//				$magicArray[$data[0]] = $data[1];
//				$counter++;
//				
//			}
//			fclose($handle);
//		}
//		
//		$magicBeans = R::findAll('artykuly');
//		foreach ($magicBeans as $fasolkaWszystkichSamkow) {
//			if(array_key_exists($fasolkaWszystkichSamkow->parent, $magicArray)){
//				$fasolkaWszystkichSamkow->parent = $magicArray[$fasolkaWszystkichSamkow->parent];
//			}else{
//				$fasolkaWszystkichSamkow->parent = 0;
//			}
//			R::store($fasolkaWszystkichSamkow);
//		}
//		echo 'Koniec!' . PHP_EOL;
//*/		
//			
//}
	