diff --git a/include/library/Cockpit/Order.php b/include/library/Cockpit/Order.php index a9b8854b4..b6fbfdeb2 100644 --- a/include/library/Cockpit/Order.php +++ b/include/library/Cockpit/Order.php @@ -57,7 +57,7 @@ class Cockpit_Order extends Crunchbutton_Order { $out['credit'] = 0; } - $out['orders_by_phone'] = $this->totalOrdersByPhone( $this->phone ); + $out['orders_by_phone'] = self::totalOrdersByPhone( $this->phone ); $paymentType = $this->paymentType(); if( $paymentType->id_user_payment_type ){ diff --git a/include/library/Crunchbutton/Agent.php b/include/library/Crunchbutton/Agent.php index 77ed6baac..f9cf83f15 100644 --- a/include/library/Crunchbutton/Agent.php +++ b/include/library/Crunchbutton/Agent.php @@ -37,10 +37,18 @@ class Crunchbutton_Agent extends Cana_Table { } - public function getAgent(){ + public static function getAgent(){ $userAgent = new Cana_UserAgent(); - $query = "SELECT * FROM agent WHERE browser='{$userAgent->getBrowserName()}' AND version = '{$userAgent->getBrowserVersion()}' AND os = '{$userAgent->getOperatingSystem()}' AND engine = '{$userAgent->getEngine()}' LIMIT 1"; - $agent = Crunchbutton_Agent::q( $query ); + $query = ' + SELECT * FROM agent + WHERE + browser=? + AND version = ? + AND os = ? + AND engine = ? + LIMIT 1 + '; + $agent = Crunchbutton_Agent::q( $query, [$userAgent->getBrowserName(), $userAgent->getBrowserVersion(), $userAgent->getOperatingSystem(), $userAgent->getEngine()]); if( !$agent->id_agent ){ $agent = new Crunchbutton_Agent; $agent->browser = $userAgent->getBrowserName(); diff --git a/include/library/Crunchbutton/Community/Resource.php b/include/library/Crunchbutton/Community/Resource.php index e2e8d5523..9419c1649 100644 --- a/include/library/Crunchbutton/Community/Resource.php +++ b/include/library/Crunchbutton/Community/Resource.php @@ -122,7 +122,7 @@ class Crunchbutton_Community_Resource extends Cana_Table { } } - public function byCommunity( $id_community, $type = false ){ + public static function byCommunity( $id_community, $type = false ){ $type = ( $type ) ? ' AND ' . $type . ' = true' : ''; diff --git a/include/library/Crunchbutton/Community/Shift.php b/include/library/Crunchbutton/Community/Shift.php index 42852bde3..a0dd685c4 100644 --- a/include/library/Crunchbutton/Community/Shift.php +++ b/include/library/Crunchbutton/Community/Shift.php @@ -235,7 +235,7 @@ class Crunchbutton_Community_Shift extends Cana_Table { return Crunchbutton_Community_Shift::q($query, $params); } - public function shiftDriverIsCurrentWorkingOn($id_admin, $dt = null, $id_community = null) { + public static function shiftDriverIsCurrentWorkingOn($id_admin, $dt = null, $id_community = null) { $admin = Admin::o($id_admin); // start using community's timezone - #4965 diff --git a/include/library/Crunchbutton/Credit.php b/include/library/Crunchbutton/Credit.php index 7433a2226..3ad2618c3 100644 --- a/include/library/Crunchbutton/Credit.php +++ b/include/library/Crunchbutton/Credit.php @@ -312,11 +312,11 @@ class Crunchbutton_Credit extends Cana_Table return 0; } - public function formatPoints( $points ){ + public static function formatPoints( $points ){ return Util::humanReadableNumbers( $points ); } - public function exportPoints($user){ + public static function exportPoints($user){ if (!$user) { $user = c::user(); } @@ -341,7 +341,7 @@ class Crunchbutton_Credit extends Cana_Table return $out; } - public function points( $id_user ){ + public static function points( $id_user ){ $query = 'SELECT SUM( value ) AS points FROM credit c WHERE c.id_user = ? AND credit_type = ? AND type = ?'; $row = Cana::db()->get( $query, [$id_user, Crunchbutton_Credit::CREDIT_TYPE_POINT, Crunchbutton_Credit::TYPE_CREDIT]); if( $row->_items && $row->_items[0] ){ diff --git a/include/library/Crunchbutton/Hour.php b/include/library/Crunchbutton/Hour.php index 8513b1146..853e09958 100644 --- a/include/library/Crunchbutton/Hour.php +++ b/include/library/Crunchbutton/Hour.php @@ -102,7 +102,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return false; } - public function restaurantIsOpen( $restaurant, $dt = null ){ + public static function restaurantIsOpen( $restaurant, $dt = null ){ $time = ( $dt ? $dt : 'now' ); $today = new DateTime( $time, new DateTimeZone( $restaurant->timezone ) ); @@ -174,7 +174,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return $hours_opened; } - public function hoursByRestaurant( $restaurant, $gmt = false ){ + public static function hoursByRestaurant( $restaurant, $gmt = false ){ if ( !isset( $restaurant->_hours[ $gmt ] ) ) { $hours = Hour::q( "SELECT * FROM hour WHERE id_restaurant = {$restaurant->id_restaurant}" ); if ( $gmt ) { @@ -194,15 +194,15 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return $restaurant->_hours[ $gmt ] ; } - public function getByRestaurantWeek( $restaurant, $utc = true){ + public static function getByRestaurantWeek( $restaurant, $utc = true){ return Hour::getByRestaurantToExport( $restaurant, $utc); } - public function getByRestaurantNext24Hours( $restaurant, $utc = true, $sd = null){ + public static function getByRestaurantNext24Hours( $restaurant, $utc = true, $sd = null){ return Hour::getByRestaurantToExport( $restaurant, $utc, true, $sd); } - public function getRestaurantRegularPlusHolidayHours( $restaurant ){ + public static function getRestaurantRegularPlusHolidayHours( $restaurant ){ Crunchbutton_Config::getVal( 'auto_close_use_community_hours' ); @@ -242,7 +242,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return Hour::mergeHolidays( $_hours, $restaurant ); } - public function getByRestaurantToExport( $restaurant, $utc = true, $next24hours = false , $sd = null){ + public static function getByRestaurantToExport( $restaurant, $utc = true, $next24hours = false , $sd = null){ $hours = Hour::getRestaurantRegularPlusHolidayHours( $restaurant ); @@ -458,7 +458,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { } // This method merge restaurant hours with the holidays - public function mergeHolidays( $hours, $restaurant, $convertHours = true ){ + public static function mergeHolidays( $hours, $restaurant, $convertHours = true ){ if( count( $hours ) == 0 ){ return $hours; @@ -736,7 +736,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return $hour . ( ( $minute > 0 ) ? ':' . str_pad( $minute, 2, '0', STR_PAD_LEFT ) : '' ) . $ampm; } - public function closedMessage( $hours ){ + public static function closedMessage( $hours ){ $weekdays = [ 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ]; @@ -812,7 +812,7 @@ class Crunchbutton_Hour extends Cana_Table_Trackchange { return join( '
', $_organized ); } - public function restaurantClosedMessage( $restaurant ){ + public static function restaurantClosedMessage( $restaurant ){ $_hours = Hour::getRestaurantRegularPlusHolidayHours( $restaurant ); // Remove the closes status diff --git a/include/library/Crunchbutton/Order.php b/include/library/Crunchbutton/Order.php index 5b741b63e..f015b2c41 100644 --- a/include/library/Crunchbutton/Order.php +++ b/include/library/Crunchbutton/Order.php @@ -324,7 +324,7 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange { // Find out if the user posted a gift card code at the notes field and get its value $this->giftcardValue = 0; if ( trim( $this->notes ) != '' ){ - $totalOrdersByPhone = $this->totalOrdersByPhone( $this->phone ); + $totalOrdersByPhone = self::totalOrdersByPhone( $this->phone ); if( $totalOrdersByPhone < 1 ){ $words = preg_replace( "/(\r\n|\r|\n)+/", ' ', $this->notes ); $words = explode( ' ', $words ); @@ -2373,7 +2373,7 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange { return null; } - public function lastDeliveredOrder($id_user = nul) { + public static function lastDeliveredOrder($id_user = nul) { $id_user = ( $id_user ) ? $id_user : $this->id_user; if( $id_user ){ $order = self::q("SELECT * FROM `order` WHERE id_user = ? AND delivery_type = 'delivery' ORDER BY id_order DESC LIMIT 1", [$id_user]); @@ -2488,7 +2488,7 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange { return $time; } - public function totalOrdersByPhone( $phone ){ + public static function totalOrdersByPhone( $phone ){ $phone = Phone::clean( $phone ); $query = 'SELECT COUNT(*) AS total FROM `order` INNER JOIN phone using(id_phone) WHERE phone.phone = ?'; $row = Cana::db()->get( $query, [$phone])->get(0); @@ -2498,7 +2498,7 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange { return 0; } - public function totalOrdersByCustomer( $id_user ){ + public static function totalOrdersByCustomer( $id_user ){ $query = 'SELECT COUNT(*) AS total FROM `order` WHERE id_user = ?'; $row = Cana::db()->get( $query, [$id_user])->get(0); if( $row->total ){ diff --git a/include/library/Crunchbutton/Order/Action.php b/include/library/Crunchbutton/Order/Action.php index ab40aedbc..3f7fa04a9 100644 --- a/include/library/Crunchbutton/Order/Action.php +++ b/include/library/Crunchbutton/Order/Action.php @@ -22,19 +22,18 @@ class Crunchbutton_Order_Action extends Cana_Table { ->load($id); } - public function byOrder( $id_order ){ - $_id_order = ( $this->id_order ? $this->id_order : $id_order ); + public static function byOrder( $id_order ){ return Crunchbutton_Order_Action::q(' SELECT oa.*, a.name, a.phone FROM order_action oa INNER JOIN admin a ON oa.id_admin = a.id_admin WHERE oa.id_order = ? and oa.type!=? ORDER BY oa.id_order_action DESC - ', [$_id_order, self::TICKET_NOT_GEOMATCHED]); + ', [$id_order, self::TICKET_NOT_GEOMATCHED]); } public function restaurant(){ - return Crunchbutton_Restaurant::q( "SELECT r.* FROM restaurant r INNER JOIN `order` o ON o.id_restaurant = r.id_restaurant WHERE id_order = {$this->id_order}" ); + return Crunchbutton_Restaurant::q('SELECT r.* FROM restaurant r INNER JOIN `order` o ON o.id_restaurant = r.id_restaurant WHERE id_order = ?', [$this->id_order]); } public function changeTransferDeliveryDriver( $id_order, $id_admin ){ diff --git a/include/library/Crunchbutton/Promo.php b/include/library/Crunchbutton/Promo.php index a5cf3f988..9ffad07d8 100644 --- a/include/library/Crunchbutton/Promo.php +++ b/include/library/Crunchbutton/Promo.php @@ -86,7 +86,7 @@ class Crunchbutton_Promo extends Cana_Table } } - public function validateNotesField( $notes, $id_restaurant = false, $phone = false ){ + public static function validateNotesField( $notes, $id_restaurant = false, $phone = false ){ $return = array(); $giftcards = array(); $words = preg_replace( "/(\r\n|\r|\n)+/", ' ', $notes ); diff --git a/include/library/Crunchbutton/Restaurant/Payment/Type.php b/include/library/Crunchbutton/Restaurant/Payment/Type.php index 440b75c84..db03a6ca9 100644 --- a/include/library/Crunchbutton/Restaurant/Payment/Type.php +++ b/include/library/Crunchbutton/Restaurant/Payment/Type.php @@ -204,9 +204,9 @@ class Crunchbutton_Restaurant_Payment_Type extends Cana_Table { return $this->_stripe_recipient; } - function byRestaurant( $id_restaurant ){ + public static function byRestaurant( $id_restaurant ){ if( $id_restaurant ){ - $payment = Crunchbutton_Restaurant_Payment_Type::q( 'SELECT * FROM restaurant_payment_type WHERE id_restaurant = ' . $id_restaurant . ' ORDER BY id_restaurant_payment_type DESC LIMIT 1' ); + $payment = Crunchbutton_Restaurant_Payment_Type::q( 'SELECT * FROM restaurant_payment_type WHERE id_restaurant = ? ORDER BY id_restaurant_payment_type DESC LIMIT 1', [$id_restaurant]); if( $payment->id_restaurant_payment_type ){ return Crunchbutton_Restaurant_Payment_Type::o( $payment->id_restaurant_payment_type ); } else{ diff --git a/include/library/Crunchbutton/User/Auth.php b/include/library/Crunchbutton/User/Auth.php index 7545b9501..4ef939b86 100644 --- a/include/library/Crunchbutton/User/Auth.php +++ b/include/library/Crunchbutton/User/Auth.php @@ -115,7 +115,7 @@ class Crunchbutton_User_Auth extends Cana_Table { return false; } - public function userHasFacebookAuth( $id_user ){ + public static function userHasFacebookAuth( $id_user ){ $row = Cana::db()->get(" SELECT * FROM user_auth @@ -131,7 +131,7 @@ class Crunchbutton_User_Auth extends Cana_Table { return false; } - public function userHasAuth( $id_user ){ + public static function userHasAuth( $id_user ){ $row = Cana::db()->get(' SELECT * FROM user_auth @@ -146,7 +146,7 @@ class Crunchbutton_User_Auth extends Cana_Table { return false; } - public function userHasEmailAuth( $id_user ){ + public static function userHasEmailAuth( $id_user ){ $row = Cana::db()->get(' SELECT * FROM user_auth @@ -163,7 +163,7 @@ class Crunchbutton_User_Auth extends Cana_Table { } // This function creates a user_auth - public function createPhoneAuth( $user_id, $phone ){ + public static function createPhoneAuth( $user_id, $phone ){ $id_user_auth = User_Auth::userHasEmailAuth( $user_id ); if( $id_user_auth ){ $phoneExists = User_Auth::checkPhoneExists( $phone ); @@ -185,7 +185,7 @@ class Crunchbutton_User_Auth extends Cana_Table { return false; } - public function createPhoneAuthFromFacebook( $user_id, $phone ){ + public static function createPhoneAuthFromFacebook( $user_id, $phone ){ $id_user_auth = User_Auth::userHasFacebookAuth( $user_id ); if( $id_user_auth ){ $phoneExists = User_Auth::checkPhoneExists( $phone ); diff --git a/include/library/Crunchbutton/User/Payment/Type.php b/include/library/Crunchbutton/User/Payment/Type.php index a7534a257..762bf1917 100644 --- a/include/library/Crunchbutton/User/Payment/Type.php +++ b/include/library/Crunchbutton/User/Payment/Type.php @@ -6,7 +6,7 @@ class Crunchbutton_User_Payment_Type extends Cana_Table { return c::config()->site->config('processor_payments')->value; } - public function getUserPaymentType($id_user = null) { + public static function getUserPaymentType($id_user = null) { $id_user = $id_user ? $id_user : c::user()->id_user; if ($id_user) { diff --git a/include/library/Crunchbutton/Util.php b/include/library/Crunchbutton/Util.php index fa73a9a9f..a3d5d16de 100755 --- a/include/library/Crunchbutton/Util.php +++ b/include/library/Crunchbutton/Util.php @@ -9,7 +9,7 @@ class Crunchbutton_Util extends Cana_Model { ( strpos( $_SERVER['HTTP_HOST'], 'dev.pit' ) !== false ) ) ? true : false; } - public function dateToUnixTimestamp( $dateTime ){ + public static function dateToUnixTimestamp( $dateTime ){ if ( is_a( $dateTime , 'DateTime' ) ) { $tz = $dateTime->getTimestamp(); return gmdate( 'Y-m-d\TH:i:s\Z', $tz );