/** * Loads a list of entries for the specicifies parameters, returns an array of Search_Backend_Data * * @return array */ public function load() { $entries = array(); $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($data as $entryData) { if ($entryData['maintype'] == 'document') { $element = Document::getById($entryData['id']); } else { if ($entryData['maintype'] == 'asset') { $element = Asset::getById($entryData['id']); } else { if ($entryData['maintype'] == 'object') { $element = Object_Abstract::getById($entryData['id']); } else { Logger::err("unknown maintype "); } } } if ($element) { $entry = new Search_Backend_Data(); $entry->setId(new Search_Backend_Data_Id($element)); $entry->setFullPath($entryData['fullpath']); $entry->setType($entryData['type']); $entry->setSubtype($entryData['subtype']); $entry->setUserOwner($entryData['userowner']); $entry->setUserModification($entryData['usermodification']); $entry->setCreationDate($entryData['creationdate']); $entry->setModificationDate($entryData['modificationdate']); $entry->setPublished($entryData['published'] === 0 ? false : true); $entries[] = $entry; } } $this->model->setEntries($entries); return $entries; }
/** * @static * @param $element * @return string */ public static function getIdPathForElement($element) { $path = ""; if ($element instanceof Document) { $nid = $element->getParentId(); $ne = Document::getById($nid); } else { if ($element instanceof Asset) { $nid = $element->getParentId(); $ne = Asset::getById($nid); } else { if ($element instanceof Object_Abstract) { $nid = $element->getO_parentId(); $ne = Object_Abstract::getById($nid); } } } if ($ne) { $path = self::getIdPathForElement($ne, $path); } if ($element) { $path = $path . "/" . $element->getId(); } return $path; }
public function setAction() { $owner = $_POST['user']; $activities = $_POST['activities']; $object = $_POST['object']; $isValid = Website_P1GlobalFunction::checkValidation($_POST, array('user', 'activities', 'object')); if (count($isValid) > 0) { $arrayReturn = array("status" => "failed", "message" => "field not found", "data" => $isValid); $json_plans = $this->_helper->json($arrayReturn); Website_P1GlobalFunction::sendResponse($json_plans); exit; } $ownerId = Object_Abstract::getById($owner); $activitiesId = Object_Abstract::getById($activities); $key = str_replace(' ', '_', strtolower($ownerId->Name)) . "-" . str_replace(' ', '_', strtolower($activitiesId->Name) . "-" . rand()); $now = date("Y-m-d,H-i"); $getDateTime = new Pimcore_Date($now); if ($ownerId->o_className == "Customer") { $getId = Object_Abstract::getByPath('/log/customers'); //get folder id $setLog = new Object\LogCustomers(); $setLog->setCustomers($ownerId); $setLog->setActivities($activitiesId); $setLog->setObjectContent($object); $setLog->setDatetime($getDateTime); $setLog->setO_parentId($getId->o_id); $setLog->setKey($key); $setLog->setPublished(1); $setLog->save(); $status = "Success"; $message = "Success"; $data = "Add Customer log Success"; } else { if ($ownerId->o_className == "Agen") { $getId = Object_Abstract::getByPath('/log/agen'); //get folder id $setLog = new Object\LogAgents(); $setLog->setAgen($ownerId); $setLog->setActivities($activitiesId); $setLog->setObjectContent($object); $setLog->setDatetime($getDateTime); $setLog->setO_parentId($getId->o_id); $setLog->setKey($key); $setLog->setPublished(1); $setLog->save(); $status = "Success"; $message = "Success"; $data = "Add Agen log Success"; } else { $status = "Field"; $message = "Log id not found"; $data = "Null"; } } $arrayReturn = array("status" => $status, "message" => $message, "data" => $data); $json_log = $this->_helper->json($arrayReturn); Website_P1GlobalFunction::sendResponse($json_log); }
public function productDetailAction() { $key = $this->_getParam('text'); $id = $this->_getParam('id'); $entries = Object_Abstract::getById($id); $data = $entries; $this->view->product = $data; $this->enableLayout(); $this->view->layout()->setLayout("layout_mobile"); }
/** * Preview entry in pimcore admin. * * @throws Zend_Controller_Action_Exception */ public function previewAction() { $id = (int) $this->_getParam('o_id'); $entry = Object_Abstract::getById($id); /* @var $entry Blog_Entry */ if (null == $entry) { throw new Zend_Controller_Action_Exception("No entry with ID '{$id}'", 404); } return $this->_forward('show', null, null, array('key' => $entry->getUrlPath())); }
/** * Loads a list of objects for the specicifies parameters, returns an array of Object_Abstract elements * * @return array */ public function load() { $objects = array(); $objectsData = $this->db->fetchAll("SELECT o_id,o_type FROM objects" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($objectsData as $objectData) { // return all documents as Type Document => fot trees an so on there isn't the whole data required $objects[] = Object_Abstract::getById($objectData["o_id"]); } $this->model->setObjects($objects); return $objects; }
/** * Loads a list of objects for the specicifies parameters, returns an array of Object_Abstract elements * * @return array */ public function load() { $objects = array(); $objectsData = $this->db->fetchAll("SELECT o_id,o_type FROM objects" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($objectsData as $objectData) { if ($object = Object_Abstract::getById($objectData["o_id"])) { $objects[] = $object; } } $this->model->setObjects($objects); return $objects; }
/** * legacy - not required anymore * * * @return void */ protected function cleanUp() { try { $class = Object_Class::getByName("unittest"); if ($class instanceof Object_Class) { $class->delete(); } } catch (Exception $e) { } try { $objectRoot = Object_Abstract::getById(1); if ($objectRoot and $objectRoot->hasChilds()) { $childs = $objectRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $assetRoot = Asset::getById(1); if ($assetRoot and $assetRoot->hasChilds()) { $childs = $assetRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $documentRoot = Asset::getById(1); if ($documentRoot and $documentRoot->hasChilds()) { $childs = $documentRoot->getChilds(); foreach ($childs as $child) { $child->delete(); } } } catch (Exception $e) { } try { $userList = new User_List(); $userList->setCondition("id > 1"); $users = $userList->load(); if (is_array($users) and count($users) > 0) { foreach ($users as $user) { $user->delete(); } } } catch (Exception $e) { } }
/** * Loads a list of objects for the specicifies parameters, returns an array of Object_Abstract elements * * @return array */ public function load() { $objects = array(); try { $objectsData = $this->db->fetchAll("SELECT DISTINCT " . $this->getTableName() . ".o_id AS o_id,o_type FROM `" . $this->getTableName() . "`" . $this->getJoins() . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); } catch (Exception $e) { return $this->exceptionHandler($e); } foreach ($objectsData as $objectData) { if ($object = Object_Abstract::getById($objectData["o_id"])) { $objects[] = Object_Abstract::getById($objectData["o_id"]); } } $this->model->setObjects($objects); return $objects; }
public function exportAction() { try { $objectId = $this->getParam("objectId"); $object = Object_Abstract::getById($objectId); $exportFile = PimPon_Object_Export::doExport($object); ob_end_clean(); header("Content-type: application/json"); header("Content-Disposition: attachment; filename=\"pimponexport.objects." . $object->getKey() . ".json\""); echo file_get_contents($exportFile); exit; } catch (Exception $ex) { Logger::err($ex->getMessage()); $this->_helper->json(array("success" => false, "data" => 'error'), false); } $this->getResponse()->setHeader("Content-Type", "text/html"); }
/** * Get the data for the object from database for the given id * @param integer $id * @return void */ public function getById($id) { $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id); if (!$data["id"]) { throw new Exception("Note item with id " . $id . " not found"); } $this->assignVariablesToModel($data); // get key-value data $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id); $preparedData = array(); foreach ($keyValues as $keyValue) { $data = $keyValue["data"]; $type = $keyValue["type"]; $name = $keyValue["name"]; if ($type == "document") { if ($data) { $data = Document::getById($data); } } else { if ($type == "asset") { if ($data) { $data = Asset::getById($data); } } else { if ($type == "object") { if ($data) { $data = Object_Abstract::getById($data); } } else { if ($type == "date") { if ($data > 0) { $data = new Zend_Date($data); } } else { if ($type == "bool") { $data = (bool) $data; } } } } } $preparedData[$name] = array("data" => $data, "type" => $type); } $this->model->setData($preparedData); }
public function getNavigationPath() { $topLevel = $this; $categories = array(); $root = Object_Abstract::getById(47); //Pimcore_Config::getWebsiteConfig()->shopCategoriesFolder; while ($topLevel && $topLevel->getId() != $root->getId()) { $categories[] = $topLevel; $topLevel = $topLevel->getParent(); } $categories = array_reverse($categories); $path = ''; foreach ($categories as $category) { $path .= Website_Tool_Text::toUrl($category->getText()) . '/'; } $path = substr($path, 0, strlen($path) - 1); return $path; }
/** * @param int $targetId */ public function setTargetId($targetId) { $this->targetId = $targetId; try { if ($this->type == "object") { $this->target = Object_Abstract::getById($targetId); } else { if ($this->type == "asset") { $this->target = Asset::getById($targetId); } else { if ($this->type == "document") { $this->target = Document::getById($targetId); } else { Logger::log(get_class($this) . ": could not set resource - unknown type[" . $this->type . "]"); } } } } catch (Exception $e) { Logger::log(get_class($this) . ": Error setting resource"); } }
public function commentsAction() { if ($this->_getParam('xaction') == "destroy") { $id = $this->_getParam("comments"); $id = str_replace('"', '', $id); RatingsComments_Plugin::deleteComment($id); $results["success"] = true; $results["comments"] = ""; } else { $id = $this->_getParam("objectid"); $type = $this->_getParam("type"); if ($type == "object") { $target = Object_Abstract::getById($id); } else { if ($type == "page" || $type == "snippet") { $target = Document::getById($id); } else { //try asset $target = Asset::getById($id); } } $comments = RatingsComments_Plugin::getComments($target); $results = array(); if (is_array($comments)) { foreach ($comments as $comment) { $shorttext = $comment->getComment(); if (strlen($shorttext) > 50) { $shorttext = substr($shorttext, 0, 50) . "..."; } $results["comments"][] = array("c_id" => $comment->getId(), "c_shorttext" => $shorttext, "c_text" => $comment->getComment(), "c_rating" => $comment->getRating(), "c_user" => $comment->getName(), "c_created" => $comment->getDate()); } } if (!isset($results["comments"])) { $results["comments"] = ""; } } echo Zend_Json::encode($results); $this->removeViewRenderer(); }
private function reassignReferences() { foreach ($this->bindReferencesCollection as $objectPath => $propertiesCollection) { $objectId = $this->objectMap[$objectPath]; $object = Object_Abstract::getById($objectId); foreach ($propertiesCollection as $property => $referencesCollection) { $value = null; foreach ($referencesCollection as $reference) { $referenceInstance = $this->getReferenceInstance($reference); if ($reference->type === PimPon_Object_Encoder_Href::TYPE) { $value = $referenceInstance; } else { if ($reference->type === PimPon_Object_Encoder_Collection::TYPE) { $value[] = $referenceInstance; } } } $object->{'set' . ucfirst($property)}($value); $object->save(); } } }
private function getDataEntry($report) { $importDate = new Zend_Date($report->getImportDate()); $importDate = $importDate->get(Zend_Date::DATETIME_MEDIUM); $product = Object_Abstract::getById($report->getProductId()); if (!empty($product)) { $product = $product->getFullPath(); } $processedDate = ""; if ($report->getProcessedDate()) { $processedDate = new Zend_Date($report->getProcessedDate()); $processedDate = $processedDate->get(Zend_Date::DATETIME_MEDIUM); } $user = User::getById($report->getUserId()); if (!empty($user)) { $user = $user->getUsername(); } else { $user = ""; } $data = array('id' => $report->getId(), 'importDate' => $importDate, 'action' => $report->getAction(), 'type' => $report->getType(), 'productid' => $report->getProductId(), 'productpath' => $product, 'state' => $report->getState(), 'processedDate' => $processedDate, 'user' => $user); return $data; }
public static function setLog() { $ownerId = Object_Abstract::getById($owner); $activitiesId = Object_Abstract::getById($activities); $key = str_replace(' ', '_', strtolower($ownerId->name)) . "-" . str_replace(' ', '_', strtolower($activitiesId->name) . "-" . rand()); $now = date("Y-m-d,H-i"); $getDateTime = new Pimcore_Date($now); if ($ownerId->o_className == "Customer") { $getId = Object_Abstract::getByPath('/log/customers'); //get folder id $setLog = new Object\LogCustomers(); $setLog->setCustomers($ownerId); $setLog->setActivities($activitiesId); $setLog->setObjectContent($object); $setLog->setDatetime($getDateTime); $setLog->setO_parentId($getId->o_id); $setLog->setKey($key); $setLog->setPublished(1); $setLog->save(); } else { if ($ownerId->o_className == "Agen") { $getId = Object_Abstract::getByPath('/log/agen'); //get folder id $setLog = new Object\LogAgents(); $setLog->setAgen($ownerId); $setLog->setActivities($activitiesId); $setLog->setObjectContent($object); $setLog->setDatetime($getDateTime); $setLog->setO_parentId($getId->o_id); $setLog->setKey($key); $setLog->setPublished(1); $setLog->save(); } else { echo "ERROR"; } } }
/** * @static * @param string $type * @param int $id * @return Element_Interface */ public static function getElementById($type, $id) { $element = null; if ($type == "asset") { $element = Asset::getById($id); } else { if ($type == "object") { $element = Object_Abstract::getById($id); } else { if ($type == "document") { $element = Document::getById($id); } } } return $element; }
/** * Receives a Webservice_Data_Document_Element from webservice import and fill the current tag's data * * @abstract * @param Webservice_Data_Document_Element $data * @return void */ public function getFromWebserviceImport($wsElement) { $data = $wsElement->value; if ($data->id !== null) { $this->type = $data->type; $this->subtype = $data->subtype; $this->id = $data->id; if (is_numeric($this->id)) { if ($this->type == "asset") { $this->element = Asset::getById($this->id); if (!$this->element instanceof Asset) { throw new Exception("cannot get values from web service import - referenced asset with id [ " . $this->id . " ] is unknown"); } } else { if ($this->type == "document") { $this->element = Document::getById($this->id); if (!$this->element instanceof Document) { throw new Exception("cannot get values from web service import - referenced document with id [ " . $this->id . " ] is unknown"); } } else { if ($this->type == "object") { $this->element = Object_Abstract::getById($this->id); if (!$this->element instanceof Object_Abstract) { throw new Exception("cannot get values from web service import - referenced object with id [ " . $this->id . " ] is unknown"); } } else { throw new Exception("cannot get values from web service import - type is not valid"); } } } } else { throw new Exception("cannot get values from web service import - id is not valid"); } } }
/** * @param Webservice_Data_Object $wsDocument * @return bool */ protected function updateObject($wsDocument) { $object = Object_Abstract::getById($wsDocument->id); $this->setModificationParams($object, false); if ($object instanceof Object_Concrete and $object->getO_className() == $wsDocument->className) { $wsDocument->reverseMap($object); $object->save(); return true; } else { if ($object instanceof Object_Folder and $object->getType() == strtolower($wsDocument->type)) { $wsDocument->reverseMap($object); $object->save(); return true; } else { if ($object instanceof Object_Abstract) { throw new Exception("Type/Class mismatch for given object with ID [" . $wsDocument->id . "] and existing object with id [" . $object->getId() . "]"); } else { throw new Exception("Object with given ID (" . $wsDocument->id . ") does not exist."); } } } }
/** * @param Object_Concrete $object * @param array $toDelete * @param array $toAdd * @param string $ownerFieldName * @return void */ protected function processRemoteOwnerRelations($object, $toDelete, $toAdd, $ownerFieldName) { $getter = "get" . ucfirst($ownerFieldName); $setter = "set" . ucfirst($ownerFieldName); foreach ($toDelete as $id) { $owner = Object_Abstract::getById($id); //TODO: lock ?! if (method_exists($owner, $getter)) { $currentData = $owner->{$getter}(); if (is_array($currentData)) { for ($i = 0; $i < count($currentData); $i++) { if ($currentData[$i]->getId() == $object->getId()) { unset($currentData[$i]); $owner->{$setter}($currentData); $owner->save(); Logger::debug("Saved object id [ " . $owner->getId() . " ] by remote modification through [" . $object->getId() . "], Action: deleted [ " . $object->getId() . " ] from [ {$ownerFieldName}]"); break; } } } } } foreach ($toAdd as $id) { $owner = Object_Abstract::getById($id); //TODO: lock ?! if (method_exists($owner, $getter)) { $currentData = $owner->{$getter}(); $currentData[] = $object; $owner->{$setter}($currentData); $owner->save(); Logger::debug("Saved object id [ " . $owner->getId() . " ] by remote modification through [" . $object->getId() . "], Action: added [ " . $object->getId() . " ] to [ {$ownerFieldName} ]"); } } }
public static function getTypePath($element) { $path = ""; if ($element) { $parentId = $element->getParentId(); if ($parentId) { $ne = Object_Abstract::getById($element->getParentId()); } } if ($ne) { $path = self::getTypePath($ne, $path); } if ($element) { $path = $path . "/" . $element->getType(); } return $path; }
public function testObjectConcrete() { $client = $this->getSoapClient(); //get an object list with 3 elements $condition = "o_type='object'"; $generalCondition = $this->getListCondition(); if (!empty($generalCondition)) { if (!empty($condition)) { $condition .= " AND " . $generalCondition; } else { $condition = $generalCondition; } } $order = ""; $orderKey = ""; $offset = 0; $limit = 3; $groupBy = ""; $wsDocument = $client->getObjectList($condition, $order, $orderKey, $offset, $limit, $groupBy); $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Object_List_Item); //take first element and fetch object $id = $wsDocument[0]->id; $this->assertTrue(is_numeric($id)); $wsDocument = $client->getObjectConcreteById($id); $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out); $className = "Object_" . ucfirst($wsDocument->className); $this->assertTrue(class_exists($className)); $object = new $className(); $wsDocument->reverseMap($object); //some checks to see if we got a valid object $this->assertTrue($object->getCreationDate() > 0); $this->assertTrue(strlen($object->getPath()) > 0); //copy the object retrieved from ws $new = clone $object; $new->id = null; $new->setKey($object->getKey() . "_phpUnitTestCopy"); $new->setResource(null); //send new object back via ws $apiObject = Webservice_Data_Mapper::map($new, "Webservice_Data_Object_Concrete_In", "in"); $id = $client->createObjectConcrete($apiObject); $this->assertTrue($id > 0); $wsDocument = $client->getObjectConcreteById($id); $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out); $refetchObject = new $className(); $wsDocument->reverseMap($refetchObject); //make sure we deal with 2 different objects $this->assertTrue($id == $refetchObject->getId()); $this->assertTrue($id != $object->getId()); //compare original object, and the one we mangled back and forth through the web service $localObject = Object_Abstract::getById($object->getId()); //remove childs, this can not be set through WS $localObject->setChilds(null); $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true)); //update object $refetchObject->setProperty("updateTest", "text", "a update test"); $refetchObject->setInput("my updated test"); $apiObject = Webservice_Data_Mapper::map($refetchObject, "Webservice_Data_Object_Concrete_In", "in"); // Logger::err(print_r($apiObject,true)); $success = $client->updateObjectConcrete($apiObject); Logger::err($client->getLastRequest()); $this->assertTrue($success); $id = $refetchObject->getId(); Test_Tool::resetRegistry(); $localObject = Object_Abstract::getById($id); $localObject->setChilds(null); $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true)); //delete our test copy $success = $client->deleteObject($refetchObject->getId()); $this->assertTrue($success); }
public function deleteAction() { $id_review = $_POST['id_review']; $customer_id = $_POST['customer_id']; $data; $return_array = array(); $getCustomerObj = Object_Abstract::getById($customer_id); if ($id_review == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Review ID is required'; $return_array['data'] = ''; } else { if ($customer_id == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Product ID is required'; $return_array['data'] = ''; } } $deletereview = array(); $deletereview = Object_Review::getById($id_review); // $deletereview->setIndex(0); $deletereview->setPublished(0); $deletereview->save(); // $delReview = new Object\Review\Listing(); // $delReview->setCondition("oo_id = '$id_review' "); // foreach ($delReview as $value) { $data = array("Id" => $deletereview->o_id); // } $return_array['status'] = 'success'; $return_array['message'] = 'Success delete your product rating'; $return_array['data'] = $data; $json_review = $this->_helper->json($return_array); print_r($json_review); die; Website_P1GlobalFunction::sendResponse($json_review); }
/** * converts data to be imported via webservices * @param mixed $value * @return mixed */ public function getFromWebserviceImport($value, $object = null) { $objects = array(); if (empty($value)) { return null; } else { if (is_array($value)) { foreach ($value as $key => $item) { $object = Object_Abstract::getById($item['id']); if ($object instanceof Object_Abstract) { $objects[] = $object; } else { throw new Exception("cannot get values from web service import - references unknown object with id [ " . $item['id'] . " ]"); } } } else { throw new Exception("cannot get values from web service import - invalid data"); } } return $objects; }
protected function createObjectConcrete($class, $keySuffix, $minAmountLazyRelations) { $document = $this->createRandomDocument("page"); $asset = $this->createRandomAssetImage(); $object = $this->createRandomObject($class); $object->setKey($object->getKey() . $keySuffix); $this->assertTrue($object->getId() > 0); //$objectFetched = Object_Unittest::getById($object->getId()); //$this->assertTrue($objectFetched instanceof Object_Unittest); $fd = $object->getClass()->getFieldDefinitions(); $this->setFieldData($object, $fd, $document, $asset, $minAmountLazyRelations); //properties $object->setProperties($this->getRandomProperties("object")); $object->save(); //new objects must be unpublished $refetch = Object_Abstract::getById($object->getId()); $this->assertFalse($refetch->isPublished()); $this->assertTrue(Test_Tool::objectsAreEqual($object, $refetch, false)); return $object; }
/** * change general user permissions * @depends testModifyUserToAdmin * @var User $user */ public function testPermissionChanges() { $userGroup = User::getByName("unitTestUserGroup"); $username = $userGroup->getUsername(); $userGroup->setAdmin(false); $userGroup->save(); unset($userGroup); $userGroup = User::getByName($username); //test if admin is allowed all $permissionList = new User_Permission_Definition_List(); $permissionList->load(); $permissions = $permissionList->getDefinitions(); $setPermissions = array(); //gradually set all system permissions foreach ($permissions as $permission) { $userGroup->setPermission($permission->getKey()); $setPermissions[] = $permission->getKey(); $userGroup->save(); unset($userGroup); $userGroup = User::getByName($username); foreach ($setPermissions as $p) { $this->assertTrue($userGroup->isAllowed($p)); } } //remove system permissions $userGroup->setAllAclToFalse(); foreach ($setPermissions as $p) { $this->assertFalse($userGroup->isAllowed($p)); } //cannot list documents, assts, objects because no permissions by now $documentRoot = Document::getById(1); $documentRoot->getPermissionsForUser($userGroup); $this->assertFalse($documentRoot->isAllowed("list")); $objectRoot = Object_Abstract::getById(1); $objectRoot->getPermissionsForUser($userGroup); $this->assertFalse($objectRoot->isAllowed("list")); $assetRoot = Asset::getById(1); $assetRoot->getPermissionsForUser($userGroup); $this->assertFalse($assetRoot->isAllowed("list")); $objectFolder = new Object_Folder(); $objectFolder->setParentId(1); $objectFolder->setUserOwner(1); $objectFolder->setUserModification(1); $objectFolder->setCreationDate(time()); $objectFolder->setKey(uniqid() . rand(10, 99)); $objectFolder->save(); $documentFolder = Document_Folder::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99))); $assetFolder = Asset_Folder::create(1, array("filename" => uniqid() . "_data", "type" => "folder", "userOwner" => 1)); $user = User::getByName("unitTestUser"); $user->setAdmin(false); $user->save(); $userGroup->setPermission("objects"); $userGroup->setPermission("documents"); $userGroup->setPermission("assets"); $userGroup->save(); //test permissions with user group and user $this->permissionTest($objectRoot, $objectFolder, $userGroup, $user, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, $userGroup, $user, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, $userGroup, $user, $user, "document"); //test permissions when there is no user group permissions $user = User::create(array("parentId" => 0, "username" => "unitTestUser2", "password" => md5("unitTestUser2"), "hasCredentials" => true, "active" => true)); unset($user); $user = User::getByName("unitTestUser2"); $user->setPermission("objects"); $user->setPermission("documents"); $user->setPermission("assets"); $user->save(); $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser2"); $this->permissionTest($objectRoot, $objectFolder, null, $user, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, null, $user, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, null, $user, $user, "document"); //test permissions when there is only user group permissions $user = User::create(array("parentId" => $userGroup->getId(), "username" => "unitTestUser3", "password" => md5("unitTestUser3"), "hasCredentials" => true, "active" => true)); unset($user); $user = User::getByName("unitTestUser3"); $this->assertTrue($user instanceof User and $user->getUsername() == "unitTestUser3"); $this->permissionTest($objectRoot, $objectFolder, $userGroup, null, $user, "object"); $this->permissionTest($assetRoot, $assetFolder, $userGroup, null, $user, "asset"); $this->permissionTest($documentRoot, $documentFolder, $userGroup, null, $user, "document"); }
/** * @see Object_Class_Data::getDataFromEditmode * @param array $data * @param null|Object_Abstract $object * @return array */ public function getDataFromEditmode($data, $object = null) { //if not set, return null if ($data === null or $data === FALSE) { return null; } $elements = array(); if (is_array($data) && count($data) > 0) { foreach ($data as $element) { if ($element["type"] == "object") { $e = Object_Abstract::getById($element["id"]); } else { if ($element["type"] == "asset") { $e = Asset::getById($element["id"]); } else { if ($element["type"] == "document") { $e = Document::getById($element["id"]); } } } if ($e instanceof Element_Interface) { $elements[] = $e; } } } //must return array if data shall be set return $elements; }
public function editAction() { $valid = true; $id_customer = $_POST['id_customer']; $username = $_POST['username']; $password = $_POST['password']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $delivery_address = $_POST['delivery_address']; $mailing_address = $_POST['mailing_address']; $race = $_POST['race']; $nationality = $_POST['nationality']; $getRaceObj = Object_Abstract::getById($race); $getNationalityObj = Object_Abstract::getById($nationality); $return_array = array(); $data; $cekuser = new Object\Customer\Listing(); $cekuser->setCondition("username = '******'"); if ($cekuser->Count() >= 1) { $return_array['status'] = 'failed'; $return_array['message'] = 'username is already used'; $return_array['data'] = ''; $valid = false; } else { if ($id_customer == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'ID Customer is required'; $return_array['data'] = ''; $valid = false; } else { if ($username == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Username is required'; $return_array['data'] = ''; $valid = false; } else { if ($password == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Password is required'; $return_array['data'] = ''; $valid = false; } else { if ($name == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Name is required'; $return_array['data'] = ''; $valid = false; } else { if ($address == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Address is required'; $return_array['data'] = ''; $valid = false; } else { if ($email == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Email is required'; $return_array['data'] = ''; $valid = false; } else { if ($delivery_address == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Delivery Address is required'; $return_array['data'] = ''; $valid = false; } else { if ($mailing_address == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Mailing Address is required'; $return_array['data'] = ''; $valid = false; } else { if ($race == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Race is required'; $return_array['data'] = ''; $valid = false; } else { if ($nationality == "") { $return_array['status'] = 'failed'; $return_array['message'] = 'Nationality is required'; $return_array['data'] = ''; $valid = false; } } } } } } } } } } } if ($valid) { $customer = Object_Customer::getById($id_customer); $customer->setusername($username); $customer->setpassword($password); $customer->setname($name); $customer->setaddress($address); $customer->setemailAddress($email); $customer->setdeliveryAddress($delivery_address); $customer->setmailingAddress($mailing_address); $customer->setrace($getRaceObj); $customer->setnationality($getNationalityObj); $customer->save(); $return_array['status'] = 'success'; $return_array['message'] = 'Success'; $return_array['data'] = $customer; } $json_customer = $this->_helper->json($return_array); Website_P1GlobalFunction::sendResponse($json_customer); $this->sendResponse($json_customer); }
public function __wakeup() { if (isset($this->_fulldump) && $this->o_properties !== null) { unset($this->_fulldump); $this->renewInheritedProperties(); } if (isset($this->_fulldump)) { // set current key and path this is necessary because the serialized data can have a different path than the original element ( element was renamed or moved ) $originalElement = Object_Abstract::getById($this->getId()); if ($originalElement) { $this->setO_key($originalElement->getO_key()); $this->setO_path($originalElement->getO_path()); } } }