set() public method

Allows several properties to be assigned at once, i.e.: $record->set(array('title' => 'Lorem Ipsum', 'value' => 42));
public set ( array $data ) : void
$data array An associative array of fields and values to assign to this `Entity` instance.
return void
コード例 #1
0
ファイル: EntityTest.php プロジェクト: ncud/sagalaya
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
 }
コード例 #2
0
ファイル: EntityTest.php プロジェクト: unionofrad/lithium
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
     $this->assertTrue($entity->modified('foo'));
     $this->assertTrue($entity->modified('baz'));
     /* and last, checking a non-existing field */
     $this->assertNull($entity->modified('ole'));
     $subentity = new Entity();
     $subentity->set($data);
     $entity->set(array('ble' => $subentity));
     $this->assertEqual(array('foo' => true, 'baz' => true, 'ble' => true), $entity->modified());
     $this->assertTrue($entity->ble->modified('foo'));
     $this->assertEmpty($entity->ble->modified('iak'));
     $this->assertEqual($entity->ble->modified(), array('foo' => true, 'baz' => true));
     $data = array('foo' => 'bar', 'baz' => 'dib');
     //it's the default data array in the test
     $entity = new Entity();
     $entity->set($data);
     $entity->sync();
     /* Checking empty values */
     $entity->foo = '';
     $this->assertTrue($entity->modified('foo'));
     $this->assertEqual(array('foo' => true, 'baz' => false), $entity->modified());
     /* and checking null values */
     $entity->sync();
     $entity->foo = null;
     $this->assertTrue($entity->modified('foo'));
 }
コード例 #3
0
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
     $this->assertTrue($entity->modified('foo'));
     $this->assertTrue($entity->modified('baz'));
     $this->assertNull($entity->modified('ole'));
     $subentity = new Entity();
     $subentity->set($data);
     $entity->set(array('ble' => $subentity));
     $this->assertEqual(array('foo' => true, 'baz' => true, 'ble' => true), $entity->modified());
     $this->assertTrue($entity->ble->modified('foo'));
     $this->assertFalse($entity->ble->modified('iak'));
     $this->assertEqual($entity->ble->modified(), array('foo' => true, 'baz' => true));
 }
コード例 #4
0
ファイル: Model.php プロジェクト: rich97/li3_tree
	/**
	 * update a Node (when parent Id is changed)
	 * 
	 * all the "move an element with all its children" magic happens here!
	 * first we calculate movements (shiftX, shiftY), afterwards shifting of ranges is done,
	 * where rangeX is is the range of the element to move and rangeY the area between rangeX
	 * and the new position of rangeX.
	 * to avoid double shifting of already shifted data rangex first is shifted in area < 0 
	 * (which is always empty), after correcting rangeY's left and rights we move it to its
	 * designated position.
	 * 
	 * @param \lithium\data\Model $self the model using this behavior
	 * @param \lithium\data\Entity $entity updated tree element
	 */
	private static function updateNode($self,$entity){
		extract(static::$_tree_config[$self]);

		$newParent = static::getById($self,$entity->data($parent));

		$span = $entity->data($right) - $entity->data($left);
		$spanToZero = $entity->data($right);
		
		$rangeX = array('floor'=>$entity->data($left),'ceiling'=>$entity->data($right));
		$shiftX = 0;
					
		static::updateNodesIndicesBetween($self, $rangeX, '-', $spanToZero);
		if($entity->data($right) < $newParent->data($right)){
			$rangeY = array('floor'=>$entity->data($right)+1,'ceiling'=>$newParent->data($right)-1);
			$shiftY = $span + 1;
			static::updateNodesIndicesBetween($self, $rangeY, '-', $shiftY);
			$shiftX = $newParent->data($right) - $entity->data($right) -1;
		}else{
			$rangeY = array('floor'=>$newParent->data($right),'ceiling'=>$entity->data($left)-1);
			$shiftY = ($newParent->data($left) - $entity->data($left) + 1) * -1;
			static::updateNodesIndicesBetween($self, $rangeY, '+', $shiftY);
			$shiftX = $newParent->data($left) - $entity->data($left) + 1;
		}
		static::updateNodesIndicesBetween($self, array('floor'=> (0 - $span),'ceiling'=> 0), '+',$spanToZero+$shiftX);
		$entity->set(array($left=>$entity->data($left)+$shiftX, $right=>$entity->data($right)+$shiftX));

	}