コード例 #1
0
 private function updateRows(&$model)
 {
     $valid = true;
     if (isset($_POST['save']) && count($model->templateRows) < 2) {
         $model->addError('defaultAccountId', Yii::t('lazy8', 'You must have at least 2 rows in a template.'));
         $valid = false;
     }
     if ($model->templateRows !== null && count($model->templateRows) > 0) {
         //first time through just see if the data makes sense
         $repParams = $model->templateRows;
         $numBalances = 0;
         $multiLineRows = 0;
         foreach ($repParams as $n => $repParam) {
             //see if there is new data to be added..
             if (isset($_POST['save'])) {
                 $accounts = TemplateRowAccount::model()->findAll(array('condition' => 'templateRowId=' . $repParam->id));
                 if ($accounts == null || count($accounts) == 0) {
                     $model->addError('defaultAccountId', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'You must have at least one account for each row.'));
                     $valid = false;
                 }
             }
             if ($_POST['TemplateRow'][$n]) {
                 $repParam->attributes = $_POST['TemplateRow'][$n];
             }
             if ($repParam->isFinalBalance) {
                 $numBalances++;
             }
             if ($repParam->allowRepeatThisRow) {
                 $multiLineRows++;
             }
             if ($repParam->isFinalBalance) {
                 //all others should be zero
                 if (strlen($repParam->defaultValue) > 0) {
                     $model->addError('[0]defaultValue', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Balance rows cannot have a default value.'));
                     $valid = false;
                 }
                 if ($repParam->allowMinus) {
                     $model->addError('[0]allowMinus', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Balance rows cannot have a minus value'));
                     $valid = false;
                 }
                 if (strlen($repParam->phpFieldCalc) > 0) {
                     $model->addError('[0]phpFieldCalc', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Balance rows cannot also be a php calculated field'));
                     $valid = false;
                 }
                 if ($repParam->allowChangeValue) {
                     $model->addError('[0]allowChangeValue', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Balance rows cannot allow to change value manually'));
                     $valid = false;
                 }
                 if ($repParam->allowRepeatThisRow) {
                     $model->addError('[0]allowRepeatThisRow', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Balance rows cannot be a repeatable row'));
                     $valid = false;
                 }
             }
             if (strlen($repParam->phpFieldCalc) > 0) {
                 //most others should be zero
                 if (strlen($repParam->defaultValue) > 0) {
                     $model->addError('[0]defaultValue', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Php calculated rows cannot have a default value.'));
                     $valid = false;
                 }
                 if ($repParam->allowMinus) {
                     $model->addError('[0]allowMinus', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Php calculated rows cannot have a minus value'));
                     $valid = false;
                 }
                 if ($repParam->allowChangeValue) {
                     $model->addError('[0]allowChangeValue', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Php calculated rows cannot allow to change value manually'));
                     $valid = false;
                 }
                 if ($repParam->allowRepeatThisRow) {
                     $model->addError('[0]allowRepeatThisRow', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Php calculated rows cannot be a repeatable row'));
                     $valid = false;
                 }
             }
             if ($repParam->allowMinus && !$repParam->allowChangeValue) {
                 $model->addError('[0]allowChangeValue', '#' . ($n + 1) . '--' . Yii::t('lazy8', 'Allow minus values and not allowing changing values does not make sense.'));
                 $valid = false;
             }
         }
         if ($numBalances > 1) {
             $model->addError('[0]isFinalBalance', Yii::t('lazy8', 'Only one row is allowed to be a balance row.'));
             $valid = false;
         }
         if ($multiLineRows > 1) {
             $model->addError('[0]allowRepeatThisRow', Yii::t('lazy8', 'Only one row is allowed to be a repeatable row.'));
             $valid = false;
         }
         if ($valid) {
             //now save it all
             foreach ($repParams as $n => $repParam) {
                 if (!$repParam->save()) {
                     return false;
                 }
             }
         } else {
             return $valid;
         }
     }
     if (isset($_POST['AddRow'])) {
         $rowparam = new TemplateRow();
         $rowparam->templateId = $model->id;
         $rowparam->allowChangeValue = 1;
         $rowparam->save();
     }
     if (isset($_POST['editrow'])) {
         $edits = $_POST['editrow'];
         //there is only one item in this array, but I don't know
         //any other way to get at it without doing this..
         foreach ($edits as $key => $transrow) {
             $this->redirect(array('editaccounts', 'id' => $model->templateRows[$key]->id, 'companyId' => $model->companyId));
             break;
         }
     }
     if (isset($_POST['deleterow'])) {
         $deletes = $_POST['deleterow'];
         //there is only one item in this array, but I don't know
         //any other way to get at it without doing this..
         foreach ($deletes as $key => $transrow) {
             $model->templateRows[$key]->delete();
             break;
         }
     }
     return $valid;
 }
コード例 #2
0
 public function delete()
 {
     parent::delete();
     $rowList = TemplateRow::model()->findAll('templateId=:templateId', array(':templateId' => $this->id));
     if ($rowList != null) {
         foreach ($rowList as $model) {
             $model->delete();
         }
     }
 }