本文整理汇总了PHP中Model_Ad::updateAd方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Ad::updateAd方法的具体用法?PHP Model_Ad::updateAd怎么用?PHP Model_Ad::updateAd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Ad
的用法示例。
在下文中一共展示了Model_Ad::updateAd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
public function editAction()
{
//check if user logged in
$auth = Zend_Auth::getInstance();
$user = new Model_User();
$ad = new Model_Ad();
$id = (int) $this->getRequest()->getParam('id');
$ad_user_owner = $ad->getAd($id);
if ($auth->hasIdentity()) {
$this->view->userRole = $this->_helper->checkUserRole->check();
//if user owner allow edit and show delete ad link , if not redir not allowed
if ($this->view->userRole == 1) {
//bazinga!!
} elseif ($user->fetchUser($auth->getIdentity()->id)->id != $ad_user_owner['user_owner']) {
$this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page'));
$this->_redirect('/' . $this->lang . '/woeid/' . $this->location . '/give');
}
} else {
$this->_helper->_flashMessenger->addMessage($this->view->translate('You are not allowed to view this page'));
$this->_redirect('/' . $this->lang . '/woeid/' . $this->location . '/give');
return;
}
$this->view->deletead = '<img src="/images/delete_ad.png" />
<a href="/' . $this->view->lang . '/ad/delete/id/' . $this->_getParam('id') . ' ">' . $this->view->translate('delete this ad') . '</a>';
$request = $this->getRequest();
require_once APPLICATION_PATH . '/forms/AdEdit.php';
$form = new Form_AdEdit();
$form->addElement('select', 'status', array('order' => '1', 'label' => 'Status:', 'required' => true, 'multioptions' => array('available' => 'available', 'booked' => 'booked', 'delivered' => 'delivered')));
$this->view->page_title .= $this->view->translate('Edit your ad');
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$formulario = $form->getValues();
//anti HOYGAN to title
//dont use strtolower because dont convert utf8 properly . ej: á é ó ...
$formulario['title'] = ucfirst(mb_convert_case($formulario['title'], MB_CASE_LOWER, "UTF-8"));
//anti hoygan to body
$split = explode(". ", $formulario['body']);
foreach ($split as $sentence) {
$sentencegood = ucfirst(mb_convert_case($sentence, MB_CASE_LOWER, "UTF-8"));
$formulario['body'] = str_replace($sentence, $sentencegood, $formulario['body']);
}
//var_dump($form);
//set filter againts xss and nasty things
$f = new Zend_Filter();
$f->addFilter(new Zend_Filter_StripTags());
$data['title'] = $f->filter($formulario['title']);
$data['body'] = $f->filter($formulario['body']);
$data['type'] = $f->filter($formulario['type']);
//create thumbnail if image exists
if ($formulario['photo']) {
$photobrut = $formulario['photo'];
$data['photo'] = $this->_createThumbnail($photobrut, '100', '90');
}
$data['status'] = $formulario['status'];
$data['comments_enabled'] = $formulario['comments_enabled'];
$model = new Model_Ad();
$model->updateAd($data, (int) $id);
//delete memcached ad if exists
//check if the ad exists in memcached
$oBackend = new Zend_Cache_Backend_Memcached(array('servers' => array(array('host' => '127.0.0.1', 'port' => '11211')), 'compression' => true));
// configure caching frontend strategy
$oFrontend = new Zend_Cache_Core(array('lifetime' => 3600 * 24 * 7, 'caching' => true, 'cache_id_prefix' => 'singleAd', 'logging' => false, 'write_control' => true, 'automatic_serialization' => true, 'ignore_user_abort' => true));
// build a caching object
$cacheAd = Zend_Cache::factory($oFrontend, $oBackend);
$cacheAd->remove((int) $id);
$this->_helper->_flashMessenger->addMessage($this->view->translate('Ad edited succesfully!'));
$this->_redirect('/' . $this->lang . '/ad/' . $id);
} else {
$id = $this->_getParam('id');
$ad = new Model_Ad();
$advalues = $ad->getAd($id);
// if photo not empty then show and let change it
$current_photo = $advalues['photo'];
if ($current_photo) {
$this->view->current_photo = ' <img src="/images/uploads/ads/100/' . $current_photo . '" />';
}
$form->populate($formData);
}
} else {
$id = $this->_getParam('id');
if ($id > 0) {
$ad = new Model_Ad();
$advalues = $ad->getAd($id);
// if photo not empty then show and let change it
$current_photo = $advalues['photo'];
if ($current_photo) {
$this->view->current_photo = ' <img src="/images/uploads/ads/100/' . $current_photo . '" />';
}
$form->populate($ad->getAd($id));
}
}
}