- <?php
-
-
- /**
- * class file.
- *
- * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
- * @copyright 2005, diemeisterei GmbH. All rights reserved.
- * @author $Author: schmunk $
- * @version $Revision: 254 $ $Date: 2006-06-06 01:53:39 +0200 (Di, 06 Jun 2006) $
- * @package Lithron.LMediaManager
- * @subpackage WebControls
- */
-
- /**
- * Implements IMetaData. (TODO)
- *
- * Displays a selection for media files
- *
- * @package System.Web.UI.WebControls
- * @subpackage MetaData
- */
-
- class LMediaSelection extends TTemplateControl implements IMetaData
- {
- private $Core;
-
- /**
- * Prepares the core
- */
- public function onInit($param)
- {
- $this->Core= new LMediaManagerCore;
- parent :: onInit($param);
- }
-
- /**
- * @return array selected items in both lists
- */
- public function getSelection()
- {
- $return= array ();
-
- // get selection from search
- $items= $this->SearchGrid->getItems();
- foreach ($items AS $item)
- {
- if ($item->Cells[0]->Select->getChecked())
- {
- $r['MetaRecordId']= $item->Cells[0]->Select->Attributes->itemAt("MediaId");
- $r['Description']= $item->Cells[2]->MediaDescription->Text;
- $r['Rank']= "z";
- $return[]= $r;
- }
- }
-
- // get selection & data from selected grid
- $items= $this->SelectedGrid->getItems();
- foreach ($items AS $item)
- {
- if ($item->Cells[0]->Select->getChecked())
- {
- $r['MetaRecordId']= $item->Cells[0]->Select->Attributes->itemAt("MediaId");
- $r['Description']= $item->Cells[3]->Description->Text;
- $r['Rank']= $item->Cells[4]->Rank->Text;
- $return[]= $r;
- }
- }
- return $return;
- }
-
- /**
- * @param array sets selection from database and current selection
- */
- public function setSelection($array= null)
- {
- $currentSelection= $this->getSelection();
- if ($array === null)
- $selection= $currentSelection;
- else
- $selection= array_merge($array, $currentSelection);
-
- // parse data for later usage
- if (is_array($selection))
- foreach ($selection AS $s)
- {
- $ids[]= $s['MetaRecordId'];
- if (isset ($s['Description']))
- $info[$s['MetaRecordId']]= array (
- $s['Description'],
- $s['Rank']
- );
- }
- else
- {
- $ids= array ();
- }
-
- // query data
- $Criteria= new LMediaCriteria;
- $Criteria->setRecordIds($ids);
- $items= LMediaManagerCore :: queryRecords($Criteria->build());
-
- // fill grid
- $this->SelectedGrid->DataSource= $items;
- $this->SelectedGrid->CurrentPageIndex= 0;
- $this->SelectedGrid->dataBind();
-
- // set checkbox & set values in selected grid
- $selected_items= $this->SelectedGrid->getItems();
- foreach ($selected_items AS $item)
- {
- $item->Cells[0]->Select->setChecked(true);
- // TODO
- if (isset ($info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")]))
- {
- $item->Cells[3]->Description->Text= $info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][0];
- $item->Cells[4]->Rank->Text= $info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][1];
- }
- }
- // unset all checkboxes in search grid
- $search_items= $this->SearchGrid->getItems();
- foreach ($search_items AS $item)
- {
- $item->Cells[0]->Select->setChecked(false);
- }
-
- }
-
- public function applyClicked($sender, $param)
- {
- $this->setSelection();
- }
-
- public function searchClicked($sender, $param)
- {
- $Criteria= new LMediaCriteria;
- $Criteria->setSearchString($sender->Parent->findControl("SearchString")->getText());
- $items= LMediaManagerCore :: queryRecords($Criteria->build());
- #$r= $this->Core->getMediaList("search", $sender->Parent->findControl("SearchString")->getText());
-
- $this->setViewstate("Records", $items);
- $this->SearchGrid->DataSource= $items;
- $this->SearchGrid->CurrentPageIndex= 0;
- $this->SearchGrid->dataBind();
- }
-
- public function searchText($sender, $param)
- {
- $Criteria= new LMediaCriteria;
- $Criteria->setSearchString($sender->getText());
- $items= LMediaManagerCore :: queryRecords($Criteria->build());
- #$r= $this->Core->getMediaList("search", $sender->getText());
-
- $this->setViewstate("Records", $items);
- $this->SearchGrid->DataSource= $items;
- $this->SearchGrid->CurrentPageIndex= 0;
- $this->SearchGrid->dataBind();
- }
-
- public function changePage($sender, $param)
- {
- #echo $param->NewPageIndex;
- $this->SearchGrid->CurrentPageIndex= $param->NewPageIndex;
- #$this->SearchGrid->CurrentPageIndex= 1;
- $this->SearchGrid->DataSource= $this->getViewstate("Records");
- $this->SearchGrid->dataBind();
- #$this->prepareData();
- }
-
- }
- ?>