mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-07 03:58:52 -06:00
70 lines
1.5 KiB
PHP
Executable File
70 lines
1.5 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
* @author HDVinnie
|
|
*/
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Topic extends Model
|
|
{
|
|
|
|
public $rules = [
|
|
'name' => 'required',
|
|
'slug' => 'required',
|
|
'state' => 'required',
|
|
'num_post' => '',
|
|
'first_post_user_id' => 'required',
|
|
'first_post_user_username' => 'required',
|
|
'last_post_user_id' => '',
|
|
'last_post_user_username' => '',
|
|
'views' => '',
|
|
'pinned' => '',
|
|
'forum_id' => 'required',
|
|
];
|
|
|
|
/**
|
|
* Belongs to Forum
|
|
*
|
|
*
|
|
*/
|
|
public function forum()
|
|
{
|
|
return $this->belongsTo(\App\Forum::class);
|
|
}
|
|
|
|
public function posts()
|
|
{
|
|
return $this->hasMany(\App\Post::class);
|
|
}
|
|
|
|
public function viewable()
|
|
{
|
|
if (auth()->user()->group->is_modo) {
|
|
return true;
|
|
}
|
|
|
|
return $this->forum->getPermission()->read_topic;
|
|
}
|
|
|
|
public function postNumberFromId($searchId)
|
|
{
|
|
$count = 0;
|
|
foreach ($this->posts as $post) {
|
|
$count += 1;
|
|
if ($searchId == $post->id) {
|
|
break;
|
|
}
|
|
}
|
|
return $count;
|
|
}
|
|
}
|