"-","replace_other"=>"-"); CModule::IncludeModule('ees.mci'); use \Ees; $file_xlsx = trim($argv[1]); if($file_xlsx=='' && $USER->IsAdmin())$file_xlsx='import_xlsx/'.basename($_REQUEST['file']); $curr_dir = __DIR__.'/'; $http_dir = str_replace($_SERVER['DOCUMENT_ROOT'],'',__DIR__).'/';; $cols = array( 'ISBN'=>0, 'PART'=>1, 'IS_TOP'=>2, 'IS_NEW'=>3, 'ANNOTACIYA'=>'4', 'SUB_PART'=>5, 'SUB_PART_DESCRIPTION'=>6, ); require_once $_SERVER['DOCUMENT_ROOT'].'/utils/lib/PHPExcel_1.8.0/Classes/PHPExcel/IOFactory.php'; $inputFileType = PHPExcel_IOFactory::identify($file_xlsx); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($file_xlsx); $aSheet = $objPHPExcel->getActiveSheet(); $highestRow = $aSheet->getHighestRow(); $highestColumn = PHPExcel_Cell::columnIndexFromString( $aSheet->getHighestColumn()); $matr = array(); for ($row =0; $row <=$highestRow; ++ $row) { for ($col = 0; $col <= $highestColumn; $col++) { $matr[$row][$col] = $aSheet->getCellByColumnAndRow($col, $row)->getValue(); } } exec('rm -rf '.$curr_dir.'json/*.json'); $aRubric = array();; foreach ($matr as $row_nom=>$row){ $rub_code = Cutil::translit(trim(mb_convert_case($row[$cols['PART']],MB_CASE_LOWER,'UTF-8')),"ru",$arTranslit);; if($rub_code=='razdel'){ echo "Пропускаем строку $row_nom\n"; continue; } $subrub_code = Cutil::translit(trim(mb_convert_case($row[$cols['SUB_PART']],MB_CASE_LOWER,'UTF-8')),"ru",$arTranslit);; if($rub_code==''){ echo "Пропускаем строку $row_nom, не известный код раздела\n"; continue; } if(!isset($aRubric[$rub_code])) { $aRubric[$rub_code] = array( 'NAME' => $row[$cols['PART']], 'CHILD' => array() ); } $book_src = \Ees\Mci\Books::find(array('ISBN'=>$row[$cols['ISBN']]),array())->getNext(); if(!$book_src){ echo "NO FIND BOOK "; print_r($row); echo "\n"; continue; } $book = array( 'NOMCODE'=>$book_src['NOMCODE'], 'NAME'=>$book_src['NAME'], 'DESCRIPTION' =>$row[$cols['ANNOTACIYA']]!=''?$row[$cols['ANNOTACIYA']]:$book_src['ANNOTACIA'], 'DETAIL_PAGE_URL'=>$book_src['DETAIL_PAGE_URL'], 'AUTHOR'=>strip_tags($book_src['AUTHOR_LINK']) ); foreach($book_src['PRICE'] as $p){ if($p['shop']=='book24_ru'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='book24_ru';} } if(!isset($book['PRICE_URL'])){ foreach($book_src['PRICE'] as $p){ if($p['shop']=='labirint'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='labirint';} } } if(!isset($book['PRICE_URL'])){ foreach($book_src['PRICE'] as $p){ if($p['shop']=='ozon'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='ozon';} } } if($subrub_code=='') $aRubric[$rub_code]['BOOKS'][]=$book; if($row[$cols['IS_TOP']]+0==1)$aRubric[$rub_code]['TOP'][]=$book; if($row[$cols['IS_NEW']]+0==1)$aRubric[$rub_code]['NEW'][]=$book; if($subrub_code=='' && $row[$cols['IS_TOP']]+0==0 && $row[$cols['IS_NEW']]+0==0){ $aRubric[$rub_code]['OTHER'][]=$book; } if($subrub_code=='')continue; if($aRubric[$rub_code]['CHILD'][$subrub_code]['NAME']=='') $aRubric[$rub_code]['CHILD'][$subrub_code]['NAME'] = $row[$cols['SUB_PART']]; if($aRubric[$rub_code]['CHILD'][$subrub_code]['DESCRIPTION']=='' && $row[$cols['SUB_PART_DESCRIPTION']]!='') $aRubric[$rub_code]['CHILD'][$subrub_code]['DESCRIPTION'] = $row[$cols['SUB_PART_DESCRIPTION']]; $aRubric[$rub_code]['CHILD'][$subrub_code]['BOOKS'][] = $book; } $menu = array(); foreach ($aRubric as $r_code=>$r){ file_put_contents($curr_dir.'json/'.$r_code.'.json',json_encode($r,JSON_UNESCAPED_UNICODE,JSON_PRETTY_PRINT)); $menu[] = array($r_code,$r['NAME']); } file_put_contents($curr_dir.'json/_menu.json',json_encode($menu,JSON_UNESCAPED_UNICODE,JSON_PRETTY_PRINT)); "-","replace_other"=>"-"); CModule::IncludeModule('ees.mci'); use \Ees; $file_xlsx = trim($argv[1]); if($file_xlsx=='' && $USER->IsAdmin())$file_xlsx='import_xlsx/'.basename($_REQUEST['file']); $curr_dir = __DIR__.'/'; $http_dir = str_replace($_SERVER['DOCUMENT_ROOT'],'',__DIR__).'/';; $cols = array( 'ISBN'=>0, 'PART'=>1, 'IS_TOP'=>2, 'IS_NEW'=>3, 'ANNOTACIYA'=>'4', 'SUB_PART'=>5, 'SUB_PART_DESCRIPTION'=>6, ); require_once $_SERVER['DOCUMENT_ROOT'].'/utils/lib/PHPExcel_1.8.0/Classes/PHPExcel/IOFactory.php'; $inputFileType = PHPExcel_IOFactory::identify($file_xlsx); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($file_xlsx); $aSheet = $objPHPExcel->getActiveSheet(); $highestRow = $aSheet->getHighestRow(); $highestColumn = PHPExcel_Cell::columnIndexFromString( $aSheet->getHighestColumn()); $matr = array(); for ($row =0; $row <=$highestRow; ++ $row) { for ($col = 0; $col <= $highestColumn; $col++) { $matr[$row][$col] = $aSheet->getCellByColumnAndRow($col, $row)->getValue(); } } exec('rm -rf '.$curr_dir.'json/*.json'); $aRubric = array();; foreach ($matr as $row_nom=>$row){ $rub_code = Cutil::translit(trim(mb_convert_case($row[$cols['PART']],MB_CASE_LOWER,'UTF-8')),"ru",$arTranslit);; if($rub_code=='razdel'){ echo "Пропускаем строку $row_nom\n"; continue; } $subrub_code = Cutil::translit(trim(mb_convert_case($row[$cols['SUB_PART']],MB_CASE_LOWER,'UTF-8')),"ru",$arTranslit);; if($rub_code==''){ echo "Пропускаем строку $row_nom, не известный код раздела\n"; continue; } if(!isset($aRubric[$rub_code])) { $aRubric[$rub_code] = array( 'NAME' => $row[$cols['PART']], 'CHILD' => array() ); } $book_src = \Ees\Mci\Books::find(array('ISBN'=>$row[$cols['ISBN']]),array())->getNext(); if(!$book_src){ echo "NO FIND BOOK "; print_r($row); echo "\n"; continue; } $book = array( 'NOMCODE'=>$book_src['NOMCODE'], 'NAME'=>$book_src['NAME'], 'DESCRIPTION' =>$row[$cols['ANNOTACIYA']]!=''?$row[$cols['ANNOTACIYA']]:$book_src['ANNOTACIA'], 'DETAIL_PAGE_URL'=>$book_src['DETAIL_PAGE_URL'], 'AUTHOR'=>strip_tags($book_src['AUTHOR_LINK']) ); foreach($book_src['PRICE'] as $p){ if($p['shop']=='book24_ru'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='book24_ru';} } if(!isset($book['PRICE_URL'])){ foreach($book_src['PRICE'] as $p){ if($p['shop']=='labirint'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='labirint';} } } if(!isset($book['PRICE_URL'])){ foreach($book_src['PRICE'] as $p){ if($p['shop']=='ozon'){$book['PRICE_URL'] = $p['url']; $book['SHOP']='ozon';} } } if($subrub_code=='') $aRubric[$rub_code]['BOOKS'][]=$book; if($row[$cols['IS_TOP']]+0==1)$aRubric[$rub_code]['TOP'][]=$book; if($row[$cols['IS_NEW']]+0==1)$aRubric[$rub_code]['NEW'][]=$book; if($subrub_code=='' && $row[$cols['IS_TOP']]+0==0 && $row[$cols['IS_NEW']]+0==0){ $aRubric[$rub_code]['OTHER'][]=$book; } if($subrub_code=='')continue; if($aRubric[$rub_code]['CHILD'][$subrub_code]['NAME']=='') $aRubric[$rub_code]['CHILD'][$subrub_code]['NAME'] = $row[$cols['SUB_PART']]; if($aRubric[$rub_code]['CHILD'][$subrub_code]['DESCRIPTION']=='' && $row[$cols['SUB_PART_DESCRIPTION']]!='') $aRubric[$rub_code]['CHILD'][$subrub_code]['DESCRIPTION'] = $row[$cols['SUB_PART_DESCRIPTION']]; $aRubric[$rub_code]['CHILD'][$subrub_code]['BOOKS'][] = $book; } $menu = array(); foreach ($aRubric as $r_code=>$r){ file_put_contents($curr_dir.'json/'.$r_code.'.json',json_encode($r,JSON_UNESCAPED_UNICODE,JSON_PRETTY_PRINT)); $menu[] = array($r_code,$r['NAME']); } file_put_contents($curr_dir.'json/_menu.json',json_encode($menu,JSON_UNESCAPED_UNICODE,JSON_PRETTY_PRINT));