Welcome Guest, Not a member yet? Register   Sign In
Is such a connection between the model and the controller acceptable?
#1
Question 
(This post was last modified: 11-05-2022, 01:39 PM by evilgazz.)

Подпись: включите свою подпись. (только для зарегистрированных пользователей)
По желанию вы можете прикрепить опрос к этой теме.
Is such a connection between the model and the controller acceptable

Screenshot

VkontakteBotModel.php
PHP Code:
<?php
class VkontakteBot extends ResourceController
{

 public function 
__construct()
 {
 
$this->model model('App\Models\VkontakteBotModel');
 }

 public function 
index() {}

 public function 
createTask()
 {
 
$account_name $this->request->getVar('account');
 
$account_id $this->model->accountIdByName($account_name);

 
$count $this->request->getVar('count');
 
$action_type $this->request->getVar('action');
 
$status $this->request->getVar('status');

 
$this->model->newTask($account_id$count$action_type$status);

 return 
$this->respondCreated($this->request->getJSON());
 }

 public function 
addAccount()
 {
 
$request $this->request->getJSON();

 return 
$this->respondCreated($this->request->getJSON());

 }

 public function 
getAllAccounts()
 {
 
$accounts $this->model->allAccounts();

 return 
$this->respond($accounts);
 }

 public function 
getAllTasks()
 {
 
$tasks $this->model->allTasks();

 return 
$this->respond($tasks);
 }

 public function 
runTask()
 {
 while (
ob_get_level() > 0) {
 
ob_end_clean();
 }

 
$activeTask $this->getActiveTask();
 
$this->setTaskStatus($activeTask->task_id'pending');

 
$GoLogin = new GoLoginProfile;

 
$proxyData = (new ProxyTask)->setProxy([
 
'task_proxy_ip' => ''
 
]);

 
$profile_id $GoLogin->createProfile($proxyData);

 echo 
'profile id = ' $profile_id PHP_EOL;
 
$profile $GoLogin->gl->getProfile($profile_id);
 echo 
'new profile name = ' $profile->name PHP_EOL;

 
$orbita $GoLogin->setOrbitaBrowser($profile_id);
 
$debugger_address $orbita->start();

 
$driver $GoLogin->runOrbitaBrowser($debugger_address);
 
$createAccount = new RegisterAccount($driver);

 
$loginPage = new LoginPage($driver);

 
$loginPage->openLoginPage('https://vk.com')
 
  ->login('username''password')
 
  ->likePosts();

 
$driver->close();
 
$orbita->stop();

 }

 public function 
getActiveTask()
 {

 return 
$this->model->ActiveTask();
 }

 public function 
setTaskStatus($taskID$status)
 {
 
$this->model->changeTaskStatus($taskID$status);
 }




VkontakteBot.php
PHP Code:
<?php
class VkontakteBotModel extends Model
{
 public function 
newTask($account_id$count$action_type$status)
 {
 
$vk_bot_tasks $this->db->table('vk_bot_tasks');

 
$vk_bot_tasks->insert([
 
'account_id'  => $account_id,
 
'task_type'  => $action_type,
 
'task_count'  => $count,
 
'task_status' => $status
 
]);

 }

 public function 
allAccounts()
 {
 
$vk_bot_accounts $this->db->table('vk_bot_accounts');

 return 
$vk_bot_accounts->select('id, account_name, created_at')->get()->getResult();
 }

 public function 
allTasks()
 {
 
$vk_bot_accounts $this->db
 
->table('vk_bot_tasks')
 ->
select('vk_bot_tasks.*, vk_bot_accounts.account_name')
 ->
join('vk_bot_accounts''vk_bot_accounts.id = vk_bot_tasks.account_id');

 return 
$vk_bot_accounts->get()->getResult();
 }

 public function 
ActiveTask()
 {
 return 
$this->db
 
->table('vk_bot_tasks')
 ->
where('task_status''active')
 ->
get()
 ->
getFirstRow();
 }

 public function 
changeTaskStatus($taskID$status)
 {
 return 
$this->db
 
->table('vk_bot_tasks')
 ->
where('task_id'$taskID)
 ->
set('task_status'$status)
 ->
update();
 }

 public function 
accountNameById($account_id) {}

 public function 
accountIdByName($account_name)
 {
 return 
$this->db
 
->table('vk_bot_accounts')
 ->
select('id')
 ->
getWhere(['account_name' => $account_name])
 ->
getRow()
 ->
id;
 }


Reply
#2

Yes, It is acceptable.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB