public static function get_news_ids4tags($tags) { if (!is_array($tags)) { $tags = (array) $tags; } if (!($tag_ids = \Model_Tag::get_ids4names($tags))) { return array(); } $objs = self::query()->where('tag_id', 'in', $tag_ids)->get(); return \Util_Orm::conv_col2array($objs, 'news_id'); }
public static function get_mentioned_member_ids4body($body) { if (!preg_match_all(Site_Util::get_match_pattern2mention(), $body, $matches, PREG_SET_ORDER)) { return array(); } $member_names = array(); foreach ($matches as $match) { $member_names[] = $match[2]; } if (!($members = \Model_Member::query()->where('name', 'in', $member_names)->get())) { array(); } return \Util_Orm::conv_col2array($members, 'id'); }
public static function get_notice_target_member_ids($member_id_to, $member_id_from, $foreign_table, $foreign_id, $type_key) { $notice_member_ids = \Util_Orm::conv_col2array(\Notice\Model_MemberWatchContent::get4foreign_data($foreign_table, $foreign_id), 'member_id'); if ($member_id_to && !in_array($member_id_to, $notice_member_ids)) { $notice_member_ids[] = $member_id_to; } $notice_member_ids = \Util_Array::unset_item($member_id_from, $notice_member_ids); if ($type_key == 'comment_like') { $type_key = 'like'; } if (!in_array($type_key, array('comment', 'like'))) { return $notice_member_ids; } $config_key = \Notice\Form_MemberConfig::get_name($type_key); return \Site_Member::get_member_ids4config_value($config_key, 1, $notice_member_ids); }
public static function delete_album_image_multiple4ids($album_image_ids = array(), $with_delete_timeline = false) { if (!is_array($album_image_ids)) { $album_image_ids = (array) $album_image_ids; } $delete_target_notice_cache_member_ids = array(); $delete_target_timeline_ids = array(); $writable_connection = \MyOrm\Model::connection(true); \DBUtil::set_connection($writable_connection); \DB::start_transaction(); foreach ($album_image_ids as $album_image_id) { if (is_enabled('notice')) { \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('album_image', $album_image_id); $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('album_image', $album_image_id); $delete_target_notice_cache_member_ids += \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids); \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids); } if (is_enabled('timeline') && $with_delete_timeline) { $delete_target_timeline_ids += \timeline\site_noormmodel::delete_timeline_multiple4foreign_data('album_image', $album_image_id); } } $file_names = \Util_Orm::conv_col2array(Model_AlbumImage::get4ids($album_image_ids), 'file_name'); \DB::delete('album_image')->where('id', 'in', $album_image_ids)->execute(); \DB::commit_transaction(); \DBUtil::set_connection(null); \DB::start_transaction(); if ($files = \Model_File::get4names($file_names)) { foreach ($files as $file) { $file->delete(); } } \DB::commit_transaction(); // delete caches if ($delete_target_notice_cache_member_ids) { foreach ($delete_target_notice_cache_member_ids as $member_id) { \Notice\Site_Util::delete_unread_count_cache($member_id); } } if ($delete_target_timeline_ids) { foreach ($delete_target_timeline_ids as $timeline_id) { \Timeline\Site_Util::delete_cache($timeline_id); } } }
public function test_delete_album_image_multiple4ids() { $timeline_ids = array_unique(\Util_Orm::conv_col2array(\Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image_id', self::$album_image->id), 'timeline_id')); $notices = array(); if (is_enabled('notice')) { $notice_ids = \Util_Orm::conv_col2array(\Notice\Model_Notice::get4foreign_data('album_image', self::$album_image->id), 'id'); $notice_ids += \Util_Orm::conv_col2array(\Notice\Model_Notice::get4parent_data('album_image', self::$album_image->id), 'id'); $notice_ids = array_unique($notice_ids); } $notice_statuses = \Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get(); $file_name = self::$album_image->file_name; $file = \Model_File::get4name($file_name); $file_size = $file->filesize; $member_filesize_before = self::$member->filesize_total; // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image')); } // file if (conf('upload.storageType') == 'db') { $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name)); } // album_image delete. Site_NoOrmModel::delete_album_image_multiple4ids(self::$album_image->id, true); // 件数 $this->assertEmpty(Model_AlbumImage::query()->where('id', self::$album_image->id)->get()); $this->assertEmpty(Model_AlbumImageLike::query()->where('album_image_id', self::$album_image_comment->id)->get()); $this->assertEmpty(Model_AlbumImageComment::query()->where('album_image_id', self::$album_image->id)->get()); $this->assertEmpty(Model_AlbumImageCommentLike::query()->where('album_image_comment_id', self::$album_image_comment->id)->get()); // file $this->assertEmpty(\Model_File::get4name($file_name)); // meber_filesize $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id)); // timeline if (is_enabled('timeline')) { $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', self::$album_image->id); $this->assertEmpty($timeline_child_datas); if ($timeline_ids) { $this->assertEmpty(\Timeline\Model_Timeline::query()->where('id', 'in', $timeline_ids)->get()); } // timeline view cache check if (self::$is_check_timeline_view_cache && $timeline_ids) { foreach ($timeline_ids as ${$timeline_id}) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline_id)); } } } // notice if (is_enabled('notice')) { $this->assertEmpty(\Notice\Model_MemberWatchContent::get4foreign_data('album_image', self::$album_image->id)); if ($notice_ids) { $this->assertEmpty(\Notice\Model_Notice::query()->where('id', 'in', $notice_ids)->get()); $this->assertEmpty(\Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get()); $this->assertEmpty(\Notice\Model_NoticeMemberFrom::query()->where('notice_id', 'in', $notice_ids)->get()); } if (self::$is_check_notice_cache) { foreach ($notice_statuses as $notice_statuse) { $this->assertEmpty(\Notice\Site_Util::get_unread_count_cache($notice_statuse->member_id)); } } } }
public function set_validation($add_fields = array(), $fieldset = 'default') { $this->validation = \Validation::forge($fieldset); // member $this->set_validation_member_field('name'); $this->set_validation_member_field('sex'); $this->set_validation_member_field_birthday(); // member_profile foreach ($this->profiles as $profile) { $member_profile = $this->member_profiles_profile_id_indexed[$profile->id]; $rules = array(); if ($profile->is_required) { $rules[] = 'required'; } switch ($profile->form_type) { case 'input': case 'textarea': $type = 'text'; if ($profile->value_type == 'email') { $type = 'email'; $rules[] = 'valid_email'; } elseif ($profile->value_type == 'integer') { $type = 'number'; $rules[] = array('valid_string', 'numeric'); } elseif ($profile->value_type == 'url') { $type = 'url'; $rules[] = 'valid_url'; } elseif ($profile->value_type == 'regexp') { $rules[] = array('match_pattern', $profile->value_regexp); } if ($profile->form_type == 'textarea') { $type = 'textarea'; } if ($profile->value_min) { $rule_name = $profile->value_type == 'integer' ? 'numeric_min' : 'min_length'; $rules[] = array($rule_name, $profile->value_min); } if ($profile->value_max) { $rule_name = $profile->value_type == 'integer' ? 'numeric_max' : 'max_length'; $rules[] = array($rule_name, $profile->value_max); } if ($profile->is_unique) { $rules[] = array('unique', 'member_profile.value', array(array('profile_id', $profile->id))); } $value = !is_null($member_profile) ? $member_profile->value : ''; $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'placeholder' => $profile->placeholder), $rules); break; case 'select': case 'radio': $type = $profile->form_type; $options = Util_Orm::conv_cols2assoc($profile->profile_option, 'id', 'label'); if (is_null($member_profile)) { $options_keys = array_keys($options); $value = array_shift($options_keys); } else { $value = $member_profile->profile_option_id; } $rules[] = array('valid_string', 'numeric'); $rules[] = array('in_array', array_keys($options)); $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'options' => $options), $rules); break; case 'checkbox': $type = $profile->form_type; $options = Util_Orm::conv_cols2assoc($profile->profile_option, 'id', 'label'); $value = !is_null($member_profile) ? Util_Orm::conv_col2array($member_profile, 'profile_option_id') : array(); $rules[] = array('checkbox_val', $options); if ($profile->is_required) { $rules[] = array('checkbox_require', 1); } $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'options' => $options), $rules); break; } } foreach ($add_fields as $name => $params) { $this->add_field($name, $params); } }
public static function get_liked_ids($parent_table, $member_id, array $parent_objs, $member_id_prop = 'member_id') { if (!$parent_objs) { return array(); } $like_model = Site_Model::get_model_name($parent_table . '_like'); $parent_foreign_key = $parent_table . '_id'; return $like_model::get_cols($parent_foreign_key, array(array($member_id_prop => $member_id), array($parent_foreign_key, 'in', \Util_Orm::conv_col2array($parent_objs, 'id', true)))); }
public static function get_ids4names($names) { return \Util_Orm::conv_col2array(self::get4names($names), 'id'); }
public static function get_col_array($column, $params = array()) { $params['select'] = $column; $query = self::get_list_query($params); return \Util_Orm::conv_col2array($query->get(), $column); }