Exemplo n.º 1
0
 public function calculate($address_id)
 {
     $total = 0;
     $model = new model("fare");
     $fare = $model->where("is_default=1")->find();
     if ($fare) {
         $addr = $model->table('address')->where("id={$address_id}")->find();
         if ($addr) {
             $city = $addr['city'];
             $first_price = $fare['first_price'];
             $second_price = $fare['second_price'];
             $first_weight = $fare['first_weight'];
             $second_weight = $fare['second_weight'];
             $zoning = unserialize($fare['zoning']);
             foreach ($zoning as $zon) {
                 if (preg_match(',' . $city . ',', ',' . $zon['area'] . ',') > 0) {
                     $first_price = $zon['f_price'];
                     $second_price = $zon['s_price'];
                     $first_weight = $zon['f_weight'];
                     $second_weight = $zon['s_weight'];
                     break;
                 }
             }
             if ($this->weight <= $first_weight) {
                 $total = $first_price;
             } else {
                 $weight = $this->weight - $first_weight;
                 $total = $first_price + ceil($weight / $second_weight) * $second_price;
             }
         }
     }
     return sprintf("%01.2f", $total);
 }
Exemplo n.º 2
0
 public function getWhere($id)
 {
     $db = new model($this->_table);
     $db->open();
     $db->where(array('account' => ':account'));
     $db->params(array(':account' => $id));
     $data = $db->get();
     $db->close();
     return $data;
 }
Exemplo n.º 3
0
 /**
  * @param $input
  * @param $user
  * @throws Exception
  */
 private function checkUserByEmail($input, $user)
 {
     //Figure out if email is not the same
     if ($user->email != $input['email']) {
         //Check to see if email exists
         if ($this->model->where('email', '=', $input['email'])->first()) {
             throw new Exception('That email address belongs to a different user.');
         }
     }
 }
 public function getBootstrapMenu($model)
 {
     $this->model = $model;
     $user = User::find(Auth::user()->id);
     //Inicializo la variable de iteración
     $cantMenu = 0;
     $routes = $this->getUrlActual();
     //Obtengo la cantidad total de opciones de menu cargadas
     $count = $this->model->where("padre", "0")->count();
     $resultMenu = $this->model->all()->where("padre", "0")->where("anterior", "0")->first();
     //Mientras no se alcance la cantidad total de menús cargados...
     while ($cantMenu < $count) {
         //Si es el primero, busco el menú principal (aquel que no tiene predecesores)
         if ($cantMenu == "0") {
             $idAnterior = "0";
         } else {
             //De lo contrario asigno la ID del menú que tiene predecesor cero
             $idAnterior = $resultMenu->id;
         }
         //Obtengo los datos del menú actual
         $resultMenu = $this->model->all()->where("padre", "0")->where("anterior", "{$idAnterior}")->first();
         //Obtengo los submenus en caso de existir
         $submenu = $this->model->all()->where("padre", "{$resultMenu->id}")->where("anterior", "0")->first();
         //Si tiene submenus, los muestro
         if ($submenu) {
             $this->menuField = new MenuField();
             $this->menuField->setData($resultMenu);
             $this->menuField->setTieneHijos(true);
             //Inicializo la variable de iteración
             $cantSubMenu = 0;
             $countSubmenu = $this->model->where("padre", "{$resultMenu->id}")->count();
             $muestraMenu = false;
             //Mientras no se alcance la cantidad total de menús cargados...
             while ($cantSubMenu < $countSubmenu) {
                 $active = false;
                 $show = false;
                 $objSubmenu = new MenuField();
                 //Si es el primero, busco el menú principal (aquel que no tiene predecesores)
                 if ($cantSubMenu == "0") {
                     $idAnteriorSubmenu = "0";
                 } else {
                     //De lo contrario asigno la ID del menú que tiene predecesor cero
                     $idAnteriorSubmenu = $submenu->id;
                 }
                 $submenu = $this->model->all()->where("padre", "{$resultMenu->id}")->where("anterior", "{$idAnteriorSubmenu}")->first();
                 // *************Consulta si el submenu tiene a su vez un submenu*************
                 //Obtengo los submenus de segundo nivel en caso de existir
                 $submenuSecond = $this->model->all()->where("padre", "{$submenu->id}")->where("anterior", "0")->first();
                 //Si tiene submenus de segundo nivel, los muestro
                 if ($submenuSecond) {
                     $objSubmenu->setData($submenu);
                     $objSubmenu->setTieneHijos(true);
                     //Inicializo la variable de iteración
                     $cantSubMenuSecond = 0;
                     $countSubmenuSecond = $this->model->where("padre", "{$submenu->id}")->count();
                     //Mientras no se alcance la cantidad total de submenu cargados...
                     while ($cantSubMenuSecond < $countSubmenuSecond) {
                         $objSubmenuSecond = new MenuField();
                         //Si es el primero, busco el menu principal (aquel que no tiene predecesores)
                         if ($cantSubMenuSecond == "0") {
                             $idAnteriorSubmenuSecond = "0";
                         } else {
                             //De lo contrario asigno la ID del menu que tiene predecesor cero
                             $idAnteriorSubmenuSecond = $submenuSecond->id;
                         }
                         $submenuSecond = $this->model->all()->where("padre", "{$submenu->id}")->where("anterior", "{$idAnteriorSubmenuSecond}")->first();
                         if ($user->can($submenuSecond->slug)) {
                             $show = true;
                             // muestro el menu con submenus
                             $objSubmenuSecond->setData($submenuSecond);
                             $objSubmenu->setChildrens($objSubmenuSecond);
                             if ($routes == $objSubmenuSecond->getLink()) {
                                 $objSubmenuSecond->setActive(true);
                                 $active = true;
                             }
                         }
                         $cantSubMenuSecond++;
                     }
                 } else {
                     if ($user->can($submenu->slug)) {
                         $show = true;
                         //de lo contrario, muestro el menu sin submenus
                         $objSubmenu->setData($submenu);
                         if ($routes == $objSubmenu->getLink()) {
                             $objSubmenu->setActive(true);
                             $active = true;
                         }
                     }
                 }
                 // *************Fin submenu del submenu*************
                 if ($show) {
                     $muestraMenu = true;
                     $this->menuField->setChildrens($objSubmenu);
                     if ($active) {
                         $this->menuField->setActive(true);
                     }
                 }
                 $cantSubMenu++;
             }
             if ($muestraMenu) {
                 $this->menu[] = $this->menuField;
             }
         } else {
             // Verifica si tiene permisos para mostrar el menu
             if ($user->can($resultMenu->slug)) {
                 //de lo contrario, muestro el menu sin submenus
                 $this->menuField = new MenuField();
                 $this->menuField->setData($resultMenu);
                 if ($routes == $this->menuField->getLink()) {
                     $this->menuField->setActive(true);
                 }
                 $this->menu[] = $this->menuField;
             }
         }
         //incremento la variable de iteracion.
         $cantMenu++;
     }
     return $this->menu;
 }
Exemplo n.º 5
0
 /**
  * @param $attribute
  * @param $value
  * @param array $columns
  * @return mixed
  */
 public function FindBy($attribute, $value, $columns = array('*'))
 {
     return $this->_model->where($attribute, '=', $value)->first($columns);
 }
 /**
  * @param array $data
  * @param $id
  * @param string $attribute
  * @return mixed
  */
 public function update(array $data, $id, $attribute = "id")
 {
     return $this->model->where($attribute, '=', $id)->update($data);
 }