Jump to content

Destramic

Members
  • Content count

    942
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Destramic

  • Rank
    Prolific Member
  • Birthday 10/06/1986

Profile Information

  • Gender
    Male
  • Location
    United Kingdom

Contact Methods

  • Skype
    destramic

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Destramic

    pattern help

    thank kicken for seeing my errors, what on earth was i donig with the regex! (head shaking) ive made the changes to my query now which gets the users assigned department and task type id's and compares it with the the ids from the appointments SELECT SUM(task_appointment.count) AS `count` FROM ((SELECT COUNT(pt.property_task_id) AS `count`, p.gas_service_expiry_date AS `priority_date`, d.department_id, tt.task_type_id, pt.status FROM property_tasks pt INNER JOIN properties p ON p.property_id = pt.property_id INNER JOIN task_types tt ON tt.task_type_id = pt.task_type_id INNER JOIN trade_task_types ttt ON ttt.task_type_id = tt.task_type_id INNER JOIN trades t ON t.trade_id = ttt.trade_id INNER JOIN departments d ON d.department_id = pt.department_id INNER JOIN property_appointments pa ON pa.property_task_id = pt.property_task_id WHERE tt.task_type = "Gas Service" AND d.department = "Gas Servicing" AND IF(pa.completed_timestamp, pa.completed_timestamp, pa.end_date) < NOW() ) UNION ALL (SELECT COUNT(pt.property_task_id) AS `count`, DATE_FORMAT(DATE_ADD(pt.created_timestamp, INTERVAL pt.priority_days DAY), "%Y-%m-%d") AS `priority_date`, d.department_id, tt.task_type_id, pt.status FROM property_tasks pt INNER JOIN properties p ON p.property_id = pt.property_id INNER JOIN task_types tt ON tt.task_type_id = pt.task_type_id INNER JOIN trade_task_types ttt ON ttt.task_type_id = tt.task_type_id INNER JOIN trades t ON t.trade_id = ttt.trade_id INNER JOIN departments d ON d.department_id = pt.department_id INNER JOIN property_appointments pa ON pa.property_task_id != pt.property_task_id WHERE tt.task_type != "Gas Service" AND d.department != "Gas Servicing" )) task_appointment INNER JOIN (SELECT u.user_id, GROUP_CONCAT(d.department_id) AS `department_ids`, GROUP_CONCAT(tt.task_type_id) AS `task_type_ids` FROM users u INNER JOIN trade_departments td ON td.user_id = u.user_id INNER JOIN departments d ON d.department_id = td.department_id INNER JOIN user_trades ut ON ut.user_id = u.user_id INNER JOIN trades t ON t.trade_id = ut.trade_id INNER JOIN trade_task_types ttt ON ttt.trade_id = t.trade_id INNER JOIN task_types tt ON tt.task_type_id = ttt.task_type_id ) user WHERE status = "Active" AND task_appointment.department_id IN (user.department_ids) AND task_appointment.task_type_id IN (user.task_type_ids) AND user.user_id = 1 ORDER BY task_appointment.priority_date ASC it comes back with the correct count which is good...any final thouhts? thank you again
  2. Destramic

    pattern help

    maybe i should post in the mysql section but i really feel this is a regex issue. my query is just to count unallocated/uncompleted tasks and appointments here is the query SELECT SUM(task_appointment.count) AS `count` FROM ((SELECT COUNT(pt.property_task_id) AS `count`, p.gas_service_expiry_date AS `priority_date`, d.department, GROUP_CONCAT(t.trade) AS `trades`, pt.status FROM property_tasks pt INNER JOIN properties p ON p.property_id = pt.property_id INNER JOIN task_types tt ON tt.task_type_id = pt.task_type_id INNER JOIN trade_task_types ttt ON ttt.task_type_id = tt.task_type_id INNER JOIN trades t ON t.trade_id = ttt.trade_id INNER JOIN departments d ON d.department_id = pt.department_id INNER JOIN property_appointments pa ON pa.property_task_id = pt.property_task_id AND tt.task_type = "Gas Service" AND d.department = "Gas Servicing" AND IF(psa.completed_timestamp, psa.completed_timestamp, psa.end_date) < NOW() ) UNION ALL (SELECT COUNT(pt.property_task_id) AS `count`, DATE_FORMAT(DATE_ADD(pt.created_timestamp, INTERVAL pt.priority_days DAY), "%Y-%m-%d") AS `priority_date`, d.department, GROUP_CONCAT(t.trade) AS `trades`, pt.status FROM property_tasks pt INNER JOIN properties p ON p.property_id = pt.property_id INNER JOIN task_types tt ON tt.task_type_id = pt.task_type_id INNER JOIN trade_task_types ttt ON ttt.task_type_id = tt.task_type_id INNER JOIN trades t ON t.trade_id = ttt.trade_id INNER JOIN departments d ON d.department_id = pt.department_id INNER JOIN property_appointments pa ON pa.property_task_id != pt.property_task_id AND tt.task_type != "Gas Service" AND d.department != "Gas Servicing" )) task_appointment INNER JOIN (SELECT GROUP_CONCAT(d.department) AS `departments`, GROUP_CONCAT(t.trade) AS `trades` FROM users u INNER JOIN trade_departments td ON td.department_id = u.user_id INNER JOIN departments d ON d.department_id = td.user_id INNER JOIN user_trades ut ON ut.user_id = u.user_id INNER JOIN trades t ON t.trade_id = ut.trade_id WHERE u.user_id = 1 ) user WHERE user.departments REGEXP REPLACE(task_appointment.department, ',', '|') > 0 AND user.trades REGEXP REPLACE(task_appointment.trades, ',', '|') > 0 AND status = "Active" ORDER BY task_appointment.priority_date ASC note the unions are almost simular but draw different rows 1st being gas servicing under certian conditions and 2nd anything else thank you
  3. Destramic

    pattern help

    i have two CONCAT_GROUPS in my sql query, 1 being the users trades and the other being the trades required for the a particular task. What im tyring to do is to find if the user has the correct trade for a particular task. here is what ive got so far which does work, but doesnt match the words as i want, for instance if @user_trades = REPLACE('plumb,electrician', ',', '|'), it will still match for plumb SELECT @user_trades := REPLACE('plumber,electrician', ',', '|'), // regex @task_trades := 'painter,plumber', // string @task_trades REGEXP @user_trades how can i make the regex match a trade 100% or nothing thank you
  4. Destramic

    select and insert

    i can pass the relevant ID's over infact, i don't know what i didnt do that instead of complicating things! the simpliest ways are always the best. thank you for the insight on how i could of done the query also.
  5. Destramic

    select and insert

    im unable to find an example when it comes to select and insert in my particular case, so any help would be greatly appreciated. here is my 2 select queries which retrieve the department_id and task_type_id. what i want to do it is use those two values inside an insert as well as adding additional values. SELECT department_id FROM departments WHERE department = "Gas Servicing" SELECT task_type_id FROM task_Types WHERE task_type = "Gas Service" INSERT INTO property_appointments (property_id, department_id, task_type_id, notes, priority_days) VALUES (:property_id, ?, ?, :notes, 1) is this possible please? thank you
  6. Destramic

    calculate times

    Beautiful stuff barand, although I've dropped the task statuses and added status, start time stamp and end timestamp to my tasks tablet and did it that way. Ps. I've still used what you've done for me previosuly but adding this will alter task times depending on task start and end, making things more accurate. Thank you again for your efforts
  7. Destramic

    calculate times

    ok brillant, i'll do it that way, thank you for your help again barand
  8. Destramic

    calculate times

    i have no idea how to do this in all honesty, hence my post. i have a table called task_statuses, which records the statuses and times of a given task, and those tasks are allocated to an engineer for the day. before the engineer is at the task he/she will hit a button called Notify, which will send an sms and email to notify an engineer is on the way....when at the tasks the engineer has 3 further statuses to choose from depending on the outcome of task No Access, Completed or Rearranged. task statuses ------------------------------------------------------------- Uncommenced default (no task status) Notified start No Access|Completed|Rearranged end ------------------------------------------------------------- If the engineer has no access at 8am, then there would be 2 statues added. 1. Notifiied 2. No Access now the engineer may try again at 11am. so before arriving the engineer will click a button called retry which will add Notified to the tasks_statuses and then is able to choose the 2nd outcome of the task 3. Notifed (Back to square one) 4. 2nd Outcome (Completed?) what i want to do is caluclate the complete time spent on the task. Here is a typical example: 1st attempt: 60 mins 2nd attempt: 28 mins. Total task time : 88 mins How is this possible please? Thank you
  9. Destramic

    simple entity validator - critique

    I've been doing things wrong for years...I've had one model class per controller with multiple methods. Ie. Get tasks, get task etc I really do like the structure I've been shown here and I'm excited to make the changes. Also I will check that link out ignace. Thank you all for your help and patience as It means a lot to me to know the correct way of doing things. 😊
  10. Destramic

    simple entity validator - critique

    here is what ive come up with: <?php class Validator { private $entities; private $fields; private $error_messages = array(); public function __construct($entities, array $fields = array()) { if (!is_array($entities)) { $entities = array($entities); } foreach ($entities as $entity) { $this->check_entity($entity); } $this->entities = $entities; $this->fields = $fields; } private function check_entity($entity) { if (!is_object($entity)) { throw new Exception('Validator: Entity must be an object.'); } return true; } public function validate(array $data, $strict = false) { foreach ($this->entities as $entity) { foreach ($data as $property => $value) { if (!empty($this->fields) && !in_array($property, $this->fields)) { throw new Exception(sprintf('Validator: Unknown field %s', $property)); } if (!method_exists($entity, $property)) { throw new Exception(sprintf('Validator: Unknown method %s', $property)); } try { $result = $entity->$property($value); } catch (Exception $exception) { if ($strict) { throw new Exception($exception->getMessage()); } else { $error_message = ucwords($property) . ': ' . $exception->getMessage(); $this->error_messages[$property] = $error_message; } } } } } public function get_error_messages() { return $this->error_messages; } public function is_valid() { return empty($this->error_messages); } } class Assert { public function __call(string $constraint, $arguments) { $class = $constraint; if (!class_exists($class)) { throw new Exception(sprintf('Assert: Constraint %s doesn\'t exist.', $constraint)); } else if (!method_exists($class, 'assert')) { throw new Exception(sprintf('Assert: Method assert doesn\'t exist for %s.', $constraint)); } return call_user_func_array(array(new $class, 'assert'), $arguments); } } class Not_Blank { public function assert($value) { if (empty($value)) { throw new Exception('Value is empty'); } return true; } } class Login extends Assert { public function username($username) { $this->not_blank($username); } public function password($password) { $this->not_blank($password); } } form validation: i added fields to be inputted to make validation stricter, becasue if post data is manipulated and there is no username or post in the data then the validator would return true. $validator = new Validator(array(new Login)); $post = array( 'username' => null, 'password' => null ); // fields added to be validated $validator->validate($post, array( 'username', 'password' )); if (!$validator->is_valid()) { print_r($validator->get_error_messages()); } business model data validation...this is where im able to put validation to strict and it will return exceptions instead of getting friendly error messages $validator = new Validator(array(new Login)); // true = exceptions will be returned $validator->validate($data, true); if you could tell me what you think and please elaborate on how form validation and business model validation should work thank you
  11. Destramic

    simple entity validator - critique

    im trying to digest everything your saying here...so... ok validating a form and returning error messages for a user is great...but for instance, if form data is passed to my business model after being validated would i need to validate the data again in themodel, but this time returning exceptions?
  12. Destramic

    Header problems

    i like the idea of loading a controller view inside of the view it's self. so here it is... view method public function load($controller, $variables = array()) { $dispatcher = new Dispatcher($this->get_request(), $this->get_response()); if (!$dispatcher->is_dispatchable($controller)) { throw new Exception(sprintf('View: Unable to dispatch %s.', $controller)); } if (!empty($variables)) { self::$variables = array_merge(self::$variables, $this->escape_values($variables)); } return $dispatcher->dispatch()->get_view()->get_contents(); } then in my pages echo $this->load('template:common:header', array( 'heading' => 'Task', 'heading_description' => 'This is a quick view of your current task' )); thank you both for your help
  13. Destramic

    range of dates

    i just ran the query and seen the figures. I assumed it was my error and not your query 🤣 but it works brillantly...can't thank you enough for your efforts barand. thank you! and i hope not
  14. Destramic

    simple entity validator - critique

    interesting, ok so the user has inputted a date and your checking if the date is >= 18 or <100 if so then set date and if not it'll throw an exception. shouldnt a validation error message go back to the user in the form process? or should i just rely on client side validation for that. and if they pass client side validation then exceptions will be thrown if invalid. i hope you can elaborate on this please. thank you
  15. Destramic

    Header problems

    a controller for the header sounds good, but leaves me with the question how would i run two controllers or load the header controller into other controllers. what would be the best pattern/way please requinix? thank you for your patience
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.