Exemple #1
0
 static function buildingOptions()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'building_id';
     $model = Building::model()->findAll();
     $buildings = array('' => '请选择相应楼栋');
     foreach ($model as $row) {
         $buildings[$row->building_id] = $row->building_id . '号';
     }
     return $buildings;
 }
 /**
  * Saves buildings. First all will be deleted and then the new or earlier existing ones will
  * be added again. This prevents a need for comparison.
  */
 public function actionBuildingSave($kohteetString, $imageid, $cd, $id, $addTo = false)
 {
     // if we are not adding to the previous values, but instead are replacing
     if (!$addTo) {
         // clearing out all the 'kohteet' for the image
         Building::model()->deleteByPk($imageid);
     }
     // getting rid of spaces in the inputstring
     $kohteetString = str_replace(' ', '', $kohteetString);
     // splits the inputted string into an array, so each building can be handled on it's own
     $kohteetArray = explode(',', $kohteetString);
     // this repeated for the kohteetArray, so that every building is it's own row in the kohteet table
     foreach ($kohteetArray as $kohde) {
         $saari = preg_replace('/[0-9k-z]/', '', $kohde);
         $rakennus = preg_replace('/[^0-9k-z]/', '', $kohde);
         // converting saari letter to uppercase
         $saari = strtolower($saari);
         if (strlen($saari) < 1) {
             continue;
         }
         // if we are adding, checks the database if the building&image combination is already there, will not add a duplicate
         if ($addTo) {
             $duplicateCriteria = new CDbCriteria();
             $duplicateCriteria->condition = 'cdno=:cdno';
             $duplicateCriteria->addCondition('idno=:idno');
             $duplicateCriteria->addCondition('saari=:saari');
             $duplicateCriteria->addCondition('rakennus=:rakennus');
             $duplicateCriteria->params = array(':cdno' => $cd, ':idno' => $id, ':saari' => $saari, ':rakennus' => $rakennus);
             // if a it's already found in the database, will continue; to the the next kohde
             if (Building::model()->find($duplicateCriteria)) {
                 continue;
             }
         }
         $newKohde = new Building();
         $newKohde->cdno = $cd;
         $newKohde->idno = $id;
         $newKohde->saari = $saari;
         $newKohde->rakennus = $rakennus;
         $newKohde->fk = $imageid;
         $newKohde->save();
         unset($newKohde);
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  */
 public function loadModel()
 {
     if ($this->_model === null) {
         if (isset($_GET['id'])) {
             $this->_model = Building::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
 public function actionGetDorms()
 {
     if (!isset($_POST['building_id'])) {
         return;
     }
     $building_id = $_POST['building_id'];
     $dorms = Building::model()->findByPk($building_id)->dorms;
     $dorms = CHtml::listData($dorms, 'dorm_id', 'dorm_name');
     $htmlData = CHtml::tag('option', array('selected' => 'selected', 'value' => ''), '请选择宿舍');
     foreach ($dorms as $value => $key) {
         $htmlData .= Chtml::tag('option', array('value' => $value), Chtml::encode($key));
     }
     echo json_encode(array('htmlData' => $htmlData));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Building the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Building::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
<?php

$data = $dataProvider;
$talolista = $this->actionBuildingList(Building::model()->findAllByPk($data->imageid));
?>

<div class="metadatabox" id="metadatabox">	
	
	<table id="metadatatable">
	
		<tr>
			<td><?php 
echo CHtml::activeLabel($data, 'kohde', array('class' => 'metadatawide'));
?>
</td>
			<td><?php 
echo $talolista;
?>
</td>
		</tr>
		<tr>
			<td><?php 
echo CHtml::activeLabel($data, 'valokuvaaja', array('class' => 'metadatawide'));
?>
</td>
			<td><?php 
echo CHtml::value($data, 'valokuvaaja');
?>
</td>
		</tr>
		<tr>