Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class workStats {
- private $id = null;
- private $date = null;
- private $fields = array();
- protected $db = null;
- protected $data = array();
- private $work_hours = ["day_start", "fixed_day_start",
- "day_end", "fixed_day_end",
- "work_hours", "last_job_time"];
- private $free_hours = ["free_hours", "free_minutes"];
- private $free_days = ["free_day"];
- private $violations = ["violation"];
- public function __construct($id, $date, array $fields, Database $db) {
- $this->id = $id;
- $this->date = $date;
- $this->fields = $fields;
- $this->db = $db;
- $this->init();
- }
- private function join_fields($glue) {
- $array = [];
- foreach ($this->fields as $field) {
- foreach ($this->{$field} as $value) {
- $array[] = $value;
- }
- }
- return join($glue, $array);
- }
- private function get_query() {
- $query = "SELECT date, ";
- //Laukeliai kurie bus imami
- $query .= $this->join_fields(", ");
- $query .= " FROM `employee_work_stats` WHERE `user` = '{$this->id}'"
- . " AND `date` LIKE '%{$this->date}%' ORDER BY `date` ASC";
- return $query;
- }
- private function set_data($result) {
- $arrayToReturn = array();
- foreach ($result as $array) {
- foreach ($array as $key => $value) {
- if ($key !== "date") {
- $arrayToReturn[$array['date']][$key] = $value;
- }
- }
- }
- return $arrayToReturn;
- }
- private function init() {
- $query = $this->get_query();
- $result = $this->db->select($query);
- $this->data = $this->set_data($result);
- var_dump($this->data);
- }
- public function get_data($domain) {
- $array = array();
- foreach ($domain as $field) {
- foreach ($this->{$field} as $value) {
- $this->data['date'][$field][$value] = $this->data[$domain][$value];
- }
- }
- return $array;
- }
- }
- require '../../controller/class/database.php';
- $work = new workStats(28, "2017-02", ["free_days", "work_hours"], new Database());
- $data = $work->get_data(["free_days"]);
- foreach ($data as $key => $value) {
- echo "$key => ";
- print_r($value);
- echo "<br>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement