Наследование: extends yii\db\ActiveRecord
Пример #1
0
 public function getIds($topic_names)
 {
     $topic_ids = [];
     if ($topic_names !== '') {
         foreach (explode(',', $topic_names) as $topic_name) {
             $topic = Topic::where('name', $topic_name)->get()->first();
             if (!$topic) {
                 $topic = new Topic(['name' => $topic_name]);
                 $topic->save();
             }
             $topic_ids[] = $topic->id;
         }
     }
     return $topic_ids;
 }
Пример #2
0
 public function actionTopics($username)
 {
     $user = $this->findUserModel($username, ['userInfo']);
     $pages = new Pagination(['totalCount' => $user['userInfo']['topic_count'], 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']);
     $topics = Topic::find()->select('id')->where(['user_id' => $user['id']])->orderBy(['id' => SORT_DESC])->offset($pages->offset)->with(['topic.node', 'topic.lastReply'])->limit($pages->limit)->asArray()->all();
     return $this->render('topics', ['user' => $user, 'topics' => $topics, 'pages' => $pages]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $categories = Categories::where('parent_id', '>=', 0)->get();
     $baseUrl = 'http://7xkn9n.com1.z0.glb.clouddn.com/img/';
     $string = file_get_contents(__DIR__ . "/../data/products.json");
     $products = json_decode($string, true);
     $cate_ids = [];
     foreach ($categories as $category) {
         $cate_ids[] = $category->id;
     }
     foreach ($products as $productData) {
         try {
             $name = $productData['meta']['title'];
             $content = '';
             if (isset($productData['content'])) {
                 $content = str_replace('<h2 class="title">百科词条</h2>', '', $productData['content']);
             }
             $klass = $productData['meta']['class']['text'];
             $category = Categories::where('name', $klass)->get();
             $description = substr($content, 0, 100);
             $cid = $faker->randomElement($cate_ids);
             if ($category->count() == 1) {
                 $cid = $category[0]->id;
             }
             $pieces = preg_split("/\\//i", $productData['meta']['image']);
             $product = Product::create(['name' => $name, 'slug' => $name, 'description' => $description, 'keywords' => $klass, 'cover' => $baseUrl . $pieces[count($pieces) - 1], 'category_id' => $cid, 'user_id' => 1]);
             $detailTopic = Topic::create(['title' => $name, 'slug' => $name, 'product_id' => $product->id, 'user_id' => 1, 'keywords' => $name, 'description' => $description, 'content' => $content, 'is_product_detail_topic' => true]);
             $product->detail_topic_id = $detailTopic->id;
             $product->save();
         } catch (Exception $e) {
             throw $e;
         }
     }
 }
Пример #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (Article::count() > 0 && Topic::count() > 0) {
         foreach (range(1, 10) as $index) {
             DB::table('article_topic')->insert(['article_id' => rand(1, Article::count()), 'topic_id' => rand(1, Topic::count())]);
         }
     }
 }
Пример #5
0
 public function afterDelete()
 {
     (new History(['user_id' => $this->user_id, 'action' => History::ACTION_DELETE_COMMENT, 'target' => $this->id]))->save(false);
     Siteinfo::updateCounterInfo('deleteComment');
     UserInfo::updateCounterInfo('deleteComment', $this->user_id);
     Topic::afterCommentDelete($this->topic_id);
     return parent::afterDelete();
 }
Пример #6
0
public function getEdit($id){
        $topic = Topic::find($id);
return view('topics.form',[
'topic' => $topic,
'update' => 'Обновить',
'teg' => $topic->with('teg')->get()
]);
}
Пример #7
0
 public function show($id)
 {
     $topic = Topic::findOrFail($id);
     $active_menu = '';
     $user = $topic->user;
     $product = $topic->product;
     return view('topic', compact(['topic', 'active_menu', 'product']));
 }
Пример #8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Topic::truncate();
     $topics = [['name' => 'Azure App Service'], ['name' => 'Laravel'], ['name' => 'Swift'], ['name' => 'Cat'], ['name' => 'Vehicle'], ['name' => 'Rock and Roll']];
     foreach ($topics as $topic) {
         factory(Topic::class)->create($topic);
     }
 }
Пример #9
0
 public function showProduct(Request $request, $id)
 {
     $product = Product::findOrFail($id);
     $active_menu = '';
     $topics = Topic::getProductTopics($id);
     $product_detail_topic = $product->detailTopic;
     return view('product', compact(['product', 'active_menu', 'topics', 'product_detail_topic']));
 }
Пример #10
0
 public function actionFollowing()
 {
     $query = Topic::find()->innerJoinWith('authorFollowedBy')->where([Favorite::tableName() . '.source_id' => Yii::$app->getUser()->id, Favorite::tableName() . '.type' => Favorite::TYPE_USER]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(1), 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']);
     $topics = $query->select([Topic::tableName() . '.id'])->orderBy([Topic::tableName() . '.id' => SORT_DESC])->offset($pages->offset)->with(['topic.author', 'topic.node', 'topic.lastReply'])->limit($pages->limit)->all();
     return $this->render('following', ['topics' => Util::convertModelToArray($topics), 'pages' => $pages]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $topics = c2a(Topic::lists('id'));
     $tags = c2a(Tag::lists('id'));
     foreach (range(0, 30) as $index) {
         topic_tag_relationship::create(['topic_id' => $faker->randomElement($topics), 'tag_id' => $faker->randomElement($tags)]);
     }
 }
Пример #12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $products = c2a(Product::lists('id'));
     $users = c2a(User::lists('id'));
     foreach (range(1, 20) as $index) {
         Topic::create(['title' => $faker->sentence(6), 'slug' => $faker->name, 'product_id' => $faker->randomElement($products), 'user_id' => $faker->randomElement($users), 'keywords' => $faker->sentence, 'description' => $faker->sentence(10), 'content' => $faker->sentence(100), 'page_view_count' => rand(10, 3059), 'vote_count' => rand(0, 199), 'reply_count' => rand(0, 100)]);
     }
 }
Пример #13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $topics = c2a(Topic::lists('id'));
     $users = c2a(User::lists('id'));
     foreach (range(1, 100) as $index) {
         Reply::create(['topic_id' => $faker->randomElement($topics), 'user_id' => $faker->randomElement($users), 'content' => $faker->sentence(100)]);
     }
 }
Пример #14
0
 /**
  * @return array
  */
 public function getTopicOptions()
 {
     $raw = Topic::find()->orderBy('Category_id')->all();
     $arr = array();
     foreach ($raw as $row) {
         $categpry = \app\models\Category::getCategoryById($row['Category_id']);
         $arr[$row['id']] = $categpry . ' - ' . $row['name'];
     }
     return $arr;
 }
Пример #15
0
 public function showIndex()
 {
     // the current page number
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $perPage = 4;
     $totalCount = Topic::count();
     $pagination = new Pagination($page, $perPage, $totalCount);
     $topics = Topic::allTopics($perPage, $pagination->offset()) or redirect(404);
     echo $this->blade->render('home', compact('topics', 'pagination'));
 }
Пример #16
0
public function getTeg($id){
try{
$teg = Teg::findOrFail($id);
return view('topics.index',[
'topics' => Topic::where('teg_id', $teg->id)->orderBy('id','desc')->paginate(),
'titlePage' => 'Статьи с меткой '.$teg->name,
]);
}catch(ModelNotFoundException $e){
return view('errors.404');
}
}
Пример #17
0
 protected function findTopicModel($id, $with = null)
 {
     $model = Topic::find()->where(['id' => $id]);
     if (!empty($with)) {
         $model = $model->with($with);
     }
     $model = $model->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('未找到id为[' . $id . ']的主题');
     }
 }
Пример #18
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Topic::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['topic_id' => $this->topic_id, 'blog_id' => $this->blog_id, 'user_id' => $this->user_id, 'topic_date_add' => $this->topic_date_add, 'topic_date_edit' => $this->topic_date_edit, 'topic_publish' => $this->topic_publish, 'topic_publish_draft' => $this->topic_publish_draft, 'topic_publish_index' => $this->topic_publish_index, 'topic_rating' => $this->topic_rating, 'topic_count_vote' => $this->topic_count_vote, 'topic_count_vote_up' => $this->topic_count_vote_up, 'topic_count_vote_down' => $this->topic_count_vote_down, 'topic_count_vote_abstain' => $this->topic_count_vote_abstain, 'topic_count_read' => $this->topic_count_read, 'topic_count_comment' => $this->topic_count_comment, 'topic_count_favourite' => $this->topic_count_favourite, 'topic_forbid_comment' => $this->topic_forbid_comment]);
     $query->andFilterWhere(['like', 'topic_type', $this->topic_type])->andFilterWhere(['like', 'topic_title', $this->topic_title])->andFilterWhere(['like', 'topic_tags', $this->topic_tags])->andFilterWhere(['like', 'topic_user_ip', $this->topic_user_ip])->andFilterWhere(['like', 'topic_cut_text', $this->topic_cut_text])->andFilterWhere(['like', 'topic_text_hash', $this->topic_text_hash]);
     return $dataProvider;
 }
Пример #19
0
 public function postCreateTopic()
 {
     $validator = new Validator();
     $errors = $validator->isValid(Topic::$createTopicRules);
     if (sizeof($errors) > 0) {
         flash('errors', $errors);
         echo $this->blade->render('create-topic');
         exit;
     }
     $data = ['title' => $_POST['title'], 'body' => strip_tags($_POST['body']), 'category_id' => $_POST['category'], 'user_id' => userLoggedIn()->id];
     if (Topic::create($data)) {
         flash('success', ['new topic created successfully']);
         redirect('/');
     }
 }
Пример #20
0
 public function actionTopic($id = null)
 {
     if ($id) {
         $model = Topic::findOne(['topic_id' => $id]);
         if ($model) {
             return $this->render('topic', ['model' => $model]);
         } else {
             return "No Id";
             //return $this->goBack();
         }
     } else {
         $str = $_GET;
         return var_dump($str);
         //return $this->goBack();
     }
 }
Пример #21
0
 public function actionIndex()
 {
     $query = Topic::find()->joinWith('topicContent')->joinWith('user')->orderBy('topic_date_add DESC');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $page = 1;
     if (isset($_GET["page"])) {
         $page = $_GET["page"];
     }
     $limit = 10;
     $offset = $limit * ($page - 1);
     $pageSize = ceil($countQuery->count() / $limit);
     $pages->setPageSize($pageSize);
     $models = $query->offset($offset)->limit($limit)->all();
     return $this->render('index', ['models' => $models, 'pages' => $pages]);
 }
Пример #22
0
 private static function addComment($from)
 {
     $notice = Notice::findOne(['type' => self::TYPE_COMMENT, 'topic_id' => $from['topic_id'], 'status' => 0]);
     if ($notice) {
         return $notice->updateCounters(['notice_count' => 1]);
     }
     if (!($topic = Topic::find()->select(['user_id'])->where(['id' => $from['topic_id']])->asArray()->one())) {
         return false;
     }
     if ($topic['user_id'] == $from['source_id']) {
         return true;
     }
     $notice = new Notice($from);
     //		$notice->attributes = $from;
     $notice->target_id = $topic['user_id'];
     return $notice->save(false);
 }
Пример #23
0
 public function search($params)
 {
     $query = Topic::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'title', true);
     $this->addCondition($query, 'content', true);
     $this->addCondition($query, 'source', true);
     $this->addCondition($query, 'node_id');
     $this->addCondition($query, 'user_id');
     $this->addCondition($query, 'created_at');
     $this->addCondition($query, 'updated_at');
     $this->addCondition($query, 'replies_count');
     $this->addCondition($query, 'last_reply_user_id');
     $this->addCondition($query, 'replied_at');
     return $dataProvider;
 }
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        $published = Carbon::now();
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 1)->update(['title' => 'Staffing, Training &amp; Talent Retention', 'text' => '<ul>
	<li>- How to recruit and retrain technical staff</li>
	<li>- IT Talent and Training
		<ul>
			<li>Supply and demand of IT talent - how to attract new talent</li>
			<li>The need for more online and virtual IT training</li>
			<li>When to hire and what to look for in a Security Officer</li>
		</ul>
	</li>
	<li>- Talent Retention - Culture and challenges of keeping top talent from leaving</li>
</ul>', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 2)->update(['title' => 'Cyber Security', 'text' => '<ul>
	<li>- BYOD vs Corporate provided devices</li>
	<li>- Multi factor authentication and protecting mobile devices</li>
	<li>- How has web based application changed this paradigm</li>
</ul>', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 3)->update(['title' => 'The Value of IT Solutions', 'text' => '<ul>
	<li>- Office 365</li>
	<li>- Flash Storage</li>
	<li>- Cloud vs on premise</li>
</ul>', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 4)->update(['title' => 'Information Security', 'text' => '<ul>
	<li>- Adaptive security architecture to identify and counter evolving threats</li>
	<li>- Email Security - protocol and enforcement of personal email through corporate mail system</li>
	<li>- System ownership - the psychology of getting end users and operators to take ownership of applications</li>
	<li>- End user security awareness training</li>
</ul>', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 5)->update(['title' => 'Internet of Things', 'text' => '- The effect on businesses of devices being added to the corporate network infrastructure', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 6)->update(['title' => 'New Technology Trends', 'text' => '- This session will focus on new technologies that we can expect to see on the horizon', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '=', 7)->update(['title' => 'Business Continuity Disaster Recovery', 'text' => '<ul>
	<li>- Mitigating risk using cloud vs traditional brick and mortar</li>
	<li>- Resiliency - RPO and RTO, what are stated, tested and recoverable Standards</li>
</ul>', 'published' => $published]);
        Topic::where('conference_slug', '=', '2016/austin')->where('priority', '>', 7)->update(['published' => null]);
        Option::where('slug', '=', '2016/austin')->where('option', '=', 'show_topics')->update(['value' => 1, 'published' => $published]);
    }
Пример #25
0
 public static function getTopicsFromIndex($pages)
 {
     $key = 'topics-index-p-' . $pages->getPage();
     $cache = Yii::$app->getCache();
     $settings = Yii::$app->params['settings'];
     if (intval($settings['cache_enabled']) === 0 || ($models = $cache->get($key)) === false) {
         $models = static::find()->select('id')->orderBy(['replied_at' => SORT_DESC])->offset($pages->offset)->with(['topic.node', 'topic.author', 'topic.lastReply'])->limit($pages->limit)->asArray()->all();
         if (intval($settings['cache_enabled']) !== 0) {
             $dep = new DbDependency(['sql' => 'SELECT MAX(updated_at) FROM ' . Topic::tableName()]);
             $cache->set($key, $models, intval($settings['cache_time']) * 60, $dep);
         }
     }
     return $models;
 }
Пример #26
0
$form = ActiveForm::begin();
?>

    <?php 
echo $form->errorSummary($model);
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'content')->textarea(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'Topic_id')->dropDownList(\app\models\Topic::getTopicOptions(), array('prompt' => '-- Select a Topic --'));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Пример #27
0
 public function getTopic()
 {
     return $this->hasOne(Topic::className(), ['id' => 'topic_id'])->select(['id', 'title']);
 }
Пример #28
0
 public function getTopic()
 {
     return $this->hasOne(Topic::className(), ['id' => 'topic_id'])->select(['id', 'node_id', 'user_id', 'reply_id', 'replied_at', 'comment_count', 'title']);
 }
 protected function conference($route, $event)
 {
     $venue = Venue::where('slug', '=', $event->venue_slug)->published()->get();
     $venue = !empty($venue[0]) ? (object) $venue[0]->toArray() : null;
     $options = Helpers::options($route, $event->slug, $event);
     //		dd($options);
     $navs = Helpers::navigation($route, $options);
     $sub = Helpers::navigation($route, $options, true);
     $partners = (object) ['companies' => null, 'text' => null];
     if (!empty($event->partners)) {
         $undo = Helpers::unserialize($event->partners);
         $companies = Partner::where(function ($query) use($undo) {
             foreach ($undo['partners'] as $i => $slug) {
                 if ($i === 0) {
                     $query->where('slug', '=', $slug);
                 } else {
                     $query->orWhere('slug', '=', $slug);
                 }
             }
         })->published()->orderBy('company')->get();
         if (!empty($undo['text'])) {
             $partners->text = $undo['text'];
         }
         if (is_object($companies)) {
             $partners->companies = [];
             foreach ($companies as $i => $company) {
                 $partners->companies[] = (object) $company->toArray();
             }
         }
     }
     $unfilteredTopics = Topic::where('conference_slug', '=', $event->slug)->published()->get();
     $topics = [];
     foreach ($unfilteredTopics as $topic) {
         $topics[] = [$topic->title => $topic->text];
     }
     if ((bool) $options->topics_by_alpha === true) {
         sort($topics);
     }
     //dd($topics);
     $agendasRaw = Agenda::where('conference_slug', '=', $event->slug)->published()->orderBy('timeslot')->orderBy('priority')->get();
     $speakerList = [];
     $agendas = [];
     if (is_object($agendasRaw)) {
         foreach ($agendasRaw as $i => $agenda) {
             $agenda = (object) $agenda->toArray();
             list($date, $time) = explode(' ', $agenda->timeslot);
             if (!empty($agenda->speakers)) {
                 //					$agenda->speakers = Helpers::unserialize($agenda->speakers);
                 //					dd($agenda->speakers);
                 $agendaSpeakers = explode(',', $agenda->speakers);
                 $agenda->speakers = [];
                 if (is_array($agendaSpeakers)) {
                     foreach ($agendaSpeakers as $s) {
                         @(list($speakerType, $speakerSlug) = @explode('|', $s));
                         $agenda->speakers[$speakerType][] = $speakerSlug;
                     }
                     //							dd($agenda->speakers);
                 }
             }
             $agendas[$date][$time][] = $agenda;
             if (!empty($agenda->speakers)) {
                 $speakersTypes = $agenda->speakers;
                 if (is_array($speakersTypes)) {
                     ksort($speakersTypes);
                     //						dd($speakersTypes);
                     foreach ($speakersTypes as $speakers) {
                         $speakerList = array_merge($speakerList, $speakers);
                     }
                 }
             }
         }
     }
     //		dd($agendas);
     if (count($speakerList) > 0) {
         $speakers = Speaker::where(function ($query) use($speakerList) {
             $query->where('slug', '=', array_pop($speakerList));
             while (count($speakerList) > 0) {
                 $query->orWhere('slug', '=', array_pop($speakerList));
             }
         })->published()->orderBy('last_name')->get();
         $speakers = Helpers::keysByField($speakers, 'slug', function ($value, $key, $field, $array, $toObj) {
             $value->sessions = [];
             return $value;
         }, true);
     }
     if ((bool) $options->sponsor_levels === true) {
         $sponsors = Lookup::lookup('sponsors', ['conference_slug' => $event->slug], ['published' => true, 'sponsorlevels' => true]);
     } else {
         $sponsors = Lookup::lookup('sponsors', ['conference_slug' => $event->slug], ['published' => true]);
     }
     //		dd($options);
     return view('pages/conference', compact('event', 'venue', 'partners', 'topics', 'agendas', 'speakers', 'sponsors', 'options', 'navs', 'sub'));
 }
Пример #30
0
<ul class="list-group sf-box">
	<li class="list-group-item">
	<?php 
echo Html::a('首页', ['topic/index']), '&nbsp;/&nbsp;', $this->title;
?>
	</li>
<?php 
foreach ($notices as $notice) {
    echo '<li class="list-group-item media">', Html::a(Html::img('@web/' . str_replace('{size}', 'small', $notice['source']['avatar']), ['class' => 'media-object', 'alt' => Html::encode($notice['source']['username'])]), ['user/view', 'username' => Html::encode($notice['source']['username'])], ['class' => 'media-left']), '<div class="media-body">
				<span class="fr gray small">', Yii::$app->formatter->asRelativeTime($notice['created_at']), '</span>', Html::a(Html::encode($notice['source']['username']), ['user/view', 'username' => Html::encode($notice['source']['username'])]), ' ';
    if ($notice['type'] == Notice::TYPE_COMMENT) {
        echo '回复了您的帖子【' . Html::a(Html::encode($notice['topic']['title']), Topic::getRedirectUrl($notice['topic_id'], $notice['position'])) . '】', $notice['notice_count'] > 0 ? '<span class="small gray">(省略类似通知' . $notice['notice_count'] . '次)</span>' : '';
    } else {
        if ($notice['type'] == Notice::TYPE_MENTION) {
            if ($notice['position'] > 0) {
                echo '在主题【' . Html::a(Html::encode($notice['topic']['title']), Topic::getRedirectUrl($notice['topic_id'], $notice['position'])) . '】的回帖中提到了您';
            } else {
                echo '在主题【' . Html::a(Html::encode($notice['topic']['title']), ['topic/view', 'id' => $notice['topic_id']]) . '】中提到了您';
            }
        } else {
            if ($notice['type'] == Notice::TYPE_FOLLOW_TOPIC) {
                echo '收藏了您发布的主题【', Html::a(Html::encode($notice['topic']['title']), ['topic/view', 'id' => $notice['topic_id']]), '】';
            } else {
                if ($notice['type'] == Notice::TYPE_FOLLOW_USER) {
                    echo '关注了您';
                }
            }
        }
    }
    echo '</div>';
    echo '</li>';