示例#1
0
 /**
  * Finds all active records with the specified primary keys.
  * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk
  * See {@link find()} for detailed explanation about $condition and $params.
  * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
  * @param mixed $condition query condition or criteria.
  * @param array $params parameters to be bound to an SQL statement.
  * @return array the records found. An empty array is returned if none is found.
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     // If we do not supply a condition or parameters, use our overwritten method
     if ($condition == '' && empty($params)) {
         $criteria = new CDbCriteria();
         $criteria->addCondition("t.id={$pk}");
         $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id={$pk})");
         return $this->query($criteria);
     }
     return parent::findByPk($pk, $conditions, $params);
 }
示例#2
0
 /**
  * Finds all active records with the specified primary keys.
  * Overloaded to support composite primary keys. For our content, we want to find the latest version of that primary key, defined as MAX(vid) WHERE id = pk
  * See {@link find()} for detailed explanation about $condition and $params.
  * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
  * @param mixed $condition query condition or criteria.
  * @param array $params parameters to be bound to an SQL statement.
  * @return array the records found. An empty array is returned if none is found.
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     // If we do not supply a condition or parameters, use our overwritten method
     if ($condition == '' && empty($params) && $pk != null) {
         if (!is_numeric($pk)) {
             throw new CHttpException(400, Yii::t('ciims.models.Content', 'The content ID provided was invalid.'));
         }
         $criteria = new CDbCriteria();
         $criteria->addCondition("t.id=:pk");
         $criteria->addCondition("vid=(SELECT MAX(vid) FROM content WHERE id=:pk)");
         $criteria->params = array(':pk' => $pk);
         return $this->query($criteria);
     }
     return parent::findByPk($pk, $condition, $params);
 }