예제 #1
0
 /**
  * Delete the related values
  *
  * @param string $strTable
  * @param string $strField
  * @param mixed  $varReference
  *
  * @throws \Exception
  */
 public static function deleteRelatedValues($strTable, $strField, $varReference)
 {
     $arrRelation = Relations::getRelation($strTable, $strField);
     if ($arrRelation === false) {
         throw new \Exception('Field ' . $strField . ' does not seem to be related!');
     }
     \Database::getInstance()->prepare("DELETE FROM " . $arrRelation['table'] . " WHERE " . $arrRelation['reference_field'] . "=?")->execute($varReference);
 }
예제 #2
0
파일: Alliance.php 프로젝트: kl0428/urtime
 public function getAlliance($alliance_id = 0)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('t.id', $alliance_id);
     $criteria->with = 'user';
     $obj = $this->find($criteria);
     if ($obj) {
         $alliance = array('id' => $obj->id, 'logo' => $obj->image, 'name' => $obj->name, 'leader' => $obj->leader, 'leader_name' => $obj->user ? $obj->user->nickname : '-', 'type' => $obj->type, 'center_name' => $obj->center_name, 'notice' => $obj->notice, 'members' => Relations::model()->getMembers($alliance_id, 0));
     } else {
         $alliance = [];
     }
     return $alliance;
 }
예제 #3
0
 public static function setError($s)
 {
     self::$error = $s;
 }
예제 #4
0
 public function addAlliance($params = array())
 {
     extract($params);
     if (isset($user_id) && $user_id && isset($alliance_id) && $alliance_id) {
         //检查是否申请过
         $obj = Relations::model()->find(array('select' => array('id'), 'condition' => 'user_id=:user_id and alliance_id=:alliance_id', 'params' => array(':user_id' => $user_id, ':alliance_id' => $alliance_id)));
         if (!$obj) {
             $relation = new Relations();
             if ($relation->validate() && $relation->save()) {
                 $id = $relation->getPrimaryKey();
                 $result = array('id' => $id);
                 $ret = $this->notice('OK', 0, '成功', $result);
             } else {
                 $ret = $this->notice('ERR', 306, '操作失败', $relation->getErrors());
             }
         } else {
             $result = array('id' => $obj->id);
             $ret = $this->notice('ERR', 305, '数据已经存在', $result);
         }
         return $ret;
     } else {
         return $this->notice('ERR', 301, '缺少参数', []);
     }
 }