<div class="table-responsive">
   <table class="table table-hover tabTuotteet small">
    <tr>
	<th>Tuote</th>
	<th>Energia<br>kcal/100g</th>
	<th></th>

    </tr>';
    foreach ($data as $model) {
        $energia_kcal = 0;
        if ($model->energia_kcal > 0) {
            $energia_kcal = round(str_replace(".", ",", round($model->energia_kcal / $model->annoskoko * 100, 2)));
        }
        $criteria = new CDbCriteria();
        $criteria->condition = " tuote_id='" . $model->id . "' AND user_id='" . Yii::app()->user->id . "' ";
        $s = RuokaSuosikit::model()->find($criteria);
        if (isset($s->id)) {
            $s = '<b class="onSuosiki fa fa-star" title="Poista suosikeista" style="font-size:150%;color:#FF9900; margin-top: 5px;" suID="su_' . $s->id . '" forID="su_' . $model->id . '"></b>';
        } else {
            $s = '<b class="tahti fa fa-star-o" title="Lisää suosikkeihin" style="font-size:150%; margin-top: 5px;" forID="su_' . $model->id . '"></b>';
        }
        $valmistaja = '';
        if (!empty($model->valmistaja)) {
            $valmistaja = $model->valmistaja . ', ';
        }
        $bod .= '
	<tr>
		<td style=" white-space: normal"><a href="#" class="link viivat" title="Katso ja valitse" id="' . $model->id . '" data-toggle="modal"  data-target="#la">' . $valmistaja . $model->tuote_nimi . '</a></td>
		<td>' . $energia_kcal . ' kcal</td>
		<td id="su_' . $model->id . '">' . $s . '</td>
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return RuokaSuosikit the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = RuokaSuosikit::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #3
0
    public function actionTb()
    {
        switch ($_GET['model']) {
            case 'viivakoodi':
                $user = User::model()->findbypk($_POST['user']);
                if (isset($_POST['keyword']) and isset($user->id)) {
                    $criteria = new CDbCriteria();
                    $criteria->condition = " \n\n\t\t\t(\n\t\t\ttuote_nimi LIKE '%" . $_POST['keyword'] . "%'\n\t\t\tOR valmistaja LIKE '%" . $_POST['keyword'] . "%'\n\t\t\tOR viivakoodi LIKE '%" . $_POST['keyword'] . "%'\n\t\t\t)\n\n\t\t\tAND ((luoja='" . $user->id . "' AND status=0) OR (status=1))\n\n\t\t";
                    $data = Viivakoodi::model()->findAll($criteria);
                    $vastaus = '';
                    if (isset($data[0])) {
                        $vastaus .= '
   <div class="panel panel-primary">
     <div class="panel-heading">Tuotteet</div>
     <div class="panel-body table-responsive">

   <table class="table table-hover tabTuotteet">
    <tr>
	<th>Tuote</th>
	<th>Valmistaja</th>
	<th>Energia kcal/100g</th>
	<th>Suosiki</th>
	<th></th>
    </tr>';
                        foreach ($data as $model) {
                            if ($model->energia_kcal != '') {
                                $energia_kcal = round(str_replace(".", ",", round($model->energia_kcal / $model->annoskoko * 100, 2)));
                            }
                            $criteria = new CDbCriteria();
                            $criteria->condition = " tuote_id='" . $model->id . "' AND user_id='" . Yii::app()->user->id . "' ";
                            $s = RuokaSuosikit::model()->find($criteria);
                            if (isset($s->id)) {
                                $s = '<b class="onSuosiki fa fa-star" title="Poista suosikeista" style="font-size:150%;color:#FF9900; margin-top: 5px;" suID="su_' . $s->id . '" forID="su_' . $model->id . '"></b>';
                            } else {
                                $s = '<b class="tahti fa fa-star-o" title="Lisää suosikkeihin" style="font-size:150%; margin-top: 5px;" forID="su_' . $model->id . '"></b>';
                            }
                            $vastaus .= '
	<tr>
		<td>' . $model->tuote_nimi . '</td>
		<td>' . $model->valmistaja . '</td>
		<td>' . $energia_kcal . ' kcal</td>
		<td id="su_' . $model->id . '">' . $s . '</td>
		<td width=1><button class="pull-right btn btn-xs btn-info link viivat"title="Katso ja valitse"id="' . $model->id . '" data-toggle="modal"  data-target="#la"><i class="fa fa-list-alt"></i></button></td>
	</tr>';
                        }
                        $vastaus .= '
   </table>
     </div>
   </div>

<div id="la" class="modal fade" role="dialog"></div>
';
                        $this->_sendResponse(200, json_encode($vastaus));
                        exit;
                    }
                    $this->_sendResponse(200, json_encode("Jotain on väärin"));
                } else {
                    $this->_sendResponse(200, json_encode("Jotain on väärin"));
                }
                break;
        }
    }
Beispiel #4
0
 public function actionRemove_suosiki()
 {
     if (isset($_POST['sivu']) and $_POST['sivu'] == 'ruoka') {
         RuokaSuosikit::model()->deletebypk($_POST['id']);
     } elseif (isset($_POST['sivu']) and $_POST['sivu'] == 'liikunta') {
         LiikuntaSuosikit::model()->deletebypk($_POST['id']);
     }
     echo 'poistettu';
 }