Skip to content

Commit

Permalink
Merge pull request #15 from aidsoul/release/v.1.4
Browse files Browse the repository at this point in the history
Closing Release/v.1.4
  • Loading branch information
aidsoul authored Oct 11, 2022
2 parents 4750d54 + 9f9ff91 commit 0c1ece8
Show file tree
Hide file tree
Showing 45 changed files with 499 additions and 284 deletions.
3 changes: 2 additions & 1 deletion app/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use Vktote\Config\Config;
use Vktote\Telegram\Telegram;
use Vktote\Wall\Wall;
use Vktote\Vk\Wall\Wall;

/**
* Start parsing and sending data
* Entry point in programm
*
* @author aidsoul <[email protected]>
* @license MIT
Expand Down
34 changes: 19 additions & 15 deletions app/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
abstract class Config
abstract class Config implements ConfigInterface
{
/**
*
Expand All @@ -24,7 +24,7 @@ abstract class Config
*/
public static function set(string $сonfigPath): void
{
self::$config = parse_ini_file($сonfigPath, true);
self::$config = parse_ini_file($сonfigPath, true);
}

/**
Expand All @@ -49,34 +49,38 @@ public function __get(string $property)
$className = (new \ReflectionClass($this))->getShortName();
if (!empty($property)) {
if (
array_key_exists($className, self::$config) and
property_exists($this, $property) and
array_key_exists(
$property,
self::$config[$className]
)
array_key_exists($className, self::$config) and
property_exists($this, $property) and
array_key_exists(
$property,
self::$config[$className]
)
) {
$item = self::$config[$className][$property];
if (!empty($item)) {
$this->$property = $item;
if (
!method_exists($this, $property) or
method_exists($this, $property) and
$this->$property() === true
!method_exists($this, $property) or
method_exists($this, $property) and
$this->$property() === true
) {
$this->$property = $item;
return $this->$property;
}
} else {
}
else {
Message::find()->show(false, __TRAIT__, 'propertyNullItem', "[{$className}->[{$property}=>'...']");
}
} else {
}
else {
Message::find()->show(false, __TRAIT__, 'property', "[{$className}]->{$property}=>'?'");
}
} else {
}
else {
Message::find()->show(false, __TRAIT__, 'propertyNull', "[{$className}->[{$property}=>'...']");
}
} catch (\Exception $e) {
}
catch (\Exception $e) {
throw new \Exception($e);
}
}
Expand Down
7 changes: 7 additions & 0 deletions app/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

/**
* Config interface
*
* @license MIT
* @author aidsoul <[email protected]>
*/
interface ConfigInterface
{
/**
* @param string $property
* @return void
*/
public function __get(string $property);
}
4 changes: 1 addition & 3 deletions app/Config/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Vktote\Config;

use Vktote\Config\ConfigInterface;

/**
* Db class
*
* @author aidsoul <[email protected]>
* @license MIT
*/
class Db extends Config implements ConfigInterface
class Db extends Config
{
/**
* @var string
Expand Down
4 changes: 1 addition & 3 deletions app/Config/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Vktote\Config;

use Vktote\Config\ConfigInterface;

/**
* Telegram class
*
* @author aidsoul <[email protected]>
* @license MIT
*/
class Telegram extends Config implements ConfigInterface
class Telegram extends Config
{
/**
* @var string
Expand Down
11 changes: 8 additions & 3 deletions app/Config/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Vktote\Config;

use Vktote\Config\ConfigInterface;

class User extends Config implements ConfigInterface
/**
* Class of User
*
* @author aidsoul [email protected]
* @license MIT
*/
class User extends Config
{
/**
* Summary of password
* @var string
*/
protected string $password;
Expand Down
13 changes: 6 additions & 7 deletions app/Config/Vk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Vktote\Config;

use Vktote\Config\ConfigInterface;
use Vktote\Message\Message;

/**
Expand All @@ -11,7 +10,7 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
class Vk extends Config implements ConfigInterface
class Vk extends Config
{
/**
* @var string
Expand All @@ -35,10 +34,10 @@ class Vk extends Config implements ConfigInterface
*/
protected function count(): bool
{
if (isset($this->count) and $this->count > 100) {
Message::find()->show(false, __CLASS__, 'count');
} else {
return true;
}
if (isset($this->count) and $this->count > 100) {
Message::find()->show(false, __CLASS__, 'count');
} else {
return true;
}
}
}
2 changes: 1 addition & 1 deletion app/DataBase/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
/**
* @return \Aidsoul\Pdo\Db
*/
public function pdo(): Db
private function pdo(): Db
{
return self::$pdo;
}
Expand Down
31 changes: 26 additions & 5 deletions app/DataBase/Models/Post.php → app/DataBase/Models/PostModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
class Post extends Database implements PostInterface
class PostModel extends Database implements PostInterface
{
/**
* @param string $tableName
* @param string $idPost
* @param string $groupId
*/
public function __construct(
private readonly string $tableName = 'post',
private readonly string $idPost = 'id_post',
private readonly string $groupId = 'group_id'
private string $tableName = 'post',
private string $idPost = 'id_post',
private string $groupId = 'group_id'
) {
parent::__construct();
}
Expand All @@ -47,7 +47,8 @@ public function create(int $postId, int $groupId): void
*
* @param integer $postId
* @param integer $groupId
* @return integer
*
* @return int|bool
*/
public function check(int $postId, int $groupId): int|bool
{
Expand All @@ -62,4 +63,24 @@ public function check(int $postId, int $groupId): int|bool

return $ask ? $ask[$this->idPost] : false;
}

/**
* Get last post
*
* @param integer $groupId
*
* @return int
*/
public function getLastPost(string $groupName): int
{
$ask = self::$pdo
->select(['MAX(' . $this->idPost . ') as max'])
->from($this->tableName)
->leftJoin('vkgroup')->on('group_id', 'id_group')
->where('name', '=', $groupName)
->execute()
->fetch();

return empty($ask['max']) ? 0 : $ask['max'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
* @author aidsoul <[email protected]>
* @license MIT
*/
class Vkgroup extends Database implements VkgroupInterface
class VkgroupModel extends Database implements VkgroupInterface
{
/**
* @param string $tableName
* @param string $idGroup
* @param string $name
*/
public function __construct(
private readonly string $tableName = 'vkgroup',
private readonly string $idGroup = 'id_group',
private readonly string $name = 'name'
private string $tableName = 'vkgroup',
private string $idGroup = 'id_group',
private string $name = 'name'

) {
parent::__construct();
}

/**
* @param string $nameGroup
*
* @return void
*/
public function create(string $nameGroup): void
Expand All @@ -41,6 +42,7 @@ public function create(string $nameGroup): void

/**
* @param string $nameGroup
*
* @return integer|boolean
*/
public function check(string $nameGroup): int|bool
Expand All @@ -58,6 +60,7 @@ public function check(string $nameGroup): int|bool

/**
* @param integer|string $idGroup
*
* @return void
*/
public function remove(int|string $idGroup): void
Expand Down
2 changes: 2 additions & 0 deletions app/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function __construct()
* @param bool $type
* @param string $className
* @param string $messageName
*
* @return void
*/
public function show(
bool $type,
Expand Down
2 changes: 1 addition & 1 deletion app/File/File.php → app/Settings/File/File.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Vktote\File;
namespace Vktote\Settings\File;

/**
* File class
Expand Down
13 changes: 7 additions & 6 deletions app/Settings/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Vktote\Config\Config;
use Vktote\Config\Vk;
use Vktote\DataBase\Models\Vkgroup;
use Vktote\File\File;
use Vktote\DataBase\Models\VkgroupModel;
use Vktote\Settings\File\File;

/**
* Group class
Expand All @@ -20,7 +20,8 @@ class Group
* @param integer $status
* @param string $pathIni
* @param string $pathPhp
* @return void
*
* @return array
*/
private function send(int $status, string $pathIni): array
{
Expand All @@ -39,7 +40,7 @@ private function send(int $status, string $pathIni): array
public function create(): string
{
$send = [];
$file = new File;
$file = new File();
$file->set($_POST['fileName']);

if (!is_dir($file->folder)) {
Expand Down Expand Up @@ -77,7 +78,7 @@ private function checkFileExist(string $file, int $status): void
*/
public function delete(string $dirName): string
{
$file = new File;
$file = new File();
$file->set($dirName);
$ret = [];
if (is_dir($file->folder)) {
Expand All @@ -86,7 +87,7 @@ public function delete(string $dirName): string
try {
// delete group from database
Config::set($file->iniFullPath);
$vk = new Vkgroup;
$vk = new VkgroupModel();
if ($idGroup = $vk->check(Vk::get()->idGroup)) {
$vk->remove($idGroup);
} else {
Expand Down
2 changes: 2 additions & 0 deletions app/Settings/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Help
* getShortName function
*
* @param object $obj
*
* @return void
*/
public static function getShortName(object $obj): string
Expand All @@ -24,6 +25,7 @@ public static function getShortName(object $obj): string
* addHeader function
*
* @param string $header
*
* @return void
*/
public static function addHeader(string $header): string
Expand Down
1 change: 1 addition & 0 deletions app/Settings/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function checkIfExist(): string
*
* @param string $filePath
* @param string $password
*
* @return void
*/
private function create(string $filePath, string $password = ''): void
Expand Down
Loading

0 comments on commit 0c1ece8

Please sign in to comment.