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

/application/modules/geocontexter/controllers/ItemEditController.php

http://geocontexter.googlecode.com/
PHP | 1030 lines | 694 code | 203 blank | 133 comment | 81 complexity | 6161d1cd5d3f861966a2d1cfad8ee593 MD5 | raw file
  1. <?php
  2. /**
  3. * GeoContexter
  4. * @link http://code.google.com/p/geocontexter/
  5. * @package GeoContexter
  6. */
  7. /**
  8. * Edit list item
  9. *
  10. * @package GeoContexter
  11. * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  12. * @author Armand Turpel <geocontexter@gmail.com>
  13. * @version $Rev: 828 $ / $LastChangedDate: 2011-02-27 10:30:28 +0100 (Sun, 27 Feb 2011) $ / $Author: armand.turpel $
  14. */
  15. class Geocontexter_ItemEditController extends Mozend_Controller_Action_AbstractAdmin
  16. {
  17. public function preDispatch()
  18. {
  19. $this->session = Zend_Registry::get('session');
  20. // set view. we keep allways the index view
  21. //
  22. $this->_helper->viewRenderer->setScriptAction('index');
  23. $this->id_list = $this->request->getParam('id_list');
  24. $this->id_item = $this->request->getParam('id_item');
  25. if((null === $this->id_item) || (0 == $this->id_item))
  26. {
  27. return $this->error( '0 or no id_item request parameter defined.', __file__, __line__ );
  28. }
  29. if((null === $this->id_list) || (0 == $this->id_list))
  30. {
  31. return $this->error( '0 or no id_list request parameter defined.', __file__, __line__ );
  32. }
  33. // fetch the active tab number for jquery ui tabs
  34. //
  35. $tab_number = $this->request->getParam('tab_number');
  36. if(null !== $tab_number)
  37. {
  38. $this->view->tab_number = (int)$tab_number;
  39. }
  40. else
  41. {
  42. $this->view->tab_number = 0;
  43. }
  44. $this->view->partialData['active_page'] = 'edit_item';
  45. $this->view->partialData['id_item'] = $this->id_item;
  46. $this->view->partialData['id_list'] = $this->id_list;
  47. $this->view->id_list = $this->id_list;
  48. $this->view->item_branch_result = array();
  49. $this->view->attribute_groups = array();
  50. $this->view->lists_result = array();
  51. $this->view->lists_childs_result = array();
  52. $this->view->item_result = array();
  53. $this->view->attribute_id_group = 0;
  54. $this->view->item_name = '';
  55. $this->view->item_description = '';
  56. $this->view->item_id_status = 100;
  57. $this->view->item_lang = 'en';
  58. $this->view->tabindex_after_attributes = 8;
  59. $this->view->error = array();
  60. $this->view->result = array();
  61. }
  62. public function indexAction()
  63. {
  64. // should we move an item list order
  65. //
  66. $this->move_item_list_order();
  67. $this->move_image_order();
  68. $this->move_file_order();
  69. $this->init_data();
  70. $this->delete_image();
  71. $this->delete_file();
  72. }
  73. /**
  74. * Delete item image
  75. *
  76. */
  77. public function delete_image()
  78. {
  79. // fetch vars to move attributes order up or down
  80. //
  81. $id_image = $this->request->getParam('deleteImage');
  82. if(null !== $id_image)
  83. {
  84. $image = new Geocontexter_Model_ItemImageDelete;
  85. $params = array('id_image' => $id_image,
  86. 'files_folder' => $this->view->item_result['files_folder']);
  87. $result = $image->delete( $params );
  88. if($result instanceof Mozend_ModelError)
  89. {
  90. return $this->error( $result->getErrorString(), __file__, __line__ );
  91. $this->view->error[] = 'Couldnt delete image';
  92. $this->view->headTitle('Couldnt delete image: ', 'PREPEND');
  93. $this->view->tab_number = 5;
  94. }
  95. else
  96. {
  97. $this->_redirect($this->view->adminAreaToken .
  98. '/geocontexter/item-edit/index/id_item/'.$this->id_item.'/id_list/'.$this->id_list.'/tab_number/' . $this->view->tab_number);
  99. }
  100. }
  101. }
  102. /**
  103. * Move order of an item image
  104. *
  105. */
  106. public function move_image_order()
  107. {
  108. // fetch vars to move attributes order up or down
  109. //
  110. $move_image_up = $this->request->getParam('imageMoveUp');
  111. $move_image_down = $this->request->getParam('imageMoveDown');
  112. $id_item = $this->request->getParam('id_item');
  113. if(null !== $move_image_up)
  114. {
  115. if(null === $id_item)
  116. {
  117. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  118. }
  119. $image_order = new Geocontexter_Model_ItemImageMoveOrder;
  120. $result = $image_order->moveUp(array('id_item' => $id_item,
  121. 'id_image' => $move_image_up));
  122. if($result instanceof Mozend_ModelError)
  123. {
  124. return $this->error( $result->getErrorString(), __file__, __line__ );
  125. }
  126. else
  127. {
  128. $this->view->headTitle('Moved image up: ', 'PREPEND');
  129. }
  130. }
  131. if(null !== $move_image_down)
  132. {
  133. if(null === $id_item)
  134. {
  135. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  136. }
  137. $image_order = new Geocontexter_Model_ItemImageMoveOrder;
  138. $result = $image_order->moveDown(array('id_item' => $id_item,
  139. 'id_image' => $move_image_down));
  140. if($result instanceof Mozend_ModelError)
  141. {
  142. return $this->error( $result->getErrorString(), __file__, __line__ );
  143. }
  144. else
  145. {
  146. $this->view->headTitle('Moved image down: ', 'PREPEND');
  147. }
  148. }
  149. }
  150. /**
  151. * Delete item file
  152. *
  153. */
  154. public function delete_file()
  155. {
  156. // fetch vars to move attributes order up or down
  157. //
  158. $id_file = $this->request->getParam('deleteFile');
  159. if(null !== $id_file)
  160. {
  161. $file = new Geocontexter_Model_ItemFileDelete;
  162. $params = array('id_file' => $id_file,
  163. 'files_folder' => $this->view->item_result['files_folder']);
  164. $result = $file->delete( $params );
  165. if($result instanceof Mozend_ModelError)
  166. {
  167. return $this->error( $result->getErrorString(), __file__, __line__ );
  168. $this->view->error[] = 'Couldnt delete image';
  169. $this->view->headTitle('Couldnt delete image: ', 'PREPEND');
  170. $this->view->tab_number = 6;
  171. }
  172. else
  173. {
  174. $this->_redirect($this->view->adminAreaToken .
  175. '/geocontexter/item-edit/index/id_item/'.$this->id_item.'/id_list/'.$this->id_list.'/tab_number/' . $this->view->tab_number);
  176. }
  177. }
  178. }
  179. /**
  180. * Move order of an item file
  181. *
  182. */
  183. public function move_file_order()
  184. {
  185. // fetch vars to move file order up or down
  186. //
  187. $move_file_up = $this->request->getParam('fileMoveUp');
  188. $move_file_down = $this->request->getParam('fileMoveDown');
  189. $id_item = $this->request->getParam('id_item');
  190. if(null !== $move_file_up)
  191. {
  192. if(null === $id_item)
  193. {
  194. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  195. }
  196. $file_order = new Geocontexter_Model_ItemFileMoveOrder;
  197. $result = $file_order->moveUp(array('id_item' => $id_item,
  198. 'id_file' => $move_file_up));
  199. if($result instanceof Mozend_ModelError)
  200. {
  201. return $this->error( $result->getErrorString(), __file__, __line__ );
  202. }
  203. else
  204. {
  205. $this->view->headTitle('Moved file up: ', 'PREPEND');
  206. }
  207. }
  208. if(null !== $move_file_down)
  209. {
  210. if(null === $id_item)
  211. {
  212. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  213. }
  214. $file_order = new Geocontexter_Model_ItemFileMoveOrder;
  215. $result = $file_order->moveDown(array('id_item' => $id_item,
  216. 'id_file' => $move_file_down));
  217. if($result instanceof Mozend_ModelError)
  218. {
  219. return $this->error( $result->getErrorString(), __file__, __line__ );
  220. }
  221. else
  222. {
  223. $this->view->headTitle('Moved file down: ', 'PREPEND');
  224. }
  225. }
  226. }
  227. /**
  228. * Move order of an item list
  229. *
  230. */
  231. public function move_item_list_order()
  232. {
  233. // fetch vars to move attributes order up or down
  234. //
  235. $move_list_up = $this->request->getParam('moveUp');
  236. $move_list_down = $this->request->getParam('moveDown');
  237. $id_list_item = $this->request->getParam('id_list_item');
  238. $id_item = $this->request->getParam('id_item');
  239. if(null !== $move_list_up)
  240. {
  241. if(null === $id_item)
  242. {
  243. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  244. }
  245. if(null === $id_list_item)
  246. {
  247. return $this->error( 'no id_list_item request parameter defined.', __file__, __line__ );
  248. }
  249. $list_order = new Geocontexter_Model_ListItemMoveOrder;
  250. $result = $list_order->moveUp(array('id_item' => $id_item,
  251. 'id_list_item' => $id_list_item));
  252. if($result instanceof Mozend_ModelError)
  253. {
  254. return $this->error( $result->getErrorString(), __file__, __line__ );
  255. }
  256. else
  257. {
  258. $this->view->headTitle('Moved list up of item: ', 'PREPEND');
  259. }
  260. }
  261. if(null !== $move_list_down)
  262. {
  263. if(null === $id_item)
  264. {
  265. return $this->error( 'no id_item request parameter defined.', __file__, __line__ );
  266. }
  267. if(null === $id_list_item)
  268. {
  269. return $this->error( 'no id_list_item request parameter defined.', __file__, __line__ );
  270. }
  271. $list_order = new Geocontexter_Model_ListItemMoveOrder;
  272. $result = $list_order->moveDown(array('id_item' => $id_item,
  273. 'id_list_item' => $id_list_item));
  274. if($result instanceof Mozend_ModelError)
  275. {
  276. return $this->error( $result->getErrorString(), __file__, __line__ );
  277. }
  278. else
  279. {
  280. $this->view->headTitle('Moved list down of item: ', 'PREPEND');
  281. }
  282. }
  283. }
  284. /**
  285. * update item data
  286. */
  287. public function updateAction()
  288. {
  289. $save = $this->request->getPost('save');
  290. // check on cancel action
  291. //
  292. $cancel = $this->request->getPost('cancel');
  293. if($cancel !== null)
  294. {
  295. $this->_redirect($this->view->adminAreaToken .
  296. '/geocontexter/list/index/id_list/' . $this->id_list);
  297. }
  298. $this->init_data();
  299. $params = array();
  300. $this->view->error = array();
  301. // check if upload image action
  302. //
  303. if(isset($_FILES['item_image']['name']) && !empty($_FILES['item_image']['name']))
  304. {
  305. // check if a files folder entry for the current item exists
  306. //
  307. if(empty($this->view->item_result['files_folder']))
  308. {
  309. $params['data']['files_folder'] = $data_folder_name = md5(uniqid($this->view->item_result['id_item'], true));
  310. }
  311. else
  312. {
  313. $data_folder_name = $this->view->item_result['files_folder'];
  314. }
  315. $image_file = new Geocontexter_Model_ImageUpload;
  316. $upload_params = array('post_name' => 'item_image',
  317. 'data_folder' => DATA_PATH . '/gc_item/' . $data_folder_name);
  318. $image_result = $image_file->upload( $upload_params );
  319. if($image_result instanceof Mozend_ModelError)
  320. {
  321. $this->error( $image_result->getErrorString(), __file__, __line__, true );
  322. // assign view error
  323. //
  324. $__error = $image_result->getErrorArray();
  325. foreach($__error as $key => $val)
  326. {
  327. if(is_array($val))
  328. {
  329. foreach($val as $err)
  330. {
  331. $this->view->error[] = $err;
  332. }
  333. }
  334. else
  335. {
  336. $this->view->error[] = $val;
  337. }
  338. }
  339. $save = false;
  340. }
  341. else
  342. {
  343. // add item image entry in geocontexter.gc_item_image
  344. //
  345. $image_params = array('id_item' => $this->view->item_result['id_item'],
  346. 'file_mime' => $image_result['type'],
  347. 'file_name' => $image_result['name'],
  348. 'file_size' => $image_result['size'],
  349. 'file_width' => $image_result['image_width'],
  350. 'file_height' => $image_result['image_height']
  351. );
  352. $image = new Geocontexter_Model_ItemImageAdd();
  353. $result = $image->add($image_params);
  354. if($result instanceof Mozend_ModelError)
  355. {
  356. $image_file->removeFile();
  357. $this->view->error[] = $result->getErrorArray();
  358. return $this->error( $result->getErrorString(), __file__, __line__, true );
  359. }
  360. $save = true;
  361. }
  362. $this->view->tab_number = 5;
  363. }
  364. else if(isset($_FILES['item_file']['name']) && !empty($_FILES['item_file']['name']))
  365. {
  366. // check if a files folder entry for the current item exists
  367. //
  368. if(empty($this->view->item_result['files_folder']))
  369. {
  370. $params['data']['files_folder'] = $data_folder_name = md5(uniqid($this->view->item_result['id_item'], true));
  371. }
  372. else
  373. {
  374. $data_folder_name = $this->view->item_result['files_folder'];
  375. }
  376. $file_file = new Geocontexter_Model_FileUpload;
  377. $upload_params = array('post_name' => 'item_file',
  378. 'data_folder' => DATA_PATH . '/gc_item/' . $data_folder_name);
  379. $file_result = $file_file->upload( $upload_params );
  380. if($file_result instanceof Mozend_ModelError)
  381. {
  382. $this->error( $file_result->getErrorString(), __file__, __line__, true );
  383. // assign view error
  384. //
  385. $__error = $file_result->getErrorArray();
  386. foreach($__error as $key => $val)
  387. {
  388. if(is_array($val))
  389. {
  390. foreach($val as $err)
  391. {
  392. $this->view->error[] = $err;
  393. }
  394. }
  395. else
  396. {
  397. $this->view->error[] = $val;
  398. }
  399. }
  400. $save = false;
  401. }
  402. else
  403. {
  404. // add item image entry in geocontexter.gc_item_file
  405. //
  406. $file_params = array('id_item' => $this->view->item_result['id_item'],
  407. 'title' => '',
  408. 'description' => '',
  409. 'file_mime' => $file_result['type'],
  410. 'file_name' => $file_result['name'],
  411. 'file_size' => $file_result['size']
  412. );
  413. $file = new Geocontexter_Model_ItemFileAdd();
  414. $result = $file->add($file_params);
  415. if($result instanceof Mozend_ModelError)
  416. {
  417. $file_file->removeFile();
  418. $this->view->error[] = $result->getErrorArray();
  419. return $this->error( $result->getErrorString(), __file__, __line__, true );
  420. }
  421. $save = true;
  422. }
  423. $this->view->tab_number = 6;
  424. }
  425. $attribute_id_group = $this->request->getPost('id_attribute_group');
  426. // fetch addditional attributes values if set
  427. //
  428. if($attribute_id_group !== null)
  429. {
  430. $this->view->attribute_id_group = $attribute_id_group;
  431. $attributes = new Geocontexter_Model_AttributeJsonEncode;
  432. $serialized_attributes = $attributes->encode( $attribute_id_group, $this->request->getPost() );
  433. if($serialized_attributes instanceof Mozend_ModelError)
  434. {
  435. return $this->error( $serialized_attributes->getErrorString(), __file__, __line__ );
  436. }
  437. else
  438. {
  439. $params['data']['attribute_value'] = $serialized_attributes;
  440. $params['data']['id_attribute_group'] = $attribute_id_group;
  441. $this->view->additionalAttributes['id_attribute_group'] = $attribute_id_group;
  442. $this->view->additionalAttributes['tabindex'] = 7;
  443. // get tabindex after the additional attribute fields
  444. //
  445. $this->view->tabindex_after_attributes += $attributes->numAttributes - 1;
  446. $attributes_values = new Geocontexter_Model_AttributeJsonDecode;
  447. $this->view->additionalAttributes['attributes'] = $attributes_values->decode( $serialized_attributes,
  448. $attribute_id_group );
  449. }
  450. }
  451. $params['id_item'] = $this->id_item;
  452. $remove_item_list = $this->request->getPost('delete_id_list');
  453. if(($remove_item_list !== null) && is_array($remove_item_list))
  454. {
  455. $params['remove_item_list'] = $remove_item_list;
  456. }
  457. $this->view->result['title'] =
  458. $params['data']['title'] = $this->request->getPost('item_name');
  459. $this->view->result['description'] =
  460. $params['data']['description'] = $this->request->getPost('item_description');
  461. $this->view->result['id_status'] =
  462. $params['data']['id_status'] = $this->request->getPost('item_id_status');
  463. $this->view->result['lang'] =
  464. $params['data']['lang'] = $this->request->getPost('item_lang');
  465. $preferred_list = $this->request->getPost('preferred_id_list');
  466. if(null !== $preferred_list)
  467. {
  468. $params['preferred_list'] = $preferred_list;
  469. }
  470. $remove_synonym_of = trim($this->request->getPost('remove_synonym_of'));
  471. if(!empty($remove_synonym_of))
  472. {
  473. $params['data']['synonym_of'] = null;
  474. }
  475. $delete_id_keyword = $this->request->getPost('delete_id_keyword');
  476. if(($delete_id_keyword !== null) && (count($delete_id_keyword) > 0))
  477. {
  478. $params['remove_id_keyword'] = $delete_id_keyword;
  479. }
  480. $delete_list_id_keyword = $this->request->getPost('delete_item_list_id_keyword');
  481. if(($delete_list_id_keyword !== null) && (count($delete_list_id_keyword) > 0))
  482. {
  483. $params['remove_list_id_keyword'] = $delete_list_id_keyword;
  484. $params['id_list_item'] = $this->item_list['id_list_item'];
  485. }
  486. if(empty($params['data']['title']))
  487. {
  488. $this->view->error[] = 'Item name is empty';
  489. $this->view->headTitle('Error: Item name field is empty', 'PREPEND');
  490. }
  491. if(count($this->view->error) > 0)
  492. {
  493. return;
  494. }
  495. $this->update_images();
  496. $this->update_files();
  497. // add item attribute
  498. //
  499. $item = new Geocontexter_Model_ItemUpdate;
  500. $result = $item->update( $params );
  501. if($result instanceof Mozend_ModelError)
  502. {
  503. return $this->error( $result->getErrorString(), __file__, __line__ );
  504. }
  505. else if($save === null)
  506. {
  507. $this->_redirect($this->view->adminAreaToken .
  508. '/geocontexter/list/index/id_list/' . $this->id_list);
  509. }
  510. else
  511. {
  512. $this->_redirect($this->view->adminAreaToken .
  513. '/geocontexter/item-edit/index/id_item/'.$this->id_item.'/id_list/'.$this->id_list.'/tab_number/' . $this->view->tab_number);
  514. }
  515. }
  516. /**
  517. * update image
  518. *
  519. */
  520. private function update_images()
  521. {
  522. $id_image = $this->request->getPost('id_image');
  523. $image_title = $this->request->getPost('image_title');
  524. $image_description = $this->request->getPost('image_description');
  525. $x = 0;
  526. $item_image = new Geocontexter_Model_ItemImageUpdate;
  527. foreach($image_title as $title)
  528. {
  529. $params = array('id_image' => $id_image[$x],
  530. 'data' => array('title' => strip_tags($title),
  531. 'description' => strip_tags($image_description[$x])));
  532. $result = $item_image->update( $params );
  533. if($result instanceof Mozend_ModelError)
  534. {
  535. $this->error( $result->getErrorString(), __file__, __line__, true );
  536. $this->view->error[] = 'error updating image';
  537. }
  538. $x++;
  539. }
  540. }
  541. /**
  542. * update files
  543. *
  544. */
  545. private function update_files()
  546. {
  547. $id_file = $this->request->getPost('id_file');
  548. $file_title = $this->request->getPost('file_title');
  549. $file_description = $this->request->getPost('file_description');
  550. $x = 0;
  551. $item_file = new Geocontexter_Model_ItemFileUpdate;
  552. foreach($file_title as $title)
  553. {
  554. $params = array('id_file' => $id_file[$x],
  555. 'data' => array('title' => strip_tags($title),
  556. 'description' => strip_tags($file_description[$x])));
  557. $result = $item_file->update( $params );
  558. if($result instanceof Mozend_ModelError)
  559. {
  560. $this->error( $result->getErrorString(), __file__, __line__, true );
  561. $this->view->error[] = 'error updating file';
  562. }
  563. $x++;
  564. }
  565. }
  566. /**
  567. * get item synonym
  568. *
  569. * @param bigint $synonym_of
  570. * @return array
  571. */
  572. private function get_item_synonym_of( $synonym_of )
  573. {
  574. $synonym_result = array();
  575. if(!empty($synonym_of))
  576. {
  577. $synonym_item = new Geocontexter_Model_ListGetItemRelated;
  578. $params = array('id_item' => $synonym_of,
  579. 'order_by_preferred_order' => true);
  580. $synonym_result = $synonym_item->get( $params );
  581. if($synonym_result instanceof Mozend_ModelError)
  582. {
  583. return $this->error( $synonym_result->getErrorString(), __file__, __line__ );
  584. }
  585. }
  586. return $synonym_result;
  587. }
  588. private function init_data()
  589. {
  590. $item = new Geocontexter_Model_ItemGet;
  591. $params = array('id_item' => $this->id_item,
  592. 'default_display' => 0,
  593. 'system_serial' => true);
  594. $item_result = $item->get( $params );
  595. if($item_result instanceof Mozend_ModelError)
  596. {
  597. return $this->error( $item_result->getErrorString(), __file__, __line__ );
  598. }
  599. else
  600. {
  601. $this->view->item_result = $item_result;
  602. // assign item attributes
  603. //
  604. if($item_result['id_attribute_group'] != null)
  605. {
  606. $attributes_values = new Geocontexter_Model_AttributeJsonDecode;
  607. // we pass this array to the partial view helper "_additional_attributes.phtml"
  608. //
  609. $this->view->additionalAttributes = array();
  610. $this->view->additionalAttributes['attributes'] = $attributes_values->decode( $item_result['attribute_value'],
  611. $item_result['id_attribute_group'] );
  612. $this->view->additionalAttributes['id_attribute_group'] = $item_result['id_attribute_group'];
  613. $this->view->additionalAttributes['tabindex'] = 7;
  614. // get tabindex after the aaditional attribute fields
  615. //
  616. $this->view->tabindex_after_attributes += count($this->view->additionalAttributes['attributes']) - 1;
  617. }
  618. }
  619. // fetch the synonym of the requested item
  620. //
  621. $this->view->synonym_result = $this->get_item_synonym_of( $item_result['synonym_of'] );
  622. // get item images
  623. //
  624. $item_images = new Geocontexter_Model_ItemImageGetAll;
  625. $params = array('id_item' => $this->id_item);
  626. $images = $item_images->get( $params );
  627. if($images instanceof Mozend_ModelError)
  628. {
  629. return $this->error( $images->getErrorString(), __file__, __line__ );
  630. }
  631. $this->view->item_images = $images;
  632. // get item files
  633. //
  634. $item_files = new Geocontexter_Model_ItemFileGetAll;
  635. $params = array('id_item' => $this->id_item);
  636. $files = $item_files->get( $params );
  637. if($files instanceof Mozend_ModelError)
  638. {
  639. return $this->error( $files->getErrorString(), __file__, __line__ );
  640. }
  641. $this->view->item_files = $files;
  642. // get item lists
  643. //
  644. $lists = new Geocontexter_Model_ListGetItemRelated;
  645. $params = array('id_item' => $this->id_item,
  646. 'order_by_preferred_order' => true,
  647. 'system_serial' => true);
  648. $result = $lists->get( $params );
  649. if($result instanceof Mozend_ModelError)
  650. {
  651. return $this->error( $result->getErrorString(), __file__, __line__ );
  652. }
  653. else
  654. {
  655. $this->view->lists_result = $result;
  656. }
  657. // get availaible languages
  658. //
  659. $languages = new Geocontexter_Model_LanguagesGet;
  660. // optional
  661. $params = array('enable' => 'true');
  662. $lang_result = $languages->get( $params );
  663. if($lang_result instanceof Mozend_ModelError)
  664. {
  665. return $this->error( $lang_result->getErrorString(), __file__, __line__ );
  666. }
  667. else
  668. {
  669. $this->view->languages = $lang_result;
  670. }
  671. // get all list related attribute groups
  672. //
  673. $attribute_groups = new Geocontexter_Model_AttributeGroupsGet;
  674. $params = array('id_table' => 3);
  675. $result = $attribute_groups->get( $params );
  676. if($result instanceof Mozend_ModelError)
  677. {
  678. return $this->error( $result->getErrorString(), __file__, __line__ );
  679. }
  680. else
  681. {
  682. $this->view->attribute_groups = $result;
  683. }
  684. // get current item list
  685. //
  686. $list = new Geocontexter_Model_ItemListGet;
  687. $params = array('id_list' => $this->id_list,
  688. 'id_item' => $this->id_item);
  689. $this->item_list = $list->get( $params );
  690. if($this->item_list instanceof Mozend_ModelError)
  691. {
  692. return $this->error( $this->item_list->getErrorString(), __file__, __line__ );
  693. }
  694. else
  695. {
  696. $this->view->list_result = $this->item_list;
  697. }
  698. $item_childs = new Geocontexter_Model_ListGetChilds;
  699. $params = array('id_parent' => 0) ;
  700. $item_childs_result = $item_childs->get( $params );
  701. if($item_childs_result instanceof Mozend_ModelError)
  702. {
  703. return $this->error( $item_childs_result->getErrorString(), __file__, __line__ );
  704. }
  705. else
  706. {
  707. $this->view->lists_childs_result = $item_childs_result;
  708. }
  709. $key_branches = new Geocontexter_Model_ItemGetKeywordBranches;
  710. $params = array('id_item' => $this->id_item);
  711. $result = $key_branches->get( $params );
  712. if($result instanceof Mozend_ModelError)
  713. {
  714. return $this->error( $result->getErrorString(), __file__, __line__ );
  715. }
  716. else
  717. {
  718. $this->view->keywords_result = $result;
  719. }
  720. $key_branches = new Geocontexter_Model_ItemListGetKeywordBranches;
  721. $params = array('id_item' => $this->id_item,
  722. 'id_list' => $this->id_list);
  723. $result = $key_branches->get( $params );
  724. if($result instanceof Mozend_ModelError)
  725. {
  726. return $this->error( $result->getErrorString(), __file__, __line__ );
  727. }
  728. else
  729. {
  730. $this->view->item_list_keywords_result = $result;
  731. }
  732. // assign html head title
  733. //
  734. $this->view->headTitle('Edit item ' . $item_result['title'], 'PREPEND');
  735. // init of model callbacks. used for new window model calls.
  736. //
  737. $this->register_model_callbacks( $this->session );
  738. }
  739. /**
  740. * Register of model callback classes
  741. *
  742. *
  743. *
  744. * @param object $session
  745. */
  746. private function register_model_callbacks( & $session )
  747. {
  748. $action_callback = new Geocontexter_Model_ModelCallback( $session );
  749. // url to reload after a model callback was done
  750. //
  751. $this->opener_url = $this->view->baseUrl().'/'.$this->view->adminAreaToken.'/geocontexter/itemEdit/index/id_item/'.$this->id_item.'/id_list/'.$this->id_list;
  752. if(false !== $this->item_list)
  753. {
  754. //
  755. // item_list_keywords
  756. //
  757. $params_item_list_keyword =
  758. array('model_class' => 'Geocontexter_Model_ItemListAddKeyword',
  759. 'model_class_methode' => 'add',
  760. 'model_field' => 'id_keyword',
  761. 'id_name' => 'id_list_item',
  762. 'id_value' => $this->item_list['id_list_item'],
  763. 'input_type' => 'checkbox',
  764. 'opener_url' => $this->opener_url . '/tab_number/3');
  765. $callback_number = $action_callback->register( $params_item_list_keyword );
  766. if($callback_number instanceof Mozend_ModelError)
  767. {
  768. return $this->error( $callback_number->getErrorString(), __file__, __line__ );
  769. }
  770. $this->view->item_list_keyword_callback_number = $callback_number;
  771. }
  772. else
  773. {
  774. $this->view->item_list_keyword_callback_number = false;
  775. }
  776. //
  777. // item_keywords
  778. //
  779. $params_item_keyword =
  780. array('model_class' => 'Geocontexter_Model_ItemAddKeywords',
  781. 'model_class_methode' => 'add',
  782. 'model_field' => 'id_keyword',
  783. 'id_name' => 'id_item',
  784. 'id_value' => $this->id_item,
  785. 'input_type' => 'checkbox',
  786. 'opener_url' => $this->opener_url . '/tab_number/2');
  787. $callback_number = $action_callback->register( $params_item_keyword );
  788. if($callback_number instanceof Mozend_ModelError)
  789. {
  790. return $this->error( $callback_number->getErrorString(), __file__, __line__ );
  791. }
  792. $this->view->item_keyword_callback_number = $callback_number;
  793. // item synonym
  794. //
  795. $params_item_synonym =
  796. array('model_class' => 'Geocontexter_Model_ItemChangeSynonym',
  797. 'model_class_methode' => 'change',
  798. 'model_field' => 'synonym_of',
  799. 'id_name' => 'id_item',
  800. 'id_value' => $this->id_item,
  801. 'input_type' => 'radio',
  802. 'opener_url' => $this->opener_url . '/tab_number/0');
  803. $callback_number = $action_callback->register( $params_item_synonym );
  804. if($callback_number instanceof Mozend_ModelError)
  805. {
  806. return $this->error( $callback_number->getErrorString(), __file__, __line__ );
  807. }
  808. $this->view->item_synonym_callback_number = $callback_number;
  809. //
  810. // item_lists
  811. //
  812. $params_item_list =
  813. array('model_class' => 'Geocontexter_Model_ItemAddList',
  814. 'model_class_methode' => 'addList',
  815. 'model_field' => 'id_list',
  816. 'id_name' => 'id_item',
  817. 'id_value' => $this->id_item,
  818. 'input_type' => 'checkbox',
  819. 'opener_url' => $this->opener_url . '/tab_number/1');
  820. $callback_number = $action_callback->register( $params_item_list );
  821. if($callback_number instanceof Mozend_ModelError)
  822. {
  823. return $this->error( $callback_number->getErrorString(), __file__, __line__ );
  824. }
  825. $this->view->item_list_callback_number = $callback_number;
  826. }
  827. }