Completed
Push — development ( eb9524...db4517 )
by Andrij
28:49 queued 02:09
created

Docs::exportData()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 2
eloc 18
nc 2
nop 0
1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * Image CMS
9
 *
10
 * Backup Class
11
 *
12
 */
0 ignored issues
show
introduced by
Additional blank lines found at end of doc comment
Loading history...
13
class Docs extends BaseAdminController
14
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
15
16
    protected $jsonListFile;
17
18
    protected $docsPath;
19
20
    public function __construct() {
21
        parent::__construct();
22
        $this->docsPath = PUBPATH . 'manual/';
23
        $this->jsonListFile = $this->docsPath . 'list.json';
24
25
        $this->load->library('DX_Auth');
26
        admin_or_redirect();
27
28
        $this->load->library('lib_admin');
29
        $this->lib_admin->init_settings();
30
    }
31
32
    public function show($pageName) {
33
        $page = file_get_contents($this->docsPath . "$pageName.html");
34
        $this->template->add_array(['page' => $page, 'd_b' => true, 'active_docs_page' => $pageName]);
35
        $this->template->show('docs', TRUE);
36
    }
37
38
    public function getPages() {
39
        $pages = (array) json_decode(file_get_contents($this->jsonListFile));
40
        foreach ($pages as $key => $page) {
41
            $pages[$key]->full_url = site_url('admin/docs/show/' . $page->full_url);
42
        }
43
        return $pages;
44
    }
45
46
    private function exportData() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
47
        $dsn = 'mysqli://root:root@localhost/premmerce';
48
        $db = $this->load->database($dsn,true);
0 ignored issues
show
introduced by
Expected one space after the comma, 0 found
Loading history...
49
50
        $result = $db->select(['title', 'url', 'full_text'])
51
            ->where(['lang' => '3', 'category' => 92, 'post_status' => 'publish'])
52
            ->order_by('position')
53
            ->get('content')->result_array();
54
//        dd($result);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 8 spaces, but found 0).
Loading history...
55
56
        $jsonsDataArray = [];
57
        foreach ($result as $pageFromDatabase) {
58
            $jsonsDataArray[] = ['full_url' => $pageFromDatabase['url'], 'title' => $pageFromDatabase['title']];
59
60
            $pageTitle = '<div class="title-default-main"><div class="title">'
61
                    . $pageFromDatabase['title'] . '</div></div>';
62
63
            $pageFromDatabase['full_text'] = str_replace('/academy/start-s-nyla/filling-store', '/admin/docs/show', $pageFromDatabase['full_text']);
64
            $cont = $pageTitle . $pageFromDatabase['full_text'];
65
            $path = $this->docsPath . $pageFromDatabase['url'] . '.html';
66
67
            echo nl2br($path . "\n");
68
            $pageFromDatabase = file_put_contents($path, $cont);
69
        }
70
        file_put_contents($this->jsonListFile, json_encode($jsonsDataArray));
71
    }
72
73
}