public function save($object) { $model = ARResource::model(); $transaction = $model->getDbConnection()->beginTransaction(); try { if (isset($object->id) && $object->id !== 0) { $resource = $model->findByPk($object->id); } if (!isset($resource) || is_null($resource)) { $resource = $model->find('name = :name', array('name' => $object->name)); if (isset($resource) && !is_null($resource)) { throw new Exception('Resource with name already exists'); } $resource = new ARResource(); $resource->create_date = time(); } $class = ResourceType::model()->find('name=:name', array('name' => $object->type)); if (!$class) { throw new Exception('Invalid CLASS'); } $resource->type_id = $class->id; $resource->name = $object->name; $resource->update_date = time(); if (!$resource->save()) { throw new Exception('Could not save RESOURCE_TYPE'); } $this->synchronizeProperties($resource, $object->property); $this->synchronizeOjbects($resource, $object->objects); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } return true; }
<?php $resourceID = $_GET['resourceID']; $resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID))); if (!is_null_date($resource->archiveDate)) { $archiveChecked = 'checked'; } else { $archiveChecked = ''; } //get all resource formats for output in drop down $resourceFormatArray = array(); $resourceFormatObj = new ResourceFormat(); $resourceFormatArray = $resourceFormatObj->sortedArray(); //get all resource types for output in drop down $resourceTypeArray = array(); $resourceTypeObj = new ResourceType(); $resourceTypeArray = $resourceTypeObj->allAsArray(); //get parents resources $sanitizedInstance = array(); $instance = new Resource(); $parentResourceArray = array(); foreach ($resource->getParentResources() as $instance) { foreach (array_keys($instance->attributeNames) as $attributeName) { $sanitizedInstance[$attributeName] = $instance->{$attributeName}; } $sanitizedInstance[$instance->primaryKeyName] = $instance->primaryKey; array_push($parentResourceArray, $sanitizedInstance); } //get all alias types for output in drop down $aliasTypeArray = array(); $aliasTypeObj = new AliasType();
/** * @param ResourceType $resourceType * @param Attribute[] $attributes */ public function BindResourceType(ResourceType $resourceType, $attributes) { $this->Set('resourceType', $resourceType->Name()); $this->Set('ResourceTypeAttributes', $attributes); }
<tr> <td class='searchRow'><label for='searchResourceTypeID'><b>Resource Type</b></label> <br /> <select name='search[resourceTypeID]' id='searchResourceTypeID' style='width:150px'> <option value=''>All</option> <?php if ($search['resourceTypeID'] == "none") { echo "<option value='none' selected>(none)</option>"; } else { echo "<option value='none'>(none)</option>"; } $display = array(); $resourceType = new ResourceType(); foreach ($resourceType->allAsArray() as $display) { if ($search['resourceTypeID'] == $display['resourceTypeID']) { echo "<option value='" . $display['resourceTypeID'] . "' selected>" . $display['shortName'] . "</option>"; } else { echo "<option value='" . $display['resourceTypeID'] . "'>" . $display['shortName'] . "</option>"; } } ?> </select> </td> </tr> <tr> <td class='searchRow'><label for='searchResourceID'><b>Record ID</b></label>
/** * @param ResourceType $resourceType * @return ResourceTypeJson */ public static function FromResourceType($resourceType) { return new ResourceTypeJson($resourceType->Id(), $resourceType->Name()); }
<tr><td><label for='shortName'><b>Variable Name</b></label</td><td><?php if (isset($calendarSettings)) { echo $calendarSettings->shortName; } ?> </td></tr> <tr> <td><label for='value'><b>Value</b></label</td> <td> <select multiple name='value' id='value' style='width:155px'> <?php $display = array(); $resourceType = new ResourceType(); foreach ($resourceType->getAllResourceType() as $display) { if (in_array($display['resourceTypeID'], explode(",", $calendarSettings->value))) { echo "<option value='" . $display['resourceTypeID'] . "' selected>" . $display['shortName'] . "</option>"; } else { echo "<option value='" . $display['resourceTypeID'] . "'>" . $display['shortName'] . "</option>"; } } ?> </select> </td> </tr> <?php } elseif (strtolower($calendarSettings->shortName) == strtolower('Authorized Site(s)')) {
public function UpdateResourceType(ResourceType $type) { $db = ServiceLocator::GetDatabase(); $db->Execute(new UpdateResourceTypeCommand($type->Id(), $type->Name(), $type->Description())); foreach ($type->GetRemovedAttributes() as $removed) { $db->Execute(new RemoveAttributeValueCommand($removed->AttributeId, $type->Id())); } foreach ($type->GetAddedAttributes() as $added) { $db->Execute(new AddAttributeValueCommand($added->AttributeId, $added->Value, $type->Id(), CustomAttributeCategory::RESOURCE_TYPE)); } }
/** * Gets the ResourceAssociationSet instance for the given source * association end. * * @param ResourceSet $resourceSet Resource set of the source * association end * @param ResourceType $resourceType Resource type of the source * association end * @param ResourceProperty $resourceProperty Resource property of the source * association end * * @return ResourceAssociationSet */ public function getResourceAssociationSet(ResourceSet $sourceResourceSet, ResourceType $sourceResourceType, ResourceProperty $targetResourceProperty) { //e.g. //ResourceSet => Representing 'Customers' entity set //ResourceType => Representing'Customer' entity type //ResourceProperty => Representing 'Orders' property //We have created ResourceAssoicationSet while adding //ResourceSetReference or ResourceReference //and kept in $this->associationSets //$metadata->addResourceSetReferenceProperty( // $customersEntityType, // 'Orders', // $ordersResourceSet // ); $targetResourceSet = $targetResourceProperty->getResourceType()->getCustomState(); if (is_null($targetResourceSet)) { throw new InvalidOperationException('Failed to retrieve the custom state from ' . $resourceProperty->getResourceType()->getName()); } //Customer_Orders_Orders, Order_Customer_Customers $key = $sourceResourceType->getName() . '_' . $targetResourceProperty->getName() . '_' . $targetResourceSet->getName(); if (array_key_exists($key, $this->associationSets)) { return $this->associationSets[$key]; } return null; }
public function testFromStringWithResource() { $this->assertSame(ResourceType::getInstance(), MixedType::fromString("resource")); }
public function remove($object) { return ResourceType::model()->deleteByPk($object->id); }
public static function GetLatestItems($number) { //$sql = 'UPDATE products SET pack_size = '.$packsize.', featured = '.$featured.', availability = '.$availability.', catalog_bal = '.$openstock.', stock_bal = '.$openstock.', optimum_bal = '.$optstock.', low_bal = '.$lowstock.' WHERE id = '.$item->itemId; $stock_accounts = array(); $sql = 'SELECT * FROM stock_accounts ORDER BY tstamp DESC LIMIT 0,' . intval($number); $stocks = DatabaseHandler::GetAll($sql); foreach ($stocks as $stock) { $sql = 'SELECT * FROM products WHERE resource_id = ' . $stock['resource_id']; $sqlf = 'SELECT * FROM features WHERE resource_id = ' . $stock['resource_id']; $product = DatabaseHandler::GetRow($sql); $features = DatabaseHandler::GetAll($sqlf); //$sqlf = 'SELECT * FROM item_features WHERE item_id = '.$product['id']; $typedata = ResourceType::GetTypeData($product['type_id']); $unit = Unit::GetUnitById($typedata['unit_id']); $item = new Product($product['resource_id'], $product['type_id'], $typedata['type'], $product['name'], $product['reference'], $unit, $product['description'], $features, $product['manufacturer'], $product['retail_price'], $product['wholesale_price'], $product['tax_code'], $product['img_url'], $product['plength'], $product['pwidth'], $product['pheight'], $product['pweight'], $product['pshape']); $stockAccount = new StockAccount($stock['account_id'], $item, $stock['pack_size'], $stock['featured'], $stock['availability'], $stock['catalog_bal'], $stock['stock_bal'], $stock['optimum_bal'], $stock['low_bal'], $stock['cost_price'], $stock['retail_price'], $stock['wholesale_price'], $stock['vat_code'], $stock['date_added'], $stock['tstamp']); $stock_accounts[] = $stockAccount; } //do something as an inventory objects return $stock_accounts; }
function __construct($typeId, $typeName, Unit $unit) { parent::__construct($typeId, $typeName, $unit); }
public function testUpdatesResourceType() { $unchanged = new AttributeValue(1, 'value'); $toChange = new AttributeValue(2, 'value'); $toAdd = new AttributeValue(3, 'value'); $id = 11; $type = new ResourceType($id, 'name', 'desc'); $type->WithAttribute($unchanged); $type->WithAttribute(new AttributeValue(100, 'should be removed')); $type->WithAttribute(new AttributeValue(2, 'new value')); $attributes = array($unchanged, $toChange, $toAdd); $type->ChangeAttributes($attributes); $this->repository->UpdateResourceType($type); $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $removeOldCommand = new RemoveAttributeValueCommand(100, $id); $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $id); $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $id, CustomAttributeCategory::RESOURCE_TYPE); $expectedCommand = new UpdateResourceTypeCommand($type->Id(), $type->Name(), $type->Description()); $this->assertEquals($expectedCommand, $this->db->_Commands[0]); $this->assertEquals($removeOldCommand, $this->db->_Commands[1]); $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted"); $this->assertEquals($addUpdated, $this->db->_Commands[3]); $this->assertEquals($addNewCommand, $this->db->_Commands[4]); }
public function testChangesAttributes() { $id = 1232; $name = 'name'; $description = 'description'; $resourceType = new ResourceType($id, $name, $description); $resourceType->ChangeAttributes(array(new AttributeValue(1, 'val'))); $attributeVals = array(new AttributeValue(1, 'val')); $this->page->expects($this->once())->method('GetId')->will($this->returnValue($id)); $this->page->expects($this->once())->method('GetAttributes')->will($this->returnValue($attributeVals)); $this->resourceRepository->expects($this->once())->method('LoadResourceType')->with($this->equalTo($id))->will($this->returnValue($resourceType)); $this->resourceRepository->expects($this->once())->method('UpdateResourceType')->with($this->equalTo($resourceType)); $this->presenter->ChangeAttributes(); }