[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Устроюсь на удаленную подработку
Страницы: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
killer8080
Цитата (Zzepish @ 20.12.2013 - 17:22)
Dezigo
Не вижу смысла делать: мне нужна работа такого типа: сделал-получил деньги. Все. т.е. не постоянная.

ну так по таким тестовым задачам, потенциальный работодатель может судить о твоих способностях строить алгоритм решения задачи. wink.gif
Invis1ble
Цитата
Не вижу смысла делать работать: мне нужнаы работа такого типа: сделал-получил деньги. Все. т.е. не постоянная.
DySprozin
killer8080
ух ты! Красивое решение! wink.gif

_____________
Господа! Я ненавижу выканье на форумах, обращайтесь ко мне на ты.
Господа! Я буду тоже тыкать, но если это так кого-то из вас коробит, пожалуйста, предупреждайте меня об этом
---
Можешь помочь — помоги, не можешь — попытайся, не хочешь — уйди.
Dezigo
Идея была не короткого кода, а показать как можно реализовать:
Создаётся новое событие.
Для этого - создаётся файл с наследованием одного интерфейса и подключается. Колонка добавляется сама.
Решение я делал как разбитие логики.
- Кода много и файлов.,

Решение которые приложили здесь на форуме, мне нравятся и они будут работать.
Мне просто интересно кто как бы сделал и мыслит , особенно когда нету условий по времени и памяти.
:lol:

В след раз, я создам топик, задачу на время и скорость. :)
Index.php

<?php
/*
* Made by dezigoo
*
*/


error_reporting(-1);

ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

//load main class
require ('Event.php');

//load IEvents interface and classes
require ('events/IEvent.php');
require ('events/Meeting.php');
require ('events/Testing.php');

/*
* Idea of this pattern
*
* to create any new special day
* (just create a class with the same interface as IEvent)
* $event->setEvent(new Testing());
* 6 - number of months
* to run from the terminal use: php -a filename
*/

$event = new Events(6);
$event->setEvent(new \Event\Meeting()); //create meeting day
$event->setEvent(new \Event\Testing()); //create testing day
$event->run();
echo 'DONE';


Events.php
<?php
/*
* Made by dezigo
* Events
*/


class Events {

/*
* collects event objects
*/

private $events = array();

private $period = 5;

/*
* final results
*/

private $data = array();

private $columns = array('month' => array(
'Month'
));

private $filename = 'data.csv';

/*
* how many months do we want to see
*/

public function __construct($period = 5) {
$this->period = $period;
}

/*
* add new event
*/

public function setEvent(\Event\IEvent $event) {
$this->events[] = $event;
}

/*
* save all methods to the array (like a collection)
*/

public function run() {
if(!empty($this->events)) {
$total = 0;
foreach ($this->events as $eventName => $event) {
$this->data[$eventName] = array($event->getTitle());
for($i = 1; $i <= $this->period ; $i++){
if($i != 1) {
//except first month
$event->setDate('next month');
}
if($total === 0) { // we need to take months only once, should be one iteration
$this->columns['month'][] = $event->getDate()->format('M');
}
$this->data[$eventName][] = $event->getDate()->format('Y-m-d D');
}
}
}

//save to the fail
$this->save();
}

/*
* save data to the file
* parse an array as columns
*/

private function save() {

$fp = fopen($this->filename, 'w');

for($i = 0; $i < $this->period+1; $i++) {
$fields[] = $this->columns['month'][$i];
for($f = 0; $f < count($this->data); $f++) {
$fields[] = $this->data[$f][$i];
}
fputcsv($fp,$fields);
$fields = array();
}
fclose($fp);
}
}


events folder:
IEvent.php
<?php
/*
* Made by dezigo
*/

namespace Event;

interface IEvent {

public function getDate() ;

public function setDate($modify);

public function getTitle();
}


Meeting.php
<?php
/*
* Made by dezigo
* Meeting event
*/

namespace Event;

class Meeting implements IEvent {

public $title = 'Mid Month Meeting Date';
private $day = 14;
private $exceptions = array('Sun','Sat');
private $date;

public function __construct() {
$this->date = new \DateTime();
}

public function getTitle() {
return $this->title;
}

/*
* exceptions -> if 'Sun','Sat' then we use next monday
*/

public function getDate() {
$this->date->setDate($this->date->format('Y'), $this->date->format('m'),$this->day);

if(in_array($this->date->format("D"),$this->exceptions)) {
$this->date->modify('next monday');
}
return $this->date;
}

/*
* changing a date object, before to use it
*/

public function setDate($modify) {
$this->date->modify($modify);
}
}


Testing.php
<?php
/*
* Made by dezigo
* Testing event
*/

namespace Event;

class Testing implements IEvent {

public $title = 'End of Month Testing Date';
private $day = 'last monday of this month';
private $exceptions = array('Sun','Sat','Fri');
private $date;

public function __construct() {
$this->date = new \DateTime($this->day);
}

public function getTitle() {
return $this->title;
}

/*
* exceptions -> if 'Sun','Sat','Fri', then we use previous thursday
*/

public function getDate() {
if(in_array($this->date->format("D"),$this->exceptions)) {
$this->date->modify('previous thursday');
}
return $this->date;
}

/*
* changing a date object, before to use it
*/

public function setDate($modify) {
$this->date->modify($modify);
}
}
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.