public function getWechatAccount() { return WechatAccount::findById($this->getAccountId()); }
<?php $id = isset($vars[1]) ? $vars[1] : null; $object = WechatAccount::findById($id); if (is_null($object)) { HTML::forward('core/404'); } // handle form submission if (isset($_POST['submit'])) { $error_flag = false; /// validation // validation for $nickname $nickname = isset($_POST["nickname"]) ? strip_tags($_POST["nickname"]) : null; if (empty($nickname)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "nickname is required.", "zh" => "请填写nickname")))); $error_flag = true; } // validation for $wechat_id $wechat_id = isset($_POST["wechat_id"]) ? strip_tags($_POST["wechat_id"]) : null; if (empty($wechat_id)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "wechat_id is required.", "zh" => "请填写wechat_id")))); $error_flag = true; } // validation for $openid $openid = isset($_POST["openid"]) ? strip_tags($_POST["openid"]) : null; if (empty($openid)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "openid is required.", "zh" => "请填写openid")))); $error_flag = true; } // validation for $introduction $introduction = isset($_POST["introduction"]) ? $_POST["introduction"] : null;
public function delete() { $rtn = parent::delete(); // delete extra relationship for wechat_account_user if existed if ($rtn) { $user = MySiteUser::getCurrentUser(); $wechat_account_user = WechatAccountUser::findbyCombo($this->getAccountId(), $user->getId()); if ($wechat_account_user) { $wechat_account_user->delete(); } } // check if there is any other users subscribing this wechat_account, if no, we delete it if ($rtn) { $wechat_account_users = WechatAccountUser::findByAccountId($this->getAccountId()); if (sizeof($wechat_account_users) == 0) { $wechat_account = WechatAccount::findById($this->getAccountId()); $wechat_account->delete(); } } return $rtn; }