コード例 #1
0
ファイル: TBApplication.php プロジェクト: thongnv90/bluesms
 /**
  * Set id of current subscription view
  * 
  * @param int $id
  */
 public static function setCurrentlySelectedSubscription($id)
 {
     if (!isset(Yii::app()->user->linx_app_selected_subscription)) {
         return false;
     }
     // check if this user is master account
     $is_master = Account::model()->isMasterAccount($id);
     // or a member of this subscription
     $master_account_id = AccountSubscription::model()->getSubscriptionOwnerID($id);
     $is_member = AccountTeamMember::model()->isValidMember($master_account_id, Yii::app()->user->id);
     if ($is_master || $is_member) {
         Yii::app()->user->linx_app_selected_subscription = $id;
         return true;
     }
     return false;
 }
コード例 #2
0
 /**
  * Look for all subscriptions that this account is under.
  * There are 2 cases:
  * 	1. Her own subscription, ie her account is a master account.
  *  2. Subscriptions of team leads of teams she belongs to.
  * @param integer $account_id
  * @param boolean	$is_master	indicating if we should only get subscription of which this account is master account
  * @return array $results	subscription id => subscription label. Label could be company name if available
  * 							, otherwise, we'll use display name
  */
 public function findSubscriptions($account_id, $is_master = false)
 {
     $results = array();
     // case 1: account's own subscription
     $subscription_case1 = self::model()->findAll('account_id = :account_id AND account_subscription_status_id = :status', array(':account_id' => $account_id, ':status' => ACCOUNT_SUBSCRIPTION_STATUS_ACTIVE));
     if (count($subscription_case1) > 0) {
         foreach ($subscription_case1 as $subscription_case1_item) {
             //			$profile = AccountProfile::model()->find('account_id = :account_id', array(':account_id' => $account_id));
             //			if ($profile)
             //			{
             //				$label = $profile->account_profile_preferred_display_name;
             //				if ($profile->account_profile_company_name != null)
             //				{
             //					$label = $profile->account_profile_company_name;
             //				}
             //				$results[$subscription_case1_item->account_subscription_id] = $label;
             //			}
             $results[$subscription_case1_item->account_subscription_id] = $subscription_case1_item->subscription_name;
         }
     }
     if ($is_master === false) {
         // case2: team lead's subscription
         // find all teamlead's id
         $teams = AccountTeamMember::model()->findAll('member_account_id = ?', array($account_id));
         foreach ($teams as $team_) {
             // if inactive team member skip
             if (!$team_->isActive()) {
                 continue;
             }
             //$master_account_id = $team_['master_account_id'];
             $master_subscription_id = $team_['account_subscription_id'];
             // find subscription for this master account
             $subscription_case2 = self::model()->find('account_subscription_id = :account_subscription_id AND account_subscription_status_id = :status', array(':account_subscription_id' => $master_subscription_id, ':status' => ACCOUNT_SUBSCRIPTION_STATUS_ACTIVE));
             if ($subscription_case2) {
                 //					$profile = AccountProfile::model()->find('account_id = ?', array($subscription_case2->account_id));
                 //					if ($profile)
                 //					{
                 //						$label = $profile->account_profile_preferred_display_name;
                 //						if ($profile->account_profile_company_name != null)
                 //						{
                 //							$label = $profile->account_profile_company_name;
                 //						}
                 //						$results[$subscription_case2->account_subscription_id] = $label;
                 //					}
                 $results[$subscription_case2->account_subscription_id] = $subscription_case2->subscription_name;
             }
         }
     }
     return $results;
 }
コード例 #3
0
 /**
  * This action is used for an existing account who is invited to another team.
  */
 public function actionJoinTeam()
 {
     if (isset($_GET['invite_id'])) {
         $invite_id = $_GET['invite_id'];
         // get invite
         $model = $this->loadModel($invite_id);
         $model->account_invitation_status = 1;
         $model->save();
         // create team member record
         $teamMember = new AccountTeamMember();
         $teamMember->accepting_invitation = true;
         $teamMember->master_account_id = $model->account_invitation_master_id;
         $teamMember->account_subscription_id = $model->account_invitation_subscription_id;
         $teamMember->member_account_id = Yii::app()->user->id;
         $teamMember->is_active = AccountTeamMember::ACCOUNT_TEAM_MEMBER_IS_ACTIVE;
         if ($model->account_invitation_type == AccountInvitation::ACCOUNT_INVITATION_TYPE_CUSTOMER) {
             $teamMember->is_customer = ACCOUNT_TEAM_MEMBER_IS_CUSTOMER;
         } else {
             $teamMember->is_customer = 0;
         }
         if ($teamMember->save()) {
             $this->redirect(array('accountTeamMember/admin'));
         }
         if ($teamMember->save()) {
             // create project member record if any
             if ($model->account_invitation_project > 0) {
                 $projectMember = new ProjectMember();
                 $projectMember->project_id = $model->account_invitation_project;
                 $projectMember->account_id = Yii::app()->user->id;
                 $projectMember->project_member_start_date = date('Y-m-d H:i:s');
                 $projectMember->project_member_is_manager = PROJECT_MEMBER_IS_NOT_MANAGER;
                 $projectMember->accepting_invitation = true;
                 $projectMember->save();
             }
         }
     }
 }
コード例 #4
0
 /**
  * Get master account for a project that this user belongs to.
  * This is use to find master account of a project that this user is involved with.
  * This user is assumed to be NOT a master account user
  * 
  * @param integer $member_account_id
  * @param number $project_id
  * @return mix Array of master account ids, master account id if project id is passed in.
  */
 public function getMasterAccountIDs($member_account_id, $project_id = 0)
 {
     // find all the records that reflect team membership of this account
     $teamMembers = AccountTeamMember::model()->findAll('member_account_id = :member_account_id', array(':member_account_id' => $member_account_id));
     // if we filter project
     if ($project_id > 0) {
         foreach ($teamMembers as $membership) {
             // get subscription id
             $sub = AccountSubscription::model()->find('account_id = :account_id AND account_subscription_status_id = 1', array(':account_id' => $membership->master_account_id));
             // get project
             if ($sub) {
                 // if matched project, return master account id
                 $project = Project::model()->find('project_id = :project_id AND account_subscription_id = :account_subscription_id', array(':project_id' => $project_id, ':account_subscription_id' => $sub->account_subscription_id));
                 if ($project && $project->project_id > 0) {
                     return $sub->account_id;
                 }
             }
         }
         return 0;
     }
     // get ids of master account
     $master_acc_ids = array();
     foreach ($teamMembers as $mem) {
         $master_acc_ids[] = $mem->master_account_id;
     }
     // return array of master account ids
     return $master_acc_ids;
 }
コード例 #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return AccountTeamMember the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = AccountTeamMember::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }