summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php
blob: d4f4c8e9c9979d6a31073afa74c8292f36bd52b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

class Sample3 extends TPage
{
	protected function getProducts()
	{
		return array(
			array('id'=>'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true),
			array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true),
			array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true),
			array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false),
			array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true),
			array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false),
			array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false),
			array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true),
			array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true),
			array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false),
		);
	}

	protected function getCategories()
	{
		return array(
			array('id'=>'CAT001','name'=>'Accessories'),
			array('id'=>'CAT002','name'=>'Input Devices'),
			array('id'=>'CAT003','name'=>'Drives'),
			array('id'=>'CAT004','name'=>'Barebone'),
		);
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		if(!$this->IsPostBack)
		{
			$this->Repeater->DataSource=$this->Products;
			$this->Repeater->dataBind();
		}
	}

	public function repeaterDataBound($sender,$param)
	{
		$item=$param->Item;
		if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
		{
			$item->ProductCategory->DataSource=$this->Categories;
			$item->ProductCategory->DataTextField='name';
			$item->ProductCategory->DataValueField='id';
			$item->ProductCategory->dataBind();
			$item->ProductCategory->SelectedValue=$item->DataItem['category'];
		}
	}

	public function saveInput($sender,$param)
	{
		if($this->IsValid)
		{
			$index=0;
			$products=$this->Products;
			$data=array();
			foreach($this->Repeater->Items as $item)
			{
				$item=array(
					'id'=>$products[$index]['id'],
					'name'=>$item->ProductName->Text,
					'category'=>$item->ProductCategory->SelectedItem->Text,
					'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text),
					'imported'=>$item->ProductImported->Checked,
				);
				$data[]=$item;
				$index++;
			}
			$this->Repeater2->DataSource=$data;
			$this->Repeater2->dataBind();
		}
	}
}

?>