public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->deleted_status_date = new CDbExpression('NOW()');
     }
     return parent::beforeSave();
 }
Example #2
0
 public function afterSave()
 {
     if ($this->isNewRecord) {
         static::logAddMessage($this->tableName(), $this->attributes);
     }
     return parent::afterSave();
 }
Example #3
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $text = $this->message;
         $text = strip_tags($text, '<p><ul><ol><li><h><b><a><br><span><div>');
         $text = preg_replace('/<([a-zA-Z]+)([^\\x00]*?)>/u', '<$1>', $text);
         $text = str_replace('<br>', '<br />', $text);
         $this->message = $text;
         return true;
     }
     return false;
 }
Example #4
0
 protected function afterSave()
 {
     if (false !== parent::afterSave()) {
         if ($this->isNewRecord) {
             // новое сообщение, надо об этом уведомить заинтересованных по longpool
             $Message = Message::model()->findByPk($this->message_id);
             Yii::log("MessageReaded afterSave Message=[" . print_r($Message, true) . "]", "info");
             $this->notifyInterestedPersonsViaLongPool('read', $Message->model, $Message->model_id, $Message->user_id, $Message->message_id);
         }
         return true;
     }
     return false;
 }
Example #5
0
 protected function afterValidate()
 {
     Yii::log("Review afterValidate start,scenario=[" . $this->getscenario() . "],new record=[" . ($this->isNewRecord ? 'true' : 'false') . "],[" . print_r($this->attributes, true) . "]", "info");
     parent::afterValidate();
     if (!$this->hasErrors()) {
         if ('valid_photo' == $this->getscenario()) {
             // первый afterValidate при негативном отзыве может не пройти т.к. валидация идёт в 2 этапа. Из-за загрузки картинок
             if ('new' == $this->status) {
                 $this->sendEmailNotifyByNewReview();
             }
         }
     }
     Yii::log("Review afterValidate end", "info");
 }
Example #6
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 public static function GetURLAndNameByModelAndID($model, $external_id)
 {
     $ret = null;
     $arrData = C2goActiveRecord::getDBRelation2Module($model);
     $urlForModel = '';
     $nameForModel = '';
     list($methodLink, $methodName) = $arrData['url'];
     if ('getModelLink' == $methodLink) {
         $urlForModel = $model::$methodLink($external_id);
         $nameForModel = $model::$methodName($external_id);
     } else {
         if ('getLink' == $methodLink) {
             $modelObj = $model::model()->findByPk($external_id);
             $urlForModel = $modelObj->{$methodLink}();
             $nameForModel = $modelObj->{$methodName}($external_id);
         }
     }
     if (strlen($urlForModel) && strlen($nameForModel)) {
         $ret = ['url' => $urlForModel, 'name' => $nameForModel];
     }
     return $ret;
 }
Example #8
0
<?php

$arrData = C2goActiveRecord::getDBRelation2Module($model, true);
if (!is_null($arrData)) {
    $moduleObj = Yii::app()->getModule($arrData['module']);
    // !!! don't erase , its autoload data
    $modelName = $arrData['class'];
    $modelObj = $modelName::model()->findByPk($external_id);
    if (!is_null($modelObj)) {
        $strCart = C2goActiveRecord::getCartViewString($arrData);
        if (isset($arrData['asmod'])) {
            $modelNameToView = $arrData['asmod'];
        } else {
            $modelNameToView = $modelName;
            // !!! see getDBRelation2Module second parameter
        }
        echo $this->renderPartial($strCart, [$modelNameToView => $modelObj]);
    } else {
        echo $this->renderPartial('//site/elementnotavail', ['external_id' => $external_id, 'model' => $modelName]);
    }
}
?>
<div class="row">
<?php 
$dataProvider = new CArrayDataProvider($Response);
$dataProvider->pagination = array('pageSize' => 25);
$this->widget('booster.widgets.TbListView', ['dataProvider' => $dataProvider, 'template' => '{pager}
        <table class="result-table">
        <thead>
            <tr>
                <th>' . Yii::t('default', 'Просмотрено') . '</th>
$this->pageTitle = Yii::t('default', 'Успешная регистрация, ссылка на заказ');
/*
 * 'model' => $paramModel, 'external_id' => $paramExternalId,'response_id'
 */
$user = Yii::app()->getUser()->getProfile();
?>
<script>
    ga('send', 'event', 'UI', 'отправка формы регистрации','registration');
</script>
<div class="alert in fade alert-success">
<?php 
echo Yii::t("default", "На ваш почтовый ящик <strong>email</strong> отправлено письмо для подтвержения регистрации.", ['email' => $user->email]);
?>
</div>
<div class="alert in fade alert-success">
<?php 
echo Yii::t("default", "Для перехода на ваш заказ, нажмите link_to_order", ['link_to_order' => CHtml::link(Yii::t("default", "сюда"), "/response/{$response_id}")]);
?>
</div>
<div class="alert in fade alert-success">
<?php 
$arrUrlName = C2goActiveRecord::GetURLAndNameByModelAndID($model, $external_id);
$strUrl = Yii::t('default', 'Не найден элемент');
if (is_array($arrUrlName)) {
    $strUrl = CHtml::link($arrUrlName['name'], $arrUrlName['url']);
}
echo Yii::t("default", "Ссылка на страницу заказываемого элемента : link_element", ['link_element' => $strUrl]);
?>
</div>
Example #10
0
 protected static function updateDBByData(&$arrData)
 {
     $arrLog = [];
     Yii::log("updateDBByData start", "info");
     foreach ($arrData as $k => $v) {
         // найти запись в {{company}}
         // блокировка её FOR UPDATE
         $Company = Company::model()->findByAttributes(['INN' => $v['inn']]);
         if (!is_null($Company)) {
             $transaction = Yii::app()->getDb()->beginTransaction();
             try {
                 C2goActiveRecord::logStart();
                 $sqlCompanyBlock = 'SELECT * FROM ' . $Company->tableName() . ' WHERE `id`=:id  FOR UPDATE';
                 $CompanyById = Company::model()->findBySql($sqlCompanyBlock, ['id' => $Company->id]);
                 //$sqlCheckStatementExist = 'SELECT * FROM {{statement}} WHERE `tnd`=:tnd AND `sum`=:sum AND `inn`=:inn AND `date`=:date';
                 $arrParams = ['tnd' => $v['tnd'], 'sum' => $v['sum'], 'date' => static::convertXMLDate($v['date']), 'inn' => $v['inn']];
                 $StatementCheck = Statement::model()->findByAttributes($arrParams);
                 if (is_null($StatementCheck)) {
                     // добавить
                     $Statement = new Statement();
                     $Statement->tnd = $v['tnd'];
                     $Statement->sum = $v['sum'];
                     $Statement->date = static::convertXMLDate($v['date']);
                     $Statement->inn = $v['inn'];
                     $Statement->name = $v['name'];
                     if (!$Statement->save()) {
                         throw new CException(Yii::t('StatementModule.default', 'Не могу сохранить запись в Statement,errors', ['errors' => print_r($Statement->getErrors(), true)]));
                     }
                     Yii::log("updateDBByData p3 ", "info");
                     //@todo: log.processed
                     static::addToStatementLog($Statement, StatementLog::PROCESSED, $CompanyById);
                     Yii::log("updateDBByData p4 ", "info");
                     // verify
                     if (!$CompanyById->verify || !$CompanyById->validate) {
                         $CompanyById->verify = 1;
                         $CompanyById->validate = 1;
                         if ($CompanyById->save()) {
                             //@todo: log.verified
                             static::addToStatementLog($Statement, StatementLog::VERIFIED, $CompanyById);
                         } else {
                             throw new CException(Yii::t('StatementModule.default', 'Не могу в Company сделать verify=1,validate=1 ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
                         }
                     }
                     // company.balance
                     $CompanyById->balance += $v['sum'];
                     if ($CompanyById->save()) {
                         $AccountMotion = new AccountMotion();
                         $AccountMotion->company_id = $CompanyById->id;
                         $AccountMotion->price = $v['sum'];
                         $AccountMotion->notice = "import statement Statement.id=[{$Statement->id}]";
                         if ($AccountMotion->save()) {
                             //@todo: log.enrolled
                             static::addToStatementLog($Statement, StatementLog::ENROLLED, $CompanyById);
                             //sleep(5);
                             $transaction->commit();
                             $arrLog[] = ['success'];
                             C2goActiveRecord::logEndAndWrite();
                         } else {
                             throw new CException(Yii::t('StatementModule.default', 'Не могу добавить в AccountMotion ,errors', ['errors' => print_r($AccountMotion->getErrors(), true)]));
                         }
                     } else {
                         throw new CException(Yii::t('StatementModule.default', 'Не могу в Company изменить balance ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
                     }
                 } else {
                     throw new CException(Yii::t('StatementModule.default', 'Statement запись уже есть'));
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 $strException = $e->__toString();
                 Yii::log("updateDBByData exception [{$strException}]", "error");
                 $arrLog[] = ['error', $e->getMessage()];
                 C2goActiveRecord::logEmptyMessages();
             } finally {
                 C2goActiveRecord::logEnd();
             }
         } else {
             $arrLog[] = ['error', Yii::t('StatementModule.default', 'Не найдена компания по INN, inn_value', ['inn_value' => $v['inn']])];
         }
         //@todo: delete
         //break;
     }
     Yii::log("updateDBByData end", "info");
     return $arrLog;
 }
Example #11
0
 public function beforeDelete()
 {
     // чтобы удалились файлики
     foreach ((array) $this->images as $image) {
         $image->delete();
     }
     return parent::beforeDelete();
 }