protected function isOrderExists($id) { $this->_order = BaseActiveRecord::model($this->orderModel)->findByPk((int) $id); if ($this->_order) { return true; } return false; }
/** * Получение дерева экземпляров модели * @param mixed $addCriteria параметры запроса на получение данных * @param string $cacheKey ключ для кэширования данных */ public function getTree($addCriteria = array(), $cacheKey = null) { $cacheKey = $cacheKey == null ? $this->owner->tableName() : $cacheKey; if (isset(self::$_tree[$cacheKey])) { return self::$_tree[$cacheKey]; } $tree = array(); if (($cache = Yii::app()->{$this->cacheId}) !== null && ($val = $cache->get($cacheKey)) !== false) { $tree = $val; } else { $criteria = new CDbCriteria(); $criteria->order = $this->order; if ($this->with != null) { $criteria->with = $this->with; } $criteria->mergeWith($addCriteria); $model = null; if ($this->owner instanceof BaseActiveRecord) { $model = BaseActiveRecord::model(get_class($this->owner)); } else { $model = CActiveRecord::model(get_class($this->owner)); } $items = $model->findAll($criteria); $child = array(); $countIntems = count($items); $idParentField = $this->idParentField; for ($i = 0; $i < $countIntems; $i++) { $item = $items[$i]; $id = $item->getPrimaryKey(); $idParent = $item->{$idParentField}; if ($idParent !== null) { $child[$idParent][] = $item; } } $className = get_class($model); $tree = new $className(); for ($i = 0; $i < $countIntems; $i++) { $item = $items[$i]; $id = $item->getPrimaryKey(); if (isset($child[$id])) { $countChild = count($child[$id]); for ($k = 0; $k < $countChild; $k++) { $child[$id][$k]->setParent($item); } $item->setChild($child[$id]); } if ($item->{$idParentField} === null) { $tree->addChild($item); } } if ($cache !== null) { $cacheKeys = $cache->get($this->getCacheKeysKey()); if ($cacheKeys === false) { $cacheKeys = array(); } if (!isset($cacheKeys[$this->owner->tableName()])) { $cacheKeys[$this->owner->tableName()] = array(); } if (!in_array($cacheKey, $cacheKeys[$this->owner->tableName()])) { $cacheKeys[$this->owner->tableName()][] = $cacheKey; } $cache->set($cacheKey, $tree, $this->cacheExpire); //кешируем ключи, чтобы в последствии была возможность очистить кеш при изменении модели $cache->set($this->getCacheKeysKey(), $cacheKeys, $this->cacheExpire); } } self::$_tree[$cacheKey] = $tree; return $tree; }
/** * Returns the static model of the specified AR class. * * @return Referral the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
public function actionView($id) { $model = BaseActiveRecord::model('User')->findByPk($id); if ($model === null) { $this->throw404Error(); } $this->render('/view', array('model' => $model)); }
public function getOwnerModel() { if ($this->_ownerModel === false) { if ($this->id_object != null && $this->id_instance != null) { $commentsModule = Yii::app()->getModule('comments'); $this->_ownerModel = BaseActiveRecord::model($commentsModule->modelClassMap[$this->id_object])->findByPk($this->id_instance); } else { $this->_ownerModel = null; } } return $this->_ownerModel; }
private function loadOwnOfferByIdInvoice($id, $criteria = null) { $offer = null; if ($invoice = BaseActiveRecord::model('Invoice')->findByPk($id, $criteria)) { $offer = $invoice->offer; } return $offer; }
public function actionSetStatusApproveComment() { $result = array(); $idComment = (int) Yii::app()->request->getPost('idComment'); $comment = BaseActiveRecord::model('CommentYii')->findByPk($idComment); if ($comment != null && Yii::app()->user->checkAccess('approveComment', array('comment' => $comment))) { $comment->setApproved(); return $this->getSuccessResultData($comment); } return $this->getFailResultData($comment); }