public function indexAction() { $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('seo_admin_main', array(), 'seo_admin_main_manage'); $items = array(); foreach (Engine_Api::_()->getItemTypes() as $itemType) { $class = Engine_Api::_()->getItemClass($itemType); if (@class_exists($class)) { $reflector = new ReflectionMethod($class, 'getHref'); if ($reflector->getDeclaringClass()->getName() == $class) { $items[$itemType] = ucfirst(Engine_Api::typeToShort($itemType, Engine_Api::_()->getItemModule($itemType))) . ' (' . $itemType . ')'; } } } $this->view->formFilter = $formFilter = new Seo_Form_Admin_Manage_Filter(); // Populate types foreach ($items as $k => $v) { $formFilter->type->addMultiOption($k, $v); } // Process form $values = array(); if ($formFilter->isValid($this->_getAllParams())) { $values = $formFilter->getValues(); } foreach ($values as $key => $value) { if (null === $value) { unset($values[$key]); } } $this->view->assign($values); if (isset($values['type'])) { try { $table = Engine_Api::_()->getItemTable($values['type']); $select = $table->select(); } catch (Engine_Api_Exception $e) { } } $this->view->paginator = $paginator = Zend_Paginator::factory(isset($select) ? $select : array()); $paginator->setItemCountPerPage(25); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); if (!isset($select)) { return; } // Set up select info $primary = array_shift($table->info('primary')); $values = array_merge(array('order' => $primary, 'order_direction' => 'DESC'), $values); $select->order((!empty($values['order']) ? $values['order'] == 'id' ? $primary : (in_array($values['order'], $table->info('cols')) ? $values['order'] : $primary) : $primary) . ' ' . (!empty($values['order_direction']) ? $values['order_direction'] : 'DESC')); if (in_array('title', $table->info('cols')) && !empty($values['title'])) { $select->where('title LIKE ?', '%' . $values['title'] . '%'); } // Filter out junk $valuesCopy = array_filter($values); // Reset enabled bit if (isset($values['enabled']) && $values['enabled'] == 0) { $valuesCopy['enabled'] = 0; } }
public function getOwner($recurseType = null) { if (empty($recurseType)) { $recurseType = null; } // Just return self for users if ($this->getType() === 'user') { if (null === $recurseType || $recurseType === 'user') { return $this; } else { throw new Core_Model_Item_Exception('Cannot request owner of user of type other than user'); } } // Get owner type $type = null; if (!empty($this->_owner_type)) { // Local definition $type = $this->_owner_type; } else { if (!empty($this->owner_type)) { // Db definition $type = $this->owner_type; } else { $type = 'user'; } } if (null === $type) { throw new Core_Model_Item_Exception('No owner type defined and not overriden'); } if (!Engine_Api::_()->hasItemType($type)) { throw new Core_Model_Item_Exception('Unknown owner type: ' . $type); } // Get parent id $id = null; if (!empty($this->owner_id)) { $id = $this->owner_id; } else { $short_type = Engine_Api::typeToShort($type, Engine_Api::_()->getItemModule($type)); $prop = $short_type . '_id'; if (!empty($this->{$prop})) { $id = $this->{$prop}; } } if (null === $id) { throw new Core_Model_Item_Exception('No owner id defined'); } if (!($owner = Engine_Api::_()->getItem($type, $id)) instanceof Core_Model_Item_Abstract || !$owner->getIdentity()) { //throw new Core_Model_Item_Exception('Owner missing'); //instead of throwing exception return and empty user object, the user model should handle it gracefully return Engine_Api::_()->getItem($type, $id); } if (null !== $recurseType && $owner->getType() != $recurseType) { $newOwner = $owner->getOwner($recurseType); if ($newOwner->isSelf($owner)) { throw new Core_Model_Item_Exception('Infinite recursion detected in getOwner()'); } return $newOwner; } return $owner; }