Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public static function setError($s)
 {
     self::$error = $s;
 }
Ejemplo n.º 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, '缺少参数', []);
     }
 }