Exemple #1
0
 public function actionForm($id = null, $template_id = null, $title = null)
 {
     if (Yii::app()->session["username"] != null) {
         $this->layout = "main";
     } else {
         $this->layout = "front";
     }
     $model = new Kpi();
     if (!empty($_POST["Kpi"])) {
         // 1.step new kpi
         $model = new Kpi();
         // 2.step edit kpi
         if (!empty($id)) {
             $model = Kpi::model()->findByPk($id);
         }
         // 3. step merge data
         $model->_attributes = $_POST["Kpi"];
         $model->template_id = $template_id;
         $model->username = Yii::app()->session["username"];
         $model->created = new CDbExpression('NOW()');
         // 4. step save/update
         if ($model->save()) {
             $this->redirect("index.php?r=kpi/index&template_id={$template_id}&title={$title}");
         }
     }
     if (!empty($id)) {
         $model = Kpi::model()->findByPk($id);
     }
     $this->render("//kpi/form", array("model" => $model, "template_id" => $template_id, "title" => $title));
 }
Exemple #2
0
 public function testSaveKpi()
 {
     $dao = new KpiDao();
     $kpi = new Kpi();
     $kpi->setJobTitleCode(1);
     $kpi->setId(1);
     $kpi->setKpiIndicators('new kpi');
     $kpi->setMinRating(1);
     $kpi->setMaxRating(2);
     $kpi->setDefaultKpi(1);
     $kpi = $dao->saveKpi($kpi);
     $this->assertEquals(1, $kpi->getId());
 }