Example #1
0
 public function testHasManyThrough()
 {
     $this->createUsersWithGroups(10, 5);
     $this->assertEqual(User::count(), 10);
     $this->assertEqual(Group::count(), 5);
     $this->assertEqual(UserAndGroupRelation::count(), 14);
     $user = User::findFirst(['conditions' => "login = '******'"]);
     // Test has_many_through collection
     $queryCount = TipyDAO::$queryCount;
     $groups = $user->groups;
     // We got a 2 new querys
     $this->assertEqual(TipyDAO::$queryCount, $queryCount + 2);
     $this->assertNotEqual($groups, null);
     $this->assertEqual(sizeof($groups), 5);
     $this->assertEqual($groups[0]->name, 'name_1');
     // Test cached association
     $this->assertNotEqual($user->associationsCache["groups"], null);
     $this->assertEqual($groups, $user->associationsCache["groups"]);
     // Test no query
     $queryCount = TipyDAO::$queryCount;
     $groupsAgain = $user->groups;
     // no more queries
     $this->assertEqual(TipyDAO::$queryCount, $queryCount);
     $this->assertEqual($groups, $groupsAgain);
     // Test has many collection with conditions
     $groups = $user->groups(["order" => " name desc"]);
     $this->assertEqual(sizeof($groups), 5);
     $this->assertEqual($groups[0]->name, 'name_5');
     // Test queries association is not cached
     $this->assertNotEqual($groups, $user->associationsCache["groups"]);
 }
Example #2
0
 public function render()
 {
     if (isset($this->config['course_id'])) {
         $course = new Course();
         $course->include_related('period');
         $course->get_by_id((int) $this->config['course_id']);
         $this->parser->assign('course', $course);
         if ($course->exists()) {
             $task_sets = new Task_set();
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'task_set');
             $task_sets_count = $task_sets->count();
             $this->parser->assign('task_sets_count', $task_sets_count);
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where('content_type', 'project');
             $projects_count = $task_sets->count();
             $this->parser->assign('projects_count', $projects_count);
             $groups = new Group();
             $groups->where_related($course);
             $groups_count = $groups->count();
             $this->parser->assign('groups_count', $groups_count);
             $students = new Student();
             $students->where_related('participant/course', 'id', $course->id);
             $students->where_related('participant', 'allowed', 1);
             $students_count = $students->count();
             $this->parser->assign('students_count', $students_count);
             $task_set_permissions = new Task_set_permission();
             $task_set_permissions->select_func('COUNT', '*', 'count');
             $task_set_permissions->where('enabled', 1);
             $task_set_permissions->where_related('task_set', 'id', '${parent}.id');
             $now = date('Y-m-d H:i:s');
             $plus_two_weeks = date('Y-m-d H:i:s', strtotime($now . ' + 2 weeks'));
             $minus_one_week = date('Y-m-d H:i:s', strtotime($now . ' - 1 week'));
             $task_sets->select('id, name, upload_end_time AS min_upload_end_time, upload_end_time AS max_upload_end_time');
             $task_sets->where_related($course);
             $task_sets->where('published', 1);
             $task_sets->where_subquery('0', $task_set_permissions);
             $task_sets->where('upload_end_time >=', $minus_one_week);
             $task_sets->where('upload_end_time <=', $plus_two_weeks);
             $task_sets_2 = new Task_set();
             $task_sets_2->select('id, name');
             $task_sets_2->where_related($course);
             $task_sets_2->where('published', 1);
             $task_sets_2->select_min('task_set_permissions.upload_end_time', 'min_upload_end_time');
             $task_sets_2->select_max('task_set_permissions.upload_end_time', 'max_upload_end_time');
             $task_sets_2->where_related('task_set_permission', 'enabled', 1);
             $task_sets_2->having('(MAX(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MAX(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->or_having('(MIN(`task_set_permissions`.`upload_end_time`) >= ' . $this->db->escape($minus_one_week) . ' AND MIN(`task_set_permissions`.`upload_end_time`) <= ' . $this->db->escape($plus_two_weeks) . ')');
             $task_sets_2->group_by('id');
             $task_sets->union_iterated($task_sets_2, FALSE, 'min_upload_end_time DESC, max_upload_end_time DESC', isset($this->config['number_of_task_sets']) ? (int) $this->config['number_of_task_sets'] : 5);
             $this->parser->assign('task_sets', $task_sets);
         }
     }
     $this->parser->parse('widgets/admin/course_overview/main.tpl');
 }
 public function run()
 {
     if (Group::count('id')) {
         echo 'Skipping group seeder' . "\n";
         return;
     }
     $groups = [['title' => 'Ожидающий доступа', 'configs' => ['stars' => 0, 'title' => 'Ожидающий доступа', 'conf_show_signature' => false]], ['title' => 'Администратор', 'configs' => ['title' => 'Администратор']], ['title' => 'Newbie', 'configs' => ['stars' => 0, 'title' => 'Ньюбл', 'conf_show_signature' => false]], ['title' => 'Junior', 'configs' => ['stars' => 1, 'title' => 'Юниор']], ['title' => 'Member', 'configs' => ['stars' => 2, 'title' => 'Участник']], ['title' => 'Full Member', 'configs' => ['stars' => 3, 'title' => 'Уверенный пользователь']], ['title' => 'Senior Member', 'configs' => ['stars' => 4, 'title' => 'Сеньор']], ['title' => 'Profi', 'configs' => ['stars' => 5, 'title' => 'Профи']], ['title' => 'Master', 'configs' => ['stars' => 6, 'title' => 'Мастер']], ['title' => 'Guru', 'configs' => ['stars' => 7, 'title' => 'Гуру']], ['title' => 'Monster', 'configs' => ['stars' => 8, 'title' => 'Монстр']], ['title' => 'Wizard', 'configs' => ['stars' => 9, 'title' => 'Волшебник']], ['title' => 'God', 'configs' => ['stars' => 10, 'title' => 'Бог']], ['title' => 'Нарушившие правила', 'configs' => ['title' => 'Нарушитель', 'conf_show_signature' => false]], ['title' => 'Бан', 'configs' => ['title' => 'В бане', 'conf_show_signature' => false]], ['title' => 'Комодератор', 'configs' => ['title' => 'Помошник модератора']], ['title' => 'Модератор', 'configs' => ['title' => 'Модератор']], ['title' => 'Супермодератор', 'configs' => ['title' => 'Супермод']], ['title' => 'Ветеран', 'configs' => ['title' => 'Ветеран']], ['title' => 'Участники клуба Sources.RU', 'configs' => ['title' => 'Клубень']]];
     DB::transaction(function () use($groups) {
         foreach ($groups as $group) {
             Group::create($group);
         }
     });
 }
Example #4
0
 /**
  * View groups
  *
  * @param Request $request
  * @return mixed
  */
 public function groups_list(Request $request)
 {
     $filter = [];
     if ($request->order) {
         $filter['order'] = $request->order;
     }
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Group::count()]);
     $filter = array_merge($filter, $paginator->limit());
     // Filter groups
     $groups = \Group::all($filter);
     $groups = array_map(function ($i) {
         return $i->to_array();
     }, $groups);
     return $this->view->render('users/groups.twig', ['title' => $this->lang->translate('user.groups'), 'groups_list' => $groups, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page]);
 }
 public function insertGroup()
 {
     $cre = ["group" => Input::get('group')];
     $rules = ["group" => 'required'];
     $validator = Validator::make($cre, $rules);
     if ($validator->passes()) {
         $group = new Group();
         $group->group_name = Input::get('group');
         $group->center_id = Input::get('center_id');
         $group->save();
         $group_info = Group::select('center.center_name', 'groups.group_name', 'city.city_name', 'groups.id')->join('center', 'groups.center_id', '=', 'center.id')->join('city', 'center.city_id', '=', 'city.id')->where('groups.id', '=', $group->id)->first();
         $count = Group::count();
         $data['success'] = 'true';
         $data['message'] = html_entity_decode(View::make('admin.manage.groups.view', ["data" => $group_info, "count" => $count]));
     } else {
         $data["success"] = false;
         $data["message"] = "All fields are not filled";
     }
     return json_encode($data);
 }
$group->name = 'Yo! Ugly Group';
$group->date = '19001231';
$group->insert();
echo '<p>The "' . $group->name . '" have ID = ' . $group->id . '.</p>';
echo "<p>Oops... it's not " . substr($group->date, 0, 4) . " but 1999. Let's <b>update</b> it.</p>";
$group->date = '19991231';
$group->update();
echo "<p>Now we have the correct year: " . substr($group->date, 0, 4) . ".</p>";
$group->reset();
echo "<h1>Let's find the groups starting with Y</h1>";
$group->addWhere("name LIKE 'Y%'");
$group->addOrder("id");
$total = $group->find();
echo "<p>We've found " . $total . " groups starting with Y.</p>";
// we can use the count method to get the same result
if ($group->count() > 1) {
    while ($group->fetch()) {
        YDDebugUtil::dump($group->getValues());
    }
}
echo "<h1>But I really want is the first group.</h1>";
$group->reset();
$group->find(1);
YDDebugUtil::dump($group->getValues());
echo "<h1>And I don't like the 'Yo! Ugly Group, so I'll delete it. I will reset the object and execute a delete.</h1>";
$group->reset();
$group->delete();
echo "<p>A PHP notice saying that I have no conditions... This is a protection defined by the configuration<br>";
echo "YD_DATABASEOBJECT_DELETE. A similar configuration is available for UPDATEs that don't have conditions<br>";
echo "YD_DATABASEOBJECT_UPDATE. The default is false for both.</p>";
echo "<p>Let's set the ID.</p>";
Example #7
0
 public function countGroups($params = array())
 {
     if (!isset($params['status'])) {
         $params['status'] = 1;
     }
     if (!isset($params['is_delete'])) {
         $params['is_del'] = 0;
     }
     $model = new Group();
     $criteria = new CDbCriteria();
     $criteria->condition .= "1";
     $criteria->order = !empty($params['order']) ? $params['order'] : 't.ctime';
     if (!empty($limit)) {
         $criteria->limit = $limit;
     }
     if (!empty($params)) {
         $array = array('id', 'uid', 'cid0', 'cid1', 'type', 'status', 'is_del');
         foreach ($params as $key => $value) {
             if (in_array($key, $array)) {
                 $criteria->condition .= " and {$key}=:{$key}";
                 $criteria->params[':' . $key] = $value;
             }
         }
     }
     if (!empty($params['pageSize'])) {
         $pageSize = $params['pageSize'];
         $page = $params['page'];
         $_GET['page'] = $page;
         $total = $model->count($criteria);
         $pages = new CPagination($total);
         $pages->pageSize = $pageSize ? $pageSize : self::PAGE_SIZE;
         $pages->applyLimit($criteria);
     }
     $count = $model->count($criteria);
     return $count;
 }
Example #8
0
 /**
  * Lists all models.
  */
 public function actionAdmin()
 {
     $model = new Group('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['Group'])) {
         $model->attributes = $_GET['Group'];
     }
     $this->render('admin', array('model' => $model, 'count' => $model->count()));
 }
Example #9
0
 private function set_paginate_options()
 {
     $config = array();
     $config['base_url'] = site_url() . 'admin/groups';
     $config['use_page_numbers'] = TRUE;
     $config['per_page'] = 10;
     $config['total_rows'] = Group::count();
     $config['uri_segment'] = 3;
     $config['first_link'] = "<< " . lang('web_first');
     $config['first_tag_open'] = "<span class='pag'>";
     $config['first_tag_close'] = '</span>';
     $config['last_link'] = lang('web_last') . " >>";
     $config['last_tag_open'] = "<span class='pag'>";
     $config['last_tag_close'] = '</span>';
     $config['next_link'] = FALSE;
     $config['next_tag_open'] = "<span class='pag'>";
     $config['next_tag_close'] = '</span>';
     $config['prev_link'] = FALSE;
     $config['prev_tag_open'] = "<span class='pag'>";
     $config['prev_tag_close'] = '</span>';
     $config['cur_tag_open'] = "<span class='pag pag_active'>";
     $config['cur_tag_close'] = '</span>';
     $config['num_tag_open'] = "<span class='pag'>";
     $config['num_tag_close'] = '</span>';
     $config['full_tag_open'] = "<div class='navigation'>";
     $config['full_tag_close'] = '</div>';
     $choice = $config["total_rows"] / $config["per_page"];
     //$config["num_links"] = round($choice);
     return $config;
 }