Beispiel #1
0
 /**
  * @Author: ANH DUNG Oct 28, 2014
  * @Todo: something
  * @Param: $mTransactions model trans
  * @Param: $nameModel is sub model of transaction, value maybe : mLandlord, mTenant...
  * @Param: $type Users::USER_LANDLORD, Users::USER_TENANT
  */
 public static function validateLandLord($mTransactions, $nameModel, $type)
 {
     if (!ProTransactions::ValidateRequiredDetail($mTransactions, $nameModel, $type)) {
         return;
     }
     $criteria = new CDbCriteria();
     //$criteria->compare('t.is_new_user', 1);
     $criteria->compare('t.type', $type);
     $criteria->compare('t.transactions_id', $mTransactions->id);
     $models = ProTransactionsVendorPurchaserDetail::model()->findAll($criteria);
     $aError = array();
     $aEmail = array();
     $aNric = array();
     if ($type == Users::USER_TENANT && empty($mTransactions->mTenatDefault->id)) {
         // thêm validate duplidate cho tenant default
         $aEmail[] = trim($mTransactions->mTenatDefault->email);
         $aNric[] = trim($mTransactions->mTenatDefault->nric_passportno_roc);
     }
     if (count($models)) {
         foreach ($models as $item) {
             // ANH DUNG May 12, 2015
             if (self::isUserSystem($item->user_id)) {
                 continue;
             }
             // ANH DUNG May 12, 2015
             if (trim($item->email) != '') {
                 $aEmail[] = trim($item->email);
             }
             $aNric[] = trim($item->nric_passportno_roc);
             Users::validateEmailLandlordTenant($item);
             // $item is model landlord
             if ($item->getError('email')) {
                 $aError['email'][] = $item->getError('email');
             }
             if ($item->getError('nric_passportno_roc')) {
                 $aError['nric_passportno_roc'][] = $item->getError('nric_passportno_roc');
             }
         }
         // check same value in submit
         // http://stackoverflow.com/questions/1170807/how-to-detect-duplicate-values-in-php-array
         $aEmailCount = array_count_values($aEmail);
         $aNricCount = array_count_values($aNric);
         foreach ($aEmailCount as $value => $count) {
             if ($count > 1) {
                 $aError['email'][] = "Email {$value} can not duplicate.";
             }
         }
         foreach ($aNricCount as $value => $count) {
             if ($count > 1) {
                 $aError['nric_passportno_roc'][] = "NRIC {$value} can not duplicate.";
             }
         }
         // check same value in submit
     }
     if (count($aError)) {
         $mTransactions->{$nameModel}->clearErrors();
         $mTransactions->{$nameModel}->addErrors($aError);
     }
 }