PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/lib/Views/AdminViews/Article/Listing.php

https://gitlab.com/gothcon/cthulhu
PHP | 247 lines | 222 code | 18 blank | 7 comment | 9 complexity | ea80749ae3c8842fc831937ad110da80 MD5 | raw file
  1. <?php
  2. require_once("lib/Views/HtmlListView.php");
  3. require_once("lib/Controllers/AdminControllers/OrderController.php");
  4. class ListingView extends HtmlListView{
  5. public function createRemoveFromCartLink($article_id){
  6. return $this->internalLink("article", num($article_id)."/".CONTROLLER_ACTION_REMOVE_FROM_CART . (isset($_GET['p']) ? "?p=".num($_GET['p']) : ""), false);
  7. }
  8. public function createAddToCartLink($article_id){
  9. return $this->internalLink("article", num($article_id)."/".CONTROLLER_ACTION_ADD_TO_CART . (isset($_GET['p']) ? "?p=".num($_GET['p']) : ""), false);
  10. }
  11. public function createArticleLink($article_id){
  12. return $this->internalLink("article", num($article_id)."/".CONTROLLER_ACTION_EDIT ,false);
  13. }
  14. public function createCategoryLink($article_id){
  15. return $this->internalLink("article", "?p=".num($article_id),false);
  16. }
  17. /** @var Article[] **/
  18. public $articles;
  19. /** @var Article[] **/
  20. public $categories;
  21. /** @var Article **/
  22. public $article;
  23. /** @var Article[] **/
  24. public $path;
  25. /** @var Person **/
  26. public $currentCustomer;
  27. /** @var Order **/
  28. public $cart;
  29. /** @var OrderRow[] **/
  30. public $cartItems;
  31. public $cartInfo;
  32. public $newOrderLink;
  33. public $orderControllerLink;
  34. public $articleControllerLink;
  35. public $newArticleLink;
  36. public $articleLinkTemplate;
  37. public $articleListLinkTemplate;
  38. public function init(){
  39. $this->articles = $this->model->getArticles();
  40. $this->categories = $this->model->getCategories();
  41. $this->article = $this->model->getArticle();
  42. $this->path = $this->model->getArticlePath();
  43. $this->currentCustomer = $this->model->getCurrentCustomer();
  44. $this->cart = $this->model->getCurrentCart();
  45. $this->cartItems = $this->cart->getOrderRows();
  46. $this->cartInfo = $this->translate("articles/cartArticleCount").": ".num($this->cart->getNumberOfArticles()).", ";
  47. $this->cartInfo .= $this->translate("articles/orderTotal").": ".number_format($this->cart->total,2).", ";
  48. $this->cartInfo .= $this->translate("articles/customer").": ".safe($this->currentCustomer);
  49. $this->newOrderLink = $this->internalLink(OrderController::getControllerName(), CONTROLLER_ACTION_CREATE_ORDER_FROM_CART, false );
  50. $this->orderControllerLink = $this->internalLink(OrderController::getControllerName(),"",false);
  51. $this->articleControllerLink = $this->internalLink("article","",false);
  52. $this->newArticleLink = $this->internalLink("article",CONTROLLER_ACTION_NEW."?p=".num($this->article->id),false);
  53. $this->articleLinkTemplate = $this->internalLink("article","%s/".$this->translate("actions/edit"),false);
  54. $this->articleListLinkTemplate = $this->internalLink("article","?p=%s",false);
  55. }
  56. public function render(){
  57. if($this->currentCustomer->id){
  58. ?>
  59. <div id="cart">
  60. <h3 class="shadedText"><?php echo $this->translate("articles/currentOrder");?></h3>
  61. <div id="tableContainer">
  62. <?php $r=0; ?>
  63. <table id="cartTable">
  64. <tr class="even">
  65. <th class="idCol"><?php echo $this->translate("articles/articleId");?></th>
  66. <th class="nameCol"><?php echo $this->translate("articles/articleName");?></th>
  67. <th class="typeCol"><?php echo $this->translate("articles/articleCount");?></th>
  68. <th><?php echo $this->translate("articles/pricePerEach");?></th>
  69. <th><?php echo $this->translate("articles/totalPrice");?></th>
  70. <th class="buttonsCol"></th>
  71. </tr>
  72. <?php foreach($this->cartItems as $row){ ?>
  73. <tr class="<?php echo $r++ % 2 ? "even" : "odd";?>">
  74. <td><?php pnum($row->article_id)?></td>
  75. <td><?php psafe($row->name)?></td>
  76. <td><?php psafe($row->count)?></td>
  77. <td><?php echo number_format($row->price_per_each,2);?></td>
  78. <td><?php echo number_format($row->total,2);?></td>
  79. <td><?php
  80. Html::DeleteButton($this->createRemoveFromCartLink($row->article_id),$this->translate("general/delete"),$this->translate("articles/removeFromCartWarning"));
  81. ?></td>
  82. </tr>
  83. <?php } ?>
  84. </table>
  85. </div>
  86. <span class="clear"></span>
  87. <div id="status" style="float:left">
  88. <?php psafe($this->cartInfo) ?>
  89. </div>
  90. <div id="buttons" style="float:right">
  91. <?php Html::LinkButton($this->translate("articles/submitOrder"), $this->newOrderLink,array("style" => "float:left; margin-right:14px;"));?>
  92. </div>
  93. <span class="clear"></span>
  94. </div>
  95. <script type="text/javascript">
  96. var texts = [];
  97. texts[true] = "<?php echo $this->translate("articles/showArticles");?>";
  98. texts[false] = "<?php echo $this->translate("articles/hideArticles");?>";
  99. var cartIsHidden = true;
  100. var $textSpan = $("<span>"+texts[cartIsHidden] +"<span>");
  101. $status = $("#status");
  102. $statusLabel = $("<span id='statusLabel'></span>").html($("#status").html());
  103. $status.html("").append($statusLabel);
  104. var $button = $("<a class='editButton buttonLink' href='<?php echo $this->orderControllerLink ;?>' style='float:right; margin-right:10px'></a>").append($textSpan).append($("<span class='end'/>"));
  105. var $cart = $("#cart #tableContainer");
  106. $button.click(function(event){
  107. console.log($cart);
  108. event.preventDefault();
  109. event.stopPropagation();
  110. if(cartIsHidden){
  111. $cart.slideDown();
  112. }
  113. else{
  114. $cart.slideUp();
  115. }
  116. cartIsHidden = !cartIsHidden;
  117. $textSpan.html(texts[cartIsHidden]);
  118. });
  119. $cart.hide();
  120. $("#buttons").append($button);
  121. </script>
  122. <?php } ?>
  123. <div id="articlePath">
  124. <?php
  125. $count = 0;
  126. foreach( $this->path as $key => $category){
  127. if($count == 0){?>
  128. <a href="<?php echo $this->articleControllerLink;?>">Start</a>
  129. <?php
  130. $first = false;
  131. }
  132. else if($count + 1 == count($this->path)){ ?>
  133. /<a href="<?php echo $this->createArticleLink($category->id);?>"><?php psafe($category->name)?></a>
  134. <?php }
  135. else{ ?>
  136. /<a href="<?php echo $this->createCategoryLink($category->id);?>"><?php psafe($category->name)?></a>
  137. <?php }
  138. $count++;
  139. }
  140. ?>
  141. </div>
  142. <span class="clear"></span>
  143. <div class="articleMainContent">
  144. <div class="subCategoriesContainer">
  145. <h3 class="shadedText"><?php echo $this->translate("articles/subCategories"); ?></h3>
  146. <table class="articleTable">
  147. <tr>
  148. <th class="thumbCol"></th>
  149. <th class="idCol"><?php echo $this->translate("articles/categoryId"); ?></th>
  150. <th><?php echo $this->translate("articles/categoryName"); ?></th>
  151. </tr>
  152. <?php foreach($this->categories as $category){
  153. $image = ( $category->getImage()->getName(32,32) ? Application::getFilesRootUrl().$category->getImage()->path.$category->getImage()->getName(32,32) : Application::getFilesRootUrl()."/missingImage_32x32.png");
  154. ?>
  155. <tr>
  156. <td><img src ="<?php psafe($image);?>"></td>
  157. <td><a href="<?php echo $this->createCategoryLink($category->id);?>"><?php pnum($category->id)?></a></td>
  158. <td><a href="<?php echo $this->createCategoryLink($category->id);?>"><?php psafe($category->name);?></a></td>
  159. </tr>
  160. <?php } ?>
  161. </table>
  162. <?php Html::LinkButton($this->translate("articles/newCategory"),$this->newArticleLink ,array("class" => "editButton"))?>
  163. </div>
  164. <div class="articlesContainer">
  165. <h3 class="shadedText"><?php echo $this->translate("articles/articles");?></h3>
  166. <table class="articleTable">
  167. <tr>
  168. <th class="thumbCol"></th>
  169. <th class="idCol"><?php echo $this->translate("articles/articleId");?></th>
  170. <th><?php echo $this->translate("articles/articleName");?></th>
  171. <th><?php echo $this->translate("articles/pricePerEach");?></th>
  172. <th class="buttonCol"></th>
  173. <?php if($this->currentCustomer->id){ ?>
  174. <th class="orderCol" style="text-align:center"><?php echo $this->translate("articles/addToOrder");?></th>
  175. <?php } ?>
  176. </tr>
  177. <?php foreach($this->articles as $article){
  178. $image = ( $article->getImage()->getName(32,32) ? Application::getFilesRootUrl().$article->getImage()->path.$article->getImage()->getName(32,32) : Application::getFilesRootUrl()."/missingImage_32x32.png");
  179. ?>
  180. <tr>
  181. <td><img src ="<?php psafe($image);?>"></td>
  182. <td><a href="<?php echo $this->createArticleLink($article->id)?>"><?php pnum($article->id)?></a></td>
  183. <td><a href="<?php echo $this->createArticleLink($article->id)?>"><?php psafe($article->name)?></a>
  184. <td><a href="<?php echo $this->createArticleLink($article->id)?>"><?php echo number_format($article->price,2);?></a>
  185. </td>
  186. <td>
  187. <?php Html::LinkButton($this->translate("articles/information"),$this->internalLink("article", "{$article->id}",false),array("class" => "editButton"))?>
  188. </td>
  189. <?php if($this->currentCustomer->id){ ?>
  190. <td>
  191. <form class="addToCartForm" action="<?php echo $this->createAddToCartLink($article->id);?>" method="post">
  192. <?php Html::Text($this->translate("articles/count"),"1");?>
  193. <?php Html::SubmitButton($this->translate("articles/addToOrder"))?>
  194. </form>
  195. </td>
  196. <?php } ?>
  197. </tr>
  198. <?php } ?>
  199. </table>
  200. <?php Html::LinkButton($this->translate("articles/newArticle"),$this->newArticleLink ,array("class" => "editButton"))?>
  201. </div>
  202. <script type="text/javascript">
  203. $(".addToCartForm").ajaxForm({preventBuiltInCallback:true,returnDataType:"html",saveCallback:function($form,data){
  204. var $response = $(data);
  205. $("#cartTable").html($response.find("#cartTable").html());
  206. $("#status").replaceWith($response.find("#status"));
  207. $response.find("#infoList li").each(function(key,obj){
  208. var message = $(obj).html();
  209. $.logger.log(message,"info");
  210. });
  211. $response.find("#errorList li").each(function(key,obj){
  212. var message = $(obj).html();
  213. $.logger.log(message,"error");
  214. });
  215. $response.find("#warningList li").each(function(key,obj){
  216. var message = $(obj).html();
  217. $.logger.log(message,"warning");
  218. });
  219. var $status = $($response.find("#status"));
  220. var $currentStatus = $("#statusLabel");
  221. var $statusButton = $($currentStatus.find(".buttonLink"));
  222. $currentStatus.html($status.html());
  223. $currentStatus.append($statusButton);
  224. }});
  225. </script>
  226. </div>
  227. <?php
  228. }
  229. }