diff --git a/getLastNews.php b/getLastNews.php new file mode 100644 index 0000000..9b6b413 --- /dev/null +++ b/getLastNews.php @@ -0,0 +1,12 @@ +channel->item[$i]; + + echo $item->title . "
"; + echo $item->link . "
"; + echo $item->description . "

"; +} +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..cb9b00a --- /dev/null +++ b/index.php @@ -0,0 +1,127 @@ + "Apple", + 'in_stock' => 22, + 'sold' => 17 + ), + array ( + 'product_name' => "Strawberry", + 'in_stock' => 15, + 'sold' => 13 + ), + array ( + 'product_name' => "Banana", + 'in_stock' => 130, + 'sold' => 35 + ), + array ( + 'product_name' => "Kiwi", + 'in_stock' => 150, + 'sold' => 17 + ), + array ( + 'product_name' => "Bomb", + 'in_stock' => 1600, + 'sold' => 17 + ), + ); + + public function test_method ($cached_cell, $sort_type, $filter_by_keyword, $field_1_optional, $field_2_optional) { + // caching + apc_store($cached_cell, $this->food); + $cached_cell = apc_fetch($cached_cell); + // END caching + + // sorting + switch ($sort_type) { + case "a": // sorting by index + asort($cached_cell); + break; + case "ar": // reverse sorting by index + arsort($cached_cell); + break; + case "k": // sorting by key + ksort($cached_cell); + break; + case "kr": // reverse sorting by key + krsort($cached_cell); + break; + default: + ; + } + // END sorting + + // filtering + if ($filter_by_keyword) { + $m_cell = array(); + $key = $filter_by_keyword; + + $m_cell_after_one_key = array_filter( + $cached_cell, + function ($var) use ($key) { + foreach ($var as $value) { + if ($value == $key) { + return $value; + } + } + } + ); + + $m_cell = array_merge($m_cell, $m_cell_after_one_key); + + $cached_cell = $m_cell; + } + // END filtering + + // fields + if ($field_1_optional || $field_2_optional) { + $cached_cell = array_column($cached_cell, $field_1_optional, $field_2_optional); + } else { + $this->render_table_from_cached_array($cached_cell); + } + // END fields + + return $cached_cell; + } + + public function render_table_from_cached_array ($cached_cell) { + echo ' + + + + + + + ' . $this->render_rows_from_array($cached_cell) . ' +
Product nameIn stockSold
+ '; + } + + public function render_rows_from_array ($cached_cell) { + $code_block = ""; + foreach ($cached_cell as $row) { + $code_block .= "\n\t\t\t\t"; + foreach ($row as $cell) { + $code_block .= "\n\t\t\t\t\t" . $cell . ""; + } + $code_block .= "\n\t\t\t\t"; + } + return $code_block; + } +} + +// RENDER PAGE +$page = new InfoBlocks(); +$page->test_method("food", "kr", "17", "", ""); +// END RENDER PAGE \ No newline at end of file