Пример #1
0
 /**
  * Store a newly created resource in storage.
  * POST /houses
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('name' => 'required|max:50|unique:houses', 'propertyID' => 'required', 'frequency' => 'required'));
     if ($v->passes()) {
         $newhouse = new House();
         $newhouse->name = Input::get('name');
         $newhouse->propertyID = Input::get('propertyID');
         $newhouse->frequency = Input::get('frequency');
         foreach (Input::get('housegroup') as $key => $value) {
             $result = strtolower(preg_replace("/[[:blank:]]+/", "_", $key));
             $newhouse->{$result} = $value;
         }
         $newhouse->save();
         $pid = Input::get('propertyID');
         return Redirect::action('HousController@show', $pid)->withFlashMessage('Unit created successfully');
     }
     return Redirect::back()->withInput()->withErrors($v)->with('message', 'There were validation errors');
 }
Пример #2
0
 /**
 * csv文件的某一行数据导入到数据库
 */
 function import_db_line($file_name, $line)
 {
     $msg = '';
     $state = 0;
     $n = 0;
     $handle = fopen($file_name, 'r');
     while ($data = fgetcsv($handle, 10000)) {
         ++$n;
         $is_print_col = 0;
         //读取第一行
         if (1 == $is_print_col) {
             $num = count($data);
             echo '<tr> ' . "\r\n";
             echo '<td>' . $line . '</td>' . "\r\n";
             for ($i = 0; $i < $num; $i++) {
                 //echo '<td>'.iconv('gb2312', 'utf-8', $data[$i]).'</td>' . "\r\n"; //中文转码
                 $this->p($i . '行: ' . $data[$i]);
             }
             echo '</tr> ' . "\r\n";
         }
         if ($line == $n) {
             $msg = '读取第' . $n . '行;';
             $num = count($data);
             if ($num > 0) {
                 $addr = trim($data[0]);
                 $a_c = trim($data[1]);
                 $yr_built = trim($data[2]);
                 $sqft = trim($data[3]);
                 $area = trim($data[4]);
                 $area_code = trim($data[5]);
                 $bsmt1_out = trim($data[6]);
                 $bsmt2_out = trim($data[7]);
                 $br = trim($data[8]);
                 $br_plus = trim($data[9]);
                 $central_vac = trim($data[10]);
                 $community = trim($data[11]);
                 $community_code = trim($data[12]);
                 $cross_st = trim($data[13]);
                 $elevator = trim($data[14]);
                 $constr1_out = trim($data[15]);
                 $constr2_out = trim($data[16]);
                 $extras = trim($data[17]);
                 $fpl_num = trim($data[18]);
                 $comp_pts = trim($data[19]);
                 $furnished = trim($data[20]);
                 $gar_spaces = trim($data[21]);
                 if ($location != '') {
                     $local_zb = $this->actionGetCodeAddress2($location);
                     $longitude = $local_zb['lng'];
                     //	经度////////待定
                     $latitude = $local_zb['lat'];
                     //	纬度////////待定
                     //					p($longitude);
                     //					p($latitude);
                 }
                 $is_print_value = 0;
                 //是否输入 读入的csv值
                 if (1 == $is_print_value) {
                     p('名称: ' . $addr);
                     p('总价: ' . $a_c);
                     p('开发商: ' . $yr_built);
                     p('所属项目: ' . $sqft);
                     p('挂牌时间: ' . $area);
                     p('地址: ' . $area_code);
                     p('描述: ' . $bsmt1_out);
                     p('房源图片: ' . $bsmt2_out);
                     p('组图: ' . $br);
                     p('房源视频路径: ' . $br_plus);
                     p('作者: ' . $central_vac);
                     p('是否推荐: ' . $community);
                     p('城市: ' . $community_code);
                     p('地区: ' . $cross_st);
                     p('社区: ' . $elevator);
                     p('投资类型: ' . $constr1_out);
                     p('物业类型: ' . $constr2_out);
                     p('土地面积: ' . $extras);
                     p('房屋面积: ' . $fpl_num);
                     p('房屋层数: ' . $comp_pts);
                     p('卧室数量: ' . $furnished);
                     p('卫生间数量: ' . $gar_spaces);
                 }
                 parent::_acl('house_create');
                 $model = new House();
                 $model->addr = $addr;
                 //名称 必填
                 $model->a_c = $a_c;
                 //总价 必填
                 $model->yr_built = $yr_built;
                 //开发商 必填
                 $model->sqft = $sqft;
                 //所属项目 必填
                 $model->area = $area;
                 //挂牌时间
                 $model->area_code = $area_code;
                 //	地址
                 $model->bsmt1_out = $bsmt1_out;
                 //	地址
                 $model->bsmt2_out = $bsmt2_out;
                 //	地址
                 $model->br = $br;
                 //	地址
                 $model->br_plus = $br_plus;
                 //	地址
                 $model->central_vac = $central_vac;
                 //	地址
                 $model->community = $community;
                 //	地址
                 $model->community_code = $community_code;
                 //	地址
                 $model->cross_st = $cross_st;
                 //	地址
                 $model->elevator = $elevator;
                 //	地址
                 $model->constr1_out = $constr1_out;
                 //	地址
                 $model->constr2_out = $constr2_out;
                 //	地址
                 $model->extras = $extras;
                 //	地址
                 $model->fpl_num = $fpl_num;
                 //	地址
                 $model->comp_pts = $comp_pts;
                 //	地址
                 $model->furnished = $furnished;
                 //	地址
                 $model->gar_spaces = $gar_spaces;
                 //	地址
                 $is_save = 1;
                 //是否保存
                 if ($is_save == 1) {
                     if ($model->save()) {
                         //echo '导入数据成功!';
                         $msg = $msg . '导入数据成功!';
                         $state = 1;
                     } else {
                         //echo '导入数据失败!';
                         $msg = $msg . '导入数据失败!';
                         $state = 0;
                         //print_r($model->errors);
                     }
                 }
             }
             break;
         }
     }
     fclose($handle);
     //关闭指针
     unset($handle);
     return array('line' => $line, 'state' => $state, 'msg' => $msg, 'err' => $model->errors);
     unset($model);
 }
 public function createUnit()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('name' => 'required|max:50|unique:houses', 'propertyid' => 'required', 'rent_deposit' => 'required', 'electricity_deposit' => 'required', 'water_deposit' => 'required', 'garbage_deposit' => 'required', 'frequency' => 'required', 'rent' => 'required', 'electricity' => 'required', 'garbage' => 'required', 'water' => 'required'));
     if ($v->passes()) {
         $newhouse = new House();
         $newhouse->name = Input::get('name');
         $newhouse->propertyID = Input::get('propertyid');
         $newhouse->frequency = Input::get('frequency');
         $newhouse->rent = Input::get('rent');
         $newhouse->water = Input::get('water');
         $newhouse->garbage = Input::get('garbage');
         $newhouse->electricity = Input::get('electricity');
         $newhouse->rent_deposit = Input::get('rent_deposit');
         $newhouse->water_deposit = Input::get('water_deposit');
         $newhouse->garbage_deposit = Input::get('garbage_deposit');
         $newhouse->electricity_deposit = Input::get('electricity_deposit');
         $newhouse->agent_id = Input::get('agent_id');
         $newhouse->save();
         $noteunit = array('error' => false, 'message' => "Unit Created Successfully");
         return $noteunit;
     }
     $noteError4 = array('error' => true, 'message' => $v->messages());
     return $noteError4;
 }
$human1 = new Human();
$human1->setName('John');
$human1->save();
$human2 = new Human();
$human2->setName('Jane');
$human2->save();
$house1 = new House();
$house1->setName('Home1');
$house1->setHumanRelatedByOwnerId($human1);
$house1->setHumanRelatedByRenterId($human2);
$house1->save();
$house2 = new House();
$house2->setName('Home2');
$house2->setHumanRelatedByOwnerId($human2);
$house2->setHumanRelatedByRenterId($human1);
$house2->save();
$finder = sfPropelFinder::from('House')->
  join('Human owner', 'House.OwnerId', 'owner.Id', 'INNER JOIN')->
  where('owner.Name', 'John');
$nbHouses = $finder->count();
$t->is($nbHouses, 1, 'join() allows to join to another table with several foreign keys using an alias');
$t->is($finder->getLatestQuery(), propel_sql('SELECT COUNT([P13*][P12house.ID]) FROM house INNER JOIN human owner ON (house.OWNER_ID=owner.ID) WHERE owner.NAME=\'John\''), 'join() uses aliased table names when using an alias relation');

/************************************************************/
/* sfPropelFinder::join() with self-referenced foreign keys */
/************************************************************/

$t->diag('sfPropelFinder::join() with self-referenced foreign keys');

HumanPeer::doDeleteAll();
$human1 = new Human();
/********************************************************************/

$t->diag('sfPropelFinderRelation::relateObject() and multiple foreign keys');

CivilityPeer::doDeleteAll();
HumanPeer::doDeleteAll();
HousePeer::doDeleteAll();
$civility1 = new Civility();
$civility1->setIsMan(true);
$civility1->save();
$human1 = new Human();
$human1->setName('John');
$human1->save();
$house1 = new House();
$house1->setName('Home1');
$house1->save();

$manager = new sfPropelFinderRelationManager('House');
$ownerRelation = $manager->addRelationFromColumns('House', HousePeer::OWNER_ID, 'Human', HumanPeer::ID, 'owner');
$civilityRelation = $manager->guessRelation('Civility');
$manager[] = $civilityRelation;

$ownerRelation->relateObject($house1, $human1);
$t->is($house1->getOwnerId(), $human1->getId(), 'relateObject() creates a relation between two Propel objects');
$civilityRelation->relateObject($house1, $civility1);
$t->is($human1->getTheSex(), $civility1->getId(), 'relateObject() creates a relation between two Propel objects via another relation');

/******************************************************/
/* sfPropelFinderRelation::relateObject() and aliases */
/******************************************************/
Пример #6
0
                         } else {
                             $serverSaveHour--;
                         }
                         $timeInfo['tm_hour'] = $serverSaveHour;
                         $timeInfo['tm_min'] = 55;
                         $timeInfo['tm_sec'] = 0;
                         $difference = mktime($timeInfo['tm_hour'], $timeInfo['tm_min'], $timeInfo['tm_sec'], (int) $timeInfo['tm_mon'] + 1, $timeInfo['tm_mday'], (int) $timeInfo['tm_year'] + 1900) - $timeNow;
                         if ($difference < 0) {
                             $difference += 86400;
                         }
                         $auctionEnd = time() + $difference + ($auctionDaysDefault - 1) * 86400;
                     }
                 }
                 $house->setBidEnd($auctionEnd);
             }
             $house->save();
             $main_content .= $goodInfoStart . 'Your offer is now highest on auction. Current price for house is <b>' . $house->getLastBid() . ' gold</b>, your maximum price is <b>' . $house->getBid() . ' gold</b>. Character <b>' . htmlspecialchars($bidder->getName()) . '</b> from your account will get house, if you win.' . $goodInfoEnd;
             // udalo sie przebic, wiec nie pokazuje formularza
             $bidded = true;
         } else {
             if ($bid >= $house->getLastBid()) {
                 $house->setLastBid($bid);
                 $house->save();
             }
             $main_content .= $badInfoStart . 'Your offer of ' . $bid . ' gold is too low.' . $badInfoEnd;
         }
     } else {
         $main_content .= $badInfoStart . 'Character <b>' . htmlspecialchars($bidder->getName()) . '</b> does not have enough money on bank account. Please login again <b>in game</b> to update your bank balance.' . $badInfoEnd;
     }
 } else {
     $main_content .= 'Selected player is not on your account?! Hax?';
Пример #7
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl('house_create');
     $original = Yii::app()->request->getQuery('original');
     $model = new House();
     $imageList = $this->_gets->getPost('imageList');
     $imageListSerialize = XUtils::imageListSerialize($imageList);
     if (isset($_POST['House'])) {
         $model->attributes = $_POST['House'];
         $model->accessDate = strtotime($_POST['House']['accessDate']);
         $model->match = implode(',', $_POST['House']['match']);
         $file = XUpload::upload($_FILES['house_image']);
         if (is_array($file)) {
             $model->house_image = $file['pathname'];
         }
         $model->image_list = $imageListSerialize['dataSerialize'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入房源信息,ID:' . $model->id));
             if (!empty($original)) {
                 $this->redirect($original);
             } else {
                 $this->redirect(array('index'));
             }
         }
     }
     $this->subject_list = parent::_groupList('subject');
     $this->city_list = parent::_groupList('city');
     $this->district_list = parent::_groupList('district');
     $this->investType_list = parent::_groupList('investType');
     $this->propertyType_list = parent::_groupList('propertyType');
     $this->match_list = parent::_groupList('match');
     $this->render('create', array('model' => $model, 'imageList' => $imageListSerialize['data'], 'original' => $original));
 }
Пример #8
0
function scraping_PKT($url, $region)
{
    // create HTML DOM
    $html = file_get_html($url);
    $ret = array();
    // get title
    // $ret['title'] = $html->find('title', 0)->innertext;
    /*
         $ret['name'] =$html->find('a[class="fn openPreview"]',1)->innertext;
         $ret['zip'] =$html->find('span[class="postal-code"]',1)->innertext;
         $ret['city'] =$html->find('span[class="locality"]',1)->innertext;
         $ret['street'] =$html->find('span[class="street-address"]',1)->innertext;
         $ret['tel'] =$html->find('p[class="tel"]',1)->innertext;
         $ret['email'] =$html->find('p[class="email"]',1)->innertext;
         $ret['www'] =$html->find('p[class="url"]',1)->innertext;
         $ret['slogan'] =$html->find('div[class="slogan"]',1)->innertext;
    */
    //$ret['record'] =$html->find('h2') ;
    foreach ($html->find('td[class="vcard"]') as $element) {
        $block = str_get_html($element->innertext);
        $house = new House();
        $house->name = $block->find('a[class="fn openPreview"]', 0)->innertext;
        $house->zipCode = $block->find('span[class="postal-code"]', 0)->innertext;
        $house->city = $block->find('span[class="locality"]', 0)->innertext;
        $house->street = $block->find('span[class="street-address"]', 0)->innertext;
        $house->tel = $block->find('p[class="tel"]', 0)->innertext;
        $tmp = $block->find('p[class="email"]');
        if (!empty($tmp)) {
            $house->email = $tmp[0]->find('a', 0)->innertext;
        }
        $tmp = $block->find('p[class="url"]');
        if (!empty($tmp)) {
            $house->www = $tmp[0]->find('a', 0)->innertext;
        }
        $house->slogan = $block->find('div[class="slogan"]', 0)->plaintext;
        $house->region = $region;
        $house->save();
        print 'Zapisano: ' . $house->name . ' ' . $house->city . "\n";
        //echo $house->name .'<br>';
        // str_get_html($block)->find('a[class="fn openPreview"]',0)->innertext;
        //array_push ($ret, Array('name'=>str_get_html($element->innertext)->find('a[class="fn openPreview"]',0)->innertext));
        $block->clear();
        //unset($block);
        $house->free();
    }
    //$next = $html->find('li[class="nextLink"]',0)->innertext;
    //$link=str_get_html($next)->find('a',0)->href;
    // get rating
    // $ret['Rating'] = $html->find('div[class="general rating"] b', 0)->innertext;
    // get overview
    /*foreach($html->find('div[class="info"]') as $div) {
            // skip user comments
            if($div->find('h5', 0)->innertext=='User Comments:')
                return $ret;
    
            $key = '';
            $val = '';
    
            foreach($div->find('*') as $node) {
                if ($node->tag=='h5')
                    $key = $node->plaintext;
    
                if ($node->tag=='a' && $node->plaintext!='more')
                    $val .= trim(str_replace("\n", '', $node->plaintext));
    
                if ($node->tag=='text')
                    $val .= trim(str_replace("\n", '', $node->plaintext));
            }
    
            $ret[$key] = $val;
        }*/
    $next = $html->find('li[class="nextLink"]');
    if (!empty($next)) {
        $link = $next[0]->find('a', 0)->href;
    } else {
        $link = "";
    }
    // clean up memory
    $html->clear();
    unset($html);
    return $link;
}