示例#1
0
 /**
  * testSaveManyDeepHasManyValidationFailure method
  *
  * @return void
  */
 public function testSaveManyDeepHasManyValidationFailure()
 {
     $this->loadFixtures('Boat', 'Comment');
     $TestModel = new Boat();
     $TestModel->Comment->validate = array('comment' => array('notBlank' => array('rule' => array('notBlank'))));
     $result = $TestModel->saveMany(array(array('user_id' => 1, 'title' => 'New Boat', 'body' => 'This article contains a invalid comment', 'Comment' => array(array('user_id' => 1, 'comment' => '')))), array('deep' => true));
     $this->assertFalse($result);
     $this->assertEquals(array(array('Comment' => array(array('comment' => array('notBlank'))))), $TestModel->validationErrors);
 }
示例#2
0
 /**
  * testDeleteDependent method
  *
  * @return void
  */
 public function testDeleteDependent()
 {
     $this->loadFixtures('Bidding', 'BiddingMessage', 'Boat', 'boatsTag', 'Comment', 'User', 'Attachment');
     $Bidding = new Bidding();
     $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
     $expected = array(array('Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), 'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1')), array('Bidding' => array('id' => 2, 'bid' => 'Two', 'name' => 'Bid 2'), 'BiddingMessage' => array('bidding' => 'Two', 'name' => 'Message 2')), array('Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'), 'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3')), array('Bidding' => array('id' => 4, 'bid' => 'Five', 'name' => 'Bid 5'), 'BiddingMessage' => array('bidding' => '', 'name' => '')));
     $this->assertEquals($expected, $result);
     $Bidding->delete(4, true);
     $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
     $expected = array(array('Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), 'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1')), array('Bidding' => array('id' => 2, 'bid' => 'Two', 'name' => 'Bid 2'), 'BiddingMessage' => array('bidding' => 'Two', 'name' => 'Message 2')), array('Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'), 'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3')));
     $this->assertEquals($expected, $result);
     $Bidding->delete(2, true);
     $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC')));
     $expected = array(array('Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), 'BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1')), array('Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3'), 'BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3')));
     $this->assertEquals($expected, $result);
     $result = $Bidding->BiddingMessage->find('all', array('order' => array('BiddingMessage.name' => 'ASC')));
     $expected = array(array('BiddingMessage' => array('bidding' => 'One', 'name' => 'Message 1'), 'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1')), array('BiddingMessage' => array('bidding' => 'Three', 'name' => 'Message 3'), 'Bidding' => array('id' => 3, 'bid' => 'Three', 'name' => 'Bid 3')), array('BiddingMessage' => array('bidding' => 'Four', 'name' => 'Message 4'), 'Bidding' => array('id' => '', 'bid' => '', 'name' => '')));
     $this->assertEquals($expected, $result);
     $Boat = new Boat();
     $result = $Boat->Comment->find('count', array('conditions' => array('Comment.article_id' => 1)));
     $this->assertEquals(4, $result);
     $result = $Boat->delete(1, true);
     $this->assertTrue($result);
     $result = $Boat->Comment->find('count', array('conditions' => array('Comment.article_id' => 1)));
     $this->assertEquals(0, $result);
 }
示例#3
0
 public function actionRoute()
 {
     $area = Area::model()->findAll();
     $continent = Continent::model()->findAll();
     $boat = Boat::model()->findAll();
     $this->g_area = $area;
     $this->g_continent = $continent;
     $company = Company::model()->findAll();
     $this->g_company = $company;
     $s_data = $_GET['d'];
     $s_company = $_GET['c'];
     $s_area = $_GET['a'];
     $s_days = $_GET['days'];
     if (strstr($s_data, '请选择')) {
         $s_data = '全部';
     }
     if (strstr($s_company, '请选择')) {
         $s_company = '全部';
     }
     if (strstr($s_area, '请选择')) {
         $s_area = '全部';
     }
     $year = date("Y");
     $month = date('n');
     $arr = array();
     for ($i = $month; $i <= 12; $i++) {
         array_push($arr, $year . '年' . $i . '月');
     }
     $year += 1;
     for ($i = 1; $i <= 12; $i++) {
         array_push($arr, $year . '年' . $i . '月');
     }
     $criteria = new CDbCriteria();
     if ($s_company != '全部') {
         $criteria->addCondition("company = '{$s_company}' ", 'AND');
     }
     if ($s_data != '全部') {
         $d = str_replace('年', '-', $s_data);
         $d = str_replace('月', '', $d);
         $criteria->addCondition(" start_time >= '{$d}' and start_time < " . '"' . $d . '-40"', 'AND');
     }
     if ($s_area != '全部') {
         $criteria->addCondition("area = '{$s_area}' or continent = '{$s_area}' ", 'AND');
     }
     if ($s_days != '全部') {
         if ($s_days == 3) {
             $criteria->addCondition("days <= {$s_days}", 'AND');
         } else {
             if ($s_days == 11) {
                 $criteria->addCondition("days >= {$s_days}", 'AND');
             } else {
                 $criteria->addCondition("days = {$s_days}", 'AND');
             }
         }
     }
     $page = 0;
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
     }
     $count = Route::model()->count($criteria);
     $criteria->limit = 10;
     $criteria->offset = $page * $criteria->limit;
     $result = Route::model()->findAll($criteria);
     $schedule = array();
     #		$item = str_replace(',', ' and id = ', $item);
     #		$item = ' id = '.$item;
     #		$c = new CDbCriteria;
     #		$c->condition = $item;
     #		$c->order = 'day asc';
     #		$c->select = 'title';
     #		$r = Schedule::model()->findAll($c);
     #		array_push($schedule, $r);
     //echo '<meta charset="UTF-8">';
     //echo $criteria->condition;
     //var_dump($result);
     $this->render('index', array('s_data' => $s_data, 's_company' => $s_company, 's_area' => $s_area, 'area' => $area, 'continent' => $continent, 'company' => $company, 'data' => $arr, 'result' => $result, 'count' => $count, 'page' => $page, 'limit' => $criteria->limit, 's_days' => $s_days, 'schedule' => $schedule));
 }
示例#4
0
 public function actionSelect_boat()
 {
     $company = $_POST['company'];
     if (!$company) {
         exit;
     }
     $criteria = new CDbCriteria();
     // 创建CDbCriteria对象
     $criteria->select = 'name';
     $criteria->condition = 'company = "' . $company . '"';
     // 设置查询条件
     $model = Boat::model()->findAll($criteria);
     $ret = '';
     foreach ($model as $value) {
         $ret .= '<option>' . $value->name . '</option>';
     }
     echo CJSON::encode(array('option' => $ret));
 }
示例#5
0
require "header/header.php";
?>
  

 <body>

   <!-- navigation folder stores the dynamic navigation bar. If user logn, it will retrieve different nav bar (Capt / User nav). -->
   <?php 
include "navigation/guestNav.php";
//if user login
if (isset($_SESSION['userType']) && isset($_SESSION['userId']) && !empty($_SESSION['userType']) && !empty($_SESSION['userId'])) {
    $userType = $_SESSION['userType'];
    $userId = $_SESSION['userId'];
    include_once "class/Captain.class.php";
    include_once "class/Boat.class.php";
    $boat = new Boat();
    $captain = new Captain();
    $boatList = array();
    $captList = array();
    //*************************** UPCOMING APPOINTMENTS ****************************************************
    echo "<div class='container'> ";
    echo "<h1>My Boats</h1>";
    $boatList = $boat->retrieveBoats($userId);
    for ($i = 0; $i < count($boatList); $i++) {
        $boatName = $boatList[$i]->getBoatName();
        $boatModel = $boatList[$i]->getBoatModel();
        $boatCapacity = $boatList[$i]->getBoatCapacity();
        $registration_number = $boatList[$i]->getRegistrationNumber();
        $registration_exp = $boatList[$i]->getRegistrationExp();
        echo "<div class='row'> ";
        echo "<div class='col-md-8 col-xs-12'>";
示例#6
0
 public function actionSearch()
 {
     $keyword = $_POST['keywords'];
     $boat = $_POST['boat'];
     $str = '';
     echo header("Content-Type: text/html;charset=utf-8");
     $model = NULL;
     if ($keyword) {
         $str = 'boat like ' . '"' . '%' . $keyword . '%' . '"';
     }
     if ($boat) {
         if ($str != '') {
             $str .= ' and ';
         }
         $str .= ' boat =' . '"' . $boat . '"';
     }
     $criteria = new CDbCriteria();
     // 创建CDbCriteria对象
     $criteria->condition = $str;
     // 设置查询条件
     $model = Diary::model()->findAll($criteria);
     $boat = Boat::model()->findAll();
     $this->render('index', array('diary' => $model, 'boat' => $boat));
 }
示例#7
0
 public function actionAdd_boat()
 {
     $boat = new Boat();
     if (isset($_POST['source'])) {
         $boat->source = $_POST['source'];
     }
     if (isset($_POST['thumb'])) {
         $boat->thumb = $_POST['thumb'];
     }
     $boat->name = $_POST['title'];
     $boat->zaikeshu = $_POST['zaikeshu'];
     $boat->paishuiliang = $_POST['paishuiliang'];
     $boat->zuigaosudu = $_POST['zuigaosudu'];
     $boat->jiabanlouceng = $_POST['jiabanlouceng'];
     $boat->gongzuorenyuan = $_POST['gongzuorenyuan'];
     $boat->changdu = $_POST['changdu'];
     $boat->kuandu = $_POST['kuandu'];
     $boat->gaodu = $_POST['gaodu'];
     $boat->description = $_POST['content'];
     $boat->type = $_POST['type'];
     $boat->save();
     echo 1;
 }
示例#8
0
 public function actionAdd()
 {
     $boat = Boat::model()->findAll();
     $area = Area::model()->findAll();
     $company = Company::model()->findAll();
     $port = Port::model()->findAll();
     $continent = Continent::model()->findAll();
     $this->render('add', array('boat' => $boat, 'area' => $area, 'port' => $port, 'company' => $company, 'continent' => $continent));
 }
示例#9
0
 /**
  * undocumented function
  *
  * @return void
  */
 public function testBindModelCallsInBehaviors()
 {
     // hasMany
     $Boat = new Boat();
     $Boat->unbindModel(array('hasMany' => array('Comment')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('Comment', $result));
     $Boat->Behaviors->load('Test4');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // belongsTo
     $Boat->unbindModel(array('belongsTo' => array('User')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('User', $result));
     $Boat->Behaviors->load('Test5');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('User', $result));
     // hasAndBelongsToMany
     $Boat->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
     $result = $Boat->find('first');
     $this->assertFalse(array_key_exists('Tag', $result));
     $Boat->Behaviors->load('Test6');
     $result = $Boat->find('first');
     $this->assertTrue(array_key_exists('Comment', $result));
     // hasOne
     $Comment = new Comment();
     $Comment->unbindModel(array('hasOne' => array('Attachment')));
     $result = $Comment->find('first');
     $this->assertFalse(array_key_exists('Attachment', $result));
     $Comment->Behaviors->load('Test7');
     $result = $Comment->find('first');
     $this->assertTrue(array_key_exists('Attachment', $result));
 }
示例#10
0
 /**
  * Testing you can dynamically add rules to a field, added this to dispel doubts
  * after a presentation made to show off this new feature
  *
  * @return void
  */
 public function testDynamicValidationRuleBuilding()
 {
     $model = new Boat();
     $validator = $model->validator();
     $validator->add('body', 'isSpecial', array('rule' => 'special'));
     $rules = $validator['body']->getRules();
     $this->assertCount(2, $rules);
     $this->assertEquals('special', $rules['isSpecial']->rule);
     $validator['body']->setRule('isAwesome', array('rule' => 'awesome'));
     $rules = $validator['body']->getRules();
     $this->assertCount(3, $rules);
     $this->assertEquals('awesome', $rules['isAwesome']->rule);
 }
示例#11
0
 /**
  * test that model->hasMethod checks self and behaviors.
  *
  * @return void
  */
 public function testHasMethod()
 {
     $Boat = new Boat();
     $Boat->Behaviors = $this->getMock('BehaviorCollection');
     $Boat->Behaviors->expects($this->at(0))->method('hasMethod')->will($this->returnValue(true));
     $Boat->Behaviors->expects($this->at(1))->method('hasMethod')->will($this->returnValue(false));
     $this->assertTrue($Boat->hasMethod('find'));
     $this->assertTrue($Boat->hasMethod('pass'));
     $this->assertFalse($Boat->hasMethod('fail'));
 }
示例#12
0
 /**
  * test to assert that != in key together with a single element array will work
  *
  * @return void
  */
 public function testNotEqualsInArrayWithOneValue()
 {
     $this->loadFixtures('Boat');
     $Boat = new Boat();
     $Boat->recursive = -1;
     $result = $Boat->find('all', array('conditions' => array('Boat.id !=' => array(1))));
     $this->assertTrue(is_array($result) && !empty($result));
 }
示例#13
0
 /**
  * Test nested transaction
  *
  * @return void
  */
 public function testNestedTransaction()
 {
     $this->Dbo->useNestedTransactions = true;
     $this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
     $this->loadFixtures('Boat');
     $model = new Boat();
     $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
     $model->cacheQueries = false;
     $this->Dbo->cacheMethods = false;
     $this->assertTrue($this->Dbo->begin());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->begin());
     $this->assertTrue($model->delete(1));
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->commit());
     $this->assertEmpty($model->read(null, 1));
     $this->assertTrue($this->Dbo->rollback());
     $this->assertNotEmpty($model->read(null, 1));
 }
示例#14
0
 public function actionGet_boat()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "(type & 4) !=0";
     $criteria->limit = 8;
     $boat = Boat::model()->findAll($criteria);
     $html = '<ul class="local_trip_pro" id="local_trip_content_list" data-blockid="recommend_localjoin">';
     for ($j = 0; $j < count($boat); $j++) {
         if ($j) {
             $html .= '<li class="local_trip_pro_li wq_clearfix hide" data-content="lj' . $j . '" style="display:none;">';
         } else {
             $html .= '<li class="local_trip_pro_li wq_clearfix" data-content="lj' . $j . '">';
         }
         $arr = explode(',', $boat[$j]->source);
         for ($i = 1; $i < count($arr) && $i < 4; $i++) {
             if ($i - 1) {
                 $html .= '<a class="local_trip_right img_slide_animte_wrapper" href="';
             } else {
                 $html .= '<a class="local_trip_left_l img_slide_animte_wrapper" href="';
             }
             if ($i - 1) {
                 $html .= '#" target="_blank"> <img class="local_trip_img_s img_slide_animte first_page"  src="' . $arr[$i] . '" data-original="' . $arr[$i] . '" style="display: block;"> <span class="local_trip_mask_s"></span> <span class="local_trip_txt_s" title="' . '">' . '</span>' . '<span class="local_trip_price_s font_size12"><span class="font_size16">' . '</span></span></a>';
             } else {
                 $html .= '#" target="_blank"> <img class="local_trip_img_l img_slide_animte first_page" alt=" ' . '" src="' . $arr[$i] . '" data-original="' . $arr[$i] . '" style="display: block;"> <span class="local_trip_mask_l"></span> <span class="local_trip_bl"></span><span class="local_trip_txt_l" title="' . '">' . '</span>' . '<span class="local_trip_price_l font_size14 font_color_orange"><span class="font_size28">' . '</span></span></a>';
             }
         }
         $html .= '</li>';
     }
     $html .= '</ul>';
     echo $html;
 }