Esempio n. 1
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);
 }
Esempio n. 2
0
 /**
  * Checking to see that the inspector is set, handling the getProperty() methods, and handling the setProperty() methods.
  * @param type $name
  * @param type $arguments
  * @return \Framework\Base
  * @throws Exception
  * @throws type
  */
 public function __call($name, $arguments)
 {
     if (empty($this->_inspector)) {
         throw new Exception("Call parent::__construct!");
     }
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9_]+)\$");
     if (sizeof($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@read"])) {
                 throw $this->_getExceptionForWriteonly($normalized);
             }
             if (isset($this->{$property})) {
                 return $this->{$property};
             }
             return null;
         }
     }
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9_]+)\$");
     if (sizeof($setMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@write"])) {
                 throw $this->_getExceptionForReadonly($normalized);
             }
             $this->{$property} = $arguments[0];
             return $this;
         }
     }
     throw $this->_getExceptionForImplementation($name);
 }
Esempio n. 3
0
 /**
  * @before _secure, _student
  */
 public function index()
 {
     $this->setSEO(array("title" => "Students | Dashboard"));
     $this->getLayoutView()->set("cal", true);
     $view = $this->getActionView();
     $session = Registry::get("session");
     $enrollment = Enrollment::first(array("user_id = ?" => $this->user->id));
     $classroom = Classroom::first(array("id = ?" => $enrollment->classroom_id));
     $grade = Grade::first(array("id = ?" => $classroom->grade_id));
     $courses = StudentService::$_courses;
     $d = StringMethods::month_se();
     // find average attendance for the month
     $service = new \Shared\Services\Attendance();
     $attendances = $service->find($d['start'], $d['end']);
     $present = 0;
     $total = 0;
     foreach ($attendances as $a) {
         $total++;
         if ($a['title'] == "Present") {
             $present++;
         }
     }
     $avg = (string) ($present / $total * 100);
     // find total assignments
     $service = new \Shared\Services\Assignment();
     $asmt = $service->total($classroom, $courses);
     $view->set("enrollment", $enrollment)->set("classroom", $classroom)->set("grade", $grade)->set("courses", $courses)->set("assignments", $asmt)->set("attendance", substr($avg, 0, 5));
 }
Esempio n. 4
0
 function get($url, $parameters = array())
 {
     if (!empty($parameters)) {
         $url .= StringMethods::indexOf($url, "?") ? "&" : "?";
         $url .= is_string($parameters) ? $parameters : http_build_query($parameters, "", "&");
     }
     return $this->request("GET", $url);
 }
Esempio n. 5
0
 protected function _partial($tree, $content)
 {
     $address = trim($tree["raw"], " /");
     if (StringMethods::indexOf($address, "http") != 0) {
         $host = RequestMethods::server("HTTP_HOST");
         $address = "http://{$host}/{$address}";
     }
     $request = new Request();
     $response = addslashes(trim($request->get($address)));
     return "\$_text[] = \"{$response}\";";
 }
Esempio n. 6
0
File: model.php Progetto: soanni/mvc
 public function getTable()
 {
     if (empty($this->_table)) {
         $low = strtolower(StringMethods::singular(get_class($this)));
         $slash = strpos($low, "\\");
         if ($slash) {
             $this->_table = substr($low, $slash + 1);
         } else {
             $this->_table = $low;
         }
     }
     return $this->_table;
 }
Esempio n. 7
0
 /**
  * Manage all serps created by the member
  * @before _secure, memberLayout
  */
 public function manage()
 {
     $this->seo(array("title" => "Serp | Manage", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $keywords = \Keyword::all(array("user_id = ?" => $this->user->id, "serp" => true));
     $view->set("serps", $keywords);
     $now = strtotime(date('Y-m-d'));
     $user_registered = strtotime(StringMethods::only_date($this->user->created));
     $datediff = $now - $user_registered;
     $datediff = floor($datediff / (60 * 60 * 24));
     if ($datediff < 7) {
         $view->set("message", true);
     }
 }
Esempio n. 8
0
 /**
  * If the template statement has specific argument format
  * return as array the contents of the braces {...}
  * @param  string $source     Chunk of template being parsed
  * @param  string $expression Content of tags
  * @return array
  */
 protected function _arguments($source, $expression)
 {
     $args = $this->_array($expression, array($expression => array("opener" => "{", "closer" => "}")));
     $tags = $args["tags"];
     $arguments = array();
     $sanitized = StringMethods::sanitize($expression, "()[],.<>*\$@");
     foreach ($tags as $i => $tag) {
         $sanitized = str_replace($tag, "(.*)", $sanitized);
         $tags[$i] = str_replace(array("{", "}"), "", $tag);
     }
     if (preg_match("#{$sanitized}#", $source, $matches)) {
         foreach ($tags as $i => $tag) {
             $arguments[$tag] = $matches[$i + 1];
         }
     }
     return $arguments;
 }
Esempio n. 9
0
 public function __call($name, $arguments)
 {
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9]+)\$");
     if (sizeof($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             return $this->{$property};
         }
     }
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9]+)\$");
     if (sizeof($setMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $this->{$property} = $arguments[0];
             return;
         }
     }
 }
Esempio n. 10
0
 /**
  * Check the Inspector is set and handle and getProperty(),
  * setProperty() methods based upon metadata of defined properties
  * @param  string $name      Name of property to be inspected
  * @param  array $arguments Paramerters to be passed to property
  */
 public function __call($name, $arguments)
 {
     // Check class calls parent construct
     if (empty($this->_inspector)) {
         throw new \Exception("Call parent::_construct!");
     }
     // If reading permissable return property value
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9]+)\$");
     if (sizeof($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@read"])) {
                 throw $this->_getExceptionForWriteonly($normalized);
             }
             if (isset($this->{$property})) {
                 return $this->{$property};
             }
             return null;
         }
     }
     // If writing is permissable set property value
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9]+)\$");
     if (sizeof($setMatches > 0)) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@write"])) {
                 throw $this->_getExceptionForReadonly($normalized);
             }
             $this->{$property} = $arguments[0];
             return $this;
         }
     }
     // If property does not exist in a class thow exception
     throw $this->_getExceptionForImplementation($name);
 }
Esempio n. 11
0
 /**
  * Evaluates a $source string to determine if it matches a tag or statement.
  * @param type $source
  * @return type
  */
 public function match($source)
 {
     $type = null;
     $delimiter = null;
     foreach ($this->_map as $_delimiter => $_type) {
         if (!$delimiter || StringMethods::indexOf($source, $type["opener"]) == -1) {
             $delimiter = $_delimiter;
             $type = $_type;
         }
         $indexOf = StringMethods::indexOf($source, $_type["opener"]);
         if ($indexOf > -1) {
             if (StringMethods::indexOf($source, $type["opener"]) > $indexOf) {
                 $delimiter = $_delimiter;
                 $type = $_type;
             }
         }
     }
     if ($type == null) {
         return null;
     }
     return array("type" => $type, "delimiter" => $delimiter);
 }
Esempio n. 12
0
 /**
  * Begins by getting a list of columns and iterating over that list. For each column, we determine whether validation should occur.
  * We then split the @validate metadata into a list of validation conditions. If a condition has arguments, we extract the arguments.
  * We then run each validation method on the column data and generate error messages for those validation conditions that failed.
  * 
  * @return type
  * @throws Exception\Validation
  */
 public function validate()
 {
     $this->_errors = array();
     foreach ($this->columns as $column) {
         if ($column["validate"]) {
             $pattern = "#[a-z]+\\(([a-zA-Z0-9, ]+)\\)#";
             $raw = $column["raw"];
             $name = $column["name"];
             $validators = $column["validate"];
             $label = $column["label"];
             $defined = $this->getValidators();
             foreach ($validators as $validator) {
                 $function = $validator;
                 $arguments = array($this->{$raw});
                 $match = StringMethods::match($validator, $pattern);
                 if (count($match) > 0) {
                     $matches = StringMethods::split($match[0], ",\\s*");
                     $arguments = array_merge($arguments, $matches);
                     $offset = StringMethods::indexOf($validator, "(");
                     $function = substr($validator, 0, $offset);
                 }
                 if (!isset($defined[$function])) {
                     throw new Exception\Validation("The {$function} validator is not defined");
                 }
                 $template = $defined[$function];
                 if (!call_user_func_array(array($this, $template["handler"]), $arguments)) {
                     $replacements = array_merge(array($label ? $label : $raw), $arguments);
                     $message = $template["message"];
                     foreach ($replacements as $i => $replacement) {
                         $message = str_replace("{{$i}}", $replacement, $message);
                     }
                     if (!isset($this->_errors[$name])) {
                         $this->_errors[$name] = array();
                     }
                     $this->_errors[$name][] = $message;
                 }
             }
         }
     }
     return !sizeof($this->errors);
 }
Esempio n. 13
0
 /**
  * Get the size of the field be it a number or a string
  * @param  string $attributes Field being tested
  * @param  mixed $value       Value held in field
  * @return mixed
  */
 protected function _size($field, $value)
 {
     if (is_numeric($value) and $this->_hasRule($field, $this->_numericRules)) {
         return $this->fields[$field];
     } else {
         if (RequestMethods::file($field)) {
             return $value['size'] / 1024;
         } else {
             return StringMethods::length(trim($value));
         }
     }
 }
Esempio n. 14
0
 public static function dateArray($arr)
 {
     $result = [];
     foreach ($arr as $key => $value) {
         $date = \Framework\StringMethods::only_date($key);
         $result[$date] = $value;
     }
     return $result;
 }
Esempio n. 15
0
 /**
  * It is the first public construct handler we have used in any of our template implementations.
  * It modifies the value string from something resembling $_text =  "foo"; to something resembling foo.
  * @param type $key
  * @param type $value
  */
 public function set($key, $value)
 {
     if (StringMethods::indexOf($value, "\$_text") > -1) {
         $first = StringMethods::indexOf($value, "\"");
         $last = StringMethods::lastIndexOf($value, "\"");
         $value = stripslashes(substr($value, $first + 1, $last - $first - 1));
     }
     if (is_array($key)) {
         $key = $this->_getKey($key);
     }
     $this->_setValue($key, $value);
 }
Esempio n. 16
0
 /**
  * @before _secure, _vendor
  */
 public function reports()
 {
     $this->seo(array("title" => "Test Report", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $centre_id = RequestMethods::get("centre_id", $this->member->centre_id);
     $appointments = Appointment::all(array("centre_id = ?" => $centre_id), array("id", "patient_id", "user_id", "service_id", "start"));
     $view->set("appointments", $appointments);
     if (RequestMethods::post("action") == "report") {
         $appt_id = RequestMethods::post("appointment_id");
         if (!array_key_exists($appt_id, $appointments)) {
             $view->set("message", "Invalid request!!");
             return;
         }
         $appt = $appointments[$appt_id];
         $job = Job::first(array("appointment_id = ?" => $appt->id));
         if (!$job) {
             $view->set("message", "Invalid Request!!");
             return;
         }
         // find emails
         $user = User::first(array("id = ?" => $appt->user_id), array("email"));
         $patient = User::first(array("id = ?" => $appt->patient_id), array("email"));
         if (!$user->email && !$patient->email) {
             $view->set("message", "No email to send message to");
             return;
         } elseif (!$patient->email) {
             $emails = $user->email;
         } else {
             $emails = array($user->email, $patient->email);
             $emails = array_unique($emails);
         }
         // upload file
         $file = $this->_upload('file', "files", array("extensions" => "pdf"));
         if (!$file) {
             $view->set("message", "File upload failed!!");
             return;
         }
         $file_path = APP_PATH . '/public/assets/uploads/files/' . $file;
         $name = $this->organization->name;
         Shared\Services\Mail::notify(array("emails" => $emails, "delivery" => "sendgrid", "template" => "sendReport", "lab" => $name, "apptime" => \Framework\StringMethods::datetime_to_text($appt->start), "subject" => RequestMethods::post("report_detail"), "attachment" => $file_path));
         unlink($file_path);
         $job->live = 1;
         $job->save();
         $view->set("message", "Sent Successfully");
     }
 }
Esempio n. 17
0
 public function popularOffers()
 {
     $this->seo(array("title" => "Popular Offers", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $organizations = Organization::all(array("live = ?" => true), array("id", "name"));
     $packages = Package::all(array(), array("title", "id"));
     $tests = Test::all(array(), array("title", "id"));
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $offers = Offer::all(array("live = ?" => 1), array("*"), "created", "desc", $limit, $page);
     $total = (int) Offer::count(array("live = ?" => 1));
     $results = array();
     foreach ($offers as $o) {
         $type = array();
         switch ($o->property) {
             case 'test':
                 $type['title'] = $tests[$o->property_id]->title;
                 $type['id'] = $o->property_id;
                 break;
             case 'package':
                 $type['title'] = $packages[$o->property_id]->title;
                 $type['id'] = $o->property_id;
                 break;
         }
         $data = array("id" => $o->id, "start" => StringMethods::datetime_to_text($o->start), "end" => StringMethods::datetime_to_text($o->end), "percent" => $o->percent, "type" => $o->property, "type_title" => $type['title'], "type_id" => $type['id'], "lab" => $organizations[$o->organization_id], "lab_id" => $o->organization_id);
         $results[] = ArrayMethods::toObject($data);
     }
     $view->set("offers", $results)->set("total", $total);
 }
Esempio n. 18
0
 /**
  * Return user defined table name or default to
  * singular form of current Model's class name
  * @return string Table name
  */
 public function getTable()
 {
     if (empty($this->_table)) {
         $this->_table = strtolower(StringMethods::singular(get_class($this)));
     }
     return $this->_table;
 }
Esempio n. 19
0
 protected function _parse($comment)
 {
     $meta = array();
     $pattern = "(@[a-zA-Z]+\\s*[a-zA-Z0-9, ()_]*)";
     $matches = StringMethods::match($comment, $pattern);
     if ($matches != null) {
         foreach ($matches as $match) {
             $parts = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($match, "[\\s]", 2)));
             $meta[$parts[0]] = true;
             if (sizeof($parts) > 1) {
                 $meta[$parts[0]] = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($parts[1], ",")));
             }
         }
     }
     return $meta;
 }
Esempio n. 20
0
 /**
  * Returns an array of objects
  * @return array|string Array of objects of \stdClass (success), Error Message (failure)
  */
 protected function _getSiteMaps(&$gClient, $website, $opts = array())
 {
     try {
         $webmaster = new Google_Service_Webmasters($gClient);
         $sitemaps = $webmaster->sitemaps;
         $response = $sitemaps->listSitemaps($website, $opts);
         $response = $response->getSitemap();
         $result = array();
         foreach ($response as $r) {
             $contents = $r->getContents();
             $content = array();
             foreach ($contents as $c) {
                 $content[] = array("type" => $c->type, "submitted" => $c->submitted, "indexed" => $c->indexed);
             }
             $result[] = array("path" => $r->path, "errors" => $r->errors, "pending" => $r->isPending, "type" => $r->type, "warnings" => $r->warnings, "lastDownloaded" => array_shift(StringMethods::match($r->lastDownloaded, "(.*)T")), "lastSubmitted" => array_shift(StringMethods::match($r->lastSubmitted, "(.*)T")), "contents" => $content);
         }
         $result = ArrayMethods::toObject($result);
     } catch (\Exception $e) {
         $result = $e->getMessage();
     }
     return $result;
 }