本文整理汇总了PHP中Collection::addItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::addItem方法的具体用法?PHP Collection::addItem怎么用?PHP Collection::addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::addItem方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: seleccComments
public static function seleccComments($tittle)
{
$c = new Collection();
$conn = conexion();
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$sentencia = $conn->stmt_init();
if (!$sentencia->prepare("select * from comentarios where (blog_id=?)")) {
echo "Falló la preparación: (" . $conn->errno . ") " . $conn->error;
} else {
mysqli_stmt_bind_param($sentencia, "i", $tittle);
if (!$sentencia->execute()) {
return "0";
} else {
$sentencia->bind_result($Id, $Titulo, $Autor, $Texto, $Blog_id, $Fecha);
while ($sentencia->fetch()) {
$comment = new Comment(array("autor" => $Autor, "fecha" => $Fecha, "titulo" => $Titulo, "texto" => $Texto, "id" => $Id, "blog_id" => $Blog_id));
$c->addItem($comment);
}
$conn->close();
return $c;
}
}
}
}
示例2: addItem
/**
* Adding entity to collection.
*
* @param Entity $entity Entity object
* @param string $key key
* @return Entity
* @throws \Exception
*/
public function addItem(Entity $entity, $key = null)
{
$entityClass = get_class($entity);
if ($entityClass !== $this->getEntityClass()) {
throw new \Exception("Item `{$entityClass}` is not valid current collection type `{$this->getEntityClass()}`");
}
return parent::addItem($entity, $key);
}
示例3: filter
public function filter($key, $value)
{
$col = new Collection();
foreach ($this->data as $row) {
if (isset($row[$key]) && Utils::startsWith($row[$key], $value)) {
$col->addItem($row);
}
}
return $col->items;
}
示例4: get
//.........这里部分代码省略.........
$l->setAlt('Buscar');
$l->setPrompt('Buscar');
$l->setRender('link');
$i->addLink($l);
}*/
} else {
/*Descomentar ao implementar métodos no recurso
$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('');
$l->setRel('get');
$l->setAlt('Buscar');
$l->setPrompt('Buscar');
$l->setRender('link');
$i->addLink($l);
*/
}
$c->addItem($i);
}
}
if (!$groups) {
$this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
return $response;
}
$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);
示例5: addItem
public function addItem($item, $key = null)
{
parent::addItem($item, $key);
}
示例6: get
/**
* Retorna uma lista de grupos
*
* @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 Adrino Coutinho da Silva.
* @return Retorna uma lista de Contatos Dinâmicos, Grupos, Contatos Pessoais, Grupos Compartilhados e Contatos Compartilhados
* @access public
* */
function get($request)
{
$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, 'UserContactsResource');
try {
$d = new Data();
$d->setName('User Contacts');
$d->setValue(null);
$d->setPrompt('Contatos do usuário');
$d->setDataType(null);
$d->setMaxLength(null);
$d->setMinLength(null);
$d->setRequired(null);
$c->addData($d);
//Recupera os contatos dinâmicos do usuario
$dynamicContacts = Controller::find(array('concept' => 'dynamicContact'), false, array('filter' => array('=', 'owner', Config::me("uidNumber")), 'order' => array('number_of_messages', 'name', 'mail'), 'orderDesc' => array(true, false, false)));
if ($dynamicContacts) {
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((int) $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);
}
}
$idS = array(Config::me("uidNumber"));
//.........这里部分代码省略.........
示例7: get
/**
* Retorna uma lista de contatos recentes
*
* @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 uma lista de contatos recentes
* @access public
* */
function get($request)
{
$this->secured();
$response = new Response($request);
$response->addHeader('Content-type', 'aplication/json');
$response->code = Response::OK;
$h = new Hypermedia();
$c = new Collection($request->resources, 'DynamicContactsResource');
try {
$dynamicContacts = Controller::find(array('concept' => 'dynamicContact'), false, array('filter' => array('=', 'owner', Config::me("uidNumber")), 'order' => array('number_of_messages', 'name', 'mail'), 'orderDesc' => array(true, false, false)));
//Se nao foi encontrado contatos na consulta
if (!$dynamicContacts) {
$this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Dynamic Contact not found.');
return $response;
}
$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);
//.........这里部分代码省略.........
示例8: getAllBook
function getAllBook()
{
$key = 'book';
$collection = CacheManager::get($key, TRUE);
if ($collection) {
return $collection;
}
$collection = new Collection();
$this->connect();
$result = $this->conn->query("CALL sp_get_all_book()");
if ($result) {
//$row = $result->fetch_assoc();
while ($obj = $result->fetch_object()) {
$book = new Book();
$book->setBookId($obj->Book_id);
$book->setTitle($obj->Title);
$book->setPublisherId($obj->Publisher_id);
$book->setIsbn($obj->Isbn);
$book->setCategoryId($obj->Category_id);
$book->setPublisherName($obj->Publisher_name);
$book->setCategoryName($obj->Subject);
$collection->addItem($book, $obj->Book_id);
}
$result->close();
// for fetch_object()
}
//$result->free_result(); // for fetch_assoc()
$this->close();
CacheManager::set($key, $collection, TRUE);
return $collection;
}
示例9: test_iterator_remove_item_2
public function test_iterator_remove_item_2()
{
$actual = '';
$coll = new Collection();
$coll->addItem('HelloWorld1', 'msg1');
$coll->addItem('HelloWorld2');
foreach ($coll as $key => $item) {
if ($key == 'msg1') {
$coll->removeItem($key);
$actual = $item;
}
}
$this->assertEquals('HelloWorld2', $actual);
}
示例10: 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);
}
示例11: searchPost
public static function searchPost($search)
{
$titulo = $search;
$conn = conexion();
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$sentencia = $conn->stmt_init();
if (!$sentencia->prepare("select * from blog where texto like '%" . $titulo . "%' OR titulo like '%" . $titulo . "%'")) {
echo "Falló la preparación: (" . $conn->errno . ") " . $conn->error;
} else {
if (!$sentencia->execute()) {
return "0";
} else {
$sentencia->bind_result($Autor, $Fecha, $Titulo, $Texto, $id, $img);
$c = new Collection();
while ($sentencia->fetch()) {
$post = new Post(array("autor" => $Autor, "fecha" => $Fecha, "titulo" => $Titulo, "texto" => $Texto, "id" => $id, "img" => $img));
$c->addItem($post);
}
$conn->close();
return $c;
}
}
}
}