本文整理汇总了PHP中Phprojekt_Loader::getModuleFromObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Phprojekt_Loader::getModuleFromObject方法的具体用法?PHP Phprojekt_Loader::getModuleFromObject怎么用?PHP Phprojekt_Loader::getModuleFromObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phprojekt_Loader
的用法示例。
在下文中一共展示了Phprojekt_Loader::getModuleFromObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _saveModel
/**
* Help to save a model by setting the models properties.
* Validation is based on the ModelInformation implementation.
*
* @param Phprojekt_Model_Interface $model The model
* @param array $params The parameters used to feed the model.
*
* @throws Exception If validation of parameters fails.
*
* @return boolean True for a sucessful save.
*/
protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
{
foreach ($params as $k => $v) {
if (isset($model->{$k})) {
// Don't allow to set the id on save, since it is done by the ActiveRecord
if (!in_array($k, array('id'))) {
$model->{$k} = $v;
}
}
}
if (empty($model->id)) {
$newItem = true;
} else {
$newItem = false;
}
// Set the owner
if ($newItem && isset($model->ownerId)) {
$model->ownerId = Phprojekt_Auth::getUserId();
}
// Parent Project
if (isset($model->projectId)) {
$projectId = $model->projectId;
} else {
$projectId = 0;
}
// Checks
$moduleName = Phprojekt_Loader::getModuleFromObject($model);
$moduleId = Phprojekt_Module::getId($moduleName);
if (!$model->recordValidate()) {
$errors = $model->getError();
$error = array_pop($errors);
throw new Phprojekt_PublishedException($error['label'] . ': ' . $error['message']);
} else {
if (!self::_checkModule($moduleId, $projectId)) {
throw new Phprojekt_PublishedException('The parent project do not have enabled this module');
} else {
if (!self::_checkItemRights($model, $moduleName)) {
throw new Phprojekt_PublishedException('You do not have access to do this action');
} else {
// Set the projectId to 1 for global modules
if (isset($model->projectId) && Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
$model->projectId = 1;
}
$model->save();
// Save access only if the user have "admin" right
$itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
$check = $itemRights->getRights($moduleId, $model->id);
if ($check['currentUser']['admin']) {
if ($moduleName == 'Core') {
$rights = Default_Helpers_Right::getModuleRights($params);
} else {
$rights = Default_Helpers_Right::getItemRights($params, $moduleId, $newItem);
}
if (count($rights) > 0) {
$model->saveRights($rights);
}
}
return $model;
}
}
}
}
示例2: testGetModuleFromObject
/**
* Test getModuleFromObject
*/
public function testGetModuleFromObject()
{
$object = Phprojekt_Loader::getModel('Todo', 'Todo');
$this->assertEquals('Todo', Phprojekt_Loader::getModuleFromObject($object));
}
示例3: _deleteModel
/**
* Help to delete a model.
*
* @param Phprojekt_ActiveRecord_Abstract $model The model to delete.
*
* @throws Exception If validation fails.
*
* @return boolean True for a sucessful delete.
*/
protected static function _deleteModel(Phprojekt_ActiveRecord_Abstract $model)
{
// Checks
$moduleName = Phprojekt_Loader::getModuleFromObject($model);
if (!self::_checkItemRights($model, $moduleName)) {
throw new Phprojekt_PublishedException('You do not have access to do this action');
} else {
$return = $model->delete();
if (isset($return->id) && null === $return->id || null === $return) {
// ActiveRecord delete the model.
return true;
} else {
if (is_bool($return)) {
// An extention returns true or false.
return $return;
} else {
// Any other value, is wrong.
return false;
}
}
}
}
示例4: _deleteModel
/**
* Help to delete a model.
*
* @param Phprojekt_ActiveRecord_Abstract $model The model to delete.
*
* @throws Exception If validation fails.
*
* @return boolean True for a sucessful delete.
*/
protected static function _deleteModel(Phprojekt_ActiveRecord_Abstract $model)
{
// Checks
$moduleName = Phprojekt_Loader::getModuleFromObject($model);
if (!self::_checkItemRights($model, $moduleName)) {
throw new Zend_Controller_Action_Exception('You do not have access to do this action', 400);
} else {
$return = $model->delete();
if (is_bool($return)) {
// An extention returns true or false.
return $return;
} else {
if (is_null($return) || is_a($return, 'Phprojekt_ActiveRecord_Abstract') && is_null($return->id)) {
// ActiveRecord delete the model.
return true;
} else {
// Any other value, is wrong.
return false;
}
}
}
}
示例5: _deleteModel
/**
* Help to delete a model.
*
* @param Phprojekt_Model_Interface $model The model to delete.
*
* @throws Exception If validation fails.
*
* @return boolean True for a sucessful delete.
*/
protected static function _deleteModel(Phprojekt_Model_Interface $model)
{
// Checks
$moduleName = Phprojekt_Loader::getModuleFromObject($model);
if (!self::_checkItemRights($model, $moduleName)) {
throw new Phprojekt_PublishedException('You do not have access to do this action');
} else {
return $model->delete();
}
}
示例6: _saveModel
/**
* Help to save a model by setting the models properties.
* Validation is based on the ModelInformation implementation.
*
* @param Phprojekt_Model_Interface $model The model
* @param array $params The parameters used to feed the model.
*
* @throws Exception If validation of parameters fails.
*
* @return boolean True for a sucessful save.
*/
protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
{
$newItem = empty($params['id']);
$model = self::parameterToModel($model, $params, $newItem);
$projectId = $model->hasField('projectId') ? $model->projectId : 0;
$userId = Phprojekt_Auth_Proxy::getEffectiveUserId();
$moduleName = Phprojekt_Loader::getModuleFromObject($model);
$moduleId = Phprojekt_Module::getId($moduleName);
if (!$model->recordValidate()) {
$errors = $model->getError();
$error = array_pop($errors);
throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400);
}
if (!self::_checkModule($moduleId, $projectId)) {
throw new Zend_Controller_Action_Exception('The parent project do not have enabled this module', 400);
}
$rights = Default_Helpers_Right::getRights($params);
if ($model instanceof Phprojekt_Item_Abstract) {
if ($newItem && !Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
$project = new Project_Models_Project();
$project->find($projectId);
if (!$project->hasRight($userId, Phprojekt_Acl::CREATE)) {
throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403);
}
$rights[$userId] = Phprojekt_Acl::ALL;
} else {
if (!$model->hasRight($userId, Phprojekt_Acl::WRITE)) {
throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403);
}
}
// Set the projectId to 1 for global modules
// @TODO Remove the Timecard limitation
if ($model->hasField('projectId') && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') {
$model->projectId = 1;
}
$model->save();
// Save access only if the user have "admin" right
if ($newItem || $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::ADMIN)) {
if (!Phprojekt_Auth_Proxy::isAdminUser() && count($rights) <= 0) {
throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400);
}
$model->saveRights($rights);
}
} else {
$model->save();
$model->saveRights($rights);
}
return $model;
}