public function getChildren() { if (!$this->_children) { $category = new self(); $this->_children = $category->findAll(array('parent_id' => $this->getId()), 'pos ASC'); } return $this->_children; }
public function getSubaccounts() { if (!$this->_subaccounts) { $subaccount = new self(); $this->_subaccounts = $subaccount->findAll(array('parent_id' => $this->getId())); } return $this->_subaccounts; }
public function setQuestionAttribute($iQuestionID, $sAttributeName, $sValue) { $oModel = new self(); $aResult = $oModel->findAll('attribute=:attributeName and qid=:questionID', array(':attributeName' => $sAttributeName, ':questionID' => $iQuestionID)); if (!empty($aResult)) { $oModel->updateAll(array('value' => $sValue), 'attribute=:attributeName and qid=:questionID', array(':attributeName' => $sAttributeName, ':questionID' => $iQuestionID)); } else { $oModel = new self(); $oModel->attribute = $sAttributeName; $oModel->value = $sValue; $oModel->qid = $iQuestionID; $oModel->save(); } return Yii::app()->db->createCommand()->select()->from($this->tableName())->where(array('and', 'qid=:qid'))->bindParam(":qid", $qid)->order('qaid asc')->query(); }
/** * @author chenliujin <*****@*****.**> * @since 2016-09-07 */ public static function get_transportation_zone($transportation_id, $delivery_country) { $transportation_zone = new self(); $transportation_zone_list = $transportation_zone->findAll(array('transportation_id' => $transportation_id)); if (!$transportation_zone_list) { throw new \Exception('Setting Error: Transportation Zone Not Exists'); } foreach ($transportation_zone_list as $transportation_zone) { if ($transportation_zone->countries == 'ALL') { return $transportation_zone; } elseif (in_array($delivery_country, explode(',', $transportation_zone->countries))) { return $transportation_zone; } } }
/** * 返回当前节点的后代 * * @param bool $self 是否包含当前节点 * @param string $direction 排序 * @param bool $directChildrenOnly 只包含相邻的下级节点 * @param bool $leavesOnly 只包含叶子节点 * @param int $limit 要获取的记录条数 * @return MPTT[] */ public function descendants($self = false, $direction = 'ASC', $directChildrenOnly = false, $leavesOnly = false, $limit = 0) { $left_operator = $self ? '>=' : '>'; $right_operator = $self ? '<=' : '<'; $query = new self(); $query->where($this->_leftColumn, $left_operator, $this->left())->where($this->_rightColumn, $right_operator, $this->right())->where($this->_scopeColumn, '=', $this->scope())->orderBy($this->_leftColumn, $direction); if ($directChildrenOnly) { if ($self) { $query->andWhereOpen()->where($this->_levelColumn, '=', $this->level())->orWhere($this->_levelColumn, '=', $this->level() + 1)->andWhereClose(); } else { $query->where($this->_levelColumn, '=', $this->level() + 1); } } if ($leavesOnly) { $query->where($this->_rightColumn, '=', $this->_leftColumn . ' + 1'); } if ($limit) { $query->limit($limit); } return $query->findAll(); }