Last active
January 27, 2017 00:46
-
-
Save kergalym/5359217a81615e16895487ad11255a9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MS\Core; | |
use PDO; | |
use PharData; | |
class Querator { | |
public $connect; | |
public function __construct() { | |
$this->connect = new \MS\Core\ConfigModel(); | |
} | |
public function checkIsNone($param) { | |
if (!isset($param) || !empty($param)) { | |
return $param; | |
} | |
} | |
public function pdoFetchType($param) { | |
if (isset($param)) { | |
switch ($param) { | |
case 'FETCH_NUM': | |
$param = 'FETCH_NUM'; | |
break; | |
case 'FETCH_ASSOC': | |
$param = 'FETCH_ASSOC'; | |
break; | |
} | |
return $param; | |
} else { | |
return FALSE; | |
} | |
} | |
/* QUERY */ | |
public function query($operand, $table) { | |
$checkedOperand = $this->checkIsNone($operand); | |
$checkedTable = $this->checkIsNone($table); | |
$pdoFetchType = $this->pdoFetchType('FETCH_ASSOC'); | |
if ($checkedOperand && $checkedTable != NULL) { | |
$conn = $this->connect->getConn(); | |
$query = $conn->prepare( | |
"SELECT operand FROM table" | |
); | |
$query->execute(array( | |
'operand' => $checkedOperand, | |
'table' => $checkedTable | |
)); | |
return $object = $query->fetch(PDO::$pdoFetchType); | |
} else { | |
return FALSE; | |
} | |
} | |
public function queryArg($operand, $table, $arg = NULL) { | |
$object = NULL; | |
$checkedOperand = $this->checkIsNone($operand); | |
$checkedTable = $this->checkIsNone($table); | |
$checkedArg = $this->checkIsNone($arg); | |
$pdoFetchType = $this->pdoFetchType('FETCH_ASSOC'); | |
if ($checkedOperand && $checkedTable && $checkedArg != NULL) { | |
$conn = $this->connect->getConn(); | |
$query = $conn->prepare( | |
"SELECT operand FROM table arg" | |
); | |
$query->execute(array( | |
'operand' => $checkedOperand, | |
'table' => $checkedTable, | |
'arg' => $checkedArg | |
)); | |
return $object = $query->fetch(PDO::$pdoFetchType); | |
} else { | |
return FALSE; | |
} | |
} | |
} | |
/* в другом месте в функции */ | |
namespace MS\Models; | |
use MS\Core\Querator; | |
/** | |
* Adminboard Model | |
* | |
* @author Kerimbekov Galym | |
*/ | |
class BoardModel extends \MS\Core\Model { | |
public $querator; | |
public function __construct() { | |
parent::__construct(); | |
$this->querator = new Querator(); | |
} | |
} | |
class BoardList extends BoardModel { | |
public function __construct() { | |
parent::__construct(); | |
} | |
/* ADM_OPERATION FUNCTIONS */ | |
/* ArticlesListShowInitial */ | |
/* | |
* Shows the list of indexes | |
* | |
* @param int $cPage Count of all files per page | |
* @param int $limIndex Limit of indexes per page | |
* | |
* @return array | |
*/ | |
public function ArticlesListShowInitial(&$cPage, $limIndex) { | |
$sendQuery = $this->querator->query('COUNT(id)', 'articles'); | |
foreach ($sendQuery as $IndexCount): | |
$cPageNum = ceil($IndexCount / $limIndex); | |
endforeach; | |
for ($i = 0; $i < $cPageNum; $i++) { | |
$cPageArrN[] = $i; | |
$cPage = $cPageArrN; | |
} | |
if ($sendQueryArg = $this->querator->queryArg( | |
'id, ' | |
. 'article_title,' | |
. 'article_author,' | |
. 'article_category,' | |
. 'article_date,' | |
. 'pos_category,' | |
. 'prior_num' | |
. 'articles', | |
'LIMIT' | |
. $limIndex)) { | |
while ($sendQueryArg) { | |
$arrayData[] = $sendQueryArg; | |
} | |
return $arrayData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment