ztabularinputmanager This class will help anyone that have to collect a tabular input

This class is a master class for a Tabular input manager.

It has been tought to be used in scenarios where you have a one-to-many relationship.

The interface should present an interface for collect the data of the one, and zero, one or many rows for collect the many.

In the hypothesis that we have to insert a ClassRoom with many Students, we will create a StudentManager by extending Tabular input manager:

<?php

class StudentManager extends TabularInputManager
{

	protected $class='Student';
	
	public function getItems()
	{
		if (is_array($this->_items))
			return ($this->_items);
		else 
			return array(
				'n0'=>new Student,
			);
	}


	public function deleteOldItems($model, $itemsPk)
	{
		$criteria=new CDbCriteria;
		$criteria->addNotInCondition('id', $itemsPk);
		$criteria->addCondition("class_id= {$model->primaryKey}");

		Student::model()->deleteAll($criteria);	
	}
	

	public static function load($model)
	{
		$return= new StudentManager;
		foreach ($model->students as $item)
			$return->_items[$item->primaryKey]=$item;
		return $return;
	}
	
	
	public function setUnsafeAttribute($item, $model)
	{
		$item->class_id=$model->primaryKey;

	}


}


In this class we implement all methods needed for manage the primary keys of the students, for load the student of a class, for delete students.

The typical controller code for use this manager is:

[php]
	/**
	 * Update a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new ClassRoom;
		$studentManager=new studentManager();

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['ClassRoom']))
		{
			$model->attributes=$_POST['ClassR
19 0
34 followers
2 920 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: zaccaria
Created on: Oct 18, 2010
Last updated: 11 years ago

Downloads

show all

Related Extensions