Commits

christiansalazar committed d2f130b

EYuiRelation demo adjustments

Comments (0)

Files changed (7)

protected/controllers/ExampleController.php

 	
 	public function actionEYuiRelation() 
 	{ 
-		$model = TblCompany::model()->findByPk(1);
+		$model = TblCompany::model()->findByPk(10);
 	
 		$this->render('eyuirelation',array('model'=>$model)); 
 	}	

protected/data/eyuirelation-demo.sql

+drop table tbl_company;
+drop table tbl_job;
+drop table tbl_department;
+drop table tbl_companyjob;
+drop table tbl_companydepartment;
+
+/* X relation a company */
+
 CREATE TABLE tbl_company (
     id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
     name VARCHAR(128) NOT NULL
 );
+INSERT INTO tbl_company (id,name) VALUES (10, 'software & designers co');
+INSERT INTO tbl_company (id,name) VALUES (20, 'website masters co');
+
+/* Y relation #1, a job */
 
 CREATE TABLE tbl_job (
     id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-	company_id INTEGER NOT NULL,
     name VARCHAR(128) NOT NULL
 );
+INSERT INTO tbl_job (name) VALUES ('analist');
+INSERT INTO tbl_job (name) VALUES ('programmer');
+INSERT INTO tbl_job (name) VALUES ('template creator');
+INSERT INTO tbl_job (name) VALUES ('html designer');
+
+/* Y relation #2, a department */
 
 CREATE TABLE tbl_department (
     id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-	company_id INTEGER NOT NULL,
     name VARCHAR(128) NOT NULL
 );
+INSERT INTO tbl_department (name) VALUES ('administration');
+INSERT INTO tbl_department (name) VALUES ('programming');
+INSERT INTO tbl_department (name) VALUES ('reception');
+INSERT INTO tbl_department (name) VALUES ('graphics');
 
-INSERT INTO tbl_company (id,name) VALUES (1, 'software & designers co');
-INSERT INTO tbl_company (id,name) VALUES (2, 'website masters co');
-
-INSERT INTO tbl_job (company_id,name) VALUES (1, 'analist');
-INSERT INTO tbl_job (company_id,name) VALUES (1, 'programmer');
-
-INSERT INTO tbl_job (company_id,name) VALUES (2, 'template creator');
-INSERT INTO tbl_job (company_id,name) VALUES (2, 'html designer');
-
-INSERT INTO tbl_department (company_id,name) VALUES (1, 'administration');
-INSERT INTO tbl_department (company_id,name) VALUES (1, 'programming');
-
-INSERT INTO tbl_department (company_id,name) VALUES (2, 'reception');
-INSERT INTO tbl_department (company_id,name) VALUES (2, 'graphics');
+/* XY relation (or AB relation) */
 
 CREATE TABLE tbl_companyjob (
     id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-	job_id INTEGER NOT NULL,
-	company_id INTEGER NOT NULL
+	company_id INTEGER NOT NULL,
+	job_id INTEGER NOT NULL
 );
 
 CREATE TABLE tbl_companydepartment (
     id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-	department_id INTEGER NOT NULL,
-	company_id INTEGER NOT NULL
+	company_id INTEGER NOT NULL,
+	department_id INTEGER NOT NULL
 );

protected/data/testdrive.db

Binary file modified.

protected/models/TblCompanyJob.php

 	implements EYuiRelationIRelation
 {
 	public function eyuirelation_insert($widgetid,$masterPrimaryId, $optionPrimaryId){
-		// $masterPrimaryId is: company_id
-		// $optionPrimaryId is: job_id
+		// $masterPrimaryId is: company_id, the X part
+		// $optionPrimaryId is: job_id, the Y part
+		// and TblCompanyJob is : the XY relationship.
+		//
 		$inst = new TblCompanyJob;
 		$inst->company_id = $masterPrimaryId;
 		$inst->job_id = $optionPrimaryId;

protected/models/TblDepartment.php

 	implements EYuiRelationIOptions
 {
 	public function eyuirelation_listData($widgetid,$primaryid) {
-		return CHtml::listData(
-		self::model()->findAllByAttributes(array('company_id'=>$primaryid)),'id','name');
+		return CHtml::listData(self::model()->findAll(),'id','name');
 	}
 
 

protected/models/TblJob.php

  *
  * The followings are the available columns in table 'tbl_job':
  * @property integer $id
- * @property integer $company_id
  * @property string $name
  */
 class TblJob extends CActiveRecord
 	implements EYuiRelationIOptions
 {
 	public function eyuirelation_listData($widgetid,$primaryid) {
-		return CHtml::listData(
-		self::model()->findAllByAttributes(array('company_id'=>$primaryid)),'id','name');
+		return CHtml::listData(self::model()->findAll(),'id','name');
 	}
 
 	/**

protected/views/example/eyuirelation.php

 <h1>EYuiRelation</h1>
 <p>EYuiRelation handles a relationship between models in a visual way. In this example, a company
 will have Departments and Jobs.</p>
-<p style='background-color: yellow;'>For demo pruposes the selected model will be a company with ID=1 stablished in actionEYuiRelation() </p>
+<p style='background-color: yellow;'>For demo pruposes the selected model will be a company with ID=10 stablished in actionEYuiRelation() </p>
 
 	<?php 
 		$this->widget('ext.eyui.EYuiRelation'
 			,array(
-				'id'=>'departmentrelationship',
+				'debug'=>true,
+				'id'=>'jobrelationship',
 				'onError'=>'function(e){ $("#mylogger").html(e.responseText); }',
 				'model'=>$model,
-				'title'=>'Departments:<hr/>',
-				'optionsClassName'=>'TblDepartment',
-				'relationClassName'=>'TblCompanyDepartment',
-				'htmlOptions'=>array('style'=>'width: 300px; margin-bottom: 10px; margin-right: 10px; float: left;'),
+				'title'=>'Jobs:<hr/>',
+				'optionsClassName'=>'TblJob',
+				'relationClassName'=>'TblCompanyJob',
+				'htmlOptions'=>array('style'=>'width: 300px; float: left; margin-right: 10px;'),
 			)
 		);
-	?>
-	
+	?>	
 	<?php 
 		$this->widget('ext.eyui.EYuiRelation'
 			,array(
-				'id'=>'jobrelationship',
+				'debug'=>true,
+				'id'=>'departmentrelationship',
 				'onError'=>'function(e){ $("#mylogger").html(e.responseText); }',
 				'model'=>$model,
-				'title'=>'Jobs:<hr/>',
-				'optionsClassName'=>'TblJob',
-				'relationClassName'=>'TblCompanyJob',
+				'title'=>'Departments:<hr/>',
+				'optionsClassName'=>'TblDepartment',
+				'relationClassName'=>'TblCompanyDepartment',
 				'htmlOptions'=>array('style'=>'width: 300px; float: left;'),
 			)
 		);