PATH:
home
/
letacommog
/
letaweb
/
admin
/
models
/
subsite_models
<?php class BActiveRecord extends CActiveRecord { const BELONGS_TO='BBelongsToRelation'; //const HAS_ONE='CHasOneRelation'; //const HAS_MANY='CHasManyRelation'; //const MANY_MANY='CManyManyRelation'; //const STAT='CStatRelation'; public $maxId; public $siteObj; protected static $dba = null; public function BActiveRecord() { $this->siteObj = Yii::app()->site; } public function deleteAll($condition = '', $params = array()) { $builder = $this->getCommandBuilder(); $criteria = $builder->createCriteria($condition, $params); if (($this->hasAttribute('site_id'))) { $alias = $this->getTableAlias(false, false); $criteria->addCondition('site_id='.Yii::app()->site->model->id); } $command = $builder->createDeleteCommand($this->getTableSchema(), $criteria); return $command->execute(); } public function updateAll($attributes, $condition = '', $params = array()) { $builder = $this->getCommandBuilder(); $criteria = $builder->createCriteria($condition, $params); if (($this->hasAttribute('site_id'))) { //$alias = $this->getTableAlias(false, false); $criteria->addCondition('site_id='.Yii::app()->site->model->id); } $command = $builder->createUpdateCommand($this->getTableSchema(), $attributes, $criteria); return $command->execute(); } public function count($condition='',$params=array()) { $this->beforeCount(); $builder=$this->getCommandBuilder(); $criteria=$builder->createCriteria($condition,$params); if (($this->hasAttribute('site_id'))) { $alias = $this->getTableAlias(false, false); $criteria->addCondition($alias.'.site_id='.Yii::app()->site->model->id); } $this->applyScopes($criteria); if(empty($criteria->with)) return $builder->createCountCommand($this->getTableSchema(),$criteria)->queryScalar(); else { $finder=$this->getActiveFinder($criteria->with); return $finder->count($criteria); } } public function getDbConnection() { if (self::$dba !== null) { return self::$dba; } else { self::$dba = Yii::app()->dba; if (self::$dba instanceof CDbConnection) { self::$dba->setActive(true); return self::$dba; } else { throw new CDbException(Yii::t('yii', 'Active Record requires a "dba" CDbConnection application component.')); } } } /*public function primaryKey() { if (($this->hasAttribute('site_id') && $this->hasAttribute('inline_id_id'))) { echo "dfdfdsfs"; return array('site_id', 'inline_id'); } return parent::primaryKey(); }*/ public function getMaxInlineId() { $db = $this->getDbConnection(); $command = $db->createCommand()->select('max(inline_id)')->from($this->tableName()); if (($this->hasAttribute('site_id'))) { $command->where('site_id='.$this->siteObj->model->id); } return $command->queryScalar(); } public function getMaxId() { $db = $this->getDbConnection(); $maxId = $maxId = $db->createCommand()->select('max(id)')->from($this->tableName())->queryScalar(); return $maxId; } public function beforeSave() { $now = date('Y-m-d H:i:s'); if ($this->isNewRecord) { if (($this->hasAttribute('date_added'))) { $this->date_added = $now; } if (($this->hasAttribute('inline_id'))) { $db = $this->getDbConnection(); $maxId = $this->getMaxInlineId(); $this->inline_id = $maxId + 1; } } if (($this->hasAttribute('date_modified'))) { $this->date_modified = $now; } if (($this->hasAttribute('site_id'))) { $this->site_id = $this->siteObj->model->id; } return true; } public function defaultScope() { if (($this->hasAttribute('site_id'))) { $alias = $this->getTableAlias(false, false); return array('condition' => '`'.$alias.'`.'.'`site_id`='.$this->siteObj->model->id); } return array(); } public function getList() { $criteria = new CDbCriteria(); //criteria->compare('id',$this->id); //$criteria->compare('name',$this->name,true); return new CActiveDataProvider(get_class($this), array( 'criteria' => $criteria, 'pagination'=>false//array( // 'pageSize'=>0, //), )); } public function getPagedList($pageSize = 10, $start = 0,$order='') { $criteria = new CDbCriteria(); $criteria->order = $order; return new ActiveDataProvider(get_class($this), array( 'criteria' => $criteria, 'pagination' => array( 'pageSize' => $pageSize, 'start'=>$start, 'class' => 'Pagination', ), )); } public function getFormData() { $criteria = new CDbCriteria(); $criteria->compare('id', $this->id); return $this->find($criteria); } } class BBelongsToRelation extends CBelongsToRelation { public function mergeWith($criteria,$fromScope=false) { if($criteria instanceof CDbCriteria) $criteria=$criteria->toArray(); if($fromScope) { if(isset($criteria['condition']) && $this->on!==$criteria['condition']) { if($this->on==='') $this->on=$criteria['condition']; elseif($criteria['condition']!=='') $this->on="({$this->on}) AND ({$criteria['condition']})"; } unset($criteria['condition']); } parent::mergeWith($criteria); if(isset($criteria['joinType'])) $this->joinType=$criteria['joinType']; if(isset($criteria['on']) && $this->on!==$criteria['on']) { if($this->on==='') $this->on=$criteria['on']; elseif($criteria['on']!=='') $this->on="({$this->on}) AND ({$criteria['on']})"; } if(isset($criteria['with'])) $this->with=$criteria['with']; if(isset($criteria['alias'])) $this->alias=$criteria['alias']; if(isset($criteria['together'])) $this->together=$criteria['together']; //print_r($criteria); } }
[+]
..
[-] BTag.php
[edit]
[-] BActiveRecord.php
[edit]
[-] BModule.php
[edit]
[-] BPages.php
[edit]
[-] BComments.php
[edit]
[-] BNews_News_Category.php
[edit]
[-] BNewsModule.php
[edit]
[-] BAuthAssignment.php
[edit]
[-] BNewsCategory.php
[edit]
[-] BConfigurations.php
[edit]
[-] BPages_Elements.php
[edit]
[-] BNews_Comments.php
[edit]
[-] BNews_Categories.php
[edit]
[-] BUsers.php
[edit]
[-] BUserIdentity.php
[edit]
[-] BNews.php
[edit]
[-] BWebUser.php
[edit]
[+]
forms
[-] BColors.php
[edit]
[-] BSkins.php
[edit]
[-] BNews_Tag.php
[edit]
[-] BContributor_Invites.php
[edit]
[-] BContributor.php
[edit]