The followings are the available columns in table 'commissioning_body_service':
Inheritance: extends BaseActiveRecordVersioned
 /**
  * @covers CommissioningBodyService::getCorrespondenceName()
  */
 public function testgetCorrespondenceAddress_withstatic()
 {
     $cbs_name = 'Test Name';
     $cbs_type_name = 'CBS Type Test Name';
     $cbs_type = new CommissioningBodyServiceType();
     $cbs_type->correspondence_name = $cbs_type_name;
     $cbs = new CommissioningBodyService();
     $cbs->name = $cbs_name;
     $cbs->type = $cbs_type;
     $this->assertEquals(array($cbs_name, $cbs_type_name), $cbs->getCorrespondenceName(), 'Correspondence Name should have type name appended when available in the CBS type');
 }
 /**
  * Search the local authorities and return both their address and the address of their social security department
  *
  * @param $term
  */
 public function actionAutoComplete($term)
 {
     $crit = new \CDbCriteria();
     // NOTE: have commented out the address eager loading here due to column ambiguity issues with the relation definitions.
     // need to investigate if this can be solved with the cunning use of scopes on the Contact model or not.
     $crit->with = array('contact' => array('alias' => 'service_contact'), 'commissioning_body', 'commissioning_body.contact', 'type' => array('alias' => 'service_type'), 'commissioning_body.type' => array('alias' => 'body_type'));
     $crit->compare('LOWER(t.name)', strtolower($term), true);
     $crit->compare('LOWER(commissioning_body.name)', strtolower($term), true, 'OR');
     $crit->addColumnCondition(array('service_type.shortname' => 'SSD'));
     $crit->addColumnCondition(array('body_type.shortname' => 'LA'));
     $crit->order = 'commissioning_body.name, t.name';
     $results = array();
     $found_bodies = array();
     foreach (\CommissioningBodyService::model()->findAll($crit) as $cbs) {
         $body = $cbs->commissioning_body;
         $found_bodies[] = $body->id;
         $results[] = array('id' => 'service' . $cbs->id, 'value' => $cbs->name . " ({$body->name})", 'service' => array('id' => $cbs->id, 'name' => $cbs->name, 'address' => $cbs->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $cbs->contact->primary_phone), 'body' => array('id' => $body->id, 'name' => $body->name, 'address' => $body->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $body->contact->primary_phone));
     }
     $body_crit = new \CDbCriteria();
     $body_crit->with = array('type', 'contact', 'contact.correspondAddress');
     $body_crit->compare('LOWER(t.name)', strtolower($term), true);
     $body_crit->addNotInCondition('t.id', $found_bodies);
     $body_crit->addColumnCondition(array('type.shortname' => 'LA'));
     foreach (\CommissioningBody::model()->findAll($body_crit) as $body) {
         $results[] = array('id' => 'body' . $body->id, 'value' => $body->name, 'body' => array('id' => $body->id, 'name' => $body->name, 'address' => $body->getLetterAddress(array('delimiter' => ",\n")), 'telephone' => $body->contact->primary_phone));
     }
     echo json_encode($results);
 }
 public function resourceToModel($res, $cb)
 {
     $cb->code = $res->code;
     $cb->name = $res->name;
     // Hard-coded for now
     $type = \CommissioningBodyType::model()->findByAttributes(array('shortname' => 'CCG'));
     if (!$type) {
         throw new \Exception("Failed to find commissioning body type 'CCG'");
     }
     $cb->commissioning_body_type_id = $type->id;
     $this->saveModel($cb);
     if ($res->address) {
         if (!($address = $cb->contact->address)) {
             $address = new \Address();
             $address->contact_id = $cb->contact->id;
         }
         $res->address->toModel($address);
         $this->saveModel($address);
     }
     // Associate with any services already in the db
     $crit = new \CDbCriteria();
     $crit->compare('code', $res->code);
     \CommissioningBodyService::model()->updateAll(array('commissioning_body_id' => $cb->id), $crit);
 }
 public function actionVerifyDeleteCommissioningBodyServiceTypes()
 {
     $criteria = new CDbCriteria();
     $criteria->addInCondition('commissioning_body_service_type_id', @$_POST['commissioning_body_service_type']);
     if (CommissioningBodyService::model()->find($criteria)) {
         echo "0";
     } else {
         echo "1";
     }
 }
<div class="box admin">
	<h2>Commissioning body services</h2>
	<form id="admin_commissioning_body_services">
		<table class="grid">
			<thead>
				<tr>
					<th><input type="checkbox" id="checkall" class="commissioning_body_services" /></th>
					<th>Code</th>
					<th>Name</th>
					<th>Type</th>
					<th>Commissioning body</th>
				</tr>
			</thead>
			<tbody>
				<?php 
foreach (CommissioningBodyService::model()->findAll(array('order' => 'name asc')) as $i => $cbs) {
    ?>
					<tr class="clickable" data-id="<?php 
    echo $cbs->id;
    ?>
" data-uri="admin/editCommissioningBodyService?commissioning_body_service_id=<?php 
    echo $cbs->id;
    ?>
">
						<td><input type="checkbox" name="commissioning_body_service[]" value="<?php 
    echo $cbs->id;
    ?>
" class="wards" /></td>
						<td><?php 
    echo $cbs->code;
    ?>
					<th>Commissioning body</th>
				</tr>
			</thead>
			<tbody>
				<?php 
$criteria = new CDbCriteria();
$criteria->with = array('commissioning_body');
$criteria->order = 't.name asc';
if (isset($commissioning_bt)) {
    $criteria->addColumnCondition(array('commissioning_body.commissioning_body_type_id' => $commissioning_bt->id));
    $url_query = 'commissioning_body_type_id=' . $commissioning_bt->id;
}
if (isset($service_type)) {
    $url_query .= '&service_type_id=' . $service_type->id . '&return_url=' . $return_url;
}
foreach (CommissioningBodyService::model()->findAll($criteria) as $i => $cbs) {
    ?>
					<tr class="clickable" data-id="<?php 
    echo $cbs->id;
    ?>
" data-uri="<?php 
    echo $base_data_url;
    ?>
editCommissioningBodyService?commissioning_body_service_id=<?php 
    echo $cbs->id;
    if (isset($data["returnUrl"])) {
        echo "&return_url=" . $data["returnUrl"];
    }
    ?>
">
						<td><input type="checkbox" name="commissioning_body_service[]" value="<?php