Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use Composer\CaBundle\CaBundle;
  6. use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Category;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9.  
  10. use AppBundle\Entity\Products;
  11. use AppBundle\Entity\Productcategory;
  12. use AppBundle\Entity\Nipples;
  13.  
  14.  
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  18. use Symfony\Component\Form\Extension\Core\Type\MoneyType;
  19. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  20. use Symfony\Component\Form\Extension\Core\Type\DateType;
  21. use Symfony\Component\Form\Extension\Core\Type\RangeType;
  22. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  23.  
  24.  
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  26. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  27.  
  28.  
  29. class AdminController extends Controller
  30. {
  31.  
  32. private $product;
  33.  
  34. /**
  35. * @Route("/", name="AdminHome")
  36. */
  37. public function indexAction()
  38. {
  39. return $this->render('admin/pages/indexPage.html.twig', [
  40.  
  41. ]);
  42.  
  43. }
  44.  
  45.  
  46. /**
  47. * @Route("/rotators", name="RotatorsAdminList")
  48. */
  49. public function rotatorsAction()
  50. {
  51. return $this->render('admin/pages/rotatorList.html.twig', [
  52.  
  53. ]);
  54.  
  55. }
  56.  
  57.  
  58. /**
  59. * @Route("/rotators/add", name="RotatorAddNew")
  60. */
  61. public function rotatorAddAction()
  62. {
  63. $em = $this->getDoctrine()->getManager();
  64. $this->product = new Products();
  65. $this->product->setCategory($em->getRepository(Productcategory::class)->find(1));
  66. return $this->redirect($this->generateUrl('updateProduct'));
  67. }
  68.  
  69. /**
  70. * @Route("/rotator/update", name="updateProduct")
  71. *
  72. */
  73. public function rotatorUpdateAction(Request $request)
  74. {
  75. var_dump($this->product);
  76. die();
  77.  
  78. $em = $this->getDoctrine()->getManager();
  79. $form = $this->createFormBuilder()
  80. ->setMethod('POST')
  81. ->add('title')
  82. ->add('doublebearing')
  83. ->add('castiron')
  84. ->add('extrachannels')
  85. ->add('oposite')
  86. ->add('statloadpositive', ChoiceType::class,
  87. ['choices' => $this->staticLoadOptions(),
  88. 'placeholder' => 'izvēlies'
  89. ])
  90. ->add('torque', ChoiceType::class,
  91. ['choices' => $this->torqueOptions(),
  92. 'placeholder' => 'izvēlies'
  93. ])
  94. ->add('oilflow', ChoiceType::class,
  95. ['choices' => $this->oilflowOptions(),
  96. 'placeholder' => 'izvēlies'
  97. ])
  98. ->add('weight')
  99. ->add('toptype', ChoiceType::class,
  100. ['choices' => $this->topTypeOptions(),
  101. 'placeholder' => 'izvēlies'
  102. ])
  103. ->add('topsize')
  104. ->add('bottype')
  105. ->add('bottsize')
  106. ->add('rotationpressure', ChoiceType::class,
  107. ['choices' => $this->maxPressureOptions(),
  108. 'placeholder' => 'izvēlies'
  109. ])
  110. ->add('rotateinputchanel', ChoiceType::class,
  111. ['choices' => $this->nippleTypes(),
  112. 'placeholder' => 'izvēlies'
  113. ])
  114. ->add('openpressure', ChoiceType::class,
  115. ['choices' => $this->maxPressureOptions(),
  116. 'placeholder' => 'izvēlies'
  117. ])
  118. ->add('closepressure', ChoiceType::class,
  119. ['choices' => $this->maxPressureOptions(),
  120. 'placeholder' => 'izvēlies'
  121. ])
  122. ->add('toolinputchanel', ChoiceType::class,
  123. ['choices' => $this->nippleTypes(),
  124. 'placeholder' => 'izvēlies'
  125. ])
  126. ->add('tooloutputchanel_one', ChoiceType::class,
  127. ['choices' => $this->nippleTypes(),
  128. 'placeholder' => 'izvēlies'
  129. ])
  130. ->add('tooloutputchanel_two', ChoiceType::class,
  131. ['choices' => $this->nippleTypes(),
  132. 'placeholder' => 'izvēlies'
  133. ])
  134. ->add('extrapressure', ChoiceType::class,
  135. ['choices' => $this->maxPressureOptions(),
  136. 'placeholder' => 'izvēlies'
  137. ])
  138. ->add('extrainputchanel', ChoiceType::class,
  139. ['choices' => $this->nippleTypes(),
  140. 'placeholder' => 'izvēlies'
  141. ])
  142. ->add('extraoutputchanel', ChoiceType::class,
  143. ['choices' => $this->nippleTypes(),
  144. 'placeholder' => 'izvēlies'
  145. ])
  146. ->add('en_description')
  147. ->add('de_description')
  148. ->add('ru_description')
  149. ->add('lv_description')
  150. ->add('en_feature')
  151. ->add('de_feature')
  152. ->add('ru_feature')
  153. ->add('lv_feature')
  154. ->add('forestry')
  155. ->add('agriculture')
  156. ->add('construction')
  157. ->add('generalcargo')
  158. ->add('recycling')
  159. ->add('lenght')
  160. ->add('width')
  161. ->add('height')
  162. ->add('mainimage', EntityType::class, [
  163. 'required' => false,
  164. 'class' => 'AppBundle:Image',
  165. 'choice_label' => 'name',
  166. 'label_format' => 'Renderis',
  167. ])
  168. ->add('view_one', EntityType::class, [
  169. 'required' => false,
  170. 'class' => 'AppBundle:Image',
  171. 'choice_label' => 'name',
  172. 'label_format' => 'Renderis',
  173. ])
  174. ->add('view_two', EntityType::class, [
  175. 'required' => false,
  176. 'class' => 'AppBundle:Image',
  177. 'choice_label' => 'name',
  178. 'label_format' => 'Renderis',
  179. ])
  180. ->add('view_three', EntityType::class, [
  181. 'required' => false,
  182. 'class' => 'AppBundle:Image',
  183. 'choice_label' => 'name',
  184. 'label_format' => 'Renderis',
  185. ])
  186. ->add('Submit', SubmitType::class)
  187. ->getForm();
  188. $form->handleRequest($request);
  189. if ($request->isMethod('POST') && $form->isSubmitted() && $form->isValid()) {
  190. return $this->redirect($this->generateUrl('RotatorsAdminList'));
  191. }
  192.  
  193. return $this->render('admin/pages/addRotatorForm.html.twig', [
  194. 'form' => $form->createView(),
  195. 'product' => $product,
  196.  
  197. ]);
  198.  
  199. }
  200.  
  201. public function nippleTypes()
  202. {
  203. $em = $this->getDoctrine()->getManager();
  204. $nipples = $em->getRepository(Nipples::class)->findAll();
  205. foreach ($nipples as $nipple) {
  206. $id = $nipple->getId();
  207. $type = $nipple->getNipletype();
  208. $size = $nipple->getNiplesize();
  209. $label = "$type $size";
  210. $nipplelist[$label] = $id;
  211. }
  212. return $nipplelist;
  213. }
  214.  
  215. public function rotatorTopTypes()
  216. {
  217. $rotatorTopTypes = [
  218. '1' => 'eye',
  219. '2' => 'fork',
  220. '3' => 'flange',
  221. ];
  222. return $rotatorTopTypes;
  223. }
  224.  
  225. public function rotatorBottomTypes()
  226. {
  227. $rotatorBottomTypes = [
  228. '1' => 'axle',
  229. '2' => 'flange',
  230. ];
  231. return $rotatorBottomTypes;
  232. }
  233.  
  234. public function staticLoadOptions()
  235. {
  236. $staticLoadOptions = [
  237. '10' => '10',
  238. '30' => '30',
  239. '45' => '45',
  240. '55' => '55',
  241. '60' => '60',
  242. '100' => '100',
  243. '120' => '120',
  244. '160' => '160'
  245. ];
  246. return $staticLoadOptions;
  247. }
  248.  
  249. public function dynaLoadOptions()
  250. {
  251. $dynaLoadOptions = [
  252. '5' => '5',
  253. '15' => '15',
  254. '25' => '25',
  255. '30' => '30',
  256. '50' => '50',
  257. '60' => '60',
  258. '80' => '80'
  259. ];
  260. return $dynaLoadOptions;
  261. }
  262.  
  263. public function maxPressureOptions()
  264. {
  265. $maxPressureOptions = [
  266. '200' => '200',
  267. '250' => '250',
  268. '300' => '300'
  269. ];
  270. return $maxPressureOptions;
  271. }
  272.  
  273. public function oilflowOptions()
  274. {
  275. $oilflowOptions = [
  276. '10' => '10',
  277. '20' => '20',
  278. '25' => '25',
  279. '30' => '30',
  280. '35' => '35',
  281. '40' => '40',
  282. ];
  283. return $oilflowOptions;
  284. }
  285.  
  286. public function torqueOptions()
  287. {
  288. $torqueOptions = [
  289. '350' => '350',
  290. '900' => '900',
  291. '1200' => '1200',
  292. '1300' => '1300',
  293. '1850' => '1850',
  294. '2800' => '2800',
  295. '2900' => '2900',
  296. '3400' => '3400',
  297. ];
  298. return $torqueOptions;
  299. }
  300.  
  301. public function topTypeOptions()
  302. {
  303. $topTypeOptions = [
  304. 'A' => '1',
  305. 'V' => '2',
  306. 'T' => '3',
  307. ];
  308. return $topTypeOptions;
  309. }
  310.  
  311. public function calculateNegativeLoad($n, $x = 5)
  312. {
  313. $n = $n * 0.8;
  314. return (round($n) % $x === 0) ? round($n) : round(($n + $x / 2) / $x) * $x;
  315. }
  316.  
  317. public function calculateDynamicLoad($n)
  318. {
  319. if ($n == 55) {
  320. return 0.5 * $n + 5;
  321. } else {
  322. return 0.5 * $n;
  323. }
  324. }
  325.  
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement