Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Illuminate\Database\Eloquent\SoftDeletes
Ejemplo n.º 1
0
 public function testValidateCorrect()
 {
     $model = new Event(['type' => 'Type', 'name' => 'Name', 'event' => 'Event', 'title' => 'Title']);
     $this->specify('event wrong', function () use($model) {
         expect('model should not validate', $model->validate())->true();
     });
 }
Ejemplo n.º 2
0
 /**
  * Reschedule an existing event.
  *
  * @param  Event  $oldEvent
  * @param  array  $data
  * @return Event
  * @throws Exception
  */
 public function reschedule(Event $oldEvent, array $data)
 {
     try {
         DB::beginTransaction();
         // Recreate venue
         $newVenue = $oldEvent->venue->replicate();
         if (is_array($data['venue']) && count($data['venue'])) {
             $newVenue->fill($data['venue']);
         }
         $newVenue->save();
         // Recreate event
         $newEvent = $oldEvent->replicate();
         if (is_array($data['event']) && count($data['event'])) {
             $newEvent->fill($data['event']);
         }
         $newEvent->status_id = EventStatus::ACTIVE;
         $newEvent->venue_id = $newVenue->id;
         $newEvent->save();
         DB::commit();
         return $newEvent;
     } catch (\Exception $e) {
         DB::rollBack();
         throw $e;
     }
 }
Ejemplo n.º 3
0
 public function actionCreate()
 {
     $model = new Event();
     if ($model->load(Yii::$app->request->post())) {
         $model->save();
         //var_dump($model->getErrors()); die;
     }
     return $this->render('create', array('model' => $model));
 }
Ejemplo n.º 4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $event = new Event();
     $event->event_name = "Test Event";
     $event->event_start_date = Carbon::createFromFormat('Y-m-d h:i A', '2016-05-21 12:00 PM')->toDateTimeString();
     $event->event_end_date = Carbon::createFromFormat('Y-m-d h:i A', '2016-05-21 3:30 PM')->toDateTimeString();
     $user = User::find(1);
     $event->user_id = $user->id;
     $event->save();
 }
Ejemplo n.º 5
0
 /**
  * Determine if a given event can be rescheduled by the user.
  *
  * @param User $user
  * @param Event $event
  * @throws Exception
  */
 public function reschedule(User $user, Event $event)
 {
     if (!$event->isOrganizer($user)) {
         throw new AuthorizationException(trans('messages.event.not_your_own'));
     }
     if (!($event->isCanceled() || $event->hasPassed())) {
         throw new AuthorizationException(trans('messages.event.cannot_reschedule_active'));
     }
     return true;
 }
Ejemplo n.º 6
0
 public function home()
 {
     if ($this->auth->check()) {
         $events = new Event();
         $future = $events->future();
         $present = $events->present();
         $past = $events->past();
         return view('pages/dashboard', compact('future', 'present', 'past'));
     } else {
         return view('pages/home');
     }
 }
Ejemplo n.º 7
0
 /**
  * Save event data in the database
  *
  * @param array $data
  * @throws \Exception
  */
 public function save(array $data)
 {
     // Check event type
     if (!$this->hasValidEventType($data)) {
         throw new \Exception(\Yii::t("app", "Event has a invalid type: Should not be recorded."));
     }
     // Prepare the data for the model validation
     $eventData = ['Event' => $data];
     // New Event Model
     $eventModel = new Event();
     // Populate Event Model and Save (with validation)
     if (!$eventModel->load($eventData) || !$eventModel->save()) {
         throw new \Exception(Yii::t("app", "Error saving Event Model"));
     }
 }
Ejemplo n.º 8
0
 public function actionIndex()
 {
     $query = Event::find();
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]);
     $events = $query->orderBy('date')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['events' => $events, 'pagination' => $pagination]);
 }
Ejemplo n.º 9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Event::find();
     if (\Yii::$app->user->isGuest) {
         return null;
     }
     $user = \Yii::$app->user->identity;
     if (!$user->admin && count($user->organisations) == 0) {
         return null;
     } else {
         if (!$user->admin) {
             $organisations = $user->organisations;
             foreach ($organisations as $organisation) {
                 $query->orWhere(['owner_id' => $organisation->id]);
             }
         }
     }
     $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(['id' => $this->id, 'owner_id' => $this->owner_id, 'start_time' => $this->start_time, 'end_time' => $this->end_time]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'summary', $this->summary]);
     return $dataProvider;
 }
Ejemplo n.º 10
0
 public function delete($id)
 {
     $event = Event::findOrFail($id);
     $event->delete();
     flash('Ви успішно видалили подію!');
     return back();
 }
 public function actionUser($id = null)
 {
     $event = Event::getAll(Yii::$app->user->identity->id);
     $userinfo = Userinfo::getAll(Yii::$app->user->identity->id);
     $content = $this->renderPartial('userinfo', ['event' => $event, 'userinfo' => $userinfo]);
     return $this->render('user', ['content' => $content]);
 }
Ejemplo n.º 12
0
 public function index()
 {
     $videoCount = Video::count();
     $memberCount = $this->userRepo->countMembers();
     $eventCount = Event::count();
     return view('admin.index', ['noOfVideos' => $videoCount, 'noOfMembers' => $memberCount, 'noOfEvents' => $eventCount]);
 }
Ejemplo n.º 13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('events')->delete();
     for ($i = 1; $i <= 100; $i++) {
         Event::create(['title' => '我是活动 - ' . $i, 'content' => 'content ' . $i, 'begin_time' => \Carbon\Carbon::now(), 'end_time' => \Carbon\Carbon::now(), 'user_count' => rand(0, 1000), 'user_id' => 1]);
     }
 }
Ejemplo n.º 14
0
 /**
  * Search events.
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function events(Request $request)
 {
     $ip = $request->ip();
     $ip = '73.85.49.134';
     $geolocation = $this->ipGeolocator->ipToGeolocation($ip);
     $perPage = 4;
     $defaultDistance = 25;
     $input = $request->only(['keyword', 'distance', 'lat', 'lng', 'city', 'type']);
     $input['distance'] = $input['distance'] ?: $defaultDistance;
     if (!$input['city'] && $geolocation) {
         $input['lat'] = $geolocation['lat'];
         $input['lng'] = $geolocation['lng'];
         $input['city'] = $geolocation['city'];
     }
     $events = Event::query()->filterActive()->filterUpcoming()->orderBySoonest();
     if ($input['keyword']) {
         $events->filterKeyword($input['keyword']);
     }
     if ($input['distance'] && is_numeric($input['distance'])) {
         $events->filterNearby($input['lat'], $input['lng'], $input['distance']);
     }
     if ($input['type']) {
         $events->filterTypes($input['type']);
     }
     $events = $events->paginate($perPage);
     $events->appends($input);
     return view('search.events.result', compact('events', 'input'));
 }
Ejemplo n.º 15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // ---------------------------------------------------------------------
     // CONFERENCE 1
     // ---------------------------------------------------------------------
     $conference = ['name' => 'India Conference', 'description' => 'A conference in India.', 'start_date' => '2016-03-01', 'end_date' => '2016-03-31', 'address' => 'Sansad Marg, Connaught Place, New Delhi, Delhi 110001, India', 'city' => 'New Delhi', 'country' => 'India', 'capacity' => 1000, 'status' => 'approved'];
     $conference = Conference::create($conference);
     $event = ['name' => 'Opening Ceremony', 'description' => 'Welcome!', 'facilitator' => 'TBD', 'date' => '2016-05-01', 'start_time' => '09:00:00', 'end_time' => '10:00:00', 'address' => 'Sansad Marg, Connaught Place, New Delhi, Delhi 110001, India', 'city' => 'New Delhi', 'country' => 'India', 'capacity' => 1000, 'status' => 'approved'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
     // ---------------------------------------------------------------------
     // CONFERENCE 2
     // ---------------------------------------------------------------------
     $conference = ['name' => 'Canada Conference', 'description' => 'A conference in Canada.', 'start_date' => '2016-05-11', 'end_date' => '2016-05-20', 'address' => '1055 Canada Pl, Vancouver, BC V6C 0C3, Canada', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 1000, 'status' => 'approved'];
     $conference = Conference::create($conference);
     $event = ['name' => 'Opening Ceremony', 'description' => 'Welcome!', 'facilitator' => 'TBD', 'date' => '2016-05-11', 'start_time' => '09:00:00', 'end_time' => '10:00:00', 'address' => '1055 Canada Pl, Vancouver, BC V6C 0C3, Canada', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 1000, 'status' => 'approved'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
     // ---------------------------------------------------------------------
     // CONFERENCE 3
     // ---------------------------------------------------------------------
     $conference = ['name' => 'France Conference', 'description' => 'A conference in France.', 'start_date' => '2016-05-21', 'end_date' => '2016-05-30', 'address' => '17 Boulevard Saint-Jacques, Paris 75014, France', 'city' => 'Paris', 'country' => 'France', 'capacity' => 1000, 'status' => 'approved'];
     $conference = Conference::create($conference);
     $event = ['name' => 'Opening Ceremony', 'description' => 'Welcome!', 'facilitator' => 'TBD', 'date' => '2016-05-21', 'start_time' => '09:00:00', 'end_time' => '10:00:00', 'address' => '17 Boulevard Saint-Jacques, Paris 75014, France', 'city' => 'Paris', 'country' => 'France', 'capacity' => 1000, 'status' => 'approved'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
     // ---------------------------------------------------------------------
     // CONFERENCE 4
     // ---------------------------------------------------------------------
     $conference = ['name' => 'CPSC 319 Final Demos', 'description' => 'Teams present their projects.', 'start_date' => '2016-03-31', 'end_date' => '2016-04-07', 'address' => 'Hugh Dempster Pavilion, 6245 Agronomy Road, Vancouver, BC V6T 1Z4', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 100, 'status' => 'approved'];
     $conference = Conference::create($conference);
     $event = ['name' => 'Project 2 Final Demos', 'description' => 'Teams 5 to 8 present their projects.', 'facilitator' => 'Dr Ahmed Awad', 'date' => '2016-03-31', 'start_time' => '12:30:00', 'end_time' => '14:00:00', 'address' => 'Hugh Dempster Pavilion, 6245 Agronomy Road, Vancouver, BC V6T 1Z4', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 100, 'status' => 'approved'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
     $event = ['name' => 'Project 3 Final Demos', 'description' => 'Teams 9 to 12 present their projects.', 'facilitator' => 'Dr Ahmed Awad', 'date' => '2016-04-05', 'start_time' => '12:30:00', 'end_time' => '14:00:00', 'address' => 'Hugh Dempster Pavilion, 6245 Agronomy Road, Vancouver, BC V6T 1Z4', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 100, 'status' => 'pending'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
     $event = ['name' => 'Project 1 Final Demos', 'description' => 'Teams 1 to 4 present their projects.', 'facilitator' => 'Dr Ahmed Awad', 'date' => '2016-04-07', 'start_time' => '12:30:00', 'end_time' => '14:00:00', 'address' => 'Hugh Dempster Pavilion, 6245 Agronomy Road, Vancouver, BC V6T 1Z4', 'city' => 'Vancouver', 'country' => 'Canada', 'capacity' => 100, 'status' => 'pending'];
     $event = new Event($event);
     $event->conference()->associate($conference);
     $event->save();
 }
Ejemplo n.º 16
0
 /**
  * Загружает запись модели текущего контроллера по айдишнику
  * @param $id
  * @return null|static
  * @throws \yii\web\HttpException
  */
 public function loadModel($id)
 {
     $model = Event::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('events')->truncate();
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 50; $i++) {
         Event::create(['title' => $faker->sentence(6), 'slug' => $faker->slug(), 'time' => $faker->randomElement(['5-7', '7-9', '6-8']), 'address' => $faker->address, 'latitude' => $faker->latitude, 'longitude' => $faker->longitude, 'description' => $faker->paragraph(4), 'website' => $faker->url, 'facebook' => $faker->url, 'user_id' => $faker->randomElement(range(1, 30))]);
     }
 }
 protected function findModel($id)
 {
     if (($model = Event::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 19
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $room = new Room();
     $room->event_id = Event::all()->first()->id;
     $room->length = 200;
     $room->width = 400;
     //need 25 tables of 6 people
     $room->save();
 }
Ejemplo n.º 20
0
 public function getRoom($eventId)
 {
     $event = Event::find($eventId);
     $room = $event->room;
     if (!$room) {
         return $this->respondNotFound('Room Not Found!');
     }
     return $this->respond([$room->toArray()]);
 }
Ejemplo n.º 21
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     foreach (Conference::all() as $conference) {
         $conference->managers()->attach(1);
     }
     foreach (Event::all() as $event) {
         $event->managers()->attach(1);
     }
 }
Ejemplo n.º 22
0
 /**
  * Bootstrap the application services.
  */
 public function boot()
 {
     User::observe('App\\Observers\\UserObserver');
     Reply::observe('App\\Observers\\ReplyObserver');
     Event::observe('App\\Observers\\EventObserver');
     Material::observe('App\\Observers\\MaterialObserver');
     Account::observe('App\\Observers\\AccountObserver');
     FanGroup::observe('App\\Observers\\FanGroupObserver');
     Fan::observe('App\\Observers\\FanObserver');
 }
Ejemplo n.º 23
0
 /**
  * Deletes an event from the database.
  *
  * @param  $id - Id of the events to be deleted
  * @return Response
  * @throws ResourceNotFoundException
  */
 public function delete($id)
 {
     $id = $this->filter->sanitize($id, 'int');
     try {
         $event = Event::findFirstOrFail(['id = ?0', 'bind' => [$id]]);
         return $this->response($this->request, $event);
     } catch (ResourceNotFoundException $e) {
         return $e->returnResponse();
     }
 }
Ejemplo n.º 24
0
 /**
  * Return the field values from the model
  *
  * @param integer $id
  * @param array $fields
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $data = Event::findOrNew($id);
     $fieldNames = array_keys($fields);
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $data->{$field};
     }
     return $fields;
 }
Ejemplo n.º 25
0
 public function eventPost($id)
 {
     //
     $event = Event::find($id);
     $posts = $event->posts;
     $response = new \stdClass();
     $response->success = true;
     $response->total = count($posts);
     $response->data = $posts;
     return response()->json($response);
 }
Ejemplo n.º 26
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //dd(Input::get('data'));
     $data = Input::get('data');
     foreach ($data as $key => $value) {
         if (Event::find($value['id']) != null) {
             Event::find($value['id'])->update(['title' => $value['title'], 'start' => $value['start'], 'end' => $value['end']]);
         } else {
             Event::create(array('title' => $value['title'], 'start' => $value['start'], 'end' => $value['end']));
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Show the home page.
  *
  * @param  Request $request
  * @return \Illuminate\View\View
  */
 public function index(Request $request)
 {
     $ip = $request->ip();
     $ip = '73.85.49.134';
     $input = ['keyword' => '', 'distance' => 25, 'lat' => '', 'lng' => '', 'city' => ''];
     if ($geolocation = $this->ipGeolocator->ipToGeolocation($ip)) {
         $input['city'] = $geolocation['city'];
         $input['lat'] = $geolocation['lat'];
         $input['lng'] = $geolocation['lng'];
     }
     $events = Event::filterNearby($input['lat'], $input['lng'], $input['distance'])->filterActive()->filterUpcoming()->limit(5)->orderBySoonest()->get();
     return view('home.index', compact('events', 'input'));
 }
Ejemplo n.º 28
0
 /**
  * AJAX
  * Добавляет site_update
  * Делает рассылку
  *
  * @param integer $id - идентификатор события
  *
  * @return string
  */
 public function actionSubscribe($id)
 {
     $item = \app\models\Event::find($id);
     if (is_null($item)) {
         return self::jsonError(101, 'Не найдено событие');
     }
     $start = microtime(true);
     Subscribe::add($item);
     SiteUpdate::add($item);
     $item->update(['is_added_site_update' => 1]);
     \Yii::info(microtime(true) - $start, 'gs\\actionSubscribe');
     return self::jsonSuccess();
 }
Ejemplo n.º 29
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(EventRequest $request, $id)
 {
     $event = Event::findOrFail($id);
     $input = $request->input();
     $validator = $event->getValidator($input);
     if ($validator->fails()) {
         return redirect()->back()->withInput()->withErrors();
     }
     $event->event_name = $input['event_name'];
     $event->event_start_date = Carbon::createFromFormat('d/m/Y h:i A', $input['event_start_date']);
     $event->event_end_date = Carbon::createFromFormat('d/m/Y h:i A', $input['event_end_date']);
     $event->save();
     return redirect()->route('event.show', [$event->slug])->with('message', 'Event Updated');
 }
Ejemplo n.º 30
0
 public function validateTime1($attribute)
 {
     if (!$this->hasErrors()) {
         if ($this->isNewRecord) {
             $timeprov = Event::find()->where(['date_event' => $this->date_event, 'id_zal' => $this->id_zal])->all();
             foreach ($timeprov as $timeprovdet) {
                 $t = explode(' - ', $timeprovdet->time_event);
                 if ($this->time_c >= $t[0] and $this->time_c <= $t[1]) {
                     $this->addError($attribute, 'В это время зал занят');
                 }
             }
         }
     }
 }