Example #1
0
 public function actionCsv($pars = 0)
 {
     if ($pars) {
         $model = Operation::find()->where("pars = :pars", [':pars' => (int) $pars])->orderBy("url asc")->all();
     } else {
         $model = Operation::find()->orderBy("url asc")->all();
     }
     include Yii::getAlias('@vendor/phpoffice/phpexcel/Classes/PHPExcel.php');
     include Yii::getAlias('@vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php');
     $objPHPExcel = new \PHPExcel();
     $objPHPExcel->getProperties()->setCreator("Php Shaman")->setLastModifiedBy("Php Shaman")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Data for yelp parsing")->setKeywords("office 2007 openxml php")->setCategory("Data for yelp parsing");
     // Add some data
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'name')->setCellValue('B1', 'categories')->setCellValue('C1', 'phone')->setCellValue('D1', 'state')->setCellValue('E1', 'city')->setCellValue('F1', 'address')->setCellValue('G1', 'postal')->setCellValue('H1', 'site')->setCellValue('I1', 'description');
     foreach ($model as $k => $o) {
         $cat = [];
         foreach ($o->categories as $c) {
             $cat[] = $c->name;
         }
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . ($k + 2), $o->name)->setCellValue('B' . ($k + 2), join(' | ', $cat))->setCellValue('C' . ($k + 2), $o->phone)->setCellValue('D' . ($k + 2), ParsSettings::getState($o->state))->setCellValue('E' . ($k + 2), $o->city)->setCellValue('F' . ($k + 2), $o->address)->setCellValue('G' . ($k + 2), $o->postal)->setCellValue('H' . ($k + 2), $o->site)->setCellValue('I' . ($k + 2), $o->description);
     }
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="pars.xls"');
     header('Cache-Control: max-age=0');
     header('Cache-Control: max-age=1');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Cache-Control: cache, must-revalidate');
     header('Pragma: public');
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save('php://output');
 }
Example #2
0
File: index.php Project: comaw/pars
use yii\helpers\Html;
use yii\grid\GridView;
use app\models\ParsSettings;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ParsSettingsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Parsing result');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="pars-settings-index">
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create new parsing'), ['/site/index'], ['class' => 'btn btn-success']);
?>
    </p>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'created', ['attribute' => 'status', 'format' => 'raw', 'value' => function ($data) {
    return $data->status;
}, 'filter' => ParsSettings::listStatus()], 'search', 'city', ['attribute' => 'state', 'format' => 'raw', 'value' => function ($data) {
    return ParsSettings::getState($data->state);
}, 'filter' => ParsSettings::listStates()], ['label' => Yii::t('app', 'View results'), 'format' => 'raw', 'value' => function ($data) {
    return Html::a(Yii::t('app', 'view'), ['/operation/index', 'pars' => $data->id]);
}, 'filter' => false], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}']]]);
?>

</div>
Example #3
0
File: view.php Project: comaw/pars
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Operations'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$r = '<ul class="list-unstyled">';
foreach ($model->categories as $cat) {
    $r .= '<li>' . $cat->name . '</li>';
}
$r .= '</ul>';
?>
<div class="operation-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'pars', 'format' => 'raw', 'value' => isset($model->pars0->search) ? $model->pars0->search : ''], 'name', ['attribute' => 'state', 'format' => 'raw', 'value' => ParsSettings::getState($model->state)], 'city', 'address', 'phone', 'site:url', ['label' => Yii::t('app', 'Categories'), 'format' => 'raw', 'value' => $r], 'created']]);
?>

</div>