Example #1
0
 public static function loadUserById($id)
 {
     $editForm = new self();
     $user = $editForm->getUser($id);
     $editForm->setAttributes($user->getAttributes());
     $editForm->oldAttributes = $editForm->getAttributes();
     return $editForm;
 }
Example #2
0
 /**
  * Ham lay ra gia tri cua option setting
  * @param string $module ten module
  * @param string $key config key
  * @return string tra ve gia tri cua config key
  */
 public static function getValue($module, $key)
 {
     $model = self::findOne(['module' => $module, 'key' => $key]);
     if (!$model) {
         $model = new self();
         $model->module = $module;
         $model->type = 'text';
         $model->key = $key;
         $model->value = '';
         $model->save();
     }
     $attributes = array_keys($model->getAttributes());
     $value = in_array('value', $attributes) ? $model->value : '';
     if ($model->type == 'text') {
         return $value;
     } elseif (in_array($model->type, ['checkbox', 'radio', 'dropdown']) and property_exists($model, 'items')) {
         return \app\helpers\ArrayHelper::getValue($model->items, $model->value, '');
     } else {
         return '';
     }
 }
Example #3
0
 /** @ignore */
 public static function __test()
 {
     $c = new ReflectionClass(get_class());
     $doc = new self($c->getDocComment());
     assert($doc->getAttribute('package') == 'ab');
     assert($doc->getAttribute('subpackage') == 'reflection');
     assert($doc->getAttribute('author') == 'Rasmus Andersson  http://hunch.se/');
     assert($doc->getDescription());
     assert($doc->getBriefDescription());
     assert(is_array($doc->getAttributeNames()));
     assert(is_array($doc->getAttributes()));
     assert(is_array($doc->getAttributes('package')));
 }
Example #4
0
 /**
  * sends emails for defined emails, admin, developer
  * @param array $emails
  * @throws Exception
  */
 public static function sendSummary($emails = [])
 {
     $log = new self();
     $module = $log->module;
     if ($module->sendToDev) {
         $emails['dev'] = $module->devEmail ? $module->devEmail : Yii::$app->params['devEmail'];
         if (empty($emails['dev'])) {
             throw new Exception('Define devEmail in Syslog module or in Yii::$app->params[\'devEmail\']');
         }
     }
     if ($module->sendToAdmin) {
         $emails['admin'] = $module->adminEmail ? $module->adminEmail : Yii::$app->params['adminEmail'];
         if (empty($emails['admin'])) {
             throw new Exception('Define adminEmail in Syslog module or in Yii::$app->params[\'adminEmail\']');
         }
     }
     $logs = self::find()->where(['and', ['<', 'created_at', strtotime('today midnight')], ['=', 'sended', self::MAIL_NOT_SENDED]])->indexBy('id')->all();
     self::updateAll(['sended' => self::MAIL_SENDED], ['and', ['in', 'id', array_keys($logs)]]);
     //get calls
     $callsIds = ApiCall::find()->where(['and', ['<', 'created_at', strtotime('today midnight')], ['=', 'sended', Syslog::MAIL_NOT_SENDED]])->indexBy('id')->all();
     $calls = ApiCall::find()->select(['id', 'COUNT(call_name) as count', 'call_name', 'call_to'])->where(['and', ['in', 'id', array_keys($callsIds)]])->groupBy('call_name')->indexBy('id')->all();
     $callsStatistic = [];
     foreach ($calls as $key => $call) {
         $callsStatistic[$key]['call_quantity'] = $call->count;
         $callsStatistic[$key]['call_name'] = $call->call_name;
         $callsStatistic[$key]['call_to'] = $call->call_to;
     }
     //update calls
     ApiCall::updateAll(['sended' => self::MAIL_SENDED], ['and', ['in', 'id', array_keys($callsIds)]]);
     $summary = [];
     foreach ($logs as $key => $log) {
         $attributes = $log->getAttributes();
         //decode JSON fieds for layout
         $attributes['issues'] = Json::decode($attributes['issues']);
         $attributes['message'] = Json::decode($attributes['message']);
         $attributes['log_source'] = self::getTypeNameById($attributes['log_source']);
         $summary[] = $attributes;
     }
     foreach ($emails as $email) {
         $log->mailer->sendSummaryMessage($email, $summary);
     }
 }