[6230] | 1 | <?php |
---|
| 2 | |
---|
| 3 | include_once('/home/acoutinho/expressoAPI/prototype/rest/hypermedia/hypermedia.php'); |
---|
| 4 | |
---|
| 5 | class DynamicContactDeleteResource extends Resource{ |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * Busca os eventos contidos nas agendas assinas do usuário |
---|
| 9 | * |
---|
| 10 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 11 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 12 | * @sponsor Caixa Econômica Federal |
---|
| 13 | * @author Adriano Coutinho da Silva |
---|
| 14 | * @author Adir Kuhn |
---|
| 15 | * @return Remove um resource do contato |
---|
| 16 | * @access public |
---|
| 17 | **/ |
---|
| 18 | function get($request) { |
---|
| 19 | try { |
---|
| 20 | |
---|
| 21 | $response = new Response($request); |
---|
| 22 | $response->addHeader('Content-type', 'aplication/json'); |
---|
| 23 | $this->secured(); |
---|
| 24 | $response->code = Response::OK; |
---|
| 25 | |
---|
| 26 | $dynamicContact = Controller::find(array('concept' => 'dynamicContact'), false, array('filter' => array('=', 'owner', Config::me("uidNumber")))); |
---|
| 27 | |
---|
| 28 | $h = new Hypermedia(); |
---|
| 29 | $c = new Collection($request->resources, 'DynamicContactsResource'); |
---|
| 30 | |
---|
| 31 | foreach($dynamicContact as $value){ |
---|
| 32 | $d = new Data(); |
---|
| 33 | $i = new Item($request->resources, 'DynamicContactResource', $value['id']); |
---|
| 34 | |
---|
| 35 | $d->setName('name'); |
---|
| 36 | $d->setValue($value['name']); |
---|
| 37 | $d->setPrompt('Nome do contato'); |
---|
| 38 | $d->setDataType('string'); |
---|
| 39 | $d->setMaxLength('100'); |
---|
| 40 | $d->setMinLength(null); |
---|
| 41 | $d->setRequired(false); |
---|
| 42 | |
---|
| 43 | $i->addData($d); |
---|
| 44 | |
---|
| 45 | $d->setName('email'); |
---|
| 46 | $d->setValue($value['mail']); |
---|
| 47 | $d->setPrompt('Email do contato'); |
---|
| 48 | $d->setDataType('string'); |
---|
| 49 | $d->setMaxLength('100'); |
---|
| 50 | $d->setMinLength(null); |
---|
| 51 | $d->setRequired(true); |
---|
| 52 | |
---|
| 53 | $i->addData($d); |
---|
| 54 | $l = new Link(); |
---|
| 55 | |
---|
| 56 | $l->setHref($i->getHref()); |
---|
| 57 | $l->setRel('delete'); |
---|
| 58 | $l->setAlt('Remover'); |
---|
| 59 | $l->setPrompt('Remover'); |
---|
| 60 | $l->setRender('link'); |
---|
| 61 | |
---|
| 62 | $i->addLink($l); |
---|
| 63 | |
---|
| 64 | $l->setHref($i->getHref()); |
---|
| 65 | $l->setRel('put'); |
---|
| 66 | $l->setAlt('Atualizar'); |
---|
| 67 | $l->setPrompt('Atualizar'); |
---|
| 68 | $l->setRender('link'); |
---|
| 69 | |
---|
| 70 | $i->addLink($l); |
---|
| 71 | |
---|
| 72 | $l->setHref($i->getHref()); |
---|
| 73 | $l->setRel('get'); |
---|
| 74 | $l->setAlt('Buscar'); |
---|
| 75 | $l->setPrompt('Buscar'); |
---|
| 76 | $l->setRender('link'); |
---|
| 77 | |
---|
| 78 | $i->addLink($l); |
---|
| 79 | $c->addItem($i); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | $t = new Template(); |
---|
| 83 | $d = new Data(); |
---|
| 84 | |
---|
| 85 | $d->setName('name'); |
---|
| 86 | $d->setValue(null); |
---|
| 87 | $d->setPrompt('Nome do contato'); |
---|
| 88 | $d->setDataType('string'); |
---|
| 89 | $d->setMaxLength(100); |
---|
| 90 | $d->setMinLength(null); |
---|
| 91 | $d->setRequired(false); |
---|
| 92 | |
---|
| 93 | $t->addData($d); |
---|
| 94 | $d = new Data(); |
---|
| 95 | |
---|
| 96 | $d->setName('email'); |
---|
| 97 | $d->setValue(null); |
---|
| 98 | $d->setPrompt('Email do contato'); |
---|
| 99 | $d->setDataType('string'); |
---|
| 100 | $d->setMaxLength(100); |
---|
| 101 | $d->setMinLength(null); |
---|
| 102 | $d->setRequired(true); |
---|
| 103 | |
---|
| 104 | $t->addData($d); |
---|
| 105 | |
---|
| 106 | $c->setTemplate($t); |
---|
| 107 | $d = new Data(); |
---|
| 108 | |
---|
| 109 | $d->setName('Dynamic Contacts'); |
---|
| 110 | $d->setValue(null); |
---|
| 111 | $d->setPrompt('Contatos Dinâmicos'); |
---|
| 112 | $d->setDataType(null); |
---|
| 113 | $d->setMaxLength(null); |
---|
| 114 | $d->setMinLength(null); |
---|
| 115 | $d->setRequired(null); |
---|
| 116 | |
---|
| 117 | $c->setData($d); |
---|
| 118 | |
---|
| 119 | $h->setCollection($c); |
---|
| 120 | |
---|
| 121 | } catch (Exception $ex){ |
---|
| 122 | $response->code = Response::INTERNALSERVERERROR; |
---|
| 123 | $error = array( |
---|
| 124 | 'code' => '500', |
---|
| 125 | 'title' => 'Internal Server Error', |
---|
| 126 | 'description' => $ex); |
---|
| 127 | return $response; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | $response->body = $h->getHypermeida($request->accept[10][0]); |
---|
| 131 | return $response; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | ?> |
---|