当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::setTemplate方法代码示例

本文整理汇总了PHP中Collection::setTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setTemplate方法的具体用法?PHP Collection::setTemplate怎么用?PHP Collection::setTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::setTemplate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importStringsProvider

 /**
  * Provides data for testImportStrings.
  *
  * @return 
  *   - 0: Object $model
  *   - 1: string JSON
  */
 function importStringsProvider()
 {
     $return = array();
     $data = new Data('title', 'CollectionJson', 'Title');
     $dataArray = array($data, new Data('author', 'Aaron Klump', 'Author'));
     $link = new Link('http://www.intheloftstudios.com/collection-json', 'item');
     $item = new Item('http://www.intheloftstudios.com/api/1.0/packages', $dataArray, array($link));
     $template = new Template(array(new Data('title', '', 'Title'), new Data('author', '', 'Author')));
     $queryArray = array(new Data('search', ''));
     $query = new Query('http://www.intheloftstudios.com/api/1.0/packages', $queryArray, 'collection', 'search');
     $error = new Error(403);
     $collection = new Collection('http://www.intheloftstudios.com/api/1.0/packages');
     $collection->setTemplate($template)->addQuery($query)->addItem($item)->setLInks(array($link));
     $return[] = array($data, strval($data));
     $return[] = array($error, strval($error));
     $return[] = array($item, strval($item));
     $return[] = array($link, strval($link));
     $return[] = array($query, strval($query));
     $return[] = array($template, strval($template));
     $return[] = array($collection, strval($collection));
     return $return;
 }
开发者ID:aklump,项目名称:collection_json,代码行数:29,代码来源:ObjectTest.php

示例2: get

 /**
  * Retorna um contato recente 
  *
  * @license    http://www.gnu.org/copyleft/gpl.html GPL
  * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
  * @sponsor    Caixa Econômica Federal
  * @author     José Vicente Tezza Jr. 
  * @return     Retorna um contato recente
  * @access     public
  * */
 function get($request, $id)
 {
     $this->secured();
     //verificar se a preferencia de contatos dinamicos nao esta ativada
     if (!$this->isEnabledDynamicContacts(Config::me("uidNumber"))) {
         $response = new Response($request);
         $this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
         return $response;
     }
     $response = new Response($request);
     $response->addHeader('Content-type', 'aplication/json');
     $response->code = Response::OK;
     $h = new Hypermedia();
     $c = new Collection($request->resources, 'DynamicContactResource', $id);
     try {
         $dynamicContact = Controller::read(array('concept' => 'dynamicContact'), false, array('filter' => array('AND', array('=', 'owner', Config::me("uidNumber")), array('=', 'id', $id))));
         //Se nao foi encontrado contatos na consulta
         if (!$dynamicContact) {
             $this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Dynamic Contact not found.');
             return $response;
         }
         //Normaliza dado
         if (is_array($dynamicContact)) {
             $dynamicContact = $dynamicContact[0];
         }
         $t = new Template();
         $d = new Data();
         $d->setName('name');
         $d->setValue(null);
         $d->setPrompt('Nome do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('mail');
         $d->setValue(null);
         $d->setPrompt('Email do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('number_of_messages');
         $d->setValue(null);
         $d->setPrompt('Quantidade de mensagens enviadas');
         $d->setDataType('integer');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(false);
         $t->addData($d);
         $c->setTemplate($t);
         $d = new Data();
         $d->setName('id');
         $d->setValue($dynamicContact['id']);
         $d->setPrompt('Identificador do Contato Recente');
         $d->setDataType('integer');
         $d->setMaxLength(null);
         $d->setMinLength(null);
         $d->setRequired(true);
         $c->addData($d);
         $d = new Data();
         $d->setName('name');
         $d->setValue($dynamicContact['name']);
         $d->setPrompt('Nome do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $c->addData($d);
         $d = new Data();
         $d->setName('mail');
         $d->setValue($dynamicContact['mail']);
         $d->setPrompt('Email do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $c->addData($d);
         $d = new Data();
         $d->setName('number_of_messages');
         $d->setValue($dynamicContact['number_of_messages']);
         $d->setPrompt('Quantidade de mensagens enviadas');
         $d->setDataType('integer');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(false);
         $c->addData($d);
//.........这里部分代码省略.........
开发者ID:cjvaz,项目名称:expressomail,代码行数:101,代码来源:DynamicContactResource.php

示例3: get

 /**
  * Retorna um contato compartilhado 
  *
  * @license    http://www.gnu.org/copyleft/gpl.html GPL
  * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
  * @sponsor    Caixa Econômica Federal
  * @author     José Vicente Tezza Jr. 
  * @return     Retorna um contato Compartilhado
  * @access     public
  * */
 function get($request, $id)
 {
     $this->secured();
     $response = new Response($request);
     $response->addHeader('Content-type', 'aplication/json');
     $response->code = Response::OK;
     $h = new Hypermedia();
     $c = new Collection($request->resources, 'SharedGroupResource');
     try {
         //Recupera o contato
         $contact = Controller::find(array('concept' => 'contact'), false, array('filter' => array('=', 'id', $id)));
         if (!$contact) {
             $this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
             return $response;
         }
         //Proprietario do contato
         $ownerId = $contact[0]['user'];
         $idS = array(Config::me("uidNumber"));
         $acl = array();
         //Recupera o uidNumber do usuário que compartilhou o grupo com o usuário logado
         $sql = 'SELECT acl_account as "uidNumber", acl_rights as "acl" ' . 'FROM phpgw_acl ' . 'WHERE (acl_location =   \'' . Config::me("uidNumber") . '\' AND acl_appname =  \'contactcenter\' AND acl_account = \'' . $ownerId . '\')';
         $shareds = Controller::service('PostgreSQL')->execResultSql($sql);
         //Verifica o acesso definido para o usuario logado
         $flagContact = false;
         if (!empty($shareds) && $shareds) {
             foreach ($shareds as $s) {
                 array_push($idS, $s['uidNumber']);
                 $acl[$s['uidNumber']] = $this->decodeAcl(decbin($s['acl']));
                 //verifica se o proprietario do contato habilitou o acesso de leitura para o usuario logado
                 if ($s['uidNumber'] == $ownerId && $acl[$s['uidNumber']]['read']) {
                     $flagContact = true;
                 }
             }
         }
         //Se o contato nao esta compartilhado
         if (!$flagContact) {
             $this->createException($request, $response, Response::UNAUTHORIZED, 'unauthorized', 'Resource unauthorized.');
             return $response;
         }
         //Obtem informacoes do proprietario do contato
         $userOwner = Controller::read(array('concept' => 'user', 'service' => 'OpenLDAP'), false, array('filter' => array('=', 'id', $ownerId), 'notExternal' => true));
         if (is_array($userOwner)) {
             $userOwner = $userOwner[0];
         }
         $t = new Template();
         $d = new Data();
         $d->setName('name');
         $d->setValue(null);
         $d->setPrompt('Nome do Contato');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('email');
         $d->setValue(null);
         $d->setPrompt('Email do Contato');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('telefone');
         $d->setValue(null);
         $d->setPrompt('Telefone do Contato');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $c->setTemplate($t);
         $d = new Data();
         $d->setName('name');
         $d->setValue($contact[0]['name']);
         $d->setPrompt('Nome do Contato');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $c->addData($d);
         $d = new Data();
         $d->setName('email');
         $d->setValue($contact[0]['email']);
         $d->setPrompt('Email do Contato');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
//.........这里部分代码省略.........
开发者ID:cjvaz,项目名称:expressomail,代码行数:101,代码来源:SharedContactResource.php

示例4: get


//.........这里部分代码省略.........
                         $l->setRel('get');
                         $l->setAlt('Buscar');
                         $l->setPrompt('Buscar');
                         $l->setRender('link');
                         $i->addLink($l);
                         /* Descomentar ao criar recursos
                         			      if ($acl[$value['user']]['delete']) {
                         			      $l = new Link();
                         			      $l->setHref('');
                         			      $l->setRel('delete');
                         			      $l->setAlt('Remover');
                         			      $l->setPrompt('Remover');
                         			      $l->setRender('link');
                         			      $i->addLink($l);
                         			      }
                         
                         			      if ($acl[$value['user']]['put']) {
                         			      $l = new Link();
                         			      $l->setHref('');
                         			      $l->setRel('put');
                         			      $l->setAlt('Atualizar');
                         			      $l->setPrompt('Atualizar');
                         			      $l->setRender('link');
                         			      $i->addLink($l);
                         			      }
                         			     */
                     } else {
                         /* Descomentar ao criar recursos
                         			      $l = new Link();
                         
                         			      $l->setHref('');
                         			      $l->setRel('delete');
                         			      $l->setAlt('Remover');
                         			      $l->setPrompt('Remover');
                         			      $l->setRender('link');
                         
                         			      $i->addLink($l);
                         
                         			      $l = new Link();
                         			      $l->setHref('');
                         			      $l->setRel('put');
                         			      $l->setAlt('Atualizar');
                         			      $l->setPrompt('Atualizar');
                         			      $l->setRender('link');
                         
                         			      $i->addLink($l);
                         			     */
                         $l = new Link();
                         $l->setHref('/contact/' . $value['id']);
                         $l->setRel('get');
                         $l->setAlt('Buscar');
                         $l->setPrompt('Buscar');
                         $l->setRender('link');
                         $i->addLink($l);
                     }
                     $c->addItem($i);
                 }
             }
         }
         if (!$contacts && !$dynamicContacts && !$groups) {
             $this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
             return $response;
         }
         $t = new Template();
         $d = new Data();
         $d->setName('id');
         $d->setValue(null);
         $d->setPrompt('Id do Grupo');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('user');
         $d->setValue(null);
         $d->setPrompt('Id Dono do Grupo');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('name');
         $d->setValue(null);
         $d->setPrompt('Nome do Grupo');
         $d->setDataType('string');
         $d->setMaxLength('100');
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $c->setTemplate($t);
         $h->setCollection($c);
         $response->body = $h->getHypermedia($request->accept[10][0]);
         return $response;
     } catch (Exception $ex) {
         $this->createException($request, $response, Response::INTERNALSERVERERROR, 'Internal Server Error', $ex);
         return $response;
     }
 }
开发者ID:cjvaz,项目名称:expressomail,代码行数:101,代码来源:UserContactsResource.php

示例5: get


//.........这里部分代码省略.........
         }
         $dynamicContacts = array_slice($dynamicContacts, 0, 50);
         foreach ($dynamicContacts as $value) {
             $d = new Data();
             $i = new Item($request->resources, 'DynamicContactsResource', $value['id']);
             $d->setName('name');
             $d->setValue($value['name']);
             $d->setPrompt('Nome do Contato Recente');
             $d->setDataType('string');
             $d->setMaxLength('100');
             $d->setMinLength(null);
             $d->setRequired(true);
             $i->addData($d);
             $d = new Data();
             $d->setName('mail');
             $d->setValue($value['mail']);
             $d->setPrompt('Email do Contato Recente');
             $d->setDataType('string');
             $d->setMaxLength('100');
             $d->setMinLength(null);
             $d->setRequired(true);
             $i->addData($d);
             $d = new Data();
             $d->setName('number_of_messages');
             $d->setValue($value['number_of_messages']);
             $d->setPrompt('Quantidade de mensagens enviadas');
             $d->setDataType('integer');
             $d->setMaxLength('100');
             $d->setMinLength(null);
             $d->setRequired(false);
             $i->addData($d);
             $d = new Data();
             $d->setName('id');
             $d->setValue($value['id']);
             $d->setPrompt('Id do contato dinamico');
             $d->setDataType('integer');
             $d->setMaxLength('100');
             $d->setMinLength(null);
             $d->setRequired(false);
             $i->addData($d);
             $l = new Link();
             $l->setHref('');
             $l->setRel('delete');
             $l->setAlt('Remover');
             $l->setPrompt('Remover');
             $l->setRender('link');
             $i->addLink($l);
             $l = new Link();
             $l->setHref('');
             $l->setRel('put');
             $l->setAlt('Atualizar');
             $l->setPrompt('Atualizar');
             $l->setRender('link');
             $i->addLink($l);
             $l = new Link();
             $l->setHref('/dynamiccontact/' . $value['id']);
             $l->setRel('get');
             $l->setAlt('Buscar');
             $l->setPrompt('Buscar');
             $l->setRender('link');
             $i->addLink($l);
             $c->addItem($i);
         }
         $t = new Template();
         $d = new Data();
         $d->setName('name');
         $d->setValue(null);
         $d->setPrompt('Nome do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(false);
         $t->addData($d);
         $d = new Data();
         $d->setName('mail');
         $d->setValue(null);
         $d->setPrompt('Email do Contato Recente');
         $d->setDataType('string');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(true);
         $t->addData($d);
         $d = new Data();
         $d->setName('number_of_messages');
         $d->setValue(null);
         $d->setPrompt('Quantidade de mensagens enviadas');
         $d->setDataType('integer');
         $d->setMaxLength(100);
         $d->setMinLength(null);
         $d->setRequired(false);
         $t->addData($d);
         $c->setTemplate($t);
         $h->setCollection($c);
     } catch (Exception $ex) {
         $this->createException($request, $response, Response::INTERNALSERVERERROR, 'Internal Server Error', $ex);
         return $response;
     }
     $response->body = $h->getHypermedia($request->accept[10][0]);
     return $response;
 }
开发者ID:cjvaz,项目名称:expressomail,代码行数:101,代码来源:DynamicContactsResource.php

示例6: testCollection

 public function testCollection()
 {
     $obj = new Collection('http://www.website.com/api/1.0/item/1');
     $control = '{"collection":{"version":"1.0","href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1"}}';
     $this->assertSame($control, (string) $obj);
     $obj->addLink(new Link('http://www.website.com/api/1.0/item/1', 'alternate', 'view', 'link', 'View on website'));
     $obj->addLink(new Link('http://alt.website.com/api/1.0/item/17', 'alternate', 'view', 'link', 'View on website2'));
     $control = '{"collection":{"version":"1.0","href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","links":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","rel":"alternate","name":"view","render":"link","prompt":"View on website"},{"href":"http:\\/\\/alt.website.com\\/api\\/1.0\\/item\\/17","rel":"alternate","name":"view","render":"link","prompt":"View on website2"}]}}';
     $this->assertSame($control, (string) $obj);
     $obj->addItem(new Item('http://www.website.com/api/1.0/person/1', array(new Data('first', 'Clark', 'First Name'), new Data('last', 'Kent', 'Last Name'), new Data('age', 39, 'Age'), new Data('color', 'black'))));
     $obj->addItem(new Item('http://www.website.com/api/1.0/person/2', array(new Data('first', 'Louis', 'First Name'), new Data('last', 'Lane', 'Last Name'), new Data('age', 36, 'Age'), new Data('color', 'brown'))));
     $control = '{"collection":{"version":"1.0","href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","links":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","rel":"alternate","name":"view","render":"link","prompt":"View on website"},{"href":"http:\\/\\/alt.website.com\\/api\\/1.0\\/item\\/17","rel":"alternate","name":"view","render":"link","prompt":"View on website2"}],"items":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/1","data":[{"name":"first","prompt":"First Name","value":"Clark"},{"name":"last","prompt":"Last Name","value":"Kent"},{"name":"age","prompt":"Age","value":39},{"name":"color","value":"black"}]},{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/2","data":[{"name":"first","prompt":"First Name","value":"Louis"},{"name":"last","prompt":"Last Name","value":"Lane"},{"name":"age","prompt":"Age","value":36},{"name":"color","value":"brown"}]}]}}';
     $this->assertSame($control, (string) $obj);
     $obj->setQueries(array(new Query('http://example.org/search', array(new Data('search', '')), 'search', 'Enter search string'), new Query('http://example.org/find', array(new Data('find', '')), 'find', 'Enter find string')));
     $control = '{"collection":{"version":"1.0","href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","links":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","rel":"alternate","name":"view","render":"link","prompt":"View on website"},{"href":"http:\\/\\/alt.website.com\\/api\\/1.0\\/item\\/17","rel":"alternate","name":"view","render":"link","prompt":"View on website2"}],"items":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/1","data":[{"name":"first","prompt":"First Name","value":"Clark"},{"name":"last","prompt":"Last Name","value":"Kent"},{"name":"age","prompt":"Age","value":39},{"name":"color","value":"black"}]},{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/2","data":[{"name":"first","prompt":"First Name","value":"Louis"},{"name":"last","prompt":"Last Name","value":"Lane"},{"name":"age","prompt":"Age","value":36},{"name":"color","value":"brown"}]}],"queries":[{"href":"http:\\/\\/example.org\\/search","rel":"search","prompt":"Enter search string","data":[{"name":"search","value":""}]},{"href":"http:\\/\\/example.org\\/find","rel":"find","prompt":"Enter find string","data":[{"name":"find","value":""}]}]}}';
     $this->assertSame($control, (string) $obj);
     $obj->setTemplate(new Template(array(new Data('first', '', 'First Name'), new Data('last', '', 'Last Name'), new Data('age', '', 'Age'), new Data('color', ''))));
     $control = '{"collection":{"version":"1.0","href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","links":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/item\\/1","rel":"alternate","name":"view","render":"link","prompt":"View on website"},{"href":"http:\\/\\/alt.website.com\\/api\\/1.0\\/item\\/17","rel":"alternate","name":"view","render":"link","prompt":"View on website2"}],"items":[{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/1","data":[{"name":"first","prompt":"First Name","value":"Clark"},{"name":"last","prompt":"Last Name","value":"Kent"},{"name":"age","prompt":"Age","value":39},{"name":"color","value":"black"}]},{"href":"http:\\/\\/www.website.com\\/api\\/1.0\\/person\\/2","data":[{"name":"first","prompt":"First Name","value":"Louis"},{"name":"last","prompt":"Last Name","value":"Lane"},{"name":"age","prompt":"Age","value":36},{"name":"color","value":"brown"}]}],"queries":[{"href":"http:\\/\\/example.org\\/search","rel":"search","prompt":"Enter search string","data":[{"name":"search","value":""}]},{"href":"http:\\/\\/example.org\\/find","rel":"find","prompt":"Enter find string","data":[{"name":"find","value":""}]}],"template":{"data":[{"name":"first","prompt":"First Name","value":""},{"name":"last","prompt":"Last Name","value":""},{"name":"age","prompt":"Age","value":""},{"name":"color","value":""}]}}}';
     $this->assertSame($control, (string) $obj);
 }
开发者ID:aklump,项目名称:collection_json,代码行数:20,代码来源:CollectionJsonTest.php


注:本文中的Collection::setTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。