Inheritance: extends Shim\Model\Table\Table
コード例 #1
0
 /**
  * StringBehaviorTest::testMultipleFieldsAndMultipleFilters()
  *
  * @return void
  */
 public function testMultipleFieldsAndMultipleFilters()
 {
     $this->Comments->behaviors()->String->config(['fields' => ['title', 'comment'], 'input' => ['strtolower', 'ucwords']]);
     $data = ['comment' => 'blaBla', 'url' => 'www.dereuromark.de', 'title' => 'some nAme'];
     $entity = $this->Comments->newEntity($data);
     $res = $this->Comments->save($entity);
     $this->assertTrue((bool) $res);
     $this->assertSame('Some Name', $res['title']);
     $this->assertSame('Blabla', $res['comment']);
 }
コード例 #2
0
 public function beforeValidate($options = [])
 {
     $ret = parent::beforeValidate($options);
     if (isset($this->data['value'])) {
         $this->data['value'] = (double) $this->data['value'];
     }
     if (isset($this->data['code'])) {
         $this->data['code'] = mb_strtoupper($this->data['code']);
         $code = $this->data['code'];
         # intelligent autocomplete
         if (isset($this->data['name']) && empty($this->data['name'])) {
             if (!isset($this->CurrencyLib)) {
                 //App::import('Component', 'Data.Currency');
                 $this->CurrencyLib = new CurrencyLib();
             }
             $this->data['name'] = $this->CurrencyLib->getName($code, '');
         }
         if (isset($this->data['value']) && $this->data['value'] == 0) {
             if (!isset($this->CurrencyLib)) {
                 //App::import('Component', 'Data.Currency');
                 $this->CurrencyLib = new CurrencyComponent();
             }
             $currencies = $this->availableCurrencies();
             if (array_key_exists($code, $currencies)) {
                 $this->data['value'] = $currencies[$code];
             }
         }
     }
     return $ret;
 }
コード例 #3
0
 /**
  * JsonableBehaviorTest::testDecodeParams()
  *
  * @return void
  */
 public function testDecodeParams()
 {
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['output' => 'array', 'fields' => ['details'], 'decodeParams' => ['assoc' => false]]);
     $data = ['comment' => 'blabla', 'url' => 'www.dereuromark.de', 'title' => 'param', 'details' => ['x' => ['y' => 'z']]];
     $entity = $this->Comments->newEntity($data);
     $this->Comments->save($entity);
     // Test decode with default params
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $obj = new stdClass();
     $obj->x = new stdClass();
     $obj->x->y = 'z';
     $expected = $obj;
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = ['x' => ['y' => 'z']];
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true and depth = 2
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true, 'depth' => 2]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = [];
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true and depth = 3
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true, 'depth' => 3]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = ['x' => ['y' => 'z']];
     $this->assertEquals($expected, $res['details']);
 }
コード例 #4
0
 /**
  * @return void
  */
 public function testNeighborsEnd()
 {
     $id = 4;
     $result = $this->Table->neighbors($id);
     $this->assertEquals('Third', $result['prev']['title']);
     $this->assertNull($result['next']);
 }
コード例 #5
0
 /**
  * District::beforeValidate()
  *
  * @param array $options
  * @return bool Success
  */
 public function beforeValidate($options = [])
 {
     parent::beforeValidate($options);
     if (!empty($this->data['name']) && !empty($this->data['city_id'])) {
         $city = $this->City->field('name', ['id' => $this->data['city_id']]);
         $this->data['address'] = $this->data['name'] . ', ' . $city;
     }
     return true;
 }
コード例 #6
0
ファイル: CitiesTable.php プロジェクト: BDhulia/cakephp-data
 public function __construct($id = false, $table = false, $ds = null)
 {
     if (Configure::read('City.District') === false) {
         unset($this->hasMany['District']);
     }
     if (Configure::read('City.County') === false) {
         unset($this->belongsTo['County']);
     }
     parent::__construct($id, $table, $ds);
 }
コード例 #7
0
 /**
  * Location::beforeSave()
  *
  * @param mixed $options
  * @return bool Success
  */
 public function beforeSave($options = [])
 {
     parent::beforeSave($options);
     $additional = ['locality', 'sublocality'];
     foreach ($additional as $field) {
         if (!empty($this->data['geocoder_result'][$field])) {
             $this->data[$field] = $this->data['geocoder_result'][$field];
         }
     }
     return true;
 }
コード例 #8
0
 public function beforeSave($options = [])
 {
     parent::beforeSave($options);
     if (isset($this->data['name'])) {
         $this->data['name'] = mb_strtolower($this->data['name']);
     }
     if (isset($this->data['ext'])) {
         $this->data['ext'] = mb_strtolower($this->data['ext']);
     }
     return true;
 }
コード例 #9
0
 /**
  * ResetBehaviorTest::testResetWithCallbackAndFieldsAutoAdded()
  *
  * @return void
  */
 public function testResetWithCallbackAndFieldsAutoAdded()
 {
     $this->Table->removeBehavior('Reset');
     $this->Table->addBehavior('Tools.Reset', ['fields' => ['id'], 'updateFields' => ['id'], 'callback' => 'TestApp\\Model\\Table\\ResetCommentsTable::fieldsCallbackAuto']);
     $x = $this->Table->find('first', ['conditions' => ['id' => 6]]);
     $this->assertEquals('Second Comment for Second Article', $x['comment']);
     $result = $this->Table->resetRecords();
     $this->assertTrue((bool) $result);
     $x = $this->Table->find('first', ['conditions' => ['id' => 6]]);
     $expected = 'bar';
     $this->assertEquals($expected, $x['comment']);
 }
コード例 #10
0
 /**
  * @return void
  */
 public function testEncodeWithNoParamsComplexContent()
 {
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['output' => 'array', 'fields' => ['details'], 'encodeParams' => ['options' => 0]]);
     $data = ['comment' => 'blabla', 'url' => 'www.dereuromark.de', 'title' => 'param', 'details' => ['foo' => 'bar', 'nan' => NAN, 'inf' => INF]];
     $entity = $this->Comments->newEntity($data);
     $result = $this->Comments->save($entity);
     $this->assertTrue((bool) $result);
     $res = $this->Comments->get($entity->id);
     $expected = [];
     $this->assertSame($expected, $res->details);
 }
コード例 #11
0
 /**
  * BitmaskedBehaviorTest::testNotContains()
  *
  * @return void
  */
 public function testNotContains()
 {
     $res = $this->Comments->containsNotBit(BitmaskedComment::STATUS_PUBLISHED);
     $expected = ['(BitmaskedComments.status & 2 != 2)'];
     $this->assertEquals($expected, $res);
     $conditions = $res;
     $res = $this->Comments->find('all', ['conditions' => $conditions])->toArray();
     $this->assertTrue(!empty($res) && count($res) === 4);
     // multiple (AND)
     $res = $this->Comments->containsNotBit([BitmaskedComment::STATUS_PUBLISHED, BitmaskedComment::STATUS_ACTIVE]);
     $expected = ['(BitmaskedComments.status & 3 != 3)'];
     $this->assertEquals($expected, $res);
     $conditions = $res;
     $res = $this->Comments->find('all', ['conditions' => $conditions])->toArray();
     $this->assertTrue(!empty($res) && count($res) === 5);
 }
コード例 #12
0
 /**
  * @return void
  */
 public function testBasicOutput()
 {
     $this->Comments->removeBehavior('String');
     $data = ['title' => 'some Name', 'comment' => 'blabla', 'url' => ''];
     $entity = $this->Comments->newEntity($data);
     $res = $this->Comments->save($entity);
     $this->assertTrue((bool) $res);
     $this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'output' => ['ucfirst']]);
     $res = $this->Comments->get($entity->id);
     $this->assertSame('Some Name', $res['title']);
 }
コード例 #13
0
 /**
  * @return void
  */
 public function testNotContains()
 {
     $config = $this->Comments->connection()->config();
     $isPostgres = strpos($config['driver'], 'Postgres') !== false;
     $res = $this->Comments->containsNotBit(BitmaskedComment::STATUS_PUBLISHED);
     $expected = ['(BitmaskedComments.status & 2 != 2)'];
     if ($isPostgres) {
         $expected = ['("BitmaskedComments"."status" & 2 != 2)'];
     }
     $this->assertEquals($expected, $res);
     $conditions = $res;
     $res = $this->Comments->find('all', ['conditions' => $conditions])->toArray();
     $this->assertTrue(!empty($res) && count($res) === 4);
     // multiple (AND)
     $res = $this->Comments->containsNotBit([BitmaskedComment::STATUS_PUBLISHED, BitmaskedComment::STATUS_ACTIVE]);
     $expected = ['(BitmaskedComments.status & 3 != 3)'];
     if ($isPostgres) {
         $expected = ['("BitmaskedComments"."status" & 3 != 3)'];
     }
     $this->assertEquals($expected, $res);
     $conditions = $res;
     $res = $this->Comments->find('all', ['conditions' => $conditions])->toArray();
     $this->assertTrue(!empty($res) && count($res) === 5);
 }
コード例 #14
0
 public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
 {
     parent::afterDelete();
     $this->cleanUp();
 }
コード例 #15
0
 /**
  * Static Model::method()
  */
 public static function addressTypes($value = null)
 {
     $options = [self::TYPE_MAIN => __('Main Residence'), self::TYPE_OTHER => __('Other')];
     return parent::enum($value, $options);
 }
コード例 #16
0
 public function initialize(array $config)
 {
     $this->displayField('comment');
     parent::initialize($config);
 }