Beispiel #1
0
 public function index()
 {
     $this->getLayoutView()->set("seo", Framework\Registry::get("seo"));
     $view = $this->getActionView();
     $alltests = Test::all(array(), array("id", "title"));
     $view->set("alltests", $alltests);
 }
Beispiel #2
0
 public function initialize()
 {
     Events::fire("framework.database.initialize.before", array($this->type, $this->options));
     if (!$this->type) {
         $configuration = Registry::get("configuration");
         if ($configuration) {
             $configuration = $configuration->initialize();
             $parsed = $configuration->parse("configuration/database");
             if (!empty($parsed->database->default) && !empty($parsed->database->default->type)) {
                 $this->type = $parsed->database->default->type;
                 unset($parsed->database->default->type);
                 $this->options = (array) $parsed->database->default;
             }
         }
     }
     if (!$this->type) {
         throw new Exception\Argument("Invalid type");
     }
     Events::fire("framework.database.initialize.after", array($this->type, $this->options));
     switch ($this->type) {
         case "mysql":
             return new Database\Connector\Mysql($this->options);
             break;
         default:
             throw new Exception\Argument("Invalid type");
             break;
     }
 }
Beispiel #3
0
 public function initialize()
 {
     $type = $this->getType();
     if (empty($type)) {
         $configuration = Registry::get('configuration');
         if ($configuration) {
             $configuration = $configuration->initialize();
             $parsed = $configuration->parse('configuration/database');
             if (!empty($parsed->database->default) && !empty($parsed->database->default->type)) {
                 $type = $parsed->database->default->type;
                 unset($parsed->database->default->type);
                 $this->__construct(array('type' => $type, 'options' => $parsed->database->default));
             }
         }
     }
     if (empty($type)) {
         throw new Exception\Argument('Invalid type');
     }
     switch ($type) {
         case 'mysql':
             return new Database\Connector\MySql($this->getOptions());
             break;
         default:
             throw new Exception\Argument('Invalid type');
             break;
     }
 }
Beispiel #4
0
 public function performance($course)
 {
     $session = Registry::get("session");
     $perf = Registry::get("MongoDB")->performance;
     $week = (new \DateTime(date('Y-m-d')))->format("W");
     $performance = array();
     $classroom = self::$_classroom;
     $record = $perf->findOne(array('user_id' => (int) self::$_student->user_id, 'course_id' => (int) $course->id, 'year' => date('Y'), 'classroom_id' => (int) $classroom->id));
     $d = StringMethods::month_se();
     $start = (int) (new \DateTime($d['start']))->format("W");
     if ($start == 53) {
         $start = 1;
     }
     $end = (int) (new \DateTime($d['end']))->format("W");
     $monthly = array();
     if (isset($record)) {
         $performance['course'] = $course->title;
         $performance['teacher'] = \User::first(array("id = ?" => $record['teacher_id']), array("name"))->name;
         foreach ($record['track'] as $track) {
             $week = $track['week'];
             if ($week <= $end && $week >= $start) {
                 $monthly[] = $track['grade'];
             }
             $performance['tracking'][] = $track;
         }
     }
     return array('performance' => $performance, 'monthly' => $monthly);
 }
Beispiel #5
0
 public function fbLogin()
 {
     $this->JSONview();
     $view = $this->getActionView();
     $session = Registry::get("session");
     if (RequestMethods::post("action") == "fbLogin" && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
         // process the registration
         $fbid = RequestMethods::post("fbid");
         $access_token = RequestMethods::post("access_token");
         $user = !$this->user ? User::first(["fbid = ?" => $fbid]) : $this->user;
         if (!$user) {
             try {
                 $user = $this->_register();
             } catch (\Exception $e) {
                 $view->set("success", false);
                 return;
             }
         }
         $this->setUser($user);
         $redirect = RequestMethods::post("loc", "");
         if ($redirect != '') {
             $token = Shared\Markup::uniqueString();
             $session->set('CampaignAccessToken', $token);
             $view->set("redirect", "/" . $redirect . "/{$token}");
         }
         $view->set("success", true);
     } else {
         $view->set("success", false);
     }
 }
Beispiel #6
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     // connect to database
     $database = Registry::get("database");
     $database->connect();
     // schedule: load user from session
     Events::add("framework.router.beforehooks.before", function ($name, $parameters) {
         $session = Registry::get("session");
         $controller = Registry::get("controller");
         $user = $session->get("user");
         if ($user) {
             $controller->user = \User::first(array("id = ?" => $user));
         }
     });
     // schedule: save user to session
     Events::add("framework.router.afterhooks.after", function ($name, $parameters) {
         $session = Registry::get("session");
         $controller = Registry::get("controller");
         if ($controller->user) {
             $session->set("user", $controller->user->id);
         }
     });
     // schedule: disconnect from database
     Events::add("framework.controller.destruct.after", function ($name) {
         $database = Registry::get("database");
         $database->disconnect();
     });
 }
Beispiel #7
0
 public function initialize()
 {
     $type = $this->getType();
     if (empty($type)) {
         $configuration = Registry::get('configuration');
         if ($configuration) {
             $configuration = $configuration->initialize();
             $parsed = $configuration->parse('configuration/session');
             if (!empty($parsed->session->default) && !empty($parsed->session->default->type)) {
                 $type = $parsed->session->default->type;
                 unset($parsed->session->default->type);
                 $this->__construct(array('type' => $type, 'options' => (array) $parsed->session->default));
             }
         }
     }
     if (empty($type)) {
         throw new Exception\Argument('Invalid type');
     }
     switch ($type) {
         case 'server':
             return new Session\Driver\Server($this->getOptions());
             break;
         default:
             throw new Exception\Argument('Invalid type');
             break;
     }
 }
Beispiel #8
0
 public function initialize()
 {
     Events::fire("framework.session.initialize.before", array($this->type, $this->options));
     if (!$this->type) {
         $configuration = Registry::get("configuration");
         if ($configuration) {
             $configuration = $configuration->initialize();
             $parsed = $configuration->parse("configuration/session");
             if (!empty($parsed->session->default) && !empty($parsed->session->default->type)) {
                 $this->type = $parsed->session->default->type;
                 unset($parsed->session->default->type);
                 $this->options = (array) $parsed->session->default;
             }
         }
     }
     if (!$this->type) {
         throw new Exception\Argument("Invalid type");
     }
     Events::fire("framework.session.initialize.after", array($this->type, $this->options));
     switch ($this->type) {
         case "server":
             return new Session\Driver\Server($this->options);
             break;
         default:
             throw new Exception\Argument("Invalid type");
             break;
     }
 }
Beispiel #9
0
 /**
  * See stats of a keyword
  * @before _secure, memberLayout
  */
 public function stats($keyword_id)
 {
     $keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => true));
     $this->_authority($keyword);
     $rank = Registry::get("MongoDB")->rank;
     $r = $rank->findOne(['keyword_id' => (int) $keyword->id, 'created' => date('Y-m-d')]);
     if ($keyword->live && !$r) {
         try {
             Shared\Service\Serp::record(array($keyword));
         } catch (\Exception $e) {
         }
     }
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $i = 0;
     $obj = array();
     while ($start_time < $end_time) {
         $start_time = strtotime($start_date . " +{$i} day");
         $date = date('Y-m-d', $start_time);
         $record = $rank->findOne(array('created' => $date, 'keyword_id' => (int) $keyword->id));
         if (isset($record)) {
             $position = $record['position'];
         } else {
             $position = 0;
         }
         $obj[] = array('y' => $date, 'a' => $position);
         ++$i;
     }
     $view->set("keyword", $keyword)->set("label", "Rank")->set("data", ArrayMethods::toObject($obj));
 }
 public function __construct()
 {
     parent::__construct();
     $this->_rules = array();
     $this->_errors = array();
     $this->input = Registry::get('input');
 }
Beispiel #11
0
 /**
  * @before _secure, _admin
  */
 public function index()
 {
     $this->seo(array("title" => "Dashboard", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $database = Registry::get("database");
     $total = $database->query()->from("transactions", array("SUM(amount)" => "earn"))->all();
     $view->set("earn", round($payments[0]["earn"], 2));
 }
Beispiel #12
0
 public function getTest()
 {
     $cache = Registry::get('cache');
     if ($this->_ajax()) {
         $test = array("Chapman");
         echo json_encode($test);
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->session = Registry::get('session');
     $this->cookie = Registry::get('cookie');
     $this->input = Registry::get('input');
     $this->validator = Registry::get('validator');
 }
Beispiel #14
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     $database = \Framework\Registry::get('database');
     $database->_connect();
     $session = \Framework\Registry::get('session');
     $user = unserialize($session->get('user', null));
     $this->setUser($user);
 }
Beispiel #15
0
 public static function delete()
 {
     $database = Framework\Registry::get('database');
     Framework\Test::add(function () use($database) {
         $example = new Model\Example(array("id" => 2));
         $example->delete();
         return Model\Example::count() == 1;
     }, "Model deletes rows", "Model");
 }
Beispiel #16
0
 /**
  * @before _secure
  */
 public function all()
 {
     $this->noview();
     $results = Event::all(array("organization_id = ?" => Registry::get("session")->get("organization")->id));
     $events = array();
     foreach ($results as $r) {
         $events[] = array("title" => $r->title, "start" => $this->returnTime($r->start), "end" => $this->returnTime($r->start), "allDay" => $r->allDay ? true : false, "id" => $r->id, "className" => "event");
     }
     echo json_encode($events);
 }
Beispiel #17
0
 public static function updateRaw($table, $find, $set, $opts = [])
 {
     $collection = Registry::get("MongoDB")->{$table};
     $many = $opts['many'] ?? false;
     if ($many) {
         $collection->updateMany($find, $set);
     } else {
         $collection->updateOne($find, $set);
     }
 }
Beispiel #18
0
 /**
  * Запуск приложения
  *
  * @param array $configArray Массив конфигурации
  * @throws \Exception
  */
 public static function run(array $configArray)
 {
     $request = new Request();
     $config = new Config($configArray);
     Registry::set('request', $request);
     Registry::set('config', $config);
     Registry::set('pdo', new PDO('mysql:host=' . $config->get('db')['host'] . ';dbname=' . $config->get('db')['dbname'] . ';charset=utf8', $config->get('db')['user'], $config->get('db')['passwd']));
     $routing = new Routing($request->server('REQUEST_URI'));
     Registry::set('routing', $routing);
     $routing->run();
 }
Beispiel #19
0
 /**
  * @protected
  * Will set variables to all the views of a controller
  */
 public function render()
 {
     $session = Registry::get("session");
     if ($this->actionView) {
         $this->actionView->set("educator", $session->get("educator"))->set("scholar", $session->get("scholar"))->set("organization", $session->get("organization"));
     }
     if ($this->layoutView) {
         $this->layoutView->set("educator", $session->get("educator"))->set("scholar", $session->get("scholar"))->set("organization", $session->get("organization"));
     }
     parent::render();
 }
Beispiel #20
0
 public function profile()
 {
     $session = Registry::get('session');
     $user = unserialize($session->get('user', null));
     if (empty($user)) {
         $user = new stdClass();
         $user->first = 'Mr.';
         $user->last = 'Smith';
     }
     $this->getActionView()->set('user', $user);
 }
Beispiel #21
0
 public function getConnector()
 {
     if (empty($this->_connector)) {
         $database = Registry::get('database');
         if (!$database) {
             throw new Exception\Connector('No connector available');
         }
         $this->_connector = $database->initialize();
     }
     return $this->_connector;
 }
Beispiel #22
0
 public function __construct()
 {
     parent::__construct();
     $this->database = Registry::get('database');
     if ($this->database !== null) {
         $this->database->connect();
     }
     $this->session = Registry::get('session');
     $this->cookie = Registry::get('cookie');
     $this->input = Registry::get('input');
 }
Beispiel #23
0
 protected function _checkLogin()
 {
     if (RequestMethods::post("action") == "logmein") {
         $username = RequestMethods::post("username");
         $password = RequestMethods::post("password");
         $user = User::first(array("username = ?" => $username, "live = ?" => true));
         if (!$user) {
             return array("error" => "Invalid username/password");
         }
         if (!Markup::checkHash($password, $user->password)) {
             return array("error" => "Invalid username/password");
         }
         $session = Registry::get("session");
         $this->setUser($user);
         if ($user->admin) {
             self::redirect("/admin");
         }
         $headers = getallheaders();
         $scholar = Scholar::first(array("user_id = ?" => $user->id));
         if ($scholar) {
             $session->set('scholar', $scholar);
             $organization = Organization::first(array("id = ?" => $scholar->organization_id));
             $session->set('organization', $organization);
             if (isset($headers["X-Student-App"])) {
                 $meta = $this->_meta($user, "student");
                 return array("success" => true, "meta" => $meta, "scholar" => $scholar);
             } else {
                 self::redirect("/student");
             }
         }
         $organization = Organization::first(array("user_id = ?" => $user->id));
         if ($organization) {
             $session->set('organization', $organization);
             self::redirect("/school");
         }
         $educator = Educator::first(array("user_id = ?" => $user->id));
         if ($educator) {
             $session->set('educator', $educator);
             $organization = Organization::first(array("id = ?" => $educator->organization_id));
             $session->set('organization', $organization);
             if (isset($headers["X-Teacher-App"])) {
                 $meta = $this->_meta($user, "teacher");
                 return array("success" => true, "meta" => $meta, "educator" => $educator);
             } else {
                 self::redirect("/teacher");
             }
         }
         return array("error" => "Something went wrong please try again later");
     } else {
         return array("error" => "Invalid Request");
     }
 }
Beispiel #24
0
 /**
  * The Main Method to return SendGrid Instance
  * 
  * @return \SendGrid\SendGrid Instance of Sendgrid
  */
 protected static function _sendgrid()
 {
     if (isset(self::$_conf['sendgrid'])) {
         return self::$_conf['sendgrid'];
     }
     $configuration = Registry::get("configuration");
     $parsed = $configuration->parse("configuration/mail");
     if (!empty($parsed->mail->sendgrid) && !empty($parsed->mail->sendgrid->username)) {
         $sendgrid = new \SendGrid\SendGrid($parsed->mail->sendgrid->username, $parsed->mail->sendgrid->password);
         self::$_conf['sendgrid'] = $sendgrid;
     }
     return self::$_conf['sendgrid'];
 }
Beispiel #25
0
 protected static function _mailgun()
 {
     if (isset(self::$_conf['mailgun'])) {
         return self::$_conf['mailgun'];
     }
     $configuration = Registry::get("configuration");
     $mailConf = $configuration->parse("configuration/mail")->mailgun;
     $mg = new \Mailgun\Mailgun($mailConf->key);
     self::$_conf['mailgun'] = $mg;
     self::$_conf['domain'] = $mailConf->domain;
     self::$_conf['team'] = $mailConf->platform;
     return self::$_conf['mailgun'];
 }
Beispiel #26
0
 protected function _execute($type)
 {
     $mongo = Registry::get("MongoDB");
     $ping = $mongo->ping;
     $ping_stats = $mongo->ping_stats;
     $records = $ping->find(array('live' => 1, 'interval' => $type));
     foreach ($records as $r) {
         $host = preg_replace('/^https?:\\/\\//', '', $r['url']);
         $ping = new JJG\Ping($host);
         $latency = $ping->ping('fsockopen');
         // false on failure (server-down)
         $ping_stats->insert(array('ping_id' => $r['_id'], 'created' => new \MongoDate(), 'latency' => $latency));
     }
 }
Beispiel #27
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     // Schedule: Update the users activity in the active users table
     Event::add("framework.router.beforehooks.after", function ($name, $parameters) {
         $session = Registry::get('session');
         $user = $session->get('user');
         $time = date("Y-m-d H:i:s");
         if ($user) {
             // @todo REPLACE INTO very Mysql specific build merge method for alternate db
             Database::replace("REPLACE INTO user_active VALUES (:user, :time)", array(':user' => $user, ':time' => $time));
         }
     });
 }
Beispiel #28
0
 /**
  * @before _secure, changeLayout, _admin
  */
 public function domains()
 {
     $this->seo(array("title" => "Domains", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "domain") {
         $p = Registry::get("MongoDB")->domains;
         $domain = new Meta(array("user_id" => $this->user->id, "property" => "domain", "value" => RequestMethods::post("domain")));
         $domain->save();
         $p->insert(array('domain' => $domain->value));
         $view->set("message", "Domain Added Successfully");
     }
     $domains = Meta::all(array("property=?" => "domain"));
     $view->set("domains", $domains);
 }
Beispiel #29
0
 public static function record($k)
 {
     $socials = Registry::get("MongoDB")->socials;
     $today = new \MongoDate(strtotime(date('Y-m-d')));
     $record = $socials->findOne(array('keyword_id' => (int) $k->id, 'user_id' => (int) $k->user_id, 'created' => $today));
     if (isset($record)) {
         return false;
     }
     $responses = self::getStats($k->link);
     foreach ($responses as $r) {
         $doc = array('count_type' => $r["count_type"], 'count' => (string) $r["count"], 'social_media' => $r["social_media"], 'user_id' => (int) $k->user_id, 'live' => true, 'created' => $today, 'keyword_id' => (int) $k->id);
         $socials->insert($doc);
     }
 }
Beispiel #30
0
 protected static function _init()
 {
     $session = Registry::get("session");
     if (!self::$_courses || !self::$_classes) {
         if (!$session->get('TeacherService:$courses') || !$session->get('TeacherService:$classes')) {
             $teaches = \Teach::all(array("user_id = ?" => self::$_teacher->user_id));
             $session->set('TeacherService:$teaches', $teaches);
             $session->set('TeacherService:$courses', self::_findCourses($teaches));
             $session->set('TeacherService:$classes', self::_findClasses($teaches));
         }
         self::$_courses = $session->get('TeacherService:$courses');
         self::$_classes = $session->get('TeacherService:$classes');
         self::$_teaches = $session->get('TeacherService:$teaches');
     }
 }