Exemplo n.º 1
0
function getSocialAccounts($model)
{
    $result = '';
    $accounts = SocialAccount::findAll(['relative_id' => $model->id]);
    if (count($accounts)) {
        foreach ($accounts as $account) {
            $result .= Html::a($account->network->title . ' ', $account->url, ['target' => '_blank']);
        }
    }
    if (Yii::$app->user->can('moder')) {
        $url = '/social-account/create?id=' . $model->id;
        $result .= Html::a('+', $url, ['class' => 'btn btn-success', 'target' => '_blank', 'title' => 'Добавить']);
    }
    return $result;
}
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SocialAccount::find()->orderBy('relative_id');
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith('relative');
     $query->joinWith('network');
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'network_id' => $this->network_id, 'relative_id' => $this->relative_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'url', $this->url])->orFilterWhere(['like', 'social_networks.title', $this->network_id])->orFilterWhere(['like', 'relatives.sname', $this->relative_id])->orFilterWhere(['like', 'relatives.fname', $this->relative_id]);
     return $dataProvider;
 }
 /**
  * Finds the SocialAccount model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SocialAccount the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SocialAccount::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }