本文整理汇总了PHP中Phprojekt_Loader::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Phprojekt_Loader::getModel方法的具体用法?PHP Phprojekt_Loader::getModel怎么用?PHP Phprojekt_Loader::getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phprojekt_Loader
的用法示例。
在下文中一共展示了Phprojekt_Loader::getModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setConfigurations
/**
* Save the configurations into the table.
*
* @param array $params Array with values to save.
*
* @return void
*/
public function setConfigurations($params)
{
$fields = $this->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
$configuration = Phprojekt_Loader::getLibraryClass('Phprojekt_Configuration');
$configuration->setModule('General');
foreach ($fields as $data) {
foreach ($params as $key => $value) {
if ($key == $data['key']) {
if ($key == 'companyName') {
// Update Root node
$project = Phprojekt_Loader::getModel('Project', 'Project');
$project->find(1);
$project->title = $value;
$project->parentSave();
}
$where = sprintf('key_value = %s AND module_id = 0', $configuration->_db->quote($key));
$record = $configuration->fetchAll($where);
if (isset($record[0])) {
$record[0]->keyValue = $key;
$record[0]->value = $value;
$record[0]->save();
} else {
$configuration->moduleId = 0;
$configuration->keyValue = $key;
$configuration->value = $value;
$configuration->save();
}
break;
}
}
}
}
示例2: jsonDeleteAction
/**
* Deletes minutes and also all minutes items belonging to this minutes.
*
* REQUIRES request parameters:
* <pre>
* - integer <b>id</b> id of the minute to delete.
* </pre>
*
* The return is a string in JSON format with:
* <pre>
* - type => 'success' or 'error'.
* - message => Success or error message.
* - code => 0.
* - id => id of the deleted item.
* </pre>
*
* @throws Phprojekt_PublishedException On missing or wrong id, or on error in the action delete.
*
* @return void
*/
public function jsonDeleteAction()
{
$id = (int) $this->getRequest()->getParam('id');
if (empty($id)) {
throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
}
$minutes = $this->getModelObject()->find($id);
$minutesItems = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($id)->fetchAll();
$success = true;
if ($minutes instanceof Phprojekt_ActiveRecord_Abstract) {
foreach ($minutesItems as $item) {
$success = $success && false !== Default_Helpers_Delete::delete($item);
}
$success = $success && false !== Default_Helpers_Delete::delete($minutes);
if ($success === false) {
$message = Phprojekt::getInstance()->translate(self::DELETE_FALSE_TEXT);
$type = 'error';
} else {
$message = Phprojekt::getInstance()->translate(self::DELETE_TRUE_TEXT);
$type = 'success';
}
$return = array('type' => $type, 'message' => $message, 'code' => 0, 'id' => $id);
Phprojekt_Converter_Json::echoConvert($return);
} else {
throw new Phprojekt_PublishedException(self::NOT_FOUND);
}
}
示例3: getStatistics
/**
* Get all the values for the current project and sub-projects and return 3 array:
* 1. With Projects names.
* 2. With users names.
* 3. Relations Projects-User-Bookings.
*
* @param string $startDate Start date for make the query.
* @param string $endDate End date for make the query.
* @param integer $projectId Current Project ID.
*
* @return array Array with 'users', 'projects' and 'rows'.
*/
public function getStatistics($startDate, $endDate, $projectId)
{
$data['data'] = array();
$data['data']['users'] = array();
$data['data']['projects'] = array();
$data['data']['rows'] = array();
// Get Sub-Projects
$activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
$tree = new Phprojekt_Tree_Node_Database($activeRecord, $projectId);
$tree = $tree->setup();
$projectsId = array(0);
foreach ($tree as $node) {
if ($node->id) {
$projectsId[] = (int) $node->id;
$data['data']['projects'][$node->id] = $node->getDepthDisplay('title');
}
}
// Get Timecard
$model = Phprojekt_Loader::getModel('Timecard', 'Timecard');
$where = sprintf('(DATE(start_datetime) >= %s AND DATE(start_datetime) <= %s AND project_id IN (%s))', $model->_db->quote($startDate), $model->_db->quote($endDate), implode(", ", $projectsId));
$records = $model->fetchAll($where);
$users = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
foreach ($records as $record) {
if (!isset($data['data']['users'][$record->ownerId])) {
$user = $users->findUserById($record->ownerId);
$data['data']['users'][$record->ownerId] = $user->username;
}
if (!isset($data['data']['rows'][$record->projectId][$record->ownerId])) {
$data['data']['rows'][$record->projectId][$record->ownerId] = 0;
}
$data['data']['rows'][$record->projectId][$record->ownerId] += $record->minutes;
}
return $data;
}
示例4: testConvertTree
/**
* Test json convert tree
*/
public function testConvertTree()
{
$converted = '{}&&({"identifier":"id","label":"name","items":[{"name"';
$object = Phprojekt_Loader::getModel('Project', 'Project');
$tree = new Phprojekt_Tree_Node_Database($object, 1);
$tree = $tree->setup();
$result = Phprojekt_Converter_Json::convert($tree);
$this->assertEquals($converted, substr($result, 0, strlen($converted)));
}
示例5: testConvert
/**
* Test csv converter
*/
public function testConvert()
{
$convertedFields = '"Title","Start date","End date","Priority","Status","Complete percent"';
$convertedValues = '"Invisible Root","","","","Offered","0.00"';
$object = Phprojekt_Loader::getModel('Project', 'Project');
$records = $object->fetchAll();
$result = Phprojekt_Converter_Csv::convert($records);
$this->assertContains($convertedFields, $result);
$this->assertContains($convertedValues, $result);
$result = Phprojekt_Converter_Csv::convert($object->find(1));
$this->assertEquals($result, "");
}
示例6: _deleteTree
/**
* Delete a tree and all the sub-itemes.
*
* @param Phprojekt_ActiveRecord_Abstract $model Model to delete.
*
* @throws Exception If validation fails.
*
* @return boolean True for a sucessful delete.
*/
protected static function _deleteTree(Phprojekt_ActiveRecord_Abstract $model)
{
$id = $model->id;
// Checks
if ($id == 1) {
throw new Phprojekt_PublishedException('You can not delete the root project');
} else {
if (!self::_checkItemRights($model, 'Project')) {
throw new Phprojekt_PublishedException('You do not have access to do this action');
} else {
$relations = Phprojekt_Loader::getModel('Project', 'ProjectModulePermissions');
$where = sprintf('project_id = %d', (int) $id);
// Delete related items
$modules = $relations->getProjectModulePermissionsById($id);
$tag = Phprojekt_Tags::getInstance();
foreach ($modules['data'] as $moduleData) {
if ($moduleData['inProject']) {
$module = Phprojekt_Loader::getModel($moduleData['name'], $moduleData['name']);
if ($module instanceof Phprojekt_ActiveRecord_Abstract) {
$records = $module->fetchAll($where);
if (is_array($records)) {
foreach ($records as $record) {
$tag->deleteTagsByItem($moduleData['id'], $record->id);
self::delete($record);
}
}
}
}
}
// Delete module-project relaton
$records = $relations->fetchAll($where);
if (is_array($records)) {
foreach ($records as $record) {
$record->delete();
}
}
// Delete user-role-projetc relation
$relations = Phprojekt_Loader::getModel('Project', 'ProjectRoleUserPermissions');
$records = $relations->fetchAll($where);
if (is_array($records)) {
foreach ($records as $record) {
$record->delete();
}
}
// Delete the project itself
return null === $model->delete();
}
}
}
示例7: testDefaultModelsDefault
/**
* Test valid method
*
*/
public function testDefaultModelsDefault()
{
$defaultModel = Phprojekt_Loader::getModel('Default', 'Default');
$this->assertEquals($defaultModel->valid(), false);
$this->assertEquals($defaultModel->save(), false);
$this->assertEquals($defaultModel->getRights(), array());
$this->assertEquals($defaultModel->recordValidate(), true);
$this->assertEquals($defaultModel->getFieldsForFilter(), array());
$this->assertEquals($defaultModel->find(), null);
$this->assertEquals($defaultModel->fetchAll(), null);
$this->assertEquals($defaultModel->current(), null);
$this->assertEquals($defaultModel->rewind(), null);
$this->assertEquals($defaultModel->next(), null);
$this->assertEquals($defaultModel->getInformation(), null);
$this->assertEquals($defaultModel->key(), null);
}
示例8: jsonDeleteAction
/**
* Deletes a module.
*
* Deletes the module entries, the module itself,
* the databasemanager entry and the table itself.
*
* REQUIRES request parameters:
* <pre>
* - integer <b>id</b> id of the item to delete.
* </pre>
*
* The return is a string in JSON format with:
* <pre>
* - type => 'success'.
* - message => Success message.
* - id => id of the deleted item.
* </pre>
*
* @throws Zend_Controller_Action_Exception On missing or wrong id, or on error in the action delete.
*
* @return void
*/
public function jsonDeleteAction()
{
$id = (int) $this->getRequest()->getParam('id');
if (empty($id)) {
throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
}
$model = $this->getModelObject()->find($id);
if ($model instanceof Phprojekt_ActiveRecord_Abstract) {
if (is_dir(PHPR_CORE_PATH . $model->name)) {
throw new Zend_Controller_Action_Exception(self::CAN_NOT_DELETE_SYSTEM_MODULE, 422);
}
$databaseModel = Phprojekt_Loader::getModel($model->name, $model->name);
if ($databaseModel instanceof Phprojekt_Item_Abstract) {
$databaseManager = new Phprojekt_DatabaseManager($databaseModel);
if (Default_Helpers_Delete::delete($model)) {
$return = $databaseManager->deleteModule();
} else {
$return = false;
}
} else {
$return = Default_Helpers_Delete::delete($model);
}
if ($return === false) {
$message = Phprojekt::getInstance()->translate('The module can not be deleted');
$type = 'error';
} else {
Phprojekt::removeControllersFolders();
$message = Phprojekt::getInstance()->translate('The module was deleted correctly');
$type = 'success';
}
$return = array('type' => $type, 'message' => $message, 'id' => $id);
Phprojekt_Converter_Json::echoConvert($return);
} else {
throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404);
}
}
示例9: jsonListItemSortOrderAction
/**
* Returns a list of items for sort ordering.
*
* The return data have:
* <pre>
* - id: Order number.
* - name: Title of the item.
* </pre>
*
* REQUIRES request parameters:
* <pre>
* - integer <b>minutesId</b> The id of the minutes.
* </pre>
*
* The return is in JSON format.
*
* @return void
*/
public function jsonListItemSortOrderAction()
{
$minutesId = (int) $this->getRequest()->getParam('minutesId');
$items = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($minutesId)->fetchAll();
$return = array('data' => array(array('id' => 0, 'name' => '')));
foreach ($items as $item) {
$return['data'][] = array('id' => (int) $item->sortOrder, 'name' => $item->title);
}
Phprojekt_Converter_Json::echoConvert($return);
}
示例10: getNotification
/**
* Returns an instance of notification class for this module.
*
* @return Phprojekt_Notification An instance of Phprojekt_Notification.
*/
public function getNotification()
{
$notification = Phprojekt_Loader::getModel('Calendar', 'Notification');
$notification->setModel($this);
return $notification;
}
示例11: jsonSaveAction
/**
* Saves the new values of the projects dates.
*
* OPTIONAL request parameters:
* <pre>
* - array <b>projects</b> Array with projectId,startDate and endDate by comma separated
* </pre>
*
* If there is an error, the save will return a Phprojekt_PublishedException,
* if not, it returns a string in JSON format with:
* <pre>
* - type => 'success'.
* - message => Success message.
* - code => 0.
* - id => 0.
* </pre>
*
* @throws Phprojekt_PublishedException On error in the action save or wrong parameters.
*
* @return void
*/
public function jsonSaveAction()
{
$projects = (array) $this->getRequest()->getParam('projects', array());
$activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
$rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
$userId = Phprojekt_Auth::getUserId();
$this->setCurrentProjectId();
// Error check: no project received
if (empty($projects)) {
$label = Phprojekt::getInstance()->translate('Projects');
$message = Phprojekt::getInstance()->translate('No project info was received');
throw new Phprojekt_PublishedException($label . ': ' . $message);
}
foreach ($projects as $project) {
list($id, $startDate, $endDate) = explode(",", $project);
// Check: are the three values available?
if (empty($id) || empty($startDate) || empty($endDate)) {
$label = Phprojekt::getInstance()->translate('Projects');
$message = Phprojekt::getInstance()->translate('Incomplete data received');
throw new Phprojekt_PublishedException($label . ': ' . $message);
}
$id = (int) $id;
$activeRecord->find($id);
// Check: project id exists?
if (empty($activeRecord->id)) {
$label = Phprojekt::getInstance()->translate('Project');
$message = Phprojekt::getInstance()->translate('Id not found #') . $id;
throw new Phprojekt_PublishedException($label . ': ' . $message);
}
// Check: dates are valid?
$validStart = Cleaner::validate('date', $startDate, false);
$validEnd = Cleaner::validate('date', $endDate, false);
if (!$validStart || !$validEnd) {
$label = Phprojekt::getInstance()->translate('Project id #') . $id;
if (!$validStart) {
$message = Phprojekt::getInstance()->translate('Start date invalid');
} else {
$message = Phprojekt::getInstance()->translate('End date invalid');
}
throw new Phprojekt_PublishedException($label . ': ' . $message);
}
// Check: start date after end date?
$startDateTemp = strtotime($startDate);
$endDateTemp = strtotime($endDate);
if ($startDateTemp > $endDateTemp) {
$label = Phprojekt::getInstance()->translate('Project id #') . $id;
$message = Phprojekt::getInstance()->translate('Start date can not be after End date');
throw new Phprojekt_PublishedException($label . ': ' . $message);
}
$activeRecord->startDate = $startDate;
$activeRecord->endDate = $endDate;
if ($rights->getItemRight(1, $id, $userId) >= Phprojekt_Acl::WRITE) {
$activeRecord->parentSave();
}
}
$message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT);
$return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => 0);
Phprojekt_Converter_Json::echoConvert($return);
}
示例12: searchModuleByWordId
/**
* Get all the modules-item with the wordId.
*
* @param array $words Array with words IDs.
* @param string $operator Query operator.
* @param integer $count Limit query.
*
* @return array Array of results.
*/
public function searchModuleByWordId($words, $operator = 'AND', $count = 0)
{
$ids = array();
$result = array();
$rights = new Phprojekt_Item_Rights();
$userId = Phprojekt_Auth::getUserId();
$db = Phprojekt::getInstance()->getDb();
foreach ($words as $content) {
$ids[] = (int) $content['id'];
}
if (!empty($ids)) {
// Search by AND
if ($operator == 'AND') {
$sqlString = '';
$selects = array();
$first = true;
while (!empty($ids)) {
$id = array_pop($ids);
if ($first) {
$first = false;
if (!empty($ids)) {
$selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id);
} else {
$selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id);
}
} else {
if (!empty($ids)) {
$selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
} else {
$selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
}
}
}
$first = true;
while (!empty($selects)) {
$select = array_shift($selects)->__toString();
if ($first) {
$sqlString = $select;
$first = false;
} else {
$sqlString = sprintf($select, $sqlString);
}
}
$stmt = $db->query($sqlString);
$tmpResult = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
} else {
// Search By OR
$where = 'word_id IN (' . implode(', ', $ids) . ')';
$order = array('module_id ASC', 'item_id DESC');
$tmpResult = $this->fetchAll($where, $order)->toArray();
}
foreach ($tmpResult as $data) {
// Limit to $count results
if ((int) $count > 0 && count($result) >= $count) {
break;
}
$moduleName = Phprojekt_Module::getModuleName($data['module_id']);
$model = Phprojekt_Loader::getModel($moduleName, $moduleName);
if ($model) {
// Only fetch records with read access
$model = $model->find($data['item_id']);
if (!empty($model)) {
$result[$data['module_id'] . '-' . $data['item_id']] = $data;
}
}
}
}
return $result;
}
示例13: jsonGetUsersRightsAction
/**
* Returns the rights for all the users of one item.
*
* OPTIONAL request parameters:
* <pre>
* - integer <b>id</b> The id of the item to consult.
* - integer <b>nodeId</b> The id of the parent project.
* </pre>
*
* The return is an array like ('#userID' => {'admin': true/false, 'read': true/false, etc})
* The return is in JSON format.
*
* @return void
*/
public function jsonGetUsersRightsAction()
{
$id = (int) $this->getRequest()->getParam('id');
$projectId = (int) $this->getRequest()->getParam('nodeId');
if (empty($id)) {
if (empty($projectId)) {
$record = $this->getModelObject();
} else {
$model = Phprojekt_Loader::getModel('Project', 'Project');
$record = $model->find($projectId);
}
} else {
$record = $this->getModelObject()->find($id);
}
if ($record instanceof Phprojekt_Model_Interface) {
Phprojekt_Converter_Json::echoConvert($record->getUsersRights());
} else {
Phprojekt_Converter_Json::echoConvert(array());
}
}
示例14: getModel
/**
* Get the object class to use for manage the settings.
*
* @return Object Class.
*/
public function getModel()
{
if (null === $this->_object) {
// System settings
if ($this->_module == 'User' || $this->_module == 'Notification') {
$this->_object = Phprojekt_Loader::getModel('Core', sprintf('%s_Setting', $this->_module));
} else {
$this->_object = Phprojekt_Loader::getModel($this->_module, 'Setting');
}
}
return $this->_object;
}
示例15: testGetFieldDefinition
public function testGetFieldDefinition()
{
// startDatetime
$data1 = array();
$data1['key'] = 'startDatetime';
$data1['label'] = Phprojekt::getInstance()->translate('Start');
$data1['originalLabel'] = 'Start';
$data1['type'] = 'datetime';
$data1['hint'] = Phprojekt::getInstance()->getTooltip('startDatetime');
$data1['listPosition'] = 1;
$data1['formPosition'] = 1;
$data1['fieldset'] = '';
$data1['range'] = array('id' => '', 'name' => '');
$data1['required'] = true;
$data1['readOnly'] = false;
$data1['tab'] = 1;
$data1['integer'] = false;
$data1['length'] = 0;
$data1['default'] = null;
// endTtime
$data2 = array();
$data2['key'] = 'endTime';
$data2['label'] = Phprojekt::getInstance()->translate('End');
$data2['originalLabel'] = 'End';
$data2['type'] = 'time';
$data2['hint'] = Phprojekt::getInstance()->getTooltip('endTime');
$data2['listPosition'] = 2;
$data2['formPosition'] = 2;
$data2['fieldset'] = '';
$data2['range'] = array('id' => '', 'name' => '');
$data2['required'] = false;
$data2['readOnly'] = false;
$data2['tab'] = 1;
$data2['integer'] = false;
$data2['length'] = 0;
$data2['default'] = null;
$data3 = array();
$data3['key'] = 'minutes';
$data3['label'] = Phprojekt::getInstance()->translate('Minutes');
$data3['originalLabel'] = 'Minutes';
$data3['type'] = 'text';
$data3['hint'] = Phprojekt::getInstance()->getTooltip('minutes');
$data3['listPosition'] = 3;
$data3['formPosition'] = 3;
$data3['fieldset'] = '';
$data3['range'] = array('id' => '', 'name' => '');
$data3['required'] = false;
$data3['readOnly'] = false;
$data3['tab'] = 1;
$data3['integer'] = true;
$data3['length'] = 0;
$data3['default'] = null;
$data4 = array();
$data4['key'] = 'projectId';
$data4['label'] = Phprojekt::getInstance()->translate('Project');
$data4['originalLabel'] = 'Project';
$data4['type'] = 'selectbox';
$data4['hint'] = Phprojekt::getInstance()->getTooltip('projectId');
$data4['listPosition'] = 4;
$data4['formPosition'] = 4;
$data4['fieldset'] = '';
$data4['range'] = array();
$activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
$tree = new Phprojekt_Tree_Node_Database($activeRecord, 1);
$tree = $tree->setup();
foreach ($tree as $node) {
$data4['range'][] = array('id' => (int) $node->id, 'name' => $node->getDepthDisplay('title'));
}
$data4['required'] = true;
$data4['readOnly'] = false;
$data4['tab'] = 1;
$data4['integer'] = true;
$data4['length'] = 0;
$data4['default'] = null;
$data5 = array();
$data5['key'] = 'notes';
$data5['label'] = Phprojekt::getInstance()->translate('Notes');
$data5['originalLabel'] = 'Notes';
$data5['type'] = 'textarea';
$data5['hint'] = Phprojekt::getInstance()->getTooltip('notes');
$data5['listPosition'] = 5;
$data5['formPosition'] = 5;
$data5['fieldset'] = '';
$data5['range'] = array('id' => '', 'name' => '');
$data5['required'] = false;
$data5['readOnly'] = false;
$data5['tab'] = 1;
$data5['integer'] = false;
$data5['length'] = 0;
$data5['default'] = null;
$timecardModel = clone $this->_model;
$expected = array($data1, $data2, $data3, $data4, $data5);
$order = Phprojekt_ModelInformation_Default::ORDERING_FORM;
$this->assertEquals($expected, $timecardModel->getInformation()->getFieldDefinition($order));
}