/**
  * ЦСКА
  */
 public function actionCskanews()
 {
     $cska = Yii::$app->params['cska'];
     $bot = new BotApi($cska['token']);
     $host = 'https://www.sports.ru';
     $dom = Html::load($cska['html']);
     $divs = $dom->getElementsByTagName('div');
     foreach ($divs as $div) {
         if ($div->getAttribute('class') == 'news') {
             $links = $div->getElementsByTagName('a');
             foreach ($links as $link) {
                 if ($link->getAttribute('class') == 'short-text') {
                     $url = Url::findOne(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                     if ($url === null) {
                         $message = $link->nodeValue . "\n" . $host . $link->getAttribute('href');
                         try {
                             $bot->sendMessage($cska['chat_id'], $message);
                         } catch (Exception $e) {
                             echo $e->getMessage() . "\n";
                         }
                         $url = new Url(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]);
                         $url->save();
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function save($profile, $urls)
 {
     $user = new User();
     $user->email = $this->email;
     $user->password = $this->password;
     $user->setPassword($user->password);
     $user->generateAuthKey();
     $user->save(false);
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_SHOP), $user->id);
     $profile->user_id = $user->id;
     $profile->host = $profile->getHost($profile->url);
     $profile->status_id = 1;
     $profile->save(false);
     $url = new Url();
     $url->user_id = $user->id;
     $url->link = $profile->url;
     $url->name = 'Главная страница';
     $url->save(false);
     if (is_array($urls)) {
         foreach ($urls as $item) {
             if (is_array($item)) {
                 $url = new Url();
                 $url->user_id = $user->id;
                 $url->link = $item['link'];
                 $url->name = $item['name'];
                 $url->save(false);
             }
         }
     }
     Yii::$app->mailer->compose('registration/shop', ['model' => $user])->setFrom(Yii::$app->params['emailFrom'])->setTo($this->email)->setSubject('Регистрация магазина')->send();
 }
Esempio n. 3
0
 private function createUrl($user_id, $link, $name)
 {
     $url = new Url();
     $url->user_id = $user_id;
     $url->link = $link;
     $url->name = $name;
     $url->save(false);
 }
 private function addUrlToDb($actual_url)
 {
     $url = new Url();
     $url->short_url = $this->generateRandomString(6);
     $url->url_hash = md5($actual_url);
     $url->actual_url = $actual_url;
     $url->save();
     return $url;
 }
Esempio n. 5
0
 /**
  * Creates a new Url model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Url();
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->identity->id;
         if ($model->save()) {
             //return $this->redirect(['view', 'id' => $model->id]);
             return $this->goBack();
         }
     } else {
     }
     return $this->render('create', ['model' => $model]);
 }
Esempio n. 6
0
 public function addUrl($link)
 {
     $shop_id = null;
     $text = '';
     $profile = new Profile();
     $host = $profile->getHost($link);
     /* @var $shop Profile */
     $shop = Profile::find()->where(['host' => $host])->one();
     if ($shop) {
         $shop_id = $shop->user_id;
         $text .= 'магазин ' . $shop->url . '<br>';
         $text .= 'бонус покупателю ' . $shop->buyer_bonus . '<br>';
         $text .= 'бонус рекомендателю ' . $shop->recommender_bonus . '<br>';
         $text .= 'статус ' . $shop->status->name . '<br>';
     } elseif (!ModerateShop::find()->where(['url' => $host])->exists()) {
         $moderateShop = new ModerateShop(['user_id' => Yii::$app->user->identity->id, 'url' => $host]);
         $moderateShop->save();
     }
     $text .= 'Вы можете давать эту ссылку своим друзьям<br>';
     $url = new Url(['user_id' => Yii::$app->user->identity->id, 'link' => $link, 'shop_id' => $shop_id]);
     $url->save();
     return $text . \yii\helpers\Url::to(['purchase/create', 'affiliate_id' => Yii::$app->user->identity->id, 'url_id' => $url->id], true);
 }