public function getKeyOptionsByUserId($id)
 {
     $keyOptions = array();
     $keyOptions[""] = "None";
     $allKeyConnections = KeyConnections::find()->where(['owner' => $id])->all();
     foreach ($allKeyConnections as $connection) {
         if ($connection->text != "") {
             $keyOptions[$connection->text] = $connection->name . " - " . $connection->text;
         }
     }
     return $keyOptions;
 }
 /**
  * Creates a new KeyConnections model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new KeyConnections();
     if ($model->load(Yii::$app->request->post())) {
         $model->owner = Yii::$app->user->identity->id;
         //Check if key already exists. If so, just redirect.
         if (KeyConnections::find()->where(['text' => $model->text, 'owner' => $model->owner])->exists()) {
             return $this->redirect(Yii::$app->request->referrer);
         }
         $date = new \DateTime();
         $model->timestamp = $date->getTimestamp();
         if ($model->save(false)) {
             return $this->redirect(Yii::$app->request->referrer);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
$endMonth = intval(date('m'));
$endYear = intval(date('Y'));
$startMonth = $endMonth;
$startYear = $endYear - 1;
//Draw our graph.
$data = getTweetsForIntervalByUsernameAsArray($user, $startMonth, $startYear, $endMonth, $endYear);
$graph = new GraphWrapper("tweetsOverYear", $data, 'date', ['numTweets'], 'date', ['Tweets']);
echo $graph->getChart();
echo "<br/>";
echo "<p class='lead'>Keys</p>";
echo "<br/>";
$model = new KeyConnections();
echo $this->render('/key-connections/_form', ['model' => $model]);
$userId = User::find()->where(['username' => $user])->one()->id;
//Draw our keys.
$dataProvider = new ActiveDataProvider(['query' => KeyConnections::find()->where(['owner' => $userId])]);
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'text', ['class' => 'yii\\grid\\ActionColumn', 'controller' => 'key-connections']]]);
?>
    </div>
</div>







<?php 
class GraphWrapper
{
    private $data;
Esempio n. 4
0
 public function hasKey($key)
 {
     return KeyConnections::find()->where(['owner' => $this->id, 'text' => $key])->exists();
 }