/** * 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 KayttajanSisalto the loaded model * @throws CHttpException */ public function loadModel($id) { $model = KayttajanSisalto::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php /* @var $this LiveController */ /* @var $model Live */ if (isset($_POST['grammMuutos'])) { if (isset($_POST['id'])) { KayttajanSisalto::model()->updatebypk($_POST['id'], array('gramm' => $_POST['uusiValue'])); echo 'OK'; exit; } } $this->breadcrumbs = array('Ruoka', 'Päiväkirjä'); $checkMobile = Yii::app()->createController('Site'); $pvm = date('d.m.Y'); if (isset($_GET['pvm'])) { $pvm = date('d.m.Y', strtotime($_GET['pvm'])); } $code = ''; if (isset($_GET['code']) or isset($_GET['ean'])) { if (isset($_GET['code'])) { $barcode = $_GET['code']; } elseif (isset($_GET['ean'])) { $barcode = $_GET['ean']; } echo '<input type="hidden" id="sainCode" value="' . $barcode . '">'; } echo '<input type="hidden" id="userAgent" value="' . $this->user_agent() . '">'; /* $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $phone = ''; if ($browser == true){
protected function ruokaYmpyra($pvm, $nimike) { $return = 0; $paino = 0; $criteria = new CDbCriteria(); $criteria->condition = "\n\t\t\tpvm='" . $pvm . "'\n\t\t\tAND user_id = '" . Yii::app()->user->id . "' \n\n\t\t"; $model = KayttajanSisalto::model()->findAll($criteria); if (isset($model[0])) { foreach ($model as $data) { $v = Viivakoodi::model()->findbypk($data->tuote); $annoskoko = 100; if (!empty($v->annoskoko)) { $annoskoko = (double) $v->annoskoko; } $return += (double) ($v->{$nimike} / $annoskoko * $data->gramm); $paino += $data->gramm; } } if ($return > 0) { return round($return / $paino * 100, 1); } else { return $return; } }