public function home()
 {
     $eureka = Eurekas::find('random');
     $projects = Projects::find('all');
     $posts = Posts::latest();
     return compact('posts', 'eureka', 'projects');
 }
示例#2
0
 public function run()
 {
     $query = Projects::find();
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 4]);
     $pages->pageSizeParam = false;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('mywidget', ['projects' => $models, 'pages' => $pages]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Projects::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'project_name', $this->project_name]);
     return $dataProvider;
 }
示例#4
0
 public function actionForm($id = NULL)
 {
     $model = $id ? Visits::findOne($id) : new Visits();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         /* Check if it is a new record before we save it  */
         $newRecord = $model->isNewRecord;
         /* Attempt to save model */
         if ($model->save(false)) {
             /* Only when the record is new */
             if ($newRecord) {
                 /* Register null-observations for un-checked boxes if available */
                 if (!$model->checked_all) {
                     foreach ($model->project->boxes as $box) {
                         if (in_array($box->id, $model->checked_boxes)) {
                             Observations::createNullObservation($model->id, $box->id);
                         }
                     }
                 }
                 /* Register checked boxes */
                 if ($model->checked_boxes) {
                     $model->unlinkAll('visitBox', true);
                     foreach ($model->checked_boxes as $checkedBox) {
                         $visitBoxModel = new VisitBoxes();
                         $visitBoxModel->box_id = $checkedBox;
                         $visitBoxModel->link('visit', $model);
                         $visitBoxModel->save();
                     }
                 }
                 /* Register null-observations for all boxes in project when "checked-all" is selected */
                 if ($model->checked_all) {
                     foreach ($model->project->boxes as $box) {
                         Observations::createNullObservation($model->id, $box->id);
                     }
                 }
             }
             /* Register observers by this visit */
             if ($model->observers) {
                 $model->unlinkAll('observers', true);
                 foreach ($model->observers as $observer) {
                     $visitObservers = new VisitObservers();
                     $visitObservers->observer_id = $observer;
                     $visitObservers->link('visit', $model);
                     $visitObservers->save();
                 }
             }
             /* Redirect on success */
             return $this->redirect(Url::toRoute('visits/detail/' . $model->id));
         }
     }
     return $this->render('form', ['model' => $model, 'projects' => Projects::find()->hasRights()->hasBoxes()->all()]);
 }
示例#5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Projects::find();
     $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->andFilterWhere(['project_id' => $this->project_id, 'final_datetime' => $this->final_datetime, 'cyclical_project_id' => $this->cyclical_project_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'logo_filepath', $this->logo_filepath]);
     return $dataProvider;
 }
示例#6
0
 public function actionForm($id = NULL)
 {
     $model = $id ? Boxes::findOne($id) : new \app\models\Boxes();
     if (Yii::$app->request->getQueryParam('project_id')) {
         $model->project_id = Yii::$app->request->getQueryParam('project_id');
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
         if ($model->validate()) {
             // Clusters
             $cluster = Yii::$app->request->post('Boxes')['cluster'];
             if ($cluster) {
                 if (ProjectClusters::find()->byCluster($cluster)->exists()) {
                     $model->cluster_id = ProjectClusters::find()->byCluster($cluster)->one()['id'];
                 } else {
                     $clusterModel = new ProjectClusters();
                     $clusterModel->cluster = $cluster;
                     $clusterModel->link('project', $model->project);
                     $clusterModel->save();
                     $model->cluster_id = $clusterModel->id;
                 }
             } else {
                 $model->cluster_id = NULL;
             }
             /* Image */
             if ($model->imageFile) {
                 $model->upload();
             }
             if ($model->deleteImage && !$model->imageFile) {
                 $model->picture = NULL;
             }
             $model->save();
             return $this->redirect(Url::toRoute('boxes/detail/' . $model->id));
         } else {
             if (isset($_POST['Boxes']['cluster'])) {
                 $model->cluster = Yii::$app->request->post('Boxes')['cluster'];
             }
         }
     }
     return $this->render('form', ['model' => $model, 'user' => $this->user, 'users' => Users::find()->select(['id', new \yii\db\Expression("CONCAT(username, ' (', fullname, ')') as username")])->all(), 'boxtypes' => Boxtypes::find()->all(), 'projects' => Projects::find()->select(['id', 'name'])->hasRights()->all()]);
 }
 /**
  * Displays a single Members model.
  * @param string $id
  * @return mixed
  */
 public function actionView($id)
 {
     $dataProviderForGroupAss = new ActiveDataProvider(['query' => GroupAssignments::find()]);
     $dataProviderForGroup = new ActiveDataProvider(['query' => Groups::find()]);
     $dataProviderForProject = new ActiveDataProvider(['query' => Projects::find()]);
     try {
         $modelPic = new UploadForm();
         if (Yii::$app->request->isPost) {
             $modelPic->file = UploadedFile::getInstance($modelPic, 'file');
             if ($modelPic->validate() && $modelPic !== null) {
                 $fileName = round(microtime(true) * 1000);
                 $uploadPath = 'uploads/' . $fileName . '.' . $modelPic->file->extension;
                 $modelPic->file->saveAs($uploadPath);
                 //save avatar to user
                 $model = $this->findModel($id);
                 $model->avatar = $uploadPath;
                 $model->save();
             }
         }
     } catch (\Exception $e) {
     }
     return $this->render('view', ['model' => $this->findModel($id), 'modelPic' => $modelPic, 'dataProviderForGroupAss' => $dataProviderForGroupAss, 'dataProviderForGroup' => $dataProviderForGroup, 'dataProviderForProject' => $dataProviderForProject]);
 }
示例#8
0
 public function rules()
 {
     return [[['code', 'cord_lat', 'cord_lng', 'province'], 'required'], [['project_id', 'boxtype_id'], 'integer'], [['placement_date', 'removal_date', 'date_created', 'date_updated', 'cluster_id', 'deleteImage'], 'safe'], [['remarks', 'placement_height'], 'string'], [['deleted'], 'boolean'], [['code', 'location'], 'string', 'max' => 45], [['cord_lat', 'cord_lng'], 'string', 'max' => 50], ['province', 'string', 'max' => 20], [['direction'], 'string', 'max' => 2], [['picture'], 'string', 'max' => 100], ['placement_height', 'trim'], ['project_id', 'required', 'when' => function () {
         return $this->isNewRecord ? true : false;
     }], ['code', function ($attribute, $params) {
         if (isset($this->project)) {
             $uniqueQuery = Boxes::find()->where(['and', ['code' => $this->{$attribute}], ['project_id' => $this->project->id]]);
             if (!$this->isNewRecord) {
                 $uniqueQuery->andWhere(['<>', 'id', $this->id]);
             }
             if ($uniqueQuery->exists()) {
                 $this->addError($attribute, Yii::t('app', 'Kastcode bestaat al binnen dit project.'));
             }
         }
     }], ['placement_date', function ($attribute, $params) {
         if ($this->placement_date >= $this->removal_date && !empty($this->removal_date)) {
             $this->addError($attribute, Yii::t('app', 'Plaatsingsdatum mag niet na de verwijderdatum liggen.'));
         }
     }], ['removal_date', function ($attribute, $params) {
         if ($this->removal_date <= $this->placement_date && !empty($this->removal_date)) {
             $this->addError($attribute, Yii::t('app', 'Verwijderdatum mag niet voor de plaatsingsdatum liggen.'));
         }
     }], ['cord_lat', function ($attribute, $params) {
         if (!WGS84::inrange(-90, $this->cord_lat, 90)) {
             $this->addError($attribute, Yii::t('app', 'Latitude coördinaat is niet valide'));
         }
     }], ['cord_lng', function ($attribute, $params) {
         if (!WGS84::inrange(-180, $this->cord_lng, 180)) {
             $this->addError($attribute, Yii::t('app', 'Longitude coördinaat is niet valide'));
         }
     }], ['project_id', function ($attribute, $params) {
         if (!Projects::find()->andWhere(['projects.id' => $this->{$attribute}])->hasRights()->exists() && $this->isNewRecord) {
             return $this->addError($attribute, Yii::t('app', 'U heeft geen toegang tot het geselecteerde project'));
         }
     }]];
 }
 /**
  * Lists all Projects models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Projects::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
示例#10
0
    $project->blog_url = Input::get('blog_url');
    $project->github_url = Input::get('github_url');
    $project->save();
    return redirect('admin/projects');
});
Route::get("/admin/project/confirm/{id}", function ($id) {
    if (!Auth::check() || !User::isAdmin(Auth::user())) {
        return redirect('login')->with('msg', "NOT LOGGED IN!");
    }
    return view('admin/projects/confirm', ['id' => $id]);
});
Route::get("/admin/project/delete/{id}", function ($id) {
    if (!Auth::check() || !User::isAdmin(Auth::user())) {
        return redirect('login')->with('msg', "NOT LOGGED IN!");
    }
    Projects::find($id)->delete();
    return redirect('admin/projects');
});
Route::post('/admin/blog/edit', function () {
    if (!Auth::check() || !User::isAdmin(Auth::user())) {
        return redirect('login')->with('msg', "NOT LOGGED IN!");
    }
    $blog = Article::find(Input::get('id'));
    $blog->title = Input::get('title');
    $blog->post_markdown = Input::get('markdown');
    $blog->save();
    return redirect('admin/blog/' . $blog->id);
});
Route::get('/admin/blog/{id}', function ($id) {
    if (!Auth::check() || !User::isAdmin(Auth::user())) {
        return redirect('login')->with('msg', "NOT LOGGED IN!");
示例#11
0
 public function delete($id)
 {
     Users::redirectIf(false);
     $member = Session::get('member');
     $project = Projects::find('id', $id);
     if ($project->id_leader != $member['id']) {
         Router::redirect('task:home.index');
     }
     $project->delete();
     Session::setFlash('success', '', 'Vous avez supprimé le projet !');
     Router::redirect('task:home.index');
 }
示例#12
0
 public function run()
 {
     $query = Projects::find();
     $data = Yii::$app->request->get('arr');
     if ('on' == $data['clear']) {
         $data = [];
     }
     $pagesize = 4;
     if (!empty($data)) {
         foreach ($data as $key => $val) {
             if ('price' == $key) {
                 switch ($val) {
                     case '1':
                         $query->where('price < :price', [':price' => 1000000]);
                         break;
                     case '2':
                         $query->where(['between', 'price', 1000000, 3000000]);
                         break;
                     case '3':
                         $query->where('price > :price', [':price' => 3000000]);
                         break;
                 }
             }
             if ('floor' == $key) {
                 switch ($val) {
                     case 1:
                         $query->andWhere('floor = :floor', [':floor' => 1]);
                         break;
                     case 2:
                         $query->andWhere('floor = :floor', [':floor' => 2]);
                         break;
                     case 3:
                         $query->andWhere('floor = :floor', [':floor' => 3]);
                         break;
                 }
             }
             if ('material' == $key) {
                 switch ($val) {
                     case 1:
                         $query->andWhere('material_brevno = :brevno', [':brevno' => 1]);
                         $pagesize = 3;
                         break;
                     case 2:
                         $query->andWhere('material_brus = :brus', [':brus' => 1]);
                         $pagesize = 8;
                         break;
                     case 3:
                         $query->andWhere('material_brevno = :brevno', [':brevno' => 1]);
                         $query->andWhere('material_brus = :brus', [':brus' => 1]);
                         break;
                 }
             }
             if ('area' == $key) {
                 switch ($val) {
                     case 1:
                         $query->andWhere('area < :area', [':area' => 100]);
                         break;
                     case 2:
                         $query->andWhere(['between', 'area', 100, 300]);
                         break;
                     case 3:
                         $query->andWhere('area > :area', [':area' => 300]);
                         break;
                 }
             }
         }
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $pagesize]);
     $pages->pageSizeParam = false;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('mywidget', ['projects' => $models, 'pages' => $pages]);
 }