Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ 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: 601 $  $Date: 2007-02-24 23:49:30 +0100 (Sa, 24 Feb 2007) $
  11.  * @package Phundament.Packages
  12.  * @subpackage LMediaManager
  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.         parent :: onInit($param);
  34.         $this->Corenew LMediaManagerCore;
  35.     }
  36.  
  37.     /**
  38.      * @return array selected items in both lists
  39.      */
  40.     public function getSelection()
  41.     {
  42.         $returnarray ();
  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($arraynull)
  76.     {
  77.         $currentSelection$this->getSelection();
  78.         if ($array === null)
  79.             $selection$currentSelection;
  80.         else
  81.             $selectionarray_merge($array$currentSelection);
  82.  
  83.         // parse data for later usage
  84.         $idsnull;
  85.         if (is_array($selection))
  86.             foreach ($selection AS $s)
  87.             {
  88.                 $ids[]$s['MetaRecordId'];
  89.                 if (isset ($s['Description']))
  90.                     $info[$s['MetaRecordId']]array (
  91.                         $s['Description'],
  92.                         $s['Rank']
  93.                     );
  94.             }
  95.         else
  96.         {
  97.             $idsarray ();
  98.         }
  99.         if ($ids == null)
  100.             return;
  101.  
  102.         // query data
  103.         $Criterianew LMediaCriteria;
  104.         $Criteria->setRecordIds($ids);
  105.         $itemsLMediaManagerCore :: queryRecords($Criteria->build());
  106.  
  107.         // fill grid
  108.         $this->SelectedGrid->DataSource$items;
  109.         $this->SelectedGrid->CurrentPageIndex0;
  110.         $this->SelectedGrid->dataBind();
  111.  
  112.         // set checkbox & set values in selected grid
  113.         $selected_items$this->SelectedGrid->getItems();
  114.         foreach ($selected_items AS $item)
  115.         {
  116.             $item->Cells[0]->Select->setChecked(true);
  117.             // TODO
  118.             if (isset ($info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")]))
  119.             {
  120.                 $item->Cells[3]->Description->Text$info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][0];
  121.                 $item->Cells[4]->Rank->Text$info[$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")][1];
  122.             }
  123.         }
  124.         // unset all checkboxes in search grid
  125.         $search_items$this->SearchGrid->getItems();
  126.         foreach ($search_items AS $item)
  127.         {
  128.             foreach ($ids AS $selectedId)
  129.             {
  130.                 #echo $selectedId." == ".$item->Cells[0]->Select->getSubProperty("Attributes.MediaId")."<br/>";
  131.                 if ($selectedId == $item->Cells[0]->Select->getSubProperty("Attributes.MediaId"))
  132.                 {
  133.                     #$item->Cells[0]->Select->setChecked(true);
  134.                     $item->Cells[0]->Select->setVisible(false);
  135.                     $item->Cells[0]->Controls["selected";
  136.                     break;
  137.                 }
  138.                 else
  139.                     $item->Cells[0]->Select->setChecked(false);
  140.             }
  141.         }
  142.  
  143.     }
  144.  
  145.     public function applyClicked($sender$param)
  146.     {
  147.         $this->setSelection();
  148.     }
  149.  
  150.     public function searchClicked($sender$param)
  151.     {
  152.         $Criterianew LMediaCriteria;
  153.         $Criteria->setSearchString($sender->Parent->findControl("SearchString")->getText());
  154.         $itemsLMediaManagerCore :: queryRecords($Criteria->build());
  155.  
  156.         $this->setViewstate("Records"$items);
  157.         $this->SearchGrid->DataSource$items;
  158.         $this->SearchGrid->CurrentPageIndex0;
  159.         $this->SearchGrid->dataBind();
  160.  
  161.         $this->setSelection();
  162.     }
  163.  
  164.     public function searchText($sender$param)
  165.     {
  166.         $Criterianew LMediaCriteria;
  167.         $Criteria->setSearchString($sender->getText());
  168.         $itemsLMediaManagerCore :: queryRecords($Criteria->build());
  169.  
  170.         $this->setViewstate("Records"$items);
  171.         $this->SearchGrid->DataSource$items;
  172.         $this->SearchGrid->CurrentPageIndex0;
  173.         $this->SearchGrid->dataBind();
  174.  
  175.         $this->setSelection();
  176.     }
  177.  
  178.     public function changePage($sender$param)
  179.     {
  180.         $this->setSelection()// TODO - two times setSelection
  181.  
  182.         $this->SearchGrid->CurrentPageIndex$param->NewPageIndex;
  183.         $this->SearchGrid->DataSource$this->getViewstate("Records");
  184.         $this->SearchGrid->dataBind();
  185.  
  186.         $this->setSelection()// TODO - two times setSelection
  187.     }
  188.  
  189. }
  190. ?>

Documentation generated on Sun, 25 Feb 2007 16:11:00 +0100 by phpDocumentor 1.3.1