Lithron.LMediaManager
[ class tree: Lithron.LMediaManager ] [ index: Lithron.LMediaManager ] [ all elements ]

Source for file LMediaSelection.php

Documentation is available at LMediaSelection.php

  1. <?php
  2.  
  3.  
  4. /**
  5. * class file.
  6. *
  7. * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  8. * @copyright 2005, diemeisterei GmbH. All rights reserved.
  9. * @author $Author: schmunk $
  10. * @version $Revision: 254 $ $Date: 2006-06-06 01:53:39 +0200 (Di, 06 Jun 2006) $
  11. * @package Lithron.LMediaManager
  12. * @subpackage WebControls
  13. */
  14.  
  15. /**
  16. * Implements IMetaData. (TODO)
  17. *
  18. * Displays a selection for media files
  19. *
  20. * @package System.Web.UI.WebControls
  21. * @subpackage MetaData
  22. */
  23.  
  24. class LMediaSelection extends TTemplateControl implements IMetaData
  25. {
  26. private $Core;
  27.  
  28. /**
  29. * Prepares the core
  30. */
  31. public function onInit($param)
  32. {
  33. $this->Core= new LMediaManagerCore;
  34. parent :: onInit($param);
  35. }
  36.  
  37. /**
  38. * @return array selected items in both lists
  39. */
  40. public function getSelection()
  41. {
  42. $return= array ();
  43.  
  44. // get selection from search
  45. $items= $this->SearchGrid->getItems();
  46. foreach ($items AS $item)
  47. {
  48. if ($item->Cells[0]->Select->getChecked())
  49. {
  50. $r['MetaRecordId']= $item->Cells[0]->Select->Attributes->itemAt("MediaId");
  51. $r['Description']= $item->Cells[2]->MediaDescription->Text;
  52. $r['Rank']= "z";
  53. $return[]= $r;
  54. }
  55. }
  56.  
  57. // get selection & data from selected grid
  58. $items= $this->SelectedGrid->getItems();
  59. foreach ($items AS $item)
  60. {
  61. if ($item->Cells[0]->Select->getChecked())
  62. {
  63. $r['MetaRecordId']= $item->Cells[0]->Select->Attributes->itemAt("MediaId");
  64. $r['Description']= $item->Cells[3]->Description->Text;
  65. $r['Rank']= $item->Cells[4]->Rank->Text;
  66. $return[]= $r;
  67. }
  68. }
  69. return $return;
  70. }
  71.  
  72. /**
  73. * @param array sets selection from database and current selection
  74. */
  75. public function setSelection($array= null)
  76. {
  77. $currentSelection= $this->getSelection();
  78. if ($array === null)
  79. $selection= $currentSelection;
  80. else
  81. $selection= array_merge($array, $currentSelection);
  82.  
  83. // parse data for later usage
  84. if (is_array($selection))
  85. foreach ($selection AS $s)
  86. {
  87. $ids[]= $s['MetaRecordId'];
  88. if (isset ($s['Description']))
  89. $info[$s['MetaRecordId']]= array (
  90. $s['Description'],
  91. $s['Rank']
  92. );
  93. }
  94. else
  95. {
  96. $ids= array ();
  97. }
  98.  
  99. // query data
  100. $Criteria= new LMediaCriteria;
  101. $Criteria->setRecordIds($ids);
  102. $items= LMediaManagerCore :: queryRecords($Criteria->build());
  103.  
  104. // fill grid
  105. $this->SelectedGrid->DataSource= $items;
  106. $this->SelectedGrid->CurrentPageIndex= 0;
  107. $this->SelectedGrid->dataBind();
  108.  
  109. // set checkbox & set values in selected grid
  110. $selected_items= $this->SelectedGrid->getItems();
  111. foreach ($selected_items AS $item)
  112. {
  113. $item->Cells[0]->Select->setChecked(true);
  114. // TODO
  115. if (isset ($info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")]))
  116. {
  117. $item->Cells[3]->Description->Text= $info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][0];
  118. $item->Cells[4]->Rank->Text= $info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][1];
  119. }
  120. }
  121. // unset all checkboxes in search grid
  122. $search_items= $this->SearchGrid->getItems();
  123. foreach ($search_items AS $item)
  124. {
  125. $item->Cells[0]->Select->setChecked(false);
  126. }
  127.  
  128. }
  129.  
  130. public function applyClicked($sender, $param)
  131. {
  132. $this->setSelection();
  133. }
  134.  
  135. public function searchClicked($sender, $param)
  136. {
  137. $Criteria= new LMediaCriteria;
  138. $Criteria->setSearchString($sender->Parent->findControl("SearchString")->getText());
  139. $items= LMediaManagerCore :: queryRecords($Criteria->build());
  140. #$r= $this->Core->getMediaList("search", $sender->Parent->findControl("SearchString")->getText());
  141.  
  142. $this->setViewstate("Records", $items);
  143. $this->SearchGrid->DataSource= $items;
  144. $this->SearchGrid->CurrentPageIndex= 0;
  145. $this->SearchGrid->dataBind();
  146. }
  147.  
  148. public function searchText($sender, $param)
  149. {
  150. $Criteria= new LMediaCriteria;
  151. $Criteria->setSearchString($sender->getText());
  152. $items= LMediaManagerCore :: queryRecords($Criteria->build());
  153. #$r= $this->Core->getMediaList("search", $sender->getText());
  154.  
  155. $this->setViewstate("Records", $items);
  156. $this->SearchGrid->DataSource= $items;
  157. $this->SearchGrid->CurrentPageIndex= 0;
  158. $this->SearchGrid->dataBind();
  159. }
  160.  
  161. public function changePage($sender, $param)
  162. {
  163. #echo $param->NewPageIndex;
  164. $this->SearchGrid->CurrentPageIndex= $param->NewPageIndex;
  165. #$this->SearchGrid->CurrentPageIndex= 1;
  166. $this->SearchGrid->DataSource= $this->getViewstate("Records");
  167. $this->SearchGrid->dataBind();
  168. #$this->prepareData();
  169. }
  170.  
  171. }
  172. ?>

Documentation generated on Tue, 20 Jun 2006 05:15:17 +0200 by phpDocumentor 1.3.0RC4