本文整理汇总了PHP中Document::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::getById方法的具体用法?PHP Document::getById怎么用?PHP Document::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document::getById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($type, $id, $contentKey = null, $user)
{
if (isset($_FILES['avatar'])) {
$type = trim($type);
$folder = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR);
$pathImage = $this->processImage($_FILES['avatar'], $id, $type);
if ($pathImage) {
$params = array();
$params["id"] = $id;
$params["type"] = $type;
$params['folder'] = $folder;
$params['moduleId'] = Yii::app()->controller->module->id;
$params['name'] = $pathImage["name"];
$params['doctype'] = "image";
$params['size'] = $pathImage["size"][0] * $pathImage["size"][1] / 1000;
$params['author'] = $user;
$params['category'] = array();
$params['contentKey'] = $contentKey;
$result = Document::save($params);
//Profile to check
$urlBdd = str_replace(DIRECTORY_SEPARATOR, "/", DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR . Yii::app()->controller->module->id . $folder . $pathImage["name"]);
Document::setImagePath($id, $type, $urlBdd, $contentKey);
$newImage = Document::getById($result["id"]);
}
$res = array('result' => true, 'msg' => 'The picture was uploaded', 'imagePath' => $urlBdd, "id" => $result["id"], "image" => $newImage);
Rest::json($res);
Yii::app()->end();
}
}
示例2: getSourceDocument
/**
* @return Document_PageSnippet
*/
public function getSourceDocument()
{
if ($this->getSourceId()) {
return Document::getById($this->getSourceId());
}
return null;
}
示例3: load
/**
* 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;
}
示例4: getIdPathForElement
/**
* @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;
}
示例5: load
/**
* Loads a list of objects (all are an instance of Document) for the given parameters an return them
*
* @return array
*/
public function load()
{
$documents = array();
$documentsData = $this->db->fetchAll("SELECT id,type FROM documents" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
foreach ($documentsData as $documentData) {
if ($documentData["type"]) {
$documents[] = Document::getById($documentData["id"]);
}
}
$this->model->setDocuments($documents);
return $documents;
}
示例6: getNavigation
public function getNavigation($activeDocument, $navigationRootDocument = null, $htmlMenuIdPrefix = null)
{
$this->_activeDocument = $activeDocument;
$this->_htmlMenuIdPrefix = $htmlMenuIdPrefix;
$this->_navigationContainer = new Zend_Navigation();
if (!$navigationRootDocument) {
$navigationRootDocument = Document::getById(1);
}
if ($navigationRootDocument->hasChilds()) {
$this->buildNextLevel($navigationRootDocument, null, true);
}
return $this->_navigationContainer;
}
示例7: load
public function load($override = false)
{
if ($this->search_result_items !== null && !$override) {
return $this->search_result_items;
}
$search_result = $this->getDocumentIds();
$sliced = array_slice($search_result, $this->offset, $this->limit, true);
$documents = array();
foreach ($sliced as $id) {
$document = Document::getById($id);
$documents[] = $document;
}
$this->search_result_items = $documents;
return $this->search_result_items;
}
示例8: exportAction
public function exportAction()
{
try {
$documentId = $this->getParam("documentId");
$document = Document::getById($documentId);
$exportFile = PimPon_Document_Export::doExport($document);
ob_end_clean();
header("Content-type: application/json");
header("Content-Disposition: attachment; filename=\"pimponexport.documents." . $document->getKey() . ".json\"");
echo file_get_contents($exportFile);
exit;
} catch (Exception $ex) {
Logger::err($ex->getMessage());
$this->_helper->json(array("success" => false, "data" => 'error'), false);
}
}
示例9: getById
/**
* 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);
}
示例10: run
public function run($dir, $type)
{
$filepath = Yii::app()->params['uploadDir'] . $dir . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $_POST['parentId'] . DIRECTORY_SEPARATOR . $_POST['name'];
if (isset(Yii::app()->session["userId"]) && file_exists($filepath)) {
if (unlink($filepath)) {
Document::removeDocumentById($_POST['docId']);
echo json_encode(array('result' => true, "msg" => Yii::t("document", "Document deleted")));
} else {
echo json_encode(array('result' => false, 'error' => Yii::t("common", "Something went wrong!"), "filepath" => $filepath));
}
} else {
$doc = Document::getById($_POST['docId']);
if ($doc) {
Document::removeDocumentById($_POST['docId']);
}
echo json_encode(array('result' => false, 'error' => Yii::t("common", "Something went wrong!"), "filepath" => $filepath));
}
}
示例11: _handleError
protected function _handleError(Zend_Controller_Request_Abstract $request)
{
// remove zend error handler
$front = Zend_Controller_Front::getInstance();
$front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler");
$response = $this->getResponse();
if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
// get errorpage
try {
// enable error handler
$front->setParam('noErrorHandler', false);
$siteKey = Pimcore_Tool_Frontend::getSiteKey();
$errorPath = Pimcore_Config::getSystemConfig()->documents->error_pages->{$siteKey};
if (empty($errorPath)) {
$errorPath = "/";
}
$document = Document::getByPath($errorPath);
if (!$document instanceof Document_Page) {
// default is home
$document = Document::getById(1);
}
if ($document instanceof Document_Page) {
$params = Pimcore_Tool::getRoutingDefaults();
if ($module = $document->getModule()) {
$params["module"] = $module;
}
if ($controller = $document->getController()) {
$params["controller"] = $controller;
$params["action"] = "index";
}
if ($action = $document->getAction()) {
$params["action"] = $action;
}
$this->setErrorHandler($params);
$request->setParam("document", $document);
Zend_Registry::set("pimcore_error_document", $document);
}
} catch (Exception $e) {
Logger::emergency("error page not found");
}
}
// call default ZF error handler
parent::_handleError($request);
}
示例12: setTargetId
/**
* @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");
}
}
示例13: commentsAction
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();
}
示例14: testPermissionChanges
/**
* 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");
}
示例15: getForWebserviceExport
/**
* Returns the current tag's data for web service export
*
* @abstract
* @return array
*/
public function getForWebserviceExport()
{
$el = parent::getForWebserviceExport();
if ($this->data["internal"]) {
if (intval($this->data["internalId"]) > 0) {
if ($this->data["internalType"] == "document") {
$referencedDocument = Document::getById($this->data["internalId"]);
if (!$referencedDocument instanceof Document) {
//detected broken link
$document = Document::getById($this->getDocumentId());
Element_Service::scheduleForSanityCheck($document);
}
} else {
if ($this->data["internalType"] == "asset") {
$referencedAsset = Asset::getById($this->data["internalId"]);
if (!$referencedAsset instanceof Asset) {
//detected broken link
$document = Document::getById($this->getDocumentId());
Element_Service::scheduleForSanityCheck($document);
}
}
}
}
}
$el->data = $this->data;
return $el;
}