public function actionSearch() { if (Yii::app()->request->isAjaxRequest) { $criteria = new CDbCriteria(); if (isset($_GET['term']) && strlen($term = $_GET['term']) > 0) { $criteria->addCondition(array('LOWER(name) LIKE :term'), 'OR'); $params[':term'] = '%' . strtolower(strtr($term, array('%' => '\\%'))) . '%'; } $criteria->order = 'name'; $criteria->select = 'id, name'; $criteria->params = $params; $results = OphTrOperationnote_PostopDrug::model()->active()->findAll($criteria); $return = array(); foreach ($results as $resultRow) { $return[] = array('label' => $resultRow->name, 'value' => $resultRow->name, 'id' => $resultRow->id); } echo CJSON::encode($return); } }
public function getName() { return OphTrOperationnote_PostopDrug::model()->findByPk($this->drug_id)->name; }
<form id="admin_drugs"> <input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?> " /> <table class="grid"> <thead> <tr> <th><input type="checkbox" name="selectall" id="selectall" /></th> <th>Name</th> <th>Active</th> </tr> </thead> <tbody> <?php foreach (OphTrOperationnote_PostopDrug::model()->findAll(array('order' => 'display_order asc')) as $i => $drug) { ?> <tr class="clickable" data-id="<?php echo $drug->id; ?> " data-uri="OphTrOperationnote/admin/editPostOpDrug/<?php echo $drug->id; ?> "> <td><input type="checkbox" name="drugs[]" value="<?php echo $drug->id; ?> " /></td> <td><?php echo $drug->active ? $drug->name : '<s>' . $drug->name . '</s>'; ?>
/** * Return the post op drugs for the current site and subspecialty. * * @param bool $default * * @return OphTrOperationnote_PostopDrug[] */ protected function getPostOpDrugsBySiteAndSubspecialty($default = false, $include_ids = null) { $criteria = new CDbCriteria(); $criteria->addCondition('subspecialty_id = :subspecialtyId and site_id = :siteId'); $criteria->params[':subspecialtyId'] = $this->firm->getSubspecialtyID(); $criteria->params[':siteId'] = Yii::app()->session['selected_site_id']; if ($default) { $criteria->addCondition('siteSubspecialtyAssignments.default = :one'); $criteria->params[':one'] = 1; } $criteria->order = 'name asc'; return OphTrOperationnote_PostopDrug::model()->with(array('siteSubspecialtyAssignments' => array('joinType' => 'JOIN')))->activeOrPk($include_ids)->findAll($criteria); }
/** * Reorder post op drugs. * * @throws Exception */ public function actionSortPostOpDrugs() { if (!empty($_POST['order'])) { foreach ($_POST['order'] as $i => $id) { if ($drug = OphTrOperationnote_PostopDrug::model()->findByPk($id)) { $drug->display_order = $i + 1; if (!$drug->save()) { throw new Exception('Unable to save drug: ' . print_r($drug->getErrors(), true)); } } } } }