/** * Update the ordered items in post save hook */ protected function postSaveHook(JModelLegacy $model, $validData = array()) { $order_id = $model->getState($model->getName() . '.id'); $data = JFactory::getApplication()->input->post->getArray(array('jform' => array('ordered' => 'array', 'deleted' => 'array'))); // We add order items right on order edit view foreach ($data['jform']['ordered'] as $item) { $item['order_id'] = $order_id; $model = JModelLegacy::getInstance('OrderItem', 'DZProductModel'); $form = $model->getForm($item, false); if (!$form) { continue; } $validItem = $model->validate($form, $item); if ($validItem === false) { continue; } if (!$model->save($validItem)) { continue; } } // Make sure the submitted deleted ids are all integer JArrayHelper::toInteger($data['jform']['deleted']); // Remove items $model = JModelLegacy::getInstance('OrderItem', 'DZProductModel'); $model->delete($data['jform']['deleted']); }
/** * Tests the getName method. * * @expectedException Exception * @expectedExceptionCode 500 * * @since 12.3 * * @return void */ public function testGetName() { // Test default fixture $this->assertEquals('lead', $this->fixture->getName()); $this->assertEquals('com_test', TestReflection::getValue($this->fixture, 'option')); // Test creating fixture with model in class name $this->fixture = JModelLegacy::getInstance('Room', 'RemodelModel'); $this->assertEquals('room', $this->fixture->getName()); $this->assertEquals('com_remodel', TestReflection::getValue($this->fixture, 'option')); // Ensure that $name can be set properly, and doesn't change $option TestReflection::setValue($this->fixture, 'name', 'foo'); $this->assertEquals('foo', $this->fixture->getName()); $this->assertEquals('com_remodel', TestReflection::getValue($this->fixture, 'option')); // Test creating a non-existant class. $this->assertFalse(JModelLegacy::getInstance('Does', 'NotExist')); // Test creating class that does exist, but does not contain 'Model' (uppercase) $this->fixture = JModelLegacy::getInstance('NomodelInName'); $this->fixture->getName(); }
/** * Method to add a model to the view. We support a multiple model single * view system by which models are referenced by classname. A caveat to the * classname referencing is that any classname prepended by JModel will be * referenced by the name without JModel, eg. JModelCategory is just * Category. * * @param JModelLegacy $model The model to add to the view. * @param boolean $default Is this the default model? * * @return object The added model. * * @since 12.2 */ public function setModel($model, $default = false) { $name = strtolower($model->getName()); $this->_models[$name] = $model; if ($default) { $this->_defaultModel = $name; } return $model; }
/** * Method to add a model to the create object. * * @param JModelLegacy $model The model to add. * * @return object The added model. */ protected function setModel($model) { $name = strtolower($model->getName()); $this->_models[$name] = $model; return $this->_models[$name]; }
/** * Test getting the name of a class that does exist, but does not contain 'Model' (upper- or lowercase) * * @expectedException Exception * @expectedExceptionCode 500 * * @since 12.3 * * @return void * * @testdox getName() throws exception if class has no 'model' in classname */ public function testNameOfExistingClassThatDoesNotContainModel() { $this->fixture = new NokeywordInName(); $this->fixture->getName(); }