当前位置: 首页>>代码示例>>PHP>>正文


PHP Database::getManager方法代码示例

本文整理汇总了PHP中Database::getManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::getManager方法的具体用法?PHP Database::getManager怎么用?PHP Database::getManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database::getManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkSessionRequirementsForUser

 /**
  * Check if the ser has completed the requirements for the session sequences
  * @param array $sequences The sequences
  * @param int $userId Optional. The user ID
  * @return array
  */
 private static function checkSessionRequirementsForUser(array $sequences, $userId = 0)
 {
     $sequenceList = [];
     $entityManager = Database::getManager();
     $gradebookCategoryRepo = $entityManager->getRepository('ChamiloCoreBundle:GradebookCategory');
     foreach ($sequences as $sequenceId => $sequence) {
         $item = ['name' => $sequence['name'], 'requirements' => []];
         foreach ($sequence['requirements'] as $sessionRequired) {
             $itemSession = ['name' => $sessionRequired->getName(), 'status' => true];
             $sessionsCourses = $sessionRequired->getCourses();
             foreach ($sessionsCourses as $sessionCourse) {
                 $course = $sessionCourse->getCourse();
                 $gradebooks = $gradebookCategoryRepo->findBy(['courseCode' => $course->getCode(), 'sessionId' => $sessionRequired->getId(), 'isRequirement' => true]);
                 foreach ($gradebooks as $gradebook) {
                     $category = Category::createCategoryObjectFromEntity($gradebook);
                     if (!empty($userId)) {
                         $itemSession['status'] = $itemSession['status'] && Category::userFinishedCourse($userId, $category, null, $course->getCode(), $sessionRequired->getId());
                     }
                 }
             }
             $item['requirements'][$sessionRequired->getId()] = $itemSession;
         }
         $sequenceList[$sequenceId] = $item;
     }
     return $sequenceList;
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:32,代码来源:SequenceResourceManager.php

示例2: get_class_data

/**
 * Get the classes to display on the current page.
 */
function get_class_data($from, $number_of_items, $column, $direction)
{
    $class_table = Database::get_main_table(TABLE_MAIN_CLASS);
    $class_user_table = Database::get_main_table(TABLE_MAIN_CLASS_USER);
    $courseId = api_get_course_int_id();
    $em = Database::getManager();
    $res = $em->getRepository('ChamiloCoreBundle:CourseRelClass')->findBy(['courseId' => $courseId]);
    $subscribed_classes = array();
    foreach ($res as $obj) {
        $subscribed_classes[] = $obj->getClassId();
    }
    $sql = "SELECT\n                c.id AS col0,\n                c.name   AS col1,\n                COUNT(cu.user_id) AS col2,\n                c.id AS col3\n            FROM {$class_table} c ";
    $sql .= " LEFT JOIN {$class_user_table} cu ON cu.class_id = c.id";
    $sql .= " WHERE 1 = 1";
    if (isset($_GET['keyword'])) {
        $keyword = Database::escape_string(trim($_GET['keyword']));
        $sql .= " AND (c.name LIKE '%" . $keyword . "%')";
    }
    if (count($subscribed_classes) > 0) {
        $sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')";
    }
    $sql .= " GROUP BY c.id, c.name ";
    $sql .= " ORDER BY col{$column} {$direction} ";
    $sql .= " LIMIT {$from},{$number_of_items}";
    $res = Database::query($sql);
    $classes = array();
    while ($class = Database::fetch_row($res)) {
        $classes[] = $class;
    }
    return $classes;
}
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:34,代码来源:subscribe_class.php

示例3: getEntityManager

 /**
  * @return EntityManager
  */
 public function getEntityManager()
 {
     if (empty($this->manager)) {
         $dbParams = array('driver' => 'pdo_mysql', 'host' => api_get_configuration_value('db_host'), 'user' => api_get_configuration_value('db_user'), 'password' => api_get_configuration_value('db_password'), 'dbname' => api_get_configuration_value('main_database'));
         $database = new \Database();
         $database->connect($dbParams, __DIR__ . '/../../', __DIR__ . '/../../');
         $this->manager = $database->getManager();
     }
     return $this->manager;
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:13,代码来源:AbstractMigrationChamilo.php

示例4: getAllValuesForAnItem

 /**
  * Get all values for an item
  * @param int $itemId The item ID
  * @param boolean $onlyVisibleFields Get the visible extra field only
  * @return array
  */
 public function getAllValuesForAnItem($itemId, $onlyVisibleFields = false)
 {
     $em = Database::getManager();
     $queryBuilder = $em->createQueryBuilder();
     $fieldOptionsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldOptions');
     $queryBuilder = $queryBuilder->select('fv')->from('ChamiloCoreBundle:ExtraFieldValues', 'fv')->innerJoin('ChamiloCoreBundle:ExtraField', 'f', Doctrine\ORM\Query\Expr\Join::WITH, 'fv.field = f')->where($queryBuilder->expr()->andX($queryBuilder->expr()->eq('fv.itemId', ':item'), $queryBuilder->expr()->eq('f.extraFieldType', ':field_type')));
     if ($onlyVisibleFields) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('f.visible', true));
     }
     $fieldValues = $queryBuilder->setParameter('item', $itemId)->setParameter('field_type', $this->getExtraField()->getExtraFieldType())->getQuery()->getResult();
     $valueList = [];
     foreach ($fieldValues as $fieldValue) {
         $item = ['value' => $fieldValue];
         switch ($fieldValue->getField()->getFieldType()) {
             case ExtraField::FIELD_TYPE_SELECT:
                 $item['option'] = $fieldOptionsRepo->findOneBy(['field' => $fieldValue->getField(), 'value' => $fieldValue->getValue()]);
                 break;
         }
         $valueList[] = $item;
     }
     return $valueList;
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:28,代码来源:extra_field_value.lib.php

示例5: save

 /**
  * Save values in the *_field_values table
  * @param array Structured array with the values to save
  * @param boolean Whether to show the insert query (passed to the parent save() method)
  * @result mixed The result sent from the parent method
  * @assert (array()) === false
  */
 public function save($params, $show_query = false)
 {
     $extra_field = new ExtraField($this->type);
     // Setting value to insert.
     $value = $params['field_value'];
     $value_to_insert = null;
     if (is_array($value)) {
         $value_to_insert = implode(';', $value);
     } else {
         $value_to_insert = Database::escape_string($value);
     }
     $params['field_value'] = $value_to_insert;
     //If field id exists
     $extra_field_info = $extra_field->get($params['field_id']);
     if ($extra_field_info) {
         switch ($extra_field_info['field_type']) {
             case ExtraField::FIELD_TYPE_RADIO:
             case ExtraField::FIELD_TYPE_SELECT:
             case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
                 //$field_options = $session_field_option->get_field_options_by_field($params['field_id']);
                 //$params['field_value'] = split(';', $value_to_insert);
                 /*
                                         if ($field_options) {
                                             $check = false;
                                             foreach ($field_options as $option) {
                                                 if (in_array($option['option_value'], $values)) {
                                                     $check = true;
                                                     break;
                                                 }
                                            }
                                            if (!$check) {
                                                return false; //option value not found
                                            }
                                        } else {
                                            return false; //enumerated type but no option found
                                        }*/
                 break;
             case ExtraField::FIELD_TYPE_TEXT:
             case ExtraField::FIELD_TYPE_TEXTAREA:
                 break;
             case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
                 if (is_array($value)) {
                     if (isset($value['extra_' . $extra_field_info['field_variable']]) && isset($value['extra_' . $extra_field_info['field_variable'] . '_second'])) {
                         $value_to_insert = $value['extra_' . $extra_field_info['field_variable']] . '::' . $value['extra_' . $extra_field_info['field_variable'] . '_second'];
                     } else {
                         $value_to_insert = null;
                     }
                 }
                 break;
             default:
                 break;
         }
         if ($extra_field_info['field_type'] == ExtraField::FIELD_TYPE_TAG) {
             $field_values = self::getAllValuesByItemAndFieldAndValue($params[$this->handler_id], $params['field_id'], $value);
         } else {
             $field_values = self::get_values_by_handler_and_field_id($params[$this->handler_id], $params['field_id']);
         }
         $params['field_value'] = $value_to_insert;
         $params['tms'] = api_get_utc_datetime();
         $params[$this->author_id] = api_get_user_id();
         // Insert
         if (empty($field_values)) {
             if ($extra_field_info['field_loggeable'] == 1) {
                 switch ($this->type) {
                     case 'question':
                         $extraFieldValue = new QuestionFieldValues();
                         $extraFieldValue->setUserId(api_get_user_id());
                         $extraFieldValue->setQuestionId($params[$this->handler_id]);
                         break;
                     case 'course':
                         $extraFieldValue = new CourseFieldValues();
                         $extraFieldValue->setUserId(api_get_user_id());
                         $extraFieldValue->setQuestionId($params[$this->handler_id]);
                         break;
                     case 'user':
                         $extraFieldValue = new UserFieldValues();
                         $extraFieldValue->setUserId($params[$this->handler_id]);
                         $extraFieldValue->setAuthorId(api_get_user_id());
                         break;
                     case 'session':
                         $extraFieldValue = new SessionFieldValues();
                         $extraFieldValue->setUserId(api_get_user_id());
                         $extraFieldValue->setSessionId($params[$this->handler_id]);
                         break;
                 }
                 if (isset($extraFieldValue)) {
                     if (!empty($params['field_value'])) {
                         $extraFieldValue->setComment($params['comment']);
                         $extraFieldValue->setFieldValue($params['field_value']);
                         $extraFieldValue->setFieldId($params['field_id']);
                         $extraFieldValue->setTms(api_get_utc_datetime(null, false, true));
                         Database::getManager()->persist($extraFieldValue);
                         Database::getManager()->flush();
//.........这里部分代码省略.........
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:101,代码来源:extra_field_value.lib.php

示例6: delete_category

 static function delete_category($id)
 {
     $em = Database::getManager();
     $item = $em->find('ChamiloCoreBundle:CLpCategory', $id);
     if ($item) {
         $courseId = $item->getCId();
         $query = $em->createQuery('SELECT u FROM ChamiloCoreBundle:CLp u WHERE u.cId = :id AND u.categoryId = :catId');
         $query->setParameter('id', $courseId);
         $query->setParameter('catId', $item->getId());
         $lps = $query->getResult();
         // Setting category = 0.
         if ($lps) {
             foreach ($lps as $lpItem) {
                 $lpItem->setCategoryId(0);
             }
         }
         // Removing category.
         $em->remove($item);
         $em->flush();
     }
 }
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:21,代码来源:learnpath.class.php

示例7: sendResetEmail

 /**
  * @param User $user
  */
 public static function sendResetEmail(User $user)
 {
     //if (null === $user->getConfirmationToken()) {
     $uniqueId = api_get_unique_id();
     $user->setConfirmationToken($uniqueId);
     $user->setPasswordRequestedAt(new \DateTime());
     Database::getManager()->persist($user);
     Database::getManager()->flush();
     $url = api_get_path(WEB_CODE_PATH) . 'auth/reset.php?token=' . $uniqueId;
     $mailTemplate = new Template(null, false, false, false, false, false);
     $mailTemplate->assign('complete_user_name', $user->getCompleteName());
     $mailTemplate->assign('link', $url);
     $mailLayout = $mailTemplate->get_template('mail/reset_password.tpl');
     $mailSubject = get_lang('ResetPasswordInstructions');
     $mailBody = $mailTemplate->fetch($mailLayout);
     api_mail_html($user->getCompleteName(), $user->getEmail(), $mailSubject, $mailBody);
     Display::addFlash(Display::return_message(get_lang('CheckYourEmailAndFollowInstructions')));
     //}
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:22,代码来源:login.lib.php

示例8: create_group

 /**
  * Create a group
  * @param string $name The name for this group
  * @param int $category_id
  * @param int $tutor The user-id of the group's tutor
  * @param int $places How many people can subscribe to the new group
  */
 public static function create_group($name, $category_id, $tutor, $places)
 {
     $courseObj = api_get_user_course_entity();
     $_course = api_get_course_info();
     $session_id = api_get_session_id();
     $currentCourseRepository = $_course['path'];
     $category = self::get_category($category_id);
     $places = intval($places);
     if ($category) {
         if ($places == 0) {
             //if the amount of users per group is not filled in, use the setting from the category
             $places = $category['max_student'];
         } else {
             if ($places > $category['max_student'] && $category['max_student'] != 0) {
                 $places = $category['max_student'];
             }
         }
         $docState = $category['doc_state'];
         $calendarState = $category['calendar_state'];
         $workState = $category['work_state'];
         $anonuncementState = $category['announcements_state'];
         $forumState = $category['forum_state'];
         $wikiState = $category['wiki_state'];
         $chatState = $category['chat_state'];
         $selfRegAllowed = $category['self_reg_allowed'];
         $selfUnregAllowed = $category['self_unreg_allowed'];
     } else {
         $docState = self::TOOL_PRIVATE;
         $calendarState = self::TOOL_PRIVATE;
         $workState = self::TOOL_PRIVATE;
         $anonuncementState = self::TOOL_PRIVATE;
         $forumState = self::TOOL_PRIVATE;
         $wikiState = self::TOOL_PRIVATE;
         $chatState = self::TOOL_PRIVATE;
         $selfRegAllowed = 0;
         $selfUnregAllowed = 0;
     }
     $group = new CGroupInfo();
     $group->setName($name)->setStatus(1)->setDescription('')->setMaxStudent($places)->setAnnouncementsState($anonuncementState)->setDocState($docState)->setCalendarState($calendarState)->setChatState($chatState)->setForumState($forumState)->setWikiState($wikiState)->setWorkState($workState)->setSelfUnregistrationAllowed($selfUnregAllowed)->setSelfRegistrationAllowed($selfRegAllowed)->setSessionId($session_id)->setCourse($courseObj)->setCategoryId($category_id)->setDescription('');
     $em = Database::getManager();
     $em->persist($group);
     $em->flush();
     $lastId = $group->getIid();
     if ($lastId) {
         $desired_dir_name = '/' . api_replace_dangerous_char($name) . '_groupdocs';
         $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
         $newFolderData = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null, 1);
         $unique_name = $newFolderData['path'];
         $group->setId($lastId);
         $group->setSecretDirectory($unique_name);
         $group->setName($name);
         $em->merge($group);
         $em->flush();
         // create a forum if needed
         if ($forumState >= 0) {
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php';
             require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
             $forum_categories = get_forum_categories();
             if (empty($forum_categories)) {
                 $categoryParam = array('forum_category_title' => get_lang('GroupForums'));
                 store_forumcategory($categoryParam);
                 $forum_categories = get_forum_categories();
             }
             $counter = 0;
             foreach ($forum_categories as $key => $value) {
                 if ($counter == 0) {
                     $forum_category_id = $key;
                 }
                 $counter++;
             }
             // A sanity check.
             if (empty($forum_category_id)) {
                 $forum_category_id = 0;
             }
             $values = array();
             $values['forum_title'] = $name;
             $values['group_id'] = $lastId;
             $values['forum_category'] = $forum_category_id;
             $values['allow_anonymous_group']['allow_anonymous'] = 0;
             $values['students_can_edit_group']['students_can_edit'] = 0;
             $values['approval_direct_group']['approval_direct'] = 0;
             $values['allow_attachments_group']['allow_attachments'] = 1;
             $values['allow_new_threads_group']['allow_new_threads'] = 1;
             $values['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
             $values['group_forum'] = $lastId;
             if ($forumState == '1') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'public';
             } elseif ($forumState == '2') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'private';
             } elseif ($forumState == '0') {
                 $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable';
             }
             store_forum($values);
//.........这里部分代码省略.........
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:101,代码来源:groupmanager.lib.php

示例9: CToolIntro

 if ($intro_cmdUpdate) {
     if ($form->validate()) {
         $form_values = $form->exportValues();
         $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY);
         $criteria = ['cId' => $course_id, 'id' => $moduleId, 'sessionId' => $session_id];
         if (!empty($intro_content)) {
             /** @var CToolIntro $toolIntro */
             $toolIntro = Database::getManager()->getRepository('ChamiloCourseBundle:CToolIntro')->findOneBy($criteria);
             if ($toolIntro) {
                 $toolIntro->setIntroText($intro_content);
             } else {
                 $toolIntro = new CToolIntro();
                 $toolIntro->setSessionId($session_id)->setCId($course_id)->setIntroText($intro_content)->setId($moduleId);
             }
             Database::getManager()->persist($toolIntro);
             Database::getManager()->flush();
             $introduction_section .= Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false);
         } else {
             // got to the delete command
             $intro_cmdDel = true;
         }
     } else {
         $intro_cmdEdit = true;
     }
 }
 /* Delete Command */
 if ($intro_cmdDel) {
     $sql = "DELETE FROM {$TBL_INTRODUCTION}\n                WHERE\n                    c_id = {$course_id} AND\n                    id='" . Database::escape_string($moduleId) . "' AND\n                    session_id='" . intval($session_id) . "'";
     Database::query($sql);
     $introduction_section .= Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:31,代码来源:introductionSection.inc.php

示例10: getPosts

/**
 * Retrieve all posts of a given thread
 * @param int $threadId The thread ID
 * @param string $orderDirection Optional. The direction for sort the posts
 * @param boolean $recursive Optional. If the list is recursive
 * @param int $postId Optional. The post ID for recursive list
 * @param int $depth Optional. The depth to indicate the indent
 * @todo move to a repository
 *
 * @return array containing all the information about the posts of a given thread
 */
function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
{
    $list = [];
    $em = Database::getManager();
    if (api_is_allowed_to_edit(false, true)) {
        $visibleCriteria = Criteria::expr()->neq('visible', 2);
    } else {
        $visibleCriteria = Criteria::expr()->eq('visible', 1);
    }
    $criteria = Criteria::create();
    $criteria->where(Criteria::expr()->eq('threadId', $threadId))->andWhere(Criteria::expr()->eq('cId', api_get_course_int_id()))->andWhere($visibleCriteria);
    if ($recursive) {
        $criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
    }
    $qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');
    $qb->select('p')->addCriteria($criteria)->addOrderBy('p.postId', $orderDirection);
    $posts = $qb->getQuery()->getResult();
    $depth++;
    /** @var \Chamilo\CourseBundle\Entity\CForumPost $post */
    foreach ($posts as $post) {
        $user = $em->find('ChamiloUserBundle:User', $post->getPosterId());
        $list[$post->getPostId()] = ['c_id' => $post->getCId(), 'post_id' => $post->getPostId(), 'post_title' => $post->getPostTitle(), 'post_text' => $post->getPostText(), 'thread_id' => $post->getThreadId(), 'forum_id' => $post->getForumId(), 'poster_id' => $post->getPosterId(), 'poster_name' => $post->getPosterName(), 'post_date' => $post->getPostDate(), 'post_notification' => $post->getPostNotification(), 'post_parent_id' => $post->getPostParentId(), 'visible' => $post->getVisible(), 'indent_cnt' => $depth, 'user_id' => $user->getUserId(), 'username' => $user->getUsername(), 'username_canonical' => $user->getUsernameCanonical(), 'lastname' => $user->getLastname(), 'firstname' => $user->getFirstname()];
        if (!$recursive) {
            continue;
        }
        $list = array_merge($list, getPosts($threadId, $orderDirection, $recursive, $post->getPostId(), $depth));
    }
    return $list;
}
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:40,代码来源:forumfunction.inc.php

示例11: register_course

 /**
  * Function register_course to create a record in the course table of the main database
  * @param array Course details (see code for details)
  * @return int  Created course ID
  * @todo use an array called $params instead of lots of params
  * @assert (null) === false
  */
 public static function register_course($params)
 {
     global $error_msg;
     $title = $params['title'];
     $code = $params['code'];
     $visual_code = $params['visual_code'];
     $directory = $params['directory'];
     $tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null;
     //$description        = $params['description'];
     $category_code = isset($params['course_category']) ? $params['course_category'] : '';
     $course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting('language.platform_language');
     $user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']);
     $department_name = isset($params['department_name']) ? $params['department_name'] : null;
     $department_url = isset($params['department_url']) ? $params['department_url'] : null;
     $disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null;
     if (!isset($params['visibility'])) {
         $default_course_visibility = api_get_setting('course.courses_default_creation_visibility');
         if ($default_course_visibility != '') {
             $visibility = $default_course_visibility;
         } else {
             $visibility = COURSE_VISIBILITY_OPEN_PLATFORM;
         }
     } else {
         $visibility = $params['visibility'];
     }
     $subscribe = isset($params['subscribe']) ? intval($params['subscribe']) : ($visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0);
     $unsubscribe = isset($params['unsubscribe']) ? intval($params['unsubscribe']) : 0;
     $expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null;
     $teachers = isset($params['teachers']) ? $params['teachers'] : null;
     $status = isset($params['status']) ? $params['status'] : null;
     $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $ok_to_register_course = true;
     // Check whether all the needed parameters are present.
     if (empty($code)) {
         $error_msg[] = 'courseSysCode is missing';
         $ok_to_register_course = false;
     }
     if (empty($visual_code)) {
         $error_msg[] = 'courseScreenCode is missing';
         $ok_to_register_course = false;
     }
     if (empty($directory)) {
         $error_msg[] = 'courseRepository is missing';
         $ok_to_register_course = false;
     }
     if (empty($title)) {
         $error_msg[] = 'title is missing';
         $ok_to_register_course = false;
     }
     if (empty($expiration_date)) {
         $expiration_date = api_get_utc_datetime(time() + FIRST_EXPIRATION_DELAY, false, true);
     } else {
         $expiration_date = api_get_utc_datetime($expiration_date, false, true);
     }
     if ($visibility < 0 || $visibility > 4) {
         $error_msg[] = 'visibility is invalid';
         $ok_to_register_course = false;
     }
     if (empty($disk_quota)) {
         $disk_quota = api_get_setting('document.default_document_quotum');
     }
     if (stripos($department_url, 'http://') === false && stripos($department_url, 'https://') === false) {
         $department_url = 'http://' . $department_url;
     }
     //just in case
     if ($department_url == 'http://') {
         $department_url = '';
     }
     $course_id = 0;
     if ($ok_to_register_course) {
         $manager = Database::getManager();
         $url = $manager->getRepository('ChamiloCoreBundle:AccessUrl')->find(api_get_current_access_url_id());
         $accessRelCourse = new AccessUrlRelCourse();
         $accessRelCourse->setUrl($url);
         $course = new Course();
         $course->setCode($code)->setDirectory($directory)->setCourseLanguage($course_language)->setTitle($title)->setDescription(self::lang2db(get_lang('CourseDescription')))->setCategoryCode($category_code)->setVisibility($visibility)->setShowScore(1)->setExpirationDate($expiration_date)->setDiskQuota(intval($disk_quota))->setTutorName($tutor_name)->setDepartmentName($department_name)->setDepartmentUrl($department_url)->setSubscribe(intval($subscribe))->setVisualCode($visual_code)->addUrls($accessRelCourse);
         $manager->persist($course);
         $manager->flush();
         $course_id = $course->getId();
         if ($course_id) {
             $sort = api_max_sort_value('0', api_get_user_id());
             // Default true
             $addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true;
             if ($addTeacher) {
                 $i_course_sort = CourseManager::userCourseSort($user_id, $code);
                 if (!empty($user_id)) {
                     $sql = "INSERT INTO " . $TABLECOURSUSER . " SET\n                                c_id     = '" . $course_id . "',\n                                user_id         = '" . intval($user_id) . "',\n                                status          = '1',\n                                is_tutor        = '0',\n                                sort            = '" . $i_course_sort . "',\n                                relation_type = 0,\n                                user_course_cat = '0'";
                     Database::query($sql);
                 }
             }
             if (!empty($teachers)) {
                 if (!is_array($teachers)) {
                     $teachers = array($teachers);
//.........这里部分代码省略.........
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:101,代码来源:add_course.lib.inc.php

示例12: getFormatedSessionsBlock

 /**
  * Get the formated data for sessions block to be displayed on Session Catalog page
  * @param array $sessions The session list
  * @return array
  */
 private function getFormatedSessionsBlock(array $sessions)
 {
     $extraFieldValue = new ExtraFieldValue('session');
     $userId = api_get_user_id();
     $sessionsBlocks = [];
     $entityManager = Database::getManager();
     $sessionRelCourseRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourse');
     $extraFieldRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraField');
     $extraFieldRelTagRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
     $tagsField = $extraFieldRepo->findOneBy(['extraFieldType' => Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE, 'variable' => 'tags']);
     /** @var \Chamilo\CoreBundle\Entity\Session $session */
     foreach ($sessions as $session) {
         $sessionDates = SessionManager::parseSessionDates(['display_start_date' => $session->getDisplayStartDate(), 'display_end_date' => $session->getDisplayEndDate(), 'access_start_date' => $session->getAccessStartDate(), 'access_end_date' => $session->getAccessEndDate(), 'coach_access_start_date' => $session->getCoachAccessStartDate(), 'coach_access_end_date' => $session->getCoachAccessEndDate()]);
         $imageField = $extraFieldValue->get_values_by_handler_and_field_variable($session->getId(), 'image');
         $sessionCourseTags = [];
         if (!is_null($tagsField)) {
             $sessionRelCourses = $sessionRelCourseRepo->findBy(['session' => $session]);
             foreach ($sessionRelCourses as $sessionRelCourse) {
                 $courseTags = $extraFieldRelTagRepo->getTags($tagsField, $sessionRelCourse->getCourse()->getId());
                 foreach ($courseTags as $tag) {
                     $sessionCourseTags[] = $tag->getTag();
                 }
             }
         }
         if (!empty($sessionCourseTags)) {
             $sessionCourseTags = array_unique($sessionCourseTags);
         }
         $repo = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
         $sequences = $repo->getRequirementsAndDependenciesWithinSequences($session->getId(), SequenceResource::SESSION_TYPE);
         $hasRequirements = false;
         foreach ($sequences['sequences'] as $sequence) {
             if (count($sequence['requirements']) === 0) {
                 continue;
             }
             $hasRequirements = true;
             break;
         }
         $sessionsBlock = array('id' => $session->getId(), 'name' => $session->getName(), 'image' => isset($imageField['value']) ? $imageField['value'] : null, 'nbr_courses' => $session->getNbrCourses(), 'nbr_users' => $session->getNbrUsers(), 'coach_name' => $session->getGeneralCoach()->getCompleteName(), 'is_subscribed' => SessionManager::isUserSubscribedAsStudent($session->getId(), $userId), 'icon' => $this->getSessionIcon($session->getName()), 'date' => $sessionDates['display'], 'subscribe_button' => $this->getRegisteredInSessionButton($session->getId(), $session->getName(), $hasRequirements), 'show_description' => $session->getShowDescription(), 'tags' => $sessionCourseTags);
         $sessionsBlock = array_merge($sessionsBlock, $sequences);
         $sessionsBlocks[] = $sessionsBlock;
     }
     return $sessionsBlocks;
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:48,代码来源:courses_controller.php

示例13: isset

/* For licensing terms, see /license.txt */
//require_once '../global.inc.php';
$action = isset($_GET['a']) ? $_GET['a'] : '';
switch ($action) {
    case 'get_second_select_options':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $option_value_id = isset($_REQUEST['option_value_id']) ? $_REQUEST['option_value_id'] : null;
        if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
            $field_options = new ExtraFieldOption($type);
            echo $field_options->get_second_select_field_options_by_field($field_id, $option_value_id, true);
        }
        break;
    case 'search_tags':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null;
        $extraFieldOption = new ExtraFieldOption($type);
        $result = [];
        $tags = Database::getManager()->getRepository('ChamiloCoreBundle:Tag')->createQueryBuilder('t')->where("t.tag LIKE :tag")->andWhere('t.fieldId = :field')->setParameter('field', $fieldId)->setParameter('tag', "{$tag}%")->getQuery()->getResult();
        foreach ($tags as $tag) {
            $result[] = ['caption' => $tag->getTag(), 'value' => $tag->getTag()];
        }
        echo json_encode($result);
        break;
    default:
        exit;
        break;
}
exit;
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:30,代码来源:extra_field.ajax.php

示例14: userCanAddFeedbackToUser

 /**
  * Check if the $fromUser can comment the $toUser skill issue 
  * @param Chamilo\UserBundle\Entity\User $fromUser
  * @param Chamilo\UserBundle\Entity\User $toUser
  * @return boolean
  */
 public static function userCanAddFeedbackToUser(User $fromUser, User $toUser)
 {
     if (api_is_platform_admin()) {
         return true;
     }
     $entityManager = Database::getManager();
     $userRepo = $entityManager->getRepository('ChamiloUserBundle:User');
     $fromUserStatus = $fromUser->getStatus();
     switch ($fromUserStatus) {
         case SESSIONADMIN:
             if (api_get_setting('allow_session_admins_to_manage_all_sessions') === 'true') {
                 if ($toUser->getCreatorId() === $fromUser->getId()) {
                     return true;
                 }
             }
             $sessionAdmins = $userRepo->getSessionAdmins($toUser);
             foreach ($sessionAdmins as $sessionAdmin) {
                 if ($sessionAdmin->getId() !== $fromUser->getId()) {
                     continue;
                 }
                 return true;
             }
             break;
         case STUDENT_BOSS:
             $studentBosses = $userRepo->getStudentBosses($toUser);
             foreach ($studentBosses as $studentBoss) {
                 if ($studentBoss->getId() !== $fromUser->getId()) {
                     continue;
                 }
                 return true;
             }
         case DRH:
             return UserManager::is_user_followed_by_drh($toUser->getId(), $fromUser->getId());
     }
     return false;
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:42,代码来源:skill.lib.php

示例15: switch

        switch ($user['relation_type']) {
            case 1:
                $status = get_lang('Drh');
                $link = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/dashboard_add_sessions_to_user.php?user=' . $userId);
                break;
            default:
                $status = get_lang('Student');
        }
        $table->setCellContents($row, 1, $status);
        $table->setCellContents($row, 2, $link);
        $row++;
    }
    $userListToShow .= $table->toHtml();
}
/** @var SequenceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$requirementAndDependencies = $repo->getRequirementAndDependencies($sessionId, SequenceResource::SESSION_TYPE);
$requirements = '';
if (!empty($requirementAndDependencies['requirements'])) {
    $requirements = Display::page_subheader(get_lang('Requirements'));
    $requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
}
$dependencies = '';
if (!empty($requirementAndDependencies['dependencies'])) {
    $dependencies = Display::page_subheader(get_lang('Dependencies'));
    $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
}
//$tpl = new Template(get_lang('Session'));
$tpl = Container::getTwig();
$tpl->addGlobal('session_header', $sessionHeader);
$tpl->addGlobal('title', $sessionTitle);
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:31,代码来源:resume_session.php


注:本文中的Database::getManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。