21 private $data = array();
23 private $emptyValue =
"";
24 private $errorMessage = array();
34 if (!is_null($data)) {
35 foreach ($data as $y => $column) {
36 if (is_array($column)) {
37 foreach ($column as $x =>
$value) {
41 $this->addErrorMessage(sprintf(
"The array have to be a two dimensional array for all the column"));
56 if (isset($this->y[$x])) {
57 $xUUID = $this->x[$x];
59 foreach ($this->y as $key => $yUUID) {
60 if (isset($this->data[$xUUID]) && isset($this->data[$xUUID][$yUUID])) {
61 $row[$key] = $this->data[$xUUID][$yUUID];
63 $row[$key] = $this->emptyValue;
68 $this->addErrorMessage(sprintf(
"Unable to get row $s out of the border", $x));
83 if ((count($row) < count($this->y)) ||
$force ==
true) {
84 foreach ($row as $key =>
$value) {
91 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , count($row)));
106 if ($x < count($this->x) && ((count($row) < count($this->y)) ||
$force ==
true)) {
107 array_splice($this->x, $x, 0, array(
110 $this->x = array_values($this->x);
113 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , count($row)));
125 public function addRow(Array $row = array() , $x = null)
128 return $this->
setRow(count($this->x) , $row,
true);
129 } elseif ($x >= count($this->x)) {
130 return $this->
setRow($x, $row,
true);
132 $this->addErrorMessage(sprintf(
"Use insert row to insert a row"));
145 if (isset($this->x[$x])) {
147 $this->x = array_values($this->x);
150 $this->addErrorMessage(sprintf(
"Unable to delete row $x out of the border", $x));
165 if ((count($column) < count($this->x)) ||
$force ==
true) {
166 foreach ($column as $key =>
$value) {
173 $this->addErrorMessage(sprintf(
"Unable to set a column bigger than the row size (%s < %s)", count($this->x) , count($column)));
188 if ($y < count($this->y)) {
189 array_splice($this->y, $y, 0, array(
192 $this->y = array_values($this->y);
195 $this->addErrorMessage(sprintf(
"Unable to set a row bigger than the column size (%s < %s)", count($this->y) , count($row)));
207 public function addColumn(Array $column = array() , $y = null)
210 return $this->
setColumn(count($this->y) , $column,
true);
211 } elseif ($y >= count($this->y)) {
212 return $this->
setColumn($y, $column,
true);
214 $this->addErrorMessage(sprintf(
"Use insert column to insert a column"));
227 if (isset($this->y[$y])) {
229 $this->y = array_values($this->y);
232 $this->addErrorMessage(sprintf(
"Unable to delete column $y out of the border", $y));
245 if (isset($this->y[$y])) {
246 $yUUID = $this->y[$y];
248 foreach ($this->x as $key => $xUUID) {
249 if (isset($this->data[$xUUID]) && isset($this->data[$xUUID][$yUUID])) {
250 $column[$key] = $this->data[$xUUID][$yUUID];
252 $column[$key] = $this->emptyValue;
257 $this->addErrorMessage(sprintf(
"Unable to get column $y out of the border", $y));
273 if (isset($this->y[$y]) && isset($this->x[$x])) {
274 $this->data[$this->x[$x]][$this->y[$y]] =
$value;
276 if (!isset($this->x[$x])) {
277 for ($i = count($this->x); $i <= $x; $i++) {
278 $this->x[$i] = uniqid();
281 if (!isset($this->y[$y])) {
282 for ($i = count($this->y); $i <= $y; $i++) {
283 $this->y[$i] = uniqid();
286 $this->data[$this->x[$x]][$this->y[$y]] =
$value;
288 $this->addErrorMessage(sprintf(
"Unable to set x : $s, y :$s, value : $s", $x, $y,
$value));
303 if (isset($this->y[$y]) && isset($this->x[$x])) {
304 $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;