Added templates
[bibliodb.git] / modeltest.php
blobacf6de30677d58b5bbc8fa66a0f7de6238746592
1 <?php
2 ob_start();
3 require_once("view/CiteView.php");
4 require_once("profiller.php");
5 Profiller::speed("Začínáme");
6 require_once("CiteConfig.php");
7 require_once("CiteOutput.php");
8 //
9 require_once("CiteFields.php");
10 require_once("CiteData.php");
11 require_once("database.php");
12 require_once("model/Models.php");
13 require_once("model/DataCache.php");
14 require_once("model/CiteModel.php");
15 require_once("view/Template.php");
16 require_once("view/HtmlTemplate.php");
17 require_once("view/LatexTemplate.php");
18 Profiller::speed("Načtení vkládaných souborů");
19 //CiteConfig::setValue("output_filter","latex");
20 class Publication{
21 private $data=array();
22 public function add($key,$data){
23 if(array_key_exists($key,$this->data)){
24 if(is_array($this->data[$key])){
25 //CiteOutput::factory("Je pole")->lineBreak()->out();
26 $this->data[$key][]=$data;
27 }else{
28 //CiteOutput::factory("Neni pole")->lineBreak()->out();
29 $old=$this->data[$key];
30 $this->data[$key]=array($old,$data);
32 }else{
33 $data=is_array($data)?array($data):$data;
34 $this->data[$key]=$data;
37 public function fetch(){
38 return $this->data;
41 class pokus extends CiteModel{
42 private $authors=null;
43 private $publikace=array();
44 public function bibliography(){
45 CSL::style("iso-690")
46 //->citation()
47 //->end()
48 ->macro("author")
49 ->field("names")->variable("author")->suffix(".")->limit(3)->limitUse(3)
50 ->name()->delimiter("; ")->delimiterAnd("; ")
51 ->namePart("family")->textCase("uppercase")->end()
52 ->end()
53 ->end()
54 ->end()
55 ->macro("editor")
56 ->field("names")->variable("editor")->suffix(".")->limit(3)->limitUse(3)
57 ->name()->delimiter("; ")->delimiterAnd("; ")
58 ->namePart("family")->textCase("uppercase")->end()
59 ->end()
60 ->end()
61 ->end()
62 ->macro("primary")
63 ->field("choose")
64 ->cslIf()->variable("editor")
65 ->field("text")->macro("editor")->end()
66 ->cslElse()
67 ->field("text")->macro("author")->end()
68 ->end()
69 ->end()
70 ->end()
71 ->macro()
72 ->end()
73 ->macro("")
74 ->end()
75 ->bibliography()
76 ->sort()->end()
77 ->layout()
78 ->field("text")->macro("primary")->end()
79 ->field("text")->macro("document_name")->end()
80 ->end()
81 ->end();
82 //->suffix(".")
83 /*->field("names")->variable("author")->suffix(".")->limit(3)->limitUse(3)
84 ->name()->delimiter("; ")->delimiterAnd("; ")
85 ->namePart("family")->textCase("uppercase")->end()
86 ->end()
87 ->end()
88 ->field("base")->variable("title")
89 ->fontStyle("italic")->fontWeight("bold")->textCase("title")
90 ->end()
91 ->field("base")->macro("publisher")->end()
92 ->field("base")->variable("date")->end()
93 ->field("group")
94 ->field("base")->term("pokus")->prefix(":")->suffix(";")->end()
95 ->field("base")->variable("titlle")->end()
96 ->field("number")->variable("ohoo")->end()
97 ->end()
98 ->field("choose")
99 ->cslIf()->variable("pokusíík title")->match("any")->field(text)->value("První podmínka")->end()
100 ->cslElseIf()->variable("title")
101 ->field("text")->value("druhá podmínka")->end()
102 //->end()
103 ->cslElse()->field("text")->value("nic z toho")->end()
104 ->end()
105 ->end()
106 ->end()
107 ->end(); */
108 /*->field("names")
109 ->variable("author")
110 ->limit(3)
111 ->limitUse(3)
112 ->name()
113 ->delimiter("; ")
114 ->delimiterAnd("; ")
115 ->namePart("family")
116 ->textCase("uppercase")
117 ->end()
118 ->end()
119 ->end()
120 ->field("base")
121 ->variable("title")
122 ->fontStyle("italic")
123 ->fontWeight("bold")
124 ->textCase("title")
125 ->end()
126 ->field("base")
127 ->variable("publisher")
128 ->end()
129 ->field("base")
130 ->variable("date")
131 ->end();*/
133 CSL::printBibliography();
135 public function __construct(){
136 $this->db=DatabaseConnector::database("krokobib")
137 //->user("root")
138 //->password("root")
139 ->connect();
140 Profiller::speed("Připojení k databázi");
141 try{
142 $name=ModelFactory::get("Name");
143 $publication=ModelFactory::get("Publication");
144 $authors=ModelFactory::get("Author");
145 $role=ModelFactory::get("AuthorRole");
146 $publication_type=ModelFactory::get("PublicationType");
147 //$res=$this->query("autori")->rawQuery("SELECT name.* FROM publication inner join author on publication_id=publication inner join name on author_name=name_id ")->result();
148 Profiller::speed("Nahrání modelů");
149 $res=$this->query("autori")
150 ->select("name.name_id, family,given, part, von_part, date, description, publication, author_id, author_name,role")
151 ->link($authors,$publication)
152 ->link($authors,$role)
153 ->link($authors,$name)
154 ->where("author_name is not null order by family")
155 ->buildQuery()
156 //Profiller::speed("Build query");
157 ->prepare()->execute()->result();
158 //->buildQuery()->rawQuery()->result();
159 Profiller::speed("Query autoři");
160 $this->authors=new DataCache($authors);
161 $this->names=new DataCache($name);
162 while($row=$res->fetch(PDO::FETCH_ASSOC)){
163 $this->authors->load($row,"publication");
164 $this->names->load($row);
166 //$this->authors->load($res);
167 Profiller::speed("Nahrání autorů");
168 //$this->show($this->authors->fetch(1));
169 //$this->show($this->authors->fetch(2));
170 //$this->show($this->authors->fetch(1));
171 //Profiller::speed("Dotazy na autory");
172 //$this->show($this->authors->fetch(5));
173 $publikace=$this->query("publikace")
174 ->select("publication_id, type")
175 ->link($publication,$publication_type)
176 ->buildQuery()->prepare()->execute()->result();
177 Profiller::speed("Query publikace");
178 while($row=$publikace->fetch(PDO::FETCH_ASSOC)){
179 $id=$row["publication_id"];
180 $type=$row["type"];
181 CiteOutput::factory("Publikace: $id typ: $type")->lineBreak()->out();
182 $authors=$this->authors->get($id);
183 $publ=new Publication();
184 if(is_array($authors)){
185 foreach($authors as $author){
186 $role=$author["role"];
187 $publ->add($role,$author);
188 $publ->add("type",$type);
189 //CiteOutput::factory("autor")->lineBreak()->out();
190 //CiteOutput::factory(implode(" / ",$author))->lineBreak()->out();
191 //$this->show($author);
193 }else{
194 //CiteOutput::factory("Autoři nejsou pole")->lineBreak()->out();
196 $publ->add("publisher","Nakladatel");
197 $publ->add("date","2009");
198 $publ->add("title","titulek");
199 $publ->add("author",array("family"=>"Obecný","given"=>"Autor"));
200 //print_r($publ->fetch());
201 $this->publikace[]=$publ->fetch();
204 Profiller::speed("Nahrání publikací");
205 }catch(Exception $e){
206 CiteOutput::factory($e->getMessage())->lineBreak()->out();
208 CiteData::loadData($this->publikace);
209 Profiller::speed("Nahrání do CiteData");
210 //ModelFactory::get("name")->retrieve(2);
213 $pokus=new Pokus();
214 $pokus->bibliography();
215 Profiller::speed("Konec");
216 Profiller::show();
217 $content=ob_get_contents();
218 $content.=CiteView::get();
219 ob_end_clean();
220 //echo $content;
221 $tpl=new HtmlTemplate();
222 $tpl->assert("page_contents",$content);
223 $tpl->assert("page_title",CiteOutput::factory(CiteConfig::getValue("page_title"))->get());
224 echo $tpl->get("index.php");