public static function getNumberOfErrorsByTime($globalData, $time)
 {
     $db = $globalData->takeConnection();
     $select = $db->select();
     $select->from('events_list');
     $select->where('log_status = ?', RealEstateAgency_Const::LOG_ERROR);
     $date = tools_date2database($time);
     $select->where('log_date >= ?', $date);
     $stmt = $db->query($select);
     $result = $stmt->fetchAll();
     //echo '<pre>';
     //var_dump($result);
     //echo '</pre>';
     return count($result);
 }
 public function execute()
 {
     $this->getInput();
     $view = $this->getGlobalData()->getView();
     $action = $this->action;
     // Show the list of settlements;
     $view->op_type = $this->operation_type;
     if ($action == 'firstpage') {
         $view->viewmode = 'firstpage';
         $list = new RealEstateAgency_Object_SettlementList();
         $list->setGlobalData($this->getGlobalData());
         $list->setAreaId(1);
         $list->loadBy();
         $view->list_of_links = $list->getArray();
     } else {
         if ($action == 'secondpage') {
             $this->secondPage($view);
             //$view->settlement_name = $this->getSettlementName();
         } else {
             if ($action == 'submit') {
                 $view->viewmode = 'show';
                 $obj = new RealEstateAgency_Object_RealEstateObject();
                 $obj->setGlobalData($this->getGlobalData());
                 $brokerID = $this->getGlobalData()->getLoginObject()->getLoggedUserID();
                 $obj->setBrokerID($brokerID);
                 //tools_log_debug($this->getGlobalData(),"validate reo",tools_get_input('op_type'));
                 $obj->readWebForm();
                 $obj->toWebForm($view);
                 $validation = $obj->validate();
                 if (count($validation) > 0) {
                     $view->validation = $validation;
                     $this->secondPage($view);
                     //$view->settlement_name = $this->getSettlementName();
                 } else {
                     // Submit;
                     $view->settlement_name = $this->getSettlementName();
                     $time = tools_date2database(time());
                     $obj->setDateOfStart($time);
                     $obj->setDateOfUpdate($time);
                     if (!$this->do_not_save) {
                         $obj->insert();
                     }
                 }
             }
         }
     }
 }
 private function load($globalData)
 {
     $db = $globalData->takeConnection();
     // mysql> select op_type, type, count(*) counter from r_e_object group by type;
     // +---------+------+----------+
     // | op_type | type | counter |
     // +---------+------+----------+
     // |       0 |    1 |      135 |
     // |       0 |    3 |        1 |
     // +---------+------+----------+
     $period = RealEstateAgency_Const::SEARCH_PERIOD_MAX;
     $current_time = time();
     $current_time -= $period * 24 * 60 * 60;
     $current_time = tools_date2database($current_time);
     $stmt = $db->query('SELECT op_type operation, type, count(*) counter from r_e_object where updated >= \'' . $current_time . '\' group by operation, type');
     $counters = $stmt->fetchAll();
     $globalData->setViewVariable('counters', $counters);
     $globalData->setViewVariable('counters_time', time());
 }
 public function execute()
 {
     // 1 - just load and show;
     // 2 - after the submit, when incorrect: read from the form + loaded object, show;
     // 3 - after the submit, whem correct: read from the form + loaded object, submit;
     $this->getInput();
     $action = $this->action;
     $objectID = $this->objectID;
     $globalData = $this->getGlobalData();
     $view = $globalData->getView();
     $view->op_type = $this->operation_type;
     $object = RealEstateAgency_Object_RealEstateObject::loadById($globalData, $objectID);
     $view->location_details = $object->getLocationDetails();
     if ($action == 'showpage') {
         $view->viewmode = 'showpage';
         $this->getCityDistricts($view, $object);
         $object->toWebForm($view);
     } else {
         if ($action == 'submit') {
             $write = $object->isEditable();
             if ($write) {
                 $object->readWebFormForUpdate();
                 $view->location_details = $object->getLocationDetails();
                 $validation = $object->validate();
                 if (count($validation) > 0) {
                     // Show again;
                     $view->validation = $validation;
                     $view->viewmode = 'showpage';
                     $this->getCityDistricts($view, $object);
                     $object->toWebForm($view);
                 } else {
                     // Update this object; Show result page;
                     $time = tools_date2database(time());
                     $object->setDateOfUpdate($time);
                     $object->update();
                     $this->uploadFile($view, $object);
                     $view->viewmode = 'resultpage';
                 }
             }
         }
     }
 }
 public function test()
 {
     require_once 'RealEstateAgency/GlobalData.php';
     $globalData = new RealEstateAgency_GlobalData();
     $object = new RealEstateAgency_Object_RealEstateObject();
     $object->setGlobalData($globalData);
     $object->setObjectID(NULL);
     $object->setBrokerID(1);
     $object->setDateOfStart(tools_date2database(time()));
     $object->setDateOfUpdate(NULL);
     $object->setPrice(10000);
     $object->setObjectType(3);
     $object->setRooms(5);
     $object->setRoomsType(1);
     $object->setSettlementID(1);
     $object->setLocationText("Альтернативне місцезнаходження");
     $object->setSettlementAreaID(1);
     $object->setStreet("Оболонський просп.");
     $object->setHouseNumber('15a');
     $object->setSquareAll(100.5);
     $object->setSquareLive(90.5);
     $object->setSquareKitchen(10.5);
     $object->setFloor(1);
     $object->setFloors(16);
     $object->setExternal(1);
     $object->setWcNumber(1);
     $object->setBathNumber(2);
     $object->setTelType(1);
     $object->setDescription("Якийсь додатковий опис.");
     $object->insert();
     $obj_id = $object->getObjectID();
     sleep(3);
     $object2 = $this->loadById($globalData, $obj_id);
     $object2->setPrice(20000);
     $update_time = time();
     $object2->setDateOfUpdate(tools_date2database($update_time));
     $object2->update();
     $object3 = $this->loadById($globalData, $obj_id);
     if ($object3->getPrice() != 20000) {
         throw new Exception('Incorrect value - price, after update.');
     }
     if (tools_database2date($object3->getDateOfUpdate()) != $update_time) {
         throw new Exception('Incorrect value - time, after update.');
     }
     RealEstateAgency_Object_RealEstateObject::deleteById($globalData, $obj_id);
 }
 /**
  * filter - RealEstateAgency_Object_SearchFilter
  */
 public function loadBy($filter)
 {
     $operationType = $filter->getOperationType();
     $period = $filter->getPeriod();
     $price_1 = $filter->getPriceFrom();
     $price_2 = $filter->getPriceTo();
     $rooms = $filter->getRooms();
     $city_district = $filter->getCityDistrict();
     $position = $filter->getPosition();
     $limit = $filter->getLimit();
     //if ($limit != NULL) {
     //$limit++;
     //}
     $db = $this->getGlobalData()->takeConnection();
     $select = $db->select();
     $select->from('r_e_object');
     $counter = $db->select();
     $counter->from('r_e_object', array('counter' => 'COUNT(*)'));
     $select->joinLeft('settlement', 'r_e_object.settlement_id=settlement.obj_id', array('settlement_name' => 'obj_name'));
     $select->joinLeft('settlement_part', 'r_e_object.settl_area_id=settlement_part.obj_id', array('settlement_part_name' => 'obj_name'));
     $select->joinLeft('district', 'settlement.district=district.obj_id', array('district_name' => 'obj_name'));
     $select->joinLeft('area', 'district.area=area.obj_id', array('area_name' => 'obj_name'));
     $select->where('op_type = ?', $operationType);
     $counter->where('op_type = ?', $operationType);
     $search = $this->search;
     if ($search) {
         if (RealEstateAgency_Const::TYPE_FLAT == $search) {
             //$select->where('settlement_id = ?', RealEstateAgency_Const::MAIN_SETTLEMENT_ID);
             $select->where('type = ?', RealEstateAgency_Const::TYPE_FLAT_NUMBER);
             $counter->where('type = ?', RealEstateAgency_Const::TYPE_FLAT_NUMBER);
             $select->order(array('area_name', 'rooms', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
         } else {
             if (RealEstateAgency_Const::TYPE_ROOM == $search) {
                 $select->where('type = ?', RealEstateAgency_Const::TYPE_ROOM_NUMBER);
                 $counter->where('type = ?', RealEstateAgency_Const::TYPE_ROOM_NUMBER);
                 $select->order(array('area_name', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
             } else {
                 if (RealEstateAgency_Const::TYPE_COMMERCIAL == $search) {
                     // Commercial;
                     $select->where('type = ?', RealEstateAgency_Const::TYPE_COMMERCIAL_NUMBER);
                     $counter->where('type = ?', RealEstateAgency_Const::TYPE_COMMERCIAL_NUMBER);
                     $select->order(array('area_name', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
                 } else {
                     if (RealEstateAgency_Const::TYPE_HOUSE == $search) {
                         // Private house;
                         $select->where('type = ?', RealEstateAgency_Const::TYPE_HOUSE_NUMBER);
                         $counter->where('type = ?', RealEstateAgency_Const::TYPE_HOUSE_NUMBER);
                         $select->order(array('area_name', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
                     } else {
                         if (RealEstateAgency_Const::TYPE_COTTAGE == $search) {
                             // Cottage;
                             $select->where('type = ?', RealEstateAgency_Const::TYPE_COTTAGE_NUMBER);
                             $counter->where('type = ?', RealEstateAgency_Const::TYPE_COTTAGE_NUMBER);
                             $select->order(array('area_name', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
                         } else {
                             if (RealEstateAgency_Const::TYPE_LAND == $search) {
                                 // Land;
                                 $select->where('type = ?', RealEstateAgency_Const::TYPE_LAND_NUMBER);
                                 $counter->where('type = ?', RealEstateAgency_Const::TYPE_LAND_NUMBER);
                                 $select->order(array('area_name', 'district_name', 'settlement_name', 'settlement_part_name', 'price'));
                             } else {
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($period != NULL) {
         $current_time = time();
         $current_time -= $period * 24 * 60 * 60;
         $current_time = tools_date2database($current_time);
         $select->where('updated >= ?', $current_time);
         $counter->where('updated >= ?', $current_time);
     }
     if ($rooms != NULL) {
         $select->where('rooms = ?', $rooms);
         $counter->where('rooms = ?', $rooms);
     }
     if ($city_district !== NULL && $city_district != 0) {
         $select->where('settl_area_id = ?', $city_district);
         $counter->where('settl_area_id = ?', $city_district);
     }
     if ($price_1 != NULL) {
         $select->where('price >= ?', $price_1);
         $counter->where('price >= ?', $price_1);
     }
     if ($price_2 != NULL) {
         $select->where('price <= ?', $price_2);
         $counter->where('price <= ?', $price_2);
     }
     //if ($district_id) {
     //  $where = $db->quoteInto('district.obj_id = ?', $district_id);
     // $select->where($where);
     //} else if ($area_id) {
     //  $where = $db->quoteInto('area.obj_id = ?', $area_id);
     // $select->where($where);
     //}
     //$select->order(array('area_name', 'district_name', 'obj_name'));
     // echo $select;
     if ($position !== NULL && $limit != NULL) {
         $select->limit($limit, $position);
     }
     if (RealEstateAgency_Const::FROZEN) {
         $result_counter = 0;
         $result = array();
     } else {
         $stmt = $db->query($select);
         $result = $stmt->fetchAll();
         // 0,0014 seconds = 0,0018 seconds with count(*).
         $stmt_counter = $db->query($counter);
         $result_counter = 0;
         if ($row_counter = $stmt_counter->fetch()) {
             $result_counter = $row_counter['counter'];
         }
     }
     $this->counter = $result_counter;
     // echo '<pre>';
     // var_dump($result);
     // echo '</pre>';
     $this->objects = $this->completeFillByArray($result);
     return;
 }