• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP DataMapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中DataMapper的典型用法代码示例。如果您正苦于以下问题:PHP DataMapper类的具体用法?PHP DataMapper怎么用?PHP DataMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DataMapper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     $this->dataMapper = $this->getMock('FSi\\Component\\DataGrid\\DataMapper\\DataMapperInterface');
     $this->dataMapper->expects($this->any())->method('getData')->will($this->returnCallback(function ($field, $object) {
         switch ($field) {
             case 'name':
                 return $object->getName();
                 break;
         }
     }));
     $this->dataMapper->expects($this->any())->method('setData')->will($this->returnCallback(function ($field, $object, $value) {
         switch ($field) {
             case 'name':
                 return $object->setName($value);
                 break;
         }
     }));
     $this->indexingStrategy = $this->getMock('FSi\\Component\\DataGrid\\Data\\IndexingStrategyInterface');
     $this->indexingStrategy->expects($this->any())->method('getIndex')->will($this->returnCallback(function ($object, $dataMapper) {
         if (is_object($object)) {
             return $object->getName();
         }
         return null;
     }));
     $this->factory = $this->getMock('FSi\\Component\\DataGrid\\DataGridFactoryInterface');
     $this->factory->expects($this->any())->method('getExtensions')->will($this->returnValue(array(new FooExtension())));
     $this->factory->expects($this->any())->method('getColumnType')->with($this->equalTo('foo'))->will($this->returnValue(new FooType()));
     $this->factory->expects($this->any())->method('hasColumnType')->with($this->equalTo('foo'))->will($this->returnValue(true));
     $this->datagrid = new DataGrid('grid', $this->factory, $this->dataMapper, $this->indexingStrategy);
 }
开发者ID:norzechowicz,项目名称:datagrid,代码行数:30,代码来源:DataGridTest.php


示例2: testGlobalMapping

 /**
  * @dataProvider globalMappedData
  */
 public function testGlobalMapping($path, $data, $expected)
 {
     $mapper = new DataMapper();
     foreach ($data as $globalData) {
         $mapper->mapAll($globalData);
     }
     $this->assertEquals($expected, $mapper->data($path));
 }
开发者ID:bloge,项目名称:bloge,代码行数:11,代码来源:DataMapperTest.php


示例3: testShouldListPossibleParents

 function testShouldListPossibleParents()
 {
     $mapper = new DataMapper($this->db);
     $parent1_id = $mapper->save(array('name' => 'Parent 1'));
     $mapper = new DataMapper($this->db);
     $parent2_id = $mapper->save(array('name' => 'Parent 1a', 'paths' => array($parent1_id)));
     $form = new Form($mapper);
     $expected = array($parent1_id => 'Parent 1', $parent1_id . '/' . $parent2_id => 'Parent 1a');
     $this->assertEquals($expected, $form->getElement('paths')->getMultiOptions());
 }
开发者ID:metator,项目名称:application,代码行数:10,代码来源:FormTest.php


示例4: testShouldUpdateAddress

 function testShouldUpdateAddress()
 {
     $address = array('first_name' => 'Joshua', 'last_name' => 'Ribakoff', 'email' => '[email protected]', 'address' => '123 Test St', 'address2' => 'Suite 5', 'city' => 'Port St Lucie', 'state' => 'FL', 'postal' => '00123', 'country' => 'USA', 'phone' => '0101010101', 'fax' => '0202020202');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($address);
     $updatedAddress = array('id' => $id, 'first_name' => 'Joshua-updated', 'last_name' => 'Ribakoff-updated', 'email' => '[email protected]', 'address' => '123 Test St-updated', 'address2' => 'Suite 5-updated', 'city' => 'Port St Lucie-updated', 'state' => 'FL-updated', 'postal' => '12345', 'country' => 'USA-updated', 'phone' => '111111111', 'fax' => '2222222222');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($updatedAddress);
     $loadedAddress = $addressMapper->load($id);
     $this->assertSame($updatedAddress, $loadedAddress, 'should save new address');
 }
开发者ID:metator,项目名称:application,代码行数:11,代码来源:DataMapperTest.php


示例5: testShouldSaveCartAndItems

 function testShouldSaveCartAndItems()
 {
     $cart = new \Metator\Cart\Cart();
     $cart->add(1, 9.99);
     $cart->add(2, 4.99);
     $cart->setQuantity(2, 2);
     $order = array('items' => $cart, 'created' => '0000-00-00 00:00:00');
     $orderMapper = new DataMapper($this->db);
     $id = $orderMapper->save($order, null);
     $reloaded_order = $orderMapper->load($id);
     $this->assertEquals(array(1, 2), $reloaded_order['items']->items(), 'should save items');
 }
开发者ID:metator,项目名称:application,代码行数:12,代码来源:DataMapperTest.php


示例6: __construct

 public function __construct()
 {
     Cowl::timer('cowl init');
     @session_start();
     // I know that the @-notation is frowned upon, but adding it to session_start saves us unnecessary warnings
     Cache::setDir(COWL_CACHE_DIR);
     Current::initialize(COWL_DIR);
     if (COWL_CLI) {
         $this->parseCLIPath();
     } else {
         $this->parseRequestPath();
     }
     Cowl::timer('cowl set defaults');
     // Get and set all directories for various things.
     list($commands_dir, $model_dir, $validators_dir, $library_dir, $view_dir, $helpers_dir, $helpers_app_dir, $drivers_dir, $app_dir, $view_layout_dir, $validator_error_messages, $lang) = Current::$config->gets('paths.commands', 'paths.model', 'paths.validators', 'paths.library', 'paths.view', 'paths.helpers', 'paths.helpers_app', 'paths.drivers', 'paths.app', 'paths.layouts', 'paths.validator_messages', 'lang');
     Controller::setDir($commands_dir);
     DataMapper::setMappersDir($model_dir);
     DataMapper::setObjectsDir($model_dir);
     Validator::setPath($validators_dir);
     Validator::loadStrings($validator_error_messages, $lang);
     Templater::setBaseDir($view_dir);
     Templater::setLayoutDir($view_layout_dir);
     Library::setPath($library_dir);
     Helpers::setPath($helpers_dir);
     Helpers::setAppPath($helpers_app_dir);
     Database::setPath($drivers_dir);
     StaticServer::setDir($app_dir);
     Cowl::timerEnd('cowl set defaults');
     Cowl::timer('cowl plugins load');
     Current::$plugins = new Plugins();
     Cowl::timerEnd('cowl plugins load');
     // Load default helper
     Helpers::load('standard', 'form');
     Cowl::timerEnd('cowl init');
 }
开发者ID:erkie,项目名称:cowl,代码行数:35,代码来源:frontcontroller.php


示例7: __construct

 public function __construct()
 {
     foreach ($this->objects as $map) {
         $this->{strtolower($map . 'mapper')} = DataMapper::get($map);
     }
     $this->template = new Templater();
 }
开发者ID:erkie,项目名称:cowl,代码行数:7,代码来源:command.php


示例8: __construct

 public function __construct($id = null)
 {
     if (!is_null($id)) {
         $this->setID($id);
     }
     $this->validator = new Validator();
     $this->validator->setStoreErrors(true);
     $this->mapper = DataMapper::get(get_class($this));
 }
开发者ID:erkie,项目名称:cowl,代码行数:9,代码来源:domainobject.php


示例9: delete

 /**
  * Delete this student or related object.
  * If no parameters are set, this method deletes current student and all participant record related with this student.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $participant = new Participant();
         $participant->where_related($this);
         $participant->get();
         $participant->delete_all();
     }
     parent::delete($object, $related_field);
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:16,代码来源:student.php


示例10: delete

 /**
  * Delete this test or related object.
  * If no parameters are set, this method deletes current test and all files associated with this test.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id;
         if (file_exists($path_to_test_files)) {
             unlink_recursive($path_to_test_files, TRUE);
         }
     }
     parent::delete($object, $related_field);
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:16,代码来源:test.php


示例11: delete

 /**
  * Deletes relations (if parameters are set) or this object from database.
  * All comments which replies to this one will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $comments = $this->comment->get_iterated();
         foreach ($comments as $comment) {
             $comment->delete();
         }
     }
     parent::delete($object, $related_field);
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:17,代码来源:comment.php


示例12: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($id = null)
 {
     $trace = debug_backtrace();
     if ((empty($trace[2]['object']) || !$trace[2]['object'] instanceof DataMapper) && self::$isInstantiated) {
         throw new RuntimeException('System_setting can be instantiated only once!');
     }
     if ($this->hasTable($this->prefix . $this->table)) {
         parent::__construct($id);
     }
     self::$isInstantiated = true;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:14,代码来源:system_setting.php


示例13: get_iterated

 /**
  * Overwrite of the get_iterated() function to add filters to the search.
  * Refer to DataMapper ORM for get_iterated() function details.
  *
  * @author	Woxxy
  * @param	integer|NULL $limit Limit the number of results.
  * @param	integer|NULL $offset Offset the results when limiting.
  * @return	DataMapper Returns self for method chaining.
  */
 public function get_iterated($limit = NULL, $offset = NULL)
 {
     // Get the CodeIgniter instance, since it isn't set in this file.
     $CI =& get_instance();
     // Check if the user is allowed to see protected chapters.
     if (!$CI->tank_auth->is_allowed()) {
         $this->where('hidden', 0);
     }
     /**
      * @todo figure out why those variables don't get unset... it would be
      * way better to use the iterated in almost all cases in FoOlSlide
      */
     return parent::get_iterated($limit, $offset);
 }
开发者ID:KasaiDot,项目名称:FoOlSlide,代码行数:23,代码来源:page.php


示例14: delete

 /**
  * Delete this period or related object.
  * If no parameters are set, this method deletes current period and re-sort all other periods.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $lower_periods = new Period();
         $lower_periods->order_by('sorting', 'asc');
         $lower_periods->where('sorting > ', $this->sorting);
         $lower_periods->get_iterated();
         $ids = array();
         foreach ($lower_periods as $lower_period) {
             $ids[] = $lower_period->id;
         }
         if (count($ids) > 0) {
             $this->db->set('sorting', 'sorting-1', FALSE);
             $this->db->where_in('id', $ids);
             $this->db->update('periods');
         }
     }
     parent::delete($object, $related_field);
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:25,代码来源:period.php


示例15: delete

 /**
  * Delete this object from database or specified relations.
  * If this object is deleted, all student files will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     $this_task_set_id = $this->task_set_id;
     $this_student_id = $this->student_id;
     parent::delete($object, $related_field);
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $task_set = new Task_set();
         $task_set->get_by_id($this_task_set_id);
         if ($task_set->exists()) {
             $student_files = $task_set->get_student_files($this_student_id);
             if (count($student_files) > 0) {
                 foreach ($student_files as $file) {
                     @unlink($file['filepath']);
                 }
             }
         }
     }
 }
开发者ID:andrejjursa,项目名称:list-lms,代码行数:25,代码来源:solution.php


示例16: delete

 function delete($object = '')
 {
     if (empty($object)) {
         $this->deattach();
     }
     return parent::delete($object);
 }
开发者ID:blumine,项目名称:vunsy,代码行数:7,代码来源:content.php


示例17: __get

 public function __get($name)
 {
     // // the conditions below should be replace by using the _get_relationship_type method
     // belongs to relationship
     if (in_array($name, $this->belongs_to)) {
         return $this->_belongs_to($name);
     } elseif (array_key_exists($name, $this->belongs_to) && is_array($this->belongs_to[$name])) {
         return $this->_belongs_to($name, $this->belongs_to[$name]);
     } elseif (in_array($name, $this->has_many)) {
         return $this->_has_many($name);
     } elseif (array_key_exists($name, $this->has_many) && is_array($this->has_many[$name])) {
         return $this->_has_many($name, $this->has_many[$name]);
         // for has_many :through
     } elseif (array_key_exists($name, $this->has_many_through)) {
         return $this->_has_many_through($name);
     } elseif (in_array($name, $this->has_one)) {
         return $this->_has_one($name);
     } elseif (array_key_exists($name, $this->has_one) && is_array($this->has_one[$name])) {
         return $this->_has_one($name, $this->has_one[$name]);
     } elseif (method_exists($this, $name)) {
         #echo $this;
         return $this->{$name}();
     } else {
         return parent::__get($name);
     }
 }
开发者ID:pmorris,项目名称:CodeIgniter-Libraries,代码行数:26,代码来源:RailsMapper.php


示例18: __construct

 public function __construct(Database $db, $user)
 {
     parent::__construct($db);
     $this->table('logins');
     $this->columns(array('id', 'users_id', 'unixtime'));
     $this->has_one = array($user);
 }
开发者ID:bamcod,项目名称:PubCodeHub,代码行数:7,代码来源:User.php


示例19: Section

 function delete_with_sub()
 {
     // getting the subsections
     $c = new Section();
     $c->where('parent_section', $this->id);
     $c->get();
     // delete all subsections relations
     $c->delete_all();
     // delete all children
     $cont = new Content();
     $cont->get_where_parent_section($this->id);
     $cont->delete_all();
     // update all the sections sort after that section
     // that in the same parent section
     $s = new Section();
     $s->where('sort >', $this->sort);
     $s->where('parent_section', $this->parent_section);
     $s->get();
     foreach ($s->all as $item) {
         $item->sort--;
         $item->save();
     }
     //delete this section
     parent::delete($object);
 }
开发者ID:sigit,项目名称:vunsy,代码行数:25,代码来源:section.php


示例20: save

 function save($o = null, $log = true)
 {
     $action = $this->id ? 'updated' : 'inserted';
     parent::save($o);
     if ($log) {
         $this->logActivity($action);
     }
 }
开发者ID:broofa,项目名称:socipedia,代码行数:8,代码来源:basemodel.php



注:本文中的DataMapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP DataModel类代码示例发布时间:2022-05-23
下一篇:
PHP DataManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap