/**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Personbenefits::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function getBenefits()
 {
     $res = "";
     //debug($this->idPerson);
     $benefits = Personbenefits::model()->findAll("PersonID = " . $this->idPerson);
     foreach ($benefits as $obj) {
         if (empty($res)) {
             $res = $obj->benefit->BenefitName;
         } else {
             $res .= "; " . $obj->benefit->BenefitName;
         }
     }
     if (empty($res)) {
         $res = "----";
     }
     return $res;
 }
Beispiel #3
0
    </div>



    <?php 
if (Yii::app()->user->checkAccess("showBenefits")) {
    ?>
        <hr>
        <div class="row-fluid">
            <div class="span6">
                <div class="row-fluid">
                    <?php 
    echo $form->labelEx($model, 'benefits');
    ?>
                    <?php 
    echo $form->dropDownList($model, 'benefits', CHtml::listData(Personbenefits::model()->findAll("PersonID = {$model->PersonID}"), "idPersonBenefits", "benefit.BenefitName"), array('empty' => "", 'style' => "width: 100%;", "multiple" => "multiple"));
    ?>
                </div>

            </div>
        </div>
    <?php 
}
?>





    <!--
    <div class="row buttons">
 public function afterSave()
 {
     // автоматическое добавление льготы
     if ($this->CoursedpID > 0) {
         $ben = Personbenefits::model()->find("PersonID = {$this->PersonID} and BenefitID = 41");
         if (empty($ben)) {
             $ben = new Personbenefits("CONVERT");
             $ben->PersonID = $this->PersonID;
             $ben->BenefitID = 41;
             $ben->save();
         }
         if (!in_array($ben->idPersonBenefits, $this->benefits)) {
             $this->benefits[] = $ben->idPersonBenefits;
         }
     } else {
     }
     // Сохраняем массив льгот привязанных к специальности
     Personspecialitybenefits::model()->deleteAll("PersonSpecialityID = {$this->idPersonSpeciality}");
     if (!empty($this->benefits) && is_array($this->benefits)) {
         foreach ($this->benefits as $val) {
             $item = Personspecialitybenefits::model()->findByPk(array("PersonBenefitID" => $val, 'PersonSpecialityID' => $this->idPersonSpeciality));
             if (count($item) == 0) {
                 $item = new Personspecialitybenefits();
             }
             $item->PersonBenefitID = $val;
             $item->PersonSpecialityID = $this->idPersonSpeciality;
             $item->save();
         }
     }
     return parent::afterSave();
 }