Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     //Check params has a id
     $user = Yii::$app->user->identity;
     $id = $user->level == 2 ? $user->parent_id : $user->id;
     $query = Mood::find()->joinWith('user')->where('user.parent_id=:parent_id', [':parent_id' => $id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 8]]);
     $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->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'date' => $this->date, 'time' => $this->time]);
     $query->andFilterWhere(['like', 'mood', $this->mood]);
     $query->andFilterWhere(['>=', 'date', $this->start_date])->andFilterWhere(['<=', 'date', $this->end_date]);
     return $dataProvider;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Post $postModel, Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'required', 'mail' => 'required|email', 'content' => 'required']);
     if ($validator->fails()) {
         $citySelect = City::lists('city_name', 'id');
         $moodSelect = Mood::lists('mood_name', 'id');
         return view('post.form', ['messages' => $validator->errors(), 'citySelect' => $citySelect, 'moodSelect' => $moodSelect, 'request' => $request]);
     } else {
         $post = new Post();
         $post->name = $request->input('name');
         $post->email = $request->input('mail');
         $post->content = $request->input('content');
         $post->city = $request->input('city');
         $post->mood = $request->input('mood');
         $post->created_at = time();
         if ($post->save()) {
             Session::flash('message', 'Feedback was added');
         } else {
             Session::flash('message', 'Add feeds failed');
         }
         return redirect()->action('PostController@index');
     }
 }
 /**
  * Display user dashboard
  * @param integer $id User ID
  */
 public function actionDashboard($id = null)
 {
     //Check user level & existence of $id
     $id = Yii::$app->user->identity->level == 0 && $id != null ? $id : Yii::$app->user->id;
     $model = User::findOne($id);
     $photos = \app\models\Photos::getItems();
     $journals = new ActiveDataProvider(['query' => Journal::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     if ($model->level == 3) {
         //if the user is child
         $moods = new ActiveDataProvider(['query' => Mood::find()->select('mood')->where(['user_id' => $id])->orderBy(['date' => SORT_DESC, 'time' => SORT_DESC])->limit(1), 'pagination' => false]);
         $DataProvider = new ActiveDataProvider(['query' => $model->findParents(), 'pagination' => ['pageSize' => 20]]);
         return $this->render('childdashboard', ['dataProvider' => $DataProvider, 'journalProvider' => $journals, 'moodsProvider' => $moods, 'moods' => new Mood(), 'model' => $model, 'photos' => $photos]);
     } else {
         //if the user is parent
         $events = new ActiveDataProvider(['query' => \app\models\Event::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
         $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['assigned_to' => $id, 'status' => 0])->orderBy('id')->limit(5), 'pagination' => false]);
         $DataProvider = new ActiveDataProvider(['query' => $model->findFamily()]);
         $activity = new ActiveDataProvider(['query' => \app\models\Activity::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->limit(4), 'pagination' => false]);
         return $this->render('dashboard', ['dataProvider' => $DataProvider, 'activity' => $activity, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists]);
     }
 }
 /**
  * Finds the Mood model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Mood the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Mood::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
/* @var $form ActiveForm */
//var_dump($model->wishlists); die();
$this->title = 'Child Dashboard';
$this->params['breadcrumbs'][] = $this->title;
?>
<!-- Content Header (Page header) -->
<?php 
if (Yii::$app->user->identity->level != 0) {
    echo $this->render('_mood', ['model' => $moods]);
    ?>
        

<div class="background-white top-fixed-margin bordered-grey padding-large">

    <?php 
    $count = (int) Yii::$app->find->setting('number_of_moods_a_day') - Mood::find()->where(['user_id' => Yii::$app->user->getId(), 'date' => date("Y-m-d")])->count();
    $count == 1 ? $entry_label = "Entry" : ($entry_label = "Entries");
    Pjax::begin(['id' => 'moodbox', 'class' => 'moodbox']);
    ?>
    <?php 
    if ($count != (int) Yii::$app->find->setting('number_of_moods_a_day')) {
        ?>
        <?php 
        echo GridView::widget(['dataProvider' => $moodsProvider, 'columns' => ['mood'], 'caption' => "<span class='label label-danger font-small'>" . $count . "</span>" . " " . "<span class='font-small color-bule'>" . $entry_label . " remaining today" . "</span>", 'options' => ['class' => 'moodbox-table'], 'emptyText' => '']);
        ?>
    <?php 
    }
    ?>
    <?php 
    Pjax::end();
    ?>
Example #6
0
<?php

use yii\helpers\Html;
use app\models\Mood;
/* @var $this yii\web\View */
/* @var $model app\models\User */
/* @var $moods app\models\Mood */
$this->title = "Mood Summary - " . $model->fullname;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Moods'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$last = Mood::find()->select('date')->where(['user_id' => $model->id])->orderBy(['date' => SORT_DESC])->one();
$mood = Mood::percentageMonthly($model->id, date("m", strtotime($last->date)));
$monthly = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$yearly = [];
?>
<div class="row">
    <div class="col-md-12 ">
        <label class="control-label">Select a month</label>
        <select id="date-range" name="date-range" class="form-control">
            <option value="<?php 
echo intval(date('m'));
?>
" data-year="<?php 
echo date('Y');
?>
">Please Select</option>
            <?php 
//Find and display available moods in a drop down, by month of selected user
foreach ($moods as $year => $months) {
    foreach ($monthly as $k => $m) {
        $yearly[$year][0][intval($k)] = isset($months[$m]) ? $months[$m]['sad'] : 0;
Example #7
0
 public static function getMoodsBetweenDates($lower, $upper, $user_id = null)
 {
     return Mood::find()->where(['and', 'date >= $lower', 'date <= $upper', ['user_id' => $user_id]])->all();
 }
Example #8
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $model app\models\Mood */
/* @var $form yii\widgets\ActiveForm */
//var_dump(Yii::$app->find->setting('number_of_moods_a_day')); die();
$date = date("Y-m-d");
if (\app\models\Mood::find()->where(['user_id' => Yii::$app->user->getId(), 'date' => $date])->count() < (int) Yii::$app->find->setting('number_of_moods_a_day')) {
    ?>

       <div class="background-white top-fixed-margin bordered-grey padding-large">
            <div class="row moodbox" id="secondmood">
                <div class="mood-form">
                    <?php 
    yii\widgets\Pjax::begin(['id' => 'new_mood']);
    ?>
                    <?php 
    $form = ActiveForm::begin(['action' => ['mood/create'], 'id' => $model->formName()]);
    ?>

                    <?php 
    echo $form->field($model, 'mood')->radioList(Yii::$app->params['moods'], array('prompt' => 'Select', 'size' => 5));
    ?>
                    <div class="form-group">
                        <?php 
    echo Html::submitButton($model->isNewRecord ? 'Set Mood' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'id' => 'submit_mood']);
    ?>
<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\Journal */
use yii\helpers\Html;
use app\models\Mood;
$date = date("Y-m-d");
$mood = Mood::percentageMonthly($model->id, date("m"));
if ($model->status != 2 && count($model->moods) > 0) {
    ?>
    <!-- single user -->
    <!-- Widget: user widget style 1 -->
    <div class="col-md-4">
        <div class="box box-widget widget-user">
            <!-- Emoji for widget -->
            <div class="widget-emoji <?php 
    echo $model->todayMood;
    ?>
"></div>
            <!-- Emoji for widget ends -->
            <!-- Add the bg color to the header using any of the bg-* classes -->
            <div class="widget-user-header" style="background-color:<?php 
    echo $model->profile->color;
    ?>
">
                <h3 class="widget-user-username"><?php 
    echo $model->fullname;
    ?>
</h3>
                <h5 class="widget-user-desc">is <?php 
Example #10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('Moods')->delete();
     Mood::create(['id' => 1, 'mood_name' => 'Good']);
     Mood::create(['id' => 2, 'mood_name' => 'Bad']);
 }
Example #11
0
 /**
  * get current day mood
  */
 public function getTodayMood($user_id = null)
 {
     $moods_today = Mood::percentageMonthly($this->id, null);
     if ($max = max($moods_today)) {
         return array_search(max($moods_today), $moods_today);
     } else {
         return "not-updated the mood";
     }
 }