param: { module: ad, action: index }
options: { model: Ad, type: object }
+companycategories_index:
+ url: /category/index
+ class: sfDoctrineRoute
+ param: { module: category, action: index }
+ options: { model: CompanyCategory, type: object }
+
# generic rules
# please, remove them by adding more specific rules
default_index:
--- /dev/null
+<?php
+
+/**
+ * category actions.
+ *
+ * @package mobiads
+ * @subpackage category
+ * @author Gustavo Martin Morcuende
+ * @version
+ */
+class categoryActions extends sfActions
+{
+ public function executeIndex(sfWebRequest $request)
+ {
+ $userId = $this->getUser()->getGuardUser()->getId();
+
+ //Get company owned by that user
+ //Just 1 user owns a company. Should this be improved?
+ $companyId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
+
+ //Doctrine Query used to show a pager with the Company Categories.
+ $query=CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuery($companyId);
+
+ $this->pager = new sfDoctrinePager('CompanyCategoryDescription', sfConfig::get('app_max_categories_on_pager'));
+ $this->pager->setQuery($query);
+ $this->pager->setPage($request->getParameter('page', 1));
+ $this->pager->init();
+ }
+
+ public function executeShow(sfWebRequest $request)
+ {
+ $this->company_category = Doctrine_Core::getTable('CompanyCategory')->find(array($request->getParameter('id')));
+ $this->forward404Unless($this->company_category);
+ }
+
+ public function executeNew(sfWebRequest $request)
+ {
+ $this->form = new CompanyCategoryForm();
+ }
+
+ public function executeCreate(sfWebRequest $request)
+ {
+ $this->forward404Unless($request->isMethod(sfRequest::POST));
+
+ $this->form = new CompanyCategoryForm();
+
+ $this->processForm($request, $this->form);
+
+ $this->setTemplate('new');
+ }
+
+ public function executeEdit(sfWebRequest $request)
+ {
+ $this->forward404Unless($company_category = Doctrine_Core::getTable('CompanyCategory')->find(array($request->getParameter('id'))), sprintf('Object company_category does not exist (%s).', $request->getParameter('id')));
+ $this->form = new CompanyCategoryForm($company_category);
+ }
+
+ public function executeUpdate(sfWebRequest $request)
+ {
+ $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
+ $this->forward404Unless($company_category = Doctrine_Core::getTable('CompanyCategory')->find(array($request->getParameter('id'))), sprintf('Object company_category does not exist (%s).', $request->getParameter('id')));
+ $this->form = new CompanyCategoryForm($company_category);
+
+ $this->processForm($request, $this->form);
+
+ $this->setTemplate('edit');
+ }
+
+ public function executeDelete(sfWebRequest $request)
+ {
+ $request->checkCSRFProtection();
+
+ $this->forward404Unless($company_category = Doctrine_Core::getTable('CompanyCategory')->find(array($request->getParameter('id'))), sprintf('Object company_category does not exist (%s).', $request->getParameter('id')));
+ $company_category->delete();
+
+ $this->redirect('category/index');
+ }
+
+ protected function processForm(sfWebRequest $request, sfForm $form)
+ {
+ $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
+ if ($form->isValid())
+ {
+ $company_category = $form->save();
+
+ $this->redirect('category/edit?id='.$company_category->getId());
+ }
+ }
+}
--- /dev/null
+<?php use_stylesheets_for_form($form) ?>
+<?php use_javascripts_for_form($form) ?>
+
+<form action="<?php echo url_for('category/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
+<?php if (!$form->getObject()->isNew()): ?>
+<input type="hidden" name="sf_method" value="put" />
+<?php endif; ?>
+ <table>
+ <tfoot>
+ <tr>
+ <td colspan="2">
+ <?php echo $form->renderHiddenFields(false) ?>
+ <a href="<?php echo url_for('category/index') ?>">Back to list</a>
+ <?php if (!$form->getObject()->isNew()): ?>
+ <?php echo link_to('Delete', 'category/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
+ <?php endif; ?>
+ <input type="submit" value="Save" />
+ </td>
+ </tr>
+ </tfoot>
+ <tbody>
+ <?php echo $form->renderGlobalErrors() ?>
+ <tr>
+ <th><?php echo $form['company_id']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['company_id']->renderError() ?>
+ <?php echo $form['company_id'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['general_categ_id']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['general_categ_id']->renderError() ?>
+ <?php echo $form['general_categ_id'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['created_at']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['created_at']->renderError() ?>
+ <?php echo $form['created_at'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['updated_at']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['updated_at']->renderError() ?>
+ <?php echo $form['updated_at'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['root_id']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['root_id']->renderError() ?>
+ <?php echo $form['root_id'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['lft']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['lft']->renderError() ?>
+ <?php echo $form['lft'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['rgt']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['rgt']->renderError() ?>
+ <?php echo $form['rgt'] ?>
+ </td>
+ </tr>
+ <tr>
+ <th><?php echo $form['level']->renderLabel() ?></th>
+ <td>
+ <?php echo $form['level']->renderError() ?>
+ <?php echo $form['level'] ?>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</form>
--- /dev/null
+<script type="text/javascript">
+ $(document).ready(function() {
+ $("#rounded-corner").treeTable();
+ });
+</script>
+
+<script type="text/javascript">
+jQuery(document).ready(function(){
+ $("#associate").click(function(event){
+ event.preventDefault();
+ event.stopPropagation();
+ window.open('<?php echo url_for('categgeneral/index') ?>', '', 'scrollbars,resizable,status,width=888,height=888');
+ });
+});
+</script>
+
+
+<table id="rounded-corner">
+ <thead>
+ <tr>
+ <th scope="col" class="rounded-company">Name</th>
+ <th scope="col" class="rounded">Current General Category</th>
+ <th scope="col" class="rounded">Associate/Delete</th>
+ <th scope="col" class="rounded">Edit</th>
+ <th scope="col" class="rounded-q4">Delete</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php foreach ($company_categories as $categ_empresa): ?>
+ <tr id="node-<?php echo $categ_empresa->getId()?>" <?php
+ // insert hierarchical info
+ $node = $categ_empresa->getNode();
+ if ($node->isValidNode() && $node->hasParent() && ($node->getParent()->getId() != '1'))
+ {
+ echo 'class="child-of-node-'.$node->getParent()->getId().'"';
+ }
+ ?>>
+ <td>
+ <a>
+ <?php echo $categ_empresa ?>
+ </a>
+ </td >
+ <td>
+ <?php echo $categ_empresa->getGeneralCategory() ?>
+ </td>
+ <td>
+ <?php if ($categ_empresa->getId() != 1): ?>
+ <?php if ($categ_empresa->getGeneralCategId() != null): ?>
+ <a href="<?php echo url_for('categgeneral/deleteassociation?idcompanycateg='.$categ_empresa->getId()) ?>">
+ <img src="/images/link_break.png" alt="" title="" border="0" /></a>
+ <?php else: ?>
+ <a><img src="/images/link.png" alt="" title="" border="0" /></a>
+ <?php endif; ?>
+ <?php else: ?>
+ <a><img src="/images/cross.png" alt="" title="" border="0" /></a>
+ <?php endif; ?>
+ </td>
+ <td>
+ <?php if ($categ_empresa->getId() != 1): ?>
+ <a href="<?php echo url_for('categempresa/edit?id='.$categ_empresa->getId()) ?>">
+ <img src="/images/pencil_add.png" alt="" title="" border="0" /></a>
+ <?php else: ?>
+ <a><img src="/images/cross.png" alt="" title="" border="0" /></a>
+ <?php endif; ?>
+ </td>
+ <td>
+ <?php if ($categ_empresa->getId() != 1): ?>
+ <?php echo link_to('<img src="/images/inadminpanel/images/trash.png" alt="" title="" border="0" />', 'categempresa/delete?id='.$categ_empresa->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
+ <?php else: ?>
+ <a><img src="/images/cross.png" alt="" title="" border="0" /></a>
+ <?php endif; ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+</table>
--- /dev/null
+<h1>Edit Company category</h1>
+
+<?php include_partial('form', array('form' => $form)) ?>
--- /dev/null
+<h2><?php echo __('Company Category Index') ?></h2>
+
+<?php include_partial('category/list', array('company_categories' => $pager->getResults())) ?>
+
+<?php if ($pager->haveToPaginate()): ?>
+ <div class="pagination">
+ <a href="<?php echo url_for('companycategories_index') ?>?page=1"><?php echo __('first page') ?></a>
+
+ <a href="<?php echo url_for('companycategories_index') ?>?page=<?php echo $pager->getPreviousPage() ?>"><?php echo __('<< prev') ?></a>
+
+ <?php foreach ($pager->getLinks() as $page): ?>
+ <?php if ($page == $pager->getPage()): ?>
+ <?php echo $page ?>
+ <?php else: ?>
+ <a href="<?php echo url_for('companycategories_index') ?>?page=<?php echo $page ?>"><?php echo $page ?></a>
+ <?php endif; ?>
+ <?php endforeach; ?>
+
+ <a href="<?php echo url_for('companycategories_index') ?>?page=<?php echo $pager->getNextPage() ?>"><?php echo __('next >>') ?></a>
+
+ <a href="<?php echo url_for('companycategories_index') ?>?page=<?php echo $pager->getLastPage() ?>"><?php echo __('last page') ?></a>
+ </div>
+<?php endif; ?>
+
+<a href="<?php echo url_for('category/new') ?>" class="bt_green"><span class="bt_green_lft"></span><strong>Create new Category</strong><span class="bt_green_r"></span></a>
--- /dev/null
+<h1>New Company category</h1>
+
+<?php include_partial('form', array('form' => $form)) ?>
--- /dev/null
+<table>
+ <tbody>
+ <tr>
+ <th>Id:</th>
+ <td><?php echo $company_category->getId() ?></td>
+ </tr>
+ <tr>
+ <th>Company:</th>
+ <td><?php echo $company_category->getCompanyId() ?></td>
+ </tr>
+ <tr>
+ <th>General categ:</th>
+ <td><?php echo $company_category->getGeneralCategId() ?></td>
+ </tr>
+ <tr>
+ <th>Created at:</th>
+ <td><?php echo $company_category->getCreatedAt() ?></td>
+ </tr>
+ <tr>
+ <th>Updated at:</th>
+ <td><?php echo $company_category->getUpdatedAt() ?></td>
+ </tr>
+ <tr>
+ <th>Root:</th>
+ <td><?php echo $company_category->getRootId() ?></td>
+ </tr>
+ <tr>
+ <th>Lft:</th>
+ <td><?php echo $company_category->getLft() ?></td>
+ </tr>
+ <tr>
+ <th>Rgt:</th>
+ <td><?php echo $company_category->getRgt() ?></td>
+ </tr>
+ <tr>
+ <th>Level:</th>
+ <td><?php echo $company_category->getLevel() ?></td>
+ </tr>
+ </tbody>
+</table>
+
+<hr />
+
+<a href="<?php echo url_for('category/edit?id='.$company_category->getId()) ?>">Edit</a>
+
+<a href="<?php echo url_for('category/index') ?>">List</a>
<a class="menuitem submenuheader" href="">Company Categories</a>
<div class="submenu">
<ul>
- <li><a href="<?php echo url_for('categempresa/index') ?>">Company Categories Index</a></li>
+ <li><a href="<?php echo url_for('category/index') ?>">Company Categories Index</a></li>
</ul>
</div>
<a class="menuitem" href="">User Reference</a>
->innerjoin('addescription.Ad ad')
->orderBy('ad.id');
}
-
}
{
return Doctrine_Core::getTable('CompanyCategoryDescription');
}
-
-
- /**
- * Return
- *
- * @return Doctrine Collection
- */
- public function getCategGeneralFromIdDAOImpl($languageId, $companyCategId)
- {
- $q = Doctrine_Query::create()
- ->from('CompanyCategoryDescription cgd')
- ->where('cgd.company_categ_id = ?', $companyCategId)
- ->andWhere('cgd.language_id = ?', $languageId);
-
- $doccollect=$q->execute();
-
- return $doccollect;
- }
}
{
return Doctrine_Core::getTable('CompanyCategory');
}
-}
\ No newline at end of file
+
+
+ /**
+ * Returns company categories by company id.
+ *
+ * @return related company categories to a company as Doctrine Query
+ */
+ public function getCompanyCategoriesByCompanyIdQuery($companyId)
+ {
+ return $this->createQuery('cg')->where('cg.company_id = ?', $companyId);
+ }
+}
*
* @package mobiads
* @subpackage model
- * @author Your name here
- * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ * @author Gustavo Martin Morcuende
+ * @version
*/
class GeneralCategory extends BaseGeneralCategory
{
+ /**
+ * Returns the string representation of this object.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $languageId = sfContext::getInstance()->getUser()->getGuardUser()->getLanguage()->getId();
+
+ //Check if there is description with the user's language
+ $generalCategoryDescriptions = GeneralCategoryDescriptionTable::getInstance()->findByGeneralCategId($this->getId());
+ foreach ($generalCategoryDescriptions as $generalCategoryDescription)
+ {
+ if ($generalCategoryDescription->getLanguageId() == $languageId)
+ {
+ //We found it!!!
+ return (string) $generalCategoryDescription->getGeneralCategName();
+ }
+ }
+
+ //Otherwise return with the default language
+ $languageCode = sfConfig::get('app_default_language');
+ $languageId = LanguageTable::getInstance()->findByCode($languageCode);
+ foreach ($generalCategoryDescriptions as $generalCategoryDescription)
+ {
+ if ($generalCategoryDescription->getLanguageId() == $languageId)
+ {
+ //We found the default name description!!!
+ return (string) $generalCategoryDescription->getGeneralCategName();
+ }
+ }
+
+ //Finally, if nothing was found, return nice error message.
+ return (string) "General category without default language";
+ }
}
--- /dev/null
+<?php
+
+include(dirname(__FILE__).'/../../bootstrap/functional.php');
+
+$browser = new sfTestFunctional(new sfBrowser());
+
+$browser->
+ get('/category/index')->
+
+ with('request')->begin()->
+ isParameter('module', 'category')->
+ isParameter('action', 'index')->
+ end()->
+
+ with('response')->begin()->
+ isStatusCode(200)->
+ checkElement('body', '!/This is a temporary page/')->
+ end()
+;