public function preDispatch() { $this->_post = $this->getRequest()->getPost(); $this->_uuid = $this->_getParam('uuid'); if ($this->_uuid) { $this->_obj = Core\Registry::get($this->_uuid); $this->_defineRedirect(array('ok', 'nok', 'err')); if ($this->_obj instanceof ObjectModel\ObjectUri) { $this->_obj = ObjectModel::factory($this->_obj); } if (!$this->_obj) { $this->_context['message'] = "Unable to restore object"; $this->_status = 'ERR'; $this->postDispatch(); } // @todo post actions coming from js, unsecure, we should keep a reference of the handling form object if ($this->_getParam('post_ok')) { $this->_actions['ok'] = $this->_getParam('post_ok'); } } else { $this->_context['message'] = 'Missing remote object id'; $this->_status = 'NOK'; $this->postDispatch(); } }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $path = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); array_pop($path); array_pop($path); $path = implode(DIRECTORY_SEPARATOR, $path) . DIRECTORY_SEPARATOR; set_include_path(get_include_path() . PATH_SEPARATOR . $path . 'library' . PATH_SEPARATOR . $path . 'tests/fixtures/model'); require_once 't41/Core.php'; t41\Core::enableAutoloader(array('t41', 'Tests')); t41\Config::addPath($path . 'tests/fixtures/configs/', t41\Config::REALM_CONFIGS); t41\ObjectModel::loadConfig(); $this->Person = \t41\ObjectModel::factory('Tests\\Person'); }
/** * Execute the action and returns a result * * @return array */ public function execute() { $res = false; switch ($this->_callback) { case 'create': $this->_obj = ObjectModel::factory($this->getClass()); foreach ($this->getContext() as $key => $value) { if ($this->_obj->setProperty($key, $value) === false) { var_dump($key); die; continue; } } $res = $this->_obj->save(); break; } return $res; }
/** * Return the current value in the $param form * @see t41\ObjectModel\Property.AbstractProperty::getValue() * @param string $param define which format to use */ public function getValue($param = null) { if (is_null($this->_value)) { return null; } /* if param is null, return the value in its current format */ if (is_null($param)) { return $this->_value; } switch ($param) { case ObjectModel::MODEL: if ($this->_value instanceof ObjectModel\DataObject) { $this->_value = ObjectModel::factory($this->_value); return $this->_value; } else { if ($this->_value instanceof ObjectUri) { /* object uri */ $this->_value = ObjectModel::factory($this->_value); } } return $this->_value; break; case ObjectModel::DATA: if ($this->_value instanceof ObjectUri) { $this->_value = ObjectModel::factory($this->_value); return $this->_value->getDataObject(); } else { if ($this->_value instanceof DataObject) { return $this->_value; } else { return $this->_value->getDataObject(); } } break; case ObjectModel::URI: default: if ($this->_value instanceof ObjectUri) { return $this->_value; } else { if ($this->_value instanceof DataObject) { return $this->_value->getUri(); } else { return $this->_value->getDataObject()->getUri(); } } break; } }
/** * Returns a new instance of a member * @return t41\ObjectModel\BaseObject */ public function newMember() { return ObjectModel::factory($this->_do->getClass()); }
public function getInstanceOf() { return ObjectModel::factory($this->getParameter('instanceof')); }
protected function _contentRendering() { $i = 0; $p = ''; $aliases = $this->_obj->getAliases(); // print out rows foreach ($this->_obj->getCollection()->getMembers(ObjectModel::DATA) as $this->_key => $this->_do) { $css = $i % 2 == 0 ? 'odd' : 'even'; // \Zend_Debug::dump($this->_do->getProperty('marche')->getValue(ObjectModel::MODEL)); die; // @todo handle objects coming from different backends $p .= sprintf('<tr data-member="%s" data-alias="%s" class="%s">', $this->_key, $this->_do->getUri() ? $aliases[$this->_do->getUri()->getIdentifier()] : null, $css); $i++; if ($this->_obj->getParameter('selectable') === true) { // make list items selectable $p .= sprintf('<td><input type="checkbox" name="t41_selection[]" value="%s"/></td>', $this->_do->getUri()->getIdentifier()); } $altDec = (array) $this->_obj->getParameter('decorators'); foreach ($this->_obj->getColumns() as $column) { if ($column instanceof Element\IdentifierElement) { $p .= sprintf('<td>%s</td>', $this->_do->getUri()->getIdentifier()); continue; } if ($column instanceof Element\MetaElement) { $attrib = $column->getParameter('type') == 'currency' ? ' class="cellcurrency"' : null; $p .= "<td{$attrib}>" . $column->getDisplayValue($this->_do) . '</td>'; continue; } $property = $this->_do->getProperty($column->getParameter('property')); if (!$property) { $p .= '<td>??</td>'; continue; } $column->setValue($property->getValue()); /* if a decorator has been declared for property/element, use it */ if (isset($altDec[$column->getId()])) { $column->setDecorator($altDec[$column->getId()]); $deco = Decorator::factory($column); $p .= sprintf('<td>%s</td>', $deco->render()); continue; } $attrib = sprintf(' class="tb-%s', $column->getId()); $attrib .= $property instanceof Property\CurrencyProperty ? ' cellcurrency"' : '"'; if ($column->getParameter('recursion')) { $parts = $column->getParameter('recursion'); foreach ($parts as $rkey => $recursion) { if ($property instanceof ArrayProperty) { // property won't be a property here ! $property = $property->getValue(); $property = $property[$recursion]; if ($property instanceof BaseObject && isset($parts[$rkey + 1])) { $property = $property->{$parts[$rkey + 1]}; } break; } // property is an object property if ($property instanceof AbstractProperty && $property->getValue()) { $property = $property->getValue(ObjectModel::DATA)->getProperty($recursion); } if ($property instanceof ObjectModel || $property instanceof DataObject) { $property = $property->getProperty($recursion); } else { if ($property instanceof ObjectUri) { $property = ObjectModel::factory($property)->getProperty($recursion); } } } } if ($property instanceof Property\MediaProperty) { $column->setValue($property->getDisplayValue()); $deco = Decorator::factory($column); $value = $deco->render(); } else { $value = $property instanceof Property\AbstractProperty ? $property->getDisplayValue() : $property; } //$p .= "<td$attrib>" . $this->_escape($value) . '</td>'; $p .= "<td{$attrib}>" . $value . '</td>'; } $p .= '<td class="tb-actions">'; foreach ($this->_obj->getEvents('row') as $button) { $button->setParameter('uri', $this->_do->getUri()); $p .= $this->_renderButton($button, $aliases[$this->_do->getUri()->getIdentifier()]); } $p .= '</td></tr>' . "\n"; } return $p; }