Esempio n. 1
0
 public function email_notifications()
 {
     if (\WebAPL\Modules::checkInstance('person')) {
         $events = \CalendarModel::join(CalendarLangModel::getTableName(), \CalendarModel::getField('id'), '=', CalendarLangModel::getField('calendar_item_id'))->join(\CalendarGroup::getTableName(), \CalendarGroup::getField('id'), '=', \CalendarModel::getField('calendar_group_id'))->join(\CalendarPostModel::getTableName(), \CalendarPostModel::getField('calendar_group_id'), '=', \CalendarGroup::getField('id'))->where(CalendarLangModel::getField('lang_id'), \WebAPL\Language::getId())->where(\CalendarModel::getField('enabled'), 1)->where(\CalendarModel::getField('person_id'), '<>', 0)->select(CalendarLangModel::getField("*"), \CalendarModel::getField('event_date'), \CalendarModel::getField('repeat_frequency'), \CalendarModel::getField('repeat_to_date'), \CalendarModel::getField('person_id'), \CalendarModel::getField('post_id'), \CalendarModel::getField('period'))->orderBy(\CalendarModel::getField('event_date'), 'asc')->where(function ($query) {
             $query->where(function ($query) {
                 $query->where(DB::raw("DATE(" . CalendarModel::getField('event_date') . ")"), '=', DB::raw('DATE(CURRENT_TIMESTAMP)'));
             })->orWhere(function ($query) {
                 $query->where(\CalendarModel::getField('event_date'), '<=', DB::raw('CURRENT_TIMESTAMP'))->where(\CalendarModel::getField('repeat_to_date'), '>=', DB::raw('CURRENT_TIMESTAMP'))->where(\CalendarModel::getField('repeat_frequency'), '<>', 'none');
             });
         })->get();
         $event_list = \CalendarModel::generateEvents($events, false);
         $today_events = [];
         foreach ($event_list as $event) {
             if (date("Y-m-d", strtotime($event['event_date'])) === date("Y-m-d") && strtotime($event['event_date']) >= time()) {
                 echo " sendone ";
                 $today_events[] = $event;
                 $this->loadClass(['PersonModel'], 'person');
                 $person = \PersonModel::getPerson($event['person_id']);
                 if (isset($person->email) && $person->email) {
                     Template::viewModule($this->module_name, function () use($person, $event) {
                         \EmailModel::sendToAddress($person->email, "Do you have an event today", 'views.calendarEmail', ['person' => $person, 'event' => $event]);
                     });
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function edit_item($id = 0)
 {
     \User::onlyHas('calendar-view');
     $data = array('calendar' => CalendarModel::find($id));
     if ($data['calendar']) {
         $langs = CalendarLangModel::where('calendar_item_id', $id)->get();
         $data['langs'] = array();
         foreach ($langs as $lang) {
             $data['langs'][$lang->lang_id] = $lang;
         }
         if (\WebAPL\Modules::checkInstance('person')) {
             $this->loadClass(['PersonLangModel'], 'person');
             $data['persons'] = \PersonLangModel::where('lang_id', Language::getId())->orderBy(\DB::raw(\PersonLangModel::getField('first_name') . ', ' . \PersonLangModel::getField('last_name')), 'asc')->get();
         }
         $data['groups'] = \CalendarGroup::orderBy('name', 'asc')->get();
         //            $data['posts'] = Post::join(PostLang::$ftable, PostLang::$ftable . ".post_id", '=', Post::$ftable . ".id")
         //                    ->select(CalendarPostModel::$ftable . ".post_id", CalendarPostModel::$ftable . ".calendar_item_id", PostLang::$ftable . ".title")
         //                    ->join(CalendarPostModel::$ftable, CalendarPostModel::$ftable . ".post_id", '=', Post::$ftable . ".id")
         //                    ->where(CalendarPostModel::$ftable . ".calendar_item_id", $id)
         //                    ->get();
         //
         //            $data['posts_all'] = Post::prepareAll()
         //                    ->select(PostLang::$ftable . ".title", Post::$ftable . ".id")
         //                    ->where(Post::$ftable . ".view_mod", $this->page_view_mod)
         //                    ->get();
         $this->layout->content = Template::moduleView($this->module_name, 'views.edit_form', $data);
         return $this->layout;
     } else {
         \App::abort(404);
     }
 }