20 private $data = array();
22 private $emptyValue =
"";
23 private $errorMessage = array();
33 if (!is_null($data)) {
34 foreach ($data as $y => $column) {
35 if (is_array($column)) {
36 foreach ($column as $x =>
$value) {
40 $this->addErrorMessage(sprintf(
"The array have to be a two dimensional array for all the column"));
55 if (isset($this->y[$x])) {
56 $xUUID = $this->x[$x];
58 foreach ($this->y as $key => $yUUID) {
59 if (isset($this->data[$xUUID]) && isset($this->data[$xUUID][$yUUID])) {
60 $row[$key] = $this->data[$xUUID][$yUUID];
62 $row[$key] = $this->emptyValue;
67 $this->addErrorMessage(sprintf(
"Unable to get row %s out of the border", $x));
82 if ((count($row) < count($this->y)) ||
$force ==
true) {
83 foreach ($row as $key =>
$value) {
90 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , count($row)));
105 if ($x < count($this->x) && ((count($row) < count($this->y)) ||
$force ==
true)) {
106 array_splice($this->x, $x, 0, array(
109 $this->x = array_values($this->x);
112 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , count($row)));
124 public function addRow(Array $row = array() , $x = null)
127 return $this->
setRow(count($this->x) , $row,
true);
128 } elseif ($x >= count($this->x)) {
129 return $this->
setRow($x, $row,
true);
131 $this->addErrorMessage(sprintf(
"Use insert row to insert a row"));
144 if (isset($this->x[$x])) {
146 $this->x = array_values($this->x);
149 $this->addErrorMessage(sprintf(
"Unable to delete row $x out of the border", $x));
164 if ((count($column) < count($this->x)) ||
$force ==
true) {
165 foreach ($column as $key =>
$value) {
172 $this->addErrorMessage(sprintf(
"Unable to set a column bigger than the row size (%s < %s)", count($this->x) , count($column)));
187 if ($y < count($this->y)) {
188 array_splice($this->y, $y, 0, array(
191 $this->y = array_values($this->y);
194 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , $y));
206 public function addColumn(Array $column = array() , $y = null)
209 return $this->
setColumn(count($this->y) , $column,
true);
210 } elseif ($y >= count($this->y)) {
211 return $this->
setColumn($y, $column,
true);
213 $this->addErrorMessage(sprintf(
"Use insert column to insert a column"));
226 if (isset($this->y[$y])) {
228 $this->y = array_values($this->y);
231 $this->addErrorMessage(sprintf(
"Unable to delete column $y out of the border", $y));
244 if (isset($this->y[$y])) {
245 $yUUID = $this->y[$y];
247 foreach ($this->x as $key => $xUUID) {
248 if (isset($this->data[$xUUID]) && isset($this->data[$xUUID][$yUUID])) {
249 $column[$key] = $this->data[$xUUID][$yUUID];
251 $column[$key] = $this->emptyValue;
256 $this->addErrorMessage(sprintf(
"Unable to get column $y out of the border", $y));
272 if (isset($this->y[$y]) && isset($this->x[$x])) {
273 $this->data[$this->x[$x]][$this->y[$y]] =
$value;
275 if (!isset($this->x[$x])) {
276 for ($i = count($this->x); $i <= $x; $i++) {
277 $this->x[$i] = uniqid();
280 if (!isset($this->y[$y])) {
281 for ($i = count($this->y); $i <= $y; $i++) {
282 $this->y[$i] = uniqid();
285 $this->data[$this->x[$x]][$this->y[$y]] =
$value;
287 $this->addErrorMessage(sprintf(
"Unable to set x : %s, y :%s, value : %s", $x, $y,
$value));
302 if (isset($this->y[$y]) && isset($this->x[$x])) {
303 if (isset($this->data[$this->x[$x]][$this->y[$y]]))
$value = $this->data[$this->x[$x]][$this->y[$y]];
306 } elseif (count($x) >= $x && count($y) >= $y) {
307 return $this->emptyValue;
309 $this->addErrorMessage(sprintf(
"Unable to get x : %s, y :%s out of the border", $x, $y));
320 $nbX = count($this->x);
321 $nbY = count($this->y);
323 $returnArray = array();
324 for ($x = 0; $x < $nbX; $x++) {
325 $returnArray[$x] = array();
326 for ($y = 0; $y < $nbY; $y++) {
327 $returnArray[$x][$y] = $this->
getValue($x, $y);
339 return $this->emptyValue;
350 $this->emptyValue = $emptyValue;
358 private function addErrorMessage($error)
360 $this->errorMessage[] = $error;
369 if (count($this->errorMessage)) {
370 $lastMessage = end($this->errorMessage);
371 reset($this->errorMessage);
383 return $this->errorMessage;
insertRow($x, Array $row=array(), $force=false)
addRow(Array $row=array(), $x=null)
addColumn(Array $column=array(), $y=null)
setColumn($y, Array $column, $force=false)
insertColumn($y, Array $column=array(), $force=false)
__construct(Array $data=null)
setRow($x, Array $row, $force=false)
setValue($x, $y, $value, $force=false)
setEmptyValue($emptyValue)